@azure-tools/typespec-ts 0.55.0-dev.3 → 0.55.0-dev.5
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/README.md +1 -13
- package/dist/src/framework/load-static-helpers.d.ts +4 -1
- package/dist/src/framework/load-static-helpers.d.ts.map +1 -1
- package/dist/src/framework/load-static-helpers.js +16 -21
- package/dist/src/framework/load-static-helpers.js.map +1 -1
- package/dist/src/framework/sample.js +1 -1
- package/dist/src/framework/sample.js.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +55 -56
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +1 -3
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +1 -11
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/build-client-context.d.ts.map +1 -1
- package/dist/src/modular/build-client-context.js +6 -15
- package/dist/src/modular/build-client-context.js.map +1 -1
- package/dist/src/modular/build-root-index.d.ts.map +1 -1
- package/dist/src/modular/build-root-index.js +4 -7
- package/dist/src/modular/build-root-index.js.map +1 -1
- package/dist/src/modular/emit-logger-file.d.ts.map +1 -1
- package/dist/src/modular/emit-logger-file.js +0 -3
- package/dist/src/modular/emit-logger-file.js.map +1 -1
- package/dist/src/modular/emit-samples.js +7 -24
- package/dist/src/modular/emit-samples.js.map +1 -1
- package/dist/src/modular/emit-tests.d.ts +2 -1
- package/dist/src/modular/emit-tests.d.ts.map +1 -1
- package/dist/src/modular/emit-tests.js +18 -8
- package/dist/src/modular/emit-tests.js.map +1 -1
- package/dist/src/modular/helpers/client-helpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/client-helpers.js +6 -16
- package/dist/src/modular/helpers/client-helpers.js.map +1 -1
- package/dist/src/modular/helpers/example-value-helpers.d.ts +1 -1
- package/dist/src/modular/helpers/example-value-helpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/example-value-helpers.js +7 -24
- package/dist/src/modular/helpers/example-value-helpers.js.map +1 -1
- package/dist/src/modular/helpers/operation-helpers.js +1 -1
- package/dist/src/modular/helpers/operation-helpers.js.map +1 -1
- package/dist/src/rlc-common/build-client-definitions.js +1 -1
- package/dist/src/rlc-common/build-client-definitions.js.map +1 -1
- package/dist/src/rlc-common/build-client.d.ts.map +1 -1
- package/dist/src/rlc-common/build-client.js +14 -21
- package/dist/src/rlc-common/build-client.js.map +1 -1
- package/dist/src/rlc-common/build-index-file.d.ts.map +1 -1
- package/dist/src/rlc-common/build-index-file.js +7 -10
- package/dist/src/rlc-common/build-index-file.js.map +1 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.js +1 -1
- package/dist/src/rlc-common/build-is-unexpected-helper.js.map +1 -1
- package/dist/src/rlc-common/build-logger.d.ts.map +1 -1
- package/dist/src/rlc-common/build-logger.js +1 -5
- package/dist/src/rlc-common/build-logger.js.map +1 -1
- package/dist/src/rlc-common/build-parameter-types.js +1 -1
- package/dist/src/rlc-common/build-parameter-types.js.map +1 -1
- package/dist/src/rlc-common/build-response-types.js +1 -1
- package/dist/src/rlc-common/build-response-types.js.map +1 -1
- package/dist/src/rlc-common/build-schema-type.js +1 -1
- package/dist/src/rlc-common/build-schema-type.js.map +1 -1
- package/dist/src/rlc-common/build-top-level-index-file.js +1 -1
- package/dist/src/rlc-common/build-top-level-index-file.js.map +1 -1
- package/dist/src/rlc-common/helpers/imports-util.d.ts +3 -4
- package/dist/src/rlc-common/helpers/imports-util.d.ts.map +1 -1
- package/dist/src/rlc-common/helpers/imports-util.js +43 -56
- package/dist/src/rlc-common/helpers/imports-util.js.map +1 -1
- package/dist/src/rlc-common/helpers/package-util.d.ts +1 -4
- package/dist/src/rlc-common/helpers/package-util.d.ts.map +1 -1
- package/dist/src/rlc-common/helpers/package-util.js +2 -5
- package/dist/src/rlc-common/helpers/package-util.js.map +1 -1
- package/dist/src/rlc-common/interfaces.d.ts +1 -6
- package/dist/src/rlc-common/interfaces.d.ts.map +1 -1
- package/dist/src/rlc-common/interfaces.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-api-extractor-config.js +1 -1
- package/dist/src/rlc-common/metadata/build-api-extractor-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-es-lint-config.d.ts +1 -1
- package/dist/src/rlc-common/metadata/build-es-lint-config.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-es-lint-config.js +1 -4
- package/dist/src/rlc-common/metadata/build-es-lint-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-package-file.js +7 -13
- package/dist/src/rlc-common/metadata/build-package-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.d.ts +2 -2
- package/dist/src/rlc-common/metadata/build-readme-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-readme-file.js +6 -10
- package/dist/src/rlc-common/metadata/build-readme-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-rollup-config.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-rollup-config.js +2 -3
- package/dist/src/rlc-common/metadata/build-rollup-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-sample-env-file.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/build-sample-env-file.js +1 -2
- package/dist/src/rlc-common/metadata/build-sample-env-file.js.map +1 -1
- package/dist/src/rlc-common/metadata/build-ts-config.js +1 -1
- package/dist/src/rlc-common/metadata/build-ts-config.js.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/package-common.d.ts +0 -3
- package/dist/src/rlc-common/metadata/package-json/package-common.d.ts.map +1 -1
- package/dist/src/rlc-common/metadata/package-json/package-common.js +0 -3
- package/dist/src/rlc-common/metadata/package-json/package-common.js.map +1 -1
- package/dist/src/rlc-common/transform-sample-groups.d.ts.map +1 -1
- package/dist/src/rlc-common/transform-sample-groups.js +6 -17
- package/dist/src/rlc-common/transform-sample-groups.js.map +1 -1
- package/dist/src/transform/transform-helper-function-details.d.ts +2 -2
- package/dist/src/transform/transform-helper-function-details.d.ts.map +1 -1
- package/dist/src/transform/transform-helper-function-details.js +1 -9
- package/dist/src/transform/transform-helper-function-details.js.map +1 -1
- package/dist/src/transform/transform.js +2 -2
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transfrom-rlc-options.d.ts.map +1 -1
- package/dist/src/transform/transfrom-rlc-options.js +17 -44
- package/dist/src/transform/transfrom-rlc-options.js.map +1 -1
- package/dist/src/utils/emit-util.d.ts.map +1 -1
- package/dist/src/utils/emit-util.js +13 -10
- package/dist/src/utils/emit-util.js.map +1 -1
- package/dist/src/utils/file-system-utils.d.ts +4 -4
- package/dist/src/utils/file-system-utils.d.ts.map +1 -1
- package/dist/src/utils/file-system-utils.js +12 -13
- package/dist/src/utils/file-system-utils.js.map +1 -1
- package/dist/src/utils/resolve-project-root.d.ts +6 -4
- package/dist/src/utils/resolve-project-root.d.ts.map +1 -1
- package/dist/src/utils/resolve-project-root.js +11 -16
- package/dist/src/utils/resolve-project-root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -18
- package/src/framework/load-static-helpers.ts +26 -26
- package/src/framework/sample.ts +1 -1
- package/src/index.ts +65 -58
- package/src/lib.ts +2 -14
- package/src/modular/build-client-context.ts +6 -14
- package/src/modular/build-root-index.ts +4 -7
- package/src/modular/emit-logger-file.ts +0 -3
- package/src/modular/emit-samples.ts +7 -22
- package/src/modular/emit-tests.ts +22 -9
- package/src/modular/helpers/client-helpers.ts +7 -17
- package/src/modular/helpers/example-value-helpers.ts +7 -22
- package/src/modular/helpers/operation-helpers.ts +1 -1
- package/src/rlc-common/build-client-definitions.ts +1 -1
- package/src/rlc-common/build-client.ts +17 -26
- package/src/rlc-common/build-index-file.ts +7 -10
- package/src/rlc-common/build-is-unexpected-helper.ts +1 -1
- package/src/rlc-common/build-logger.ts +1 -5
- package/src/rlc-common/build-parameter-types.ts +1 -1
- package/src/rlc-common/build-response-types.ts +1 -1
- package/src/rlc-common/build-schema-type.ts +1 -1
- package/src/rlc-common/build-top-level-index-file.ts +1 -1
- package/src/rlc-common/helpers/imports-util.ts +44 -56
- package/src/rlc-common/helpers/package-util.ts +3 -7
- package/src/rlc-common/interfaces.ts +1 -8
- package/src/rlc-common/metadata/build-api-extractor-config.ts +1 -1
- package/src/rlc-common/metadata/build-es-lint-config.ts +1 -4
- package/src/rlc-common/metadata/build-package-file.ts +7 -19
- package/src/rlc-common/metadata/build-readme-file.ts +6 -10
- package/src/rlc-common/metadata/build-rollup-config.ts +2 -3
- package/src/rlc-common/metadata/build-sample-env-file.ts +1 -4
- package/src/rlc-common/metadata/build-ts-config.ts +1 -1
- package/src/rlc-common/metadata/package-json/package-common.ts +0 -4
- package/src/rlc-common/transform-sample-groups.ts +7 -22
- package/src/transform/transform-helper-function-details.ts +1 -10
- package/src/transform/transform.ts +2 -2
- package/src/transform/transfrom-rlc-options.ts +17 -51
- package/src/utils/emit-util.ts +13 -24
- package/src/utils/file-system-utils.ts +13 -13
- package/src/utils/resolve-project-root.ts +11 -22
- package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.d.ts +0 -57
- package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.d.ts.map +0 -1
- package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.js +0 -53
- package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.js.map +0 -1
- package/src/rlc-common/metadata/package-json/build-flavorless-package.ts +0 -68
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-ts",
|
|
3
|
-
"version": "0.55.0-dev.
|
|
3
|
+
"version": "0.55.0-dev.5",
|
|
4
4
|
"description": "An experimental TypeSpec emitter for TypeScript RLC",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"@typespec/spec-api": "^0.1.0-alpha.14 || >=0.1.0-alpha.15-dev <0.1.0-alpha.15",
|
|
24
24
|
"@typespec/tspd": "^0.75.0 || >=0.76.0-dev <0.76.0",
|
|
25
25
|
"@azure-tools/azure-http-specs": "^0.1.0-alpha.42 || >=0.1.0-alpha.43-dev <0.1.0-alpha.43",
|
|
26
|
-
"@azure-tools/typespec-autorest": "^0.69.
|
|
26
|
+
"@azure-tools/typespec-autorest": "^0.69.1 || >=0.70.0-dev <0.70.0",
|
|
27
27
|
"@azure-tools/typespec-azure-core": "^0.69.0 || >=0.70.0-dev <0.70.0",
|
|
28
|
-
"@azure-tools/typespec-azure-resource-manager": "^0.69.
|
|
28
|
+
"@azure-tools/typespec-azure-resource-manager": "^0.69.1 || >=0.70.0-dev <0.70.0",
|
|
29
29
|
"@azure-tools/typespec-client-generator-core": "^0.69.0 || >=0.70.0-dev <0.70.0",
|
|
30
30
|
"@azure/abort-controller": "^2.1.2",
|
|
31
31
|
"@azure/core-auth": "^1.6.0",
|
|
@@ -91,37 +91,26 @@
|
|
|
91
91
|
"build": "tsc -p .",
|
|
92
92
|
"test": "npm run test-next && npm run unit-test && npm run integration-test-ci",
|
|
93
93
|
"test:azure": "npm run test-next && npm run copy:typespec && npm run integration-test-ci:azure-rlc && npm run integration-test-ci:azure-modular",
|
|
94
|
-
"test:standard": "npm run test-next && npm run copy:typespec && npm run unit-test&& npm run integration-test-ci:rlc && npm run integration-test-ci:modular",
|
|
95
94
|
"lint": "eslint . --ext .ts --max-warnings=0",
|
|
96
95
|
"lint:fix": "eslint . --fix --ext .ts",
|
|
97
96
|
"check:tree": "tsx ./test/commands/check-clean-tree.ts",
|
|
98
97
|
"test:ts:e2e": "npm run copy:typespec && npm run integration-test-ci:azure-rlc && npm run integration-test-ci:azure-modular",
|
|
99
|
-
"integration-test-ci": "npm-run-all copy:typespec integration-test-ci:
|
|
100
|
-
"integration-test-ci:sequential": "npm-run-all --serial copy:typespec integration-test-ci:modular && npm run integration-test-ci:modular",
|
|
101
|
-
"integration-test-ci:rlc": "npm-run-all --silent -p start-test-server:rlc --race generate-and-run:rlc",
|
|
98
|
+
"integration-test-ci": "npm-run-all copy:typespec integration-test-ci:azure-rlc integration-test-ci:azure-modular",
|
|
99
|
+
"integration-test-ci:sequential": "npm-run-all --serial copy:typespec integration-test-ci:azure-modular && npm run integration-test-ci:azure-modular",
|
|
102
100
|
"integration-test-ci:azure-rlc": "npm-run-all --silent -p start-test-server:azure-rlc --race generate-and-run:azure-rlc",
|
|
103
|
-
"integration-test-ci:modular": "npm-run-all --silent -p start-test-server:modular --race generate-and-run:modular",
|
|
104
101
|
"integration-test-ci:azure-modular": "npm-run-all --silent -p start-test-server:azure-modular --race generate-and-run:azure-modular",
|
|
105
102
|
"start-test-server": "mkdirp -p coverage && npx tsp-spector serve ./node_modules/@typespec/http-specs/specs --coverageFile ./coverage/spector-coverage-typescript.json",
|
|
106
|
-
"start-test-server:rlc": "mkdirp -p coverage && npx tsp-spector serve ./node_modules/@typespec/http-specs/specs --coverageFile ./coverage/spector-coverage-typescript-rlc-standard.json",
|
|
107
103
|
"start-test-server:azure-rlc": "mkdirp -p coverage && npx tsp-spector serve ./node_modules/@azure-tools/azure-http-specs/specs ./node_modules/@typespec/http-specs/specs --coverageFile ./coverage/spector-coverage-typescript-rlc-azure.json",
|
|
108
|
-
"start-test-server:modular": "mkdirp -p coverage && npx tsp-spector serve ./node_modules/@typespec/http-specs/specs --port 3002 --coverageFile ./coverage/spector-coverage-typescript-modular-standard.json",
|
|
109
104
|
"start-test-server:azure-modular": "mkdirp -p coverage && npx tsp-spector serve ./node_modules/@azure-tools/azure-http-specs/specs ./node_modules/@typespec/http-specs/specs --port 3002 --coverageFile ./coverage/spector-coverage-typescript-modular-azure.json",
|
|
110
105
|
"copy:typespec": "rm -rf temp && mkdirp -p temp/specs && mkdirp -p temp/assets && cp -r ./node_modules/@typespec/http-specs/specs/* ./temp/specs && cp -r ./node_modules/@azure-tools/azure-http-specs/specs/* ./temp/specs && cp -r ./test/integration/typespec/* ./temp/specs && cp -r ./node_modules/@typespec/http-specs/assets/* ./temp/assets",
|
|
111
|
-
"generate-and-run:rlc": "npm run generate-tsp-only:rlc && npm run integration-test:alone:rlc && npm run stop-test-server -- -p 3000",
|
|
112
106
|
"generate-and-run:azure-rlc": "npm run generate-tsp-only:azure-rlc && npm run integration-test:alone:azure-rlc && npm run stop-test-server -- -p 3000",
|
|
113
|
-
"generate-and-run:modular": "npm run generate-tsp-only:modular && npm run integration-test:alone:modular && npm run stop-test-server -- -p 3002",
|
|
114
107
|
"generate-and-run:azure-modular": "npm run generate-tsp-only:azure-modular && npm run integration-test:alone:azure-modular && npm run stop-test-server -- -p 3002",
|
|
115
|
-
"generate-tsp-only": "npm run generate-tsp-only:azure-rlc && npm run generate-tsp-only:
|
|
116
|
-
"generate-tsp-only:rlc": "npx tsx ./test/commands/gen-spector.js --tag=rlc",
|
|
108
|
+
"generate-tsp-only": "npm run generate-tsp-only:azure-rlc && npm run generate-tsp-only:azure-modular",
|
|
117
109
|
"generate-tsp-only:azure-rlc": "npx tsx ./test/commands/gen-spector.js --tag=azure-rlc",
|
|
118
|
-
"generate-tsp-only:modular": "npx tsx ./test/commands/gen-spector.js --tag=modular",
|
|
119
110
|
"generate-tsp-only:azure-modular": "npx tsx ./test/commands/gen-spector.js --tag=azure-modular",
|
|
120
111
|
"regen-test-baselines": "npm run generate-tsp-only",
|
|
121
|
-
"integration-test:alone": "npm run integration-test:alone:
|
|
122
|
-
"integration-test:alone:rlc": "vitest run --project integration-rlc",
|
|
112
|
+
"integration-test:alone": "npm run integration-test:alone:azure-rlc && npm run integration-test:alone:azure-modular",
|
|
123
113
|
"integration-test:alone:azure-rlc": "vitest run --project integration-azure-rlc",
|
|
124
|
-
"integration-test:alone:modular": "vitest run --project integration-modular",
|
|
125
114
|
"integration-test:alone:azure-modular": "vitest run --project integration-azure-modular",
|
|
126
115
|
"stop-test-server": "npx tsp-spector server stop",
|
|
127
116
|
"unit-test": "npm-run-all --parallel unit-test:rlc unit-test:modular",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { joinPaths, NoTarget, Program } from "@typespec/compiler";
|
|
2
|
-
import { readdir, readFile, stat } from "fs/promises";
|
|
1
|
+
import { type CompilerHost, joinPaths, NoTarget, Program } from "@typespec/compiler";
|
|
3
2
|
import {
|
|
4
3
|
ClassDeclaration,
|
|
5
4
|
EnumDeclaration,
|
|
@@ -11,7 +10,6 @@ import {
|
|
|
11
10
|
} from "ts-morph";
|
|
12
11
|
import { reportDiagnostic } from "../lib.js";
|
|
13
12
|
import { ModularEmitterOptions } from "../modular/interfaces.js";
|
|
14
|
-
import { isAzurePackage } from "../rlc-common/index.js";
|
|
15
13
|
import { resolveProjectRoot } from "../utils/resolve-project-root.js";
|
|
16
14
|
import { refkey } from "./refkey.js";
|
|
17
15
|
export const SourceFileSymbol = Symbol("SourceFile");
|
|
@@ -38,6 +36,9 @@ export interface LoadStaticHelpersOptions extends Partial<ModularEmitterOptions>
|
|
|
38
36
|
sourcesDir?: string;
|
|
39
37
|
rootDir?: string;
|
|
40
38
|
program?: Program;
|
|
39
|
+
host?: CompilerHost;
|
|
40
|
+
/** The emitter package root directory (where static/ lives). */
|
|
41
|
+
packageRoot?: string;
|
|
41
42
|
/** When true, also load test helpers from static/test-helpers/ into test/generated/util/ */
|
|
42
43
|
loadTestHelpers?: boolean;
|
|
43
44
|
}
|
|
@@ -53,27 +54,29 @@ export async function loadStaticHelpers(
|
|
|
53
54
|
options: LoadStaticHelpersOptions = {},
|
|
54
55
|
): Promise<Map<string, StaticHelperMetadata>> {
|
|
55
56
|
const helpersMap = new Map<string, StaticHelperMetadata>();
|
|
57
|
+
const host = options.host ?? options.program?.host;
|
|
58
|
+
if (!host) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
"loadStaticHelpers requires either a host or program in options to access the file system.",
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const packageRoot = options.packageRoot ?? resolveProjectRoot();
|
|
65
|
+
|
|
56
66
|
// Load static helpers used in sources code
|
|
57
|
-
const defaultStaticHelpersPath = joinPaths(
|
|
58
|
-
resolveProjectRoot(),
|
|
59
|
-
DEFAULT_SOURCES_STATIC_HELPERS_PATH,
|
|
60
|
-
);
|
|
67
|
+
const defaultStaticHelpersPath = joinPaths(packageRoot, DEFAULT_SOURCES_STATIC_HELPERS_PATH);
|
|
61
68
|
const filesInSources = await traverseDirectory(
|
|
62
69
|
options.helpersAssetDirectory ?? defaultStaticHelpersPath,
|
|
70
|
+
host,
|
|
63
71
|
options.program,
|
|
64
72
|
);
|
|
65
73
|
await loadFiles(filesInSources, options.sourcesDir ?? "");
|
|
66
74
|
// Load static helpers used in testing code (only when loadTestHelpers is enabled)
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
(options.options?.generateTest && isAzurePackage({ options: options.options }))
|
|
70
|
-
) {
|
|
71
|
-
const defaultTestingHelpersPath = joinPaths(
|
|
72
|
-
resolveProjectRoot(),
|
|
73
|
-
DEFAULT_SOURCES_TESTING_HELPERS_PATH,
|
|
74
|
-
);
|
|
75
|
+
if (options.loadTestHelpers ?? options.options?.generateTest) {
|
|
76
|
+
const defaultTestingHelpersPath = joinPaths(packageRoot, DEFAULT_SOURCES_TESTING_HELPERS_PATH);
|
|
75
77
|
const filesInTestings = await traverseDirectory(
|
|
76
78
|
defaultTestingHelpersPath,
|
|
79
|
+
host,
|
|
77
80
|
options.program,
|
|
78
81
|
[],
|
|
79
82
|
"",
|
|
@@ -86,19 +89,12 @@ export async function loadStaticHelpers(
|
|
|
86
89
|
async function loadFiles(files: FileMetadata[], generateDir: string) {
|
|
87
90
|
for (const file of files) {
|
|
88
91
|
const targetPath = joinPaths(generateDir, file.target);
|
|
89
|
-
const
|
|
92
|
+
const sourceFile = await host!.readFile(file.source);
|
|
93
|
+
const contents = sourceFile.text;
|
|
90
94
|
const addedFile = project.createSourceFile(targetPath, contents, {
|
|
91
95
|
overwrite: true,
|
|
92
96
|
});
|
|
93
97
|
addedFile.getImportDeclarations().map((i) => {
|
|
94
|
-
if (!isAzurePackage({ options: options.options })) {
|
|
95
|
-
if (i.getModuleSpecifier().getFullText().includes("@azure/core-rest-pipeline")) {
|
|
96
|
-
i.setModuleSpecifier("@typespec/ts-http-runtime");
|
|
97
|
-
}
|
|
98
|
-
if (i.getModuleSpecifier().getFullText().includes("@azure-rest/core-client")) {
|
|
99
|
-
i.setModuleSpecifier("@typespec/ts-http-runtime");
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
98
|
// Rewrite relative platform-types imports to #platform/ specifiers
|
|
103
99
|
// so that browser/react-native variants are resolved via subpath imports.
|
|
104
100
|
// Only rewrite imports to the default variant (not -browser/-react-native variants
|
|
@@ -186,25 +182,29 @@ function getDeclarationByMetadata(
|
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
184
|
|
|
185
|
+
type FsHost = Pick<CompilerHost, "readFile" | "readDir" | "stat">;
|
|
186
|
+
|
|
189
187
|
const _targetStaticHelpersBaseDir = "static-helpers";
|
|
190
188
|
async function traverseDirectory(
|
|
191
189
|
directory: string,
|
|
190
|
+
host: FsHost,
|
|
192
191
|
program?: Program,
|
|
193
192
|
result: { source: string; target: string }[] = [],
|
|
194
193
|
relativePath: string = "",
|
|
195
194
|
targetBaseDir: string = _targetStaticHelpersBaseDir,
|
|
196
195
|
): Promise<{ source: string; target: string }[]> {
|
|
197
196
|
try {
|
|
198
|
-
const files = await
|
|
197
|
+
const files = await host.readDir(directory);
|
|
199
198
|
|
|
200
199
|
await Promise.all(
|
|
201
200
|
files.map(async (file) => {
|
|
202
201
|
const filePath = joinPaths(directory, file);
|
|
203
|
-
const fileStat = await stat(filePath);
|
|
202
|
+
const fileStat = await host.stat(filePath);
|
|
204
203
|
|
|
205
204
|
if (fileStat.isDirectory()) {
|
|
206
205
|
await traverseDirectory(
|
|
207
206
|
filePath,
|
|
207
|
+
host,
|
|
208
208
|
program,
|
|
209
209
|
result,
|
|
210
210
|
joinPaths(relativePath, file),
|
package/src/framework/sample.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { useBinder } from "./hooks/binder.js";
|
|
|
9
9
|
import { resolveReference } from "./reference.js";
|
|
10
10
|
|
|
11
11
|
// Create a new ts-morph project
|
|
12
|
-
const project = new Project();
|
|
12
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
13
13
|
|
|
14
14
|
// Create a source file
|
|
15
15
|
const sourceFile = project.createSourceFile("test.ts", "", { overwrite: true });
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
EmitContext,
|
|
6
|
+
Program,
|
|
7
|
+
getBaseFileName,
|
|
8
|
+
getDirectoryPath,
|
|
9
|
+
joinPaths,
|
|
10
|
+
resolvePath,
|
|
11
|
+
type CompilerHost,
|
|
12
|
+
} from "@typespec/compiler";
|
|
6
13
|
import { provideContext, useContext } from "./context-manager.js";
|
|
7
14
|
import { buildRootIndex, buildSubClientIndexFile } from "./modular/build-root-index.js";
|
|
8
15
|
import {
|
|
@@ -10,7 +17,6 @@ import {
|
|
|
10
17
|
AzureIdentityDependencies,
|
|
11
18
|
AzurePollingDependencies,
|
|
12
19
|
AzureTestDependencies,
|
|
13
|
-
DefaultCoreDependencies,
|
|
14
20
|
} from "./modular/external-dependencies.js";
|
|
15
21
|
import {
|
|
16
22
|
CloudSettingHelpers,
|
|
@@ -66,7 +72,6 @@ import {
|
|
|
66
72
|
getClientName,
|
|
67
73
|
hasClientNameChanged,
|
|
68
74
|
hasUnexpectedHelper,
|
|
69
|
-
isAzurePackage,
|
|
70
75
|
updatePackageFile,
|
|
71
76
|
updateReadmeFile,
|
|
72
77
|
} from "./rlc-common/index.js";
|
|
@@ -117,8 +122,15 @@ export async function $onEmit(context: EmitContext) {
|
|
|
117
122
|
return;
|
|
118
123
|
}
|
|
119
124
|
/** Shared status */
|
|
120
|
-
const outputProject = new Project();
|
|
125
|
+
const outputProject = new Project({ useInMemoryFileSystem: true });
|
|
121
126
|
const program: Program = context.program;
|
|
127
|
+
const host: CompilerHost = program.host;
|
|
128
|
+
// Derive the emitter package root from the compiler's resolved emitter entry point.
|
|
129
|
+
// This works correctly in both Node.js and the browser playground VFS.
|
|
130
|
+
const emitterRef = program.emitters.find((e) => e.metadata.name === "@azure-tools/typespec-ts");
|
|
131
|
+
const emitterPackageRoot = emitterRef
|
|
132
|
+
? resolvePath(getDirectoryPath(emitterRef.main), "../..")
|
|
133
|
+
: undefined;
|
|
122
134
|
const emitterOptions: EmitterOptions = context.options;
|
|
123
135
|
const dpgContext = await createContextWithDefaultOptions(context);
|
|
124
136
|
|
|
@@ -160,16 +172,16 @@ export async function $onEmit(context: EmitContext) {
|
|
|
160
172
|
rootDir: dpgContext.generationPathDetail?.rootDir,
|
|
161
173
|
options: rlcOptions,
|
|
162
174
|
program,
|
|
175
|
+
host,
|
|
176
|
+
packageRoot: emitterPackageRoot,
|
|
163
177
|
},
|
|
164
178
|
);
|
|
165
|
-
const extraDependencies =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
: { ...DefaultCoreDependencies };
|
|
179
|
+
const extraDependencies = {
|
|
180
|
+
...AzurePollingDependencies,
|
|
181
|
+
...AzureCoreDependencies,
|
|
182
|
+
...AzureIdentityDependencies,
|
|
183
|
+
...AzureTestDependencies,
|
|
184
|
+
};
|
|
173
185
|
const binder = provideBinder(outputProject, {
|
|
174
186
|
staticHelpers,
|
|
175
187
|
dependencies: {
|
|
@@ -216,16 +228,16 @@ export async function $onEmit(context: EmitContext) {
|
|
|
216
228
|
// clear output folder if needed
|
|
217
229
|
if (options.clearOutputFolder) {
|
|
218
230
|
// Clear output directory while preserving TempTypeSpecFiles
|
|
219
|
-
await clearDirectory(context.emitterOutputDir, ["TempTypeSpecFiles"], program);
|
|
231
|
+
await clearDirectory(host, context.emitterOutputDir, ["TempTypeSpecFiles"], program);
|
|
220
232
|
}
|
|
221
233
|
const hasTestFolder = await pathExists(
|
|
234
|
+
host,
|
|
222
235
|
joinPaths(dpgContext.generationPathDetail?.metadataDir ?? "", "test"),
|
|
223
236
|
);
|
|
224
237
|
options.generateTest =
|
|
225
238
|
options.generateTest === true ||
|
|
226
239
|
(options.generateTest === undefined &&
|
|
227
|
-
(!hasTestFolder || (options.azureSdkForJs && options.azureArm))
|
|
228
|
-
isAzurePackage({ options: options }));
|
|
240
|
+
(!hasTestFolder || (options.azureSdkForJs && options.azureArm)));
|
|
229
241
|
dpgContext.rlcOptions = options;
|
|
230
242
|
}
|
|
231
243
|
|
|
@@ -234,10 +246,10 @@ export async function $onEmit(context: EmitContext) {
|
|
|
234
246
|
const customizationFolder = joinPaths(projectRoot, "generated");
|
|
235
247
|
const srcGeneratedFolder = joinPaths(projectRoot, "src", "generated");
|
|
236
248
|
// if customization folder exists, use it as sources root
|
|
237
|
-
const finalCustomizationFolder = (await pathExists(srcGeneratedFolder))
|
|
249
|
+
const finalCustomizationFolder = (await pathExists(host, srcGeneratedFolder))
|
|
238
250
|
? srcGeneratedFolder
|
|
239
251
|
: customizationFolder;
|
|
240
|
-
const sourcesRoot = (await pathExists(finalCustomizationFolder))
|
|
252
|
+
const sourcesRoot = (await pathExists(host, finalCustomizationFolder))
|
|
241
253
|
? finalCustomizationFolder
|
|
242
254
|
: joinPaths(projectRoot, "src");
|
|
243
255
|
return {
|
|
@@ -250,6 +262,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
250
262
|
|
|
251
263
|
async function clearSrcFolder() {
|
|
252
264
|
await emptyDir(
|
|
265
|
+
host,
|
|
253
266
|
dpgContext.generationPathDetail?.modularSourcesDir ??
|
|
254
267
|
dpgContext.generationPathDetail?.rlcSourcesDir ??
|
|
255
268
|
"",
|
|
@@ -262,8 +275,8 @@ export async function $onEmit(context: EmitContext) {
|
|
|
262
275
|
dpgContext.generationPathDetail?.rootDir ?? "",
|
|
263
276
|
"samples-dev",
|
|
264
277
|
);
|
|
265
|
-
if (await pathExists(samplesDevPath)) {
|
|
266
|
-
await emptyDir(samplesDevPath);
|
|
278
|
+
if (await pathExists(host, samplesDevPath)) {
|
|
279
|
+
await emptyDir(host, samplesDevPath);
|
|
267
280
|
}
|
|
268
281
|
}
|
|
269
282
|
}
|
|
@@ -453,29 +466,28 @@ export async function $onEmit(context: EmitContext) {
|
|
|
453
466
|
// warp.config.yml, and snippets.spec.ts. metadata.json is still updated.
|
|
454
467
|
const sourcesDir = dpgContext.generationPathDetail?.modularSourcesDir ?? "";
|
|
455
468
|
const hasManualConvenienceLayer = getBaseFileName(sourcesDir) === "generated";
|
|
456
|
-
const isAzureFlavor = isAzurePackage({ options: option });
|
|
457
469
|
// Generate metadata
|
|
458
470
|
const existingPackageFilePath = joinPaths(
|
|
459
471
|
dpgContext.generationPathDetail?.metadataDir ?? "",
|
|
460
472
|
"package.json",
|
|
461
473
|
);
|
|
462
|
-
const hasPackageFile =
|
|
474
|
+
const hasPackageFile = await pathExists(host, existingPackageFilePath);
|
|
463
475
|
const existingReadmeFilePath = joinPaths(
|
|
464
476
|
dpgContext.generationPathDetail?.metadataDir ?? "",
|
|
465
477
|
"README.md",
|
|
466
478
|
);
|
|
467
|
-
const hasReadmeFile =
|
|
479
|
+
const hasReadmeFile = await pathExists(host, existingReadmeFilePath);
|
|
468
480
|
const existingChangelogFilePath = joinPaths(
|
|
469
481
|
dpgContext.generationPathDetail?.metadataDir ?? "",
|
|
470
482
|
"CHANGELOG.md",
|
|
471
483
|
);
|
|
472
|
-
const hasChangelogFile =
|
|
484
|
+
const hasChangelogFile = await pathExists(host, existingChangelogFilePath);
|
|
473
485
|
const shouldGenerateMetadata = option.generateMetadata === true || !hasPackageFile;
|
|
474
486
|
const existingTestFolderPath = joinPaths(
|
|
475
487
|
dpgContext.generationPathDetail?.metadataDir ?? "",
|
|
476
488
|
"test",
|
|
477
489
|
);
|
|
478
|
-
const hasTestFolder =
|
|
490
|
+
const hasTestFolder = await pathExists(host, existingTestFolderPath);
|
|
479
491
|
if (option.generateTest === undefined) {
|
|
480
492
|
if (hasTestFolder) {
|
|
481
493
|
option.generateTest = false;
|
|
@@ -505,9 +517,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
505
517
|
commonBuilders.push((model) => buildTestBrowserTsConfig(model));
|
|
506
518
|
commonBuilders.push((model) => buildTestNodeTsConfig(model));
|
|
507
519
|
}
|
|
508
|
-
|
|
509
|
-
commonBuilders.push(buildEsLintConfig);
|
|
510
|
-
}
|
|
520
|
+
commonBuilders.push(buildEsLintConfig);
|
|
511
521
|
if (!hasChangelogFile) {
|
|
512
522
|
commonBuilders.push(buildChangelogFile);
|
|
513
523
|
}
|
|
@@ -516,7 +526,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
516
526
|
option.azureSdkForJs === true &&
|
|
517
527
|
emitterOptions["generate-metadata"] === true
|
|
518
528
|
) {
|
|
519
|
-
await emitTests(dpgContext);
|
|
529
|
+
await emitTests(dpgContext, host);
|
|
520
530
|
}
|
|
521
531
|
let modularPackageInfo = {};
|
|
522
532
|
if (option.isModularLibrary) {
|
|
@@ -525,25 +535,16 @@ export async function $onEmit(context: EmitContext) {
|
|
|
525
535
|
};
|
|
526
536
|
// Build dependencies
|
|
527
537
|
const dependencies: Record<string, string> = {};
|
|
528
|
-
|
|
529
|
-
dependencies["@azure/core-util"] = "^1.9.2";
|
|
530
|
-
}
|
|
538
|
+
dependencies["@azure/core-util"] = "^1.9.2";
|
|
531
539
|
// Add fast-xml-parser if XML serialization is used
|
|
532
540
|
if (packageUsesXmlSerialization(dpgContext.sdkPackage)) {
|
|
533
541
|
dependencies["fast-xml-parser"] = "^4.5.0";
|
|
534
542
|
}
|
|
535
|
-
|
|
536
|
-
modularPackageInfo
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
};
|
|
541
|
-
} else if (Object.keys(dependencies).length > 0) {
|
|
542
|
-
modularPackageInfo = {
|
|
543
|
-
...modularPackageInfo,
|
|
544
|
-
dependencies,
|
|
545
|
-
};
|
|
546
|
-
}
|
|
543
|
+
modularPackageInfo = {
|
|
544
|
+
...modularPackageInfo,
|
|
545
|
+
dependencies,
|
|
546
|
+
clientContextPaths: getRelativeContextPaths(context, modularEmitterOptions),
|
|
547
|
+
};
|
|
547
548
|
}
|
|
548
549
|
commonBuilders.push((model) => buildPackageFile(model, modularPackageInfo));
|
|
549
550
|
// Generate warp.config.yml for Azure monorepo ESM packages
|
|
@@ -561,9 +562,7 @@ export async function $onEmit(context: EmitContext) {
|
|
|
561
562
|
if (option.generateSample) {
|
|
562
563
|
commonBuilders.push(buildTsSampleConfig);
|
|
563
564
|
}
|
|
564
|
-
|
|
565
|
-
commonBuilders.push(buildTsLintConfig);
|
|
566
|
-
}
|
|
565
|
+
commonBuilders.push(buildTsLintConfig);
|
|
567
566
|
}
|
|
568
567
|
|
|
569
568
|
// TODO: need support snippets generation for multi-client cases. https://github.com/Azure/autorest.typescript/issues/3048
|
|
@@ -617,8 +616,16 @@ export async function $onEmit(context: EmitContext) {
|
|
|
617
616
|
// Always update package.json for monorepo packages (adds #platform/* imports)
|
|
618
617
|
// and for modular packages (adds exports, clientContextPaths, LRO deps)
|
|
619
618
|
if (option.isModularLibrary || option.azureSdkForJs) {
|
|
619
|
+
// Read package.json content via host and pass parsed object
|
|
620
|
+
const pkgSourceFile = await host.readFile(existingPackageFilePath);
|
|
621
|
+
let packageInfo: Record<string, any>;
|
|
622
|
+
try {
|
|
623
|
+
packageInfo = JSON.parse(pkgSourceFile.text);
|
|
624
|
+
} catch {
|
|
625
|
+
packageInfo = {};
|
|
626
|
+
}
|
|
620
627
|
updateBuilders.push((model: RLCModel) =>
|
|
621
|
-
updatePackageFile(model,
|
|
628
|
+
updatePackageFile(model, packageInfo, modularPackageInfo),
|
|
622
629
|
);
|
|
623
630
|
}
|
|
624
631
|
|
|
@@ -630,11 +637,13 @@ export async function $onEmit(context: EmitContext) {
|
|
|
630
637
|
// If the client name changed, regenerate the README and snippets completely;
|
|
631
638
|
// otherwise update only the API reference link in-place.
|
|
632
639
|
if (hasReadmeFile) {
|
|
633
|
-
const
|
|
640
|
+
const readmeSourceFile = await host.readFile(existingReadmeFilePath);
|
|
641
|
+
const existingReadmeContent = readmeSourceFile.text;
|
|
642
|
+
const clientNameChanged = hasClientNameChanged(rlcClient, existingReadmeContent);
|
|
634
643
|
updateBuilders.push(
|
|
635
644
|
clientNameChanged
|
|
636
645
|
? buildReadmeFile
|
|
637
|
-
: (model: RLCModel) => updateReadmeFile(model,
|
|
646
|
+
: (model: RLCModel) => updateReadmeFile(model, existingReadmeContent),
|
|
638
647
|
);
|
|
639
648
|
|
|
640
649
|
// Regenerate snippets.spec.ts only when the client name changed
|
|
@@ -655,14 +664,12 @@ export async function $onEmit(context: EmitContext) {
|
|
|
655
664
|
dpgContext.generationPathDetail?.metadataDir,
|
|
656
665
|
);
|
|
657
666
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
);
|
|
665
|
-
}
|
|
667
|
+
await emitContentByBuilder(
|
|
668
|
+
program,
|
|
669
|
+
buildMetadataJson,
|
|
670
|
+
rlcClient,
|
|
671
|
+
dpgContext.generationPathDetail?.metadataDir,
|
|
672
|
+
);
|
|
666
673
|
|
|
667
674
|
// Generate test relevant files
|
|
668
675
|
if (option.generateTest && !hasTestFolder) {
|
package/src/lib.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { createTypeSpecLibrary, JSONSchemaType, paramMessage } from "@typespec/compiler";
|
|
5
5
|
import { Options } from "prettier";
|
|
6
|
-
import { DependencyInfo, PackageDetails,
|
|
6
|
+
import { DependencyInfo, PackageDetails, ServiceInfo } from "./rlc-common/index.js";
|
|
7
7
|
|
|
8
8
|
export interface EmitterOptions {
|
|
9
9
|
/**
|
|
@@ -54,7 +54,6 @@ export interface EmitterOptions {
|
|
|
54
54
|
"is-modular-library"?: boolean;
|
|
55
55
|
"module-kind"?: "esm";
|
|
56
56
|
"enable-operation-group"?: boolean;
|
|
57
|
-
flavor?: PackageFlavor;
|
|
58
57
|
"enable-model-namespace"?: boolean;
|
|
59
58
|
"hierarchy-client"?: boolean;
|
|
60
59
|
"compatibility-mode"?: boolean;
|
|
@@ -63,7 +62,6 @@ export interface EmitterOptions {
|
|
|
63
62
|
"clear-output-folder"?: boolean;
|
|
64
63
|
"ignore-property-name-normalize"?: boolean;
|
|
65
64
|
"compatibility-query-multi-format"?: boolean;
|
|
66
|
-
branded?: boolean;
|
|
67
65
|
"typespec-title-map"?: Record<string, string>;
|
|
68
66
|
"ignore-enum-member-name-normalize"?: boolean;
|
|
69
67
|
"default-value-object"?: boolean;
|
|
@@ -210,7 +208,7 @@ export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
|
210
208
|
type: "boolean",
|
|
211
209
|
nullable: true,
|
|
212
210
|
description:
|
|
213
|
-
"This is used to indicate your project is generated in [azure-sdk-for-js](https://github.com/Azure/azure-sdk-for-js) repo or not. If your package is located in that repo we'll leverage `dev-tool` to accelerate our building and testing, however if not we'll remove the dependency for that tool. Defaults to `undefined`.
|
|
211
|
+
"This is used to indicate your project is generated in [azure-sdk-for-js](https://github.com/Azure/azure-sdk-for-js) repo or not. If your package is located in that repo we'll leverage `dev-tool` to accelerate our building and testing, however if not we'll remove the dependency for that tool. Defaults to `undefined`. ",
|
|
214
212
|
},
|
|
215
213
|
"azure-output-directory": {
|
|
216
214
|
type: "string",
|
|
@@ -288,16 +286,6 @@ export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
|
288
286
|
description:
|
|
289
287
|
"An option to organize the client in a hierarchical way as defined by `@clientInitialization`. This is true by default.",
|
|
290
288
|
},
|
|
291
|
-
branded: {
|
|
292
|
-
type: "boolean",
|
|
293
|
-
nullable: true,
|
|
294
|
-
description: "A section of flavor",
|
|
295
|
-
},
|
|
296
|
-
flavor: {
|
|
297
|
-
type: "string",
|
|
298
|
-
nullable: true,
|
|
299
|
-
description: "The flavor of the SDK.",
|
|
300
|
-
},
|
|
301
289
|
"module-kind": {
|
|
302
290
|
type: "string",
|
|
303
291
|
nullable: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NameType,
|
|
1
|
+
import { NameType, normalizeName } from "../rlc-common/index.js";
|
|
2
2
|
import {
|
|
3
3
|
buildGetClientCredentialParam,
|
|
4
4
|
buildGetClientEndpointParam,
|
|
@@ -164,13 +164,10 @@ export function buildClientContext(
|
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
// TODO use binder here
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
namedImports: ["logger"],
|
|
172
|
-
});
|
|
173
|
-
}
|
|
167
|
+
clientContextFile.addImportDeclaration({
|
|
168
|
+
moduleSpecifier: "../".repeat(hierarchy.length + 1) + "logger.js",
|
|
169
|
+
namedImports: ["logger"],
|
|
170
|
+
});
|
|
174
171
|
|
|
175
172
|
const factoryFunction = clientContextFile.addFunction({
|
|
176
173
|
docs: getDocsFromDescription(client.doc),
|
|
@@ -241,15 +238,10 @@ export function buildClientContext(
|
|
|
241
238
|
if (!apiVersionInEndpoint && apiVersionParam.clientDefaultValue) {
|
|
242
239
|
apiVersionStatement += `const ${apiVersionParamName} = options.${apiVersionParamName};`;
|
|
243
240
|
}
|
|
244
|
-
} else if (isAzurePackage(emitterOptions)) {
|
|
245
|
-
apiVersionStatement += `
|
|
246
|
-
if (options.apiVersion) {
|
|
247
|
-
logger.warning("This client does not support client api-version, please change it at the operation level");
|
|
248
|
-
}`;
|
|
249
241
|
} else {
|
|
250
242
|
apiVersionStatement += `
|
|
251
243
|
if (options.apiVersion) {
|
|
252
|
-
|
|
244
|
+
logger.warning("This client does not support client api-version, please change it at the operation level");
|
|
253
245
|
}`;
|
|
254
246
|
}
|
|
255
247
|
factoryFunction.addStatements(apiVersionStatement);
|
|
@@ -4,7 +4,7 @@ import { Project, SourceFile } from "ts-morph";
|
|
|
4
4
|
import { useContext } from "../context-manager.js";
|
|
5
5
|
import { resolveReference } from "../framework/reference.js";
|
|
6
6
|
import { reportDiagnostic } from "../lib.js";
|
|
7
|
-
import {
|
|
7
|
+
import { NameType, normalizeName } from "../rlc-common/index.js";
|
|
8
8
|
import { getModularClientOptions } from "../utils/client-utils.js";
|
|
9
9
|
import { SdkContext } from "../utils/interfaces.js";
|
|
10
10
|
import { getMethodHierarchiesMap } from "../utils/operation-util.js";
|
|
@@ -28,7 +28,7 @@ export function buildRootIndex(
|
|
|
28
28
|
if (!clientMap) {
|
|
29
29
|
// we still need to export the models if no client is provided
|
|
30
30
|
exportModels(emitterOptions, rootIndexFile);
|
|
31
|
-
exportRestErrorTypes(
|
|
31
|
+
exportRestErrorTypes(rootIndexFile);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
const project = useContext("outputProject");
|
|
@@ -71,7 +71,7 @@ export function buildRootIndex(
|
|
|
71
71
|
exportPagingTypes(context, rootIndexFile);
|
|
72
72
|
exportFileContentsType(context, rootIndexFile);
|
|
73
73
|
exportAzureCloudTypes(context, rootIndexFile);
|
|
74
|
-
exportRestErrorTypes(
|
|
74
|
+
exportRestErrorTypes(rootIndexFile);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
function exportModels(
|
|
@@ -105,10 +105,7 @@ function exportAzureCloudTypes(context: SdkContext, rootIndexFile: SourceFile) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
function exportRestErrorTypes(
|
|
109
|
-
if (!isAzurePackage({ options: context.rlcOptions })) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
108
|
+
function exportRestErrorTypes(rootIndexFile: SourceFile) {
|
|
112
109
|
const existingExports = getExistingExports(rootIndexFile);
|
|
113
110
|
const namedExports = ["RestError", "isRestError"].filter((name) => !existingExports.has(name));
|
|
114
111
|
if (namedExports.length > 0) {
|
|
@@ -3,9 +3,6 @@ import { ModularEmitterOptions } from "./interfaces.js";
|
|
|
3
3
|
|
|
4
4
|
export function emitLoggerFile(emitterOptions: ModularEmitterOptions, srcPath: string = "src") {
|
|
5
5
|
const project = useContext("outputProject");
|
|
6
|
-
if (emitterOptions.options.flavor !== "azure") {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
6
|
|
|
10
7
|
const sourceFile = project.createSourceFile(`${srcPath}/logger.ts`, "", {
|
|
11
8
|
overwrite: true,
|
|
@@ -14,7 +14,7 @@ import { useContext } from "../context-manager.js";
|
|
|
14
14
|
import { resolveReference } from "../framework/reference.js";
|
|
15
15
|
import { reportDiagnostic } from "../index.js";
|
|
16
16
|
import { AzureIdentityDependencies } from "../modular/external-dependencies.js";
|
|
17
|
-
import {
|
|
17
|
+
import { NameType, normalizeName } from "../rlc-common/index.js";
|
|
18
18
|
import { getSubscriptionId } from "../transform/transfrom-rlc-options.js";
|
|
19
19
|
import { hasKeyCredential, hasTokenCredential } from "../utils/credential-utils.js";
|
|
20
20
|
import { SdkContext } from "../utils/interfaces.js";
|
|
@@ -464,7 +464,7 @@ function prepareExampleParameters(
|
|
|
464
464
|
}
|
|
465
465
|
|
|
466
466
|
function getCredentialExampleValue(
|
|
467
|
-
|
|
467
|
+
_dpgContext: SdkContext,
|
|
468
468
|
initialization: SdkClientInitializationType,
|
|
469
469
|
): ExampleValue | undefined {
|
|
470
470
|
const keyCredential = hasKeyCredential(initialization),
|
|
@@ -475,26 +475,11 @@ function getCredentialExampleValue(
|
|
|
475
475
|
name: "credential",
|
|
476
476
|
};
|
|
477
477
|
if (keyCredential || tokenCredential) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
};
|
|
484
|
-
} else if (keyCredential) {
|
|
485
|
-
// Support ApiKeyCredential for non-Azure packages
|
|
486
|
-
return {
|
|
487
|
-
...defaultSetting,
|
|
488
|
-
value: `{ key: "INPUT_YOUR_KEY_HERE" }`,
|
|
489
|
-
};
|
|
490
|
-
} else if (tokenCredential) {
|
|
491
|
-
// Support TokenCredential for non-Azure packages
|
|
492
|
-
return {
|
|
493
|
-
...defaultSetting,
|
|
494
|
-
value: `{ getToken: async () => {
|
|
495
|
-
return { token: "INPUT_YOUR_TOKEN_HERE", expiresOnTimestamp: now() }; } }`,
|
|
496
|
-
};
|
|
497
|
-
}
|
|
478
|
+
// Support DefaultAzureCredential for Azure packages
|
|
479
|
+
return {
|
|
480
|
+
...defaultSetting,
|
|
481
|
+
value: `new ${resolveReference(AzureIdentityDependencies.DefaultAzureCredential)}()`,
|
|
482
|
+
};
|
|
498
483
|
}
|
|
499
484
|
return undefined;
|
|
500
485
|
}
|