@simplysm/sd-cli 12.8.18 → 12.8.21

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 (37) hide show
  1. package/dist/entry/sd-cli-cordova.d.ts +30 -0
  2. package/dist/entry/sd-cli-cordova.js +309 -249
  3. package/dist/entry/sd-cli-cordova.js.map +1 -1
  4. package/dist/entry/sd-cli-project.d.ts +1 -1
  5. package/dist/entry/sd-cli-project.js +8 -9
  6. package/dist/entry/sd-cli-project.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/pkg-builders/client/sd-ng.bundler.d.ts +15 -1
  11. package/dist/pkg-builders/client/sd-ng.bundler.js +60 -70
  12. package/dist/pkg-builders/client/sd-ng.bundler.js.map +1 -1
  13. package/dist/pkg-builders/client/sd-ng.plugin-creator.js +49 -29
  14. package/dist/pkg-builders/client/sd-ng.plugin-creator.js.map +1 -1
  15. package/dist/pkg-builders/lib/sd-ts-lib.builder.js +7 -4
  16. package/dist/pkg-builders/lib/sd-ts-lib.builder.js.map +1 -1
  17. package/dist/ts-compiler/sd-ts-compiler.d.ts +24 -2
  18. package/dist/ts-compiler/sd-ts-compiler.js +267 -575
  19. package/dist/ts-compiler/sd-ts-compiler.js.map +1 -1
  20. package/dist/ts-compiler/sd-ts-dependency-analyzer.d.ts +10 -0
  21. package/dist/ts-compiler/sd-ts-dependency-analyzer.js +140 -0
  22. package/dist/ts-compiler/sd-ts-dependency-analyzer.js.map +1 -0
  23. package/dist/types/ts-compiler.types.d.ts +12 -7
  24. package/dist/types/worker.types.d.ts +13 -0
  25. package/dist/utils/sd-cli-performance-time.js +1 -1
  26. package/package.json +10 -12
  27. package/src/entry/sd-cli-cordova.ts +394 -281
  28. package/src/entry/sd-cli-project.ts +11 -23
  29. package/src/index.ts +1 -0
  30. package/src/pkg-builders/client/sd-ng.bundler.ts +70 -69
  31. package/src/pkg-builders/client/sd-ng.plugin-creator.ts +47 -27
  32. package/src/pkg-builders/lib/sd-ts-lib.builder.ts +14 -7
  33. package/src/ts-compiler/sd-ts-compiler.ts +334 -705
  34. package/src/ts-compiler/sd-ts-dependency-analyzer.ts +176 -0
  35. package/src/types/ts-compiler.types.ts +11 -6
  36. package/src/types/worker.types.ts +7 -6
  37. package/src/utils/sd-cli-performance-time.ts +1 -1
@@ -2,10 +2,9 @@ import path from "path";
2
2
  import { FsUtils, PathUtils, SdLogger, SdProcess } from "@simplysm/sd-core-node";
3
3
  import { pathToFileURL } from "url";
4
4
  import semver from "semver";
5
- import { NeverEntryError, StringUtils, Wait } from "@simplysm/sd-core-common";
5
+ import { NeverEntryError, StringUtils, Wait, XmlConvert } from "@simplysm/sd-core-common";
6
6
  import { SdStorage } from "@simplysm/sd-storage";
7
7
  import { SdCliLocalUpdate } from "./sd-cli-local-update";
8
- import xml2js from "xml2js";
9
8
  import { SdMultiBuildRunner } from "../pkg-builders/sd-multi.build-runner";
10
9
  import { SdCliConvertMessageUtils } from "../utils/sd-cli-convert-message.utils";
11
10
  import { ISdProjectConfig, TSdPackageConfig } from "../types/config.types";
@@ -22,13 +21,9 @@ export class SdCliProject {
22
21
  const logger = SdLogger.get(["simplysm", "sd-cli", "SdCliProject", "watchAsync"]);
23
22
 
24
23
  logger.debug("프로젝트 설정 가져오기...");
25
- const projConf = (await import(pathToFileURL(path.resolve(
26
- process.cwd(),
27
- opt.confFileRelPath,
28
- )).href)).default(
29
- true,
30
- opt.optNames,
31
- ) as ISdProjectConfig;
24
+ const projConf = (
25
+ await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)
26
+ ).default(true, opt.optNames) as ISdProjectConfig;
32
27
 
33
28
  if (projConf.localUpdates) {
34
29
  logger.debug("로컬 라이브러리 업데이트 변경감지 시작...");
@@ -111,7 +106,7 @@ export class SdCliProject {
111
106
  }
112
107
 
113
108
  logger.debug("프로젝트 및 패키지 버전 설정...");
114
- await this._upgradeVersionAsync(projNpmConf, allPkgPaths);
109
+ this._upgradeVersion(projNpmConf, allPkgPaths);
115
110
 
116
111
  logger.debug("빌드 프로세스 시작...");
117
112
  const multiBuildRunner = new SdMultiBuildRunner();
@@ -176,7 +171,7 @@ export class SdCliProject {
176
171
 
177
172
  if (!opt.noBuild) {
178
173
  logger.debug("프로젝트 및 패키지 버전 설정...");
179
- await this._upgradeVersionAsync(projNpmConf, allPkgPaths);
174
+ this._upgradeVersion(projNpmConf, allPkgPaths);
180
175
 
181
176
  // 빌드
182
177
  try {
@@ -312,10 +307,7 @@ export class SdCliProject {
312
307
  process.stdout.clearLine(0);
313
308
  }
314
309
 
315
- private static async _upgradeVersionAsync(
316
- projNpmConf: INpmConfig,
317
- allPkgPaths: string[],
318
- ): Promise<void> {
310
+ private static _upgradeVersion(projNpmConf: INpmConfig, allPkgPaths: string[]) {
319
311
  // 작업공간 package.json 버전 설정
320
312
  const newVersion = semver.inc(projNpmConf.version, "patch")!;
321
313
  projNpmConf.version = newVersion;
@@ -342,7 +334,7 @@ export class SdCliProject {
342
334
  FsUtils.writeJson(projNpmConfFilePath, projNpmConf, { space: 2 });
343
335
 
344
336
  // 각 패키지 package.json 버전 설정
345
- await allPkgPaths.parallelAsync(async (pkgPath) => {
337
+ for (const pkgPath of allPkgPaths) {
346
338
  const pkgNpmConfFilePath = path.resolve(pkgPath, "package.json");
347
339
  const pkgNpmConf = FsUtils.readJson(pkgNpmConfFilePath);
348
340
  pkgNpmConf.version = newVersion;
@@ -356,16 +348,12 @@ export class SdCliProject {
356
348
 
357
349
  if (FsUtils.exists(path.resolve(pkgPath, "plugin.xml"))) {
358
350
  const cordovaPluginConfFilePath = path.resolve(pkgPath, "plugin.xml");
359
- const cordovaPluginConfXml = await xml2js.parseStringPromise(FsUtils.readFile(
360
- cordovaPluginConfFilePath));
351
+ const cordovaPluginConfXml = XmlConvert.parse(FsUtils.readFile(cordovaPluginConfFilePath));
361
352
  cordovaPluginConfXml.plugin.$.version = newVersion;
362
353
 
363
- FsUtils.writeFile(
364
- cordovaPluginConfFilePath,
365
- new xml2js.Builder().buildObject(cordovaPluginConfXml),
366
- );
354
+ FsUtils.writeFile(cordovaPluginConfFilePath, XmlConvert.stringify(cordovaPluginConfXml));
367
355
  }
368
- });
356
+ }
369
357
  }
370
358
 
371
359
  static #logging(buildResults: ISdBuildMessage[], logger: SdLogger): void {
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ export * from "./pkg-builders/server/sd-server.bundler";
20
20
  export * from "./pkg-builders/server/sd-server.plugin-creator";
21
21
  import "./sd-cli";
22
22
  export * from "./ts-compiler/sd-ts-compiler";
23
+ export * from "./ts-compiler/sd-ts-dependency-analyzer";
23
24
  export * from "./types/build-plugin.types";
24
25
  export * from "./types/build-runner.types";
25
26
  export * from "./types/build.types";
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import esbuild, { Metafile } from "esbuild";
3
- import { FsUtils, PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
3
+ import { FsUtils, HashUtils, PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
4
4
  import { fileURLToPath } from "url";
5
5
  import nodeStdLibBrowser from "node-stdlib-browser";
6
6
  import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
@@ -47,27 +47,27 @@ import { ISdBuildMessage } from "../../types/build.types";
47
47
  import nodeModule from "node:module";
48
48
 
49
49
  export class SdNgBundler {
50
- readonly #logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundler"]);
50
+ private readonly _logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundler"]);
51
51
 
52
- readonly #modifiedFileSet = new Set<TNormPath>();
53
- readonly #ngResultCache: ISdCliNgPluginResultCache = {
52
+ private readonly _modifiedFileSet = new Set<TNormPath>();
53
+ private readonly _ngResultCache: ISdCliNgPluginResultCache = {
54
54
  affectedFileSet: new Set<TNormPath>(),
55
55
  watchFileSet: new Set<TNormPath>(),
56
56
  };
57
- readonly #styleLoadResultCache = new MemoryLoadResultCache();
57
+ private readonly _styleLoadResultCache = new MemoryLoadResultCache();
58
58
 
59
- #contexts: SdNgBundlerContext[] | undefined;
59
+ private _contexts: SdNgBundlerContext[] | undefined;
60
60
 
61
- readonly #outputCache = new Map<TNormPath, string | number>();
61
+ private readonly _outputHashCache = new Map<TNormPath, string>();
62
62
 
63
- readonly #pkgNpmConf: INpmConfig;
64
- readonly #mainFilePath: string;
65
- readonly #tsConfigFilePath: string;
66
- readonly #swConfFilePath: string;
67
- readonly #browserTarget: string[];
68
- readonly #indexHtmlFilePath: string;
69
- readonly #pkgName: string;
70
- readonly #baseHref: string;
63
+ private readonly _pkgNpmConf: INpmConfig;
64
+ private readonly _mainFilePath: string;
65
+ private readonly _tsConfigFilePath: string;
66
+ private readonly _swConfFilePath: string;
67
+ private readonly _browserTarget: string[];
68
+ private readonly _indexHtmlFilePath: string;
69
+ private readonly _pkgName: string;
70
+ private readonly _baseHref: string;
71
71
 
72
72
  public constructor(
73
73
  private _opt: {
@@ -81,25 +81,25 @@ export class SdNgBundler {
81
81
  watchScopePaths: TNormPath[];
82
82
  },
83
83
  ) {
84
- this.#pkgNpmConf = FsUtils.readJson(path.resolve(this._opt.pkgPath, "package.json"));
85
- this.#mainFilePath = path.resolve(this._opt.pkgPath, "src/main.ts");
86
- this.#tsConfigFilePath = path.resolve(this._opt.pkgPath, "tsconfig.json");
87
- this.#swConfFilePath = path.resolve(this._opt.pkgPath, "ngsw-config.json");
88
- this.#browserTarget = transformSupportedBrowsersToTargets(browserslist(["Chrome > 78"]));
89
- this.#indexHtmlFilePath = path.resolve(this._opt.pkgPath, "src/index.html");
90
- this.#pkgName = path.basename(this._opt.pkgPath);
91
- this.#baseHref =
84
+ this._pkgNpmConf = FsUtils.readJson(path.resolve(this._opt.pkgPath, "package.json"));
85
+ this._mainFilePath = path.resolve(this._opt.pkgPath, "src/main.ts");
86
+ this._tsConfigFilePath = path.resolve(this._opt.pkgPath, "tsconfig.json");
87
+ this._swConfFilePath = path.resolve(this._opt.pkgPath, "ngsw-config.json");
88
+ this._browserTarget = transformSupportedBrowsersToTargets(browserslist(["Chrome > 78"]));
89
+ this._indexHtmlFilePath = path.resolve(this._opt.pkgPath, "src/index.html");
90
+ this._pkgName = path.basename(this._opt.pkgPath);
91
+ this._baseHref =
92
92
  this._opt.builderType === "web"
93
- ? `/${this.#pkgName}/`
93
+ ? `/${this._pkgName}/`
94
94
  : this._opt.dev
95
- ? `/${this.#pkgName}/${this._opt.builderType}/`
95
+ ? `/${this._pkgName}/${this._opt.builderType}/`
96
96
  : ``;
97
97
  }
98
98
 
99
99
  public markForChanges(filePaths: string[]): void {
100
100
  for (const filePath of filePaths) {
101
- this.#modifiedFileSet.add(PathUtils.norm(filePath));
102
- this.#styleLoadResultCache.invalidate(PathUtils.norm(filePath));
101
+ this._modifiedFileSet.add(PathUtils.norm(filePath));
102
+ this._styleLoadResultCache.invalidate(PathUtils.norm(filePath));
103
103
  }
104
104
  // this._sourceFileCache.invalidate(filePaths);
105
105
  }
@@ -112,10 +112,10 @@ export class SdNgBundler {
112
112
  }> {
113
113
  const perf = new SdCliPerformanceTimer("ng bundle");
114
114
 
115
- this.#debug(`get contexts...`);
115
+ this._debug(`get contexts...`);
116
116
 
117
- if (!this.#contexts) {
118
- this.#contexts = perf.run("get contexts", () => [
117
+ if (!this._contexts) {
118
+ this._contexts = perf.run("get contexts", () => [
119
119
  this._getAppContext(),
120
120
  ...FsUtils.exists(path.resolve(this._opt.pkgPath, "src/styles.scss")) ? [
121
121
  this._getStyleContext(),
@@ -124,16 +124,16 @@ export class SdNgBundler {
124
124
  ]);
125
125
  }
126
126
 
127
- this.#debug(`build...`);
127
+ this._debug(`build...`);
128
128
 
129
129
  const bundlingResults = await perf.run("build", async () => {
130
- return await this.#contexts!.mapAsync(async (ctx) => await ctx.bundleAsync());
130
+ return await this._contexts!.mapAsync(async (ctx) => await ctx.bundleAsync());
131
131
  });
132
132
 
133
133
  //-- results
134
134
  const results = bundlingResults.mapMany((bundlingResult) => bundlingResult.results);
135
135
 
136
- this.#debug(`convert result...`);
136
+ this._debug(`convert result...`);
137
137
 
138
138
  const outputFiles: BuildOutputFile[] = bundlingResults.mapMany(
139
139
  (item) => item.outputFiles?.map((file) => convertOutputFile(file, BuildOutputFileType.Root))
@@ -159,7 +159,7 @@ export class SdNgBundler {
159
159
  outputFiles.push(createOutputFile("cordova-empty.js", "export default {};", BuildOutputFileType.Root));
160
160
  }*/
161
161
 
162
- this.#debug(`create index.html...`);
162
+ this._debug(`create index.html...`);
163
163
  await perf.run("create index.html", async () => {
164
164
  const genIndexHtmlResult = await this._genIndexHtmlAsync(outputFiles, initialFiles);
165
165
  for (const warning of genIndexHtmlResult.warnings) {
@@ -208,8 +208,8 @@ export class SdNgBundler {
208
208
  });
209
209
 
210
210
  //-- service worker
211
- if (FsUtils.exists(this.#swConfFilePath)) {
212
- this.#debug(`prepare service worker...`);
211
+ if (FsUtils.exists(this._swConfFilePath)) {
212
+ this._debug(`prepare service worker...`);
213
213
 
214
214
  await perf.run("prepare service worker", async () => {
215
215
  try {
@@ -236,40 +236,44 @@ export class SdNgBundler {
236
236
  }
237
237
 
238
238
  //-- write
239
- this.#debug(`write output files...(${outputFiles.length})`);
239
+ this._debug(`write output files...(${outputFiles.length})`);
240
240
 
241
241
  const emitFileSet = new Set<TNormPath>();
242
242
  perf.run("write output file", () => {
243
243
  for (const outputFile of outputFiles) {
244
244
  const distFilePath = PathUtils.norm(this._opt.outputPath, outputFile.path);
245
- const prev = this.#outputCache.get(distFilePath);
246
- if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
245
+ const prevHash = this._outputHashCache.get(distFilePath);
246
+ const currHash = HashUtils.get(outputFile.contents);
247
+ if (prevHash !== currHash) {
247
248
  FsUtils.writeFile(distFilePath, outputFile.contents);
248
- this.#outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
249
+ this._outputHashCache.set(
250
+ distFilePath,
251
+ Buffer.from(outputFile.contents).toString("base64"),
252
+ );
249
253
  emitFileSet.add(PathUtils.norm(outputFile.path));
250
254
  }
251
255
  }
252
256
  for (const assetFile of assetFiles) {
253
- const prev = this.#outputCache.get(PathUtils.norm(assetFile.source));
254
- const curr = FsUtils.lstat(assetFile.source).mtime.getTime();
255
- if (prev !== curr) {
257
+ const prevHash = this._outputHashCache.get(PathUtils.norm(assetFile.source));
258
+ const currHash = FsUtils.hash(assetFile.source);
259
+ if (prevHash !== currHash) {
256
260
  FsUtils.copy(assetFile.source, path.resolve(this._opt.outputPath, assetFile.destination));
257
- this.#outputCache.set(PathUtils.norm(assetFile.source), curr);
261
+ this._outputHashCache.set(PathUtils.norm(assetFile.source), currHash);
258
262
  emitFileSet.add(PathUtils.norm(assetFile.destination));
259
263
  }
260
264
  }
261
265
  });
262
266
 
263
- this.#debug(perf.toString());
267
+ this._debug(perf.toString());
264
268
 
265
269
  return {
266
270
  watchFileSet: new Set([
267
- ...this.#ngResultCache.watchFileSet!,
268
- ...this.#styleLoadResultCache.watchFiles.map((item) => PathUtils.norm(item)),
271
+ ...this._ngResultCache.watchFileSet!,
272
+ ...this._styleLoadResultCache.watchFiles.map((item) => PathUtils.norm(item)),
269
273
  ...assetFiles.map((item) => PathUtils.norm(item.source)),
270
- PathUtils.norm(this.#indexHtmlFilePath),
274
+ PathUtils.norm(this._indexHtmlFilePath),
271
275
  ]),
272
- affectedFileSet: this.#ngResultCache.affectedFileSet!,
276
+ affectedFileSet: this._ngResultCache.affectedFileSet!,
273
277
  results,
274
278
  emitFileSet: emitFileSet,
275
279
  };
@@ -290,7 +294,7 @@ export class SdNgBundler {
290
294
  };
291
295
 
292
296
  const indexHtmlGenerator = new IndexHtmlGenerator({
293
- indexPath: this.#indexHtmlFilePath,
297
+ indexPath: this._indexHtmlFilePath,
294
298
  entrypoints: [
295
299
  ["polyfills", true],
296
300
  ["styles", false],
@@ -335,7 +339,7 @@ export class SdNgBundler {
335
339
  }
336
340
 
337
341
  return await indexHtmlGenerator.process({
338
- baseHref: this.#baseHref,
342
+ baseHref: this._baseHref,
339
343
  lang: undefined,
340
344
  outputPath: "/",
341
345
  files: [...initialFiles].map(([file, record]) => ({
@@ -402,8 +406,8 @@ export class SdNgBundler {
402
406
  }> {
403
407
  return await augmentAppWithServiceWorkerEsbuild(
404
408
  this._opt.pkgPath,
405
- this.#swConfFilePath,
406
- this.#baseHref,
409
+ this._swConfFilePath,
410
+ this._baseHref,
407
411
  "index.html",
408
412
  outputFiles,
409
413
  assetFiles,
@@ -434,7 +438,7 @@ export class SdNgBundler {
434
438
  outExtension: undefined,
435
439
  sourcemap: this._opt.dev,
436
440
  chunkNames: "[name]-[hash]",
437
- tsconfig: this.#tsConfigFilePath,
441
+ tsconfig: this._tsConfigFilePath,
438
442
  write: false,
439
443
  preserveSymlinks: false,
440
444
  define: {
@@ -443,7 +447,7 @@ export class SdNgBundler {
443
447
  "global": "global",
444
448
  "process": "process",
445
449
  "Buffer": "Buffer",
446
- "process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
450
+ "process.env.SD_VERSION": JSON.stringify(this._pkgNpmConf.version),
447
451
  "process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
448
452
  ...(this._opt.env
449
453
  ? Object.keys(this._opt.env).toObject(
@@ -455,8 +459,7 @@ export class SdNgBundler {
455
459
  mainFields: ["es2020", "es2015", "browser", "module", "main"],
456
460
  entryNames: "[dir]/[name]",
457
461
  entryPoints: {
458
- main: this.#mainFilePath,
459
- // TODO: Polyfills Bundler 분리
462
+ main: this._mainFilePath,
460
463
  ...FsUtils.exists(path.resolve(this._opt.pkgPath, "src/polyfills.ts")) ? {
461
464
  polyfills: path.resolve(this._opt.pkgPath, "src/polyfills.ts"),
462
465
  } : {},
@@ -469,8 +472,6 @@ export class SdNgBundler {
469
472
  ),
470
473
  }
471
474
  : {}),
472
-
473
- // TODO: Workers Bundler 분리
474
475
  ...workerEntries,
475
476
  },
476
477
  supported: { "async-await": false, "object-rest-spread": false },
@@ -509,7 +510,7 @@ export class SdNgBundler {
509
510
  }
510
511
  : {
511
512
  platform: "browser",
512
- target: this.#browserTarget,
513
+ target: this._browserTarget,
513
514
  format: "esm",
514
515
  splitting: true,
515
516
  inject: [
@@ -520,10 +521,10 @@ export class SdNgBundler {
520
521
  plugins: [
521
522
  createSourcemapIgnorelistPlugin(),
522
523
  createSdNgPlugin({
523
- modifiedFileSet: this.#modifiedFileSet,
524
+ modifiedFileSet: this._modifiedFileSet,
524
525
  dev: this._opt.dev,
525
526
  pkgPath: this._opt.pkgPath,
526
- result: this.#ngResultCache,
527
+ result: this._ngResultCache,
527
528
  watchScopePaths: this._opt.watchScopePaths,
528
529
  }),
529
530
  ...(this._opt.builderType === "electron"
@@ -550,7 +551,7 @@ export class SdNgBundler {
550
551
  sourcemap: this._opt.dev,
551
552
  includePaths: [],
552
553
  },
553
- this.#styleLoadResultCache,
554
+ this._styleLoadResultCache,
554
555
  );
555
556
 
556
557
  return new SdNgBundlerContext(this._opt.pkgPath, {
@@ -565,7 +566,7 @@ export class SdNgBundler {
565
566
  outdir: this._opt.pkgPath,
566
567
  write: false,
567
568
  platform: "browser",
568
- target: this.#browserTarget,
569
+ target: this._browserTarget,
569
570
  preserveSymlinks: false,
570
571
  external: [],
571
572
  conditions: ["style", "sass"],
@@ -577,7 +578,7 @@ export class SdNgBundler {
577
578
  plugins: [
578
579
  pluginFactory.create(SassStylesheetLanguage),
579
580
  pluginFactory.create(CssStylesheetLanguage),
580
- createCssResourcePlugin(this.#styleLoadResultCache),
581
+ createCssResourcePlugin(this._styleLoadResultCache),
581
582
  ],
582
583
  });
583
584
  }
@@ -596,13 +597,13 @@ export class SdNgBundler {
596
597
  minify: !this._opt.dev,
597
598
  outdir: this._opt.pkgPath,
598
599
  sourcemap: this._opt.dev,
599
- tsconfig: this.#tsConfigFilePath,
600
+ tsconfig: this._tsConfigFilePath,
600
601
  write: false,
601
602
  preserveSymlinks: false,
602
603
  external: ["electron"],
603
604
  define: {
604
605
  ...(!this._opt.dev ? { ngDevMode: "false" } : {}),
605
- "process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
606
+ "process.env.SD_VERSION": JSON.stringify(this._pkgNpmConf.version),
606
607
  "process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
607
608
  ...(this._opt.env
608
609
  ? Object.keys(this._opt.env).toObject(
@@ -618,7 +619,7 @@ export class SdNgBundler {
618
619
  });
619
620
  }
620
621
 
621
- #debug(...msg: any[]): void {
622
- this.#logger.debug(`[${path.basename(this._opt.pkgPath)}]`, ...msg);
622
+ private _debug(...msg: any[]): void {
623
+ this._logger.debug(`[${path.basename(this._opt.pkgPath)}]`, ...msg);
623
624
  }
624
625
  }
@@ -2,7 +2,7 @@ import esbuild from "esbuild";
2
2
  import path from "path";
3
3
  import os from "os";
4
4
  import { JavaScriptTransformer } from "@angular/build/src/tools/esbuild/javascript-transformer";
5
- import { SdLogger, PathUtils, TNormPath } from "@simplysm/sd-core-node";
5
+ import { PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
6
6
  import { SdCliPerformanceTimer } from "../../utils/sd-cli-performance-time";
7
7
  import { SdCliConvertMessageUtils } from "../../utils/sd-cli-convert-message.utils";
8
8
  import { ISdCliNgPluginResultCache } from "../../types/build-plugin.types";
@@ -16,7 +16,7 @@ export function createSdNgPlugin(conf: {
16
16
  result: ISdCliNgPluginResultCache;
17
17
  watchScopePaths: TNormPath[];
18
18
  }): esbuild.Plugin {
19
- let webWorkerResultMap = new Map<
19
+ /*let webWorkerResultMap = new Map<
20
20
  TNormPath,
21
21
  {
22
22
  outputFiles: esbuild.OutputFile[];
@@ -24,7 +24,7 @@ export function createSdNgPlugin(conf: {
24
24
  errors?: esbuild.Message[];
25
25
  warnings?: esbuild.Message[];
26
26
  }
27
- >();
27
+ >();*/
28
28
 
29
29
  // let workerRevDepMap = new Map<TNormPath, Set<TNormPath>>();
30
30
 
@@ -147,18 +147,18 @@ export function createSdNgPlugin(conf: {
147
147
  ...Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
148
148
  .flatMap((item) => item.errors)
149
149
  .filterExists(),
150
- ...Array.from(webWorkerResultMap.values())
150
+ /*...Array.from(webWorkerResultMap.values())
151
151
  .flatMap((item) => item.errors)
152
- .filterExists(),
152
+ .filterExists(),*/
153
153
  ].filterExists(),
154
154
  warnings: [
155
155
  ...tsEsbuildResult.warnings,
156
156
  ...Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
157
157
  .flatMap((item) => item.warnings)
158
158
  .filterExists(),
159
- ...Array.from(webWorkerResultMap.values())
159
+ /*...Array.from(webWorkerResultMap.values())
160
160
  .flatMap((item) => item.warnings)
161
- .filterExists(),
161
+ .filterExists(),*/
162
162
  ],
163
163
  };
164
164
  });
@@ -173,7 +173,8 @@ export function createSdNgPlugin(conf: {
173
173
  return { contents: output, loader: "js" };
174
174
  }
175
175
 
176
- const emittedJsFile = tsCompileResult.emittedFilesCacheMap.get(PathUtils.norm(args.path))?.last();
176
+ const emittedJsFile = tsCompileResult.emittedFilesCacheMap.get(PathUtils.norm(args.path))
177
+ ?.last();
177
178
  if (!emittedJsFile) {
178
179
  return {
179
180
  errors: [
@@ -191,7 +192,12 @@ export function createSdNgPlugin(conf: {
191
192
  resolveDir: build.initialOptions.absWorkingDir ?? "",
192
193
  });
193
194
 
194
- const newContents = await javascriptTransformer.transformData(args.path, contents, true, sideEffects);
195
+ const newContents = await javascriptTransformer.transformData(
196
+ args.path,
197
+ contents,
198
+ true,
199
+ sideEffects,
200
+ );
195
201
 
196
202
  outputContentsCacheMap.set(PathUtils.norm(args.path), newContents);
197
203
 
@@ -211,24 +217,36 @@ export function createSdNgPlugin(conf: {
211
217
  resolveDir: build.initialOptions.absWorkingDir ?? "",
212
218
  });
213
219
 
214
- const newContents = await javascriptTransformer.transformFile(args.path, false, sideEffects);
220
+ try {
221
+ const newContents = await javascriptTransformer.transformFile(
222
+ args.path,
223
+ false,
224
+ sideEffects,
225
+ );
215
226
 
216
- outputContentsCacheMap.set(PathUtils.norm(args.path), newContents);
227
+ outputContentsCacheMap.set(PathUtils.norm(args.path), newContents);
217
228
 
218
- return {
219
- contents: newContents,
220
- loader: "js",
221
- };
229
+ return {
230
+ contents: newContents,
231
+ loader: "js",
232
+ };
233
+ }
234
+ catch (err) {
235
+ return {
236
+ contents: `console.error(${JSON.stringify(err.message)});`,
237
+ loader: "js",
238
+ };
239
+ }
222
240
  });
223
241
 
224
242
  build.onLoad(
225
243
  {
226
244
  filter: new RegExp(
227
245
  "(" +
228
- Object.keys(build.initialOptions.loader!)
229
- .map((item) => "\\" + item)
230
- .join("|") +
231
- ")$",
246
+ Object.keys(build.initialOptions.loader!)
247
+ .map((item) => "\\" + item)
248
+ .join("|") +
249
+ ")$",
232
250
  ),
233
251
  },
234
252
  (args) => {
@@ -241,17 +259,19 @@ export function createSdNgPlugin(conf: {
241
259
  perf.end("transform & bundling");
242
260
  debug(perf.toString());
243
261
 
244
- for (const { outputFiles, metafile } of tsCompileResult.stylesheetBundlingResultMap.values()) {
245
- result.outputFiles ??= [];
246
- result.outputFiles.push(...outputFiles ?? []);
262
+ for (const stylesheetBundlingResult of tsCompileResult.stylesheetBundlingResultMap.values()) {
263
+ if ("outputFiles" in stylesheetBundlingResult) {
264
+ result.outputFiles ??= [];
265
+ result.outputFiles.push(...stylesheetBundlingResult.outputFiles);
247
266
 
248
- if (result.metafile && metafile) {
249
- result.metafile.inputs = { ...result.metafile.inputs, ...metafile.inputs };
250
- result.metafile.outputs = { ...result.metafile.outputs, ...metafile.outputs };
267
+ if (result.metafile) {
268
+ result.metafile.inputs = { ...result.metafile.inputs, ...stylesheetBundlingResult.metafile.inputs };
269
+ result.metafile.outputs = { ...result.metafile.outputs, ...stylesheetBundlingResult.metafile.outputs };
270
+ }
251
271
  }
252
272
  }
253
273
 
254
- for (const { outputFiles, metafile } of webWorkerResultMap.values()) {
274
+ /*for (const { outputFiles, metafile } of webWorkerResultMap.values()) {
255
275
  result.outputFiles ??= [];
256
276
  result.outputFiles.push(...outputFiles);
257
277
 
@@ -259,7 +279,7 @@ export function createSdNgPlugin(conf: {
259
279
  result.metafile.inputs = { ...result.metafile.inputs, ...metafile.inputs };
260
280
  result.metafile.outputs = { ...result.metafile.outputs, ...metafile.outputs };
261
281
  }
262
- }
282
+ }*/
263
283
 
264
284
  conf.result.outputFiles = result.outputFiles;
265
285
  conf.result.metafile = result.metafile;
@@ -42,10 +42,16 @@ export class SdTsLibBuilder {
42
42
  }
43
43
  }
44
44
 
45
- const globalStylesheetBundlingResult = tsCompileResult.stylesheetBundlingResultMap.get(emitFile);
46
- if (globalStylesheetBundlingResult) {
47
- for (const outputFile of globalStylesheetBundlingResult.outputFiles ?? []) {
48
- const distPath = PathUtils.norm(this._pkgPath, "dist", path.relative(this._pkgPath, outputFile.path));
45
+ const globalStylesheetBundlingResult = tsCompileResult
46
+ .stylesheetBundlingResultMap
47
+ .get(emitFile);
48
+ if (globalStylesheetBundlingResult && "outputFiles" in globalStylesheetBundlingResult) {
49
+ for (const outputFile of globalStylesheetBundlingResult.outputFiles) {
50
+ const distPath = PathUtils.norm(
51
+ this._pkgPath,
52
+ "dist",
53
+ path.relative(this._pkgPath, outputFile.path),
54
+ );
49
55
  if (PathUtils.isChildPath(distPath, path.resolve(this._pkgPath, "dist"))) {
50
56
  FsUtils.writeFile(distPath, outputFile.text);
51
57
  emitFileSet.add(distPath);
@@ -54,9 +60,10 @@ export class SdTsLibBuilder {
54
60
  }
55
61
  }
56
62
 
57
- const styleResults = Array.from(tsCompileResult.stylesheetBundlingResultMap.values()).mapMany((item) =>
58
- SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(item, this._pkgPath),
59
- );
63
+ const styleResults = Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
64
+ .mapMany((item) =>
65
+ SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(item, this._pkgPath),
66
+ );
60
67
 
61
68
  return {
62
69
  watchFileSet: tsCompileResult.watchFileSet,