@azure-tools/rlc-common 0.52.3 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +17 -0
  3. package/dist/buildIndexFile.js +9 -0
  4. package/dist/buildIndexFile.js.map +1 -1
  5. package/dist/metadata/buildPackageFile.js +44 -9
  6. package/dist/metadata/buildPackageFile.js.map +1 -1
  7. package/dist/metadata/buildTestConfig.js +28 -60
  8. package/dist/metadata/buildTestConfig.js.map +1 -1
  9. package/dist/metadata/buildTsConfig.js +120 -93
  10. package/dist/metadata/buildTsConfig.js.map +1 -1
  11. package/dist/metadata/buildVitestConfig.js +5 -21
  12. package/dist/metadata/buildVitestConfig.js.map +1 -1
  13. package/dist/metadata/buildWarpConfig.js +18 -18
  14. package/dist/metadata/buildWarpConfig.js.map +1 -1
  15. package/dist/metadata/packageJson/buildAzureMonorepoPackage.js +9 -3
  16. package/dist/metadata/packageJson/buildAzureMonorepoPackage.js.map +1 -1
  17. package/dist/metadata/packageJson/packageCommon.js +9 -0
  18. package/dist/metadata/packageJson/packageCommon.js.map +1 -1
  19. package/dist/package.json +1 -1
  20. package/dist-esm/buildIndexFile.js +9 -0
  21. package/dist-esm/buildIndexFile.js.map +1 -1
  22. package/dist-esm/metadata/buildPackageFile.js +41 -6
  23. package/dist-esm/metadata/buildPackageFile.js.map +1 -1
  24. package/dist-esm/metadata/buildTestConfig.js +28 -59
  25. package/dist-esm/metadata/buildTestConfig.js.map +1 -1
  26. package/dist-esm/metadata/buildTsConfig.js +115 -90
  27. package/dist-esm/metadata/buildTsConfig.js.map +1 -1
  28. package/dist-esm/metadata/buildVitestConfig.js +5 -21
  29. package/dist-esm/metadata/buildVitestConfig.js.map +1 -1
  30. package/dist-esm/metadata/buildWarpConfig.js +18 -18
  31. package/dist-esm/metadata/buildWarpConfig.js.map +1 -1
  32. package/dist-esm/metadata/packageJson/buildAzureMonorepoPackage.js +8 -3
  33. package/dist-esm/metadata/packageJson/buildAzureMonorepoPackage.js.map +1 -1
  34. package/dist-esm/metadata/packageJson/packageCommon.js +9 -0
  35. package/dist-esm/metadata/packageJson/packageCommon.js.map +1 -1
  36. package/dist-esm/package.json +1 -1
  37. package/package.json +1 -1
  38. package/src/buildIndexFile.ts +10 -0
  39. package/src/metadata/buildPackageFile.ts +49 -7
  40. package/src/metadata/buildTestConfig.ts +36 -75
  41. package/src/metadata/buildTsConfig.ts +146 -99
  42. package/src/metadata/buildVitestConfig.ts +6 -23
  43. package/src/metadata/buildWarpConfig.ts +19 -19
  44. package/src/metadata/packageJson/buildAzureMonorepoPackage.ts +8 -3
  45. package/src/metadata/packageJson/packageCommon.ts +9 -0
  46. package/test/integration/packageJson.spec.ts +154 -8
  47. package/test/integration/vitestConfig.spec.ts +1 -1
  48. package/test/integration/warpConfig.spec.ts +97 -0
  49. package/types/metadata/buildPackageFile.d.ts +7 -2
  50. package/types/metadata/buildTestConfig.d.ts +6 -4
  51. package/types/metadata/buildTsConfig.d.ts +35 -3
  52. package/types/metadata/buildVitestConfig.d.ts +1 -1
  53. package/types/metadata/buildWarpConfig.d.ts +7 -3
  54. package/types/metadata/packageJson/packageCommon.d.ts +8 -0
@@ -132,10 +132,12 @@ describe("Package file generation", () => {
132
132
  const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
133
133
 
134
134
  expect(packageFile).to.have.property("sdk-type", "client");
135
- expect(packageFile).to.have.property(
136
- "repository",
137
- "github:Azure/azure-sdk-for-js"
138
- );
135
+ expect(packageFile).to.have.property("repository");
136
+ expect(packageFile.repository).to.deep.equal({
137
+ type: "git",
138
+ url: "git+https://github.com/Azure/azure-sdk-for-js",
139
+ directory: "test"
140
+ });
139
141
  expect(packageFile).to.have.property("bugs");
140
142
  expect(packageFile.bugs).to.have.property(
141
143
  "url",
@@ -151,6 +153,21 @@ describe("Package file generation", () => {
151
153
  );
152
154
  });
153
155
 
156
+ it("should set a default repository directory when package directory is unavailable", () => {
157
+ const model = createMockModel({
158
+ ...baseConfig
159
+ });
160
+ const packageFileContent = buildPackageFile(model);
161
+ const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
162
+
163
+ expect(packageFile).to.have.property("repository");
164
+ expect(packageFile.repository).to.deep.equal({
165
+ type: "git",
166
+ url: "git+https://github.com/Azure/azure-sdk-for-js",
167
+ directory: "sdk/"
168
+ });
169
+ });
170
+
154
171
  it("should have monorepo metadata", () => {
155
172
  const model = createMockModel({ ...baseConfig });
156
173
  const packageFileContent = buildPackageFile(model);
@@ -396,7 +413,7 @@ describe("Package file generation", () => {
396
413
 
397
414
  expect(packageFile.scripts).to.have.property(
398
415
  "build:samples",
399
- "tsc -p tsconfig.samples.json && dev-tool samples publish -f"
416
+ "tsc -p config/tsconfig.samples.json && dev-tool samples publish -f"
400
417
  );
401
418
  });
402
419
 
@@ -411,7 +428,7 @@ describe("Package file generation", () => {
411
428
 
412
429
  expect(packageFile.scripts).to.have.property(
413
430
  "build:samples",
414
- "tsc -p tsconfig.samples.json"
431
+ "tsc -p config/tsconfig.samples.json"
415
432
  );
416
433
  });
417
434
 
@@ -901,8 +918,12 @@ describe("Package file generation", () => {
901
918
  clientContextPaths: []
902
919
  });
903
920
 
904
- // Should return undefined when nothing needs to be updated
905
- expect(packageFileContent).to.be.undefined;
921
+ // Should still return a result (imports are added for warp packages),
922
+ // but constantPaths should remain unchanged
923
+ const packageInfo = JSON.parse(packageFileContent!.content);
924
+ expect(packageInfo["//metadata"].constantPaths).to.deep.equal([
925
+ { path: "src/old-path.ts", prefix: "userAgentInfo" }
926
+ ]);
906
927
  });
907
928
 
908
929
  it("should not update constantPaths for non-Azure packages", () => {
@@ -932,6 +953,131 @@ describe("Package file generation", () => {
932
953
  { path: "src/old-path.ts", prefix: "userAgentInfo" }
933
954
  ]);
934
955
  });
956
+
957
+ it("should migrate @azure/core-client to @azure-rest/core-client", () => {
958
+ const model = createMockModel({
959
+ moduleKind: "esm",
960
+ flavor: "azure",
961
+ isMonorepo: true,
962
+ hasLro: false
963
+ });
964
+
965
+ const initialPackageInfo = {
966
+ name: "@azure/test-package",
967
+ version: "1.0.0",
968
+ dependencies: {
969
+ "@azure/core-client": "^1.9.3",
970
+ "@azure/core-rest-pipeline": "^1.19.1",
971
+ "tslib": "^2.6.2"
972
+ }
973
+ };
974
+
975
+ const packageFileContent = updatePackageFile(model, initialPackageInfo);
976
+ expect(packageFileContent).to.not.be.undefined;
977
+ const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
978
+
979
+ expect(packageFile.dependencies).to.not.have.property("@azure/core-client");
980
+ expect(packageFile.dependencies).to.have.property(
981
+ "@azure-rest/core-client",
982
+ "^2.3.1"
983
+ );
984
+ expect(packageFile.dependencies).to.have.property(
985
+ "@azure/core-rest-pipeline",
986
+ "^1.19.1"
987
+ );
988
+ });
989
+
990
+ it("should not add duplicate @azure-rest/core-client if already present", () => {
991
+ const model = createMockModel({
992
+ moduleKind: "esm",
993
+ flavor: "azure",
994
+ isMonorepo: true,
995
+ hasLro: false
996
+ });
997
+
998
+ const initialPackageInfo = {
999
+ name: "@azure/test-package",
1000
+ version: "1.0.0",
1001
+ dependencies: {
1002
+ "@azure/core-client": "^1.9.3",
1003
+ "@azure-rest/core-client": "^2.0.0",
1004
+ "tslib": "^2.6.2"
1005
+ }
1006
+ };
1007
+
1008
+ const packageFileContent = updatePackageFile(model, initialPackageInfo);
1009
+ expect(packageFileContent).to.not.be.undefined;
1010
+ const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
1011
+
1012
+ expect(packageFile.dependencies).to.not.have.property("@azure/core-client");
1013
+ // Existing version should be preserved, not overwritten
1014
+ expect(packageFile.dependencies).to.have.property(
1015
+ "@azure-rest/core-client",
1016
+ "^2.0.0"
1017
+ );
1018
+ });
1019
+
1020
+ it("should only add platform imports when no @azure/core-client and no other update triggers", () => {
1021
+ const model = createMockModel({
1022
+ moduleKind: "esm",
1023
+ flavor: "azure",
1024
+ isMonorepo: true,
1025
+ hasLro: false
1026
+ });
1027
+
1028
+ const initialPackageInfo = {
1029
+ name: "@azure/test-package",
1030
+ version: "1.0.0",
1031
+ dependencies: {
1032
+ "@azure-rest/core-client": "^2.3.1",
1033
+ "@azure/core-rest-pipeline": "^1.20.0",
1034
+ "tslib": "^2.8.1"
1035
+ }
1036
+ };
1037
+
1038
+ const packageFileContent = updatePackageFile(model, initialPackageInfo);
1039
+ expect(packageFileContent).to.not.be.undefined;
1040
+ const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
1041
+
1042
+ // Dependencies should remain unchanged
1043
+ expect(packageFile.dependencies).to.not.have.property("@azure/core-client");
1044
+ expect(packageFile.dependencies).to.have.property(
1045
+ "@azure-rest/core-client",
1046
+ "^2.3.1"
1047
+ );
1048
+
1049
+ // Platform imports should be added for Azure monorepo ESM packages
1050
+ expect(packageFile).to.have.property("imports");
1051
+ expect(packageFile.imports).to.have.property("#platform/*.js");
1052
+ });
1053
+
1054
+ it("should migrate @azure/core-client for non-monorepo Azure packages", () => {
1055
+ const model = createMockModel({
1056
+ moduleKind: "cjs",
1057
+ flavor: "azure",
1058
+ isMonorepo: false,
1059
+ hasLro: false
1060
+ });
1061
+
1062
+ const initialPackageInfo = {
1063
+ name: "@azure/test-package",
1064
+ version: "1.0.0",
1065
+ dependencies: {
1066
+ "@azure/core-client": "^1.9.3",
1067
+ "tslib": "^2.6.2"
1068
+ }
1069
+ };
1070
+
1071
+ const packageFileContent = updatePackageFile(model, initialPackageInfo);
1072
+ expect(packageFileContent).to.not.be.undefined;
1073
+ const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
1074
+
1075
+ expect(packageFile.dependencies).to.not.have.property("@azure/core-client");
1076
+ expect(packageFile.dependencies).to.have.property(
1077
+ "@azure-rest/core-client",
1078
+ "^2.3.1"
1079
+ );
1080
+ });
935
1081
  });
936
1082
 
937
1083
  describe("Flavorless lib", () => {
@@ -14,7 +14,7 @@ describe("vitest.config", () => {
14
14
 
15
15
  const result = buildVitestConfig(model, "browser");
16
16
  expect(result?.content).includes(
17
- `export default viteConfig;`
17
+ `export { default } from "../../../eng/vitestconfigs/browser.config.ts";`
18
18
  );
19
19
  });
20
20
  });
@@ -0,0 +1,97 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ import { describe, it, expect } from "vitest";
5
+
6
+ import { buildWarpConfig } from "../../src/metadata/buildWarpConfig.js";
7
+ import { createMockModel } from "./mockHelper.js";
8
+
9
+ describe("warp.config.yml generation", () => {
10
+ describe("azure monorepo", () => {
11
+ it("should generate a self-contained config without polyfillSuffix", () => {
12
+ const model = createMockModel({
13
+ moduleKind: "esm",
14
+ isMonorepo: true,
15
+ flavor: "azure"
16
+ });
17
+
18
+ const result = buildWarpConfig(model);
19
+ expect(result).toBeDefined();
20
+ expect(result!.path).toBe("warp.config.yml");
21
+ expect(result!.content).not.toContain("extends:");
22
+ // polyfillSuffix is no longer used — polyfill resolution is handled
23
+ // via package.json subpath imports instead.
24
+ expect(result!.content).not.toContain("polyfillSuffix");
25
+ // All four targets with tsconfig paths
26
+ expect(result!.content).toContain("name: browser");
27
+ expect(result!.content).toContain("name: react-native");
28
+ expect(result!.content).toContain("name: esm");
29
+ expect(result!.content).toContain("name: commonjs");
30
+ expect(result!.content).toContain("tsconfig:");
31
+ // Base exports should be included
32
+ expect(result!.content).toContain('"./package.json"');
33
+ expect(result!.content).toContain('"."');
34
+ });
35
+
36
+ it("should include custom exports alongside base exports", () => {
37
+ const model = createMockModel({
38
+ moduleKind: "esm",
39
+ isMonorepo: true,
40
+ flavor: "azure"
41
+ });
42
+
43
+ const result = buildWarpConfig(model, {
44
+ exports: {
45
+ ".": "./src/index.ts",
46
+ "./models": "./src/models/index.ts"
47
+ }
48
+ });
49
+ expect(result).toBeDefined();
50
+ expect(result!.content).not.toContain("extends:");
51
+ expect(result!.content).not.toContain("polyfillSuffix");
52
+ expect(result!.content).toContain("./models");
53
+ expect(result!.content).toContain("./package.json");
54
+ expect(result!.content).toContain("moduleType: commonjs");
55
+ });
56
+
57
+ it("should not return config for non-esm module kind", () => {
58
+ const model = createMockModel({
59
+ moduleKind: "cjs",
60
+ isMonorepo: true,
61
+ flavor: "azure"
62
+ });
63
+
64
+ const result = buildWarpConfig(model);
65
+ expect(result).toBeUndefined();
66
+ });
67
+ });
68
+
69
+ describe("non-monorepo", () => {
70
+ it("should generate a self-contained config without polyfillSuffix", () => {
71
+ const model = createMockModel({
72
+ moduleKind: "esm",
73
+ isMonorepo: false
74
+ });
75
+
76
+ const result = buildWarpConfig(model);
77
+ expect(result).toBeDefined();
78
+ expect(result!.path).toBe("warp.config.yml");
79
+ expect(result!.content).not.toContain("extends:");
80
+ expect(result!.content).not.toContain("polyfillSuffix");
81
+ });
82
+
83
+ it("should include all target definitions", () => {
84
+ const model = createMockModel({
85
+ moduleKind: "esm",
86
+ isMonorepo: false
87
+ });
88
+
89
+ const result = buildWarpConfig(model);
90
+ expect(result).toBeDefined();
91
+ expect(result!.content).toContain("name: browser");
92
+ expect(result!.content).toContain("name: react-native");
93
+ expect(result!.content).toContain("name: esm");
94
+ expect(result!.content).toContain("name: commonjs");
95
+ });
96
+ });
97
+ });
@@ -9,8 +9,13 @@ export declare function buildPackageFile(model: RLCModel, { exports, dependencie
9
9
  content: string;
10
10
  } | undefined;
11
11
  /**
12
- * Automatically updates the package.json with correct paging and LRO dependencies for Azure SDK.
13
- * Also updates tshy.exports if provided.
12
+ * Automatically updates the package.json for an existing Azure SDK package.
13
+ * - Migrates `@azure/core-client` `@azure-rest/core-client` when found in dependencies.
14
+ * - Updates `@azure/core-lro` from `^2.x` to `^3.1.0`.
15
+ * - Adds LRO dependencies (`@azure/core-lro`, `@azure/abort-controller`) when the package has
16
+ * polling operations (for non-monorepo Azure packages).
17
+ * - Updates exports (tshy or warp) when `exports` is provided.
18
+ * - Updates `//metadata.constantPaths` when `clientContextPaths` is provided.
14
19
  */
15
20
  export declare function updatePackageFile(model: RLCModel, existingFilePathOrContent: string | Record<string, any>, { exports, clientContextPaths }?: PackageFileOptions): {
16
21
  path: string;
@@ -1,13 +1,15 @@
1
1
  import { RLCModel } from "../interfaces.js";
2
+ /**
3
+ * Builds config/tsconfig.test.browser.json — extends eng/tsconfigs/test.browser.json
4
+ */
2
5
  export declare function buildTestBrowserTsConfig(model: RLCModel): {
3
6
  path: string;
4
7
  content: string;
5
8
  } | undefined;
9
+ /**
10
+ * Builds config/tsconfig.test.node.json — extends eng/tsconfigs/test.node.json
11
+ */
6
12
  export declare function buildTestNodeTsConfig(model: RLCModel): {
7
13
  path: string;
8
14
  content: string;
9
15
  } | undefined;
10
- export declare function buildTestMainTsConfig(model: RLCModel): {
11
- path: string;
12
- content: string;
13
- } | undefined;
@@ -1,20 +1,52 @@
1
1
  import { RLCModel } from "../interfaces.js";
2
+ /**
3
+ * Builds the root tsconfig.json.
4
+ *
5
+ * For azureSdkForJs packages, emits project references pointing into the
6
+ * `config/` subfolder (following the eng/tsconfigs pattern).
7
+ */
2
8
  export declare function buildTsConfig(model: RLCModel): {
3
9
  path: string;
4
10
  content: string;
5
11
  };
6
- export declare function buildTsSrcConfig(): {
12
+ /**
13
+ * Builds config/tsconfig.src.esm.json — extends eng/tsconfigs/src.esm.json
14
+ */
15
+ export declare function buildTsSrcEsmConfig(): {
7
16
  path: string;
8
17
  content: string;
9
18
  };
10
- export declare function buildTsSampleConfig(model: RLCModel): {
19
+ /**
20
+ * Builds config/tsconfig.src.browser.json — extends eng/tsconfigs/src.browser.json
21
+ */
22
+ export declare function buildTsSrcBrowserConfig(): {
23
+ path: string;
24
+ content: string;
25
+ };
26
+ /**
27
+ * Builds config/tsconfig.src.react-native.json — extends eng/tsconfigs/src.react-native.json
28
+ */
29
+ export declare function buildTsSrcReactNativeConfig(): {
11
30
  path: string;
12
31
  content: string;
13
32
  };
14
- export declare function buildTsTestConfig(): {
33
+ /**
34
+ * Builds config/tsconfig.src.cjs.json — extends eng/tsconfigs/src.cjs.json
35
+ */
36
+ export declare function buildTsSrcCjsConfig(): {
37
+ path: string;
38
+ content: string;
39
+ };
40
+ /**
41
+ * Builds config/tsconfig.samples.json — extends eng/tsconfigs/samples.json
42
+ */
43
+ export declare function buildTsSampleConfig(model: RLCModel): {
15
44
  path: string;
16
45
  content: string;
17
46
  };
47
+ /**
48
+ * Builds config/tsconfig.snippets.json — extends eng/tsconfigs/snippets.json
49
+ */
18
50
  export declare function buildTsSnippetsConfig(): {
19
51
  path: string;
20
52
  content: string;
@@ -1,5 +1,5 @@
1
1
  import { RLCModel } from "../interfaces.js";
2
- export declare function buildVitestConfig(model: RLCModel, platform: "browser" | "node" | "esm"): {
2
+ export declare function buildVitestConfig(model: RLCModel, platform: "browser" | "node"): {
3
3
  path: string;
4
4
  content: string;
5
5
  } | undefined;
@@ -3,10 +3,14 @@ export interface WarpConfigOptions {
3
3
  /** Source-level exports, e.g. { ".": "./src/index.ts", "./models": "./src/models/index.ts" } */
4
4
  exports?: Record<string, string>;
5
5
  }
6
- export declare const WarpConfigTemplate = "# warp.config.yml \u2014 build configuration\n\nexports:\n{{exports}}\n\ntargets:\n - name: browser\n tsconfig: \"../../../tsconfig.src.browser.json\"\n polyfillSuffix: \"-browser\"\n\n - name: react-native\n tsconfig: \"../../../tsconfig.src.react-native.json\"\n polyfillSuffix: \"-react-native\"\n\n - name: esm\n condition: import\n tsconfig: \"../../../tsconfig.src.esm.json\"\n\n - name: commonjs\n condition: require\n tsconfig: \"../../../tsconfig.src.cjs.json\"\n";
6
+ /** Full inline warp config template. */
7
+ export declare const WarpConfigTemplate = "# warp.config.yml \u2014 build configuration\n\nexports:\n{{exports}}\n\ntargets:\n - name: browser\n tsconfig: \"./config/tsconfig.src.browser.json\"\n\n - name: react-native\n tsconfig: \"./config/tsconfig.src.react-native.json\"\n\n - name: esm\n condition: import\n tsconfig: \"./config/tsconfig.src.esm.json\"\n\n - name: commonjs\n condition: require\n tsconfig: \"./config/tsconfig.src.cjs.json\"\n moduleType: commonjs\n";
7
8
  /**
8
- * Builds a warp.config.yml file for Azure SDK monorepo packages.
9
- * Only generated when azureSdkForJs is true.
9
+ * Builds a self-contained warp.config.yml file.
10
+ *
11
+ * Emits a full inline config with all exports and targets.
12
+ * Polyfill resolution (browser/react-native file substitution) is handled
13
+ * via package.json `imports` subpath imports (#platform/*).
10
14
  */
11
15
  export declare function buildWarpConfig(model: RLCModel, { exports }?: WarpConfigOptions): {
12
16
  path: string;
@@ -34,6 +34,13 @@ export declare function getPackageCommonInfo(config: PackageCommonInfoConfig): {
34
34
  types: string;
35
35
  browser: string;
36
36
  "react-native": string;
37
+ imports: {
38
+ "#platform/*.js": {
39
+ browser: string;
40
+ "react-native": string;
41
+ default: string;
42
+ };
43
+ };
37
44
  exports: Record<string, any>;
38
45
  tshy?: undefined;
39
46
  name: string;
@@ -52,6 +59,7 @@ export declare function getPackageCommonInfo(config: PackageCommonInfoConfig): {
52
59
  main?: string | undefined;
53
60
  module?: string | undefined;
54
61
  types?: string | undefined;
62
+ imports?: undefined;
55
63
  exports?: undefined;
56
64
  name: string;
57
65
  version: string;