Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions packages/autorest.typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "6.0.59",
"scripts": {
"build": "tsc -p . && npm run copyFiles",
"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",
"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",
"check:tree": "ts-node ./test/commands/check-clean-tree.ts",
"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",
"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",
"check:tree": "tsx ./test/commands/check-clean-tree.ts",
"format": "echo skipped",
"pack": "npm pack 2>&1",
"clean": "rimraf --glob test-browser test/**/node_modules",
Expand All @@ -22,26 +22,26 @@
"integration-test:new": "npm-run-all start-test-server generate-and-test integration-test:alone stop-test-server",
"integration-test:browser": "npm run build:test:browser && karma start karma.conf.js",
"generate-and-test": "npm-run-all -s build generate-swaggers integration-test:alone integration-test:browser",
"integration-test:alone": "mocha -r ts-node/register --timeout 2000 \"./test/integration/**/!(sampleTest).spec.ts\"",
"integration-test:alone": "mocha --require tsx/cjs --timeout 2000 \"./test/integration/**/!(sampleTest).spec.ts\"",
"rlc-integration-test": "npm run start-test-server:v2 & npm run rlc-generate-and-test && npm run stop-test-server",
"rlc-integration-test:new": "npm-run-all start-test-server rlc-generate-and-test rlc-integration-test:alone stop-test-server",
"rlc-integration-test:browser": "npm run build:test:browser:rlc && karma start karma.conf.js",
"rlc-generate-and-test": "npm-run-all -s build rlc-generate-swaggers rlc-integration-test:alone rlc-integration-test:browser",
"rlc-integration-test:alone": "ts-node test/commands/prepare-deps.ts && mocha -r ts-node/register --timeout 2000 \"./test/rlcIntegration/!(sampleTest).spec.ts\"",
"start-test-server": "ts-node test/commands/start-server.ts",
"rlc-integration-test:alone": "tsx test/commands/prepare-deps.ts && mocha --require tsx/cjs --timeout 2000 \"./test/rlcIntegration/!(sampleTest).spec.ts\"",
"start-test-server": "tsx test/commands/start-server.ts",
"start-test-server:v2": "autorest-testserver run --appendCoverage",
"stop-test-server": "autorest-testserver stop",
"debug": "node --inspect-brk ./dist/src/main.js",
"generate-swaggers": "ts-node ./test/commands/test-swagger-gen.ts",
"rlc-generate-swaggers": "ts-node ./test/commands/test-swagger-gen.ts -- rlc",
"generate-swaggers": "tsx ./test/commands/test-swagger-gen.ts",
"rlc-generate-swaggers": "tsx ./test/commands/test-swagger-gen.ts -- rlc",
"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",
"generate-version-tolerance": "ts-node ./test/commands/version-tolerance.ts",
"generate-version-tolerance:tests": "ts-node ./test/commands/version-tolerance.ts --test-gen",
"generate-version-tolerance": "tsx ./test/commands/version-tolerance.ts",
"generate-version-tolerance:tests": "tsx ./test/commands/version-tolerance.ts --test-gen",
"regen-test-baselines": "npm run generate-swaggers && npm run rlc-generate-swaggers && npm run generate-version-tolerance && npm run smoke-test",
"test-version-tolerance": "mocha -r ts-node/register --timeout 2000 \"./test/version-tolerance/**/!(sampleTest).spec.ts\"",
"test-version-tolerance": "mocha --require tsx/cjs --timeout 2000 \"./test/version-tolerance/**/!(sampleTest).spec.ts\"",
"clone:specs": "git clone -c core.longpaths=true https://github.com/Azure/azure-rest-api-specs.git ./.tmp/specs",
"smoke-test": "ts-node ./test/commands/smoke-test.ts",
"copyFiles": "ts-node ./src/utils/copyFiles.ts"
"smoke-test": "tsx ./test/commands/smoke-test.ts",
"copyFiles": "tsx ./src/utils/copyFiles.ts"
},
"browser": {
"./test-browser/utils/stream-helpers.js": "./test-browser/utils/stream-helpers.browser.js",
Expand Down Expand Up @@ -112,6 +112,7 @@
"puppeteer": "^22.2.0",
"sinon": "^10.0.0",
"source-map-loader": "^1.0.0",
"tsx": "^4.19.0",
"ts-node": "^8.5.2",
"wait-port": "^0.2.6",
"webpack": "^5.72.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"@azure-tools/test-recorder": "workspace:^",
"@azure-tools/test-utils-vitest": "workspace:^",
"@azure/dev-tool": "workspace:^",
"tshy": "catalog:",
"@azure/eslint-plugin-azure-sdk": "workspace:^",
"@azure/identity": "catalog:internal",
"@types/node": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@azure-tools/test-recorder": "workspace:^",
"@azure-tools/test-utils-vitest": "workspace:^",
"@azure/dev-tool": "workspace:^",
"tshy": "catalog:",
"@azure/eslint-plugin-azure-sdk": "workspace:^",
"@azure/identity": "catalog:internal",
"@types/node": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@azure-tools/test-recorder": "workspace:^",
"@azure-tools/test-utils-vitest": "workspace:^",
"@azure/dev-tool": "workspace:^",
"tshy": "catalog:",
"@azure/eslint-plugin-azure-sdk": "workspace:^",
"@azure/identity": "catalog:internal",
"@types/node": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@azure-tools/test-recorder": "workspace:^",
"@azure-tools/test-utils-vitest": "workspace:^",
"@azure/dev-tool": "workspace:^",
"tshy": "catalog:",
"@azure/eslint-plugin-azure-sdk": "workspace:^",
"@azure/identity": "catalog:internal",
"@types/node": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@azure-tools/test-recorder": "workspace:^",
"@azure-tools/test-utils-vitest": "workspace:^",
"@azure/dev-tool": "workspace:^",
"tshy": "catalog:",
"@azure/eslint-plugin-azure-sdk": "workspace:^",
"@azure/identity": "catalog:internal",
"@types/node": "catalog:",
Expand Down
1 change: 1 addition & 0 deletions packages/rlc-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export * from "./metadata/buildApiExtractorConfig.js";
export * from "./metadata/buildPackageFile.js";
export * from "./metadata/buildRollupConfig.js";
export * from "./metadata/buildTsConfig.js";
export * from "./metadata/buildWarpConfig.js";
export * from "./metadata/buildESLintConfig.js";
export * from "./metadata/buildLicenseFile.js";
export * from "./metadata/buildVitestConfig.js";
Expand Down
23 changes: 15 additions & 8 deletions packages/rlc-common/src/metadata/buildPackageFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
} from "../helpers/packageUtil.js";
import {
PackageCommonInfoConfig,
getTshyConfig
getTshyConfig,
resolveWarpExports
} from "./packageJson/packageCommon.js";
import { Project, SourceFile } from "ts-morph";
import { RLCModel } from "../interfaces.js";
Expand Down Expand Up @@ -118,13 +119,19 @@ export function updatePackageFile(
packageInfo = existingFilePathOrContent;
}

// Update tshy.exports if exports are provided and tshy exists
if (needsExportsUpdate && packageInfo.tshy) {
const newTshy = getTshyConfig({
exports,
azureSdkForJs: model.options?.azureSdkForJs
} as PackageCommonInfoConfig);
packageInfo.tshy.exports = newTshy.exports;
// Update exports based on build system (warp for monorepo, tshy for others)
if (needsExportsUpdate) {
if (model.options?.azureSdkForJs) {
// Warp: update resolved exports in package.json
packageInfo.exports = resolveWarpExports(exports);
} else if (packageInfo.tshy) {
// Tshy: update tshy.exports in package.json
const newTshy = getTshyConfig({
exports,
azureSdkForJs: model.options?.azureSdkForJs
} as PackageCommonInfoConfig);
packageInfo.tshy.exports = newTshy.exports;
}
}

// Update LRO dependencies for Azure packages
Expand Down
64 changes: 64 additions & 0 deletions packages/rlc-common/src/metadata/buildWarpConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { RLCModel } from "../interfaces.js";
import { isAzureMonorepoPackage } from "../helpers/packageUtil.js";

export interface WarpConfigOptions {
/** Source-level exports, e.g. { ".": "./src/index.ts", "./models": "./src/models/index.ts" } */
exports?: Record<string, string>;
}

/**
* Builds a warp.config.yml file for Azure SDK monorepo packages.
* Only generated when azureSdkForJs is true.
*/
export function buildWarpConfig(
model: RLCModel,
{ exports }: WarpConfigOptions = {}
) {
if (!isAzureMonorepoPackage(model)) {
return;
}

if (model.options?.moduleKind !== "esm") {
return;
}

const allExports: Record<string, string> = {
"./package.json": "./package.json",
".": "./src/index.ts",
...exports
};

const lines: string[] = [];
lines.push("# warp.config.yml — build configuration");
lines.push("");
lines.push("exports:");
for (const [key, value] of Object.entries(allExports)) {
lines.push(` ${JSON.stringify(key)}: ${JSON.stringify(value)}`);
}
lines.push("");
lines.push("targets:");
lines.push(" - name: browser");
lines.push(' tsconfig: "../../../tsconfig.src.browser.json"');
lines.push(' polyfillSuffix: "-browser"');
lines.push("");
lines.push(" - name: react-native");
lines.push(' tsconfig: "../../../tsconfig.src.react-native.json"');
lines.push(' polyfillSuffix: "-react-native"');
lines.push("");
lines.push(" - name: esm");
lines.push(" condition: import");
lines.push(' tsconfig: "../../../tsconfig.src.esm.json"');
lines.push("");
lines.push(" - name: commonjs");
lines.push(" condition: require");
lines.push(' tsconfig: "../../../tsconfig.src.cjs.json"');
lines.push("");

return {
path: "warp.config.yml",
content: lines.join("\n")
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export function getAzureMonorepoDependencies(config: AzureMonorepoInfoConfig) {
"@azure-tools/test-recorder": "workspace:^",
"@azure-tools/test-utils-vitest": "workspace:^",
"@azure/dev-tool": "workspace:^",
tshy: "catalog:",
"@azure/eslint-plugin-azure-sdk": "workspace:^",
"@azure/identity": "catalog:internal",
"@types/node": "catalog:",
Expand Down
70 changes: 69 additions & 1 deletion packages/rlc-common/src/metadata/packageJson/packageCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,17 @@ export function getCommonPackageDevDependencies(
};
}

function getEsmDevDependencies({ moduleKind }: PackageCommonInfoConfig) {
function getEsmDevDependencies({
moduleKind,
azureSdkForJs
}: PackageCommonInfoConfig) {
if (moduleKind !== "esm") {
return {};
}
// Azure monorepo packages use warp (invoked via dev-tool), no tshy needed
if (azureSdkForJs) {
return {};
}
return {
tshy: "^2.0.0"
};
Expand Down Expand Up @@ -97,6 +104,19 @@ function getEsmEntrypointInformation(config: PackageCommonInfoConfig) {
return;
}

// Azure monorepo packages use warp instead of tshy
if (config.azureSdkForJs) {
return {
type: "module",
main: "./dist/commonjs/index.js",
module: "./dist/esm/index.js",
types: "./dist/commonjs/index.d.ts",
browser: "./dist/browser/index.js",
"react-native": "./dist/react-native/index.js",
exports: resolveWarpExports(config.exports)
};
}

return {
tshy: getTshyConfig(config),
type: "module",
Expand All @@ -105,6 +125,54 @@ function getEsmEntrypointInformation(config: PackageCommonInfoConfig) {
};
}

/**
* Resolve source-level exports to dist-level exports for warp.
* Converts { ".": "./src/index.ts" } to the nested condition map with
* browser/import/require conditions pointing to dist/ paths.
*/
export function resolveWarpExports(
sourceExports?: Record<string, any>
): Record<string, any> {
const exports: Record<string, any> = {};
const allExports: Record<string, string> = {
"./package.json": "./package.json",
".": "./src/index.ts",
...sourceExports
};

for (const [subpath, sourcePath] of Object.entries(allExports)) {
// Pass-through entries (e.g. "./package.json": "./package.json")
if (!/\.ts$/.test(sourcePath)) {
exports[subpath] = sourcePath;
continue;
}

// Convert source path to dist path: "./src/foo/index.ts" -> "foo/index"
const relPath = sourcePath.replace(/^\.\/src\//, "").replace(/\.ts$/, "");

exports[subpath] = {
browser: {
types: `./dist/browser/${relPath}.d.ts`,
default: `./dist/browser/${relPath}.js`
},
"react-native": {
types: `./dist/react-native/${relPath}.d.ts`,
default: `./dist/react-native/${relPath}.js`
},
import: {
types: `./dist/esm/${relPath}.d.ts`,
default: `./dist/esm/${relPath}.js`
},
require: {
types: `./dist/commonjs/${relPath}.d.ts`,
default: `./dist/commonjs/${relPath}.js`
}
};
}

return exports;
}

export function getTshyConfig(config: PackageCommonInfoConfig) {
const { exports = {} } = config;
const tshyConfig: Record<string, any> = {
Expand Down
Loading
Loading