@simplysm/sd-cli 11.1.46 → 11.1.52
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-tools/SdLinter.js +4 -4
- package/dist/build-tools/SdLinter.js.map +1 -1
- package/dist/build-tools/SdNgBundler.d.ts +10 -19
- package/dist/build-tools/SdNgBundler.js +115 -104
- package/dist/build-tools/SdNgBundler.js.map +1 -1
- package/dist/build-tools/SdNgBundlerContext.d.ts +1 -0
- package/dist/build-tools/SdNgBundlerContext.js +11 -3
- package/dist/build-tools/SdNgBundlerContext.js.map +1 -1
- package/dist/build-tools/SdTsCompiler.d.ts +23 -10
- package/dist/build-tools/SdTsCompiler.js +262 -221
- package/dist/build-tools/SdTsCompiler.js.map +1 -1
- package/dist/build-tools/SdTsLibBundler.d.ts +13 -0
- package/dist/build-tools/SdTsLibBundler.js +51 -0
- package/dist/build-tools/SdTsLibBundler.js.map +1 -0
- package/dist/builders/SdCliTsLibBuilder.d.ts +2 -6
- package/dist/builders/SdCliTsLibBuilder.js +26 -21
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/bundle-plugins/sdNgPlugin.js +2 -2
- package/dist/bundle-plugins/sdNgPlugin.js.map +1 -1
- package/dist/bundle-plugins/sdServerPlugin.js +2 -2
- package/dist/bundle-plugins/sdServerPlugin.js.map +1 -1
- package/dist/entry/SdCliProject.js +4 -1
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/sd-cli.d.ts +1 -1
- package/dist/sd-cli.js +1 -1
- package/package.json +5 -5
- package/src/build-tools/SdLinter.ts +4 -4
- package/src/build-tools/SdNgBundler.ts +133 -114
- package/src/build-tools/SdNgBundlerContext.ts +14 -3
- package/src/build-tools/SdTsCompiler.ts +375 -214
- package/src/build-tools/SdTsLibBundler.ts +70 -0
- package/src/builders/SdCliTsLibBuilder.ts +29 -22
- package/src/bundle-plugins/sdNgPlugin.ts +2 -2
- package/src/bundle-plugins/sdServerPlugin.ts +2 -2
- package/src/entry/SdCliProject.ts +4 -1
- package/src/index.ts +1 -1
- package/src/sd-cli.ts +1 -1
- package/dist/build-tools2/SdTsCompiler2.d.ts +0 -26
- package/dist/build-tools2/SdTsCompiler2.js +0 -280
- package/dist/build-tools2/SdTsCompiler2.js.map +0 -1
- package/src/build-tools2/SdTsCompiler2.ts +0 -427
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import esbuild from "esbuild";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { Logger } from "@simplysm/sd-core-node";
|
|
3
4
|
export class SdNgBundlerContext {
|
|
5
|
+
#logger = Logger.get(["simplysm", "sd-cli", "SdNgBundlerContext"]);
|
|
4
6
|
constructor(_pkgPath, _esbuildOptions) {
|
|
5
7
|
this._pkgPath = _pkgPath;
|
|
6
8
|
this._esbuildOptions = _esbuildOptions;
|
|
@@ -11,7 +13,9 @@ export class SdNgBundlerContext {
|
|
|
11
13
|
}
|
|
12
14
|
let buildResult;
|
|
13
15
|
try {
|
|
16
|
+
this.#debug(`rebuild...`);
|
|
14
17
|
buildResult = await this._context.rebuild();
|
|
18
|
+
this.#debug(`rebuild completed`);
|
|
15
19
|
}
|
|
16
20
|
catch (err) {
|
|
17
21
|
if ("warnings" in err || "errors" in err) {
|
|
@@ -21,6 +25,7 @@ export class SdNgBundlerContext {
|
|
|
21
25
|
throw err;
|
|
22
26
|
}
|
|
23
27
|
}
|
|
28
|
+
this.#debug(`convert results...`);
|
|
24
29
|
const results = [
|
|
25
30
|
...buildResult.warnings.map((warn) => ({
|
|
26
31
|
filePath: warn.location?.file !== undefined ? path.resolve(this._pkgPath, warn.location.file) : undefined,
|
|
@@ -28,16 +33,16 @@ export class SdNgBundlerContext {
|
|
|
28
33
|
char: warn.location?.column,
|
|
29
34
|
code: warn.text.slice(0, warn.text.indexOf(":")),
|
|
30
35
|
severity: "warning",
|
|
31
|
-
message: `${warn.pluginName
|
|
36
|
+
message: `${warn.pluginName ? `(${warn.pluginName}) ` : ""} ${warn.text.slice(warn.text.indexOf(":") + 1)}`,
|
|
32
37
|
type: "build"
|
|
33
38
|
})),
|
|
34
|
-
...buildResult.errors
|
|
39
|
+
...buildResult.errors.map((err) => ({
|
|
35
40
|
filePath: err.location?.file !== undefined ? path.resolve(this._pkgPath, err.location.file) : undefined,
|
|
36
41
|
line: err.location?.line,
|
|
37
42
|
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
38
43
|
code: err.text.slice(0, err.text.indexOf(":")),
|
|
39
44
|
severity: "error",
|
|
40
|
-
message: `${err.pluginName
|
|
45
|
+
message: `${err.pluginName ? `(${err.pluginName}) ` : ""} ${err.text.slice(err.text.indexOf(":") + 1)}`,
|
|
41
46
|
type: "build"
|
|
42
47
|
}))
|
|
43
48
|
];
|
|
@@ -96,5 +101,8 @@ export class SdNgBundlerContext {
|
|
|
96
101
|
metafile: buildResult.metafile
|
|
97
102
|
};
|
|
98
103
|
}
|
|
104
|
+
#debug(...msg) {
|
|
105
|
+
this.#logger.debug(`[${path.basename(this._pkgPath)}] (${Object.keys(this._esbuildOptions.entryPoints).join(", ")})`, ...msg);
|
|
106
|
+
}
|
|
99
107
|
}
|
|
100
108
|
//# sourceMappingURL=SdNgBundlerContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SdNgBundlerContext.js","sourceRoot":"","sources":["../../src/build-tools/SdNgBundlerContext.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"SdNgBundlerContext.js","sourceRoot":"","sources":["../../src/build-tools/SdNgBundlerContext.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAC,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAE9C,M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,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,WAAkC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;IACvJ,CAAC;CACF"}
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import ts, { CompilerOptions } from "typescript";
|
|
2
|
+
import esbuild from "esbuild";
|
|
3
3
|
export declare class SdTsCompiler {
|
|
4
4
|
#private;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
buildAsync(): Promise<{
|
|
9
|
-
watchFileSet: Set<string>;
|
|
10
|
-
affectedFileSet: Set<string>;
|
|
11
|
-
results: ISdCliPackageBuildResult[];
|
|
12
|
-
}>;
|
|
5
|
+
constructor(pkgPath: string, additionalOptions: CompilerOptions, isDevMode: boolean, globalStyleFilePath?: string);
|
|
6
|
+
invalidate(modifiedFileSet: Set<string>): void;
|
|
7
|
+
buildAsync(): Promise<ISdTsCompiler2Result>;
|
|
13
8
|
}
|
|
9
|
+
export interface ISdTsCompiler2Result {
|
|
10
|
+
program: ts.Program;
|
|
11
|
+
typescriptDiagnostics: ts.Diagnostic[];
|
|
12
|
+
stylesheetResultMap: Map<string, IStylesheetResult>;
|
|
13
|
+
emittedFilesCacheMap: Map<string, {
|
|
14
|
+
outRelPath?: string;
|
|
15
|
+
text: string;
|
|
16
|
+
}[]>;
|
|
17
|
+
watchFileSet: Set<string>;
|
|
18
|
+
affectedFileSet: Set<string>;
|
|
19
|
+
}
|
|
20
|
+
interface IStylesheetResult {
|
|
21
|
+
outputFiles: esbuild.OutputFile[];
|
|
22
|
+
metafile?: esbuild.Metafile;
|
|
23
|
+
errors?: esbuild.PartialMessage[];
|
|
24
|
+
warnings?: esbuild.PartialMessage[];
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -1,250 +1,291 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { SdTsCompiler2 } from "../build-tools2/SdTsCompiler2";
|
|
1
|
+
import ts from "typescript";
|
|
3
2
|
import path from "path";
|
|
4
|
-
import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
|
|
3
|
+
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
4
|
+
import { transformSupportedBrowsersToTargets } from "@angular-devkit/build-angular/src/tools/esbuild/utils";
|
|
5
|
+
import browserslist from "browserslist";
|
|
6
|
+
import { ComponentStylesheetBundler } from "@angular-devkit/build-angular/src/tools/esbuild/angular/component-stylesheets";
|
|
7
|
+
import { StringUtil } from "@simplysm/sd-core-common";
|
|
8
|
+
import { NgtscProgram, OptimizeFor } from "@angular/compiler-cli";
|
|
9
|
+
import { createHash } from "crypto";
|
|
5
10
|
export class SdTsCompiler {
|
|
6
|
-
#
|
|
11
|
+
#logger = Logger.get(["simplysm", "sd-cli", "SdTsCompiler"]);
|
|
12
|
+
#parsedTsconfig;
|
|
13
|
+
#isForAngular;
|
|
14
|
+
#resourceDependencyCacheMap = new Map();
|
|
15
|
+
#sourceFileCacheMap = new Map();
|
|
16
|
+
#emittedFilesCacheMap = new Map();
|
|
17
|
+
#stylesheetBundler;
|
|
18
|
+
#compilerHost;
|
|
19
|
+
#ngProgram;
|
|
20
|
+
#program;
|
|
21
|
+
#builder;
|
|
22
|
+
#modifiedFileSet = new Set();
|
|
23
|
+
#watchFileSet = new Set();
|
|
24
|
+
#stylesheetResultMap = new Map();
|
|
25
|
+
#affectedFileSet = new Set();
|
|
7
26
|
#pkgPath;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
return this._program;
|
|
13
|
-
}*/
|
|
14
|
-
constructor(pkgPath, dev) {
|
|
27
|
+
#distPath;
|
|
28
|
+
#globalStyleFilePath;
|
|
29
|
+
constructor(pkgPath, additionalOptions, isDevMode, globalStyleFilePath) {
|
|
15
30
|
this.#pkgPath = pkgPath;
|
|
16
|
-
this.#
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
this.#globalStyleFilePath = globalStyleFilePath != null ? path.normalize(globalStyleFilePath) : undefined;
|
|
32
|
+
this.#debug("초기화...");
|
|
33
|
+
//-- isForAngular / parsedTsConfig
|
|
34
|
+
const tsconfigPath = path.resolve(pkgPath, "tsconfig.json");
|
|
35
|
+
const tsconfig = FsUtil.readJson(tsconfigPath);
|
|
36
|
+
this.#isForAngular = Boolean(tsconfig.angularCompilerOptions);
|
|
37
|
+
this.#parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, pkgPath, {
|
|
38
|
+
...tsconfig.angularCompilerOptions,
|
|
39
|
+
...additionalOptions
|
|
40
|
+
});
|
|
41
|
+
this.#distPath = this.#parsedTsconfig.options.outDir ?? path.resolve(pkgPath, "dist");
|
|
42
|
+
//-- compilerHost
|
|
43
|
+
this.#compilerHost = ts.createIncrementalCompilerHost(this.#parsedTsconfig.options);
|
|
44
|
+
const baseGetSourceFile = this.#compilerHost.getSourceFile;
|
|
45
|
+
this.#compilerHost.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile, ...args) => {
|
|
46
|
+
if (!shouldCreateNewSourceFile && this.#sourceFileCacheMap.has(path.normalize(fileName))) {
|
|
47
|
+
return this.#sourceFileCacheMap.get(path.normalize(fileName));
|
|
48
|
+
}
|
|
49
|
+
const sf = baseGetSourceFile.call(this.#compilerHost, fileName, languageVersionOrOptions, onError, true, ...args);
|
|
50
|
+
if (sf) {
|
|
51
|
+
this.#sourceFileCacheMap.set(path.normalize(fileName), sf);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.#sourceFileCacheMap.delete(path.normalize(fileName));
|
|
55
|
+
}
|
|
56
|
+
return sf;
|
|
57
|
+
};
|
|
58
|
+
if (this.#isForAngular) {
|
|
59
|
+
//-- stylesheetBundler
|
|
60
|
+
const browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
|
|
61
|
+
this.#stylesheetBundler = new ComponentStylesheetBundler({
|
|
62
|
+
workspaceRoot: pkgPath,
|
|
63
|
+
optimization: !isDevMode,
|
|
64
|
+
inlineFonts: true,
|
|
65
|
+
preserveSymlinks: false,
|
|
66
|
+
sourcemap: 'inline', //conf.dev ? 'inline' : false,
|
|
67
|
+
outputNames: { bundles: '[name]', media: 'media/[name]' },
|
|
68
|
+
includePaths: [],
|
|
69
|
+
externalDependencies: [],
|
|
70
|
+
target: browserTarget,
|
|
71
|
+
tailwindConfiguration: undefined,
|
|
72
|
+
cacheOptions: {
|
|
73
|
+
enabled: true,
|
|
74
|
+
path: ".cache/angular",
|
|
75
|
+
basePath: ".cache"
|
|
76
|
+
}
|
|
77
|
+
}, isDevMode);
|
|
78
|
+
//-- compilerHost
|
|
79
|
+
this.#compilerHost.readResource = (fileName) => {
|
|
80
|
+
return this.#compilerHost.readFile(fileName) ?? "";
|
|
81
|
+
};
|
|
82
|
+
this.#compilerHost.transformResource = async (data, context) => {
|
|
83
|
+
if (context.type !== "style") {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const contents = await this.#bundleStylesheetAsync(data, context.containingFile, context.resourceFile);
|
|
87
|
+
return StringUtil.isNullOrEmpty(contents) ? null : { content: contents };
|
|
88
|
+
};
|
|
89
|
+
this.#compilerHost.getModifiedResourceFiles = () => {
|
|
90
|
+
return this.#modifiedFileSet;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
20
93
|
}
|
|
21
|
-
async
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
94
|
+
async #bundleStylesheetAsync(data, containingFile, resourceFile = null) {
|
|
95
|
+
this.#debug(`스타일시트 번들링...(${containingFile}, ${resourceFile})`);
|
|
96
|
+
const stylesheetResult = resourceFile != null
|
|
97
|
+
? await this.#stylesheetBundler.bundleFile(resourceFile)
|
|
98
|
+
: await this.#stylesheetBundler.bundleInline(data, containingFile, "scss");
|
|
99
|
+
this.#watchFileSet.add(path.normalize(containingFile));
|
|
100
|
+
if (resourceFile != null) {
|
|
101
|
+
this.#watchFileSet.add(path.normalize(resourceFile));
|
|
102
|
+
}
|
|
103
|
+
if (stylesheetResult.referencedFiles) {
|
|
104
|
+
for (const referencedFile of stylesheetResult.referencedFiles) {
|
|
105
|
+
const referencingMapValSet = this.#resourceDependencyCacheMap.getOrCreate(path.normalize(referencedFile), new Set());
|
|
106
|
+
referencingMapValSet.add(path.normalize(containingFile));
|
|
107
|
+
if (resourceFile != null) {
|
|
108
|
+
referencingMapValSet.add(path.normalize(resourceFile));
|
|
32
109
|
}
|
|
33
110
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
111
|
+
this.#watchFileSet.adds(...Array.from(stylesheetResult.referencedFiles.values()).map(item => path.normalize(item)));
|
|
112
|
+
}
|
|
113
|
+
this.#stylesheetResultMap.set(path.normalize(resourceFile ?? containingFile), {
|
|
114
|
+
outputFiles: stylesheetResult.outputFiles,
|
|
115
|
+
metafile: stylesheetResult.metafile,
|
|
116
|
+
errors: stylesheetResult.errors,
|
|
117
|
+
warnings: stylesheetResult.warnings
|
|
118
|
+
});
|
|
119
|
+
return stylesheetResult.contents;
|
|
120
|
+
}
|
|
121
|
+
invalidate(modifiedFileSet) {
|
|
122
|
+
this.#stylesheetBundler?.invalidate(modifiedFileSet);
|
|
123
|
+
for (const modifiedFile of modifiedFileSet) {
|
|
124
|
+
this.#stylesheetResultMap.delete(path.normalize(modifiedFile));
|
|
125
|
+
this.#sourceFileCacheMap.delete(path.normalize(modifiedFile));
|
|
126
|
+
this.#emittedFilesCacheMap.delete(path.normalize(modifiedFile));
|
|
127
|
+
if (this.#resourceDependencyCacheMap.has(path.normalize(modifiedFile))) {
|
|
128
|
+
for (const referencingFile of this.#resourceDependencyCacheMap.get(path.normalize(modifiedFile))) {
|
|
129
|
+
this.#stylesheetResultMap.delete(path.normalize(referencingFile));
|
|
130
|
+
this.#sourceFileCacheMap.delete(path.normalize(referencingFile));
|
|
131
|
+
this.#emittedFilesCacheMap.delete(path.normalize(referencingFile));
|
|
41
132
|
}
|
|
42
133
|
}
|
|
43
134
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
this._compilerHost,
|
|
56
|
-
this._ngProgram
|
|
57
|
-
);
|
|
58
|
-
this._program = this._ngProgram.getTsProgram();
|
|
59
|
-
|
|
60
|
-
const baseGetSourceFiles = this._program.getSourceFiles;
|
|
61
|
-
this._program.getSourceFiles = function (...parameters) {
|
|
62
|
-
const files: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(...parameters);
|
|
63
|
-
|
|
64
|
-
for (const file of files) {
|
|
65
|
-
if (file.version === undefined) {
|
|
66
|
-
file.version = createHash("sha256").update(file.text).digest("hex");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return files;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
this._builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(
|
|
74
|
-
this._program,
|
|
75
|
-
this._compilerHost,
|
|
76
|
-
this._builder
|
|
77
|
-
);
|
|
135
|
+
this.#modifiedFileSet.adds(...modifiedFileSet);
|
|
136
|
+
}
|
|
137
|
+
async buildAsync() {
|
|
138
|
+
this.#resourceDependencyCacheMap.clear();
|
|
139
|
+
this.#watchFileSet.clear();
|
|
140
|
+
this.#stylesheetResultMap.clear();
|
|
141
|
+
this.#affectedFileSet.clear();
|
|
142
|
+
this.#debug(`create program...`);
|
|
143
|
+
if (this.#isForAngular) {
|
|
144
|
+
this.#ngProgram = new NgtscProgram(this.#parsedTsconfig.fileNames, this.#parsedTsconfig.options, this.#compilerHost, this.#ngProgram);
|
|
145
|
+
this.#program = this.#ngProgram.getTsProgram();
|
|
78
146
|
}
|
|
79
147
|
else {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this._parsedTsConfig.options,
|
|
83
|
-
this._compilerHost,
|
|
84
|
-
this._program
|
|
85
|
-
);*!/
|
|
86
|
-
|
|
87
|
-
this._builder = ts.createIncrementalProgram({
|
|
88
|
-
rootNames: srcFilePaths,
|
|
89
|
-
host: this._compilerHost,
|
|
90
|
-
options: this._parsedTsConfig.options,
|
|
91
|
-
createProgram: ts.createEmitAndSemanticDiagnosticsBuilderProgram
|
|
92
|
-
});
|
|
93
|
-
this._program = this._builder.getProgram();
|
|
148
|
+
// noinspection UnnecessaryLocalVariableJS
|
|
149
|
+
this.#program = ts.createProgram(this.#parsedTsconfig.fileNames, this.#parsedTsconfig.options, this.#compilerHost, this.#program);
|
|
94
150
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
await this._ngProgram.compiler.analyzeAsync();
|
|
151
|
+
const baseGetSourceFiles = this.#program.getSourceFiles;
|
|
152
|
+
this.#program.getSourceFiles = function (...parameters) {
|
|
153
|
+
const files = baseGetSourceFiles(...parameters);
|
|
154
|
+
for (const file of files) {
|
|
155
|
+
if (file.version === undefined) {
|
|
156
|
+
file.version = createHash("sha256").update(file.text).digest("hex");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return files;
|
|
160
|
+
};
|
|
161
|
+
this.#debug(`create builder...`);
|
|
162
|
+
this.#builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(this.#program, this.#compilerHost, this.#builder);
|
|
163
|
+
if (this.#ngProgram) {
|
|
164
|
+
await this.#ngProgram.compiler.analyzeAsync();
|
|
110
165
|
}
|
|
111
|
-
|
|
112
|
-
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 확인중...`);
|
|
166
|
+
this.#debug(`get affected...`);
|
|
113
167
|
while (true) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
//-- 나머지 무시
|
|
134
|
-
else {
|
|
135
|
-
return true;
|
|
168
|
+
const result = this.#builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
|
|
169
|
+
if (this.#ngProgram
|
|
170
|
+
&& this.#ngProgram.compiler.ignoreForDiagnostics.has(sourceFile)
|
|
171
|
+
&& sourceFile.fileName.endsWith('.ngtypecheck.ts')) {
|
|
172
|
+
const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';
|
|
173
|
+
// const originalSourceFile = this.#sourceFileCacheMap.get(originalFilename);
|
|
174
|
+
const originalSourceFile = this.#builder.getSourceFile(originalFilename);
|
|
175
|
+
if (originalSourceFile) {
|
|
176
|
+
this.#affectedFileSet.add(path.normalize(originalSourceFile.fileName));
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
});
|
|
182
|
+
if (!result) {
|
|
183
|
+
break;
|
|
136
184
|
}
|
|
137
|
-
|
|
138
|
-
if (!semanticResult || !affectedSourceFile) break;
|
|
139
|
-
diagnostics.push(...semanticResult.result);
|
|
140
|
-
|
|
141
|
-
if ("fileName" in affectedSourceFile) {
|
|
142
|
-
affectedFileSet.add(path.normalize(affectedSourceFile.fileName));
|
|
143
|
-
}
|
|
185
|
+
this.#affectedFileSet.add(path.normalize(result.affected.fileName));
|
|
144
186
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
|
|
187
|
+
this.#debug(`get resource ref...`);
|
|
188
|
+
this.#builder.getSourceFiles().filter(sf => !this.#ngProgram || !this.#ngProgram.compiler.ignoreForEmit.has(sf))
|
|
189
|
+
.forEach(sf => {
|
|
190
|
+
this.#watchFileSet.add(path.normalize(sf.fileName));
|
|
191
|
+
if (this.#ngProgram) {
|
|
192
|
+
const deps = this.#ngProgram.compiler.getResourceDependencies(sf);
|
|
193
|
+
for (const dep of deps) {
|
|
194
|
+
const ref = this.#resourceDependencyCacheMap.getOrCreate(path.normalize(dep), new Set());
|
|
195
|
+
ref.add(path.normalize(sf.fileName));
|
|
196
|
+
this.#watchFileSet.add(path.normalize(dep));
|
|
197
|
+
}
|
|
151
198
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (this
|
|
157
|
-
|
|
199
|
+
});
|
|
200
|
+
this.#debug(`get diagnostics...`);
|
|
201
|
+
const diagnostics = [];
|
|
202
|
+
diagnostics.push(...this.#builder.getConfigFileParsingDiagnostics(), ...this.#builder.getOptionsDiagnostics(), ...this.#builder.getGlobalDiagnostics());
|
|
203
|
+
if (this.#ngProgram) {
|
|
204
|
+
diagnostics.push(...this.#ngProgram.compiler.getOptionDiagnostics());
|
|
158
205
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (this._opt.globalStyle && affectedFilePath === globalStyleFilePath) {
|
|
164
|
-
try {
|
|
165
|
-
const content = await FsUtil.readFileAsync(affectedFilePath);
|
|
166
|
-
const scssResult = await sass.compileStringAsync(content, {
|
|
167
|
-
url: new URL(affectedFilePath),
|
|
168
|
-
importer: {
|
|
169
|
-
findFileUrl: (url) => pathToFileURL(url)
|
|
170
|
-
},
|
|
171
|
-
logger: sass.Logger.silent
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
|
|
175
|
-
for (const dep of deps) {
|
|
176
|
-
const depCache = this._styleDepsCache.getOrCreate(dep, new Set<string>());
|
|
177
|
-
depCache.add(affectedFilePath);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (this._opt.emit) {
|
|
181
|
-
const outFilePath = path.resolve(this._opt.pkgPath, path.basename(affectedFilePath, path.extname(affectedFilePath)) + ".css");
|
|
182
|
-
|
|
183
|
-
this._writeFile(outFilePath, scssResult.css.toString());
|
|
184
|
-
}
|
|
206
|
+
for (const affectedFile of this.#affectedFileSet) {
|
|
207
|
+
const affectedSourceFile = this.#sourceFileCacheMap.get(affectedFile);
|
|
208
|
+
if (!affectedSourceFile || (this.#ngProgram && this.#ngProgram.compiler.ignoreForDiagnostics.has(affectedSourceFile))) {
|
|
209
|
+
continue;
|
|
185
210
|
}
|
|
186
|
-
|
|
187
|
-
|
|
211
|
+
diagnostics.push(...this.#builder.getSyntacticDiagnostics(affectedSourceFile), ...this.#builder.getSemanticDiagnostics(affectedSourceFile));
|
|
212
|
+
if (this.#ngProgram) {
|
|
213
|
+
if (affectedSourceFile.isDeclarationFile) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
diagnostics.push(...this.#ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram));
|
|
188
217
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// remove "../../"
|
|
204
|
-
sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
|
|
205
|
-
realData = JSON.stringify(sourceMapContents);
|
|
206
|
-
}
|
|
218
|
+
}
|
|
219
|
+
this.#debug(`prepare emit...`);
|
|
220
|
+
while (true) {
|
|
221
|
+
const affectedFileResult = this.#builder.emitNextAffectedFile((fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
|
|
222
|
+
if (!sourceFiles || sourceFiles.length === 0) {
|
|
223
|
+
this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
|
|
227
|
+
if (this.#ngProgram) {
|
|
228
|
+
if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
|
|
207
232
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
233
|
+
const emittedFiles = this.#emittedFilesCacheMap.getOrCreate(path.normalize(sourceFile.fileName), []);
|
|
234
|
+
if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
|
|
235
|
+
let realFilePath = fileName;
|
|
236
|
+
let realText = text;
|
|
237
|
+
if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
|
|
238
|
+
realFilePath = path.resolve(this.#distPath, path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath));
|
|
239
|
+
if (fileName.endsWith(".js.map")) {
|
|
240
|
+
const sourceMapContents = JSON.parse(realText);
|
|
241
|
+
// remove "../../"
|
|
242
|
+
sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
|
|
243
|
+
realText = JSON.stringify(sourceMapContents);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
emittedFiles.push({
|
|
247
|
+
outRelPath: path.relative(this.#distPath, realFilePath),
|
|
248
|
+
text: realText
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
emittedFiles.push({ text });
|
|
253
|
+
}
|
|
254
|
+
}, undefined, undefined, this.#ngProgram?.compiler.prepareEmit().transformers);
|
|
255
|
+
if (!affectedFileResult) {
|
|
256
|
+
break;
|
|
230
257
|
}
|
|
231
|
-
|
|
258
|
+
diagnostics.push(...affectedFileResult.result.diagnostics);
|
|
232
259
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
260
|
+
//-- global style
|
|
261
|
+
if (this.#globalStyleFilePath != null
|
|
262
|
+
&& !this.#stylesheetResultMap.has(this.#globalStyleFilePath)
|
|
263
|
+
&& FsUtil.exists(this.#globalStyleFilePath)) {
|
|
264
|
+
this.#debug(`bundle global style...`);
|
|
265
|
+
const data = await FsUtil.readFileAsync(this.#globalStyleFilePath);
|
|
266
|
+
const contents = await this.#bundleStylesheetAsync(data, this.#globalStyleFilePath, this.#globalStyleFilePath);
|
|
267
|
+
const emittedFiles = this.#emittedFilesCacheMap.getOrCreate(path.normalize(this.#globalStyleFilePath), []);
|
|
268
|
+
emittedFiles.push({
|
|
269
|
+
outRelPath: path.relative(path.resolve(this.#pkgPath, "src"), this.#globalStyleFilePath).replace(/\.scss$/, ".css"),
|
|
270
|
+
text: contents
|
|
271
|
+
});
|
|
272
|
+
this.#affectedFileSet.add(this.#globalStyleFilePath);
|
|
273
|
+
}
|
|
274
|
+
//-- init
|
|
275
|
+
this.#modifiedFileSet.clear();
|
|
276
|
+
this.#debug(`build completed`);
|
|
277
|
+
//-- result
|
|
237
278
|
return {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
/*...Array.from(buildResult.stylesheetResultMap.values()).mapMany(item => item.warnings!)
|
|
245
|
-
.map(warn => SdCliBuildResultUtil.convertFromEsbuildResult(warn, "build", "warning"))*/
|
|
246
|
-
]
|
|
279
|
+
program: this.#program,
|
|
280
|
+
typescriptDiagnostics: diagnostics,
|
|
281
|
+
stylesheetResultMap: this.#stylesheetResultMap,
|
|
282
|
+
emittedFilesCacheMap: this.#emittedFilesCacheMap,
|
|
283
|
+
watchFileSet: this.#watchFileSet,
|
|
284
|
+
affectedFileSet: this.#affectedFileSet
|
|
247
285
|
};
|
|
248
286
|
}
|
|
287
|
+
#debug(...msg) {
|
|
288
|
+
this.#logger.debug(`[${path.basename(this.#pkgPath)}]`, ...msg);
|
|
289
|
+
}
|
|
249
290
|
}
|
|
250
291
|
//# sourceMappingURL=SdTsCompiler.js.map
|