@simplysm/sd-cli 11.0.39 → 11.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-cluster.d.ts +1 -1
- package/dist/build-cluster.js +181 -181
- package/dist/build-tools/SdCliCordova.d.ts +21 -21
- package/dist/build-tools/SdCliCordova.js +217 -217
- package/dist/build-tools/SdCliIndexFileGenerator.d.ts +5 -5
- package/dist/build-tools/SdCliIndexFileGenerator.js +50 -50
- package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +4 -4
- package/dist/build-tools/SdCliNgRoutesFileGenerator.js +57 -57
- package/dist/build-tools/SdLinter.d.ts +5 -5
- package/dist/build-tools/SdLinter.js +54 -54
- package/dist/build-tools/SdNgBundler.d.ts +35 -35
- package/dist/build-tools/SdNgBundler.js +545 -533
- package/dist/build-tools/SdNgBundler.js.map +1 -1
- package/dist/build-tools/SdNgBundlerContext.d.ts +16 -16
- package/dist/build-tools/SdNgBundlerContext.js +97 -97
- package/dist/build-tools/SdTsBundler.d.ts +15 -15
- package/dist/build-tools/SdTsBundler.js +87 -87
- package/dist/build-tools/SdTsCompiler.d.ts +29 -29
- package/dist/build-tools/SdTsCompiler.js +227 -227
- package/dist/builders/SdCliClientBuilder.d.ts +18 -18
- package/dist/builders/SdCliClientBuilder.js +129 -129
- package/dist/builders/SdCliJsLibLinter.d.ts +14 -14
- package/dist/builders/SdCliJsLibLinter.js +59 -59
- package/dist/builders/SdCliServerBuilder.d.ts +20 -20
- package/dist/builders/SdCliServerBuilder.js +215 -215
- package/dist/builders/SdCliTsLibBuilder.d.ts +17 -17
- package/dist/builders/SdCliTsLibBuilder.js +79 -79
- package/dist/commons.d.ts +132 -132
- package/dist/commons.js +1 -1
- package/dist/entry/SdCliElectron.d.ts +12 -12
- package/dist/entry/SdCliElectron.js +99 -99
- package/dist/entry/SdCliLocalUpdate.d.ts +12 -12
- package/dist/entry/SdCliLocalUpdate.js +90 -90
- package/dist/entry/SdCliProject.d.ts +26 -26
- package/dist/entry/SdCliProject.js +477 -477
- package/dist/index.d.ts +19 -19
- package/dist/index.js +19 -19
- package/dist/sd-cli.d.ts +2 -2
- package/dist/sd-cli.js +210 -210
- package/dist/server-worker.d.ts +1 -1
- package/dist/server-worker.js +38 -38
- package/dist/utils/SdCliBuildResultUtil.d.ts +6 -6
- package/dist/utils/SdCliBuildResultUtil.js +37 -37
- package/dist/utils/SdMemoryLoadResultCache.d.ts +9 -9
- package/dist/utils/SdMemoryLoadResultCache.js +34 -34
- package/dist/utils/SdSourceFileCache.d.ts +6 -6
- package/dist/utils/SdSourceFileCache.js +14 -14
- package/dist/utils/SdSourceFileCache.js.map +1 -1
- package/package.json +19 -19
- package/src/build-tools/SdNgBundler.ts +21 -12
- package/src/utils/SdSourceFileCache.ts +1 -1
|
@@ -1,228 +1,228 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
|
|
4
|
-
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
5
|
-
import { NgtscProgram } from "@angular/compiler-cli";
|
|
6
|
-
import { createHash } from "crypto";
|
|
7
|
-
import { fileURLToPath, pathToFileURL } from "url";
|
|
8
|
-
import * as sass from "sass";
|
|
9
|
-
export class SdTsCompiler {
|
|
10
|
-
get program() {
|
|
11
|
-
if (!this._program) {
|
|
12
|
-
throw new Error("TS 프로그램 NULL");
|
|
13
|
-
}
|
|
14
|
-
return this._program;
|
|
15
|
-
}
|
|
16
|
-
constructor(_opt) {
|
|
17
|
-
this._opt = _opt;
|
|
18
|
-
this._logger = Logger.get(["simplysm", "sd-cli", "SdTsCompiler"]);
|
|
19
|
-
this._writeFileCache = new Map();
|
|
20
|
-
this._styleDepsCache = new Map();
|
|
21
|
-
this._markedChanges = [];
|
|
22
|
-
//-- tsconfig
|
|
23
|
-
const tsConfigFilePath = path.resolve(_opt.pkgPath, "tsconfig.json");
|
|
24
|
-
const tsConfig = FsUtil.readJson(tsConfigFilePath);
|
|
25
|
-
this._parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig, ts.sys, _opt.pkgPath, {
|
|
26
|
-
...tsConfig.angularCompilerOptions ?? {},
|
|
27
|
-
..._opt.emitDts !== undefined ? { declaration: _opt.emitDts } : {}
|
|
28
|
-
});
|
|
29
|
-
//-- vars
|
|
30
|
-
this._isForAngular = Boolean(tsConfig.angularCompilerOptions);
|
|
31
|
-
//-- host
|
|
32
|
-
this._compilerHost = ts.createIncrementalCompilerHost(this._parsedTsConfig.options);
|
|
33
|
-
if (tsConfig.angularCompilerOptions) {
|
|
34
|
-
this._compilerHost["readResource"] = (fileName) => {
|
|
35
|
-
return this._compilerHost.readFile(fileName);
|
|
36
|
-
};
|
|
37
|
-
this._compilerHost["transformResource"] = async (data, context) => {
|
|
38
|
-
if (context.resourceFile != null || context.type !== "style") {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const scssResult = await sass.compileStringAsync(data, {
|
|
43
|
-
url: new URL(context.containingFile + ".scss"),
|
|
44
|
-
importer: {
|
|
45
|
-
findFileUrl: (url) => pathToFileURL(url)
|
|
46
|
-
},
|
|
47
|
-
logger: sass.Logger.silent
|
|
48
|
-
});
|
|
49
|
-
const styleContent = scssResult.css.toString();
|
|
50
|
-
const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
|
|
51
|
-
for (const dep of deps) {
|
|
52
|
-
const depCache = this._styleDepsCache.getOrCreate(dep, new Set());
|
|
53
|
-
depCache.add(path.resolve(context.containingFile));
|
|
54
|
-
}
|
|
55
|
-
return { content: styleContent };
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
this._logger.error("scss 파싱 에러", err);
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
markChanges(changes) {
|
|
65
|
-
this._markedChanges.push(...changes);
|
|
66
|
-
}
|
|
67
|
-
async buildAsync() {
|
|
68
|
-
const markedChanges = this._markedChanges;
|
|
69
|
-
this._markedChanges = [];
|
|
70
|
-
const distPath = path.resolve(this._opt.pkgPath, "dist");
|
|
71
|
-
const srcFilePaths = await FsUtil.globAsync(path.resolve(this._opt.pkgPath, "src/**/*.{ts,tsx}"));
|
|
72
|
-
const srcFilePathSet = new Set(srcFilePaths);
|
|
73
|
-
if (this._isForAngular) {
|
|
74
|
-
this._ngProgram = new NgtscProgram(srcFilePaths, this._parsedTsConfig.options, this._compilerHost, this._ngProgram);
|
|
75
|
-
this._program = this._ngProgram.getTsProgram();
|
|
76
|
-
const baseGetSourceFiles = this._program.getSourceFiles;
|
|
77
|
-
this._program.getSourceFiles = function (...parameters) {
|
|
78
|
-
const files = baseGetSourceFiles(...parameters);
|
|
79
|
-
for (const file of files) {
|
|
80
|
-
if (file.version === undefined) {
|
|
81
|
-
file.version = createHash("sha256").update(file.text).digest("hex");
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return files;
|
|
85
|
-
};
|
|
86
|
-
this._builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(this._program, this._compilerHost, this._builder);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
/*this._program = ts.createProgram(
|
|
90
|
-
srcFilePaths,
|
|
91
|
-
this._parsedTsConfig.options,
|
|
92
|
-
this._compilerHost,
|
|
93
|
-
this._program
|
|
94
|
-
);*/
|
|
95
|
-
this._builder = ts.createIncrementalProgram({
|
|
96
|
-
rootNames: srcFilePaths,
|
|
97
|
-
host: this._compilerHost,
|
|
98
|
-
options: this._parsedTsConfig.options,
|
|
99
|
-
createProgram: ts.createEmitAndSemanticDiagnosticsBuilderProgram
|
|
100
|
-
});
|
|
101
|
-
this._program = this._builder.getProgram();
|
|
102
|
-
}
|
|
103
|
-
const diagnostics = [];
|
|
104
|
-
const affectedFilePaths = [];
|
|
105
|
-
if (this._ngProgram) {
|
|
106
|
-
diagnostics.push(...this._ngProgram.compiler.getOptionDiagnostics());
|
|
107
|
-
}
|
|
108
|
-
diagnostics.push(...this._builder.getOptionsDiagnostics(), ...this._builder.getGlobalDiagnostics());
|
|
109
|
-
if (this._ngProgram) {
|
|
110
|
-
await this._ngProgram.compiler.analyzeAsync();
|
|
111
|
-
}
|
|
112
|
-
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 확인중...`);
|
|
113
|
-
while (true) {
|
|
114
|
-
let affectedSourceFile;
|
|
115
|
-
const semanticResult = this._builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
|
|
116
|
-
//-- ngtypecheck의 org파일 포함 (ngtypecheck 파일는 무시)
|
|
117
|
-
if (this._ngProgram?.compiler.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith(".ngtypecheck.ts")) {
|
|
118
|
-
const orgFileName = sourceFile.fileName.slice(0, -15) + ".ts";
|
|
119
|
-
const orgSourceFile = this._builder.getSourceFile(orgFileName);
|
|
120
|
-
if (orgSourceFile) {
|
|
121
|
-
affectedSourceFile = orgSourceFile;
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
//-- 소스폴더 파일 포함
|
|
126
|
-
else if (srcFilePathSet.has(path.resolve(sourceFile.fileName))) {
|
|
127
|
-
affectedSourceFile = sourceFile;
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
//-- 나머지 무시
|
|
131
|
-
else {
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
if (!semanticResult || !affectedSourceFile)
|
|
136
|
-
break;
|
|
137
|
-
diagnostics.push(...semanticResult.result);
|
|
138
|
-
if ("fileName" in affectedSourceFile) {
|
|
139
|
-
affectedFilePaths.push(path.resolve(affectedSourceFile.fileName));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (this._isForAngular) {
|
|
143
|
-
for (const markedChange of markedChanges) {
|
|
144
|
-
const depsSet = this._styleDepsCache.get(markedChange);
|
|
145
|
-
if (depsSet) {
|
|
146
|
-
affectedFilePaths.push(...depsSet);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
affectedFilePaths.distinctThis();
|
|
150
|
-
}
|
|
151
|
-
const globalStyleFilePath = path.resolve(this._opt.pkgPath, "src/styles.scss");
|
|
152
|
-
if (this._opt.globalStyle && FsUtil.exists(globalStyleFilePath) && markedChanges.includes(globalStyleFilePath)) {
|
|
153
|
-
affectedFilePaths.push(globalStyleFilePath);
|
|
154
|
-
affectedFilePaths.distinctThis();
|
|
155
|
-
}
|
|
156
|
-
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 ${this._opt.emit ? "EMIT" : "CHECK"}...`);
|
|
157
|
-
for (const affectedFilePath of affectedFilePaths) {
|
|
158
|
-
if (this._opt.globalStyle && affectedFilePath === globalStyleFilePath) {
|
|
159
|
-
try {
|
|
160
|
-
const content = await FsUtil.readFileAsync(affectedFilePath);
|
|
161
|
-
const scssResult = await sass.compileStringAsync(content, {
|
|
162
|
-
url: new URL(affectedFilePath),
|
|
163
|
-
importer: {
|
|
164
|
-
findFileUrl: (url) => pathToFileURL(url)
|
|
165
|
-
},
|
|
166
|
-
logger: sass.Logger.silent
|
|
167
|
-
});
|
|
168
|
-
const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
|
|
169
|
-
for (const dep of deps) {
|
|
170
|
-
const depCache = this._styleDepsCache.getOrCreate(dep, new Set());
|
|
171
|
-
depCache.add(affectedFilePath);
|
|
172
|
-
}
|
|
173
|
-
if (this._opt.emit) {
|
|
174
|
-
const outFilePath = path.resolve(this._opt.pkgPath, path.basename(affectedFilePath, path.extname(affectedFilePath)) + ".css");
|
|
175
|
-
this._writeFile(outFilePath, scssResult.css.toString());
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (err) {
|
|
179
|
-
this._logger.error(err);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
const affectedSourceFile = this._builder.getSourceFile(affectedFilePath);
|
|
184
|
-
if (!affectedSourceFile)
|
|
185
|
-
continue;
|
|
186
|
-
const emitResult = this._builder.emit(affectedSourceFile, (filePath, data) => {
|
|
187
|
-
let realFilePath = filePath;
|
|
188
|
-
let realData = data;
|
|
189
|
-
if (PathUtil.isChildPath(realFilePath, path.resolve(distPath, path.basename(this._opt.pkgPath), "src"))) {
|
|
190
|
-
realFilePath = path.resolve(distPath, path.relative(path.resolve(distPath, path.basename(this._opt.pkgPath), "src"), realFilePath));
|
|
191
|
-
if (filePath.endsWith(".js.map")) {
|
|
192
|
-
const sourceMapContents = JSON.parse(realData);
|
|
193
|
-
// remove "../../"
|
|
194
|
-
sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
|
|
195
|
-
realData = JSON.stringify(sourceMapContents);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
this._writeFile(realFilePath, realData);
|
|
199
|
-
}, undefined, !this._opt.emit, { ...this._ngProgram?.compiler.prepareEmit().transformers ?? {} });
|
|
200
|
-
diagnostics.push(...emitResult.diagnostics);
|
|
201
|
-
diagnostics.push(...this._builder.getSyntacticDiagnostics(affectedSourceFile));
|
|
202
|
-
if (this._ngProgram &&
|
|
203
|
-
!affectedSourceFile.isDeclarationFile &&
|
|
204
|
-
!this._ngProgram.compiler.ignoreForEmit.has(affectedSourceFile) &&
|
|
205
|
-
!this._ngProgram.compiler.incrementalCompilation.safeToSkipEmit(affectedSourceFile)) {
|
|
206
|
-
diagnostics.push(...this._ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, 1));
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 ${this._opt.emit ? "EMIT" : "CHECK"} 완료`, affectedFilePaths);
|
|
211
|
-
const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item, this._opt.emit ? "build" : "check"));
|
|
212
|
-
return {
|
|
213
|
-
filePaths: [
|
|
214
|
-
...Array.from(this._styleDepsCache.keys()),
|
|
215
|
-
...this._builder.getSourceFiles().map(item => path.resolve(item.fileName))
|
|
216
|
-
],
|
|
217
|
-
affectedFilePaths: affectedFilePaths,
|
|
218
|
-
results: buildResults
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
_writeFile(filePath, data) {
|
|
222
|
-
if (this._writeFileCache.get(filePath) !== data) {
|
|
223
|
-
this._compilerHost.writeFile(filePath, data, false);
|
|
224
|
-
}
|
|
225
|
-
this._writeFileCache.set(filePath, data);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
|
|
4
|
+
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
5
|
+
import { NgtscProgram } from "@angular/compiler-cli";
|
|
6
|
+
import { createHash } from "crypto";
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
8
|
+
import * as sass from "sass";
|
|
9
|
+
export class SdTsCompiler {
|
|
10
|
+
get program() {
|
|
11
|
+
if (!this._program) {
|
|
12
|
+
throw new Error("TS 프로그램 NULL");
|
|
13
|
+
}
|
|
14
|
+
return this._program;
|
|
15
|
+
}
|
|
16
|
+
constructor(_opt) {
|
|
17
|
+
this._opt = _opt;
|
|
18
|
+
this._logger = Logger.get(["simplysm", "sd-cli", "SdTsCompiler"]);
|
|
19
|
+
this._writeFileCache = new Map();
|
|
20
|
+
this._styleDepsCache = new Map();
|
|
21
|
+
this._markedChanges = [];
|
|
22
|
+
//-- tsconfig
|
|
23
|
+
const tsConfigFilePath = path.resolve(_opt.pkgPath, "tsconfig.json");
|
|
24
|
+
const tsConfig = FsUtil.readJson(tsConfigFilePath);
|
|
25
|
+
this._parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig, ts.sys, _opt.pkgPath, {
|
|
26
|
+
...tsConfig.angularCompilerOptions ?? {},
|
|
27
|
+
..._opt.emitDts !== undefined ? { declaration: _opt.emitDts } : {}
|
|
28
|
+
});
|
|
29
|
+
//-- vars
|
|
30
|
+
this._isForAngular = Boolean(tsConfig.angularCompilerOptions);
|
|
31
|
+
//-- host
|
|
32
|
+
this._compilerHost = ts.createIncrementalCompilerHost(this._parsedTsConfig.options);
|
|
33
|
+
if (tsConfig.angularCompilerOptions) {
|
|
34
|
+
this._compilerHost["readResource"] = (fileName) => {
|
|
35
|
+
return this._compilerHost.readFile(fileName);
|
|
36
|
+
};
|
|
37
|
+
this._compilerHost["transformResource"] = async (data, context) => {
|
|
38
|
+
if (context.resourceFile != null || context.type !== "style") {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const scssResult = await sass.compileStringAsync(data, {
|
|
43
|
+
url: new URL(context.containingFile + ".scss"),
|
|
44
|
+
importer: {
|
|
45
|
+
findFileUrl: (url) => pathToFileURL(url)
|
|
46
|
+
},
|
|
47
|
+
logger: sass.Logger.silent
|
|
48
|
+
});
|
|
49
|
+
const styleContent = scssResult.css.toString();
|
|
50
|
+
const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
|
|
51
|
+
for (const dep of deps) {
|
|
52
|
+
const depCache = this._styleDepsCache.getOrCreate(dep, new Set());
|
|
53
|
+
depCache.add(path.resolve(context.containingFile));
|
|
54
|
+
}
|
|
55
|
+
return { content: styleContent };
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
this._logger.error("scss 파싱 에러", err);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
markChanges(changes) {
|
|
65
|
+
this._markedChanges.push(...changes);
|
|
66
|
+
}
|
|
67
|
+
async buildAsync() {
|
|
68
|
+
const markedChanges = this._markedChanges;
|
|
69
|
+
this._markedChanges = [];
|
|
70
|
+
const distPath = path.resolve(this._opt.pkgPath, "dist");
|
|
71
|
+
const srcFilePaths = await FsUtil.globAsync(path.resolve(this._opt.pkgPath, "src/**/*.{ts,tsx}"));
|
|
72
|
+
const srcFilePathSet = new Set(srcFilePaths);
|
|
73
|
+
if (this._isForAngular) {
|
|
74
|
+
this._ngProgram = new NgtscProgram(srcFilePaths, this._parsedTsConfig.options, this._compilerHost, this._ngProgram);
|
|
75
|
+
this._program = this._ngProgram.getTsProgram();
|
|
76
|
+
const baseGetSourceFiles = this._program.getSourceFiles;
|
|
77
|
+
this._program.getSourceFiles = function (...parameters) {
|
|
78
|
+
const files = baseGetSourceFiles(...parameters);
|
|
79
|
+
for (const file of files) {
|
|
80
|
+
if (file.version === undefined) {
|
|
81
|
+
file.version = createHash("sha256").update(file.text).digest("hex");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return files;
|
|
85
|
+
};
|
|
86
|
+
this._builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(this._program, this._compilerHost, this._builder);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
/*this._program = ts.createProgram(
|
|
90
|
+
srcFilePaths,
|
|
91
|
+
this._parsedTsConfig.options,
|
|
92
|
+
this._compilerHost,
|
|
93
|
+
this._program
|
|
94
|
+
);*/
|
|
95
|
+
this._builder = ts.createIncrementalProgram({
|
|
96
|
+
rootNames: srcFilePaths,
|
|
97
|
+
host: this._compilerHost,
|
|
98
|
+
options: this._parsedTsConfig.options,
|
|
99
|
+
createProgram: ts.createEmitAndSemanticDiagnosticsBuilderProgram
|
|
100
|
+
});
|
|
101
|
+
this._program = this._builder.getProgram();
|
|
102
|
+
}
|
|
103
|
+
const diagnostics = [];
|
|
104
|
+
const affectedFilePaths = [];
|
|
105
|
+
if (this._ngProgram) {
|
|
106
|
+
diagnostics.push(...this._ngProgram.compiler.getOptionDiagnostics());
|
|
107
|
+
}
|
|
108
|
+
diagnostics.push(...this._builder.getOptionsDiagnostics(), ...this._builder.getGlobalDiagnostics());
|
|
109
|
+
if (this._ngProgram) {
|
|
110
|
+
await this._ngProgram.compiler.analyzeAsync();
|
|
111
|
+
}
|
|
112
|
+
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 확인중...`);
|
|
113
|
+
while (true) {
|
|
114
|
+
let affectedSourceFile;
|
|
115
|
+
const semanticResult = this._builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
|
|
116
|
+
//-- ngtypecheck의 org파일 포함 (ngtypecheck 파일는 무시)
|
|
117
|
+
if (this._ngProgram?.compiler.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith(".ngtypecheck.ts")) {
|
|
118
|
+
const orgFileName = sourceFile.fileName.slice(0, -15) + ".ts";
|
|
119
|
+
const orgSourceFile = this._builder.getSourceFile(orgFileName);
|
|
120
|
+
if (orgSourceFile) {
|
|
121
|
+
affectedSourceFile = orgSourceFile;
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
//-- 소스폴더 파일 포함
|
|
126
|
+
else if (srcFilePathSet.has(path.resolve(sourceFile.fileName))) {
|
|
127
|
+
affectedSourceFile = sourceFile;
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
//-- 나머지 무시
|
|
131
|
+
else {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
if (!semanticResult || !affectedSourceFile)
|
|
136
|
+
break;
|
|
137
|
+
diagnostics.push(...semanticResult.result);
|
|
138
|
+
if ("fileName" in affectedSourceFile) {
|
|
139
|
+
affectedFilePaths.push(path.resolve(affectedSourceFile.fileName));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (this._isForAngular) {
|
|
143
|
+
for (const markedChange of markedChanges) {
|
|
144
|
+
const depsSet = this._styleDepsCache.get(markedChange);
|
|
145
|
+
if (depsSet) {
|
|
146
|
+
affectedFilePaths.push(...depsSet);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
affectedFilePaths.distinctThis();
|
|
150
|
+
}
|
|
151
|
+
const globalStyleFilePath = path.resolve(this._opt.pkgPath, "src/styles.scss");
|
|
152
|
+
if (this._opt.globalStyle && FsUtil.exists(globalStyleFilePath) && markedChanges.includes(globalStyleFilePath)) {
|
|
153
|
+
affectedFilePaths.push(globalStyleFilePath);
|
|
154
|
+
affectedFilePaths.distinctThis();
|
|
155
|
+
}
|
|
156
|
+
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 ${this._opt.emit ? "EMIT" : "CHECK"}...`);
|
|
157
|
+
for (const affectedFilePath of affectedFilePaths) {
|
|
158
|
+
if (this._opt.globalStyle && affectedFilePath === globalStyleFilePath) {
|
|
159
|
+
try {
|
|
160
|
+
const content = await FsUtil.readFileAsync(affectedFilePath);
|
|
161
|
+
const scssResult = await sass.compileStringAsync(content, {
|
|
162
|
+
url: new URL(affectedFilePath),
|
|
163
|
+
importer: {
|
|
164
|
+
findFileUrl: (url) => pathToFileURL(url)
|
|
165
|
+
},
|
|
166
|
+
logger: sass.Logger.silent
|
|
167
|
+
});
|
|
168
|
+
const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
|
|
169
|
+
for (const dep of deps) {
|
|
170
|
+
const depCache = this._styleDepsCache.getOrCreate(dep, new Set());
|
|
171
|
+
depCache.add(affectedFilePath);
|
|
172
|
+
}
|
|
173
|
+
if (this._opt.emit) {
|
|
174
|
+
const outFilePath = path.resolve(this._opt.pkgPath, path.basename(affectedFilePath, path.extname(affectedFilePath)) + ".css");
|
|
175
|
+
this._writeFile(outFilePath, scssResult.css.toString());
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
this._logger.error(err);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const affectedSourceFile = this._builder.getSourceFile(affectedFilePath);
|
|
184
|
+
if (!affectedSourceFile)
|
|
185
|
+
continue;
|
|
186
|
+
const emitResult = this._builder.emit(affectedSourceFile, (filePath, data) => {
|
|
187
|
+
let realFilePath = filePath;
|
|
188
|
+
let realData = data;
|
|
189
|
+
if (PathUtil.isChildPath(realFilePath, path.resolve(distPath, path.basename(this._opt.pkgPath), "src"))) {
|
|
190
|
+
realFilePath = path.resolve(distPath, path.relative(path.resolve(distPath, path.basename(this._opt.pkgPath), "src"), realFilePath));
|
|
191
|
+
if (filePath.endsWith(".js.map")) {
|
|
192
|
+
const sourceMapContents = JSON.parse(realData);
|
|
193
|
+
// remove "../../"
|
|
194
|
+
sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
|
|
195
|
+
realData = JSON.stringify(sourceMapContents);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
this._writeFile(realFilePath, realData);
|
|
199
|
+
}, undefined, !this._opt.emit, { ...this._ngProgram?.compiler.prepareEmit().transformers ?? {} });
|
|
200
|
+
diagnostics.push(...emitResult.diagnostics);
|
|
201
|
+
diagnostics.push(...this._builder.getSyntacticDiagnostics(affectedSourceFile));
|
|
202
|
+
if (this._ngProgram &&
|
|
203
|
+
!affectedSourceFile.isDeclarationFile &&
|
|
204
|
+
!this._ngProgram.compiler.ignoreForEmit.has(affectedSourceFile) &&
|
|
205
|
+
!this._ngProgram.compiler.incrementalCompilation.safeToSkipEmit(affectedSourceFile)) {
|
|
206
|
+
diagnostics.push(...this._ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, 1));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 ${this._opt.emit ? "EMIT" : "CHECK"} 완료`, affectedFilePaths);
|
|
211
|
+
const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item, this._opt.emit ? "build" : "check"));
|
|
212
|
+
return {
|
|
213
|
+
filePaths: [
|
|
214
|
+
...Array.from(this._styleDepsCache.keys()),
|
|
215
|
+
...this._builder.getSourceFiles().map(item => path.resolve(item.fileName))
|
|
216
|
+
],
|
|
217
|
+
affectedFilePaths: affectedFilePaths,
|
|
218
|
+
results: buildResults
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
_writeFile(filePath, data) {
|
|
222
|
+
if (this._writeFileCache.get(filePath) !== data) {
|
|
223
|
+
this._compilerHost.writeFile(filePath, data, false);
|
|
224
|
+
}
|
|
225
|
+
this._writeFileCache.set(filePath, data);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
228
|
//# sourceMappingURL=SdTsCompiler.js.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from "events";
|
|
3
|
-
import { ISdCliBuilderResult, ISdCliConfig } from "../commons";
|
|
4
|
-
export declare class SdCliClientBuilder extends EventEmitter {
|
|
5
|
-
private readonly _projConf;
|
|
6
|
-
private readonly _pkgPath;
|
|
7
|
-
private readonly _logger;
|
|
8
|
-
private readonly _pkgConf;
|
|
9
|
-
private _builders?;
|
|
10
|
-
private _cordova?;
|
|
11
|
-
constructor(_projConf: ISdCliConfig, _pkgPath: string);
|
|
12
|
-
on(event: "change", listener: () => void): this;
|
|
13
|
-
on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
|
|
14
|
-
buildAsync(): Promise<ISdCliBuilderResult>;
|
|
15
|
-
watchAsync(): Promise<void>;
|
|
16
|
-
private _runAsync;
|
|
17
|
-
private _debug;
|
|
18
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { ISdCliBuilderResult, ISdCliConfig } from "../commons";
|
|
4
|
+
export declare class SdCliClientBuilder extends EventEmitter {
|
|
5
|
+
private readonly _projConf;
|
|
6
|
+
private readonly _pkgPath;
|
|
7
|
+
private readonly _logger;
|
|
8
|
+
private readonly _pkgConf;
|
|
9
|
+
private _builders?;
|
|
10
|
+
private _cordova?;
|
|
11
|
+
constructor(_projConf: ISdCliConfig, _pkgPath: string);
|
|
12
|
+
on(event: "change", listener: () => void): this;
|
|
13
|
+
on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
|
|
14
|
+
buildAsync(): Promise<ISdCliBuilderResult>;
|
|
15
|
+
watchAsync(): Promise<void>;
|
|
16
|
+
private _runAsync;
|
|
17
|
+
private _debug;
|
|
18
|
+
}
|