@simplysm/sd-cli 12.5.16 → 12.5.18
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/SdCliIndexFileGenerator.js +2 -2
- package/dist/build-tools/SdCliIndexFileGenerator.js.map +1 -1
- package/dist/build-tools/SdLinter.js +5 -2
- package/dist/build-tools/SdLinter.js.map +1 -1
- package/dist/build-tools/SdReactBundler.d.ts +24 -0
- package/dist/build-tools/SdReactBundler.js +294 -0
- package/dist/build-tools/SdReactBundler.js.map +1 -0
- package/dist/build-tools/SdReactBundlerContext.d.ts +14 -0
- package/dist/build-tools/SdReactBundlerContext.js +59 -0
- package/dist/build-tools/SdReactBundlerContext.js.map +1 -0
- package/dist/build-tools/SdTsCompiler.js +274 -226
- package/dist/build-tools/SdTsCompiler.js.map +1 -1
- package/dist/builders/SdCliClientBuilder.js +41 -17
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/bundle-plugins/sdReactPlugin.d.ts +15 -0
- package/dist/bundle-plugins/sdReactPlugin.js +116 -0
- package/dist/bundle-plugins/sdReactPlugin.js.map +1 -0
- package/dist/entry/SdCliProject.js +2 -2
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +15 -15
- package/src/build-tools/SdCliIndexFileGenerator.ts +2 -2
- package/src/build-tools/SdLinter.ts +8 -2
- package/src/build-tools/SdReactBundler.ts +370 -0
- package/src/build-tools/SdReactBundlerContext.ts +71 -0
- package/src/build-tools/SdTsCompiler.ts +227 -112
- package/src/builders/SdCliClientBuilder.ts +52 -27
- package/src/bundle-plugins/sdReactPlugin.ts +160 -0
- package/src/entry/SdCliProject.ts +6 -2
- package/src/index.ts +3 -0
- package/tsconfig.json +5 -11
- package/eslint.config.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
4
|
-
import {
|
|
4
|
+
import { StringUtil } from "@simplysm/sd-core-common";
|
|
5
5
|
import { NgtscProgram, OptimizeFor } from "@angular/compiler-cli";
|
|
6
6
|
import { createHash } from "crypto";
|
|
7
7
|
import { ComponentStylesheetBundler } from "@angular/build/src/tools/esbuild/angular/component-stylesheets";
|
|
@@ -13,7 +13,7 @@ export class SdTsCompiler {
|
|
|
13
13
|
#logger = Logger.get(["simplysm", "sd-cli", "SdTsCompiler"]);
|
|
14
14
|
#parsedTsconfig;
|
|
15
15
|
#isForAngular;
|
|
16
|
-
#revDependencyCacheMap = new Map();
|
|
16
|
+
// readonly #revDependencyCacheMap = new Map<string, Set<string>>();
|
|
17
17
|
#resourceDependencyCacheMap = new Map();
|
|
18
18
|
#sourceFileCacheMap = new Map();
|
|
19
19
|
#emittedFilesCacheMap = new Map();
|
|
@@ -21,6 +21,7 @@ export class SdTsCompiler {
|
|
|
21
21
|
#compilerHost;
|
|
22
22
|
#ngProgram;
|
|
23
23
|
#program;
|
|
24
|
+
#builder;
|
|
24
25
|
#modifiedFileSet = new Set();
|
|
25
26
|
#watchFileSet = new Set();
|
|
26
27
|
#stylesheetBundlingResultMap = new Map();
|
|
@@ -125,26 +126,33 @@ export class SdTsCompiler {
|
|
|
125
126
|
return stylesheetResult.contents;
|
|
126
127
|
}
|
|
127
128
|
invalidate(modifiedFileSet) {
|
|
128
|
-
|
|
129
|
+
for (const modifiedFile of Array.from(modifiedFileSet).map((item) => path.normalize(item))) {
|
|
130
|
+
this.#modifiedFileSet.add(modifiedFile);
|
|
131
|
+
this.#modifiedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
|
|
132
|
+
}
|
|
129
133
|
}
|
|
130
134
|
async buildAsync() {
|
|
131
|
-
const
|
|
135
|
+
const affectedSourceFileSet = new Set();
|
|
132
136
|
const emitFileSet = new Set();
|
|
133
137
|
this.#debug(`get affected (old deps & old res deps)...`);
|
|
134
138
|
for (const modifiedFile of this.#modifiedFileSet) {
|
|
135
|
-
affectedFileSet.add(modifiedFile);
|
|
136
|
-
affectedFileSet.adds(...(this.#revDependencyCacheMap.get(modifiedFile) ?? []));
|
|
137
|
-
affectedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
|
|
139
|
+
// affectedFileSet.add(modifiedFile);
|
|
140
|
+
// affectedFileSet.adds(...(this.#revDependencyCacheMap.get(modifiedFile) ?? []));
|
|
141
|
+
// affectedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
|
|
138
142
|
this.#emittedFilesCacheMap.delete(path.normalize(modifiedFile));
|
|
143
|
+
this.#sourceFileCacheMap.delete(path.normalize(modifiedFile));
|
|
144
|
+
this.#stylesheetBundlingResultMap.delete(path.normalize(modifiedFile));
|
|
145
|
+
this.#watchFileSet.delete(path.normalize(modifiedFile));
|
|
139
146
|
}
|
|
140
|
-
this.#debug(`invalidate & clear cache...`);
|
|
141
147
|
this.#stylesheetBundler?.invalidate(this.#modifiedFileSet);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.#
|
|
148
|
+
// this.#debug(`invalidate & clear cache...`);
|
|
149
|
+
// this.#stylesheetBundler?.invalidate(affectedFileSet);
|
|
150
|
+
// for (const affectedFile of affectedFileSet) {
|
|
151
|
+
// this.#sourceFileCacheMap.delete(path.normalize(affectedFile));
|
|
152
|
+
// this.#stylesheetBundlingResultMap.delete(path.normalize(affectedFile));
|
|
153
|
+
// this.#watchFileSet.delete(path.normalize(affectedFile));
|
|
154
|
+
// }
|
|
155
|
+
// this.#revDependencyCacheMap.clear();
|
|
148
156
|
this.#resourceDependencyCacheMap.clear();
|
|
149
157
|
this.#debug(`create program...`);
|
|
150
158
|
if (this.#isForAngular) {
|
|
@@ -154,6 +162,7 @@ export class SdTsCompiler {
|
|
|
154
162
|
else {
|
|
155
163
|
this.#program = ts.createProgram(this.#parsedTsconfig.fileNames, this.#parsedTsconfig.options, this.#compilerHost, this.#program);
|
|
156
164
|
}
|
|
165
|
+
this.#debug(`create builder...`);
|
|
157
166
|
const baseGetSourceFiles = this.#program.getSourceFiles;
|
|
158
167
|
this.#program.getSourceFiles = function (...parameters) {
|
|
159
168
|
const files = baseGetSourceFiles(...parameters);
|
|
@@ -164,7 +173,7 @@ export class SdTsCompiler {
|
|
|
164
173
|
}
|
|
165
174
|
return files;
|
|
166
175
|
};
|
|
167
|
-
this.#
|
|
176
|
+
this.#builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(this.#program, this.#compilerHost, this.#builder);
|
|
168
177
|
if (this.#ngProgram) {
|
|
169
178
|
await this.#ngProgram.compiler.analyzeAsync();
|
|
170
179
|
}
|
|
@@ -176,91 +185,126 @@ export class SdTsCompiler {
|
|
|
176
185
|
return sf;
|
|
177
186
|
};
|
|
178
187
|
this.#debug(`get affected (new deps)...`);
|
|
179
|
-
const sourceFileSet = new Set(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
188
|
+
// const sourceFileSet = new Set(
|
|
189
|
+
// this.#program
|
|
190
|
+
// .getSourceFiles()
|
|
191
|
+
// .map((sf) => getOrgSourceFile(sf))
|
|
192
|
+
// .filterExists(),
|
|
193
|
+
// );
|
|
194
|
+
// const depMap = new Map<
|
|
195
|
+
// string,
|
|
196
|
+
// {
|
|
197
|
+
// fileName: string;
|
|
198
|
+
// importName: string;
|
|
199
|
+
// exportName?: string;
|
|
200
|
+
// }[]
|
|
201
|
+
// >();
|
|
202
|
+
// for (const sf of sourceFileSet) {
|
|
203
|
+
// const refs = this.#findDeps(sf);
|
|
204
|
+
// depMap.set(path.normalize(sf.fileName), refs);
|
|
205
|
+
// }
|
|
206
|
+
//
|
|
207
|
+
// const allDepMap = new Map<string, Set<string>>();
|
|
208
|
+
// const getAllDeps = (fileName: string, prevSet?: Set<string>) => {
|
|
209
|
+
// if (allDepMap.has(fileName)) {
|
|
210
|
+
// return allDepMap.get(fileName)!;
|
|
211
|
+
// }
|
|
212
|
+
//
|
|
213
|
+
// const result = new Set<string>();
|
|
214
|
+
//
|
|
215
|
+
// const deps = depMap.get(fileName) ?? [];
|
|
216
|
+
// result.adds(...deps.map((item) => item.fileName));
|
|
217
|
+
//
|
|
218
|
+
// for (const dep of deps) {
|
|
219
|
+
// const targetDeps = depMap.get(dep.fileName) ?? [];
|
|
220
|
+
//
|
|
221
|
+
// if (dep.importName === "*") {
|
|
222
|
+
// for (const targetRefItem of targetDeps.filter((item) => item.exportName != null)) {
|
|
223
|
+
// if (prevSet?.has(targetRefItem.fileName)) continue;
|
|
224
|
+
//
|
|
225
|
+
// result.add(targetRefItem.fileName);
|
|
226
|
+
// result.adds(...getAllDeps(targetRefItem.fileName, new Set<string>(prevSet).adds(...result)));
|
|
227
|
+
// }
|
|
228
|
+
// } else {
|
|
229
|
+
// for (const targetRefItem of targetDeps.filter((item) => item.exportName === dep.importName)) {
|
|
230
|
+
// if (prevSet?.has(targetRefItem.fileName)) continue;
|
|
231
|
+
//
|
|
232
|
+
// result.add(targetRefItem.fileName);
|
|
233
|
+
// result.adds(...getAllDeps(targetRefItem.fileName, new Set<string>(prevSet).adds(...result)));
|
|
234
|
+
// }
|
|
235
|
+
// }
|
|
236
|
+
// }
|
|
237
|
+
//
|
|
238
|
+
// return result;
|
|
239
|
+
// };
|
|
240
|
+
// for (const sf of sourceFileSet) {
|
|
241
|
+
// const deps = getAllDeps(path.normalize(sf.fileName));
|
|
242
|
+
// allDepMap.set(path.normalize(sf.fileName), deps);
|
|
243
|
+
//
|
|
244
|
+
// for (const dep of getAllDeps(path.normalize(sf.fileName))) {
|
|
245
|
+
// const depCache = this.#revDependencyCacheMap.getOrCreate(path.normalize(dep), new Set<string>());
|
|
246
|
+
// depCache.add(path.normalize(sf.fileName));
|
|
247
|
+
// if (this.#modifiedFileSet.has(path.normalize(dep))) {
|
|
248
|
+
// affectedFileSet.add(path.normalize(sf.fileName));
|
|
249
|
+
// }
|
|
250
|
+
// }
|
|
251
|
+
//
|
|
252
|
+
// if (this.#ngProgram) {
|
|
253
|
+
// if (this.#ngProgram.compiler.ignoreForEmit.has(sf)) {
|
|
254
|
+
// continue;
|
|
255
|
+
// }
|
|
256
|
+
//
|
|
257
|
+
// for (const dep of this.#ngProgram.compiler.getResourceDependencies(sf)) {
|
|
258
|
+
// const ref = this.#resourceDependencyCacheMap.getOrCreate(path.normalize(dep), new Set<string>());
|
|
259
|
+
// ref.add(path.normalize(sf.fileName));
|
|
260
|
+
// if (this.#modifiedFileSet.has(path.normalize(dep))) {
|
|
261
|
+
// affectedFileSet.add(path.normalize(sf.fileName));
|
|
262
|
+
// }
|
|
263
|
+
// }
|
|
264
|
+
// }
|
|
265
|
+
// }
|
|
266
|
+
// if (affectedFileSet.size === 0) {
|
|
267
|
+
// this.#debug(`get affected (init)...`);
|
|
268
|
+
//
|
|
269
|
+
// for (const sf of this.#program.getSourceFiles()) {
|
|
270
|
+
// const orgSf = getOrgSourceFile(sf);
|
|
271
|
+
// if (!orgSf) continue;
|
|
272
|
+
//
|
|
273
|
+
// affectedFileSet.add(path.normalize(orgSf.fileName));
|
|
274
|
+
// }
|
|
275
|
+
// }
|
|
249
276
|
this.#debug(`get diagnostics...`);
|
|
250
277
|
const diagnostics = [];
|
|
251
|
-
diagnostics.push(...this.#
|
|
278
|
+
diagnostics.push(...this.#builder.getConfigFileParsingDiagnostics(), ...this.#builder.getOptionsDiagnostics(), ...this.#builder.getGlobalDiagnostics());
|
|
279
|
+
/*diagnostics.push(
|
|
280
|
+
...this.#program.getConfigFileParsingDiagnostics(),
|
|
281
|
+
...this.#program.getOptionsDiagnostics(),
|
|
282
|
+
...this.#program.getGlobalDiagnostics(),
|
|
283
|
+
);*/
|
|
252
284
|
if (this.#ngProgram) {
|
|
253
285
|
diagnostics.push(...this.#ngProgram.compiler.getOptionDiagnostics());
|
|
254
286
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
(this.#ngProgram &&
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
287
|
+
this.#debug(`get diagnostics of files...`);
|
|
288
|
+
while (true) {
|
|
289
|
+
const affectedFileResult = this.#builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sf) => {
|
|
290
|
+
if (this.#ngProgram &&
|
|
291
|
+
this.#ngProgram.compiler.ignoreForDiagnostics.has(sf) &&
|
|
292
|
+
sf.fileName.endsWith(".ngtypecheck.ts")) {
|
|
293
|
+
const orgSourceFile = getOrgSourceFile(sf);
|
|
294
|
+
if (orgSourceFile) {
|
|
295
|
+
affectedSourceFileSet.add(orgSourceFile);
|
|
296
|
+
}
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
return false;
|
|
300
|
+
});
|
|
301
|
+
if (!affectedFileResult)
|
|
302
|
+
break;
|
|
303
|
+
const affectedSourceFile = affectedFileResult.affected;
|
|
304
|
+
affectedSourceFileSet.add(affectedSourceFile);
|
|
305
|
+
}
|
|
306
|
+
for (const affectedSourceFile of affectedSourceFileSet) {
|
|
307
|
+
this.#debug(`get diagnostics of file [${affectedSourceFile.fileName}]`);
|
|
264
308
|
diagnostics.push(...this.#program.getSyntacticDiagnostics(affectedSourceFile), ...this.#program.getSemanticDiagnostics(affectedSourceFile));
|
|
265
309
|
if (this.#ngProgram) {
|
|
266
310
|
if (affectedSourceFile.isDeclarationFile) {
|
|
@@ -269,6 +313,37 @@ export class SdTsCompiler {
|
|
|
269
313
|
diagnostics.push(...this.#ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram));
|
|
270
314
|
}
|
|
271
315
|
}
|
|
316
|
+
/*
|
|
317
|
+
for (const affectedFile of affectedFileSet) {
|
|
318
|
+
if (!PathUtil.isChildPath(affectedFile, this.#pkgPath)) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
this.#debug(`get diagnostics of file [${affectedFile}]`);
|
|
323
|
+
|
|
324
|
+
const affectedSourceFile = this.#program.getSourceFile(affectedFile);
|
|
325
|
+
if (
|
|
326
|
+
!affectedSourceFile ||
|
|
327
|
+
(this.#ngProgram && this.#ngProgram.compiler.ignoreForDiagnostics.has(affectedSourceFile))
|
|
328
|
+
) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
diagnostics.push(
|
|
333
|
+
...this.#program.getSyntacticDiagnostics(affectedSourceFile),
|
|
334
|
+
...this.#program.getSemanticDiagnostics(affectedSourceFile),
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
if (this.#ngProgram) {
|
|
338
|
+
if (affectedSourceFile.isDeclarationFile) {
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
diagnostics.push(
|
|
343
|
+
...this.#ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram),
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
}*/
|
|
272
347
|
this.#debug(`prepare emit...`);
|
|
273
348
|
let transformers = {};
|
|
274
349
|
if (this.#ngProgram) {
|
|
@@ -279,6 +354,42 @@ export class SdTsCompiler {
|
|
|
279
354
|
(transformers.before ??= []).push(replaceBootstrap(() => this.#program.getTypeChecker()));
|
|
280
355
|
}
|
|
281
356
|
(transformers.before ??= []).push(transformKeys(this.#program));
|
|
357
|
+
this.#debug(`prepare emit files...`);
|
|
358
|
+
while (this.#builder.emitNextAffectedFile((fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
|
|
359
|
+
if (!sourceFiles || sourceFiles.length === 0) {
|
|
360
|
+
this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
|
|
364
|
+
if (this.#ngProgram) {
|
|
365
|
+
if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
|
|
369
|
+
}
|
|
370
|
+
const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(path.normalize(sourceFile.fileName), []);
|
|
371
|
+
if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
|
|
372
|
+
let realFilePath = fileName;
|
|
373
|
+
let realText = text;
|
|
374
|
+
if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
|
|
375
|
+
realFilePath = path.resolve(this.#distPath, path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath));
|
|
376
|
+
if (fileName.endsWith(".js.map")) {
|
|
377
|
+
const sourceMapContents = JSON.parse(realText);
|
|
378
|
+
// remove "../../"
|
|
379
|
+
sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
|
|
380
|
+
realText = JSON.stringify(sourceMapContents);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
emitFileInfoCaches.push({
|
|
384
|
+
outAbsPath: realFilePath,
|
|
385
|
+
text: realText,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
emitFileInfoCaches.push({ text });
|
|
390
|
+
}
|
|
391
|
+
emitFileSet.add(path.normalize(sourceFile.fileName));
|
|
392
|
+
}, undefined, undefined, transformers)) { }
|
|
282
393
|
// affected에 새로 추가된 파일은 포함되지 않는 현상이 있어 getSourceFiles로 바꿈
|
|
283
394
|
// 비교해보니, 딱히 getSourceFiles라서 더 느려지는것 같지는 않음
|
|
284
395
|
/*for (const affectedFile of affectedFileSet) {
|
|
@@ -290,59 +401,76 @@ export class SdTsCompiler {
|
|
|
290
401
|
if (!sf) {
|
|
291
402
|
continue;
|
|
292
403
|
}*/
|
|
293
|
-
for (const sf of sourceFileSet) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
404
|
+
/*for (const sf of sourceFileSet) {
|
|
405
|
+
if (this.#emittedFilesCacheMap.has(path.normalize(sf.fileName))) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (sf.isDeclarationFile) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (this.#ngProgram?.compiler.ignoreForEmit.has(sf)) {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// esbuild를 통해 bundle로 묶어야 하는놈들은 모든 output이 있어야 함.
|
|
418
|
+
if (!this.#isForBundle) {
|
|
419
|
+
if (!PathUtil.isChildPath(sf.fileName, this.#pkgPath)) {
|
|
420
|
+
continue;
|
|
308
421
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
let realFilePath = fileName;
|
|
325
|
-
let realText = text;
|
|
326
|
-
if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
|
|
327
|
-
realFilePath = path.resolve(this.#distPath, path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath));
|
|
328
|
-
if (fileName.endsWith(".js.map")) {
|
|
329
|
-
const sourceMapContents = JSON.parse(realText);
|
|
330
|
-
// remove "../../"
|
|
331
|
-
sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
|
|
332
|
-
realText = JSON.stringify(sourceMapContents);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
emitFileInfoCaches.push({
|
|
336
|
-
outAbsPath: realFilePath,
|
|
337
|
-
text: realText,
|
|
338
|
-
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
this.#debug(`emit for`, sf.fileName);
|
|
425
|
+
this.#program.emit(
|
|
426
|
+
sf,
|
|
427
|
+
(fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
|
|
428
|
+
if (!sourceFiles || sourceFiles.length === 0) {
|
|
429
|
+
this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
|
|
434
|
+
if (this.#ngProgram) {
|
|
435
|
+
if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
|
|
436
|
+
return;
|
|
339
437
|
}
|
|
340
|
-
|
|
341
|
-
|
|
438
|
+
this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(path.normalize(sourceFile.fileName), []);
|
|
442
|
+
if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
|
|
443
|
+
let realFilePath = fileName;
|
|
444
|
+
let realText = text;
|
|
445
|
+
if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
|
|
446
|
+
realFilePath = path.resolve(
|
|
447
|
+
this.#distPath,
|
|
448
|
+
path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath),
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
if (fileName.endsWith(".js.map")) {
|
|
452
|
+
const sourceMapContents = JSON.parse(realText);
|
|
453
|
+
// remove "../../"
|
|
454
|
+
sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
|
|
455
|
+
realText = JSON.stringify(sourceMapContents);
|
|
456
|
+
}
|
|
342
457
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
458
|
+
|
|
459
|
+
emitFileInfoCaches.push({
|
|
460
|
+
outAbsPath: realFilePath,
|
|
461
|
+
text: realText,
|
|
462
|
+
});
|
|
463
|
+
} else {
|
|
464
|
+
emitFileInfoCaches.push({ text });
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
emitFileSet.add(path.normalize(sourceFile.fileName));
|
|
468
|
+
},
|
|
469
|
+
undefined,
|
|
470
|
+
undefined,
|
|
471
|
+
transformers,
|
|
472
|
+
);
|
|
473
|
+
}*/
|
|
346
474
|
//-- global style
|
|
347
475
|
if (this.#globalStyleFilePath != null &&
|
|
348
476
|
FsUtil.exists(this.#globalStyleFilePath) &&
|
|
@@ -359,6 +487,7 @@ export class SdTsCompiler {
|
|
|
359
487
|
}
|
|
360
488
|
//-- init
|
|
361
489
|
this.#modifiedFileSet.clear();
|
|
490
|
+
const affectedFileSet = new Set(Array.from(affectedSourceFileSet).map((item) => path.normalize(item.fileName)));
|
|
362
491
|
this.#debug(`build completed`, affectedFileSet, diagnostics.length);
|
|
363
492
|
//-- result
|
|
364
493
|
return {
|
|
@@ -374,86 +503,5 @@ export class SdTsCompiler {
|
|
|
374
503
|
#debug(...msg) {
|
|
375
504
|
this.#logger.debug(`[${path.basename(this.#pkgPath)}]`, ...msg);
|
|
376
505
|
}
|
|
377
|
-
#findDeps(sf) {
|
|
378
|
-
const deps = [];
|
|
379
|
-
const tc = this.#program.getTypeChecker();
|
|
380
|
-
sf.forEachChild((node) => {
|
|
381
|
-
if (ts.isExportDeclaration(node)) {
|
|
382
|
-
if (node.moduleSpecifier) {
|
|
383
|
-
const moduleSymbol = tc.getSymbolAtLocation(node.moduleSpecifier);
|
|
384
|
-
if (!moduleSymbol)
|
|
385
|
-
throw new NeverEntryError(`export moduleSymbol: ${sf.fileName}`);
|
|
386
|
-
const decls = moduleSymbol.getDeclarations();
|
|
387
|
-
if (!decls)
|
|
388
|
-
throw new NeverEntryError(`export decls: ${sf.fileName}`);
|
|
389
|
-
const namedBindings = node.exportClause;
|
|
390
|
-
if (namedBindings && ts.isNamedExports(namedBindings)) {
|
|
391
|
-
for (const el of namedBindings.elements) {
|
|
392
|
-
for (const decl of decls) {
|
|
393
|
-
deps.push({
|
|
394
|
-
fileName: path.normalize(decl.getSourceFile().fileName),
|
|
395
|
-
importName: el.name.text,
|
|
396
|
-
exportName: el.propertyName?.text ?? el.name.text,
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
if (!moduleSymbol.exports) {
|
|
403
|
-
throw new NeverEntryError("1234");
|
|
404
|
-
}
|
|
405
|
-
for (const decl of decls) {
|
|
406
|
-
for (const key of moduleSymbol.exports.keys()) {
|
|
407
|
-
deps.push({
|
|
408
|
-
fileName: path.normalize(decl.getSourceFile().fileName),
|
|
409
|
-
importName: key.toString(),
|
|
410
|
-
exportName: key.toString(),
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
else if (ts.isImportDeclaration(node)) {
|
|
418
|
-
const moduleSymbol = tc.getSymbolAtLocation(node.moduleSpecifier);
|
|
419
|
-
if (!moduleSymbol) {
|
|
420
|
-
if (ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text.startsWith("./")) {
|
|
421
|
-
deps.push({
|
|
422
|
-
fileName: path.normalize(path.resolve(path.dirname(sf.fileName), node.moduleSpecifier.text)),
|
|
423
|
-
importName: "*",
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
/*else {
|
|
427
|
-
throw new NeverEntryError(`import moduleSymbol: ${sf.fileName} ${node.moduleSpecifier["text"]}`);
|
|
428
|
-
}*/
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
const decls = moduleSymbol.getDeclarations();
|
|
432
|
-
if (!decls)
|
|
433
|
-
throw new NeverEntryError(`import decls: ${sf.fileName}`);
|
|
434
|
-
const namedBindings = node.importClause?.namedBindings;
|
|
435
|
-
if (namedBindings && ts.isNamedImports(namedBindings)) {
|
|
436
|
-
for (const el of namedBindings.elements) {
|
|
437
|
-
for (const decl of decls) {
|
|
438
|
-
deps.push({
|
|
439
|
-
fileName: path.normalize(decl.getSourceFile().fileName),
|
|
440
|
-
importName: el.name.text,
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
for (const decl of decls) {
|
|
447
|
-
deps.push({
|
|
448
|
-
fileName: path.normalize(decl.getSourceFile().fileName),
|
|
449
|
-
importName: "*",
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
return deps;
|
|
457
|
-
}
|
|
458
506
|
}
|
|
459
507
|
//# sourceMappingURL=SdTsCompiler.js.map
|