Skip to content

Commit d9855d8

Browse files
deyaaeldeenCopilotCopilot
authored
feat: emit warp config instead of tshy for Azure monorepo packages (#3802)
* feat: emit warp config instead of tshy for Azure monorepo packages Replace tshy build configuration with warp for packages generated with azureSdkForJs=true. This generates a warp.config.yml file and resolved dist-level exports in package.json instead of inline tshy config. Changes: - Add buildWarpConfig.ts to generate warp.config.yml with targets for workerd, browser, react-native, esm, and commonjs - Update packageCommon.ts to emit warp entrypoints (main, module, types, browser, react-native) and resolved exports for monorepo packages - Remove tshy from monorepo devDependencies - Update buildPackageFile.ts to handle warp exports in update path - Wire up warp config builder in typespec-ts emitter - Update unit tests for new warp behavior Non-monorepo (standalone/flavorless) packages continue to use tshy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: remove tshy from azureSdkForJs autorest test packages The PR's change to skip tshy devDependency for azureSdkForJs packages (using warp instead) wasn't reflected in the 5 committed autorest test package.json files that default azureSdkForJs to true. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: replace ts-node with tsx for integration tests to fix ESM compatibility Generated test packages have "type": "module" in their package.json, which triggers Node.js ESM loader when ts-node/register (v8) is used. The old ts-node/register only hooks into CJS require(), not the ESM loader, causing 'Unknown file extension .ts' errors. Replace ts-node with tsx for: - mocha --require hooks in integration/rlc/version-tolerance tests - standalone script execution (test commands, smoke test, copyFiles) Keep ts-node for unit tests since they don't import from ESM packages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: skip warp.config.yml generation if file already exists (#3806) * Initial plan * fix: don't overwrite existing warp.config.yml files Co-authored-by: deyaaeldeen <6074665+deyaaeldeen@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: deyaaeldeen <6074665+deyaaeldeen@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: deyaaeldeen <6074665+deyaaeldeen@users.noreply.github.com>
1 parent 254d030 commit d9855d8

14 files changed

Lines changed: 230 additions & 60 deletions

File tree

packages/autorest.typescript/package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "6.0.59",
44
"scripts": {
55
"build": "tsc -p . && npm run copyFiles",
6-
"build:test:browser:rlc": "tsc -p tsconfig.browser-test.json && ts-node test/commands/prepare-deps.ts --browser && webpack --config webpack.config.test.js --env mode=rlc",
7-
"build:test:browser": "tsc -p tsconfig.browser-test.json && ts-node test/commands/prepare-deps.ts --removal && webpack --config webpack.config.test.js --env mode=hlc",
8-
"check:tree": "ts-node ./test/commands/check-clean-tree.ts",
6+
"build:test:browser:rlc": "tsc -p tsconfig.browser-test.json && tsx test/commands/prepare-deps.ts --browser && webpack --config webpack.config.test.js --env mode=rlc",
7+
"build:test:browser": "tsc -p tsconfig.browser-test.json && tsx test/commands/prepare-deps.ts --removal && webpack --config webpack.config.test.js --env mode=hlc",
8+
"check:tree": "tsx ./test/commands/check-clean-tree.ts",
99
"format": "echo skipped",
1010
"pack": "npm pack 2>&1",
1111
"clean": "rimraf --glob test-browser test/**/node_modules",
@@ -22,26 +22,26 @@
2222
"integration-test:new": "npm-run-all start-test-server generate-and-test integration-test:alone stop-test-server",
2323
"integration-test:browser": "npm run build:test:browser && karma start karma.conf.js",
2424
"generate-and-test": "npm-run-all -s build generate-swaggers integration-test:alone integration-test:browser",
25-
"integration-test:alone": "mocha -r ts-node/register --timeout 2000 \"./test/integration/**/!(sampleTest).spec.ts\"",
25+
"integration-test:alone": "mocha --require tsx/cjs --timeout 2000 \"./test/integration/**/!(sampleTest).spec.ts\"",
2626
"rlc-integration-test": "npm run start-test-server:v2 & npm run rlc-generate-and-test && npm run stop-test-server",
2727
"rlc-integration-test:new": "npm-run-all start-test-server rlc-generate-and-test rlc-integration-test:alone stop-test-server",
2828
"rlc-integration-test:browser": "npm run build:test:browser:rlc && karma start karma.conf.js",
2929
"rlc-generate-and-test": "npm-run-all -s build rlc-generate-swaggers rlc-integration-test:alone rlc-integration-test:browser",
30-
"rlc-integration-test:alone": "ts-node test/commands/prepare-deps.ts && mocha -r ts-node/register --timeout 2000 \"./test/rlcIntegration/!(sampleTest).spec.ts\"",
31-
"start-test-server": "ts-node test/commands/start-server.ts",
30+
"rlc-integration-test:alone": "tsx test/commands/prepare-deps.ts && mocha --require tsx/cjs --timeout 2000 \"./test/rlcIntegration/!(sampleTest).spec.ts\"",
31+
"start-test-server": "tsx test/commands/start-server.ts",
3232
"start-test-server:v2": "autorest-testserver run --appendCoverage",
3333
"stop-test-server": "autorest-testserver stop",
3434
"debug": "node --inspect-brk ./dist/src/main.js",
35-
"generate-swaggers": "ts-node ./test/commands/test-swagger-gen.ts",
36-
"rlc-generate-swaggers": "ts-node ./test/commands/test-swagger-gen.ts -- rlc",
35+
"generate-swaggers": "tsx ./test/commands/test-swagger-gen.ts",
36+
"rlc-generate-swaggers": "tsx ./test/commands/test-swagger-gen.ts -- rlc",
3737
"validate-version-tolerance": "npm run start-test-server:v2 & npm run generate-version-tolerance && npm run generate-version-tolerance:tests && npm run test-version-tolerance && npm run stop-test-server",
38-
"generate-version-tolerance": "ts-node ./test/commands/version-tolerance.ts",
39-
"generate-version-tolerance:tests": "ts-node ./test/commands/version-tolerance.ts --test-gen",
38+
"generate-version-tolerance": "tsx ./test/commands/version-tolerance.ts",
39+
"generate-version-tolerance:tests": "tsx ./test/commands/version-tolerance.ts --test-gen",
4040
"regen-test-baselines": "npm run generate-swaggers && npm run rlc-generate-swaggers && npm run generate-version-tolerance && npm run smoke-test",
41-
"test-version-tolerance": "mocha -r ts-node/register --timeout 2000 \"./test/version-tolerance/**/!(sampleTest).spec.ts\"",
41+
"test-version-tolerance": "mocha --require tsx/cjs --timeout 2000 \"./test/version-tolerance/**/!(sampleTest).spec.ts\"",
4242
"clone:specs": "git clone -c core.longpaths=true https://github.com/Azure/azure-rest-api-specs.git ./.tmp/specs",
43-
"smoke-test": "ts-node ./test/commands/smoke-test.ts",
44-
"copyFiles": "ts-node ./src/utils/copyFiles.ts"
43+
"smoke-test": "tsx ./test/commands/smoke-test.ts",
44+
"copyFiles": "tsx ./src/utils/copyFiles.ts"
4545
},
4646
"browser": {
4747
"./test-browser/utils/stream-helpers.js": "./test-browser/utils/stream-helpers.browser.js",
@@ -112,6 +112,7 @@
112112
"puppeteer": "^22.2.0",
113113
"sinon": "^10.0.0",
114114
"source-map-loader": "^1.0.0",
115+
"tsx": "^4.19.0",
115116
"ts-node": "^8.5.2",
116117
"wait-port": "^0.2.6",
117118
"webpack": "^5.72.0",

packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"@azure-tools/test-recorder": "workspace:^",
5555
"@azure-tools/test-utils-vitest": "workspace:^",
5656
"@azure/dev-tool": "workspace:^",
57-
"tshy": "catalog:",
5857
"@azure/eslint-plugin-azure-sdk": "workspace:^",
5958
"@azure/identity": "catalog:internal",
6059
"@types/node": "catalog:",

packages/autorest.typescript/test/rlcIntegration/generated/httpInfrastructureRest/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"@azure-tools/test-recorder": "workspace:^",
5353
"@azure-tools/test-utils-vitest": "workspace:^",
5454
"@azure/dev-tool": "workspace:^",
55-
"tshy": "catalog:",
5655
"@azure/eslint-plugin-azure-sdk": "workspace:^",
5756
"@azure/identity": "catalog:internal",
5857
"@types/node": "catalog:",

packages/autorest.typescript/test/rlcIntegration/generated/multipleUrlParameters/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"@azure-tools/test-recorder": "workspace:^",
5353
"@azure-tools/test-utils-vitest": "workspace:^",
5454
"@azure/dev-tool": "workspace:^",
55-
"tshy": "catalog:",
5655
"@azure/eslint-plugin-azure-sdk": "workspace:^",
5756
"@azure/identity": "catalog:internal",
5857
"@types/node": "catalog:",

packages/autorest.typescript/test/rlcIntegration/generated/securityAADRest/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"@azure-tools/test-recorder": "workspace:^",
5353
"@azure-tools/test-utils-vitest": "workspace:^",
5454
"@azure/dev-tool": "workspace:^",
55-
"tshy": "catalog:",
5655
"@azure/eslint-plugin-azure-sdk": "workspace:^",
5756
"@azure/identity": "catalog:internal",
5857
"@types/node": "catalog:",

packages/autorest.typescript/test/rlcIntegration/generated/securityKeyRest/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"@azure-tools/test-recorder": "workspace:^",
5353
"@azure-tools/test-utils-vitest": "workspace:^",
5454
"@azure/dev-tool": "workspace:^",
55-
"tshy": "catalog:",
5655
"@azure/eslint-plugin-azure-sdk": "workspace:^",
5756
"@azure/identity": "catalog:internal",
5857
"@types/node": "catalog:",

packages/rlc-common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export * from "./metadata/buildApiExtractorConfig.js";
2727
export * from "./metadata/buildPackageFile.js";
2828
export * from "./metadata/buildRollupConfig.js";
2929
export * from "./metadata/buildTsConfig.js";
30+
export * from "./metadata/buildWarpConfig.js";
3031
export * from "./metadata/buildESLintConfig.js";
3132
export * from "./metadata/buildLicenseFile.js";
3233
export * from "./metadata/buildVitestConfig.js";

packages/rlc-common/src/metadata/buildPackageFile.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
} from "../helpers/packageUtil.js";
1111
import {
1212
PackageCommonInfoConfig,
13-
getTshyConfig
13+
getTshyConfig,
14+
resolveWarpExports
1415
} from "./packageJson/packageCommon.js";
1516
import { Project, SourceFile } from "ts-morph";
1617
import { RLCModel } from "../interfaces.js";
@@ -118,13 +119,19 @@ export function updatePackageFile(
118119
packageInfo = existingFilePathOrContent;
119120
}
120121

121-
// Update tshy.exports if exports are provided and tshy exists
122-
if (needsExportsUpdate && packageInfo.tshy) {
123-
const newTshy = getTshyConfig({
124-
exports,
125-
azureSdkForJs: model.options?.azureSdkForJs
126-
} as PackageCommonInfoConfig);
127-
packageInfo.tshy.exports = newTshy.exports;
122+
// Update exports based on build system (warp for monorepo, tshy for others)
123+
if (needsExportsUpdate) {
124+
if (model.options?.azureSdkForJs) {
125+
// Warp: update resolved exports in package.json
126+
packageInfo.exports = resolveWarpExports(exports);
127+
} else if (packageInfo.tshy) {
128+
// Tshy: update tshy.exports in package.json
129+
const newTshy = getTshyConfig({
130+
exports,
131+
azureSdkForJs: model.options?.azureSdkForJs
132+
} as PackageCommonInfoConfig);
133+
packageInfo.tshy.exports = newTshy.exports;
134+
}
128135
}
129136

130137
// Update LRO dependencies for Azure packages
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { RLCModel } from "../interfaces.js";
5+
import { isAzureMonorepoPackage } from "../helpers/packageUtil.js";
6+
7+
export interface WarpConfigOptions {
8+
/** Source-level exports, e.g. { ".": "./src/index.ts", "./models": "./src/models/index.ts" } */
9+
exports?: Record<string, string>;
10+
}
11+
12+
/**
13+
* Builds a warp.config.yml file for Azure SDK monorepo packages.
14+
* Only generated when azureSdkForJs is true.
15+
*/
16+
export function buildWarpConfig(
17+
model: RLCModel,
18+
{ exports }: WarpConfigOptions = {}
19+
) {
20+
if (!isAzureMonorepoPackage(model)) {
21+
return;
22+
}
23+
24+
if (model.options?.moduleKind !== "esm") {
25+
return;
26+
}
27+
28+
const allExports: Record<string, string> = {
29+
"./package.json": "./package.json",
30+
".": "./src/index.ts",
31+
...exports
32+
};
33+
34+
const lines: string[] = [];
35+
lines.push("# warp.config.yml — build configuration");
36+
lines.push("");
37+
lines.push("exports:");
38+
for (const [key, value] of Object.entries(allExports)) {
39+
lines.push(` ${JSON.stringify(key)}: ${JSON.stringify(value)}`);
40+
}
41+
lines.push("");
42+
lines.push("targets:");
43+
lines.push(" - name: browser");
44+
lines.push(' tsconfig: "../../../tsconfig.src.browser.json"');
45+
lines.push(' polyfillSuffix: "-browser"');
46+
lines.push("");
47+
lines.push(" - name: react-native");
48+
lines.push(' tsconfig: "../../../tsconfig.src.react-native.json"');
49+
lines.push(' polyfillSuffix: "-react-native"');
50+
lines.push("");
51+
lines.push(" - name: esm");
52+
lines.push(" condition: import");
53+
lines.push(' tsconfig: "../../../tsconfig.src.esm.json"');
54+
lines.push("");
55+
lines.push(" - name: commonjs");
56+
lines.push(" condition: require");
57+
lines.push(' tsconfig: "../../../tsconfig.src.cjs.json"');
58+
lines.push("");
59+
60+
return {
61+
path: "warp.config.yml",
62+
content: lines.join("\n")
63+
};
64+
}

packages/rlc-common/src/metadata/packageJson/buildAzureMonorepoPackage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export function getAzureMonorepoDependencies(config: AzureMonorepoInfoConfig) {
7373
"@azure-tools/test-recorder": "workspace:^",
7474
"@azure-tools/test-utils-vitest": "workspace:^",
7575
"@azure/dev-tool": "workspace:^",
76-
tshy: "catalog:",
7776
"@azure/eslint-plugin-azure-sdk": "workspace:^",
7877
"@azure/identity": "catalog:internal",
7978
"@types/node": "catalog:",

0 commit comments

Comments
 (0)