@simplysm/sd-cli 12.12.7 → 12.12.8

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 (26) hide show
  1. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.d.ts +5 -2
  2. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.js +15 -11
  3. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.js.map +1 -1
  4. package/dist/pkg-builders/client/sd-client.build-runner.js +26 -31
  5. package/dist/pkg-builders/client/sd-client.build-runner.js.map +1 -1
  6. package/dist/pkg-builders/lib/sd-cli-db-context.file-generator.d.ts +5 -2
  7. package/dist/pkg-builders/lib/sd-cli-db-context.file-generator.js +15 -16
  8. package/dist/pkg-builders/lib/sd-cli-db-context.file-generator.js.map +1 -1
  9. package/dist/pkg-builders/lib/sd-cli-index.file-generator.d.ts +5 -2
  10. package/dist/pkg-builders/lib/sd-cli-index.file-generator.js +14 -9
  11. package/dist/pkg-builders/lib/sd-cli-index.file-generator.js.map +1 -1
  12. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js +34 -19
  13. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js.map +1 -1
  14. package/dist/ts-compiler/sd-dependency-cache.d.ts +1 -0
  15. package/dist/ts-compiler/sd-dependency-cache.js +7 -1
  16. package/dist/ts-compiler/sd-dependency-cache.js.map +1 -1
  17. package/dist/ts-compiler/sd-ts-compiler.js +23 -18
  18. package/dist/ts-compiler/sd-ts-compiler.js.map +1 -1
  19. package/package.json +9 -9
  20. package/src/pkg-builders/client/sd-cli-ng-routes.file-generator.ts +8 -7
  21. package/src/pkg-builders/client/sd-client.build-runner.ts +38 -48
  22. package/src/pkg-builders/lib/sd-cli-db-context.file-generator.ts +8 -12
  23. package/src/pkg-builders/lib/sd-cli-index.file-generator.ts +9 -10
  24. package/src/pkg-builders/lib/sd-ts-lib.build-runner.ts +19 -10
  25. package/src/ts-compiler/sd-dependency-cache.ts +12 -12
  26. package/src/ts-compiler/sd-ts-compiler.ts +53 -106
@@ -4,25 +4,15 @@ import { FsUtils, PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node"
4
4
  import { StringUtils, Wait } from "@simplysm/sd-core-common";
5
5
  import { NgtscProgram, OptimizeFor } from "@angular/compiler-cli";
6
6
  import { AngularCompilerHost } from "@angular/build/src/tools/angular/angular-host";
7
- import {
8
- replaceBootstrap,
9
- } from "@angular/build/src/tools/angular/transformers/jit-bootstrap-transformer";
7
+ import { replaceBootstrap } from "@angular/build/src/tools/angular/transformers/jit-bootstrap-transformer";
10
8
  import { SdCliPerformanceTimer } from "../utils/sd-cli-performance-time";
11
9
  import { SdCliConvertMessageUtils } from "../utils/sd-cli-convert-message.utils";
12
- import {
13
- ISdTsCompilerResult,
14
- SdTsCompilerOptions,
15
- TStylesheetBundlingResult,
16
- } from "../types/ts-compiler.types";
17
- import {
18
- createWorkerTransformer,
19
- } from "@angular/build/src/tools/angular/transformers/web-worker-transformer";
10
+ import { ISdTsCompilerResult, SdTsCompilerOptions, TStylesheetBundlingResult } from "../types/ts-compiler.types";
11
+ import { createWorkerTransformer } from "@angular/build/src/tools/angular/transformers/web-worker-transformer";
20
12
  import { ISdAffectedFileTreeNode, SdDependencyCache } from "./sd-dependency-cache";
21
13
  import { SdDependencyAnalyzer } from "./sd-dependency-analyzer";
22
14
  import { FlatESLint } from "eslint/use-at-your-own-risk";
23
- import {
24
- ComponentStylesheetBundler,
25
- } from "@angular/build/src/tools/esbuild/angular/component-stylesheets";
15
+ import { ComponentStylesheetBundler } from "@angular/build/src/tools/esbuild/angular/component-stylesheets";
26
16
  import { transformSupportedBrowsersToTargets } from "@angular/build/src/tools/esbuild/utils";
27
17
  import browserslist from "browserslist";
28
18
 
@@ -95,10 +85,7 @@ export class SdTsCompiler {
95
85
  ...this._opt.additionalOptions,
96
86
  });
97
87
 
98
- const distPath = PathUtils.norm(parsedTsconfig.options.outDir ?? path.resolve(
99
- this._opt.pkgPath,
100
- "dist",
101
- ));
88
+ const distPath = PathUtils.norm(parsedTsconfig.options.outDir ?? path.resolve(this._opt.pkgPath, "dist"));
102
89
 
103
90
  return {
104
91
  fileNames: parsedTsconfig.fileNames,
@@ -107,10 +94,9 @@ export class SdTsCompiler {
107
94
  };
108
95
  }
109
96
 
110
- #createCompilerHost(
111
- compilerOptions: ts.CompilerOptions,
112
- modifiedFileSet: Set<TNormPath>,
113
- ) {
97
+ #createCompilerHost(compilerOptions: ts.CompilerOptions, modifiedFileSet: Set<TNormPath>) {
98
+ // 지식: SourceFile은 하나의 파일에만 국한된 정적 정보객체임, 변경된 파일의 SourceFile만 다시 생성하면됨
99
+
114
100
  const compilerHost = ts.createCompilerHost(compilerOptions);
115
101
 
116
102
  const baseGetSourceFile = compilerHost.getSourceFile;
@@ -123,7 +109,11 @@ export class SdTsCompiler {
123
109
  ): ts.SourceFile | undefined => {
124
110
  const fileNPath = PathUtils.norm(fileName);
125
111
 
126
- if (!shouldCreateNewSourceFile && this.#sourceFileCacheMap.has(fileNPath)) {
112
+ /*if (!shouldCreateNewSourceFile && this.#sourceFileCacheMap.has(fileNPath)) {
113
+ return this.#sourceFileCacheMap.get(fileNPath);
114
+ }*/
115
+
116
+ if (this.#sourceFileCacheMap.has(fileNPath)) {
127
117
  return this.#sourceFileCacheMap.get(fileNPath);
128
118
  }
129
119
 
@@ -132,7 +122,7 @@ export class SdTsCompiler {
132
122
  fileName,
133
123
  languageVersionOrOptions,
134
124
  onError,
135
- true,
125
+ false,
136
126
  ...args,
137
127
  );
138
128
 
@@ -141,6 +131,8 @@ export class SdTsCompiler {
141
131
  return undefined;
142
132
  }
143
133
 
134
+ this.#sourceFileCacheMap.set(fileNPath, sf);
135
+
144
136
  return sf;
145
137
  };
146
138
 
@@ -220,9 +212,10 @@ export class SdTsCompiler {
220
212
  // const worker = this._stylesheetBundlingWorker!;
221
213
  // const result = await worker.run("bundle", [data, containingFile, resourceFile]);
222
214
 
223
- const result = resourceFile != null
224
- ? await this.#stylesheetBundler.bundleFile(resourceFile)
225
- : await this.#stylesheetBundler.bundleInline(data, containingFile, "scss");
215
+ const result =
216
+ resourceFile != null
217
+ ? await this.#stylesheetBundler.bundleFile(resourceFile)
218
+ : await this.#stylesheetBundler.bundleInline(data, containingFile, "scss");
226
219
 
227
220
  for (const referencedFile of result.referencedFiles ?? []) {
228
221
  // for (const referencedFile of result.referencedFiles) {
@@ -230,6 +223,8 @@ export class SdTsCompiler {
230
223
  this.#depCache.addImport(fileNPath, PathUtils.norm(referencedFile), 0);
231
224
  }
232
225
 
226
+ this.#stylesheetBundlingResultMap.set(fileNPath, result);
227
+
233
228
  // this._stylesheetBundlingResultMap.set(fileNPath, {
234
229
  // errors: undefined,
235
230
  // warnings: [],
@@ -242,8 +237,7 @@ export class SdTsCompiler {
242
237
  // ...result,
243
238
  // };
244
239
  return result;
245
- }
246
- catch (err) {
240
+ } catch (err) {
247
241
  const result = {
248
242
  errors: [
249
243
  {
@@ -311,21 +305,25 @@ export class SdTsCompiler {
311
305
  };
312
306
 
313
307
  const affectedFileTree = this.#depCache.getAffectedFileTree(modifiedFileSet);
314
- this.#debug(`
315
- 영향받은 기존파일:
316
- ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
308
+ this.#debug(`영향받은 기존파일: ${affectedFileTree.map((item) => getTreeText(item)).join("\n")}`.trim());
317
309
 
318
310
  // 스타일 번들러에서 영향받은 파일 관련 항목 무효화
319
- this.#stylesheetBundler.invalidate(affectedFileSet);
311
+ this.#stylesheetBundler.invalidate(
312
+ new Set([...modifiedFileSet, ...Array.from(affectedFileSet).filter((item) => item.endsWith(".scss"))]),
313
+ );
320
314
  // await worker.run("invalidate", [affectedFileSet]);
321
315
 
322
- // 의존성 캐시에서 영향받은 파일 관련 항목 무효화
323
- this.#depCache.invalidates(affectedFileSet);
316
+ // 소스파일은 변경된 파일들로 무효화
317
+ for (const modifiedFile of modifiedFileSet) {
318
+ this.#sourceFileCacheMap.delete(modifiedFile);
319
+ }
320
+
321
+ // 의존성 캐시에서 영향받은 파일 관련 항목 무효화 (Affected더라도 SF는 동일하므로, modifiedFileSet만 넣어도될듯?)
322
+ this.#depCache.invalidates(modifiedFileSet);
324
323
 
325
324
  // 내부 캐시에서 영향받은 파일 관련 항목 무효화
326
325
  for (const affectedFile of affectedFileSet) {
327
326
  this.#emittedFilesCacheMap.delete(affectedFile);
328
- this.#sourceFileCacheMap.delete(affectedFile);
329
327
  this.#stylesheetBundlingResultMap.delete(affectedFile);
330
328
  }
331
329
  });
@@ -340,21 +338,10 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
340
338
 
341
339
  this.#perf.run("ts.Program 생성", () => {
342
340
  if (this.#isForAngular) {
343
- this.#ngProgram = new NgtscProgram(
344
- tsconfig.fileNames,
345
- tsconfig.options,
346
- compilerHost,
347
- this.#ngProgram,
348
- );
341
+ this.#ngProgram = new NgtscProgram(tsconfig.fileNames, tsconfig.options, compilerHost, this.#ngProgram);
349
342
  this.#program = this.#ngProgram.getTsProgram();
350
- }
351
- else {
352
- this.#program = ts.createProgram(
353
- tsconfig.fileNames,
354
- tsconfig.options,
355
- compilerHost,
356
- this.#program,
357
- );
343
+ } else {
344
+ this.#program = ts.createProgram(tsconfig.fileNames, tsconfig.options, compilerHost, this.#program);
358
345
  }
359
346
  });
360
347
  this.#debug(`ts.Program 생성`);
@@ -370,26 +357,16 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
370
357
 
371
358
  this.#perf.run("새 의존성 분석", () => {
372
359
  // SdTsDependencyAnalyzer를 통해 의존성 분석 및 SdDepCache 업데이트
373
- SdDependencyAnalyzer.analyze(
374
- this.#program!,
375
- compilerHost,
376
- this._opt.watchScopePathSet,
377
- this.#depCache,
378
- );
360
+ SdDependencyAnalyzer.analyze(this.#program!, compilerHost, this._opt.watchScopePathSet, this.#depCache);
379
361
 
380
362
  // Angular 리소스 의존성 추가
381
363
  if (this.#ngProgram) {
382
- SdDependencyAnalyzer.analyzeAngularResources(
383
- this.#ngProgram,
384
- this._opt.watchScopePathSet,
385
- this.#depCache,
386
- );
364
+ SdDependencyAnalyzer.analyzeAngularResources(this.#ngProgram, this._opt.watchScopePathSet, this.#depCache);
387
365
  }
388
366
  });
389
367
 
390
- const affectedFileSet = modifiedFileSet.size === 0
391
- ? this.#depCache.getFiles()
392
- : this.#depCache.getAffectedFileSet(modifiedFileSet);
368
+ const affectedFileSet =
369
+ modifiedFileSet.size === 0 ? this.#depCache.getFiles() : this.#depCache.getAffectedFileSet(modifiedFileSet);
393
370
  const watchFileSet = this.#depCache.getFiles();
394
371
 
395
372
  return {
@@ -403,10 +380,7 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
403
380
  async #lintAsync(prepareResult: IPrepareResult) {
404
381
  const lintFilePaths = Array.from(prepareResult.affectedFileSet)
405
382
  .filter((item) => PathUtils.isChildPath(item, this._opt.pkgPath))
406
- .filter((item) => (
407
- (!item.endsWith(".d.ts") && item.endsWith(".ts")) ||
408
- item.endsWith(".js")
409
- ))
383
+ .filter((item) => (!item.endsWith(".d.ts") && item.endsWith(".ts")) || item.endsWith(".js"))
410
384
  .filter((item) => FsUtils.exists(item));
411
385
 
412
386
  if (lintFilePaths.length === 0) {
@@ -444,14 +418,12 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
444
418
  this._opt.globalStyleFilePath!,
445
419
  this._opt.globalStyleFilePath,
446
420
  );
447
- const emitFileInfos = this.#emittedFilesCacheMap.getOrCreate(
448
- this._opt.globalStyleFilePath!,
449
- [],
450
- );
421
+ const emitFileInfos = this.#emittedFilesCacheMap.getOrCreate(this._opt.globalStyleFilePath!, []);
451
422
  emitFileInfos.push({
452
423
  outAbsPath: PathUtils.norm(
453
424
  this._opt.pkgPath,
454
- path.relative(path.resolve(this._opt.pkgPath, "src"), this._opt.globalStyleFilePath!)
425
+ path
426
+ .relative(path.resolve(this._opt.pkgPath, "src"), this._opt.globalStyleFilePath!)
455
427
  .replace(/\.scss$/, ".css"),
456
428
  ),
457
429
  text: stylesheetBundlingResult.contents ?? "",
@@ -509,10 +481,7 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
509
481
  if (affectedSourceFile.isDeclarationFile) return;
510
482
 
511
483
  diagnostics.push(
512
- ...this.#ngProgram!.compiler.getDiagnosticsForFile(
513
- affectedSourceFile,
514
- OptimizeFor.WholeProgram,
515
- ),
484
+ ...this.#ngProgram!.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram),
516
485
  );
517
486
  });
518
487
  }
@@ -525,15 +494,9 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
525
494
 
526
495
  if (this.#ngProgram) {
527
496
  const angularTransfomers = this.#ngProgram.compiler.prepareEmit().transformers;
528
- (transformers.before ??= []).push(
529
- ...(angularTransfomers.before ?? []),
530
- );
531
- (transformers.after ??= []).push(
532
- ...(angularTransfomers.after ?? []),
533
- );
534
- (transformers.afterDeclarations ??= []).push(
535
- ...(angularTransfomers.afterDeclarations ?? []),
536
- );
497
+ (transformers.before ??= []).push(...(angularTransfomers.before ?? []));
498
+ (transformers.after ??= []).push(...(angularTransfomers.after ?? []));
499
+ (transformers.afterDeclarations ??= []).push(...(angularTransfomers.afterDeclarations ?? []));
537
500
 
538
501
  (transformers.before ??= []).push(replaceBootstrap(() => this.#program!.getTypeChecker()));
539
502
  (transformers.before ??= []).push(
@@ -568,14 +531,7 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
568
531
  sf,
569
532
  (fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
570
533
  if (!sourceFiles || sourceFiles.length === 0) {
571
- prepareResult.compilerHost.writeFile(
572
- fileName,
573
- text,
574
- writeByteOrderMark,
575
- onError,
576
- sourceFiles,
577
- data,
578
- );
534
+ prepareResult.compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
579
535
  return;
580
536
  }
581
537
 
@@ -585,24 +541,16 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
585
541
  this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
586
542
  }
587
543
 
588
- const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(
589
- PathUtils.norm(sourceFile.fileName),
590
- [],
591
- );
544
+ const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(PathUtils.norm(sourceFile.fileName), []);
592
545
 
593
546
  if (PathUtils.isChildPath(sourceFile.fileName, this._opt.pkgPath)) {
594
- const real = this.#convertOutputToReal(
595
- fileName,
596
- prepareResult.tsconfig.distPath,
597
- text,
598
- );
547
+ const real = this.#convertOutputToReal(fileName, prepareResult.tsconfig.distPath, text);
599
548
 
600
549
  emitFileInfoCaches.push({
601
550
  outAbsPath: real.filePath,
602
551
  text: real.text,
603
552
  });
604
- }
605
- else {
553
+ } else {
606
554
  emitFileInfoCaches.push({ text });
607
555
  }
608
556
 
@@ -646,7 +594,6 @@ ${affectedFileTree.map(item => getTreeText(item)).join("\n")}`.trim());
646
594
  }
647
595
  }
648
596
 
649
-
650
597
  interface ITsConfigInfo {
651
598
  fileNames: string[];
652
599
  options: ts.CompilerOptions;