Fix package.json dependency migration when moving from Swagger to TypeSpec modular#3811
Fix package.json dependency migration when moving from Swagger to TypeSpec modular#3811
Conversation
…e-client when moving from Swagger to TypeSpec modular Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
|
@copilot when generateMetadata is true, we will call buildPackageFile, in this case, generateMetadata is false, emitter will not run buildPackageFile. so we need additionally update them |
…-parser) to updatePackageFile when generateMetadata is false Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
Fixed in 9e41525. The |
|
@copilot we need to have a check to compare origin packageJson with the one from getAzureMonorepoDependencies function in |
…es canonical set and update inconsistencies Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
Done in 1b63394. |
Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
|
@copilot clean up all changes first. In this case, the root cause is: BackgroundWhen using ProblemWhen migrating a library originally generated by AutoRest (from Swagger) to TypeSpec generation via AutoRest-generated (original):
TypeSpec-generated (expected):
Since Expected BehaviorWhen Proposed Solution
|
…index.ts, overwrite with getAzureMonorepoDependencies canonical set Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/6da87dc7-e715-4f35-b121-eda9d3f0b532
Done in 63c3c0b. Previous approach was cleaned up and re-implemented as proposed:
|
| if (hasAutorestDeps) { | ||
| const additionalDependencies: Record<string, string> = {}; | ||
| if (packageUsesXmlSerialization(dpgContext.sdkPackage)) { | ||
| additionalDependencies["fast-xml-parser"] = "^4.5.0"; | ||
| } | ||
| const depConfig: AzureMonorepoInfoConfig = { | ||
| name: | ||
| rlcClient.options?.packageDetails?.name ?? | ||
| rlcClient.libraryName, | ||
| version: | ||
| rlcClient.options?.packageDetails?.version ?? "1.0.0-beta.1", | ||
| description: | ||
| rlcClient.options?.packageDetails?.description ?? | ||
| `A generated SDK for ${rlcClient.libraryName}.`, | ||
| moduleKind: option.moduleKind ?? "esm", | ||
| withTests: option.generateTest === true, | ||
| withSamples: option.generateSample === true, | ||
| hasLro: hasPollingOperations(rlcClient), | ||
| specSource: "TypeSpec", | ||
| clientFilePaths: [], | ||
| isModularLibrary: true, | ||
| ...(Object.keys(additionalDependencies).length > 0 && { | ||
| dependencies: additionalDependencies | ||
| }) | ||
| }; | ||
| const { | ||
| dependencies: canonicalDeps, | ||
| devDependencies: canonicalDevDeps | ||
| } = getAzureMonorepoDependencies(depConfig); |
There was a problem hiding this comment.
@copilot could we move these step under updatePackageFile?
There was a problem hiding this comment.
Done in ea7412d. The AutoRest detection steps are now entirely inside updatePackageFile in rlc-common: it reads the existing file, checks for AutoRest-specific deps, builds the AzureMonorepoInfoConfig from the model, and calls getAzureMonorepoDependencies to overwrite dependencies/devDependencies. index.ts is simplified to just pass format-specific extra deps (e.g. fast-xml-parser) and call updatePackageFile as before.
…plify index.ts Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/2f2504b0-1a5b-4c45-9cb3-774f98a4fa5f
…thub.com/Azure/autorest.typescript into copilot/update-package-json-dependencies
| const needsLroUpdate = isAzure && hasLro; | ||
| const isAzureMonorepoLib = | ||
| isAzureMonorepoPackage(model) && !!model.options?.isModularLibrary; | ||
| const needsLroUpdate = isAzure && hasLro && !isAzureMonorepoLib; |
There was a problem hiding this comment.
Why do we need to modify needsLroUpdate related logic? isAzureMonorepoLib conflicts with isAzure and needsLroUpdate will never return true.
When
tsp-clientruns against an existing Swagger-generated package, it preservespackage.json, causinggenerateMetadata: false. The emitter skips regeneratingpackage.jsonentirely, leaving AutoRest-specific dependencies in place and causing compile errors in the newly generated modular code.Background
When migrating a library originally generated by AutoRest (from Swagger) to TypeSpec generation via
tsp-client, the existingpackage.jsoncontains AutoRest-specific dependencies that differ from what the TypeSpec emitter produces. For example:AutoRest-generated (original):
TypeSpec-generated (expected):
Changes
packages/rlc-common/src/metadata/buildPackageFile.ts—updatePackageFilenow handles the full Swagger→TypeSpec migration internally:AUTOREST_ONLY_DEPSconstant listing AutoRest-specific deps (@azure/core-client,@azure/core-tracing,@azure/core-paging)@azure/core-lro ^2.x), buildsAzureMonorepoInfoConfigfrom the model, callsgetAzureMonorepoDependencies, and overwritesdependencies/devDependencieswith canonical TypeSpec valuesdependenciesoption inPackageFileOptionsaccepts format-specific extra deps (e.g.fast-xml-parser) to merge into the canonical set during migrationgetAzureMonorepoDependenciesandAzureMonorepoInfoConfigvia@azure-tools/rlc-commonpackages/typespec-ts/src/index.ts— Simplifiedelse if (hasPackageFile)branch: only passes format-specific extra deps (e.g.fast-xml-parser: ^4.5.0when XML serialization is used) toupdatePackageFile; all AutoRest detection and canonical dep resolution is handled insideupdatePackageFilepackages/rlc-common/test/integration/packageJson.spec.ts— Added tests for:@azure/core-clientand migration to canonical TypeSpec deps@azure/core-lro ^2.xand migrationfast-xml-parser) merged into canonical set on migrationExample
Before (Swagger-generated
package.json, kept bytsp-client):{ "dependencies": { "@azure/core-client": "^1.9.3", "@azure/core-tracing": "^1.0.0", "@azure/core-rest-pipeline": "^1.19.1", "tslib": "^2.6.2" }, "devDependencies": { "autorest": "catalog:", "@types/node": "^18.0.0" } }After
updatePackageFileruns during modular TypeSpec generation:{ "dependencies": { "@azure-rest/core-client": "^2.3.1", "@azure/core-auth": "^1.9.0", "@azure/core-rest-pipeline": "^1.20.0", "@azure/core-util": "^1.12.0", "@azure/logger": "^1.2.0", "tslib": "^2.8.1" }, "devDependencies": { "@azure-tools/test-credential": "workspace:^", "@azure/dev-tool": "workspace:^", "@types/node": "catalog:", "typescript": "catalog:" } }Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.