@rushstack/heft-typescript-plugin 0.1.0-dev.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 +111 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/heft-plugin.json +10 -0
- package/lib/EmitFilesPatch.d.ts +28 -0
- package/lib/EmitFilesPatch.d.ts.map +1 -0
- package/lib/EmitFilesPatch.js +99 -0
- package/lib/EmitFilesPatch.js.map +1 -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/TypeScriptBuilder.d.ts +69 -0
- package/lib/TypeScriptBuilder.d.ts.map +1 -0
- package/lib/TypeScriptBuilder.js +681 -0
- package/lib/TypeScriptBuilder.js.map +1 -0
- package/lib/TypeScriptPlugin.d.ts +102 -0
- package/lib/TypeScriptPlugin.d.ts.map +1 -0
- package/lib/TypeScriptPlugin.js +191 -0
- package/lib/TypeScriptPlugin.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 +90 -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/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,111 @@
|
|
|
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
|
+
project?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Configures additional file types that should be copied into the TypeScript compiler's emit folders, for example
|
|
77
|
+
* so that these files can be resolved by import statements.
|
|
78
|
+
*/
|
|
79
|
+
staticAssetsToCopy?: IStaticAssetsCopyConfiguration;
|
|
80
|
+
/**
|
|
81
|
+
* Set this to change the maximum number of file handles that will be opened concurrently for writing.
|
|
82
|
+
* The default is 50.
|
|
83
|
+
*/
|
|
84
|
+
maxWriteParallelism?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @beta
|
|
89
|
+
*/
|
|
90
|
+
export declare interface ITypeScriptPluginAccessor {
|
|
91
|
+
readonly onChangedFilesHook: SyncHook<IChangedFilesHookOptions>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @beta
|
|
96
|
+
*/
|
|
97
|
+
export declare function loadPartialTsconfigFileAsync(heftConfiguration: HeftConfiguration, terminal: ITerminal, typeScriptConfigurationJson: ITypeScriptConfigurationJson | undefined): Promise<IPartialTsconfig | undefined>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @beta
|
|
101
|
+
*/
|
|
102
|
+
export declare function loadTypeScriptConfigurationFileAsync(heftConfiguration: HeftConfiguration, terminal: ITerminal): Promise<ITypeScriptConfigurationJson | undefined>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The name of the plugin, as specified in heft-plugin.json
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export declare const TypeScriptPluginName: 'TypeScriptPlugin';
|
|
110
|
+
|
|
111
|
+
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.29.0"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/heft-plugin.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as TTypescript from 'typescript';
|
|
2
|
+
import { ExtendedTypeScript } from './internalTypings/TypeScriptInternals';
|
|
3
|
+
export interface ICachedEmitModuleKind {
|
|
4
|
+
moduleKind: TTypescript.ModuleKind;
|
|
5
|
+
outFolderPath: string;
|
|
6
|
+
/**
|
|
7
|
+
* File extension to use instead of '.js' for emitted ECMAScript files.
|
|
8
|
+
* For example, '.cjs' to indicate commonjs content, or '.mjs' to indicate ECMAScript modules.
|
|
9
|
+
*/
|
|
10
|
+
jsExtensionOverride: string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Set to true if this is the emit kind that is specified in the tsconfig.json.
|
|
13
|
+
* Declarations are only emitted for the primary module kind.
|
|
14
|
+
*/
|
|
15
|
+
isPrimary: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class EmitFilesPatch {
|
|
18
|
+
private static _patchedTs;
|
|
19
|
+
private static _baseEmitFiles;
|
|
20
|
+
static install(ts: ExtendedTypeScript, tsconfig: TTypescript.ParsedCommandLine, moduleKindsToEmit: ICachedEmitModuleKind[], changedFiles?: Set<TTypescript.SourceFile>): void;
|
|
21
|
+
static get isInstalled(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Wraps the writeFile callback on the IEmitHost to override the .js extension, if applicable
|
|
24
|
+
*/
|
|
25
|
+
static wrapWriteFile(baseWriteFile: TTypescript.WriteFileCallback, jsExtensionOverride: string | undefined): TTypescript.WriteFileCallback;
|
|
26
|
+
static uninstall(ts: ExtendedTypeScript): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=EmitFilesPatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmitFilesPatch.d.ts","sourceRoot":"","sources":["../src/EmitFilesPatch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,WAAW,MAAM,YAAY,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAInB,MAAM,uCAAuC,CAAC;AAE/C,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,WAAW,CAAC,UAAU,CAAC;IAEnC,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,UAAU,CAA6C;IAEtE,OAAO,CAAC,MAAM,CAAC,cAAc,CAA8B;WAE7C,OAAO,CACnB,EAAE,EAAE,kBAAkB,EACtB,QAAQ,EAAE,WAAW,CAAC,iBAAiB,EACvC,iBAAiB,EAAE,qBAAqB,EAAE,EAC1C,YAAY,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,GACzC,IAAI;IAsHP,WAAkB,WAAW,IAAI,OAAO,CAEvC;IAED;;OAEG;WACW,aAAa,CACzB,aAAa,EAAE,WAAW,CAAC,iBAAiB,EAC5C,mBAAmB,EAAE,MAAM,GAAG,SAAS,GACtC,WAAW,CAAC,iBAAiB;WAuBlB,SAAS,CAAC,EAAE,EAAE,kBAAkB,GAAG,IAAI;CAatD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
exports.EmitFilesPatch = void 0;
|
|
6
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
7
|
+
class EmitFilesPatch {
|
|
8
|
+
static install(ts, tsconfig, moduleKindsToEmit, changedFiles) {
|
|
9
|
+
if (EmitFilesPatch._patchedTs === ts) {
|
|
10
|
+
// We already patched this instance of TS
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (EmitFilesPatch._patchedTs !== undefined) {
|
|
14
|
+
throw new node_core_library_1.InternalError('EmitFilesPatch.install() cannot be called without first uninstalling the existing patch');
|
|
15
|
+
}
|
|
16
|
+
EmitFilesPatch._patchedTs = ts;
|
|
17
|
+
EmitFilesPatch._baseEmitFiles = ts.emitFiles;
|
|
18
|
+
let foundPrimary = false;
|
|
19
|
+
let defaultModuleKind;
|
|
20
|
+
for (const moduleKindToEmit of moduleKindsToEmit) {
|
|
21
|
+
if (moduleKindToEmit.isPrimary) {
|
|
22
|
+
if (foundPrimary) {
|
|
23
|
+
throw new Error('Multiple primary module emit kinds encountered.');
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
foundPrimary = true;
|
|
27
|
+
}
|
|
28
|
+
defaultModuleKind = moduleKindToEmit.moduleKind;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const patchedEmitFiles = (resolver, host, targetSourceFile, emitTransformers, emitOnlyDtsFiles, onlyBuildInfo, forceDtsEmit) => {
|
|
32
|
+
if (onlyBuildInfo || emitOnlyDtsFiles) {
|
|
33
|
+
// There should only be one tsBuildInfo and one set of declaration files
|
|
34
|
+
return EmitFilesPatch._baseEmitFiles(resolver, host, targetSourceFile, emitTransformers, emitOnlyDtsFiles, onlyBuildInfo, forceDtsEmit);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (targetSourceFile && changedFiles) {
|
|
38
|
+
changedFiles.add(targetSourceFile);
|
|
39
|
+
}
|
|
40
|
+
let defaultModuleKindResult;
|
|
41
|
+
const diagnostics = [];
|
|
42
|
+
let emitSkipped = false;
|
|
43
|
+
for (const moduleKindToEmit of moduleKindsToEmit) {
|
|
44
|
+
const compilerOptions = moduleKindToEmit.isPrimary
|
|
45
|
+
? Object.assign({}, tsconfig.options) : Object.assign(Object.assign({}, tsconfig.options), { module: moduleKindToEmit.moduleKind, outDir: moduleKindToEmit.outFolderPath,
|
|
46
|
+
// Don't emit declarations for secondary module kinds
|
|
47
|
+
declaration: false, declarationMap: false });
|
|
48
|
+
if (!compilerOptions.outDir) {
|
|
49
|
+
throw new node_core_library_1.InternalError('Expected compilerOptions.outDir to be assigned');
|
|
50
|
+
}
|
|
51
|
+
const flavorResult = EmitFilesPatch._baseEmitFiles(resolver, Object.assign(Object.assign({}, host), { writeFile: EmitFilesPatch.wrapWriteFile(host.writeFile, moduleKindToEmit.jsExtensionOverride), getCompilerOptions: () => compilerOptions }), targetSourceFile, ts.getTransformers(compilerOptions, undefined, emitOnlyDtsFiles), emitOnlyDtsFiles, onlyBuildInfo, forceDtsEmit);
|
|
52
|
+
emitSkipped = emitSkipped || flavorResult.emitSkipped;
|
|
53
|
+
for (const diagnostic of flavorResult.diagnostics) {
|
|
54
|
+
diagnostics.push(diagnostic);
|
|
55
|
+
}
|
|
56
|
+
if (moduleKindToEmit.moduleKind === defaultModuleKind) {
|
|
57
|
+
defaultModuleKindResult = flavorResult;
|
|
58
|
+
}
|
|
59
|
+
// Should results be aggregated, in case for whatever reason the diagnostics are not the same?
|
|
60
|
+
}
|
|
61
|
+
const mergedDiagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics);
|
|
62
|
+
return Object.assign(Object.assign({}, defaultModuleKindResult), { diagnostics: mergedDiagnostics, emitSkipped });
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// Override the underlying file emitter to run itself once for each flavor
|
|
66
|
+
// This is a rather inelegant way to convince the TypeScript compiler not to duplicate parse/link/check
|
|
67
|
+
ts.emitFiles = patchedEmitFiles;
|
|
68
|
+
}
|
|
69
|
+
static get isInstalled() {
|
|
70
|
+
return this._patchedTs !== undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Wraps the writeFile callback on the IEmitHost to override the .js extension, if applicable
|
|
74
|
+
*/
|
|
75
|
+
static wrapWriteFile(baseWriteFile, jsExtensionOverride) {
|
|
76
|
+
if (!jsExtensionOverride) {
|
|
77
|
+
return baseWriteFile;
|
|
78
|
+
}
|
|
79
|
+
const replacementExtension = `${jsExtensionOverride}$1`;
|
|
80
|
+
return (fileName, data, writeBOM, onError, sourceFiles) => {
|
|
81
|
+
return baseWriteFile(fileName.replace(/\.js(\.map)?$/g, replacementExtension), data, writeBOM, onError, sourceFiles);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
static uninstall(ts) {
|
|
85
|
+
if (EmitFilesPatch._patchedTs === undefined) {
|
|
86
|
+
throw new node_core_library_1.InternalError('EmitFilesPatch.uninstall() cannot be called if no patch was installed');
|
|
87
|
+
}
|
|
88
|
+
if (ts !== EmitFilesPatch._patchedTs) {
|
|
89
|
+
throw new node_core_library_1.InternalError('EmitFilesPatch.uninstall() called for the wrong object');
|
|
90
|
+
}
|
|
91
|
+
ts.emitFiles = EmitFilesPatch._baseEmitFiles;
|
|
92
|
+
EmitFilesPatch._patchedTs = undefined;
|
|
93
|
+
EmitFilesPatch._baseEmitFiles = undefined;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.EmitFilesPatch = EmitFilesPatch;
|
|
97
|
+
EmitFilesPatch._patchedTs = undefined;
|
|
98
|
+
EmitFilesPatch._baseEmitFiles = undefined; // eslint-disable-line
|
|
99
|
+
//# sourceMappingURL=EmitFilesPatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmitFilesPatch.js","sourceRoot":"","sources":["../src/EmitFilesPatch.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAA6D;AA2B7D,MAAa,cAAc;IAKlB,MAAM,CAAC,OAAO,CACnB,EAAsB,EACtB,QAAuC,EACvC,iBAA0C,EAC1C,YAA0C;QAE1C,IAAI,cAAc,CAAC,UAAU,KAAK,EAAE,EAAE;YACpC,yCAAyC;YACzC,OAAO;SACR;QAED,IAAI,cAAc,CAAC,UAAU,KAAK,SAAS,EAAE;YAC3C,MAAM,IAAI,iCAAa,CACrB,yFAAyF,CAC1F,CAAC;SACH;QAED,cAAc,CAAC,UAAU,GAAG,EAAE,CAAC;QAC/B,cAAc,CAAC,cAAc,GAAG,EAAE,CAAC,SAAS,CAAC;QAE7C,IAAI,YAAY,GAAY,KAAK,CAAC;QAClC,IAAI,iBAAyC,CAAC;QAE9C,KAAK,MAAM,gBAAgB,IAAI,iBAAiB,EAAE;YAChD,IAAI,gBAAgB,CAAC,SAAS,EAAE;gBAC9B,IAAI,YAAY,EAAE;oBAChB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;iBACpE;qBAAM;oBACL,YAAY,GAAG,IAAI,CAAC;iBACrB;gBA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cAAc,CAAC,UAAU,KAAK,SAAS,EAAE;YAC3C,MAAM,IAAI,iCAAa,CAAC,uEAAuE,CAAC,CAAC;SAClG;QACD,IAAI,EAAE,KAAK,cAAc,CAAC,UAAU,EAAE;YACpC,MAAM,IAAI,iCAAa,CAAC,wDAAwD,CAAC,CAAC;SACnF;QAED,EAAE,CAAC,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC;QAE7C,cAAc,CAAC,UAAU,GAAG,SAAS,CAAC;QACtC,cAAc,CAAC,cAAc,GAAG,SAAS,CAAC;IAC5C,CAAC;;AA7KH,wCA8KC;AA7KgB,yBAAU,GAAmC,SAAS,CAAC;AAEvD,6BAAc,GAAoB,SAAS,CAAC,CAAC,sBAAsB","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 { InternalError } from '@rushstack/node-core-library';\nimport type * as TTypescript from 'typescript';\nimport {\n ExtendedTypeScript,\n IEmitResolver,\n IEmitHost,\n IEmitTransformers\n} from './internalTypings/TypeScriptInternals';\n\nexport interface ICachedEmitModuleKind {\n moduleKind: TTypescript.ModuleKind;\n\n outFolderPath: string;\n\n /**\n * File extension to use instead of '.js' for emitted ECMAScript files.\n * For example, '.cjs' to indicate commonjs content, or '.mjs' to indicate ECMAScript modules.\n */\n jsExtensionOverride: string | undefined;\n\n /**\n * Set to true if this is the emit kind that is specified in the tsconfig.json.\n * Declarations are only emitted for the primary module kind.\n */\n isPrimary: boolean;\n}\n\nexport class EmitFilesPatch {\n private static _patchedTs: ExtendedTypeScript | undefined = undefined;\n\n private static _baseEmitFiles: any | undefined = undefined; // eslint-disable-line\n\n public static install(\n ts: ExtendedTypeScript,\n tsconfig: TTypescript.ParsedCommandLine,\n moduleKindsToEmit: ICachedEmitModuleKind[],\n changedFiles?: Set<TTypescript.SourceFile>\n ): void {\n if (EmitFilesPatch._patchedTs === ts) {\n // We already patched this instance of TS\n return;\n }\n\n if (EmitFilesPatch._patchedTs !== undefined) {\n throw new InternalError(\n 'EmitFilesPatch.install() cannot be called without first uninstalling the existing patch'\n );\n }\n\n EmitFilesPatch._patchedTs = ts;\n EmitFilesPatch._baseEmitFiles = ts.emitFiles;\n\n let foundPrimary: boolean = false;\n let defaultModuleKind: TTypescript.ModuleKind;\n\n for (const moduleKindToEmit of moduleKindsToEmit) {\n if (moduleKindToEmit.isPrimary) {\n if (foundPrimary) {\n throw new Error('Multiple primary module emit kinds encountered.');\n } else {\n foundPrimary = true;\n }\n\n defaultModuleKind = moduleKindToEmit.moduleKind;\n }\n }\n\n const patchedEmitFiles = (\n resolver: IEmitResolver,\n host: IEmitHost,\n targetSourceFile: TTypescript.SourceFile | undefined,\n emitTransformers: IEmitTransformers,\n emitOnlyDtsFiles?: boolean,\n onlyBuildInfo?: boolean,\n forceDtsEmit?: boolean\n ): TTypescript.EmitResult => {\n if (onlyBuildInfo || emitOnlyDtsFiles) {\n // There should only be one tsBuildInfo and one set of declaration files\n return EmitFilesPatch._baseEmitFiles(\n resolver,\n host,\n targetSourceFile,\n emitTransformers,\n emitOnlyDtsFiles,\n onlyBuildInfo,\n forceDtsEmit\n );\n } else {\n if (targetSourceFile && changedFiles) {\n changedFiles.add(targetSourceFile);\n }\n\n let defaultModuleKindResult: TTypescript.EmitResult;\n const diagnostics: TTypescript.Diagnostic[] = [];\n let emitSkipped: boolean = false;\n for (const moduleKindToEmit of moduleKindsToEmit) {\n const compilerOptions: TTypescript.CompilerOptions = moduleKindToEmit.isPrimary\n ? {\n ...tsconfig.options\n }\n : {\n ...tsconfig.options,\n module: moduleKindToEmit.moduleKind,\n outDir: moduleKindToEmit.outFolderPath,\n\n // Don't emit declarations for secondary module kinds\n declaration: false,\n declarationMap: false\n };\n\n if (!compilerOptions.outDir) {\n throw new InternalError('Expected compilerOptions.outDir to be assigned');\n }\n\n const flavorResult: TTypescript.EmitResult = EmitFilesPatch._baseEmitFiles(\n resolver,\n {\n ...host,\n writeFile: EmitFilesPatch.wrapWriteFile(host.writeFile, moduleKindToEmit.jsExtensionOverride),\n getCompilerOptions: () => compilerOptions\n },\n targetSourceFile,\n ts.getTransformers(compilerOptions, undefined, emitOnlyDtsFiles),\n emitOnlyDtsFiles,\n onlyBuildInfo,\n forceDtsEmit\n );\n\n emitSkipped = emitSkipped || flavorResult.emitSkipped;\n for (const diagnostic of flavorResult.diagnostics) {\n diagnostics.push(diagnostic);\n }\n\n if (moduleKindToEmit.moduleKind === defaultModuleKind) {\n defaultModuleKindResult = flavorResult;\n }\n // Should results be aggregated, in case for whatever reason the diagnostics are not the same?\n }\n\n const mergedDiagnostics: readonly TTypescript.Diagnostic[] =\n ts.sortAndDeduplicateDiagnostics(diagnostics);\n\n return {\n ...defaultModuleKindResult!,\n diagnostics: mergedDiagnostics,\n emitSkipped\n };\n }\n };\n\n // Override the underlying file emitter to run itself once for each flavor\n // This is a rather inelegant way to convince the TypeScript compiler not to duplicate parse/link/check\n ts.emitFiles = patchedEmitFiles;\n }\n\n public static get isInstalled(): boolean {\n return this._patchedTs !== undefined;\n }\n\n /**\n * Wraps the writeFile callback on the IEmitHost to override the .js extension, if applicable\n */\n public static wrapWriteFile(\n baseWriteFile: TTypescript.WriteFileCallback,\n jsExtensionOverride: string | undefined\n ): TTypescript.WriteFileCallback {\n if (!jsExtensionOverride) {\n return baseWriteFile;\n }\n\n const replacementExtension: string = `${jsExtensionOverride}$1`;\n return (\n fileName: string,\n data: string,\n writeBOM: boolean,\n onError?: ((message: string) => void) | undefined,\n sourceFiles?: readonly TTypescript.SourceFile[] | undefined\n ) => {\n return baseWriteFile(\n fileName.replace(/\\.js(\\.map)?$/g, replacementExtension),\n data,\n writeBOM,\n onError,\n sourceFiles\n );\n };\n }\n\n public static uninstall(ts: ExtendedTypeScript): void {\n if (EmitFilesPatch._patchedTs === undefined) {\n throw new InternalError('EmitFilesPatch.uninstall() cannot be called if no patch was installed');\n }\n if (ts !== EmitFilesPatch._patchedTs) {\n throw new InternalError('EmitFilesPatch.uninstall() called for the wrong object');\n }\n\n ts.emitFiles = EmitFilesPatch._baseEmitFiles;\n\n EmitFilesPatch._patchedTs = undefined;\n EmitFilesPatch._baseEmitFiles = undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type PerformanceMeasurer = <TResult extends object | void>(measurementName: string, fn: () => TResult) => TResult & {
|
|
2
|
+
duration: number;
|
|
3
|
+
};
|
|
4
|
+
export declare 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,oBAAY,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,oBAAY,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,69 @@
|
|
|
1
|
+
import type * as TTypescript from 'typescript';
|
|
2
|
+
import type { IScopedLogger } from '@rushstack/heft';
|
|
3
|
+
import type { ExtendedTypeScript } from './internalTypings/TypeScriptInternals';
|
|
4
|
+
import type { ITypeScriptConfigurationJson } from './TypeScriptPlugin';
|
|
5
|
+
import type { PerformanceMeasurer, PerformanceMeasurerAsync } from './Performance';
|
|
6
|
+
export interface ITypeScriptBuilderConfiguration extends ITypeScriptConfigurationJson {
|
|
7
|
+
/**
|
|
8
|
+
* The root folder of the build.
|
|
9
|
+
*/
|
|
10
|
+
buildFolderPath: string;
|
|
11
|
+
/**
|
|
12
|
+
* The folder to write build metadata.
|
|
13
|
+
*/
|
|
14
|
+
buildMetadataFolderPath: string;
|
|
15
|
+
/**
|
|
16
|
+
* The path to the TypeScript tool.
|
|
17
|
+
*/
|
|
18
|
+
typeScriptToolPath: string;
|
|
19
|
+
/**
|
|
20
|
+
* The path to the tsconfig file being built.
|
|
21
|
+
*/
|
|
22
|
+
tsconfigPath: string;
|
|
23
|
+
/**
|
|
24
|
+
* Set this to change the maximum number of file handles that will be opened concurrently for writing.
|
|
25
|
+
* The default is 50.
|
|
26
|
+
*/
|
|
27
|
+
maxWriteParallelism: number;
|
|
28
|
+
/**
|
|
29
|
+
* The scoped logger that the builder will log to.
|
|
30
|
+
*/
|
|
31
|
+
scopedLogger: IScopedLogger;
|
|
32
|
+
/**
|
|
33
|
+
* The callback used to emit the typescript program (or programs) from the builder.
|
|
34
|
+
*/
|
|
35
|
+
emitChangedFilesCallback: (program: TTypescript.Program, changedFiles?: Set<TTypescript.SourceFile>) => void;
|
|
36
|
+
}
|
|
37
|
+
export declare class TypeScriptBuilder {
|
|
38
|
+
private readonly _configuration;
|
|
39
|
+
private readonly _typescriptLogger;
|
|
40
|
+
private readonly _typescriptTerminal;
|
|
41
|
+
private _typescriptVersion;
|
|
42
|
+
private _typescriptParsedVersion;
|
|
43
|
+
private _capabilities;
|
|
44
|
+
private _useSolutionBuilder;
|
|
45
|
+
private _moduleKindsToEmit;
|
|
46
|
+
private __tsCacheFilePath;
|
|
47
|
+
private _tsReadJsonCache;
|
|
48
|
+
private _cachedFileSystem;
|
|
49
|
+
private get _tsCacheFilePath();
|
|
50
|
+
constructor(configuration: ITypeScriptBuilderConfiguration);
|
|
51
|
+
invokeAsync(): Promise<void>;
|
|
52
|
+
_runBuildAsync(ts: ExtendedTypeScript, measureTsPerformance: PerformanceMeasurer, measureTsPerformanceAsync: PerformanceMeasurerAsync): Promise<void>;
|
|
53
|
+
_runSolutionBuild(ts: ExtendedTypeScript, measureTsPerformance: PerformanceMeasurer): void;
|
|
54
|
+
private _logDiagnostics;
|
|
55
|
+
private _logEmitPerformance;
|
|
56
|
+
private _logReadPerformance;
|
|
57
|
+
private _printDiagnosticMessage;
|
|
58
|
+
private _getAdjustedDiagnosticCategory;
|
|
59
|
+
private _emit;
|
|
60
|
+
private _validateTsconfig;
|
|
61
|
+
private _addModuleKindToEmit;
|
|
62
|
+
private _loadTsconfig;
|
|
63
|
+
private _buildSolutionBuilderHost;
|
|
64
|
+
private _buildIncrementalCompilerHost;
|
|
65
|
+
private _getCachingTypeScriptSystem;
|
|
66
|
+
private _overrideTypeScriptReadJson;
|
|
67
|
+
private _parseModuleKind;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=TypeScriptBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptBuilder.d.ts","sourceRoot":"","sources":["../src/TypeScriptBuilder.ts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