Skip to content

Commit 679311a

Browse files
deyaaeldeenCopilotJialinHuang803
authored
fix: Do not generate React Native build targets by default (#3943)
* fix: Do not generate React Native build targets by default Previously, the SDK generator always included React Native build targets (warp target, tsconfig reference, package.json exports/imports) for all generated packages. This caused CI failures in the azure-sdk-for-js monorepo because most packages don't need RN support and the RN build infrastructure isn't fully set up. This change: - Adds a new `generateReactNativeTarget` option (default: false) - Updates buildWarpConfig to conditionally include the react-native target - Updates buildTsConfig to conditionally include tsconfig.src.react-native.json - Updates package.json generation to conditionally include: - `react-native` top-level field - `react-native` condition in exports - `react-native` in imports subpath patterns - `react-native` in tshy esmDialects (for non-monorepo packages) - Updates tests to verify the new default behavior Packages that need React Native support can opt-in by setting `generateReactNativeTarget: true` in the emitter options. Fixes: Azure/azure-sdk-for-js#37XXX Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * chore: Regenerate test fixtures without react-native targets Updates test fixtures to reflect the new default behavior where react-native build targets are not generated unless explicitly enabled. - Updated RLC integration tests (removed react-native tsconfig references) - Updated smoke tests (removed react-native from package.json) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * chore: Regenerate all test fixtures without react-native targets Regenerated HLC integration tests, RLC integration tests, and version-tolerance tests with the new codegen that excludes react-native targets by default. Note: Smoke tests could not be regenerated locally due to environment limitations but were manually updated in the previous commit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat: remove react-native from HLC generator by default Add generateReactNativeTarget option to AutorestOptions interface and update packageFileGenerator.ts to conditionally include react-native targets based on this option (defaults to false). Regenerated all HLC test fixtures to remove react-native from package.json. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * chore: remove react-native from smoke and typespec test fixtures Manual update since regeneration scripts cannot run locally. These match the expected output from the generators with generateReactNativeTarget: false (default). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * chore: regenerate TypeSpec test fixtures with proper emitter Previous manual update missed react-native entries in sub-exports. Proper regeneration removes all react-native from all export paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: wire generateReactNativeTarget option through TypeSpec emitter The TypeSpec emitter checked option.generateReactNativeTarget but never wired it from emitter options. Add the option to EmitterOptions interface, RLCOptionsSchema, and extractRLCOptions so TypeSpec users can opt in via tspconfig.yaml. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Deyaa Eldeen <deyaaeldeen@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jialin Huang <jialinhuang@microsoft.com> Co-authored-by: JialinHuang803 <139532647+JialinHuang803@users.noreply.github.com>
1 parent cae57c5 commit 679311a

244 files changed

Lines changed: 344 additions & 1571 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/autorest.typescript/src/autorestSession.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export interface AutorestOptions {
4444
lenientModelDeduplication?: boolean;
4545
useLegacyLro?: boolean;
4646
flavor?: PackageFlavor;
47+
/**
48+
* When true, generates React Native build targets. Defaults to false.
49+
*/
50+
generateReactNativeTarget?: boolean;
4751
}
4852

4953
let host: AutorestExtensionHost;

packages/autorest.typescript/src/generators/static/packageFileGenerator.ts

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,26 @@ import { getAutorestOptions, getSession } from "../../autorestSession";
88
import { hasPollingOperations } from "../../restLevelClient/helpers/hasPollingOperations";
99
import { NameType, normalizeName } from "../../utils/nameUtils";
1010
import { getSecurityInfoFromModel } from "../../utils/schemaHelpers";
11-
import { WarpConfigTemplate } from "@azure-tools/rlc-common";
11+
12+
/** Warp config template for HLC packages (does not include react-native by default). */
13+
const WarpConfigTemplate = `# warp.config.yml — build configuration
14+
15+
exports:
16+
{{exports}}
17+
18+
targets:
19+
- name: browser
20+
tsconfig: "./config/tsconfig.src.browser.json"
21+
22+
- name: esm
23+
condition: import
24+
tsconfig: "./config/tsconfig.src.esm.json"
25+
26+
- name: commonjs
27+
condition: require
28+
tsconfig: "./config/tsconfig.src.cjs.json"
29+
moduleType: commonjs
30+
`;
1231

1332
export function generatePackageJson(
1433
project: Project,
@@ -62,7 +81,8 @@ function regularAutorestPackage(
6281
generateSample,
6382
coreHttpCompatMode,
6483
azureSdkForJs,
65-
isTestPackage
84+
isTestPackage,
85+
generateReactNativeTarget
6686
} = getAutorestOptions();
6787
const { model } = getSession();
6888
const { addCredentials } = getSecurityInfoFromModel(model.security);
@@ -163,33 +183,38 @@ function regularAutorestPackage(
163183
},
164184
autoPublish: true,
165185
browser: "./dist/browser/index.js",
166-
"react-native": "./dist/react-native/index.js",
167186
};
187+
if (generateReactNativeTarget) {
188+
packageInfo["react-native"] = "./dist/react-native/index.js";
189+
}
168190
if (azureOutputDirectory) {
169191
packageInfo.homepage = `https://github.com/Azure/azure-sdk-for-js/tree/main/${azureOutputDirectory}/README.md`;
170192
}
171193
if (azureSdkForJs) {
172194
// Azure monorepo packages use warp (via dev-tool run build-package) instead of tshy
195+
const exportsEntry: Record<string, any> = {
196+
browser: {
197+
types: "./dist/browser/index.d.ts",
198+
default: "./dist/browser/index.js"
199+
},
200+
import: {
201+
types: "./dist/esm/index.d.ts",
202+
default: "./dist/esm/index.js"
203+
},
204+
require: {
205+
types: "./dist/commonjs/index.d.ts",
206+
default: "./dist/commonjs/index.js"
207+
}
208+
};
209+
if (generateReactNativeTarget) {
210+
exportsEntry["react-native"] = {
211+
types: "./dist/react-native/index.d.ts",
212+
default: "./dist/react-native/index.js"
213+
};
214+
}
173215
packageInfo.exports = {
174216
"./package.json": "./package.json",
175-
".": {
176-
browser: {
177-
types: "./dist/browser/index.d.ts",
178-
default: "./dist/browser/index.js"
179-
},
180-
"react-native": {
181-
types: "./dist/react-native/index.d.ts",
182-
default: "./dist/react-native/index.js"
183-
},
184-
import: {
185-
types: "./dist/esm/index.d.ts",
186-
default: "./dist/esm/index.js"
187-
},
188-
require: {
189-
types: "./dist/commonjs/index.d.ts",
190-
default: "./dist/commonjs/index.js"
191-
}
192-
}
217+
".": exportsEntry
193218
};
194219
packageInfo.devDependencies["@azure/dev-tool"] = "workspace:^";
195220
packageInfo.devDependencies["cross-env"] = "catalog:";
@@ -210,13 +235,16 @@ function regularAutorestPackage(
210235
packageInfo.scripts["format"] = "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.{ts,cts,mts}\" \"test/**/*.{ts,cts,mts}\" \"*.{js,cjs,mjs,json}\" ";
211236
} else {
212237
// Non-Azure packages use tshy for building
238+
const esmDialects = generateReactNativeTarget
239+
? ["browser", "react-native"]
240+
: ["browser"];
213241
packageInfo.tshy = {
214242
exports: {
215243
"./package.json": "./package.json",
216244
".": "./src/index.ts"
217245
},
218246
dialects: ["esm", "commonjs"],
219-
esmDialects: ["browser", "react-native"],
247+
esmDialects,
220248
selfLink: false
221249
};
222250
packageInfo.devDependencies["@rollup/plugin-commonjs"] = "^24.0.0";

packages/autorest.typescript/src/restLevelClient/generateRestLevel.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ export async function generateRestLevelClient() {
138138
if (azureSdkForJs) {
139139
generateFileByBuilder(project, buildTsSrcEsmConfig, rlcModels);
140140
generateFileByBuilder(project, buildTsSrcBrowserConfig, rlcModels);
141-
generateFileByBuilder(project, buildTsSrcReactNativeConfig, rlcModels);
141+
if (rlcModels.options?.generateReactNativeTarget) {
142+
generateFileByBuilder(project, buildTsSrcReactNativeConfig, rlcModels);
143+
}
142144
generateFileByBuilder(project, buildTsSrcCjsConfig, rlcModels);
143145
if (generateSample) {
144146
// buildTsSampleConfig

packages/autorest.typescript/src/utils/autorestOptions.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,21 @@ export async function extractAutorestOptions(): Promise<AutorestOptions> {
8080
dependencyInfo,
8181
useLegacyLro,
8282
flavor,
83+
generateReactNativeTarget: await getGenerateReactNativeTarget(host)
8384
};
8485
}
8586

87+
async function getGenerateReactNativeTarget(
88+
host: AutorestExtensionHost
89+
): Promise<boolean> {
90+
const generateReactNativeTarget = await host.getValue(
91+
"generate-react-native-target"
92+
);
93+
return generateReactNativeTarget === null
94+
? false
95+
: Boolean(generateReactNativeTarget);
96+
}
97+
8698
async function getUseLegacyLro(host: AutorestExtensionHost): Promise<boolean> {
8799
const useLegacyLroOption = await host.getValue("use-legacy-lro");
88100
return useLegacyLroOption === null ? false : Boolean(useLegacyLroOption);

packages/autorest.typescript/test/integration/generated/additionalProperties/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@
7272
},
7373
"autoPublish": true,
7474
"browser": "./dist/browser/index.js",
75-
"react-native": "./dist/react-native/index.js",
7675
"tshy": {
7776
"exports": { "./package.json": "./package.json", ".": "./src/index.ts" },
7877
"dialects": ["esm", "commonjs"],
79-
"esmDialects": ["browser", "react-native"],
78+
"esmDialects": ["browser"],
8079
"selfLink": false
8180
}
8281
}

packages/autorest.typescript/test/integration/generated/appconfiguration/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,13 @@
5656
},
5757
"autoPublish": true,
5858
"browser": "./dist/browser/index.js",
59-
"react-native": "./dist/react-native/index.js",
6059
"exports": {
6160
"./package.json": "./package.json",
6261
".": {
6362
"browser": {
6463
"types": "./dist/browser/index.d.ts",
6564
"default": "./dist/browser/index.js"
6665
},
67-
"react-native": {
68-
"types": "./dist/react-native/index.d.ts",
69-
"default": "./dist/react-native/index.js"
70-
},
7166
"import": {
7267
"types": "./dist/esm/index.d.ts",
7368
"default": "./dist/esm/index.js"

packages/autorest.typescript/test/integration/generated/appconfiguration/warp.config.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ targets:
88
- name: browser
99
tsconfig: "./config/tsconfig.src.browser.json"
1010

11-
- name: react-native
12-
tsconfig: "./config/tsconfig.src.react-native.json"
13-
1411
- name: esm
1512
condition: import
1613
tsconfig: "./config/tsconfig.src.esm.json"

packages/autorest.typescript/test/integration/generated/appconfigurationexport/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,13 @@
5656
},
5757
"autoPublish": true,
5858
"browser": "./dist/browser/index.js",
59-
"react-native": "./dist/react-native/index.js",
6059
"exports": {
6160
"./package.json": "./package.json",
6261
".": {
6362
"browser": {
6463
"types": "./dist/browser/index.d.ts",
6564
"default": "./dist/browser/index.js"
6665
},
67-
"react-native": {
68-
"types": "./dist/react-native/index.d.ts",
69-
"default": "./dist/react-native/index.js"
70-
},
7166
"import": {
7267
"types": "./dist/esm/index.d.ts",
7368
"default": "./dist/esm/index.js"

packages/autorest.typescript/test/integration/generated/appconfigurationexport/warp.config.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ targets:
88
- name: browser
99
tsconfig: "./config/tsconfig.src.browser.json"
1010

11-
- name: react-native
12-
tsconfig: "./config/tsconfig.src.react-native.json"
13-
1411
- name: esm
1512
condition: import
1613
tsconfig: "./config/tsconfig.src.esm.json"

packages/autorest.typescript/test/integration/generated/arrayConstraints/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,13 @@
5555
},
5656
"autoPublish": true,
5757
"browser": "./dist/browser/index.js",
58-
"react-native": "./dist/react-native/index.js",
5958
"exports": {
6059
"./package.json": "./package.json",
6160
".": {
6261
"browser": {
6362
"types": "./dist/browser/index.d.ts",
6463
"default": "./dist/browser/index.js"
6564
},
66-
"react-native": {
67-
"types": "./dist/react-native/index.d.ts",
68-
"default": "./dist/react-native/index.js"
69-
},
7065
"import": {
7166
"types": "./dist/esm/index.d.ts",
7267
"default": "./dist/esm/index.js"

0 commit comments

Comments
 (0)