@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.
Files changed (164) hide show
  1. package/README.md +1 -13
  2. package/dist/src/framework/load-static-helpers.d.ts +4 -1
  3. package/dist/src/framework/load-static-helpers.d.ts.map +1 -1
  4. package/dist/src/framework/load-static-helpers.js +16 -21
  5. package/dist/src/framework/load-static-helpers.js.map +1 -1
  6. package/dist/src/framework/sample.js +1 -1
  7. package/dist/src/framework/sample.js.map +1 -1
  8. package/dist/src/index.d.ts.map +1 -1
  9. package/dist/src/index.js +55 -56
  10. package/dist/src/index.js.map +1 -1
  11. package/dist/src/lib.d.ts +1 -3
  12. package/dist/src/lib.d.ts.map +1 -1
  13. package/dist/src/lib.js +1 -11
  14. package/dist/src/lib.js.map +1 -1
  15. package/dist/src/modular/build-client-context.d.ts.map +1 -1
  16. package/dist/src/modular/build-client-context.js +6 -15
  17. package/dist/src/modular/build-client-context.js.map +1 -1
  18. package/dist/src/modular/build-root-index.d.ts.map +1 -1
  19. package/dist/src/modular/build-root-index.js +4 -7
  20. package/dist/src/modular/build-root-index.js.map +1 -1
  21. package/dist/src/modular/emit-logger-file.d.ts.map +1 -1
  22. package/dist/src/modular/emit-logger-file.js +0 -3
  23. package/dist/src/modular/emit-logger-file.js.map +1 -1
  24. package/dist/src/modular/emit-samples.js +7 -24
  25. package/dist/src/modular/emit-samples.js.map +1 -1
  26. package/dist/src/modular/emit-tests.d.ts +2 -1
  27. package/dist/src/modular/emit-tests.d.ts.map +1 -1
  28. package/dist/src/modular/emit-tests.js +18 -8
  29. package/dist/src/modular/emit-tests.js.map +1 -1
  30. package/dist/src/modular/helpers/client-helpers.d.ts.map +1 -1
  31. package/dist/src/modular/helpers/client-helpers.js +6 -16
  32. package/dist/src/modular/helpers/client-helpers.js.map +1 -1
  33. package/dist/src/modular/helpers/example-value-helpers.d.ts +1 -1
  34. package/dist/src/modular/helpers/example-value-helpers.d.ts.map +1 -1
  35. package/dist/src/modular/helpers/example-value-helpers.js +7 -24
  36. package/dist/src/modular/helpers/example-value-helpers.js.map +1 -1
  37. package/dist/src/modular/helpers/operation-helpers.js +1 -1
  38. package/dist/src/modular/helpers/operation-helpers.js.map +1 -1
  39. package/dist/src/rlc-common/build-client-definitions.js +1 -1
  40. package/dist/src/rlc-common/build-client-definitions.js.map +1 -1
  41. package/dist/src/rlc-common/build-client.d.ts.map +1 -1
  42. package/dist/src/rlc-common/build-client.js +14 -21
  43. package/dist/src/rlc-common/build-client.js.map +1 -1
  44. package/dist/src/rlc-common/build-index-file.d.ts.map +1 -1
  45. package/dist/src/rlc-common/build-index-file.js +7 -10
  46. package/dist/src/rlc-common/build-index-file.js.map +1 -1
  47. package/dist/src/rlc-common/build-is-unexpected-helper.js +1 -1
  48. package/dist/src/rlc-common/build-is-unexpected-helper.js.map +1 -1
  49. package/dist/src/rlc-common/build-logger.d.ts.map +1 -1
  50. package/dist/src/rlc-common/build-logger.js +1 -5
  51. package/dist/src/rlc-common/build-logger.js.map +1 -1
  52. package/dist/src/rlc-common/build-parameter-types.js +1 -1
  53. package/dist/src/rlc-common/build-parameter-types.js.map +1 -1
  54. package/dist/src/rlc-common/build-response-types.js +1 -1
  55. package/dist/src/rlc-common/build-response-types.js.map +1 -1
  56. package/dist/src/rlc-common/build-schema-type.js +1 -1
  57. package/dist/src/rlc-common/build-schema-type.js.map +1 -1
  58. package/dist/src/rlc-common/build-top-level-index-file.js +1 -1
  59. package/dist/src/rlc-common/build-top-level-index-file.js.map +1 -1
  60. package/dist/src/rlc-common/helpers/imports-util.d.ts +3 -4
  61. package/dist/src/rlc-common/helpers/imports-util.d.ts.map +1 -1
  62. package/dist/src/rlc-common/helpers/imports-util.js +43 -56
  63. package/dist/src/rlc-common/helpers/imports-util.js.map +1 -1
  64. package/dist/src/rlc-common/helpers/package-util.d.ts +1 -4
  65. package/dist/src/rlc-common/helpers/package-util.d.ts.map +1 -1
  66. package/dist/src/rlc-common/helpers/package-util.js +2 -5
  67. package/dist/src/rlc-common/helpers/package-util.js.map +1 -1
  68. package/dist/src/rlc-common/interfaces.d.ts +1 -6
  69. package/dist/src/rlc-common/interfaces.d.ts.map +1 -1
  70. package/dist/src/rlc-common/interfaces.js.map +1 -1
  71. package/dist/src/rlc-common/metadata/build-api-extractor-config.js +1 -1
  72. package/dist/src/rlc-common/metadata/build-api-extractor-config.js.map +1 -1
  73. package/dist/src/rlc-common/metadata/build-es-lint-config.d.ts +1 -1
  74. package/dist/src/rlc-common/metadata/build-es-lint-config.d.ts.map +1 -1
  75. package/dist/src/rlc-common/metadata/build-es-lint-config.js +1 -4
  76. package/dist/src/rlc-common/metadata/build-es-lint-config.js.map +1 -1
  77. package/dist/src/rlc-common/metadata/build-package-file.d.ts.map +1 -1
  78. package/dist/src/rlc-common/metadata/build-package-file.js +7 -13
  79. package/dist/src/rlc-common/metadata/build-package-file.js.map +1 -1
  80. package/dist/src/rlc-common/metadata/build-readme-file.d.ts +2 -2
  81. package/dist/src/rlc-common/metadata/build-readme-file.d.ts.map +1 -1
  82. package/dist/src/rlc-common/metadata/build-readme-file.js +6 -10
  83. package/dist/src/rlc-common/metadata/build-readme-file.js.map +1 -1
  84. package/dist/src/rlc-common/metadata/build-rollup-config.d.ts.map +1 -1
  85. package/dist/src/rlc-common/metadata/build-rollup-config.js +2 -3
  86. package/dist/src/rlc-common/metadata/build-rollup-config.js.map +1 -1
  87. package/dist/src/rlc-common/metadata/build-sample-env-file.d.ts.map +1 -1
  88. package/dist/src/rlc-common/metadata/build-sample-env-file.js +1 -2
  89. package/dist/src/rlc-common/metadata/build-sample-env-file.js.map +1 -1
  90. package/dist/src/rlc-common/metadata/build-ts-config.js +1 -1
  91. package/dist/src/rlc-common/metadata/build-ts-config.js.map +1 -1
  92. package/dist/src/rlc-common/metadata/package-json/package-common.d.ts +0 -3
  93. package/dist/src/rlc-common/metadata/package-json/package-common.d.ts.map +1 -1
  94. package/dist/src/rlc-common/metadata/package-json/package-common.js +0 -3
  95. package/dist/src/rlc-common/metadata/package-json/package-common.js.map +1 -1
  96. package/dist/src/rlc-common/transform-sample-groups.d.ts.map +1 -1
  97. package/dist/src/rlc-common/transform-sample-groups.js +6 -17
  98. package/dist/src/rlc-common/transform-sample-groups.js.map +1 -1
  99. package/dist/src/transform/transform-helper-function-details.d.ts +2 -2
  100. package/dist/src/transform/transform-helper-function-details.d.ts.map +1 -1
  101. package/dist/src/transform/transform-helper-function-details.js +1 -9
  102. package/dist/src/transform/transform-helper-function-details.js.map +1 -1
  103. package/dist/src/transform/transform.js +2 -2
  104. package/dist/src/transform/transform.js.map +1 -1
  105. package/dist/src/transform/transfrom-rlc-options.d.ts.map +1 -1
  106. package/dist/src/transform/transfrom-rlc-options.js +17 -44
  107. package/dist/src/transform/transfrom-rlc-options.js.map +1 -1
  108. package/dist/src/utils/emit-util.d.ts.map +1 -1
  109. package/dist/src/utils/emit-util.js +13 -10
  110. package/dist/src/utils/emit-util.js.map +1 -1
  111. package/dist/src/utils/file-system-utils.d.ts +4 -4
  112. package/dist/src/utils/file-system-utils.d.ts.map +1 -1
  113. package/dist/src/utils/file-system-utils.js +12 -13
  114. package/dist/src/utils/file-system-utils.js.map +1 -1
  115. package/dist/src/utils/resolve-project-root.d.ts +6 -4
  116. package/dist/src/utils/resolve-project-root.d.ts.map +1 -1
  117. package/dist/src/utils/resolve-project-root.js +11 -16
  118. package/dist/src/utils/resolve-project-root.js.map +1 -1
  119. package/dist/tsconfig.tsbuildinfo +1 -1
  120. package/package.json +7 -18
  121. package/src/framework/load-static-helpers.ts +26 -26
  122. package/src/framework/sample.ts +1 -1
  123. package/src/index.ts +65 -58
  124. package/src/lib.ts +2 -14
  125. package/src/modular/build-client-context.ts +6 -14
  126. package/src/modular/build-root-index.ts +4 -7
  127. package/src/modular/emit-logger-file.ts +0 -3
  128. package/src/modular/emit-samples.ts +7 -22
  129. package/src/modular/emit-tests.ts +22 -9
  130. package/src/modular/helpers/client-helpers.ts +7 -17
  131. package/src/modular/helpers/example-value-helpers.ts +7 -22
  132. package/src/modular/helpers/operation-helpers.ts +1 -1
  133. package/src/rlc-common/build-client-definitions.ts +1 -1
  134. package/src/rlc-common/build-client.ts +17 -26
  135. package/src/rlc-common/build-index-file.ts +7 -10
  136. package/src/rlc-common/build-is-unexpected-helper.ts +1 -1
  137. package/src/rlc-common/build-logger.ts +1 -5
  138. package/src/rlc-common/build-parameter-types.ts +1 -1
  139. package/src/rlc-common/build-response-types.ts +1 -1
  140. package/src/rlc-common/build-schema-type.ts +1 -1
  141. package/src/rlc-common/build-top-level-index-file.ts +1 -1
  142. package/src/rlc-common/helpers/imports-util.ts +44 -56
  143. package/src/rlc-common/helpers/package-util.ts +3 -7
  144. package/src/rlc-common/interfaces.ts +1 -8
  145. package/src/rlc-common/metadata/build-api-extractor-config.ts +1 -1
  146. package/src/rlc-common/metadata/build-es-lint-config.ts +1 -4
  147. package/src/rlc-common/metadata/build-package-file.ts +7 -19
  148. package/src/rlc-common/metadata/build-readme-file.ts +6 -10
  149. package/src/rlc-common/metadata/build-rollup-config.ts +2 -3
  150. package/src/rlc-common/metadata/build-sample-env-file.ts +1 -4
  151. package/src/rlc-common/metadata/build-ts-config.ts +1 -1
  152. package/src/rlc-common/metadata/package-json/package-common.ts +0 -4
  153. package/src/rlc-common/transform-sample-groups.ts +7 -22
  154. package/src/transform/transform-helper-function-details.ts +1 -10
  155. package/src/transform/transform.ts +2 -2
  156. package/src/transform/transfrom-rlc-options.ts +17 -51
  157. package/src/utils/emit-util.ts +13 -24
  158. package/src/utils/file-system-utils.ts +13 -13
  159. package/src/utils/resolve-project-root.ts +11 -22
  160. package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.d.ts +0 -57
  161. package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.d.ts.map +0 -1
  162. package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.js +0 -53
  163. package/dist/src/rlc-common/metadata/package-json/build-flavorless-package.js.map +0 -1
  164. package/src/rlc-common/metadata/package-json/build-flavorless-package.ts +0 -68
@@ -3,11 +3,9 @@
3
3
 
4
4
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
5
  // @ts-ignore: to fix the handlebars issue
6
- import { readFileSync } from "fs";
7
6
  import hbs from "handlebars";
8
7
  import { getClientName } from "../helpers/name-constructors.js";
9
8
  import { NameType, normalizeName } from "../helpers/name-utils.js";
10
- import { isAzurePackage } from "../helpers/package-util.js";
11
9
  import { RLCModel } from "../interfaces.js";
12
10
 
13
11
  const azureReadmeRLCTemplate = `# {{ clientDescriptiveName }} library for JavaScript
@@ -350,7 +348,7 @@ interface Metadata {
350
348
  export function buildReadmeFile(model: RLCModel) {
351
349
  const metadata = createMetadata(model) ?? {};
352
350
  const readmeFileContents = hbs.compile(
353
- model.options && isAzurePackage(model)
351
+ model.options
354
352
  ? model.options.isModularLibrary
355
353
  ? azureReadmeModularTemplate
356
354
  : azureReadmeRLCTemplate
@@ -363,10 +361,9 @@ export function buildReadmeFile(model: RLCModel) {
363
361
  };
364
362
  }
365
363
 
366
- export function hasClientNameChanged(model: RLCModel, existingReadmeFilePath: string): boolean {
364
+ export function hasClientNameChanged(model: RLCModel, existingReadmeContent: string): boolean {
367
365
  try {
368
- const existingContent = readFileSync(existingReadmeFilePath, "utf8");
369
- const importMatch = existingContent.match(
366
+ const importMatch = existingReadmeContent.match(
370
367
  /import\s*\{\s*([A-Za-z0-9_]+)\s*\}\s*from\s*["'][^"']*["']/,
371
368
  );
372
369
  const existingClientName = importMatch?.[1];
@@ -379,21 +376,20 @@ export function hasClientNameChanged(model: RLCModel, existingReadmeFilePath: st
379
376
 
380
377
  export function updateReadmeFile(
381
378
  model: RLCModel,
382
- existingReadmeFilePath: string,
379
+ existingReadmeContent: string,
383
380
  ): { path: string; content: string } | undefined {
384
381
  try {
385
- const existingContent = readFileSync(existingReadmeFilePath, "utf8");
386
382
  const metadata = createMetadata(model) ?? {};
387
383
 
388
384
  const newApiRefLink = hbs.compile(apiReferenceTemplate, { noEscape: true })(metadata).trim();
389
385
 
390
386
  if (!newApiRefLink) {
391
- return { path: "README.md", content: existingContent };
387
+ return { path: "README.md", content: existingReadmeContent };
392
388
  }
393
389
 
394
390
  const apiRefRegex =
395
391
  /^- \[API reference documentation\]\(https:\/\/learn\.microsoft\.com\/javascript\/api\/[^)]+\)$/m;
396
- const updatedContent = existingContent.replace(apiRefRegex, (match) =>
392
+ const updatedContent = existingReadmeContent.replace(apiRefRegex, (match) =>
397
393
  match ? newApiRefLink : match,
398
394
  );
399
395
 
@@ -2,17 +2,16 @@
2
2
  // Licensed under the MIT License.
3
3
 
4
4
  import { Project } from "ts-morph";
5
- import { isAzurePackage } from "../helpers/package-util.js";
6
5
  import { RLCModel } from "../interfaces.js";
7
6
 
8
7
  export function buildRollupConfig(model: RLCModel) {
9
8
  const azureSdkForJs = Boolean(model.options?.azureSdkForJs);
10
9
  // Only generate the file when it is not in sdk repo
11
- if (isAzurePackage(model) && (azureSdkForJs === true || azureSdkForJs === undefined)) {
10
+ if (azureSdkForJs === true || azureSdkForJs === undefined) {
12
11
  return;
13
12
  }
14
13
 
15
- const project = new Project();
14
+ const project = new Project({ useInMemoryFileSystem: true });
16
15
  const filePath = "rollup.config.js";
17
16
  const rollupFile = project.createSourceFile(filePath, undefined, {
18
17
  overwrite: true,
@@ -7,10 +7,7 @@ const sampleEnvText = `
7
7
  `;
8
8
 
9
9
  export function buildSampleEnvFile(model: RLCModel) {
10
- if (
11
- (model.options?.generateMetadata === true || model.options?.generateSample === true) &&
12
- model.options?.flavor === "azure"
13
- ) {
10
+ if (model.options?.generateMetadata === true || model.options?.generateSample === true) {
14
11
  const filePath = "sample.env";
15
12
  return {
16
13
  path: filePath,
@@ -14,7 +14,7 @@ export function buildTsConfig(model: RLCModel) {
14
14
  const { packageDetails, azureSdkForJs } = model.options || {};
15
15
  const { generateTest, generateSample, generateReactNativeTarget } = model.options || {};
16
16
  const clientPackageName = packageDetails?.name ?? "";
17
- const project = new Project();
17
+ const project = new Project({ useInMemoryFileSystem: true });
18
18
 
19
19
  let tsConfig: Record<string, any>;
20
20
 
@@ -40,10 +40,6 @@ export function getPackageCommonInfo(config: PackageCommonInfoConfig) {
40
40
  };
41
41
  }
42
42
 
43
- export const commonPackageDependencies = {
44
- tslib: "^2.6.2",
45
- };
46
-
47
43
  export function getCommonPackageDevDependencies(config: PackageCommonInfoConfig) {
48
44
  return {
49
45
  "@types/node": "^20.0.0",
@@ -1,6 +1,5 @@
1
1
  import { getClientName } from "./helpers/name-constructors.js";
2
2
  import { NameType, camelCase, normalizeName } from "./helpers/name-utils.js";
3
- import { isAzurePackage } from "./helpers/package-util.js";
4
3
  import { buildSchemaObjectMap } from "./helpers/schema-helpers.js";
5
4
  import { generateParameterTypeValue } from "./helpers/value-generation-util.js";
6
5
  import {
@@ -201,13 +200,8 @@ function convertClientLevelParameters(
201
200
  // Do not include parameters with constant values in the signature, these should go in the options bag
202
201
  (p) => p.value === undefined,
203
202
  );
204
- const {
205
- addCredentials,
206
- credentialScopes,
207
- credentialKeyHeaderName,
208
- customHttpAuthHeaderName,
209
- flavor,
210
- } = model.options;
203
+ const { addCredentials, credentialScopes, credentialKeyHeaderName, customHttpAuthHeaderName } =
204
+ model.options;
211
205
  const hasUrlParameter = !!urlParameters,
212
206
  hasCredentials =
213
207
  addCredentials && (credentialScopes || credentialKeyHeaderName || customHttpAuthHeaderName);
@@ -227,34 +221,25 @@ function convertClientLevelParameters(
227
221
  }
228
222
  if (hasCredentials) {
229
223
  // Currently only support token credential
230
- const apiKeyCredentialPackage = isAzurePackage(model)
231
- ? "@azure/core-auth"
232
- : "@typespec/ts-http-runtime";
233
- const tokenCredentialPackage = isAzurePackage(model)
234
- ? "@azure/identity"
235
- : "@typespec/ts-http-runtime";
236
- if (credentialKeyHeaderName && isAzurePackage(model)) {
224
+ const apiKeyCredentialPackage = "@azure/core-auth";
225
+ const tokenCredentialPackage = "@azure/identity";
226
+ if (credentialKeyHeaderName) {
237
227
  clientParams.push({
238
228
  name: "credential",
239
229
  assignment: `const credential = new AzureKeyCredential("{Your API key}");`,
240
230
  });
241
231
  addValueInImportedDict(apiKeyCredentialPackage, "AzureKeyCredential", importedDict);
242
- } else if ((credentialKeyHeaderName && flavor !== "azure") || customHttpAuthHeaderName) {
232
+ } else if (customHttpAuthHeaderName) {
243
233
  clientParams.push({
244
234
  name: "credential",
245
235
  assignment: `const credential = { key: "{Your API key}"};`,
246
236
  });
247
- } else if (isAzurePackage(model)) {
237
+ } else {
248
238
  clientParams.push({
249
239
  name: "credential",
250
240
  assignment: "const credential = new DefaultAzureCredential();",
251
241
  });
252
242
  addValueInImportedDict(tokenCredentialPackage, "DefaultAzureCredential", importedDict);
253
- } else {
254
- clientParams.push({
255
- name: "credential",
256
- assignment: `const credential = {getToken: () => Promise.resolve({ token: "{Your token}", expiresOnTimestamp: 0 })};`,
257
- });
258
243
  }
259
244
  }
260
245
  return clientParams;
@@ -1,5 +1,5 @@
1
1
  import { getHttpOperationWithCache, SdkClient } from "@azure-tools/typespec-client-generator-core";
2
- import { HelperFunctionDetails, PackageFlavor } from "../rlc-common/index.js";
2
+ import { HelperFunctionDetails } from "../rlc-common/index.js";
3
3
  import { listOperationsUnderRLCClient } from "../utils/client-utils.js";
4
4
  import { SdkContext } from "../utils/interfaces.js";
5
5
  import { getCollectionFormat } from "../utils/model-utils.js";
@@ -13,17 +13,8 @@ import {
13
13
  export function transformHelperFunctionDetails(
14
14
  client: SdkClient,
15
15
  dpgContext: SdkContext,
16
- flavor?: PackageFlavor,
17
16
  ): HelperFunctionDetails {
18
17
  const serializeInfo = extractSpecialSerializeInfo(client, dpgContext);
19
- // Disable paging and long running for non-Azure clients.
20
- if (flavor !== "azure") {
21
- return {
22
- hasLongRunning: false,
23
- hasPaging: false,
24
- ...serializeInfo,
25
- };
26
- }
27
18
 
28
19
  const annotationDetails = {
29
20
  hasLongRunning: hasPollingOperations(client, dpgContext),
@@ -72,7 +72,7 @@ export async function transformRLCModel(
72
72
  importSet,
73
73
  urlInfo?.apiVersionInfo,
74
74
  );
75
- const helperDetails = transformHelperFunctionDetails(client, dpgContext, options.flavor);
75
+ const helperDetails = transformHelperFunctionDetails(client, dpgContext);
76
76
  // Enrich client-level annotation detail
77
77
  helperDetails.clientLroOverload = getClientLroOverload(paths);
78
78
 
@@ -91,7 +91,7 @@ export async function transformRLCModel(
91
91
  telemetryOptions,
92
92
  importInfo: {
93
93
  internalImports: importSet,
94
- runtimeImports: buildRuntimeImports(options.flavor),
94
+ runtimeImports: buildRuntimeImports(),
95
95
  },
96
96
  rlcSourceDir,
97
97
  };
@@ -7,7 +7,6 @@ import {
7
7
  NameType,
8
8
  normalizeName,
9
9
  PackageDetails,
10
- PackageFlavor,
11
10
  pascalCase,
12
11
  RLCOptions,
13
12
  ServiceInfo,
@@ -43,13 +42,12 @@ function extractRLCOptions(
43
42
  const isModularLibrary = emitterOptions["is-modular-library"] !== false;
44
43
  const includeShortcuts = getIncludeShortcuts(emitterOptions);
45
44
  const packageDetails = getPackageDetails(program, emitterOptions, isModularLibrary);
46
- const flavor = getFlavor(emitterOptions, packageDetails);
47
45
  const moduleKind = getModuleKind(emitterOptions);
48
46
  const serviceInfo = getServiceInfo(program, isModularLibrary);
49
47
  const includeHeadersInResponse = emitterOptions["include-headers-in-response"] === true;
50
- const azureSdkForJs = getAzureSdkForJs(emitterOptions, flavor);
48
+ const azureSdkForJs = getAzureSdkForJs(emitterOptions);
51
49
  const generateMetadata = getGenerateMetadata(emitterOptions);
52
- const generateTest = getGenerateTest(emitterOptions, flavor);
50
+ const generateTest = getGenerateTest(emitterOptions);
53
51
  const generateSample = getGenerateSample(dpgContext, emitterOptions);
54
52
  const credentialInfo = getCredentialInfo(program, emitterOptions, isModularLibrary);
55
53
  const azureOutputDirectory = getAzureOutputDirectory(generationRootDir);
@@ -77,14 +75,13 @@ function extractRLCOptions(
77
75
  const typespecTitleMap = emitterOptions["typespec-title-map"];
78
76
  const generateReactNativeTarget = emitterOptions["generate-react-native-target"] === true;
79
77
  const hasSubscriptionId = getSubscriptionId(dpgContext);
80
- const ignoreNullableOnOptional = getIgnoreNullableOnOptional(emitterOptions, flavor);
81
- const wrapNonModelReturn = getWrapNonModelReturn(emitterOptions, flavor);
78
+ const ignoreNullableOnOptional = getIgnoreNullableOnOptional(emitterOptions);
79
+ const wrapNonModelReturn = getWrapNonModelReturn(emitterOptions);
82
80
  const isMultiService = (dpgContext.allServiceNamespaces?.length ?? 0) > 1;
83
81
 
84
82
  return {
85
83
  ...credentialInfo,
86
84
  includeHeadersInResponse,
87
- flavor,
88
85
  moduleKind,
89
86
  includeShortcuts,
90
87
  packageDetails,
@@ -247,25 +244,22 @@ function detectIfNameConflicts(dpgContext: SdkContext, isModularLibrary: boolean
247
244
  return false;
248
245
  }
249
246
 
250
- function getIgnoreNullableOnOptional(
251
- emitterOptions: EmitterOptions,
252
- flavor: PackageFlavor,
253
- ): boolean {
247
+ function getIgnoreNullableOnOptional(emitterOptions: EmitterOptions): boolean {
254
248
  // If explicitly set in options, use that value
255
249
  if (emitterOptions["ignore-nullable-on-optional"] !== undefined) {
256
250
  return Boolean(emitterOptions["ignore-nullable-on-optional"]);
257
251
  }
258
- // Default to true for Azure services (same as HLC behavior)
259
- return flavor === "azure";
252
+ // Default to true (same as HLC behavior)
253
+ return true;
260
254
  }
261
255
 
262
- function getWrapNonModelReturn(emitterOptions: EmitterOptions, flavor: PackageFlavor): boolean {
256
+ function getWrapNonModelReturn(emitterOptions: EmitterOptions): boolean {
263
257
  // If explicitly set in options, use that value
264
258
  if (emitterOptions["wrap-non-model-return"] !== undefined) {
265
259
  return Boolean(emitterOptions["wrap-non-model-return"]);
266
260
  }
267
- // Default to true for Azure services to maintain HLC backward compatibility
268
- return flavor === "azure";
261
+ // Default to true to maintain HLC backward compatibility
262
+ return true;
269
263
  }
270
264
 
271
265
  function getIncludeShortcuts(emitterOptions: EmitterOptions) {
@@ -276,32 +270,6 @@ function getModuleKind(emitterOptions: EmitterOptions) {
276
270
  return emitterOptions["module-kind"] ?? "esm";
277
271
  }
278
272
 
279
- function getFlavor(emitterOptions: EmitterOptions, packageDetails?: PackageDetails): PackageFlavor {
280
- const flavor = emitterOptions.flavor;
281
-
282
- if (flavor !== undefined) {
283
- if (flavor.toLowerCase() === "azure") {
284
- return "azure";
285
- } else {
286
- return undefined;
287
- }
288
- }
289
-
290
- const branded = emitterOptions.branded;
291
- if (branded !== undefined) {
292
- return branded ? "azure" : undefined;
293
- }
294
-
295
- const scopeName = packageDetails?.scopeName;
296
- if (
297
- scopeName !== undefined &&
298
- (scopeName.startsWith("azure") || scopeName.startsWith("msinternal"))
299
- ) {
300
- return "azure";
301
- } else {
302
- return undefined;
303
- }
304
- }
305
273
  function buildPackageDetails(
306
274
  program: Program,
307
275
  emitterOptions: EmitterOptions,
@@ -350,13 +318,11 @@ function getServiceInfo(program: Program, isModularLibrary: boolean): ServiceInf
350
318
  };
351
319
  }
352
320
 
353
- function getAzureSdkForJs(emitterOptions: EmitterOptions, flavor: PackageFlavor) {
354
- return flavor !== "azure"
355
- ? false
356
- : emitterOptions["azure-sdk-for-js"] === undefined ||
357
- emitterOptions["azure-sdk-for-js"] === null
358
- ? true
359
- : Boolean(emitterOptions["azure-sdk-for-js"]);
321
+ function getAzureSdkForJs(emitterOptions: EmitterOptions) {
322
+ return emitterOptions["azure-sdk-for-js"] === undefined ||
323
+ emitterOptions["azure-sdk-for-js"] === null
324
+ ? true
325
+ : Boolean(emitterOptions["azure-sdk-for-js"]);
360
326
  }
361
327
 
362
328
  function getGenerateMetadata(emitterOptions: EmitterOptions) {
@@ -374,9 +340,9 @@ function getGenerateMetadata(emitterOptions: EmitterOptions) {
374
340
  * @param emitterOptions
375
341
  * @returns
376
342
  */
377
- function getGenerateTest(emitterOptions: EmitterOptions, flavor: PackageFlavor) {
343
+ function getGenerateTest(emitterOptions: EmitterOptions) {
378
344
  // Disable generateTest if azureSdkForJS is false
379
- if (!getAzureSdkForJs(emitterOptions, flavor)) {
345
+ if (!getAzureSdkForJs(emitterOptions)) {
380
346
  return false;
381
347
  }
382
348
  return emitterOptions["generate-test"];
@@ -1,24 +1,20 @@
1
1
  import { CompilerHost, getDirectoryPath, joinPaths, NoTarget, Program } from "@typespec/compiler";
2
2
  import { format } from "prettier";
3
+ import prettierPluginBabel from "prettier/plugins/babel";
4
+ import prettierPluginEstree from "prettier/plugins/estree";
5
+ import prettierPluginTypescript from "prettier/plugins/typescript";
3
6
  import { prettierJSONOptions, prettierTypeScriptOptions, reportDiagnostic } from "../lib.js";
4
- import {
5
- buildSchemaTypes,
6
- ContentBuilder,
7
- File,
8
- isAzurePackage,
9
- RLCModel,
10
- } from "../rlc-common/index.js";
7
+ import { buildSchemaTypes, ContentBuilder, File, RLCModel } from "../rlc-common/index.js";
11
8
 
12
9
  export async function emitModels(rlcModels: RLCModel, program: Program) {
13
10
  const schemaOutput = buildSchemaTypes(rlcModels);
14
- const isAzureFlavor = isAzurePackage(rlcModels);
15
11
  if (schemaOutput) {
16
12
  const { inputModelFile, outputModelFile } = schemaOutput;
17
13
  if (inputModelFile) {
18
- await emitFile(inputModelFile, program, isAzureFlavor);
14
+ await emitFile(inputModelFile, program);
19
15
  }
20
16
  if (outputModelFile) {
21
- await emitFile(outputModelFile, program, isAzureFlavor);
17
+ await emitFile(outputModelFile, program);
22
18
  }
23
19
  }
24
20
  }
@@ -32,7 +28,6 @@ export async function emitContentByBuilder(
32
28
  if (!Array.isArray(builderFnOrList)) {
33
29
  builderFnOrList = [builderFnOrList];
34
30
  }
35
- const isAzureFlavor = isAzurePackage(rlcModels);
36
31
  for (const builderFn of builderFnOrList) {
37
32
  let contentFiles: File[] | File | undefined = builderFn(rlcModels);
38
33
  if (!contentFiles) {
@@ -42,17 +37,12 @@ export async function emitContentByBuilder(
42
37
  contentFiles = [contentFiles];
43
38
  }
44
39
  for (const file of contentFiles) {
45
- await emitFile(file, program, isAzureFlavor, emitterOutputDir);
40
+ await emitFile(file, program, emitterOutputDir);
46
41
  }
47
42
  }
48
43
  }
49
44
 
50
- async function emitFile(
51
- file: File,
52
- program: Program,
53
- isAzureFlavor: boolean,
54
- emitterOutputDir?: string,
55
- ) {
45
+ async function emitFile(file: File, program: Program, emitterOutputDir?: string) {
56
46
  if (program.compilerOptions.noEmit || program.hasError()) {
57
47
  return;
58
48
  }
@@ -60,8 +50,7 @@ async function emitFile(
60
50
  const filePath = joinPaths(emitterOutputDir ?? "", file.path);
61
51
  const isJson = /\.json$/gi.test(filePath);
62
52
  const isSourceCode = /\.(ts|js)$/gi.test(filePath);
63
- const microsoftHeader = isAzureFlavor ? `// Copyright (c) Microsoft Corporation.\n` : "";
64
- const licenseHeader = `${microsoftHeader}// Licensed under the MIT License.\n`;
53
+ const licenseHeader = `// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n`;
65
54
  let prettierFileContent = file.content;
66
55
 
67
56
  if (isSourceCode) {
@@ -70,10 +59,10 @@ async function emitFile(
70
59
  // Format the contents if necessary
71
60
  if (isJson || isSourceCode) {
72
61
  try {
73
- prettierFileContent = await format(
74
- prettierFileContent,
75
- isJson ? prettierJSONOptions : prettierTypeScriptOptions,
76
- );
62
+ prettierFileContent = await format(prettierFileContent, {
63
+ ...(isJson ? prettierJSONOptions : prettierTypeScriptOptions),
64
+ plugins: [prettierPluginTypescript, prettierPluginEstree, prettierPluginBabel],
65
+ });
77
66
  } catch (e) {
78
67
  reportDiagnostic(program, {
79
68
  code: "file-formatting-error",
@@ -1,48 +1,48 @@
1
- import { NoTarget, Program, resolvePath } from "@typespec/compiler";
2
- import { mkdir, readdir, rm, stat } from "fs/promises";
1
+ import { NoTarget, Program, resolvePath, type CompilerHost } from "@typespec/compiler";
3
2
  import { reportDiagnostic } from "../lib.js";
4
3
 
5
- export async function pathExists(targetPath: string): Promise<boolean> {
4
+ export async function pathExists(host: CompilerHost, targetPath: string): Promise<boolean> {
6
5
  try {
7
- await stat(targetPath);
6
+ await host.stat(targetPath);
8
7
  return true;
9
8
  } catch {
10
9
  return false;
11
10
  }
12
11
  }
13
12
 
14
- export async function emptyDir(dirPath: string): Promise<void> {
13
+ export async function emptyDir(host: CompilerHost, dirPath: string): Promise<void> {
15
14
  let entries: string[];
16
15
  try {
17
- entries = await readdir(dirPath);
16
+ entries = await host.readDir(dirPath);
18
17
  } catch {
19
- await mkdir(dirPath, { recursive: true });
18
+ await host.mkdirp(dirPath);
20
19
  return;
21
20
  }
22
21
 
23
22
  await Promise.all(
24
- entries.map((entry) => rm(resolvePath(dirPath, entry), { recursive: true, force: true })),
23
+ entries.map((entry) => host.rm(resolvePath(dirPath, entry), { recursive: true })),
25
24
  );
26
25
  }
27
26
 
28
27
  export async function clearDirectory(
28
+ host: CompilerHost,
29
29
  dirPath: string,
30
30
  excludeNames: string[] = [],
31
31
  program?: Program,
32
32
  ): Promise<void> {
33
- if (!(await pathExists(dirPath))) {
33
+ if (!(await pathExists(host, dirPath))) {
34
34
  return;
35
35
  }
36
36
 
37
37
  // If no exclude names, just use regular emptyDir for efficiency
38
38
  if (excludeNames.length === 0) {
39
- await emptyDir(dirPath);
39
+ await emptyDir(host, dirPath);
40
40
  return;
41
41
  }
42
42
 
43
43
  try {
44
44
  // Get all subdirectories and files
45
- const entries = await readdir(dirPath);
45
+ const entries = await host.readDir(dirPath);
46
46
 
47
47
  // Filter entries to exclude those that should be preserved
48
48
  const filteredEntries = entries.filter((entry) => {
@@ -52,7 +52,7 @@ export async function clearDirectory(
52
52
  // Process each entry
53
53
  for (const entry of filteredEntries) {
54
54
  const entryPath = resolvePath(dirPath, entry);
55
- await rm(entryPath, { recursive: true, force: true });
55
+ await host.rm(entryPath, { recursive: true });
56
56
  }
57
57
  } catch (error) {
58
58
  // If there's an error, fall back to regular emptyDir
@@ -63,6 +63,6 @@ export async function clearDirectory(
63
63
  target: NoTarget,
64
64
  });
65
65
  }
66
- await emptyDir(dirPath);
66
+ await emptyDir(host, dirPath);
67
67
  }
68
68
  }
@@ -1,26 +1,15 @@
1
- import { existsSync } from "fs";
2
- import { dirname, resolve } from "path";
3
- import { fileURLToPath } from "url";
1
+ import { resolvePath } from "@typespec/compiler";
4
2
 
5
3
  /**
6
- * Recursively finds the nearest package.json file starting from the specified directory.
7
- * @param {string} currentDir - The directory to start searching from. Defaults to the directory of the current module.
8
- * @returns {string} path to the directory containing the package.json file.
4
+ * Returns the package root directory for the emitter.
5
+ *
6
+ * The compiled output lives at `dist/src/utils/resolve-project-root.js`,
7
+ * so the package root is 3 levels up. This avoids filesystem access,
8
+ * making it compatible with virtual file systems (e.g., the playground).
9
9
  */
10
- export function resolveProjectRoot(
11
- currentDir: string = dirname(fileURLToPath(import.meta.url)),
12
- ): string {
13
- const packageJsonPath = resolve(currentDir, "package.json");
14
-
15
- if (existsSync(packageJsonPath)) {
16
- return currentDir;
17
- }
18
-
19
- const parentDir = resolve(currentDir, "..");
20
-
21
- if (parentDir === currentDir) {
22
- throw new Error("Could not find package.json");
23
- }
24
-
25
- return resolveProjectRoot(parentDir);
10
+ export function resolveProjectRoot(): string {
11
+ // Use the global URL constructor (works in both Node.js and browsers)
12
+ const currentDir = new URL(".", import.meta.url).pathname;
13
+ // From dist/src/utils/ -> package root (3 levels: utils -> src -> dist -> root)
14
+ return resolvePath(currentDir, "../../..");
26
15
  }
@@ -1,57 +0,0 @@
1
- import { PackageCommonInfoConfig } from "./package-common.js";
2
- /**
3
- * Builds the package.json for a flavorless package.
4
- */
5
- export declare function buildFlavorlessPackage(config: PackageCommonInfoConfig): {
6
- scripts: {
7
- build?: undefined;
8
- clean: string;
9
- "extract-api": string;
10
- pack: string;
11
- lint: string;
12
- "lint:fix": string;
13
- } | {
14
- build: string;
15
- clean: string;
16
- "extract-api": string;
17
- pack: string;
18
- lint: string;
19
- "lint:fix": string;
20
- } | {
21
- build: string;
22
- clean: string;
23
- "extract-api": string;
24
- pack: string;
25
- lint: string;
26
- "lint:fix": string;
27
- } | {
28
- build: string;
29
- clean: string;
30
- "extract-api": string;
31
- pack: string;
32
- lint: string;
33
- "lint:fix": string;
34
- };
35
- devDependencies: {
36
- "@microsoft/api-extractor": string;
37
- rimraf: string;
38
- mkdirp: string;
39
- tshy?: undefined;
40
- "@types/node": string;
41
- eslint: string;
42
- typescript: string;
43
- } | {
44
- "@microsoft/api-extractor": string;
45
- rimraf: string;
46
- mkdirp: string;
47
- tshy: string;
48
- "@types/node": string;
49
- eslint: string;
50
- typescript: string;
51
- };
52
- dependencies: {
53
- "@typespec/ts-http-runtime": string;
54
- tslib: string;
55
- };
56
- };
57
- //# sourceMappingURL=build-flavorless-package.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-flavorless-package.d.ts","sourceRoot":"","sources":["../../../../../src/rlc-common/metadata/package-json/build-flavorless-package.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,uBAAuB,EAKxB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBrE"}
@@ -1,53 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { commonPackageDependencies, getCommonPackageDevDependencies, getCommonPackageScripts, getPackageCommonInfo, } from "./package-common.js";
4
- /**
5
- * Builds the package.json for a flavorless package.
6
- */
7
- export function buildFlavorlessPackage(config) {
8
- const packageInfo = {
9
- ...getFlavorlessPackageInfo(config),
10
- scripts: getFlavorlessScripts(config),
11
- devDependencies: {
12
- ...getCommonPackageDevDependencies(config),
13
- "@microsoft/api-extractor": "^7.40.3",
14
- rimraf: "^5.0.5",
15
- mkdirp: "^3.0.1",
16
- },
17
- dependencies: {
18
- ...commonPackageDependencies,
19
- "@typespec/ts-http-runtime": "0.1.0",
20
- },
21
- };
22
- return packageInfo;
23
- }
24
- function getFlavorlessPackageInfo(config) {
25
- const commonPackageInfo = getPackageCommonInfo(config);
26
- return {
27
- ...commonPackageInfo,
28
- };
29
- }
30
- function getFlavorlessScripts(config) {
31
- return {
32
- ...getCommonPackageScripts(),
33
- ...getCjsScripts(config),
34
- ...getEsmScripts(config),
35
- };
36
- }
37
- function getCjsScripts({ moduleKind }) {
38
- if (moduleKind !== "cjs") {
39
- return {};
40
- }
41
- return {
42
- build: "npm run clean && tsc && npm run extract-api",
43
- };
44
- }
45
- function getEsmScripts({ moduleKind }) {
46
- if (moduleKind !== "esm") {
47
- return {};
48
- }
49
- return {
50
- build: "npm run clean && tshy && npm run extract-api",
51
- };
52
- }
53
- //# sourceMappingURL=build-flavorless-package.js.map