@rushstack/heft-typescript-plugin 1.1.14 → 1.2.1

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 (75) hide show
  1. package/CHANGELOG.json +58 -0
  2. package/CHANGELOG.md +15 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/heft-plugin.json +1 -1
  5. package/lib-esm/Performance.js +4 -0
  6. package/lib-esm/Performance.js.map +1 -0
  7. package/lib-esm/TranspilerWorker.js +92 -0
  8. package/lib-esm/TranspilerWorker.js.map +1 -0
  9. package/lib-esm/TypeScriptBuilder.js +758 -0
  10. package/lib-esm/TypeScriptBuilder.js.map +1 -0
  11. package/lib-esm/TypeScriptPlugin.js +205 -0
  12. package/lib-esm/TypeScriptPlugin.js.map +1 -0
  13. package/lib-esm/configureProgramForMultiEmit.js +110 -0
  14. package/lib-esm/configureProgramForMultiEmit.js.map +1 -0
  15. package/lib-esm/fileSystem/TypeScriptCachedFileSystem.js +159 -0
  16. package/lib-esm/fileSystem/TypeScriptCachedFileSystem.js.map +1 -0
  17. package/lib-esm/index.js +6 -0
  18. package/lib-esm/index.js.map +1 -0
  19. package/lib-esm/internalTypings/TypeScriptInternals.js +4 -0
  20. package/lib-esm/internalTypings/TypeScriptInternals.js.map +1 -0
  21. package/lib-esm/loadTypeScriptTool.js +75 -0
  22. package/lib-esm/loadTypeScriptTool.js.map +1 -0
  23. package/lib-esm/schemas/anything.schema.json +28 -0
  24. package/lib-esm/schemas/typescript.schema.json +106 -0
  25. package/lib-esm/tsconfigLoader.js +33 -0
  26. package/lib-esm/tsconfigLoader.js.map +1 -0
  27. package/lib-esm/types.js +4 -0
  28. package/lib-esm/types.js.map +1 -0
  29. package/package.json +34 -8
  30. /package/{lib → lib-commonjs}/Performance.js +0 -0
  31. /package/{lib → lib-commonjs}/Performance.js.map +0 -0
  32. /package/{lib → lib-commonjs}/TranspilerWorker.js +0 -0
  33. /package/{lib → lib-commonjs}/TranspilerWorker.js.map +0 -0
  34. /package/{lib → lib-commonjs}/TypeScriptBuilder.js +0 -0
  35. /package/{lib → lib-commonjs}/TypeScriptBuilder.js.map +0 -0
  36. /package/{lib → lib-commonjs}/TypeScriptPlugin.js +0 -0
  37. /package/{lib → lib-commonjs}/TypeScriptPlugin.js.map +0 -0
  38. /package/{lib → lib-commonjs}/configureProgramForMultiEmit.js +0 -0
  39. /package/{lib → lib-commonjs}/configureProgramForMultiEmit.js.map +0 -0
  40. /package/{lib → lib-commonjs}/fileSystem/TypeScriptCachedFileSystem.js +0 -0
  41. /package/{lib → lib-commonjs}/fileSystem/TypeScriptCachedFileSystem.js.map +0 -0
  42. /package/{lib → lib-commonjs}/index.js +0 -0
  43. /package/{lib → lib-commonjs}/index.js.map +0 -0
  44. /package/{lib → lib-commonjs}/internalTypings/TypeScriptInternals.js +0 -0
  45. /package/{lib → lib-commonjs}/internalTypings/TypeScriptInternals.js.map +0 -0
  46. /package/{lib → lib-commonjs}/loadTypeScriptTool.js +0 -0
  47. /package/{lib → lib-commonjs}/loadTypeScriptTool.js.map +0 -0
  48. /package/{lib → lib-commonjs}/schemas/anything.schema.json +0 -0
  49. /package/{lib → lib-commonjs}/schemas/typescript.schema.json +0 -0
  50. /package/{lib → lib-commonjs}/tsconfigLoader.js +0 -0
  51. /package/{lib → lib-commonjs}/tsconfigLoader.js.map +0 -0
  52. /package/{lib → lib-commonjs}/types.js +0 -0
  53. /package/{lib → lib-commonjs}/types.js.map +0 -0
  54. /package/{lib → lib-dts}/Performance.d.ts +0 -0
  55. /package/{lib → lib-dts}/Performance.d.ts.map +0 -0
  56. /package/{lib → lib-dts}/TranspilerWorker.d.ts +0 -0
  57. /package/{lib → lib-dts}/TranspilerWorker.d.ts.map +0 -0
  58. /package/{lib → lib-dts}/TypeScriptBuilder.d.ts +0 -0
  59. /package/{lib → lib-dts}/TypeScriptBuilder.d.ts.map +0 -0
  60. /package/{lib → lib-dts}/TypeScriptPlugin.d.ts +0 -0
  61. /package/{lib → lib-dts}/TypeScriptPlugin.d.ts.map +0 -0
  62. /package/{lib → lib-dts}/configureProgramForMultiEmit.d.ts +0 -0
  63. /package/{lib → lib-dts}/configureProgramForMultiEmit.d.ts.map +0 -0
  64. /package/{lib → lib-dts}/fileSystem/TypeScriptCachedFileSystem.d.ts +0 -0
  65. /package/{lib → lib-dts}/fileSystem/TypeScriptCachedFileSystem.d.ts.map +0 -0
  66. /package/{lib → lib-dts}/index.d.ts +0 -0
  67. /package/{lib → lib-dts}/index.d.ts.map +0 -0
  68. /package/{lib → lib-dts}/internalTypings/TypeScriptInternals.d.ts +0 -0
  69. /package/{lib → lib-dts}/internalTypings/TypeScriptInternals.d.ts.map +0 -0
  70. /package/{lib → lib-dts}/loadTypeScriptTool.d.ts +0 -0
  71. /package/{lib → lib-dts}/loadTypeScriptTool.d.ts.map +0 -0
  72. /package/{lib → lib-dts}/tsconfigLoader.d.ts +0 -0
  73. /package/{lib → lib-dts}/tsconfigLoader.d.ts.map +0 -0
  74. /package/{lib → lib-dts}/types.d.ts +0 -0
  75. /package/{lib → lib-dts}/types.d.ts.map +0 -0
package/CHANGELOG.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@rushstack/heft-typescript-plugin",
3
3
  "entries": [
4
+ {
5
+ "version": "1.2.1",
6
+ "tag": "@rushstack/heft-typescript-plugin_v1.2.1",
7
+ "date": "Fri, 20 Feb 2026 00:15:04 GMT",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "comment": "Add `\"node\"` condition before `\"import\"` in the `\"exports\"` map so that Node.js uses the CJS output (which handles extensionless imports), while bundlers still use ESM via `\"import\"`. Fixes https://github.com/microsoft/rushstack/issues/5644."
12
+ }
13
+ ],
14
+ "dependency": [
15
+ {
16
+ "comment": "Updating dependency \"@rushstack/node-core-library\" to `5.20.1`"
17
+ },
18
+ {
19
+ "comment": "Updating dependency \"@rushstack/heft-config-file\" to `0.20.1`"
20
+ },
21
+ {
22
+ "comment": "Updating dependency \"@rushstack/heft\" to `1.2.1`"
23
+ },
24
+ {
25
+ "comment": "Updating dependency \"@rushstack/terminal\" to `0.22.1`"
26
+ },
27
+ {
28
+ "comment": "Updating dependency \"@rushstack/heft\" from `1.2.0` to `1.2.1`"
29
+ }
30
+ ]
31
+ }
32
+ },
33
+ {
34
+ "version": "1.2.0",
35
+ "tag": "@rushstack/heft-typescript-plugin_v1.2.0",
36
+ "date": "Thu, 19 Feb 2026 00:04:52 GMT",
37
+ "comments": {
38
+ "minor": [
39
+ {
40
+ "comment": "Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `\"exports\"` field in `package.json`."
41
+ }
42
+ ],
43
+ "dependency": [
44
+ {
45
+ "comment": "Updating dependency \"@rushstack/node-core-library\" to `5.20.0`"
46
+ },
47
+ {
48
+ "comment": "Updating dependency \"@rushstack/heft-config-file\" to `0.20.0`"
49
+ },
50
+ {
51
+ "comment": "Updating dependency \"@rushstack/heft\" to `1.2.0`"
52
+ },
53
+ {
54
+ "comment": "Updating dependency \"@rushstack/terminal\" to `0.22.0`"
55
+ },
56
+ {
57
+ "comment": "Updating dependency \"@rushstack/heft\" from `1.1.14` to `1.2.0`"
58
+ }
59
+ ]
60
+ }
61
+ },
4
62
  {
5
63
  "version": "1.1.14",
6
64
  "tag": "@rushstack/heft-typescript-plugin_v1.1.14",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Change Log - @rushstack/heft-typescript-plugin
2
2
 
3
- This log was last generated on Sat, 07 Feb 2026 01:13:26 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 20 Feb 2026 00:15:04 GMT and should not be manually modified.
4
+
5
+ ## 1.2.1
6
+ Fri, 20 Feb 2026 00:15:04 GMT
7
+
8
+ ### Patches
9
+
10
+ - Add `"node"` condition before `"import"` in the `"exports"` map so that Node.js uses the CJS output (which handles extensionless imports), while bundlers still use ESM via `"import"`. Fixes https://github.com/microsoft/rushstack/issues/5644.
11
+
12
+ ## 1.2.0
13
+ Thu, 19 Feb 2026 00:04:52 GMT
14
+
15
+ ### Minor changes
16
+
17
+ - Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `"exports"` field in `package.json`.
4
18
 
5
19
  ## 1.1.14
6
20
  Sat, 07 Feb 2026 01:13:26 GMT
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.55.2"
8
+ "packageVersion": "7.57.0"
9
9
  }
10
10
  ]
11
11
  }
package/heft-plugin.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "taskPlugins": [
5
5
  {
6
6
  "pluginName": "typescript-plugin",
7
- "entryPoint": "./lib/TypeScriptPlugin"
7
+ "entryPoint": "./lib-commonjs/TypeScriptPlugin"
8
8
  }
9
9
  ]
10
10
  }
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ export {};
4
+ //# sourceMappingURL=Performance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Performance.js","sourceRoot":"","sources":["../src/Performance.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport type PerformanceMeasurer = <TResult extends object | void>(\n measurementName: string,\n fn: () => TResult\n) => TResult & { duration: number };\n\nexport type PerformanceMeasurerAsync = <TResult extends object | void>(\n measurementName: string,\n fn: () => Promise<TResult>\n) => Promise<TResult & { duration: number }>;\n"]}
@@ -0,0 +1,92 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ import { parentPort, workerData } from 'node:worker_threads';
4
+ import { configureProgramForMultiEmit } from './configureProgramForMultiEmit';
5
+ const typedWorkerData = workerData;
6
+ const ts = require(typedWorkerData.typeScriptToolPath);
7
+ process.exitCode = 1;
8
+ function handleMessage(message) {
9
+ if (!message) {
10
+ parentPort.off('message', handleMessage);
11
+ parentPort.close();
12
+ return;
13
+ }
14
+ try {
15
+ const response = runTranspiler(message);
16
+ parentPort.postMessage(response);
17
+ }
18
+ catch (err) {
19
+ const errorResponse = {
20
+ requestId: message.requestId,
21
+ type: 'error',
22
+ result: {
23
+ message: err.message,
24
+ ...Object.fromEntries(Object.entries(err))
25
+ }
26
+ };
27
+ parentPort.postMessage(errorResponse);
28
+ }
29
+ }
30
+ function runTranspiler(message) {
31
+ const { requestId, compilerOptions, moduleKindsToEmit, filesToTranspile } = message;
32
+ const fullySkipTypeCheck =
33
+ /* TypeScript 5+ */ compilerOptions.verbatimModuleSyntax ||
34
+ /* TypeScript 4 */ compilerOptions.importsNotUsedAsValues === ts.ImportsNotUsedAsValues.Error;
35
+ for (const [option, value] of Object.entries(ts.getDefaultCompilerOptions())) {
36
+ if (compilerOptions[option] === undefined) {
37
+ compilerOptions[option] = value;
38
+ }
39
+ }
40
+ const { target: rawTarget } = compilerOptions;
41
+ for (const option of ts.transpileOptionValueCompilerOptions) {
42
+ compilerOptions[option.name] = option.transpileOptionValue;
43
+ }
44
+ compilerOptions.suppressOutputPathCheck = true;
45
+ compilerOptions.skipDefaultLibCheck = true;
46
+ // To fully disable the type checker, we have to set `hasNoDefaultLib: true` on every source file.
47
+ // However, doing so loses the information about which imports are used.
48
+ // To retain the imports, we use `preserveValueImports`. However, if some imports are only used for types,
49
+ // this will produce invalid runtime output unless said imports are marked with `type `.
50
+ // Thus we can only enable this optimization if `verbatimModuleSyntax` is enabled (or equivalent).
51
+ compilerOptions.preserveValueImports = fullySkipTypeCheck;
52
+ const sourceFileByPath = new Map();
53
+ const includedFiles = [];
54
+ for (const [fileName, sourceText] of filesToTranspile) {
55
+ if (sourceText) {
56
+ const sourceFile = ts.createSourceFile(fileName, sourceText, rawTarget);
57
+ sourceFile.hasNoDefaultLib = fullySkipTypeCheck;
58
+ sourceFileByPath.set(fileName, sourceFile);
59
+ includedFiles.push(fileName);
60
+ }
61
+ }
62
+ const newLine = ts.getNewLineCharacter(compilerOptions);
63
+ const compilerHost = {
64
+ getSourceFile: (fileName) => sourceFileByPath.get(fileName),
65
+ writeFile: ts.sys.writeFile,
66
+ getDefaultLibFileName: () => 'lib.d.ts',
67
+ useCaseSensitiveFileNames: () => true,
68
+ getCanonicalFileName: (fileName) => fileName,
69
+ getCurrentDirectory: () => '',
70
+ getNewLine: () => newLine,
71
+ fileExists: (fileName) => sourceFileByPath.has(fileName),
72
+ readFile: () => '',
73
+ directoryExists: () => true,
74
+ getDirectories: () => []
75
+ };
76
+ const program = ts.createProgram(includedFiles, compilerOptions, compilerHost);
77
+ configureProgramForMultiEmit(program, ts, moduleKindsToEmit, 'transpile');
78
+ const result = program.emit(undefined,
79
+ // The writeFile callback must be provided for the multi-emit redirector
80
+ ts.sys.writeFile, undefined, undefined, undefined);
81
+ const response = {
82
+ requestId,
83
+ type: 'success',
84
+ result
85
+ };
86
+ return response;
87
+ }
88
+ parentPort.once('close', () => {
89
+ process.exitCode = 0;
90
+ });
91
+ parentPort.on('message', handleMessage);
92
+ //# sourceMappingURL=TranspilerWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TranspilerWorker.js","sourceRoot":"","sources":["../src/TranspilerWorker.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAW7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E,MAAM,eAAe,GAA0B,UAAU,CAAC;AAE1D,MAAM,EAAE,GAAuB,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;AAE3E,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AA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AmB,EAAE,GAAG,EAAE,CAAC,EAAE;QAC7B,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO;QACzB,UAAU,EAAE,CAAC,QAAgB,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC;QAChE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE;QAClB,eAAe,EAAE,GAAG,EAAE,CAAC,IAAI;QAC3B,cAAc,EAAE,GAAG,EAAE,CAAC,EAAE;KACzB,CAAC;IAEF,MAAM,OAAO,GAAwB,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;IAEpG,4BAA4B,CAAC,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,WAAW,CAAC,CAAC;IAE1E,MAAM,MAAM,GAA2B,OAAO,CAAC,IAAI,CACjD,SAAS;IACT,wEAAwE;IACxE,EAAE,CAAC,GAAG,CAAC,SAAS,EAChB,SAAS,EACT,SAAS,EACT,SAAS,CACV,CAAC;IAEF,MAAM,QAAQ,GAAiC;QAC7C,SAAS;QACT,IAAI,EAAE,SAAS;QACf,MAAM;KACP,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,UAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;IAC7B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC;AACH,UAAW,CAAC,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { parentPort, workerData } from 'node:worker_threads';\n\nimport type * as TTypescript from 'typescript';\n\nimport type {\n ITranspilationErrorMessage,\n ITranspilationRequestMessage,\n ITranspilationSuccessMessage,\n ITypescriptWorkerData\n} from './types';\nimport type { ExtendedTypeScript } from './internalTypings/TypeScriptInternals';\nimport { configureProgramForMultiEmit } from './configureProgramForMultiEmit';\n\nconst typedWorkerData: ITypescriptWorkerData = workerData;\n\nconst ts: ExtendedTypeScript = require(typedWorkerData.typeScriptToolPath);\n\nprocess.exitCode = 1;\n\nfunction handleMessage(message: ITranspilationRequestMessage | false): void {\n if (!message) {\n parentPort!.off('message', handleMessage);\n parentPort!.close();\n return;\n }\n\n try {\n const response: ITranspilationSuccessMessage = runTranspiler(message);\n parentPort!.postMessage(response);\n } catch (err) {\n const errorResponse: ITranspilationErrorMessage = {\n requestId: message.requestId,\n type: 'error',\n result: {\n message: err.message,\n ...Object.fromEntries(Object.entries(err))\n }\n };\n parentPort!.postMessage(errorResponse);\n }\n}\n\nfunction runTranspiler(message: ITranspilationRequestMessage): ITranspilationSuccessMessage {\n const { requestId, compilerOptions, moduleKindsToEmit, filesToTranspile } = message;\n\n const fullySkipTypeCheck: boolean =\n /* TypeScript 5+ */ compilerOptions.verbatimModuleSyntax ||\n /* TypeScript 4 */ compilerOptions.importsNotUsedAsValues === ts.ImportsNotUsedAsValues.Error;\n\n for (const [option, value] of Object.entries(ts.getDefaultCompilerOptions())) {\n if (compilerOptions[option] === undefined) {\n compilerOptions[option] = value;\n }\n }\n\n const { target: rawTarget } = compilerOptions;\n\n for (const option of ts.transpileOptionValueCompilerOptions) {\n compilerOptions[option.name] = option.transpileOptionValue;\n }\n\n compilerOptions.suppressOutputPathCheck = true;\n compilerOptions.skipDefaultLibCheck = true;\n // To fully disable the type checker, we have to set `hasNoDefaultLib: true` on every source file.\n // However, doing so loses the information about which imports are used.\n // To retain the imports, we use `preserveValueImports`. However, if some imports are only used for types,\n // this will produce invalid runtime output unless said imports are marked with `type `.\n // Thus we can only enable this optimization if `verbatimModuleSyntax` is enabled (or equivalent).\n compilerOptions.preserveValueImports = fullySkipTypeCheck;\n\n const sourceFileByPath: Map<string, TTypescript.SourceFile> = new Map();\n\n const includedFiles: string[] = [];\n for (const [fileName, sourceText] of filesToTranspile) {\n if (sourceText) {\n const sourceFile: TTypescript.SourceFile = ts.createSourceFile(fileName, sourceText, rawTarget!);\n sourceFile.hasNoDefaultLib = fullySkipTypeCheck;\n sourceFileByPath.set(fileName, sourceFile);\n includedFiles.push(fileName);\n }\n }\n\n const newLine: string = ts.getNewLineCharacter(compilerOptions);\n\n const compilerHost: TTypescript.CompilerHost = {\n getSourceFile: (fileName: string) => sourceFileByPath.get(fileName),\n writeFile: ts.sys.writeFile,\n getDefaultLibFileName: () => 'lib.d.ts',\n useCaseSensitiveFileNames: () => true,\n getCanonicalFileName: (fileName: string) => fileName,\n getCurrentDirectory: () => '',\n getNewLine: () => newLine,\n fileExists: (fileName: string) => sourceFileByPath.has(fileName),\n readFile: () => '',\n directoryExists: () => true,\n getDirectories: () => []\n };\n\n const program: TTypescript.Program = ts.createProgram(includedFiles, compilerOptions, compilerHost);\n\n configureProgramForMultiEmit(program, ts, moduleKindsToEmit, 'transpile');\n\n const result: TTypescript.EmitResult = program.emit(\n undefined,\n // The writeFile callback must be provided for the multi-emit redirector\n ts.sys.writeFile,\n undefined,\n undefined,\n undefined\n );\n\n const response: ITranspilationSuccessMessage = {\n requestId,\n type: 'success',\n result\n };\n\n return response;\n}\n\nparentPort!.once('close', () => {\n process.exitCode = 0;\n});\nparentPort!.on('message', handleMessage);\n"]}