@azure-tools/rlc-common 0.53.1 → 0.53.2
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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/metadata/buildPackageFile.js +9 -7
- package/dist/metadata/buildPackageFile.js.map +1 -1
- package/dist/metadata/buildTsConfig.js +6 -4
- package/dist/metadata/buildTsConfig.js.map +1 -1
- package/dist/metadata/buildWarpConfig.js +29 -5
- package/dist/metadata/buildWarpConfig.js.map +1 -1
- package/dist/metadata/packageJson/packageCommon.js +40 -21
- package/dist/metadata/packageJson/packageCommon.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist-esm/interfaces.js.map +1 -1
- package/dist-esm/metadata/buildPackageFile.js +5 -3
- package/dist-esm/metadata/buildPackageFile.js.map +1 -1
- package/dist-esm/metadata/buildTsConfig.js +6 -4
- package/dist-esm/metadata/buildTsConfig.js.map +1 -1
- package/dist-esm/metadata/buildWarpConfig.js +28 -3
- package/dist-esm/metadata/buildWarpConfig.js.map +1 -1
- package/dist-esm/metadata/packageJson/packageCommon.js +40 -21
- package/dist-esm/metadata/packageJson/packageCommon.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/package.json +1 -1
- package/src/interfaces.ts +5 -0
- package/src/metadata/buildPackageFile.ts +8 -3
- package/src/metadata/buildTsConfig.ts +9 -4
- package/src/metadata/buildWarpConfig.ts +30 -3
- package/src/metadata/packageJson/packageCommon.ts +63 -22
- package/test/integration/mockHelper.ts +2 -0
- package/test/integration/packageJson.spec.ts +44 -3
- package/test/integration/warpConfig.spec.ts +38 -5
- package/types/interfaces.d.ts +5 -0
- package/types/metadata/buildWarpConfig.d.ts +3 -2
- package/types/metadata/packageJson/packageCommon.d.ts +6 -43
|
@@ -68,38 +68,51 @@ function getEsmEntrypointInformation(config) {
|
|
|
68
68
|
}
|
|
69
69
|
// Azure monorepo packages use warp instead of tshy
|
|
70
70
|
if (config.azureSdkForJs) {
|
|
71
|
-
|
|
71
|
+
const result = {
|
|
72
72
|
type: "module",
|
|
73
73
|
main: "./dist/commonjs/index.js",
|
|
74
74
|
module: "./dist/esm/index.js",
|
|
75
75
|
types: "./dist/commonjs/index.d.ts",
|
|
76
76
|
browser: "./dist/browser/index.js",
|
|
77
|
-
"react-native": "./dist/react-native/index.js",
|
|
78
77
|
imports: {
|
|
79
78
|
"#platform/*.js": {
|
|
80
79
|
browser: "./src/*-browser.mjs",
|
|
81
|
-
"react-native": "./src/*-react-native.mjs",
|
|
82
80
|
default: "./src/*.js"
|
|
83
81
|
}
|
|
84
82
|
},
|
|
85
|
-
exports: resolveWarpExports(config.exports)
|
|
83
|
+
exports: resolveWarpExports(config.exports, config.generateReactNativeTarget)
|
|
86
84
|
};
|
|
85
|
+
if (config.generateReactNativeTarget) {
|
|
86
|
+
result["react-native"] = "./dist/react-native/index.js";
|
|
87
|
+
result.imports["#platform/*.js"]["react-native"] = "./src/*-react-native.mjs";
|
|
88
|
+
// Reorder so react-native comes before default
|
|
89
|
+
const importsEntry = result.imports["#platform/*.js"];
|
|
90
|
+
result.imports["#platform/*.js"] = {
|
|
91
|
+
browser: importsEntry.browser,
|
|
92
|
+
"react-native": importsEntry["react-native"],
|
|
93
|
+
default: importsEntry.default
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
87
97
|
}
|
|
88
98
|
// Non-monorepo packages use tshy which manages polyfill resolution
|
|
89
99
|
// via esmDialects — do NOT add imports here.
|
|
90
|
-
|
|
100
|
+
const result = {
|
|
91
101
|
tshy: getTshyConfig(config),
|
|
92
102
|
type: "module",
|
|
93
|
-
browser: "./dist/browser/index.js"
|
|
94
|
-
"react-native": "./dist/react-native/index.js"
|
|
103
|
+
browser: "./dist/browser/index.js"
|
|
95
104
|
};
|
|
105
|
+
if (config.generateReactNativeTarget) {
|
|
106
|
+
result["react-native"] = "./dist/react-native/index.js";
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
96
109
|
}
|
|
97
110
|
/**
|
|
98
111
|
* Resolve source-level exports to dist-level exports for warp.
|
|
99
112
|
* Converts { ".": "./src/index.ts" } to the nested condition map with
|
|
100
113
|
* browser/import/require conditions pointing to dist/ paths.
|
|
101
114
|
*/
|
|
102
|
-
export function resolveWarpExports(sourceExports) {
|
|
115
|
+
export function resolveWarpExports(sourceExports, includeReactNative) {
|
|
103
116
|
const exports = {};
|
|
104
117
|
const allExports = {
|
|
105
118
|
"./package.json": "./package.json",
|
|
@@ -114,29 +127,35 @@ export function resolveWarpExports(sourceExports) {
|
|
|
114
127
|
}
|
|
115
128
|
// Convert source path to dist path: "./src/foo/index.ts" -> "foo/index"
|
|
116
129
|
const relPath = sourcePath.replace(/^\.\/src\//, "").replace(/\.ts$/, "");
|
|
117
|
-
|
|
130
|
+
const exportEntry = {
|
|
118
131
|
browser: {
|
|
119
132
|
types: `./dist/browser/${relPath}.d.ts`,
|
|
120
133
|
default: `./dist/browser/${relPath}.js`
|
|
121
|
-
}
|
|
122
|
-
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
if (includeReactNative) {
|
|
137
|
+
exportEntry["react-native"] = {
|
|
123
138
|
types: `./dist/react-native/${relPath}.d.ts`,
|
|
124
139
|
default: `./dist/react-native/${relPath}.js`
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
exportEntry["import"] = {
|
|
143
|
+
types: `./dist/esm/${relPath}.d.ts`,
|
|
144
|
+
default: `./dist/esm/${relPath}.js`
|
|
145
|
+
};
|
|
146
|
+
exportEntry["require"] = {
|
|
147
|
+
types: `./dist/commonjs/${relPath}.d.ts`,
|
|
148
|
+
default: `./dist/commonjs/${relPath}.js`
|
|
134
149
|
};
|
|
150
|
+
exports[subpath] = exportEntry;
|
|
135
151
|
}
|
|
136
152
|
return exports;
|
|
137
153
|
}
|
|
138
154
|
export function getTshyConfig(config) {
|
|
139
155
|
const { exports = {} } = config;
|
|
156
|
+
const esmDialects = config.generateReactNativeTarget
|
|
157
|
+
? ["browser", "react-native"]
|
|
158
|
+
: ["browser"];
|
|
140
159
|
const tshyConfig = {
|
|
141
160
|
exports: {
|
|
142
161
|
"./package.json": "./package.json",
|
|
@@ -144,7 +163,7 @@ export function getTshyConfig(config) {
|
|
|
144
163
|
...exports
|
|
145
164
|
},
|
|
146
165
|
dialects: ["esm", "commonjs"],
|
|
147
|
-
esmDialects
|
|
166
|
+
esmDialects,
|
|
148
167
|
selfLink: false
|
|
149
168
|
};
|
|
150
169
|
if (config.azureSdkForJs) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageCommon.js","sourceRoot":"","sources":["../../../src/metadata/packageJson/packageCommon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;
|
|
1
|
+
{"version":3,"file":"packageCommon.js","sourceRoot":"","sources":["../../../src/metadata/packageJson/packageCommon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAsBlC;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAA+B;IAClE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAE9C,OAAO;QACL,IAAI;QACJ,OAAO;QACP,WAAW;QACX,OAAO,EAAE;YACP,IAAI,EAAE,UAAU;SACjB;QACD,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,KAAK;QAClB,GAAG,wBAAwB,CAAC,MAAM,CAAC;KACpC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,KAAK,EAAE,QAAQ;CAChB,CAAC;AAEF,MAAM,UAAU,+BAA+B,CAC7C,MAA+B;IAE/B,OAAO;QACL,aAAa,EAAE,SAAS;QACxB,MAAM,EAA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AAE,OAAO,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAChC,MAAM,WAAW,GAAG,MAAM,CAAC,yBAAyB;QAClD,CAAC,CAAC,CAAC,SAAS,EAAE,cAAc,CAAC;QAC7B,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAChB,MAAM,UAAU,GAAwB;QACtC,OAAO,EAAE;YACP,gBAAgB,EAAE,gBAAgB;YAClC,GAAG,EAAE,gBAAgB;YACrB,GAAG,OAAO;SACX;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC;QAC7B,WAAW;QACX,QAAQ,EAAE,KAAK;KAChB,CAAC;IACF,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QACzB,UAAU,CAAC,SAAS,CAAC,GAAG,kCAAkC,CAAC;IAC7D,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,OAAO;QACL,KAAK,EACH,2EAA2E;QAC7E,aAAa,EACX,+DAA+D;QACjE,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,4CAA4C;QAClD,UAAU,EACR,kFAAkF;KACrF,CAAC;AACJ,CAAC"}
|
package/dist-esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@azure-tools/rlc-common","version":"0.53.
|
|
1
|
+
{"name":"@azure-tools/rlc-common","version":"0.53.2","description":"","type":"module","main":"dist/index.js","module":"dist-esm/index.js","exports":{".":{"types":"./types/index.d.ts","require":"./dist/index.js","import":"./dist-esm/index.js"}},"types":"./types/index.d.ts","scripts":{"lint":"eslint src --ext .ts --max-warnings=0","lint:fix":"eslint src --fix --ext .ts","format":"npm run -s prettier -- --write","check-format":"npm run prettier -- --check","prettier":"prettier --config ./.prettierrc \"src/**/*.ts\"","build":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js","build:cjs":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js","build:esm":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js","test":"npm run unit-test","unit-test":"vitest run"},"keywords":[],"author":"","license":"ISC","dependencies":{"handlebars":"^4.7.7","lodash":"^4.17.21","ts-morph":"^23.0.0"},"devDependencies":{"@types/fs-extra":"^8.1.0","@types/lodash":"^4.14.182","@typescript-eslint/eslint-plugin":"^8.18.0","@typescript-eslint/parser":"^8.18.0","chai":"^4.3.7","eslint-plugin-require-extensions":"0.1.3","fs-extra":"^10.0.0","prettier":"^3.1.0","rimraf":"^5.0.10","vitest":"^4.1.0","vite":"^6.0.0"},"bugs":{"url":"https://github.com/Azure/autorest.typescript/issues"},"homepage":"https://github.com/Azure/autorest.typescript/tree/main/packages/rlc-common/"}
|
package/package.json
CHANGED
package/src/interfaces.ts
CHANGED
|
@@ -285,6 +285,11 @@ export interface RLCOptions {
|
|
|
285
285
|
* where `unknown` in swagger mapped to `Record<string, unknown>`.
|
|
286
286
|
*/
|
|
287
287
|
treatUnknownAsRecord?: boolean;
|
|
288
|
+
/**
|
|
289
|
+
* When set to true, generates React Native build targets (tsconfig, warp target, package.json exports).
|
|
290
|
+
* Defaults to false. Only applicable when azureSdkForJs is true.
|
|
291
|
+
*/
|
|
292
|
+
generateReactNativeTarget?: boolean;
|
|
288
293
|
}
|
|
289
294
|
|
|
290
295
|
export interface ServiceInfo {
|
|
@@ -42,7 +42,8 @@ export function buildPackageFile(
|
|
|
42
42
|
exports,
|
|
43
43
|
azureArm: model.options?.azureArm,
|
|
44
44
|
isModularLibrary: model.options?.isModularLibrary ?? false,
|
|
45
|
-
azureSdkForJs: model.options?.azureSdkForJs
|
|
45
|
+
azureSdkForJs: model.options?.azureSdkForJs,
|
|
46
|
+
generateReactNativeTarget: model.options?.generateReactNativeTarget
|
|
46
47
|
};
|
|
47
48
|
|
|
48
49
|
let packageInfo: Record<string, any> = buildFlavorlessPackage(config);
|
|
@@ -158,12 +159,16 @@ export function updatePackageFile(
|
|
|
158
159
|
if (needsExportsUpdate) {
|
|
159
160
|
if (model.options?.azureSdkForJs) {
|
|
160
161
|
// Warp: update resolved exports in package.json
|
|
161
|
-
packageInfo.exports = resolveWarpExports(
|
|
162
|
+
packageInfo.exports = resolveWarpExports(
|
|
163
|
+
exports,
|
|
164
|
+
model.options?.generateReactNativeTarget
|
|
165
|
+
);
|
|
162
166
|
} else if (packageInfo.tshy) {
|
|
163
167
|
// Tshy: update tshy.exports in package.json
|
|
164
168
|
const newTshy = getTshyConfig({
|
|
165
169
|
exports,
|
|
166
|
-
azureSdkForJs: model.options?.azureSdkForJs
|
|
170
|
+
azureSdkForJs: model.options?.azureSdkForJs,
|
|
171
|
+
generateReactNativeTarget: model.options?.generateReactNativeTarget
|
|
167
172
|
} as PackageCommonInfoConfig);
|
|
168
173
|
packageInfo.tshy.exports = newTshy.exports;
|
|
169
174
|
}
|
|
@@ -12,7 +12,8 @@ import { RLCModel } from "../interfaces.js";
|
|
|
12
12
|
*/
|
|
13
13
|
export function buildTsConfig(model: RLCModel) {
|
|
14
14
|
const { packageDetails, azureSdkForJs } = model.options || {};
|
|
15
|
-
const { generateTest, generateSample } =
|
|
15
|
+
const { generateTest, generateSample, generateReactNativeTarget } =
|
|
16
|
+
model.options || {};
|
|
16
17
|
const clientPackageName = packageDetails?.name ?? "";
|
|
17
18
|
const project = new Project();
|
|
18
19
|
|
|
@@ -21,11 +22,15 @@ export function buildTsConfig(model: RLCModel) {
|
|
|
21
22
|
if (azureSdkForJs) {
|
|
22
23
|
const references: { path: string }[] = [
|
|
23
24
|
{ path: "./config/tsconfig.src.esm.json" },
|
|
24
|
-
{ path: "./config/tsconfig.src.browser.json" }
|
|
25
|
-
{ path: "./config/tsconfig.src.react-native.json" },
|
|
26
|
-
{ path: "./config/tsconfig.src.cjs.json" }
|
|
25
|
+
{ path: "./config/tsconfig.src.browser.json" }
|
|
27
26
|
];
|
|
28
27
|
|
|
28
|
+
if (generateReactNativeTarget) {
|
|
29
|
+
references.push({ path: "./config/tsconfig.src.react-native.json" });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
references.push({ path: "./config/tsconfig.src.cjs.json" });
|
|
33
|
+
|
|
29
34
|
if (generateTest) {
|
|
30
35
|
references.push(
|
|
31
36
|
{ path: "./config/tsconfig.test.node.json" },
|
|
@@ -14,8 +14,8 @@ const BASE_EXPORTS: Record<string, string> = {
|
|
|
14
14
|
".": "./src/index.ts"
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
/** Full inline warp config template. */
|
|
18
|
-
|
|
17
|
+
/** Full inline warp config template with react-native target. */
|
|
18
|
+
const WarpConfigTemplateWithReactNative = `# warp.config.yml — build configuration
|
|
19
19
|
|
|
20
20
|
exports:
|
|
21
21
|
{{exports}}
|
|
@@ -37,12 +37,35 @@ targets:
|
|
|
37
37
|
moduleType: commonjs
|
|
38
38
|
`;
|
|
39
39
|
|
|
40
|
+
/** Warp config template without react-native target (default). */
|
|
41
|
+
const WarpConfigTemplateDefault = `# warp.config.yml — build configuration
|
|
42
|
+
|
|
43
|
+
exports:
|
|
44
|
+
{{exports}}
|
|
45
|
+
|
|
46
|
+
targets:
|
|
47
|
+
- name: browser
|
|
48
|
+
tsconfig: "./config/tsconfig.src.browser.json"
|
|
49
|
+
|
|
50
|
+
- name: esm
|
|
51
|
+
condition: import
|
|
52
|
+
tsconfig: "./config/tsconfig.src.esm.json"
|
|
53
|
+
|
|
54
|
+
- name: commonjs
|
|
55
|
+
condition: require
|
|
56
|
+
tsconfig: "./config/tsconfig.src.cjs.json"
|
|
57
|
+
moduleType: commonjs
|
|
58
|
+
`;
|
|
59
|
+
|
|
40
60
|
/**
|
|
41
61
|
* Builds a self-contained warp.config.yml file.
|
|
42
62
|
*
|
|
43
63
|
* Emits a full inline config with all exports and targets.
|
|
44
64
|
* Polyfill resolution (browser/react-native file substitution) is handled
|
|
45
65
|
* via package.json `imports` subpath imports (#platform/*).
|
|
66
|
+
*
|
|
67
|
+
* By default, react-native target is NOT included. Set `generateReactNativeTarget: true`
|
|
68
|
+
* in options to include it.
|
|
46
69
|
*/
|
|
47
70
|
export function buildWarpConfig(
|
|
48
71
|
model: RLCModel,
|
|
@@ -61,7 +84,11 @@ export function buildWarpConfig(
|
|
|
61
84
|
.map(([key, value]) => ` ${JSON.stringify(key)}: ${JSON.stringify(value)}`)
|
|
62
85
|
.join("\n");
|
|
63
86
|
|
|
64
|
-
const
|
|
87
|
+
const template = model.options?.generateReactNativeTarget
|
|
88
|
+
? WarpConfigTemplateWithReactNative
|
|
89
|
+
: WarpConfigTemplateDefault;
|
|
90
|
+
|
|
91
|
+
const content = template.replace("{{exports}}", exportsContent);
|
|
65
92
|
|
|
66
93
|
return { path: "warp.config.yml", content };
|
|
67
94
|
}
|
|
@@ -14,6 +14,11 @@ export interface PackageCommonInfoConfig {
|
|
|
14
14
|
azureArm?: boolean;
|
|
15
15
|
isModularLibrary?: boolean;
|
|
16
16
|
azureSdkForJs?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* When true, generates React Native build targets (dist/react-native, exports condition).
|
|
19
|
+
* Defaults to false. Only applicable when azureSdkForJs is true.
|
|
20
|
+
*/
|
|
21
|
+
generateReactNativeTarget?: boolean;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
/**
|
|
@@ -106,32 +111,57 @@ function getEsmEntrypointInformation(config: PackageCommonInfoConfig) {
|
|
|
106
111
|
|
|
107
112
|
// Azure monorepo packages use warp instead of tshy
|
|
108
113
|
if (config.azureSdkForJs) {
|
|
109
|
-
|
|
114
|
+
const result: Record<string, any> = {
|
|
110
115
|
type: "module",
|
|
111
116
|
main: "./dist/commonjs/index.js",
|
|
112
117
|
module: "./dist/esm/index.js",
|
|
113
118
|
types: "./dist/commonjs/index.d.ts",
|
|
114
119
|
browser: "./dist/browser/index.js",
|
|
115
|
-
"react-native": "./dist/react-native/index.js",
|
|
116
120
|
imports: {
|
|
117
121
|
"#platform/*.js": {
|
|
118
122
|
browser: "./src/*-browser.mjs",
|
|
119
|
-
"react-native": "./src/*-react-native.mjs",
|
|
120
123
|
default: "./src/*.js"
|
|
121
|
-
}
|
|
124
|
+
} as Record<string, string>
|
|
122
125
|
},
|
|
123
|
-
exports: resolveWarpExports(
|
|
126
|
+
exports: resolveWarpExports(
|
|
127
|
+
config.exports,
|
|
128
|
+
config.generateReactNativeTarget
|
|
129
|
+
)
|
|
124
130
|
};
|
|
131
|
+
|
|
132
|
+
if (config.generateReactNativeTarget) {
|
|
133
|
+
result["react-native"] = "./dist/react-native/index.js";
|
|
134
|
+
(result.imports["#platform/*.js"] as Record<string, string>)[
|
|
135
|
+
"react-native"
|
|
136
|
+
] = "./src/*-react-native.mjs";
|
|
137
|
+
// Reorder so react-native comes before default
|
|
138
|
+
const importsEntry = result.imports["#platform/*.js"] as Record<
|
|
139
|
+
string,
|
|
140
|
+
string
|
|
141
|
+
>;
|
|
142
|
+
result.imports["#platform/*.js"] = {
|
|
143
|
+
browser: importsEntry.browser,
|
|
144
|
+
"react-native": importsEntry["react-native"],
|
|
145
|
+
default: importsEntry.default
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return result;
|
|
125
150
|
}
|
|
126
151
|
|
|
127
152
|
// Non-monorepo packages use tshy which manages polyfill resolution
|
|
128
153
|
// via esmDialects — do NOT add imports here.
|
|
129
|
-
|
|
154
|
+
const result: Record<string, any> = {
|
|
130
155
|
tshy: getTshyConfig(config),
|
|
131
156
|
type: "module",
|
|
132
|
-
browser: "./dist/browser/index.js"
|
|
133
|
-
"react-native": "./dist/react-native/index.js"
|
|
157
|
+
browser: "./dist/browser/index.js"
|
|
134
158
|
};
|
|
159
|
+
|
|
160
|
+
if (config.generateReactNativeTarget) {
|
|
161
|
+
result["react-native"] = "./dist/react-native/index.js";
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return result;
|
|
135
165
|
}
|
|
136
166
|
|
|
137
167
|
/**
|
|
@@ -140,7 +170,8 @@ function getEsmEntrypointInformation(config: PackageCommonInfoConfig) {
|
|
|
140
170
|
* browser/import/require conditions pointing to dist/ paths.
|
|
141
171
|
*/
|
|
142
172
|
export function resolveWarpExports(
|
|
143
|
-
sourceExports?: Record<string, any
|
|
173
|
+
sourceExports?: Record<string, any>,
|
|
174
|
+
includeReactNative?: boolean
|
|
144
175
|
): Record<string, any> {
|
|
145
176
|
const exports: Record<string, any> = {};
|
|
146
177
|
const allExports: Record<string, string> = {
|
|
@@ -159,24 +190,31 @@ export function resolveWarpExports(
|
|
|
159
190
|
// Convert source path to dist path: "./src/foo/index.ts" -> "foo/index"
|
|
160
191
|
const relPath = sourcePath.replace(/^\.\/src\//, "").replace(/\.ts$/, "");
|
|
161
192
|
|
|
162
|
-
|
|
193
|
+
const exportEntry: Record<string, any> = {
|
|
163
194
|
browser: {
|
|
164
195
|
types: `./dist/browser/${relPath}.d.ts`,
|
|
165
196
|
default: `./dist/browser/${relPath}.js`
|
|
166
|
-
}
|
|
167
|
-
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
if (includeReactNative) {
|
|
201
|
+
exportEntry["react-native"] = {
|
|
168
202
|
types: `./dist/react-native/${relPath}.d.ts`,
|
|
169
203
|
default: `./dist/react-native/${relPath}.js`
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
exportEntry["import"] = {
|
|
208
|
+
types: `./dist/esm/${relPath}.d.ts`,
|
|
209
|
+
default: `./dist/esm/${relPath}.js`
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
exportEntry["require"] = {
|
|
213
|
+
types: `./dist/commonjs/${relPath}.d.ts`,
|
|
214
|
+
default: `./dist/commonjs/${relPath}.js`
|
|
179
215
|
};
|
|
216
|
+
|
|
217
|
+
exports[subpath] = exportEntry;
|
|
180
218
|
}
|
|
181
219
|
|
|
182
220
|
return exports;
|
|
@@ -184,6 +222,9 @@ export function resolveWarpExports(
|
|
|
184
222
|
|
|
185
223
|
export function getTshyConfig(config: PackageCommonInfoConfig) {
|
|
186
224
|
const { exports = {} } = config;
|
|
225
|
+
const esmDialects = config.generateReactNativeTarget
|
|
226
|
+
? ["browser", "react-native"]
|
|
227
|
+
: ["browser"];
|
|
187
228
|
const tshyConfig: Record<string, any> = {
|
|
188
229
|
exports: {
|
|
189
230
|
"./package.json": "./package.json",
|
|
@@ -191,7 +232,7 @@ export function getTshyConfig(config: PackageCommonInfoConfig) {
|
|
|
191
232
|
...exports
|
|
192
233
|
},
|
|
193
234
|
dialects: ["esm", "commonjs"],
|
|
194
|
-
esmDialects
|
|
235
|
+
esmDialects,
|
|
195
236
|
selfLink: false
|
|
196
237
|
};
|
|
197
238
|
if (config.azureSdkForJs) {
|
|
@@ -24,6 +24,7 @@ export type TestModelConfig = {
|
|
|
24
24
|
hasSubscriptionId?: boolean;
|
|
25
25
|
addCredentials?: boolean;
|
|
26
26
|
scopeName?: string;
|
|
27
|
+
generateReactNativeTarget?: boolean;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
export function createMockModel(config: TestModelConfig = {}): RLCModel {
|
|
@@ -57,6 +58,7 @@ export function createMockModel(config: TestModelConfig = {}): RLCModel {
|
|
|
57
58
|
azureArm: config.azureArm ?? false,
|
|
58
59
|
hasSubscriptionId: config.hasSubscriptionId ?? false,
|
|
59
60
|
addCredentials: config.addCredentials ?? false,
|
|
61
|
+
generateReactNativeTarget: config.generateReactNativeTarget ?? false
|
|
60
62
|
},
|
|
61
63
|
helperDetails: {
|
|
62
64
|
hasPaging: config.hasPaging ?? false,
|
|
@@ -253,7 +253,7 @@ describe("Package file generation", () => {
|
|
|
253
253
|
);
|
|
254
254
|
});
|
|
255
255
|
|
|
256
|
-
it("[esm] should include correct entrypoints", () => {
|
|
256
|
+
it("[esm] should include correct entrypoints (without react-native by default)", () => {
|
|
257
257
|
const model = createMockModel({
|
|
258
258
|
...baseConfig,
|
|
259
259
|
withSamples: true,
|
|
@@ -275,10 +275,13 @@ describe("Package file generation", () => {
|
|
|
275
275
|
"browser",
|
|
276
276
|
"./dist/browser/index.js"
|
|
277
277
|
);
|
|
278
|
+
// Default: no react-native entrypoint
|
|
279
|
+
expect(packageFile).to.not.have.property("react-native");
|
|
278
280
|
expect(packageFile).to.have.property("exports");
|
|
279
281
|
expect(packageFile.exports["./package.json"]).to.equal("./package.json");
|
|
280
282
|
expect(packageFile.exports["."]).to.have.property("browser");
|
|
281
|
-
|
|
283
|
+
// Default: no react-native in exports
|
|
284
|
+
expect(packageFile.exports["."]).to.not.have.property("react-native");
|
|
282
285
|
expect(packageFile.exports["."]).to.have.property("import");
|
|
283
286
|
expect(packageFile.exports["."]).to.have.property("require");
|
|
284
287
|
expect(packageFile.exports["."]["import"]).to.deep.equal({
|
|
@@ -287,6 +290,27 @@ describe("Package file generation", () => {
|
|
|
287
290
|
});
|
|
288
291
|
});
|
|
289
292
|
|
|
293
|
+
it("[esm] should include react-native entrypoints when generateReactNativeTarget is true", () => {
|
|
294
|
+
const model = createMockModel({
|
|
295
|
+
...baseConfig,
|
|
296
|
+
withSamples: true,
|
|
297
|
+
moduleKind: "esm",
|
|
298
|
+
generateReactNativeTarget: true
|
|
299
|
+
});
|
|
300
|
+
const packageFileContent = buildPackageFile(model);
|
|
301
|
+
const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
|
|
302
|
+
|
|
303
|
+
expect(packageFile).to.have.property(
|
|
304
|
+
"react-native",
|
|
305
|
+
"./dist/react-native/index.js"
|
|
306
|
+
);
|
|
307
|
+
expect(packageFile.exports["."]).to.have.property("react-native");
|
|
308
|
+
expect(packageFile.exports["."]["react-native"]).to.deep.equal({
|
|
309
|
+
types: "./dist/react-native/index.d.ts",
|
|
310
|
+
default: "./dist/react-native/index.js"
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
290
314
|
it("[esm] should include correct devDependencies", () => {
|
|
291
315
|
const model = createMockModel({
|
|
292
316
|
...baseConfig,
|
|
@@ -461,7 +485,7 @@ describe("Package file generation", () => {
|
|
|
461
485
|
);
|
|
462
486
|
});
|
|
463
487
|
|
|
464
|
-
it("should include browser
|
|
488
|
+
it("should include browser but not react-native entrypoints by default", () => {
|
|
465
489
|
const model = createMockModel({
|
|
466
490
|
...baseConfig,
|
|
467
491
|
azureArm: true,
|
|
@@ -470,6 +494,23 @@ describe("Package file generation", () => {
|
|
|
470
494
|
const packageFileContent = buildPackageFile(model);
|
|
471
495
|
const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
|
|
472
496
|
|
|
497
|
+
expect(packageFile).to.have.property(
|
|
498
|
+
"browser", "./dist/browser/index.js",
|
|
499
|
+
);
|
|
500
|
+
// Default: no react-native entrypoint
|
|
501
|
+
expect(packageFile).to.not.have.property("react-native");
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it("should include react-native entrypoint when generateReactNativeTarget is true", () => {
|
|
505
|
+
const model = createMockModel({
|
|
506
|
+
...baseConfig,
|
|
507
|
+
azureArm: true,
|
|
508
|
+
isModularLibrary: true,
|
|
509
|
+
generateReactNativeTarget: true
|
|
510
|
+
});
|
|
511
|
+
const packageFileContent = buildPackageFile(model);
|
|
512
|
+
const packageFile = JSON.parse(packageFileContent?.content ?? "{}");
|
|
513
|
+
|
|
473
514
|
expect(packageFile).to.have.property(
|
|
474
515
|
"browser", "./dist/browser/index.js",
|
|
475
516
|
);
|
|
@@ -8,7 +8,7 @@ import { createMockModel } from "./mockHelper.js";
|
|
|
8
8
|
|
|
9
9
|
describe("warp.config.yml generation", () => {
|
|
10
10
|
describe("azure monorepo", () => {
|
|
11
|
-
it("should generate a self-contained config without polyfillSuffix", () => {
|
|
11
|
+
it("should generate a self-contained config without polyfillSuffix and without react-native by default", () => {
|
|
12
12
|
const model = createMockModel({
|
|
13
13
|
moduleKind: "esm",
|
|
14
14
|
isMonorepo: true,
|
|
@@ -22,9 +22,9 @@ describe("warp.config.yml generation", () => {
|
|
|
22
22
|
// polyfillSuffix is no longer used — polyfill resolution is handled
|
|
23
23
|
// via package.json subpath imports instead.
|
|
24
24
|
expect(result!.content).not.toContain("polyfillSuffix");
|
|
25
|
-
//
|
|
25
|
+
// Default: three targets without react-native
|
|
26
26
|
expect(result!.content).toContain("name: browser");
|
|
27
|
-
expect(result!.content).toContain("name: react-native");
|
|
27
|
+
expect(result!.content).not.toContain("name: react-native");
|
|
28
28
|
expect(result!.content).toContain("name: esm");
|
|
29
29
|
expect(result!.content).toContain("name: commonjs");
|
|
30
30
|
expect(result!.content).toContain("tsconfig:");
|
|
@@ -33,6 +33,22 @@ describe("warp.config.yml generation", () => {
|
|
|
33
33
|
expect(result!.content).toContain('"."');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
it("should include react-native target when generateReactNativeTarget is true", () => {
|
|
37
|
+
const model = createMockModel({
|
|
38
|
+
moduleKind: "esm",
|
|
39
|
+
isMonorepo: true,
|
|
40
|
+
flavor: "azure",
|
|
41
|
+
generateReactNativeTarget: true
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const result = buildWarpConfig(model);
|
|
45
|
+
expect(result).toBeDefined();
|
|
46
|
+
expect(result!.content).toContain("name: browser");
|
|
47
|
+
expect(result!.content).toContain("name: react-native");
|
|
48
|
+
expect(result!.content).toContain("name: esm");
|
|
49
|
+
expect(result!.content).toContain("name: commonjs");
|
|
50
|
+
});
|
|
51
|
+
|
|
36
52
|
it("should include custom exports alongside base exports", () => {
|
|
37
53
|
const model = createMockModel({
|
|
38
54
|
moduleKind: "esm",
|
|
@@ -67,7 +83,7 @@ describe("warp.config.yml generation", () => {
|
|
|
67
83
|
});
|
|
68
84
|
|
|
69
85
|
describe("non-monorepo", () => {
|
|
70
|
-
it("should generate a self-contained config without polyfillSuffix", () => {
|
|
86
|
+
it("should generate a self-contained config without polyfillSuffix and without react-native by default", () => {
|
|
71
87
|
const model = createMockModel({
|
|
72
88
|
moduleKind: "esm",
|
|
73
89
|
isMonorepo: false
|
|
@@ -78,14 +94,31 @@ describe("warp.config.yml generation", () => {
|
|
|
78
94
|
expect(result!.path).toBe("warp.config.yml");
|
|
79
95
|
expect(result!.content).not.toContain("extends:");
|
|
80
96
|
expect(result!.content).not.toContain("polyfillSuffix");
|
|
97
|
+
// Default: no react-native target
|
|
98
|
+
expect(result!.content).not.toContain("name: react-native");
|
|
81
99
|
});
|
|
82
100
|
|
|
83
|
-
it("should include
|
|
101
|
+
it("should include three targets by default (browser, esm, commonjs)", () => {
|
|
84
102
|
const model = createMockModel({
|
|
85
103
|
moduleKind: "esm",
|
|
86
104
|
isMonorepo: false
|
|
87
105
|
});
|
|
88
106
|
|
|
107
|
+
const result = buildWarpConfig(model);
|
|
108
|
+
expect(result).toBeDefined();
|
|
109
|
+
expect(result!.content).toContain("name: browser");
|
|
110
|
+
expect(result!.content).toContain("name: esm");
|
|
111
|
+
expect(result!.content).toContain("name: commonjs");
|
|
112
|
+
expect(result!.content).not.toContain("name: react-native");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("should include all four targets when generateReactNativeTarget is true", () => {
|
|
116
|
+
const model = createMockModel({
|
|
117
|
+
moduleKind: "esm",
|
|
118
|
+
isMonorepo: false,
|
|
119
|
+
generateReactNativeTarget: true
|
|
120
|
+
});
|
|
121
|
+
|
|
89
122
|
const result = buildWarpConfig(model);
|
|
90
123
|
expect(result).toBeDefined();
|
|
91
124
|
expect(result!.content).toContain("name: browser");
|
package/types/interfaces.d.ts
CHANGED
|
@@ -238,6 +238,11 @@ export interface RLCOptions {
|
|
|
238
238
|
* where `unknown` in swagger mapped to `Record<string, unknown>`.
|
|
239
239
|
*/
|
|
240
240
|
treatUnknownAsRecord?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* When set to true, generates React Native build targets (tsconfig, warp target, package.json exports).
|
|
243
|
+
* Defaults to false. Only applicable when azureSdkForJs is true.
|
|
244
|
+
*/
|
|
245
|
+
generateReactNativeTarget?: boolean;
|
|
241
246
|
}
|
|
242
247
|
export interface ServiceInfo {
|
|
243
248
|
title?: string;
|
|
@@ -3,14 +3,15 @@ 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
|
-
/** 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";
|
|
8
6
|
/**
|
|
9
7
|
* Builds a self-contained warp.config.yml file.
|
|
10
8
|
*
|
|
11
9
|
* Emits a full inline config with all exports and targets.
|
|
12
10
|
* Polyfill resolution (browser/react-native file substitution) is handled
|
|
13
11
|
* via package.json `imports` subpath imports (#platform/*).
|
|
12
|
+
*
|
|
13
|
+
* By default, react-native target is NOT included. Set `generateReactNativeTarget: true`
|
|
14
|
+
* in options to include it.
|
|
14
15
|
*/
|
|
15
16
|
export declare function buildWarpConfig(model: RLCModel, { exports }?: WarpConfigOptions): {
|
|
16
17
|
path: string;
|