@simplysm/sd-cli 12.5.22 → 12.5.24

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.
Files changed (77) hide show
  1. package/dist/entry/SdCliCordova.js +2 -2
  2. package/dist/entry/SdCliCordova.js.map +1 -1
  3. package/dist/entry/SdCliElectron.js +2 -2
  4. package/dist/entry/SdCliElectron.js.map +1 -1
  5. package/dist/entry/SdCliLocalUpdate.js +6 -8
  6. package/dist/entry/SdCliLocalUpdate.js.map +1 -1
  7. package/dist/entry/SdCliProject.js +4 -4
  8. package/dist/entry/SdCliProject.js.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/pkg-builders/SdMultiBuildRunner.d.ts +3 -10
  13. package/dist/pkg-builders/SdMultiBuildRunner.js +133 -117
  14. package/dist/pkg-builders/SdMultiBuildRunner.js.map +1 -1
  15. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.js +1 -1
  16. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.js.map +1 -1
  17. package/dist/pkg-builders/client/SdClientBuildRunner.d.ts +6 -5
  18. package/dist/pkg-builders/client/SdClientBuildRunner.js +16 -8
  19. package/dist/pkg-builders/client/SdClientBuildRunner.js.map +1 -1
  20. package/dist/pkg-builders/client/SdNgBundler.js +13 -61
  21. package/dist/pkg-builders/client/SdNgBundler.js.map +1 -1
  22. package/dist/pkg-builders/client/createSdNgPlugin.js +3 -3
  23. package/dist/pkg-builders/client/createSdNgPlugin.js.map +1 -1
  24. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js +1 -1
  25. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js.map +1 -1
  26. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js +1 -1
  27. package/dist/pkg-builders/lib/SdTsLibBuildRunner.d.ts +6 -1
  28. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js +27 -28
  29. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js.map +1 -1
  30. package/dist/pkg-builders/lib/SdTsLibBuilder.d.ts +3 -4
  31. package/dist/pkg-builders/lib/SdTsLibBuilder.js +7 -11
  32. package/dist/pkg-builders/lib/SdTsLibBuilder.js.map +1 -1
  33. package/dist/pkg-builders/server/SdServerBuildRunner.d.ts +5 -1
  34. package/dist/pkg-builders/server/SdServerBuildRunner.js +32 -29
  35. package/dist/pkg-builders/server/SdServerBuildRunner.js.map +1 -1
  36. package/dist/pkg-builders/server/createSdServerPlugin.js +3 -3
  37. package/dist/pkg-builders/server/createSdServerPlugin.js.map +1 -1
  38. package/dist/ts-builder/SdTsCompiler.d.ts +1 -1
  39. package/dist/ts-builder/SdTsCompiler.js +222 -201
  40. package/dist/ts-builder/SdTsCompiler.js.map +1 -1
  41. package/dist/types/build-runner.type.d.ts +7 -0
  42. package/dist/types/build-runner.type.js +2 -0
  43. package/dist/types/build-runner.type.js.map +1 -0
  44. package/dist/types/workers.type.d.ts +15 -1
  45. package/dist/workers/build-runner-worker.js +45 -0
  46. package/dist/workers/build-runner-worker.js.map +1 -0
  47. package/package.json +6 -6
  48. package/src/entry/SdCliCordova.ts +2 -2
  49. package/src/entry/SdCliElectron.ts +2 -2
  50. package/src/entry/SdCliLocalUpdate.ts +8 -8
  51. package/src/entry/SdCliProject.ts +4 -4
  52. package/src/index.ts +1 -1
  53. package/src/pkg-builders/SdMultiBuildRunner.ts +123 -121
  54. package/src/pkg-builders/client/SdCliNgRoutesFileGenerator.ts +1 -1
  55. package/src/pkg-builders/client/SdClientBuildRunner.ts +26 -22
  56. package/src/pkg-builders/client/SdNgBundler.ts +16 -74
  57. package/src/pkg-builders/client/createSdNgPlugin.ts +3 -3
  58. package/src/pkg-builders/lib/SdCliIndexFileGenerator.ts +1 -1
  59. package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +1 -1
  60. package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +42 -29
  61. package/src/pkg-builders/lib/SdTsLibBuilder.ts +13 -14
  62. package/src/pkg-builders/server/SdServerBuildRunner.ts +44 -29
  63. package/src/pkg-builders/server/createSdServerPlugin.ts +3 -3
  64. package/src/ts-builder/SdTsCompiler.ts +282 -261
  65. package/src/types/build-runner.type.ts +8 -0
  66. package/src/types/workers.type.ts +14 -1
  67. package/src/workers/build-runner-worker.ts +52 -0
  68. package/tsconfig.json +1 -1
  69. package/dist/ts-builder/SdTsCompileWorker.d.ts +0 -9
  70. package/dist/ts-builder/SdTsCompileWorker.js +0 -16
  71. package/dist/ts-builder/SdTsCompileWorker.js.map +0 -1
  72. package/dist/workers/compile-worker.js +0 -27
  73. package/dist/workers/compile-worker.js.map +0 -1
  74. package/lib/dev-worker.cjs +0 -5
  75. package/src/ts-builder/SdTsCompileWorker.ts +0 -21
  76. package/src/workers/compile-worker.ts +0 -31
  77. /package/dist/workers/{compile-worker.d.ts → build-runner-worker.d.ts} +0 -0
@@ -52,6 +52,8 @@ export class SdTsCompiler {
52
52
 
53
53
  readonly #lintWorker = new SdWorker<TSdLintWorkerType>(import.meta.resolve("../workers/lint-worker"));
54
54
 
55
+ #perf!: SdCliPerformanceTimer;
56
+
55
57
  constructor(opt: SdTsCompilerOptions) {
56
58
  this.#pkgPath = opt.pkgPath;
57
59
  this.#globalStyleFilePath = opt.globalStyleFilePath;
@@ -159,7 +161,7 @@ export class SdTsCompiler {
159
161
  };
160
162
 
161
163
  (this.#compilerHost as AngularCompilerHost).getModifiedResourceFiles = () => {
162
- return this.#modifiedFileSet;
164
+ return new Set(Array.from(this.#modifiedFileSet).map((item) => PathUtil.posix(item)));
163
165
  };
164
166
  }
165
167
  }
@@ -169,73 +171,98 @@ export class SdTsCompiler {
169
171
  // resourceFile: 외부 리소스 파일 (styleUrls로 입력하지 않고 styles에 직접 입력한 경우 null)
170
172
  // referencedFiles: import한 외부 scss 파일 혹은 woff파일등 외부 파일
171
173
 
172
- this.#debug(`스타일시트 번들링...(${containingFile}, ${resourceFile})`);
174
+ // this.#debug(`bundle stylesheet...(${containingFile}, ${resourceFile})`);
173
175
 
174
- const stylesheetResult =
175
- resourceFile != null
176
- ? await this.#stylesheetBundler!.bundleFile(resourceFile)
177
- : await this.#stylesheetBundler!.bundleInline(data, containingFile, "scss");
176
+ return await this.#perf.run("bundle style", async () => {
177
+ const stylesheetResult =
178
+ resourceFile != null
179
+ ? await this.#stylesheetBundler!.bundleFile(resourceFile)
180
+ : await this.#stylesheetBundler!.bundleInline(data, containingFile, "scss");
178
181
 
179
- if (stylesheetResult.referencedFiles) {
180
- for (const referencedFile of stylesheetResult.referencedFiles) {
181
- const depCacheSet = this.#resourceDependencyCacheMap.getOrCreate(
182
- PathUtil.norm(referencedFile),
183
- new Set<TNormPath>(),
182
+ if (stylesheetResult.referencedFiles) {
183
+ for (const referencedFile of stylesheetResult.referencedFiles) {
184
+ const depCacheSet = this.#resourceDependencyCacheMap.getOrCreate(
185
+ PathUtil.norm(referencedFile),
186
+ new Set<TNormPath>(),
187
+ );
188
+ depCacheSet.add(resourceFile ?? containingFile);
189
+ }
190
+
191
+ this.#watchFileSet.adds(
192
+ ...Array.from(stylesheetResult.referencedFiles.values()).map((item) => PathUtil.norm(item)),
184
193
  );
185
- depCacheSet.add(resourceFile ?? containingFile);
186
194
  }
187
195
 
188
- this.#watchFileSet.adds(
189
- ...Array.from(stylesheetResult.referencedFiles.values()).map((item) => PathUtil.norm(item)),
190
- );
191
- }
196
+ this.#stylesheetBundlingResultMap.set(PathUtil.norm(resourceFile ?? containingFile), {
197
+ outputFiles: stylesheetResult.outputFiles,
198
+ metafile: stylesheetResult.metafile,
199
+ errors: stylesheetResult.errors,
200
+ warnings: stylesheetResult.warnings,
201
+ });
192
202
 
193
- this.#stylesheetBundlingResultMap.set(PathUtil.norm(resourceFile ?? containingFile), {
194
- outputFiles: stylesheetResult.outputFiles,
195
- metafile: stylesheetResult.metafile,
196
- errors: stylesheetResult.errors,
197
- warnings: stylesheetResult.warnings,
203
+ return stylesheetResult.contents;
198
204
  });
199
-
200
- return stylesheetResult.contents;
201
205
  }
202
206
 
203
- async compileAsync(modifiedFileSet?: Set<TNormPath>): Promise<ISdTsCompilerResult> {
204
- let perf = new SdCliPerformanceTimer("esbuild compile");
207
+ async compileAsync(modifiedFileSet: Set<TNormPath>): Promise<ISdTsCompilerResult> {
208
+ this.#perf = new SdCliPerformanceTimer("esbuild compile");
205
209
 
206
- this.#modifiedFileSet = modifiedFileSet ?? new Set<TNormPath>();
210
+ this.#modifiedFileSet = new Set(modifiedFileSet);
207
211
  this.#affectedFileSet = new Set<TNormPath>();
208
212
 
209
- this.#debug(`get affected (old deps & old res deps)...`);
213
+ const prepareResult = await this.#prepareAsync();
210
214
 
211
- perf.run("get affected", () => {
212
- for (const modifiedFile of this.#modifiedFileSet) {
213
- this.#affectedFileSet.add(modifiedFile);
214
- this.#affectedFileSet.adds(...(this.#revDependencyCacheMap.get(modifiedFile) ?? []));
215
- this.#affectedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
215
+ const [buildResult, lintResults] = await Promise.all([this.#buildAsync(), this.#lintAsync()]);
216
216
 
217
- this.#emittedFilesCacheMap.delete(modifiedFile);
218
- }
219
- });
217
+ this.#debug(`build completed`, this.#perf.toString());
220
218
 
221
- this.#debug(`invalidate & clear cache...`);
219
+ return {
220
+ messages: [
221
+ ...prepareResult.messages,
222
+ ...SdCliConvertMessageUtil.convertToBuildMessagesFromTsDiag(buildResult.diagnostics),
223
+ ...SdCliConvertMessageUtil.convertToBuildMessagesFromEslint(lintResults),
224
+ ],
225
+ watchFileSet: this.#watchFileSet,
226
+ affectedFileSet: this.#affectedFileSet,
227
+ stylesheetBundlingResultMap: this.#stylesheetBundlingResultMap,
228
+ emittedFilesCacheMap: this.#emittedFilesCacheMap,
229
+ emitFileSet: buildResult.emitFileSet,
230
+ };
231
+ }
222
232
 
223
- perf.run("invalidate & clear cache", () => {
224
- this.#stylesheetBundler?.invalidate(this.#modifiedFileSet);
233
+ async #prepareAsync() {
234
+ if (this.#modifiedFileSet.size !== 0) {
235
+ this.#debug(`get affected (old deps & old res deps)...`);
225
236
 
226
- for (const affectedFile of this.#affectedFileSet) {
227
- this.#sourceFileCacheMap.delete(affectedFile);
228
- this.#stylesheetBundlingResultMap.delete(affectedFile);
229
- this.#watchFileSet.delete(affectedFile);
230
- }
237
+ this.#perf.run("get affected", () => {
238
+ for (const modifiedFile of this.#modifiedFileSet) {
239
+ this.#affectedFileSet.add(modifiedFile);
240
+ this.#affectedFileSet.adds(...(this.#revDependencyCacheMap.get(modifiedFile) ?? []));
241
+ this.#affectedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
231
242
 
232
- this.#revDependencyCacheMap.clear();
233
- this.#resourceDependencyCacheMap.clear();
234
- });
243
+ this.#emittedFilesCacheMap.delete(modifiedFile);
244
+ }
245
+ });
246
+
247
+ this.#debug(`invalidate & clear cache...`);
248
+
249
+ this.#perf.run("invalidate & clear cache", () => {
250
+ this.#stylesheetBundler?.invalidate(this.#modifiedFileSet);
251
+
252
+ for (const affectedFile of this.#affectedFileSet) {
253
+ this.#sourceFileCacheMap.delete(affectedFile);
254
+ this.#stylesheetBundlingResultMap.delete(affectedFile);
255
+ this.#watchFileSet.delete(affectedFile);
256
+ }
257
+
258
+ this.#revDependencyCacheMap.clear();
259
+ this.#resourceDependencyCacheMap.clear();
260
+ });
261
+ }
235
262
 
236
263
  this.#debug(`create program...`);
237
264
 
238
- perf.run("create program", () => {
265
+ this.#perf.run("create program", () => {
239
266
  if (this.#isForAngular) {
240
267
  this.#ngProgram = new NgtscProgram(
241
268
  this.#parsedTsconfig.fileNames,
@@ -255,7 +282,7 @@ export class SdTsCompiler {
255
282
  });
256
283
 
257
284
  if (this.#ngProgram) {
258
- await perf.run("ng analyze", async () => {
285
+ await this.#perf.run("ng analyze", async () => {
259
286
  await this.#ngProgram!.compiler.analyzeAsync();
260
287
  });
261
288
  }
@@ -269,17 +296,17 @@ export class SdTsCompiler {
269
296
  return sf;
270
297
  };
271
298
 
272
- this.#debug(`get affected (new deps)...`);
299
+ const sourceFileSet = new Set(
300
+ this.#program!.getSourceFiles()
301
+ .map((sf) => getOrgSourceFile(sf))
302
+ .filterExists(),
303
+ );
273
304
 
274
- const messages: ISdBuildMessage[] = [];
305
+ this.#debug(`get new deps...`);
275
306
 
276
- perf.run("get affected (deps)", () => {
277
- const sourceFileSet = new Set(
278
- this.#program!.getSourceFiles()
279
- .map((sf) => getOrgSourceFile(sf))
280
- .filterExists(),
281
- );
307
+ const messages: ISdBuildMessage[] = [];
282
308
 
309
+ this.#perf.run("get new deps", () => {
283
310
  const depMap = new Map<
284
311
  TNormPath,
285
312
  {
@@ -346,14 +373,6 @@ export class SdTsCompiler {
346
373
  for (const dep of getAllDeps(PathUtil.norm(sf.fileName))) {
347
374
  const depCache = this.#revDependencyCacheMap.getOrCreate(dep, new Set<TNormPath>());
348
375
  depCache.add(PathUtil.norm(sf.fileName));
349
- if (this.#modifiedFileSet.has(dep)) {
350
- this.#affectedFileSet.add(PathUtil.norm(sf.fileName));
351
- }
352
- // dep이 emit된적이 없으면 affected에 추가해야함.
353
- // dep파일이 추가된후 기존 파일에서 import하면 dep파일이 affected에 포함이 안되는 현상 때문
354
- if (!this.#emittedFilesCacheMap.has(dep)) {
355
- this.#affectedFileSet.add(dep);
356
- }
357
376
  }
358
377
 
359
378
  if (this.#ngProgram) {
@@ -364,14 +383,6 @@ export class SdTsCompiler {
364
383
  for (const dep of this.#ngProgram.compiler.getResourceDependencies(sf)) {
365
384
  const ref = this.#resourceDependencyCacheMap.getOrCreate(PathUtil.norm(dep), new Set<TNormPath>());
366
385
  ref.add(PathUtil.norm(sf.fileName));
367
- if (this.#modifiedFileSet.has(PathUtil.norm(dep))) {
368
- this.#affectedFileSet.add(PathUtil.norm(sf.fileName));
369
- }
370
- // dep이 emit된적이 없으면 affected에 추가해야함.
371
- // dep파일이 추가된후 기존 파일에서 import하면 dep파일이 affected에 포함이 안되는 현상 때문
372
- if (!this.#emittedFilesCacheMap.has(PathUtil.norm(dep))) {
373
- this.#affectedFileSet.add(PathUtil.norm(dep));
374
- }
375
386
  }
376
387
  }
377
388
  }
@@ -380,239 +391,249 @@ export class SdTsCompiler {
380
391
  if (this.#modifiedFileSet.size === 0) {
381
392
  this.#debug(`get affected (init)...`);
382
393
 
383
- perf.run("get affected (init)", () => {
384
- for (const sf of this.#program!.getSourceFiles()) {
394
+ this.#perf.run("get affected (init)", () => {
395
+ for (const sf of sourceFileSet) {
385
396
  if (!this.#watchScopePaths.some((scopePath) => PathUtil.isChildPath(sf.fileName, scopePath))) {
386
397
  continue;
387
398
  }
388
399
 
389
- const orgSf = getOrgSourceFile(sf);
390
- if (!orgSf) continue;
391
-
392
- this.#affectedFileSet.add(PathUtil.norm(orgSf.fileName));
400
+ this.#affectedFileSet.add(PathUtil.norm(sf.fileName));
393
401
  }
394
402
  });
395
403
  }
396
404
 
397
- const emitFileSet = new Set<TNormPath>();
405
+ for (const dep of this.#revDependencyCacheMap.keys()) {
406
+ if (this.#modifiedFileSet.has(dep)) {
407
+ this.#affectedFileSet.adds(
408
+ ...Array.from(this.#revDependencyCacheMap.get(dep)!).mapMany((item) =>
409
+ [
410
+ item,
411
+ // .d.ts면 .js파일도 affected에 추가
412
+ item.endsWith(".d.ts") ? PathUtil.norm(item.replace(/\.d\.ts$/, ".js")) : undefined,
413
+ ].filterExists(),
414
+ ),
415
+ );
416
+ }
398
417
 
399
- const [lintResults] = await Promise.all([
400
- this.#lintWorker.run("lint", [
401
- {
402
- cwd: this.#pkgPath,
403
- fileSet: this.#affectedFileSet,
404
- },
405
- ]),
406
- (async () => {
407
- this.#debug(`get diagnostics...`);
418
+ // dep이 emit된적이 없으면 affected에 추가해야함.
419
+ // dep파일이 추가된후 기존 파일에서 import하면 dep파일이 affected에 포함이 안되는 현상 때문
420
+ if (!this.#emittedFilesCacheMap.has(dep)) {
421
+ this.#affectedFileSet.add(dep);
422
+ }
423
+ }
408
424
 
409
- const diagnostics: ts.Diagnostic[] = [];
425
+ if (this.#ngProgram) {
426
+ for (const dep of this.#resourceDependencyCacheMap.keys()) {
427
+ if (this.#modifiedFileSet.has(dep)) {
428
+ this.#affectedFileSet.adds(...this.#resourceDependencyCacheMap.get(dep)!);
429
+ }
410
430
 
411
- perf.run("get program diagnostics", () => {
412
- diagnostics.push(
413
- ...this.#program!.getConfigFileParsingDiagnostics(),
414
- ...this.#program!.getOptionsDiagnostics(),
415
- ...this.#program!.getGlobalDiagnostics(),
416
- );
431
+ // dep이 emit된적이 없으면 affected에 추가해야함.
432
+ // dep파일이 추가된후 기존 파일에서 import하면 dep파일이 affected에 포함이 안되는 현상 때문
433
+ if (!this.#emittedFilesCacheMap.has(dep)) {
434
+ this.#affectedFileSet.add(dep);
435
+ }
436
+ }
437
+ }
417
438
 
418
- if (this.#ngProgram) {
419
- diagnostics.push(...this.#ngProgram.compiler.getOptionDiagnostics());
420
- }
421
- });
439
+ return {
440
+ messages,
441
+ };
442
+ }
422
443
 
423
- this.#debug(`get diagnostics of files...`);
444
+ async #lintAsync() {
445
+ return await this.#lintWorker.run("lint", [
446
+ {
447
+ cwd: this.#pkgPath,
448
+ fileSet: this.#affectedFileSet,
449
+ },
450
+ ]);
451
+ }
424
452
 
425
- for (const affectedFile of this.#affectedFileSet) {
426
- if (!PathUtil.isChildPath(affectedFile, this.#pkgPath)) {
427
- continue;
428
- }
453
+ async #buildAsync() {
454
+ const emitFileSet = new Set<TNormPath>();
455
+ const diagnostics: ts.Diagnostic[] = [];
429
456
 
430
- const affectedSourceFile = this.#program!.getSourceFile(affectedFile);
457
+ this.#debug(`get diagnostics...`);
431
458
 
432
- if (
433
- !affectedSourceFile ||
434
- (this.#ngProgram && this.#ngProgram.compiler.ignoreForDiagnostics.has(affectedSourceFile))
435
- ) {
436
- continue;
437
- }
459
+ this.#perf.run("get program diagnostics", () => {
460
+ diagnostics.push(
461
+ ...this.#program!.getConfigFileParsingDiagnostics(),
462
+ ...this.#program!.getOptionsDiagnostics(),
463
+ ...this.#program!.getGlobalDiagnostics(),
464
+ );
438
465
 
439
- // this.#debug(`get diagnostics of file ${affectedFile}...`);
466
+ if (this.#ngProgram) {
467
+ diagnostics.push(...this.#ngProgram.compiler.getOptionDiagnostics());
468
+ }
469
+ });
440
470
 
441
- perf.run("get file diagnostics", () => {
442
- diagnostics.push(
443
- ...this.#program!.getSyntacticDiagnostics(affectedSourceFile),
444
- ...this.#program!.getSemanticDiagnostics(affectedSourceFile),
445
- );
446
- });
471
+ this.#debug(`get diagnostics of files...`);
447
472
 
448
- if (this.#ngProgram) {
449
- perf.run("get file diagnostics: ng", () => {
450
- if (affectedSourceFile.isDeclarationFile) {
451
- return;
452
- }
473
+ for (const affectedFile of this.#affectedFileSet) {
474
+ if (!PathUtil.isChildPath(affectedFile, this.#pkgPath)) {
475
+ continue;
476
+ }
453
477
 
454
- diagnostics.push(
455
- ...this.#ngProgram!.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram),
456
- );
457
- });
458
- }
459
- }
478
+ const affectedSourceFile = this.#program!.getSourceFile(affectedFile);
460
479
 
461
- perf.run("emit", () => {
462
- this.#debug(`prepare emit...`);
480
+ if (
481
+ !affectedSourceFile ||
482
+ (this.#ngProgram && this.#ngProgram.compiler.ignoreForDiagnostics.has(affectedSourceFile))
483
+ ) {
484
+ continue;
485
+ }
486
+
487
+ // this.#debug(`get diagnostics of file ${affectedFile}...`);
463
488
 
464
- let transformers: ts.CustomTransformers = {};
489
+ this.#perf.run("get file diagnostics", () => {
490
+ diagnostics.push(
491
+ ...this.#program!.getSyntacticDiagnostics(affectedSourceFile),
492
+ ...this.#program!.getSemanticDiagnostics(affectedSourceFile),
493
+ );
494
+ });
465
495
 
466
- if (this.#ngProgram) {
467
- transformers = {
468
- ...transformers,
469
- ...this.#ngProgram.compiler.prepareEmit().transformers,
470
- };
471
- (transformers.before ??= []).push(replaceBootstrap(() => this.#program!.getTypeChecker()));
496
+ if (this.#ngProgram) {
497
+ this.#perf.run("get file diagnostics: ng", () => {
498
+ if (affectedSourceFile.isDeclarationFile) {
499
+ return;
472
500
  }
473
- // (transformers.before ??= []).push(transformKeys(this.#program));
474
501
 
475
- this.#debug(`emit for files...`);
502
+ diagnostics.push(
503
+ ...this.#ngProgram!.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram),
504
+ );
505
+ });
506
+ }
507
+ }
476
508
 
477
- // affected에 새로 추가된 파일은 포함되지 않는 현상이 있어 sourceFileSet으로 바꿈
478
- // 비교해보니, 딱히 getSourceFiles라서 더 느려지는것 같지는 않음
479
- // 그래도 affected로 다시 테스트
480
- for (const affectedFile of this.#affectedFileSet) {
481
- if (this.#emittedFilesCacheMap.has(affectedFile)) {
482
- continue;
483
- }
509
+ this.#perf.run("emit", () => {
510
+ this.#debug(`prepare emit...`);
484
511
 
485
- const sf = this.#program!.getSourceFile(affectedFile);
486
- if (!sf) {
487
- continue;
488
- }
512
+ let transformers: ts.CustomTransformers = {};
489
513
 
490
- if (sf.isDeclarationFile) {
491
- continue;
492
- }
514
+ if (this.#ngProgram) {
515
+ transformers = {
516
+ ...transformers,
517
+ ...this.#ngProgram.compiler.prepareEmit().transformers,
518
+ };
519
+ (transformers.before ??= []).push(replaceBootstrap(() => this.#program!.getTypeChecker()));
520
+ }
521
+ // (transformers.before ??= []).push(transformKeys(this.#program));
493
522
 
494
- if (this.#ngProgram?.compiler.ignoreForEmit.has(sf)) {
495
- continue;
496
- }
523
+ this.#debug(`emit for files...`);
497
524
 
498
- if (this.#ngProgram?.compiler.incrementalCompilation.safeToSkipEmit(sf)) {
499
- continue;
500
- }
501
-
502
- // esbuild를 통해 bundle로 묶어야 하는놈들은 모든 output이 있어야 함.
503
- if (!this.#isForBundle) {
504
- if (!PathUtil.isChildPath(sf.fileName, this.#pkgPath)) {
505
- continue;
506
- }
507
- }
525
+ // affected에 새로 추가된 파일은 포함되지 않는 현상이 있어 sourceFileSet으로 바꿈
526
+ // 비교해보니, 딱히 getSourceFiles라서 더 느려지는것 같지는 않음
527
+ // 그래도 affected로 다시 테스트
528
+ for (const affectedFile of this.#affectedFileSet) {
529
+ if (this.#emittedFilesCacheMap.has(affectedFile)) {
530
+ continue;
531
+ }
508
532
 
509
- // this.#debug(`emit for`, sf.fileName);
510
- this.#program!.emit(
511
- sf,
512
- (fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
513
- if (!sourceFiles || sourceFiles.length === 0) {
514
- this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
515
- return;
516
- }
533
+ const sf = this.#program!.getSourceFile(affectedFile);
534
+ if (!sf) {
535
+ continue;
536
+ }
517
537
 
518
- const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
519
- if (this.#ngProgram) {
520
- if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
521
- return;
522
- }
523
- this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
524
- }
538
+ if (sf.isDeclarationFile) {
539
+ continue;
540
+ }
525
541
 
526
- const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(
527
- PathUtil.norm(sourceFile.fileName),
528
- [],
529
- );
542
+ if (this.#ngProgram?.compiler.ignoreForEmit.has(sf)) {
543
+ continue;
544
+ }
530
545
 
531
- if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
532
- let realFilePath = PathUtil.norm(fileName);
533
- let realText = text;
534
- if (
535
- PathUtil.isChildPath(
536
- realFilePath,
537
- path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"),
538
- )
539
- ) {
540
- realFilePath = PathUtil.norm(
541
- this.#distPath,
542
- path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath),
543
- );
544
-
545
- if (fileName.endsWith(".js.map")) {
546
- const sourceMapContents = JSON.parse(realText);
547
- // remove "../../"
548
- sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
549
- realText = JSON.stringify(sourceMapContents);
550
- }
551
- }
552
-
553
- emitFileInfoCaches.push({
554
- outAbsPath: realFilePath,
555
- text: realText,
556
- });
557
- } else {
558
- emitFileInfoCaches.push({ text });
559
- }
546
+ if (this.#ngProgram?.compiler.incrementalCompilation.safeToSkipEmit(sf)) {
547
+ continue;
548
+ }
560
549
 
561
- emitFileSet.add(PathUtil.norm(sourceFile.fileName));
562
- },
563
- undefined,
564
- undefined,
565
- transformers,
566
- );
550
+ // esbuild를 통해 bundle로 묶어야 하는놈들은 모든 output이 있어야 함.
551
+ if (!this.#isForBundle) {
552
+ if (!PathUtil.isChildPath(sf.fileName, this.#pkgPath)) {
553
+ continue;
567
554
  }
568
- });
569
-
570
- //-- global style
571
- if (
572
- this.#globalStyleFilePath != null &&
573
- FsUtil.exists(this.#globalStyleFilePath) &&
574
- !this.#emittedFilesCacheMap.has(this.#globalStyleFilePath)
575
- ) {
576
- this.#debug(`bundle global style...`);
577
-
578
- await perf.run("bundle global style", async () => {
579
- const data = FsUtil.readFile(this.#globalStyleFilePath!);
580
- const contents = await this.#bundleStylesheetAsync(
581
- data,
582
- this.#globalStyleFilePath!,
583
- this.#globalStyleFilePath,
584
- );
585
- const emitFileInfos = this.#emittedFilesCacheMap.getOrCreate(this.#globalStyleFilePath!, []);
586
- emitFileInfos.push({
587
- outAbsPath: PathUtil.norm(
588
- this.#pkgPath,
589
- path
590
- .relative(path.resolve(this.#pkgPath, "src"), this.#globalStyleFilePath!)
591
- .replace(/\.scss$/, ".css"),
592
- ),
593
- text: contents,
594
- });
595
- emitFileSet.add(this.#globalStyleFilePath!);
596
- });
597
555
  }
598
556
 
599
- this.#debug(`build completed`, perf.toString());
557
+ this.#program!.emit(
558
+ sf,
559
+ (fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
560
+ if (!sourceFiles || sourceFiles.length === 0) {
561
+ this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
562
+ return;
563
+ }
564
+
565
+ const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
566
+ if (this.#ngProgram) {
567
+ if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
568
+ return;
569
+ }
570
+ this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
571
+ }
600
572
 
601
- //-- result
573
+ const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(PathUtil.norm(sourceFile.fileName), []);
574
+
575
+ if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
576
+ let realFilePath = PathUtil.norm(fileName);
577
+ let realText = text;
578
+ if (
579
+ PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))
580
+ ) {
581
+ realFilePath = PathUtil.norm(
582
+ this.#distPath,
583
+ path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath),
584
+ );
602
585
 
603
- messages.push(...SdCliConvertMessageUtil.convertToBuildMessagesFromTsDiag(diagnostics));
604
- })(),
605
- ]);
586
+ if (fileName.endsWith(".js.map")) {
587
+ const sourceMapContents = JSON.parse(realText);
588
+ // remove "../../"
589
+ sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
590
+ realText = JSON.stringify(sourceMapContents);
591
+ }
592
+ }
606
593
 
607
- messages.push(...SdCliConvertMessageUtil.convertToBuildMessagesFromEslint(lintResults));
594
+ emitFileInfoCaches.push({
595
+ outAbsPath: realFilePath,
596
+ text: realText,
597
+ });
598
+ } else {
599
+ emitFileInfoCaches.push({ text });
600
+ }
601
+
602
+ emitFileSet.add(PathUtil.norm(sourceFile.fileName));
603
+ },
604
+ undefined,
605
+ undefined,
606
+ transformers,
607
+ );
608
+ }
609
+ });
610
+
611
+ //-- global style
612
+ if (
613
+ this.#globalStyleFilePath != null &&
614
+ FsUtil.exists(this.#globalStyleFilePath) &&
615
+ !this.#emittedFilesCacheMap.has(this.#globalStyleFilePath)
616
+ ) {
617
+ this.#debug(`bundle global style...`);
618
+
619
+ await this.#perf.run("bundle global style", async () => {
620
+ const data = FsUtil.readFile(this.#globalStyleFilePath!);
621
+ const contents = await this.#bundleStylesheetAsync(data, this.#globalStyleFilePath!, this.#globalStyleFilePath);
622
+ const emitFileInfos = this.#emittedFilesCacheMap.getOrCreate(this.#globalStyleFilePath!, []);
623
+ emitFileInfos.push({
624
+ outAbsPath: PathUtil.norm(
625
+ this.#pkgPath,
626
+ path.relative(path.resolve(this.#pkgPath, "src"), this.#globalStyleFilePath!).replace(/\.scss$/, ".css"),
627
+ ),
628
+ text: contents,
629
+ });
630
+ emitFileSet.add(this.#globalStyleFilePath!);
631
+ });
632
+ }
608
633
 
609
634
  return {
610
- messages,
611
- watchFileSet: this.#watchFileSet,
612
- affectedFileSet: this.#affectedFileSet,
613
- stylesheetBundlingResultMap: this.#stylesheetBundlingResultMap,
614
- emittedFilesCacheMap: this.#emittedFilesCacheMap,
615
635
  emitFileSet,
636
+ diagnostics,
616
637
  };
617
638
  }
618
639
 
@@ -0,0 +1,8 @@
1
+ import { TNormPath } from "@simplysm/sd-core-node";
2
+ import { ISdProjectConfig } from "./sd-configs.type";
3
+
4
+ export interface ISdBuildRunnerWorkerRequest {
5
+ cmd: "watch" | "build";
6
+ pkgPath: TNormPath;
7
+ projConf: ISdProjectConfig;
8
+ }