Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customization process part2 #1967

Merged
merged 44 commits into from
Aug 15, 2023

Conversation

MaryGao
Copy link
Member

@MaryGao MaryGao commented Aug 11, 2023

fixes #1811 #1958

[Part 2] In this pr we would cover:

  • Generate modular version for package.json and tsconfig.json
  • Generate metadata if relevant files are absent and not generate if existing
  • Refresh OpenAI to the latest tsp

Please notice the change would only apply to typespec as input. For swagger if needed we could have another pr.

@MaryGao MaryGao marked this pull request as ready for review August 13, 2023 08:13
"clean": "rimraf dist dist-browser dist-esm test-dist temp types *.tgz *.log",
"execute:samples": "echo skipped",
"extract-api": "rimraf review && mkdirp ./review && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small fix when there is no sample folder included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this trying to completely ignore the samples-dev folder?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the small fix, sample folder should be ignored if there is no samples generated.

Should not be ignored if there is samples generated.

"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you point to me where you add this check in the codegen side ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaryGao
Copy link
Member Author

MaryGao commented Aug 14, 2023

Below cases are covered in our smoke/integration test(T - true, F - false, U - undefined):

generateMetadata generateTest metaGenerated? testGenerated? Comments
T T Y Y
T F Y N
T U Y Y(if absent) N(if existing)
F F N N
F T N Y
F U Y Y(if absent) N(if existing)
U U Y(if absent) N(if existing) Y(if absent) N(if existing)
U T Y(if absent) N(if existing) Y
U F Y(if absent) N(if existing) N

@MaryGao MaryGao requested a review from qiaozha August 14, 2023 05:41
Copy link
Member

@qiaozha qiaozha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we by default geenrateTest and generateSample is good or not ? given the sample quality and we might have problem to compiling the code in CI.

"clean": "rimraf dist dist-browser dist-esm test-dist temp types *.tgz *.log",
"execute:samples": "echo skipped",
"extract-api": "rimraf review && mkdirp ./review && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this trying to completely ignore the samples-dev folder?

packages/typespec-ts/src/index.ts Show resolved Hide resolved
packages/typespec-ts/src/index.ts Outdated Show resolved Hide resolved
packages/typespec-ts/src/index.ts Outdated Show resolved Hide resolved
const { generateTest, packageDetails } = model.options || {};
let { generateTest, packageDetails, isModularLibrary } = model.options || {};
// Take the undefined as true by default
generateTest = generateTest === true || generateTest === undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have some automatical check if the tests exist or not ?

Copy link
Member Author

@MaryGao MaryGao Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this automatical check in emitter side, https://github.com/Azure/autorest.typescript/pull/1967/files#diff-3d0e467e1b9edbc8377b86fbeaac71ce5bc0ddc8260bee5e56a777360cf19398R236-R242.

In common layer we also need to check if we need to generate test relevant stuff so we have the dependency of generateTest.

const project = new Project();
const config = {
$schema:
"https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
mainEntryPointFilePath: `./types${generateTest ? "/src" : ""}/index.d.ts`,
mainEntryPointFilePath: `./types${
generateTest || isModularLibrary ? "/src" : ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isModularLibrary can have impact on this mainEntryPointFilePath ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For modular the generated index.d.ts would be in types/src folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even if we don't generate tests and samples ?

Copy link
Member Author

@MaryGao MaryGao Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is because in modular tsconfig.json we by default add below option which would always intro a src folder in dist-ems folder.

"rootDir": "."

https://www.typescriptlang.org/tsconfig#rootDir

@MaryGao MaryGao mentioned this pull request Aug 14, 2023
7 tasks
@MaryGao
Copy link
Member Author

MaryGao commented Aug 15, 2023

Not sure if we by default geenrateTest and generateSample is good or not ? given the sample quality and we might have problem to compiling the code in CI.

The default behavior of generateSample(not generating samples) is not changed, I enable the generateTest if this config is undefined and there is no test folder. And I prefer to turn on this option because it could help add testing relevant configs and sample codes to allow customer grow up.

@MaryGao MaryGao requested a review from qiaozha August 15, 2023 03:28
const hasPackageFile = await existsSync(
join(dpgContext.generationPathDetail?.metadataDir ?? "", "package.json")
);
const shouldGenerateMetadata =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the emitter logic to detect if we need to generate metadata.

const hasTestFolder = await fsextra.pathExists(
join(dpgContext.generationPathDetail?.metadataDir ?? "", "test")
);
const shouldGenerateTest =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the emitter logic to detect if we need to generate test files.

@@ -718,6 +719,8 @@ function deserializeResponseValue(
return required
? `new Date(${restValue})`
: `${restValue} !== undefined? new Date(${restValue}): undefined`;
case "combined":
return `${restValue} as any`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temp workaround for this issue #1921

error: !p.error ? undefined : p.error,
})),
created: new Date(result.body.result?.["created"]),
data: result.body.result?.["data"] as any,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround: #1921

@MaryGao MaryGao merged commit e3cc0f4 into Azure:main Aug 15, 2023
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RLC] Generate metadata if relevant files are absent
2 participants