@simplysm/sd-cli 11.1.45 → 11.1.51
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/dist/build-cluster.js +16 -3
- package/dist/build-cluster.js.map +1 -1
- package/dist/build-tools/SdLibBundler.d.ts +13 -0
- package/dist/build-tools/SdLibBundler.js +51 -0
- package/dist/build-tools/SdLibBundler.js.map +1 -0
- package/dist/build-tools/SdLinter.js +4 -4
- package/dist/build-tools/SdLinter.js.map +1 -1
- package/dist/build-tools/SdNgBundler.d.ts +11 -20
- package/dist/build-tools/SdNgBundler.js +103 -96
- package/dist/build-tools/SdNgBundler.js.map +1 -1
- package/dist/build-tools/SdServerBundler.js.map +1 -1
- package/dist/build-tools/SdTsCompiler.d.ts +24 -27
- package/dist/build-tools/SdTsCompiler.js +237 -184
- package/dist/build-tools/SdTsCompiler.js.map +1 -1
- package/dist/builders/SdCliTsLibBuilder.d.ts +2 -6
- package/dist/builders/SdCliTsLibBuilder.js +30 -30
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/bundle-plugins/sdNgPlugin.d.ts +3 -3
- package/dist/bundle-plugins/sdNgPlugin.js +22 -212
- package/dist/bundle-plugins/sdNgPlugin.js.map +1 -1
- package/dist/bundle-plugins/sdServerPlugin.d.ts +2 -2
- package/dist/bundle-plugins/sdServerPlugin.js +17 -110
- package/dist/bundle-plugins/sdServerPlugin.js.map +1 -1
- package/dist/commons.d.ts +1 -0
- package/dist/entry/SdCliProject.d.ts +1 -0
- package/dist/entry/SdCliProject.js +14 -30
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sd-cli.d.ts +1 -1
- package/dist/sd-cli.js +8 -2
- package/dist/sd-cli.js.map +1 -1
- package/dist/server-worker.js.map +1 -1
- package/dist/utils/SdCliBuildResultUtil.d.ts +10 -0
- package/dist/utils/SdCliBuildResultUtil.js +17 -1
- package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
- package/package.json +15 -15
- package/src/build-cluster.ts +18 -4
- package/src/build-tools/SdLibBundler.ts +70 -0
- package/src/build-tools/SdLinter.ts +4 -4
- package/src/build-tools/SdNgBundler.ts +120 -112
- package/src/build-tools/SdServerBundler.ts +2 -2
- package/src/build-tools/SdTsCompiler.ts +352 -241
- package/src/builders/SdCliTsLibBuilder.ts +33 -31
- package/src/bundle-plugins/sdNgPlugin.ts +26 -320
- package/src/bundle-plugins/sdServerPlugin.ts +20 -168
- package/src/commons.ts +1 -0
- package/src/entry/SdCliProject.ts +15 -31
- package/src/index.ts +1 -0
- package/src/sd-cli.ts +8 -2
- package/src/server-worker.ts +3 -3
- package/src/utils/SdCliBuildResultUtil.ts +22 -3
|
@@ -2,21 +2,27 @@ import {FsUtil, Logger, PathUtil, SdFsWatcher} from "@simplysm/sd-core-node";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import {ISdCliBuilderResult, ISdCliConfig, ISdCliLibPackageConfig, ISdCliPackageBuildResult} from "../commons";
|
|
4
4
|
import {EventEmitter} from "events";
|
|
5
|
-
import {
|
|
5
|
+
import {SdLibBundler} from "../build-tools/SdLibBundler";
|
|
6
6
|
import {SdLinter} from "../build-tools/SdLinter";
|
|
7
7
|
import {FunctionQueue} from "@simplysm/sd-core-common";
|
|
8
8
|
import {SdCliIndexFileGenerator} from "../build-tools/SdCliIndexFileGenerator";
|
|
9
9
|
|
|
10
10
|
export class SdCliTsLibBuilder extends EventEmitter {
|
|
11
|
-
|
|
11
|
+
readonly #logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
readonly #projConf: ISdCliConfig;
|
|
14
|
+
readonly #pkgPath: string;
|
|
15
|
+
readonly #pkgConf: ISdCliLibPackageConfig;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
#bundler?: SdLibBundler;
|
|
18
|
+
|
|
19
|
+
public constructor(projConf: ISdCliConfig,
|
|
20
|
+
pkgPath: string) {
|
|
18
21
|
super();
|
|
19
|
-
this
|
|
22
|
+
this.#projConf = projConf;
|
|
23
|
+
this.#pkgPath = pkgPath;
|
|
24
|
+
|
|
25
|
+
this.#pkgConf = projConf.packages[path.basename(pkgPath)] as ISdCliLibPackageConfig;
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
public override on(event: "change", listener: () => void): this;
|
|
@@ -28,14 +34,14 @@ export class SdCliTsLibBuilder extends EventEmitter {
|
|
|
28
34
|
|
|
29
35
|
public async buildAsync(): Promise<ISdCliBuilderResult> {
|
|
30
36
|
this._debug("dist 초기화...");
|
|
31
|
-
await FsUtil.removeAsync(path.resolve(this
|
|
37
|
+
await FsUtil.removeAsync(path.resolve(this.#pkgPath, "dist"));
|
|
32
38
|
|
|
33
|
-
if (!this.
|
|
39
|
+
if (!this.#pkgConf.noGenIndex) {
|
|
34
40
|
this._debug("GEN index.ts...");
|
|
35
|
-
await SdCliIndexFileGenerator.runAsync(this
|
|
41
|
+
await SdCliIndexFileGenerator.runAsync(this.#pkgPath, this.#pkgConf.polyfills);
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
const result = await this._runAsync();
|
|
44
|
+
const result = await this._runAsync(false);
|
|
39
45
|
return {
|
|
40
46
|
affectedFilePaths: Array.from(result.affectedFileSet),
|
|
41
47
|
buildResults: result.buildResults
|
|
@@ -46,14 +52,14 @@ export class SdCliTsLibBuilder extends EventEmitter {
|
|
|
46
52
|
this.emit("change");
|
|
47
53
|
|
|
48
54
|
this._debug("dist 초기화...");
|
|
49
|
-
await FsUtil.removeAsync(path.resolve(this
|
|
55
|
+
await FsUtil.removeAsync(path.resolve(this.#pkgPath, "dist"));
|
|
50
56
|
|
|
51
|
-
if (!this.
|
|
57
|
+
if (!this.#pkgConf.noGenIndex) {
|
|
52
58
|
this._debug("WATCH GEN index.ts...");
|
|
53
|
-
await SdCliIndexFileGenerator.watchAsync(this
|
|
59
|
+
await SdCliIndexFileGenerator.watchAsync(this.#pkgPath, this.#pkgConf.polyfills);
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
const result = await this._runAsync();
|
|
62
|
+
const result = await this._runAsync(true);
|
|
57
63
|
this.emit("complete", {
|
|
58
64
|
affectedFilePaths: Array.from(result.affectedFileSet),
|
|
59
65
|
buildResults: result.buildResults
|
|
@@ -64,12 +70,12 @@ export class SdCliTsLibBuilder extends EventEmitter {
|
|
|
64
70
|
const watcher = SdFsWatcher
|
|
65
71
|
.watch(Array.from(result.watchFileSet))
|
|
66
72
|
.onChange({delay: 100,}, (changeInfos) => {
|
|
67
|
-
this
|
|
73
|
+
this.#bundler!.markChanges(new Set(changeInfos.map((item) => item.path)));
|
|
68
74
|
|
|
69
75
|
fnQ.runLast(async () => {
|
|
70
76
|
this.emit("change");
|
|
71
77
|
|
|
72
|
-
const watchResult = await this._runAsync();
|
|
78
|
+
const watchResult = await this._runAsync(true);
|
|
73
79
|
this.emit("complete", {
|
|
74
80
|
affectedFilePaths: Array.from(watchResult.affectedFileSet),
|
|
75
81
|
buildResults: watchResult.buildResults
|
|
@@ -80,28 +86,24 @@ export class SdCliTsLibBuilder extends EventEmitter {
|
|
|
80
86
|
});
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
private async _runAsync(): Promise<{
|
|
89
|
+
private async _runAsync(dev: boolean): Promise<{
|
|
84
90
|
watchFileSet: Set<string>;
|
|
85
91
|
affectedFileSet: Set<string>;
|
|
86
92
|
buildResults: ISdCliPackageBuildResult[];
|
|
87
93
|
}> {
|
|
88
|
-
this._debug(`BUILD
|
|
89
|
-
this
|
|
90
|
-
|
|
91
|
-
emit: true,
|
|
92
|
-
emitDts: true,
|
|
93
|
-
globalStyle: true
|
|
94
|
-
});
|
|
95
|
-
const buildResult = await this._builder.buildAsync();
|
|
94
|
+
this._debug(`BUILD...`);
|
|
95
|
+
this.#bundler = this.#bundler ?? new SdLibBundler(this.#pkgPath, dev);
|
|
96
|
+
const buildResult = await this.#bundler.buildAsync();
|
|
96
97
|
|
|
97
98
|
this._debug("LINT...");
|
|
98
|
-
const
|
|
99
|
+
const lintFilePaths = Array.from(buildResult.affectedFileSet).filter(item => PathUtil.isChildPath(item, this.#pkgPath));
|
|
100
|
+
const lintResults = await SdLinter.lintAsync(lintFilePaths, buildResult.program);
|
|
99
101
|
|
|
100
102
|
this._debug(`빌드 완료`);
|
|
101
|
-
const localUpdatePaths = Object.keys(this.
|
|
102
|
-
.mapMany((key) => FsUtil.glob(path.resolve(this
|
|
103
|
+
const localUpdatePaths = Object.keys(this.#projConf.localUpdates ?? {})
|
|
104
|
+
.mapMany((key) => FsUtil.glob(path.resolve(this.#pkgPath, "../../node_modules", key)));
|
|
103
105
|
const watchFileSet = new Set(Array.from(buildResult.watchFileSet).filter(item =>
|
|
104
|
-
PathUtil.isChildPath(item, path.resolve(this
|
|
106
|
+
PathUtil.isChildPath(item, path.resolve(this.#pkgPath, "../")) ||
|
|
105
107
|
localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu))
|
|
106
108
|
));
|
|
107
109
|
|
|
@@ -113,6 +115,6 @@ export class SdCliTsLibBuilder extends EventEmitter {
|
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
private _debug(msg: string): void {
|
|
116
|
-
this.
|
|
118
|
+
this.#logger.debug(`[${path.basename(this.#pkgPath)}] ${msg}`);
|
|
117
119
|
}
|
|
118
120
|
}
|
|
@@ -1,178 +1,24 @@
|
|
|
1
1
|
import esbuild from "esbuild";
|
|
2
|
-
import {FsUtil} from "@simplysm/sd-core-node";
|
|
3
2
|
import ts from "typescript";
|
|
4
3
|
import path from "path";
|
|
5
|
-
import {convertTypeScriptDiagnostic} from "@angular-devkit/build-angular/src/tools/esbuild/angular/diagnostics";
|
|
6
|
-
import {AngularCompilerHost} from "@angular-devkit/build-angular/src/tools/esbuild/angular/angular-host";
|
|
7
|
-
import {
|
|
8
|
-
ComponentStylesheetBundler
|
|
9
|
-
} from "@angular-devkit/build-angular/src/tools/esbuild/angular/component-stylesheets";
|
|
10
|
-
import {transformSupportedBrowsersToTargets} from "@angular-devkit/build-angular/src/tools/esbuild/utils";
|
|
11
|
-
import browserslist from "browserslist";
|
|
12
|
-
import {StringUtil} from "@simplysm/sd-core-common";
|
|
13
|
-
import {NgtscProgram, OptimizeFor} from "@angular/compiler-cli";
|
|
14
|
-
import {createHash} from "crypto";
|
|
15
4
|
import {JavaScriptTransformer} from "@angular-devkit/build-angular/src/tools/esbuild/javascript-transformer";
|
|
16
5
|
import os from "os";
|
|
6
|
+
import {ISdTsCompiler2Result, SdTsCompiler} from "../build-tools/SdTsCompiler";
|
|
7
|
+
import {convertTypeScriptDiagnostic} from "@angular-devkit/build-angular/src/tools/esbuild/angular/diagnostics";
|
|
17
8
|
|
|
18
9
|
export function sdNgPlugin(conf: {
|
|
19
10
|
pkgPath: string;
|
|
20
11
|
dev: boolean;
|
|
21
12
|
modifiedFileSet: Set<string>;
|
|
22
|
-
result:
|
|
13
|
+
result: INgPluginResultCache;
|
|
23
14
|
}): esbuild.Plugin {
|
|
24
|
-
const tsConfigPath = path.resolve(conf.pkgPath, "tsconfig.json");
|
|
25
|
-
const tsConfig = FsUtil.readJson(tsConfigPath);
|
|
26
|
-
const parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig, ts.sys, conf.pkgPath, {
|
|
27
|
-
...tsConfig.angularCompilerOptions,
|
|
28
|
-
declaration: false
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const sourceFileCache = new Map<string, ts.SourceFile>();
|
|
32
|
-
const referencingMap = new Map<string, Set<string>>();
|
|
33
|
-
|
|
34
|
-
let ngProgram: NgtscProgram | undefined;
|
|
35
|
-
let builder: ts.EmitAndSemanticDiagnosticsBuilderProgram | undefined;
|
|
36
|
-
|
|
37
|
-
// const watchFileSet = new Set<string>();
|
|
38
|
-
// const affectedFileSet = new Set<string>();
|
|
39
|
-
const additionalResultMap = new Map<string, IAdditionalResult>();
|
|
40
|
-
|
|
41
|
-
const tscPrepareMap = new Map<string, string>();
|
|
42
|
-
const outputCacheMap = new Map<string, Uint8Array>();
|
|
43
|
-
|
|
44
|
-
let stylesheetBundler: ComponentStylesheetBundler | undefined;
|
|
45
|
-
|
|
46
|
-
function createCompilerHost() {
|
|
47
|
-
const compilerHost: AngularCompilerHost = ts.createIncrementalCompilerHost(parsedTsConfig.options);
|
|
48
|
-
compilerHost.readResource = (fileName: string) => {
|
|
49
|
-
return compilerHost.readFile(fileName) ?? "";
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
compilerHost.transformResource = async (data: string, context: {
|
|
53
|
-
type: string,
|
|
54
|
-
containingFile: string,
|
|
55
|
-
resourceFile: any
|
|
56
|
-
}) => {
|
|
57
|
-
if (context.type !== "style") {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const stylesheetResult = context.resourceFile != null
|
|
62
|
-
? await stylesheetBundler!.bundleFile(context.resourceFile)
|
|
63
|
-
: await stylesheetBundler!.bundleInline(
|
|
64
|
-
data,
|
|
65
|
-
context.containingFile,
|
|
66
|
-
"scss",
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
conf.result.watchFileSet!.add(path.normalize(context.containingFile));
|
|
70
|
-
|
|
71
|
-
if (stylesheetResult.referencedFiles) {
|
|
72
|
-
for (const referencedFile of stylesheetResult.referencedFiles) {
|
|
73
|
-
const referencingMapValSet = referencingMap.getOrCreate(path.normalize(referencedFile), new Set<string>());
|
|
74
|
-
referencingMapValSet.add(path.normalize(context.containingFile));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
conf.result.watchFileSet!.adds(...Array.from(stylesheetResult.referencedFiles.values()).map(item => path.normalize(item)));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
additionalResultMap.set(path.normalize(context.resourceFile ?? context.containingFile), {
|
|
81
|
-
outputFiles: stylesheetResult.outputFiles ?? [],
|
|
82
|
-
metafile: stylesheetResult.metafile,
|
|
83
|
-
errors: stylesheetResult.errors,
|
|
84
|
-
// warnings: stylesheetResult.warnings
|
|
85
|
-
warnings: []
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
return StringUtil.isNullOrEmpty(stylesheetResult.contents) ? null : {content: stylesheetResult.contents};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
compilerHost.getModifiedResourceFiles = () => {
|
|
92
|
-
return conf.modifiedFileSet;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const baseGetSourceFile = compilerHost.getSourceFile;
|
|
96
|
-
compilerHost.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile, ...args) => {
|
|
97
|
-
if (!shouldCreateNewSourceFile && sourceFileCache.has(path.normalize(fileName))) {
|
|
98
|
-
return sourceFileCache.get(path.normalize(fileName));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const file = baseGetSourceFile.call(
|
|
102
|
-
compilerHost,
|
|
103
|
-
fileName,
|
|
104
|
-
languageVersionOrOptions,
|
|
105
|
-
onError,
|
|
106
|
-
true,
|
|
107
|
-
...args,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
if (file) {
|
|
111
|
-
sourceFileCache.set(path.normalize(fileName), file);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return file;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
return compilerHost;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function findAffectedFileSet() {
|
|
121
|
-
const affectedFileSet = new Set<string>();
|
|
122
|
-
|
|
123
|
-
while (true) {
|
|
124
|
-
const result = builder!.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
|
|
125
|
-
if (ngProgram?.compiler.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith('.ngtypecheck.ts')) {
|
|
126
|
-
const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';
|
|
127
|
-
const originalSourceFile = sourceFileCache.get(originalFilename);
|
|
128
|
-
if (originalSourceFile) {
|
|
129
|
-
affectedFileSet.add(path.normalize(originalSourceFile.fileName));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return false;
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
if (!result) {
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
affectedFileSet.add(path.normalize((result.affected as ts.SourceFile).fileName));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return affectedFileSet;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
15
|
return {
|
|
149
16
|
name: "sd-ng-compiler",
|
|
150
17
|
setup: (build: esbuild.PluginBuild) => {
|
|
151
|
-
|
|
152
|
-
const browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
|
|
153
|
-
stylesheetBundler = new ComponentStylesheetBundler(
|
|
154
|
-
{
|
|
155
|
-
workspaceRoot: conf.pkgPath,
|
|
156
|
-
optimization: !conf.dev,
|
|
157
|
-
inlineFonts: true,
|
|
158
|
-
preserveSymlinks: false,
|
|
159
|
-
sourcemap: 'inline', //conf.dev ? 'inline' : false,
|
|
160
|
-
outputNames: {bundles: '[name]', media: 'media/[name]'},
|
|
161
|
-
includePaths: [],
|
|
162
|
-
externalDependencies: [],
|
|
163
|
-
target: browserTarget,
|
|
164
|
-
tailwindConfiguration: undefined,
|
|
165
|
-
cacheOptions: {
|
|
166
|
-
enabled: true,
|
|
167
|
-
path: ".cache/angular",
|
|
168
|
-
basePath: ".cache"
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
conf.dev
|
|
172
|
-
);
|
|
18
|
+
const compiler = new SdTsCompiler(conf.pkgPath, {declaration: false}, conf.dev);
|
|
173
19
|
|
|
174
|
-
|
|
175
|
-
const
|
|
20
|
+
let buildResult: ISdTsCompiler2Result;
|
|
21
|
+
const outputContentsCacheMap = new Map<string, Uint8Array>();
|
|
176
22
|
|
|
177
23
|
//-- js babel transformer
|
|
178
24
|
const javascriptTransformer = new JavaScriptTransformer({
|
|
@@ -182,165 +28,36 @@ export function sdNgPlugin(conf: {
|
|
|
182
28
|
advancedOptimizations: true
|
|
183
29
|
}, os.cpus().length);
|
|
184
30
|
|
|
185
|
-
//-- vars
|
|
186
|
-
|
|
187
31
|
//---------------------------
|
|
188
32
|
|
|
189
33
|
build.onStart(async () => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
stylesheetBundler!.invalidate(conf.modifiedFileSet);
|
|
193
|
-
for (const modifiedFile of conf.modifiedFileSet) {
|
|
194
|
-
sourceFileCache.delete(modifiedFile);
|
|
195
|
-
outputCacheMap.delete(modifiedFile);
|
|
196
|
-
|
|
197
|
-
if (referencingMap.has(modifiedFile)) {
|
|
198
|
-
for (const referencingFile of referencingMap.get(modifiedFile)!) {
|
|
199
|
-
sourceFileCache.delete(referencingFile);
|
|
200
|
-
outputCacheMap.delete(modifiedFile);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
referencingMap.clear();
|
|
205
|
-
|
|
206
|
-
//-- init resultCache
|
|
34
|
+
compiler.invalidate(conf.modifiedFileSet);
|
|
35
|
+
buildResult = await compiler.buildAsync();
|
|
207
36
|
|
|
208
|
-
conf.result.watchFileSet =
|
|
209
|
-
conf.result.affectedFileSet =
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
//-- createBuilder
|
|
213
|
-
|
|
214
|
-
ngProgram = new NgtscProgram(
|
|
215
|
-
parsedTsConfig.fileNames,
|
|
216
|
-
parsedTsConfig.options,
|
|
217
|
-
compilerHost,
|
|
218
|
-
ngProgram
|
|
219
|
-
);
|
|
220
|
-
const ngCompiler = ngProgram.compiler;
|
|
221
|
-
const program = ngProgram.getTsProgram();
|
|
222
|
-
conf.result.program = program;
|
|
223
|
-
|
|
224
|
-
const baseGetSourceFiles = program.getSourceFiles;
|
|
225
|
-
program.getSourceFiles = function (...parameters) {
|
|
226
|
-
const files: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(...parameters);
|
|
227
|
-
|
|
228
|
-
for (const file of files) {
|
|
229
|
-
if (file.version === undefined) {
|
|
230
|
-
file.version = createHash("sha256").update(file.text).digest("hex");
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return files;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(
|
|
238
|
-
program,
|
|
239
|
-
compilerHost,
|
|
240
|
-
builder
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
await ngCompiler.analyzeAsync();
|
|
244
|
-
|
|
245
|
-
//-- affectedFilePathSet
|
|
246
|
-
|
|
247
|
-
conf.result.affectedFileSet.adds(...findAffectedFileSet());
|
|
248
|
-
|
|
249
|
-
// Deps -> refMap
|
|
250
|
-
builder.getSourceFiles().filter(sf => !ngCompiler.ignoreForEmit.has(sf))
|
|
251
|
-
.forEach(sf => {
|
|
252
|
-
conf.result.watchFileSet!.add(path.normalize(sf.fileName));
|
|
253
|
-
|
|
254
|
-
const deps = ngCompiler.getResourceDependencies(sf);
|
|
255
|
-
for (const dep of deps) {
|
|
256
|
-
const ref = referencingMap.getOrCreate(dep, new Set<string>());
|
|
257
|
-
ref.add(dep);
|
|
258
|
-
|
|
259
|
-
conf.result.watchFileSet!.add(path.normalize(dep));
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
// refMap, modFile -> affectedFileSet
|
|
264
|
-
for (const modifiedFile of conf.modifiedFileSet) {
|
|
265
|
-
conf.result.affectedFileSet.adds(...referencingMap.get(modifiedFile) ?? []);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
//-- diagnostics / build
|
|
269
|
-
const diagnostics: ts.Diagnostic[] = [];
|
|
270
|
-
|
|
271
|
-
diagnostics.push(
|
|
272
|
-
...builder.getConfigFileParsingDiagnostics(),
|
|
273
|
-
...ngCompiler.getOptionDiagnostics(),
|
|
274
|
-
...builder.getOptionsDiagnostics(),
|
|
275
|
-
...builder.getGlobalDiagnostics()
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
for (const affectedFile of conf.result.affectedFileSet) {
|
|
279
|
-
const affectedSourceFile = sourceFileCache.get(path.normalize(affectedFile));
|
|
280
|
-
if (!affectedSourceFile || ngCompiler.ignoreForDiagnostics.has(affectedSourceFile)) {
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
diagnostics.push(
|
|
285
|
-
...builder.getSyntacticDiagnostics(affectedSourceFile),
|
|
286
|
-
...builder.getSemanticDiagnostics(affectedSourceFile)
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
if (affectedSourceFile.isDeclarationFile) {
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
diagnostics.push(
|
|
294
|
-
...ngCompiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram),
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
//-- prepare emit cache
|
|
299
|
-
while (true) {
|
|
300
|
-
const affectedFileResult = builder.emitNextAffectedFile((fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
|
|
301
|
-
if (!sourceFiles || sourceFiles.length === 0) {
|
|
302
|
-
compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
|
|
307
|
-
if (ngCompiler.ignoreForEmit.has(sourceFile)) {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
ngCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
|
|
312
|
-
tscPrepareMap.set(path.normalize(sourceFile.fileName), text);
|
|
313
|
-
}, undefined, undefined, ngProgram.compiler.prepareEmit().transformers);
|
|
314
|
-
|
|
315
|
-
if (!affectedFileResult) {
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
diagnostics.push(...affectedFileResult.result.diagnostics);
|
|
320
|
-
}
|
|
37
|
+
conf.result.watchFileSet = buildResult.watchFileSet;
|
|
38
|
+
conf.result.affectedFileSet = buildResult.affectedFileSet;
|
|
39
|
+
conf.result.program = buildResult.program;
|
|
321
40
|
|
|
322
41
|
//-- return err/warn
|
|
323
42
|
return {
|
|
324
43
|
errors: [
|
|
325
|
-
...
|
|
326
|
-
...Array.from(
|
|
44
|
+
...buildResult.typescriptDiagnostics.filter(item => item.category === ts.DiagnosticCategory.Error).map(item => convertTypeScriptDiagnostic(ts, item)),
|
|
45
|
+
...Array.from(buildResult.stylesheetResultMap.values()).flatMap(item => item.errors)
|
|
327
46
|
].filterExists(),
|
|
328
47
|
warnings: [
|
|
329
|
-
...
|
|
330
|
-
...Array.from(
|
|
48
|
+
...buildResult.typescriptDiagnostics.filter(item => item.category !== ts.DiagnosticCategory.Error).map(item => convertTypeScriptDiagnostic(ts, item)),
|
|
49
|
+
// ...Array.from(buildResult.stylesheetResultMap.values()).flatMap(item => item.warnings)
|
|
331
50
|
],
|
|
332
51
|
};
|
|
333
52
|
});
|
|
334
53
|
|
|
335
54
|
build.onLoad({filter: /\.ts$/}, async (args) => {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const output = outputCacheMap.get(path.normalize(args.path));
|
|
55
|
+
const output = outputContentsCacheMap.get(path.normalize(args.path));
|
|
339
56
|
if (output != null) {
|
|
340
57
|
return {contents: output, loader: "js"};
|
|
341
58
|
}
|
|
342
59
|
|
|
343
|
-
const contents =
|
|
60
|
+
const contents = buildResult.emittedFilesCacheMap.get(path.normalize(args.path))!.last()!.text;
|
|
344
61
|
|
|
345
62
|
const {sideEffects} = await build.resolve(args.path, {
|
|
346
63
|
kind: 'import-statement',
|
|
@@ -349,12 +66,12 @@ export function sdNgPlugin(conf: {
|
|
|
349
66
|
|
|
350
67
|
const newContents = await javascriptTransformer.transformData(
|
|
351
68
|
args.path,
|
|
352
|
-
contents
|
|
69
|
+
contents,
|
|
353
70
|
true,
|
|
354
71
|
sideEffects
|
|
355
72
|
);
|
|
356
73
|
|
|
357
|
-
|
|
74
|
+
outputContentsCacheMap.set(path.normalize(args.path), newContents);
|
|
358
75
|
|
|
359
76
|
return {contents: newContents, loader: "js"};
|
|
360
77
|
});
|
|
@@ -364,7 +81,7 @@ export function sdNgPlugin(conf: {
|
|
|
364
81
|
async (args) => {
|
|
365
82
|
conf.result.watchFileSet!.add(path.normalize(args.path));
|
|
366
83
|
|
|
367
|
-
const output =
|
|
84
|
+
const output = outputContentsCacheMap.get(path.normalize(args.path));
|
|
368
85
|
if (output != null) {
|
|
369
86
|
return {contents: output, loader: "js"};
|
|
370
87
|
}
|
|
@@ -374,15 +91,13 @@ export function sdNgPlugin(conf: {
|
|
|
374
91
|
resolveDir: build.initialOptions.absWorkingDir ?? '',
|
|
375
92
|
});
|
|
376
93
|
|
|
377
|
-
// const contents = await FsUtil.readFileAsync(args.path);
|
|
378
|
-
|
|
379
94
|
const newContents = await javascriptTransformer.transformFile(
|
|
380
95
|
args.path,
|
|
381
96
|
false,
|
|
382
97
|
sideEffects
|
|
383
98
|
);
|
|
384
99
|
|
|
385
|
-
|
|
100
|
+
outputContentsCacheMap.set(path.normalize(args.path), newContents);
|
|
386
101
|
|
|
387
102
|
return {
|
|
388
103
|
contents: newContents,
|
|
@@ -400,8 +115,9 @@ export function sdNgPlugin(conf: {
|
|
|
400
115
|
);
|
|
401
116
|
|
|
402
117
|
build.onEnd((result) => {
|
|
403
|
-
for (const {outputFiles, metafile} of
|
|
404
|
-
result.outputFiles
|
|
118
|
+
for (const {outputFiles, metafile} of buildResult.stylesheetResultMap.values()) {
|
|
119
|
+
result.outputFiles = result.outputFiles ?? [];
|
|
120
|
+
result.outputFiles.push(...outputFiles);
|
|
405
121
|
|
|
406
122
|
if (result.metafile && metafile) {
|
|
407
123
|
result.metafile.inputs = {...result.metafile.inputs, ...metafile.inputs};
|
|
@@ -409,9 +125,6 @@ export function sdNgPlugin(conf: {
|
|
|
409
125
|
}
|
|
410
126
|
}
|
|
411
127
|
|
|
412
|
-
// conf.result.watchFileSet = resultCache.watchFileSet;
|
|
413
|
-
// conf.result.affectedFileSet = resultCache.affectedFileSet;
|
|
414
|
-
// conf.result.program = ngProgram!.getTsProgram();
|
|
415
128
|
conf.result.outputFiles = result.outputFiles;
|
|
416
129
|
conf.result.metafile = result.metafile;
|
|
417
130
|
|
|
@@ -421,17 +134,10 @@ export function sdNgPlugin(conf: {
|
|
|
421
134
|
};
|
|
422
135
|
}
|
|
423
136
|
|
|
424
|
-
interface
|
|
425
|
-
outputFiles: esbuild.OutputFile[];
|
|
426
|
-
metafile?: esbuild.Metafile;
|
|
427
|
-
errors?: esbuild.PartialMessage[];
|
|
428
|
-
warnings: esbuild.PartialMessage[];
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export interface INgResultCache {
|
|
137
|
+
export interface INgPluginResultCache {
|
|
432
138
|
watchFileSet?: Set<string>;
|
|
433
139
|
affectedFileSet?: Set<string>;
|
|
140
|
+
program?: ts.Program;
|
|
434
141
|
outputFiles?: esbuild.OutputFile[];
|
|
435
142
|
metafile?: esbuild.Metafile;
|
|
436
|
-
program?: ts.Program;
|
|
437
143
|
}
|