@rushstack/heft-typescript-plugin 0.0.0
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/LICENSE +24 -0
- package/README.md +12 -0
- package/dist/heft-typescript-plugin.d.ts +110 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/heft-plugin.json +10 -0
- package/lib/Performance.d.ts +7 -0
- package/lib/Performance.d.ts.map +1 -0
- package/lib/Performance.js +5 -0
- package/lib/Performance.js.map +1 -0
- package/lib/TranspilerWorker.d.ts +2 -0
- package/lib/TranspilerWorker.d.ts.map +1 -0
- package/lib/TranspilerWorker.js +85 -0
- package/lib/TranspilerWorker.js.map +1 -0
- package/lib/TypeScriptBuilder.d.ts +96 -0
- package/lib/TypeScriptBuilder.d.ts.map +1 -0
- package/lib/TypeScriptBuilder.js +790 -0
- package/lib/TypeScriptBuilder.js.map +1 -0
- package/lib/TypeScriptPlugin.d.ts +100 -0
- package/lib/TypeScriptPlugin.d.ts.map +1 -0
- package/lib/TypeScriptPlugin.js +219 -0
- package/lib/TypeScriptPlugin.js.map +1 -0
- package/lib/configureProgramForMultiEmit.d.ts +7 -0
- package/lib/configureProgramForMultiEmit.d.ts.map +1 -0
- package/lib/configureProgramForMultiEmit.js +99 -0
- package/lib/configureProgramForMultiEmit.js.map +1 -0
- package/lib/fileSystem/TypeScriptCachedFileSystem.d.ts +36 -0
- package/lib/fileSystem/TypeScriptCachedFileSystem.d.ts.map +1 -0
- package/lib/fileSystem/TypeScriptCachedFileSystem.js +163 -0
- package/lib/fileSystem/TypeScriptCachedFileSystem.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/internalTypings/TypeScriptInternals.d.ts +56 -0
- package/lib/internalTypings/TypeScriptInternals.d.ts.map +1 -0
- package/lib/internalTypings/TypeScriptInternals.js +5 -0
- package/lib/internalTypings/TypeScriptInternals.js.map +1 -0
- package/lib/schemas/anything.schema.json +28 -0
- package/lib/schemas/typescript.schema.json +101 -0
- package/lib/types.d.ts +54 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@rushstack/heft-typescript-plugin
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be
|
|
16
|
+
included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @rushstack/heft-typescript-plugin
|
|
2
|
+
|
|
3
|
+
This is a Heft plugin for compiling TypeScript.
|
|
4
|
+
|
|
5
|
+
## Links
|
|
6
|
+
|
|
7
|
+
- [CHANGELOG.md](
|
|
8
|
+
https://github.com/microsoft/rushstack/blob/main/heft-plugins/heft-typescript-plugin/CHANGELOG.md) - Find
|
|
9
|
+
out what's new in the latest version
|
|
10
|
+
- [@rushstack/heft](https://www.npmjs.com/package/@rushstack/heft) - Heft is a config-driven toolchain that invokes popular tools such as TypeScript, ESLint, Jest, Webpack, and API Extractor.
|
|
11
|
+
|
|
12
|
+
Heft is part of the [Rush Stack](https://rushstack.io/) family of projects.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Heft plugin for using TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { HeftConfiguration } from '@rushstack/heft';
|
|
8
|
+
import { ITerminal } from '@rushstack/node-core-library';
|
|
9
|
+
import { SyncHook } from 'tapable';
|
|
10
|
+
import type * as TTypescript from 'typescript';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
export declare interface IChangedFilesHookOptions {
|
|
16
|
+
program: TTypescript.Program;
|
|
17
|
+
changedFiles?: ReadonlySet<TTypescript.SourceFile>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @beta
|
|
22
|
+
*/
|
|
23
|
+
export declare interface IEmitModuleKind {
|
|
24
|
+
moduleKind: 'commonjs' | 'amd' | 'umd' | 'system' | 'es2015' | 'esnext';
|
|
25
|
+
outFolderName: string;
|
|
26
|
+
jsExtensionOverride?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
export declare interface IPartialTsconfig {
|
|
33
|
+
compilerOptions?: IPartialTsconfigCompilerOptions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @beta
|
|
38
|
+
*/
|
|
39
|
+
export declare interface IPartialTsconfigCompilerOptions {
|
|
40
|
+
outDir?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @beta
|
|
45
|
+
*/
|
|
46
|
+
export declare interface IStaticAssetsCopyConfiguration {
|
|
47
|
+
fileExtensions: string[];
|
|
48
|
+
excludeGlobs: string[];
|
|
49
|
+
includeGlobs: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @beta
|
|
54
|
+
*/
|
|
55
|
+
export declare interface ITypeScriptConfigurationJson {
|
|
56
|
+
/**
|
|
57
|
+
* If provided, emit these module kinds in addition to the modules specified in the tsconfig.
|
|
58
|
+
* Note that this option only applies to the main tsconfig.json configuration.
|
|
59
|
+
*/
|
|
60
|
+
additionalModuleKindsToEmit?: IEmitModuleKind[] | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* If 'true', emit CommonJS output into the TSConfig outDir with the file extension '.cjs'
|
|
63
|
+
*/
|
|
64
|
+
emitCjsExtensionForCommonJS?: boolean | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* If 'true', emit ESModule output into the TSConfig outDir with the file extension '.mjs'
|
|
67
|
+
*/
|
|
68
|
+
emitMjsExtensionForESModule?: boolean | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* If true, enable behavior analogous to the "tsc --build" command. Will build projects referenced by the main project in dependency order.
|
|
71
|
+
* Note that this will effectively enable \"noEmitOnError\".
|
|
72
|
+
*/
|
|
73
|
+
buildProjectReferences?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* If true, and the tsconfig has \"isolatedModules\": true, then transpilation will happen in parallel in a worker thread.
|
|
76
|
+
*/
|
|
77
|
+
useTranspilerWorker?: boolean;
|
|
78
|
+
project?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Configures additional file types that should be copied into the TypeScript compiler's emit folders, for example
|
|
81
|
+
* so that these files can be resolved by import statements.
|
|
82
|
+
*/
|
|
83
|
+
staticAssetsToCopy?: IStaticAssetsCopyConfiguration;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @beta
|
|
88
|
+
*/
|
|
89
|
+
export declare interface ITypeScriptPluginAccessor {
|
|
90
|
+
readonly onChangedFilesHook: SyncHook<IChangedFilesHookOptions>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @beta
|
|
95
|
+
*/
|
|
96
|
+
export declare function loadPartialTsconfigFileAsync(heftConfiguration: HeftConfiguration, terminal: ITerminal, typeScriptConfigurationJson: ITypeScriptConfigurationJson | undefined): Promise<IPartialTsconfig | undefined>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @beta
|
|
100
|
+
*/
|
|
101
|
+
export declare function loadTypeScriptConfigurationFileAsync(heftConfiguration: HeftConfiguration, terminal: ITerminal): Promise<ITypeScriptConfigurationJson | undefined>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The name of the plugin, as specified in heft-plugin.json
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export declare const TypeScriptPluginName: 'typescript-plugin';
|
|
109
|
+
|
|
110
|
+
export { }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.35.0"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/heft-plugin.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type PerformanceMeasurer = <TResult extends object | void>(measurementName: string, fn: () => TResult) => TResult & {
|
|
2
|
+
duration: number;
|
|
3
|
+
};
|
|
4
|
+
export type PerformanceMeasurerAsync = <TResult extends object | void>(measurementName: string, fn: () => Promise<TResult>) => Promise<TResult & {
|
|
5
|
+
duration: number;
|
|
6
|
+
}>;
|
|
7
|
+
//# sourceMappingURL=Performance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Performance.d.ts","sourceRoot":"","sources":["../src/Performance.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,SAAS,MAAM,GAAG,IAAI,EAC9D,eAAe,EAAE,MAAM,EACvB,EAAE,EAAE,MAAM,OAAO,KACd,OAAO,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpC,MAAM,MAAM,wBAAwB,GAAG,CAAC,OAAO,SAAS,MAAM,GAAG,IAAI,EACnE,eAAe,EAAE,MAAM,EACvB,EAAE,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,KACvB,OAAO,CAAC,OAAO,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
//# 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 @@
|
|
|
1
|
+
{"version":3,"file":"TranspilerWorker.d.ts","sourceRoot":"","sources":["../src/TranspilerWorker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
4
|
+
// See LICENSE in the project root for license information.
|
|
5
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
6
|
+
const configureProgramForMultiEmit_1 = require("./configureProgramForMultiEmit");
|
|
7
|
+
const typedWorkerData = node_worker_threads_1.workerData;
|
|
8
|
+
const ts = require(typedWorkerData.typeScriptToolPath);
|
|
9
|
+
function handleMessage(message) {
|
|
10
|
+
if (!message) {
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const response = runTranspiler(message);
|
|
15
|
+
node_worker_threads_1.parentPort.postMessage(response);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
const errorResponse = {
|
|
19
|
+
requestId: message.requestId,
|
|
20
|
+
type: 'error',
|
|
21
|
+
result: Object.assign({ message: err.message }, Object.fromEntries(Object.entries(err)))
|
|
22
|
+
};
|
|
23
|
+
node_worker_threads_1.parentPort.postMessage(errorResponse);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function runTranspiler(message) {
|
|
27
|
+
const { requestId, compilerOptions, moduleKindsToEmit, filesToTranspile } = message;
|
|
28
|
+
const fullySkipTypeCheck =
|
|
29
|
+
/* TypeScript 5+ */ compilerOptions.verbatimModuleSyntax ||
|
|
30
|
+
/* TypeScript 4 */ compilerOptions.importsNotUsedAsValues === ts.ImportsNotUsedAsValues.Error;
|
|
31
|
+
for (const [option, value] of Object.entries(ts.getDefaultCompilerOptions())) {
|
|
32
|
+
if (compilerOptions[option] === undefined) {
|
|
33
|
+
compilerOptions[option] = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const { target: rawTarget } = compilerOptions;
|
|
37
|
+
for (const option of ts.transpileOptionValueCompilerOptions) {
|
|
38
|
+
compilerOptions[option.name] = option.transpileOptionValue;
|
|
39
|
+
}
|
|
40
|
+
compilerOptions.suppressOutputPathCheck = true;
|
|
41
|
+
compilerOptions.skipDefaultLibCheck = true;
|
|
42
|
+
// To fully disable the type checker, we have to set `hasNoDefaultLib: true` on every source file.
|
|
43
|
+
// However, doing so loses the information about which imports are used.
|
|
44
|
+
// To retain the imports, we use `preserveValueImports`. However, if some imports are only used for types,
|
|
45
|
+
// this will produce invalid runtime output unless said imports are marked with `type `.
|
|
46
|
+
// Thus we can only enable this optimization if `verbatimModuleSyntax` is enabled (or equivalent).
|
|
47
|
+
compilerOptions.preserveValueImports = fullySkipTypeCheck;
|
|
48
|
+
const sourceFileByPath = new Map();
|
|
49
|
+
const includedFiles = [];
|
|
50
|
+
for (const [fileName, sourceText] of filesToTranspile) {
|
|
51
|
+
if (sourceText) {
|
|
52
|
+
const sourceFile = ts.createSourceFile(fileName, sourceText, rawTarget);
|
|
53
|
+
sourceFile.hasNoDefaultLib = fullySkipTypeCheck;
|
|
54
|
+
sourceFileByPath.set(fileName, sourceFile);
|
|
55
|
+
includedFiles.push(fileName);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const newLine = ts.getNewLineCharacter(compilerOptions);
|
|
59
|
+
const compilerHost = {
|
|
60
|
+
getSourceFile: (fileName) => sourceFileByPath.get(fileName),
|
|
61
|
+
writeFile: ts.sys.writeFile,
|
|
62
|
+
getDefaultLibFileName: () => 'lib.d.ts',
|
|
63
|
+
useCaseSensitiveFileNames: () => true,
|
|
64
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
65
|
+
getCurrentDirectory: () => '',
|
|
66
|
+
getNewLine: () => newLine,
|
|
67
|
+
fileExists: (fileName) => sourceFileByPath.has(fileName),
|
|
68
|
+
readFile: () => '',
|
|
69
|
+
directoryExists: () => true,
|
|
70
|
+
getDirectories: () => []
|
|
71
|
+
};
|
|
72
|
+
const program = ts.createProgram(includedFiles, compilerOptions, compilerHost);
|
|
73
|
+
(0, configureProgramForMultiEmit_1.configureProgramForMultiEmit)(program, ts, moduleKindsToEmit, 'transpile');
|
|
74
|
+
const result = program.emit(undefined,
|
|
75
|
+
// The writeFile callback must be provided for the multi-emit redirector
|
|
76
|
+
ts.sys.writeFile, undefined, undefined, undefined);
|
|
77
|
+
const response = {
|
|
78
|
+
requestId,
|
|
79
|
+
type: 'success',
|
|
80
|
+
result
|
|
81
|
+
};
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
node_worker_threads_1.parentPort.on('message', handleMessage);
|
|
85
|
+
//# sourceMappingURL=TranspilerWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranspilerWorker.js","sourceRoot":"","sources":["../src/TranspilerWorker.ts"],"names":[],"mappings":";;AAAA,4FAA4F;AAC5F,2DAA2D;AAC3D,6DAA6D;AAU7D,iFAA8E;AAE9E,MAAM,eAAe,GAA0B,gCAAU,CAAC;AAE1D,MAAM,EAAE,GAAuB,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;AAE3E,SAAS,aAAa,CAAC,OAA6C;IAClE,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,IAAI;QACF,MAAM,QAAQ,GAAiC,aAAa,CAAC,OAAO,CAAC,CAAC;QACtE,gCAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;KACnC;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,aAAa,GAA+B;YAChD,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,IAAI,EAAE,OAAO;YACb,MAAM,kBACJ,OAAO,EAAE,GAAG,CAAC,OAAO,IACjB,MAAM,CAAC,WAAW,CAAC,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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,gCAAW,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.\nimport { parentPort, workerData } from 'node:worker_threads';\n\nimport type * as TTypescript from 'typescript';\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\nfunction handleMessage(message: ITranspilationRequestMessage | false): void {\n if (!message) {\n process.exit(0);\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!.on('message', handleMessage);\n"]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Worker } from 'worker_threads';
|
|
3
|
+
import type * as TTypescript from 'typescript';
|
|
4
|
+
import type { IScopedLogger } from '@rushstack/heft';
|
|
5
|
+
import type { ExtendedTypeScript, IExtendedSolutionBuilder } from './internalTypings/TypeScriptInternals';
|
|
6
|
+
import type { ITypeScriptConfigurationJson } from './TypeScriptPlugin';
|
|
7
|
+
import type { PerformanceMeasurer } from './Performance';
|
|
8
|
+
export interface ITypeScriptBuilderConfiguration extends ITypeScriptConfigurationJson {
|
|
9
|
+
/**
|
|
10
|
+
* The root folder of the build.
|
|
11
|
+
*/
|
|
12
|
+
buildFolderPath: string;
|
|
13
|
+
/**
|
|
14
|
+
* The folder to write build metadata.
|
|
15
|
+
*/
|
|
16
|
+
buildMetadataFolderPath: string;
|
|
17
|
+
/**
|
|
18
|
+
* The path to the TypeScript tool.
|
|
19
|
+
*/
|
|
20
|
+
typeScriptToolPath: string;
|
|
21
|
+
/**
|
|
22
|
+
* The path to the tsconfig file being built.
|
|
23
|
+
*/
|
|
24
|
+
tsconfigPath: string;
|
|
25
|
+
/**
|
|
26
|
+
* The scoped logger that the builder will log to.
|
|
27
|
+
*/
|
|
28
|
+
scopedLogger: IScopedLogger;
|
|
29
|
+
/**
|
|
30
|
+
* The callback used to emit the typescript program (or programs) from the builder.
|
|
31
|
+
*/
|
|
32
|
+
emitChangedFilesCallback: (program: TTypescript.Program, changedFiles?: Set<TTypescript.SourceFile>) => void;
|
|
33
|
+
}
|
|
34
|
+
type TWatchProgram = TTypescript.WatchOfFilesAndCompilerOptions<TTypescript.EmitAndSemanticDiagnosticsBuilderProgram>;
|
|
35
|
+
interface IPendingWork {
|
|
36
|
+
(): void;
|
|
37
|
+
}
|
|
38
|
+
interface ITranspileSignal {
|
|
39
|
+
resolve: (result: TTypescript.EmitResult) => void;
|
|
40
|
+
reject: (error: Error) => void;
|
|
41
|
+
}
|
|
42
|
+
interface ITypeScriptTool {
|
|
43
|
+
ts: ExtendedTypeScript;
|
|
44
|
+
measureSync: PerformanceMeasurer;
|
|
45
|
+
sourceFileCache: Map<string, TTypescript.SourceFile>;
|
|
46
|
+
watchProgram: TWatchProgram | undefined;
|
|
47
|
+
solutionBuilder: IExtendedSolutionBuilder | undefined;
|
|
48
|
+
rawDiagnostics: TTypescript.Diagnostic[];
|
|
49
|
+
pendingOperations: Set<IPendingWork>;
|
|
50
|
+
executing: boolean;
|
|
51
|
+
worker: Worker | undefined;
|
|
52
|
+
pendingTranspilePromises: Map<number, Promise<TTypescript.EmitResult>>;
|
|
53
|
+
pendingTranspileSignals: Map<number, ITranspileSignal>;
|
|
54
|
+
reportDiagnostic: TTypescript.DiagnosticReporter;
|
|
55
|
+
clearTimeout: (timeout: IPendingWork) => void;
|
|
56
|
+
setTimeout: <T extends unknown[]>(timeout: (...args: T) => void, ms: number, ...args: T) => IPendingWork;
|
|
57
|
+
}
|
|
58
|
+
export declare class TypeScriptBuilder {
|
|
59
|
+
private readonly _configuration;
|
|
60
|
+
private readonly _typescriptLogger;
|
|
61
|
+
private readonly _typescriptTerminal;
|
|
62
|
+
private _typescriptVersion;
|
|
63
|
+
private _typescriptParsedVersion;
|
|
64
|
+
private _capabilities;
|
|
65
|
+
private _useSolutionBuilder;
|
|
66
|
+
private _moduleKindsToEmit;
|
|
67
|
+
private readonly _suppressedDiagnosticCodes;
|
|
68
|
+
private __tsCacheFilePath;
|
|
69
|
+
private _tool;
|
|
70
|
+
private _nextRequestId;
|
|
71
|
+
private get _tsCacheFilePath();
|
|
72
|
+
constructor(configuration: ITypeScriptBuilderConfiguration);
|
|
73
|
+
invokeAsync(onChangeDetected?: () => void): Promise<void>;
|
|
74
|
+
_runWatchAsync(tool: ITypeScriptTool): Promise<void>;
|
|
75
|
+
_runBuildAsync(tool: ITypeScriptTool): Promise<void>;
|
|
76
|
+
_runSolutionBuildAsync(tool: ITypeScriptTool): Promise<void>;
|
|
77
|
+
private _logDiagnostics;
|
|
78
|
+
private _logEmitPerformance;
|
|
79
|
+
private _logReadPerformance;
|
|
80
|
+
private _printDiagnosticMessage;
|
|
81
|
+
private _getAdjustedDiagnosticCategory;
|
|
82
|
+
private _validateTsconfig;
|
|
83
|
+
private _addModuleKindToEmit;
|
|
84
|
+
private _loadTsconfig;
|
|
85
|
+
private _getCreateBuilderProgram;
|
|
86
|
+
private _buildSolutionBuilderHost;
|
|
87
|
+
private _buildIncrementalCompilerHost;
|
|
88
|
+
private _buildWatchCompilerHost;
|
|
89
|
+
private _changeCompilerHostToUseCache;
|
|
90
|
+
private _buildWatchSolutionBuilderHost;
|
|
91
|
+
private _parseModuleKind;
|
|
92
|
+
private _queueTranspileInWorker;
|
|
93
|
+
private _cleanupWorker;
|
|
94
|
+
}
|
|
95
|
+
export {};
|
|
96
|
+
//# sourceMappingURL=TypeScriptBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptBuilder.d.ts","sourceRoot":"","sources":["../src/TypeScriptBuilder.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,KAAK,KAAK,WAAW,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAC1G,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AASzD,MAAM,WAAW,+BAAgC,SAAQ,4BAA4B;IACnF;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,uBAAuB,EAAE,MAAM,CAAC;IAEhC;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAI3B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,YAA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