@simplysm/sd-cli 12.8.22 → 12.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/entry/sd-cli-ai-command.js +2 -1
  2. package/dist/entry/sd-cli-ai-command.js.map +1 -1
  3. package/dist/entry/sd-cli-cordova.d.ts +1 -1
  4. package/dist/entry/sd-cli-cordova.js +1 -1
  5. package/dist/entry/sd-cli-cordova.js.map +1 -1
  6. package/dist/entry/sd-cli-electron.d.ts +6 -6
  7. package/dist/entry/sd-cli-electron.js +15 -9
  8. package/dist/entry/sd-cli-electron.js.map +1 -1
  9. package/dist/entry/sd-cli-local-update.d.ts +5 -5
  10. package/dist/entry/sd-cli-local-update.js +8 -12
  11. package/dist/entry/sd-cli-local-update.js.map +1 -1
  12. package/dist/entry/sd-cli-project.d.ts +11 -11
  13. package/dist/entry/sd-cli-project.js +11 -14
  14. package/dist/entry/sd-cli-project.js.map +1 -1
  15. package/dist/entry/utils/loadProjConfAsync.d.ts +5 -0
  16. package/dist/entry/utils/loadProjConfAsync.js +8 -0
  17. package/dist/entry/utils/loadProjConfAsync.js.map +1 -0
  18. package/dist/pkg-builders/client/sd-client.build-runner.js +1 -1
  19. package/dist/pkg-builders/client/sd-client.build-runner.js.map +1 -1
  20. package/dist/pkg-builders/client/sd-ng.bundler-context.d.ts +6 -5
  21. package/dist/pkg-builders/client/sd-ng.bundler-context.js +6 -6
  22. package/dist/pkg-builders/client/sd-ng.bundler-context.js.map +1 -1
  23. package/dist/pkg-builders/client/sd-ng.bundler.d.ts +13 -13
  24. package/dist/pkg-builders/client/sd-ng.bundler.js.map +1 -1
  25. package/dist/pkg-builders/client/sd-ng.plugin-creator.js +4 -88
  26. package/dist/pkg-builders/client/sd-ng.plugin-creator.js.map +1 -1
  27. package/dist/pkg-builders/lib/sd-js-lib.build-runner.js.map +1 -1
  28. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.d.ts +1 -1
  29. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js.map +1 -1
  30. package/dist/pkg-builders/lib/sd-ts-lib.builder.js.map +1 -1
  31. package/dist/pkg-builders/sd-multi.build-runner.d.ts +4 -0
  32. package/dist/pkg-builders/sd-multi.build-runner.js +33 -25
  33. package/dist/pkg-builders/sd-multi.build-runner.js.map +1 -1
  34. package/dist/pkg-builders/server/sd-server.build-runner.js.map +1 -1
  35. package/dist/pkg-builders/server/sd-server.bundler.d.ts +6 -2
  36. package/dist/pkg-builders/server/sd-server.bundler.js +18 -19
  37. package/dist/pkg-builders/server/sd-server.bundler.js.map +1 -1
  38. package/dist/sd-cli/vitest.config.d.ts +2 -0
  39. package/dist/sd-cli/vitest.config.js +15 -0
  40. package/dist/sd-cli/vitest.config.js.map +1 -0
  41. package/dist/sd-cli.js +7 -36
  42. package/dist/sd-cli.js.map +1 -1
  43. package/dist/ts-compiler/sd-dependency-analyzer.d.ts +8 -0
  44. package/dist/ts-compiler/sd-dependency-analyzer.js +244 -0
  45. package/dist/ts-compiler/sd-dependency-analyzer.js.map +1 -0
  46. package/dist/ts-compiler/sd-dependency-cache.d.ts +27 -0
  47. package/dist/ts-compiler/sd-dependency-cache.js +232 -0
  48. package/dist/ts-compiler/sd-dependency-cache.js.map +1 -0
  49. package/dist/ts-compiler/sd-ts-compiler.d.ts +7 -10
  50. package/dist/ts-compiler/sd-ts-compiler.js +102 -228
  51. package/dist/ts-compiler/sd-ts-compiler.js.map +1 -1
  52. package/dist/types/worker.types.d.ts +19 -0
  53. package/dist/utils/sd-cli-performance-time.d.ts +2 -1
  54. package/dist/utils/sd-cli-performance-time.js +9 -9
  55. package/dist/utils/sd-cli-performance-time.js.map +1 -1
  56. package/dist/workers/style-bundler.worker.d.ts +1 -0
  57. package/dist/workers/style-bundler.worker.js +56 -0
  58. package/dist/workers/style-bundler.worker.js.map +1 -0
  59. package/package.json +10 -10
  60. package/src/entry/sd-cli-ai-command.ts +2 -1
  61. package/src/entry/sd-cli-cordova.ts +5 -5
  62. package/src/entry/sd-cli-electron.ts +54 -23
  63. package/src/entry/sd-cli-local-update.ts +14 -29
  64. package/src/entry/sd-cli-project.ts +24 -41
  65. package/src/entry/utils/loadProjConfAsync.ts +12 -0
  66. package/src/pkg-builders/client/sd-client.build-runner.ts +7 -7
  67. package/src/pkg-builders/client/sd-ng.bundler-context.ts +15 -12
  68. package/src/pkg-builders/client/sd-ng.bundler.ts +16 -16
  69. package/src/pkg-builders/client/sd-ng.plugin-creator.ts +5 -94
  70. package/src/pkg-builders/lib/sd-js-lib.build-runner.ts +6 -6
  71. package/src/pkg-builders/lib/sd-ts-lib.build-runner.ts +7 -7
  72. package/src/pkg-builders/lib/sd-ts-lib.builder.ts +1 -1
  73. package/src/pkg-builders/sd-multi.build-runner.ts +54 -39
  74. package/src/pkg-builders/server/sd-server.build-runner.ts +6 -6
  75. package/src/pkg-builders/server/sd-server.bundler.ts +26 -28
  76. package/src/sd-cli.ts +7 -36
  77. package/src/ts-compiler/sd-dependency-analyzer.ts +312 -0
  78. package/src/ts-compiler/sd-dependency-cache.ts +328 -0
  79. package/src/ts-compiler/sd-ts-compiler.ts +161 -302
  80. package/src/types/worker.types.ts +17 -0
  81. package/src/utils/sd-cli-performance-time.ts +9 -9
  82. package/src/workers/style-bundler.worker.ts +70 -0
  83. package/tests/deps/sd-dependency-analyzer.spec.ts +272 -0
  84. package/tests/deps/sd-dependency-cache.spec.ts +144 -0
  85. package/tsconfig.json +1 -1
  86. package/tsconfig.test.json +8 -0
  87. package/vitest.config.ts +15 -0
  88. package/dist/index.d.ts +0 -34
  89. package/dist/index.js +0 -35
  90. package/dist/index.js.map +0 -1
  91. package/dist/ts-compiler/sd-ts-dependency-analyzer.d.ts +0 -6
  92. package/dist/ts-compiler/sd-ts-dependency-analyzer.js +0 -141
  93. package/dist/ts-compiler/sd-ts-dependency-analyzer.js.map +0 -1
  94. package/src/index.ts +0 -34
  95. package/src/ts-compiler/sd-ts-dependency-analyzer.ts +0 -185
@@ -8,24 +8,24 @@ import { SdCliConvertMessageUtils } from "../../utils/sd-cli-convert-message.uti
8
8
  interface InitialFileRecord {
9
9
  entrypoint: boolean;
10
10
  name?: string;
11
- type: 'script' | 'style';
11
+ type: "script" | "style";
12
12
  external?: boolean;
13
13
  serverFile: boolean;
14
14
  depth: number;
15
15
  }
16
16
 
17
17
  export class SdNgBundlerContext {
18
- readonly #logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundlerContext"]);
18
+ private _logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundlerContext"]);
19
19
 
20
20
  private _context?: esbuild.BuildContext;
21
21
 
22
- public constructor(
23
- private readonly _pkgPath: string,
24
- private readonly _esbuildOptions: esbuild.BuildOptions,
22
+ constructor(
23
+ private _pkgPath: string,
24
+ private _esbuildOptions: esbuild.BuildOptions,
25
25
  ) {
26
26
  }
27
27
 
28
- public async bundleAsync() {
28
+ async bundleAsync() {
29
29
  if (this._context == null) {
30
30
  this._context = await esbuild.context(this._esbuildOptions);
31
31
  }
@@ -33,9 +33,9 @@ export class SdNgBundlerContext {
33
33
  let esbuildResult: esbuild.BuildResult;
34
34
 
35
35
  try {
36
- this.#debug(`rebuild...`);
36
+ this._debug(`rebuild...`);
37
37
  esbuildResult = await this._context.rebuild();
38
- this.#debug(`rebuild completed`);
38
+ this._debug(`rebuild completed`);
39
39
  }
40
40
  catch (err) {
41
41
  if ("warnings" in err || "errors" in err) {
@@ -46,9 +46,12 @@ export class SdNgBundlerContext {
46
46
  }
47
47
  }
48
48
 
49
- this.#debug(`convert results...`);
49
+ this._debug(`convert results...`);
50
50
 
51
- const results = SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(esbuildResult, this._pkgPath);
51
+ const results = SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(
52
+ esbuildResult,
53
+ this._pkgPath,
54
+ );
52
55
 
53
56
  const initialFiles = new Map<string, InitialFileRecord>();
54
57
 
@@ -115,8 +118,8 @@ export class SdNgBundlerContext {
115
118
  };
116
119
  }
117
120
 
118
- #debug(...msg: any[]): void {
119
- this.#logger.debug(
121
+ private _debug(...msg: any[]): void {
122
+ this._logger.debug(
120
123
  `[${path.basename(this._pkgPath)}] (${Object.keys(this._esbuildOptions.entryPoints as Record<string, any>)
121
124
  .join(", ")})`,
122
125
  ...msg,
@@ -47,29 +47,29 @@ import { ISdBuildMessage } from "../../types/build.types";
47
47
  import nodeModule from "node:module";
48
48
 
49
49
  export class SdNgBundler {
50
- private readonly _logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundler"]);
50
+ private _logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundler"]);
51
51
 
52
- private readonly _modifiedFileSet = new Set<TNormPath>();
53
- private readonly _ngResultCache: ISdCliNgPluginResultCache = {
52
+ private _modifiedFileSet = new Set<TNormPath>();
53
+ private _ngResultCache: ISdCliNgPluginResultCache = {
54
54
  affectedFileSet: new Set<TNormPath>(),
55
55
  watchFileSet: new Set<TNormPath>(),
56
56
  };
57
- private readonly _styleLoadResultCache = new MemoryLoadResultCache();
57
+ private _styleLoadResultCache = new MemoryLoadResultCache();
58
58
 
59
59
  private _contexts: SdNgBundlerContext[] | undefined;
60
60
 
61
- private readonly _outputHashCache = new Map<TNormPath, string>();
61
+ private _outputHashCache = new Map<TNormPath, string>();
62
62
 
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;
63
+ private _pkgNpmConf: INpmConfig;
64
+ private _mainFilePath: string;
65
+ private _tsConfigFilePath: string;
66
+ private _swConfFilePath: string;
67
+ private _browserTarget: string[];
68
+ private _indexHtmlFilePath: string;
69
+ private _pkgName: string;
70
+ private _baseHref: string;
71
71
 
72
- public constructor(
72
+ constructor(
73
73
  private _opt: {
74
74
  dev: boolean;
75
75
  outputPath: TNormPath;
@@ -96,7 +96,7 @@ export class SdNgBundler {
96
96
  : ``;
97
97
  }
98
98
 
99
- public markForChanges(filePaths: string[]): void {
99
+ markForChanges(filePaths: string[]): void {
100
100
  for (const filePath of filePaths) {
101
101
  this._modifiedFileSet.add(PathUtils.norm(filePath));
102
102
  this._styleLoadResultCache.invalidate(PathUtils.norm(filePath));
@@ -104,7 +104,7 @@ export class SdNgBundler {
104
104
  // this._sourceFileCache.invalidate(filePaths);
105
105
  }
106
106
 
107
- public async bundleAsync(): Promise<{
107
+ async bundleAsync(): Promise<{
108
108
  watchFileSet: Set<TNormPath>;
109
109
  affectedFileSet: Set<TNormPath>;
110
110
  results: ISdBuildMessage[];
@@ -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 { PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
5
+ import { PathUtils, SdLogger, SdLoggerSeverity, 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,24 +16,12 @@ export function createSdNgPlugin(conf: {
16
16
  result: ISdCliNgPluginResultCache;
17
17
  watchScopePaths: TNormPath[];
18
18
  }): esbuild.Plugin {
19
- /*let webWorkerResultMap = new Map<
20
- TNormPath,
21
- {
22
- outputFiles: esbuild.OutputFile[];
23
- metafile?: esbuild.Metafile;
24
- errors?: esbuild.Message[];
25
- warnings?: esbuild.Message[];
26
- }
27
- >();*/
28
-
29
- // let workerRevDepMap = new Map<TNormPath, Set<TNormPath>>();
30
-
31
19
  let perf: SdCliPerformanceTimer;
32
20
  const logger = SdLogger.get(["simplysm", "sd-cli", "createSdNgPlugin"]);
33
21
 
34
- function debug(...msg: any[]): void {
35
- logger.debug(`[${path.basename(conf.pkgPath)}]`, ...msg);
36
- }
22
+ const log = (severity: Exclude<keyof typeof SdLoggerSeverity, "none">, ...msg: any[]) => {
23
+ logger[severity](`[${path.basename(conf.pkgPath)}]`, ...msg);
24
+ };
37
25
 
38
26
  return {
39
27
  name: "sd-ng-compile",
@@ -44,64 +32,11 @@ export function createSdNgPlugin(conf: {
44
32
  isDevMode: conf.dev,
45
33
  isForBundle: true,
46
34
  watchScopePaths: conf.watchScopePaths,
47
- /*processWebWorker: (workerFile, containingFile) => {
48
- const fullWorkerPath = path.join(path.dirname(containingFile), workerFile);
49
- const workerResult = build.esbuild.buildSync({
50
- ...build.initialOptions,
51
- platform: "browser",
52
- write: false,
53
- bundle: true,
54
- metafile: true,
55
- format: "esm",
56
- entryNames: "worker-[hash]",
57
- entryPoints: [fullWorkerPath],
58
- supported: undefined,
59
- plugins: undefined,
60
- // plugins: build.initialOptions.plugins?.filter((item) => item.name !== "sd-ng-compile"),
61
- });
62
-
63
- const dependencySet = new Set<TNormPath>();
64
-
65
- if (workerResult.errors.length > 0) {
66
- dependencySet.adds(
67
- ...workerResult.errors
68
- .map((error) => error.location?.file)
69
- .filterExists()
70
- .map((file) => PathUtil.norm(build.initialOptions.absWorkingDir ?? "", file)),
71
- );
72
- } else {
73
- dependencySet.adds(
74
- ...Object.keys(workerResult.metafile.inputs).map((input) =>
75
- PathUtil.norm(build.initialOptions.absWorkingDir ?? "", input),
76
- ),
77
- );
78
- }
79
-
80
- for (const dep of dependencySet) {
81
- const depCache = workerRevDepMap.getOrCreate(dep, new Set<TNormPath>());
82
- depCache.add(PathUtil.norm(containingFile));
83
- }
84
-
85
- webWorkerResultMap.set(PathUtil.norm(fullWorkerPath), {
86
- outputFiles: workerResult.outputFiles,
87
- metafile: workerResult.metafile,
88
- warnings: workerResult.warnings,
89
- errors: workerResult.errors,
90
- });
91
-
92
- const workerCodeFile = workerResult.outputFiles.single((file) =>
93
- /^worker-[A-Z0-9]{8}.[cm]?js$/.test(path.basename(file.path)),
94
- )!;
95
- const workerCodePath = path.relative(build.initialOptions.outdir ?? "", workerCodeFile.path);
96
-
97
- return workerCodePath.replaceAll("\\", "/");
98
- },*/
99
35
  });
100
36
 
101
37
  let tsCompileResult: ISdTsCompilerResult;
102
38
  const outputContentsCacheMap = new Map<TNormPath, Uint8Array>();
103
39
 
104
- // const cacheStore = new LmbdCacheStore(path.join(process.cwd(), "angular-compiler.db"));
105
40
  //-- js babel transformer
106
41
  const javascriptTransformer = new JavaScriptTransformer(
107
42
  {
@@ -111,7 +46,6 @@ export function createSdNgPlugin(conf: {
111
46
  advancedOptimizations: true,
112
47
  },
113
48
  os.cpus().length,
114
- // cacheStore.createCache("jstransformer"),
115
49
  );
116
50
 
117
51
  //---------------------------
@@ -122,13 +56,6 @@ export function createSdNgPlugin(conf: {
122
56
  const res = await perf.run("typescript build", async () => {
123
57
  for (const modifiedFile of conf.modifiedFileSet) {
124
58
  outputContentsCacheMap.delete(modifiedFile);
125
-
126
- /*if (workerRevDepMap.has(modifiedFile)) {
127
- for (const workerContainingFile of workerRevDepMap.get(modifiedFile)!) {
128
- outputContentsCacheMap.delete(workerContainingFile);
129
- conf.modifiedFileSet.add(workerContainingFile);
130
- }
131
- }*/
132
59
  }
133
60
 
134
61
  tsCompileResult = await tsCompiler.compileAsync(conf.modifiedFileSet);
@@ -147,18 +74,12 @@ export function createSdNgPlugin(conf: {
147
74
  ...Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
148
75
  .flatMap((item) => item.errors)
149
76
  .filterExists(),
150
- /*...Array.from(webWorkerResultMap.values())
151
- .flatMap((item) => item.errors)
152
- .filterExists(),*/
153
77
  ].filterExists(),
154
78
  warnings: [
155
79
  ...tsEsbuildResult.warnings,
156
80
  ...Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
157
81
  .flatMap((item) => item.warnings)
158
82
  .filterExists(),
159
- /*...Array.from(webWorkerResultMap.values())
160
- .flatMap((item) => item.warnings)
161
- .filterExists(),*/
162
83
  ],
163
84
  };
164
85
  });
@@ -257,7 +178,7 @@ export function createSdNgPlugin(conf: {
257
178
 
258
179
  build.onEnd((result) => {
259
180
  perf.end("transform & bundling");
260
- debug(perf.toString());
181
+ log("log", perf.toString());
261
182
 
262
183
  for (const stylesheetBundlingResult of tsCompileResult.stylesheetBundlingResultMap.values()) {
263
184
  if ("outputFiles" in stylesheetBundlingResult) {
@@ -271,16 +192,6 @@ export function createSdNgPlugin(conf: {
271
192
  }
272
193
  }
273
194
 
274
- /*for (const { outputFiles, metafile } of webWorkerResultMap.values()) {
275
- result.outputFiles ??= [];
276
- result.outputFiles.push(...outputFiles);
277
-
278
- if (result.metafile && metafile) {
279
- result.metafile.inputs = { ...result.metafile.inputs, ...metafile.inputs };
280
- result.metafile.outputs = { ...result.metafile.outputs, ...metafile.outputs };
281
- }
282
- }*/
283
-
284
195
  conf.result.outputFiles = result.outputFiles;
285
196
  conf.result.metafile = result.metafile;
286
197
 
@@ -13,7 +13,7 @@ export class SdJsLibBuildRunner extends EventEmitter {
13
13
 
14
14
  // private readonly _lintWorker: SdWorker<TSdLintWorkerType>;
15
15
 
16
- public constructor(
16
+ constructor(
17
17
  private readonly _projConf: ISdProjectConfig,
18
18
  private readonly _pkgPath: string,
19
19
  ) {
@@ -23,14 +23,14 @@ export class SdJsLibBuildRunner extends EventEmitter {
23
23
  // this._lintWorker = new SdWorker(import.meta.resolve("../../workers/lint-worker"));
24
24
  }
25
25
 
26
- public override on(event: "change", listener: () => void): this;
27
- public override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
28
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
26
+ override on(event: "change", listener: () => void): this;
27
+ override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
28
+ override on(event: string | symbol, listener: (...args: any[]) => void): this {
29
29
  super.on(event, listener);
30
30
  return this;
31
31
  }
32
32
 
33
- public async buildAsync(): Promise<ISdBuildRunnerResult> {
33
+ async buildAsync(): Promise<ISdBuildRunnerResult> {
34
34
  this._debug("LINT...");
35
35
  const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.js");
36
36
  const srcFilePaths = FsUtils.glob(srcGlobPath);
@@ -46,7 +46,7 @@ export class SdJsLibBuildRunner extends EventEmitter {
46
46
  };
47
47
  }
48
48
 
49
- public async watchAsync(): Promise<void> {
49
+ async watchAsync(): Promise<void> {
50
50
  this.emit("change");
51
51
  this._debug("LINT...");
52
52
  const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.js");
@@ -17,7 +17,7 @@ export class SdTsLibBuildRunner extends EventEmitter {
17
17
 
18
18
  private _builder?: SdTsLibBuilder;
19
19
 
20
- public constructor(projConf: ISdProjectConfig, pkgPath: string) {
20
+ constructor(projConf: ISdProjectConfig, pkgPath: string) {
21
21
  super();
22
22
  this._projConf = projConf;
23
23
  this._pkgPath = pkgPath;
@@ -32,14 +32,14 @@ export class SdTsLibBuildRunner extends EventEmitter {
32
32
  );
33
33
  }
34
34
 
35
- public override on(event: "change", listener: () => void): this;
36
- public override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
37
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
35
+ override on(event: "change", listener: () => void): this;
36
+ override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
37
+ override on(event: string | symbol, listener: (...args: any[]) => void): this {
38
38
  super.on(event, listener);
39
39
  return this;
40
40
  }
41
41
 
42
- public async buildAsync(): Promise<ISdBuildRunnerResult> {
42
+ async buildAsync(): Promise<ISdBuildRunnerResult> {
43
43
  this._debug("dist 초기화...");
44
44
  FsUtils.remove(path.resolve(this._pkgPath, "dist"));
45
45
 
@@ -61,7 +61,7 @@ export class SdTsLibBuildRunner extends EventEmitter {
61
61
  };
62
62
  }
63
63
 
64
- public async watchAsync(): Promise<void> {
64
+ async watchAsync(): Promise<void> {
65
65
  this.emit("change");
66
66
 
67
67
  this._debug("dist 초기화...");
@@ -150,7 +150,7 @@ export class SdTsLibBuildRunner extends EventEmitter {
150
150
  };
151
151
  }
152
152
 
153
- private _debug(msg: string): void {
153
+ protected _debug(msg: string): void {
154
154
  this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
155
155
  }
156
156
  }
@@ -22,7 +22,7 @@ export class SdTsLibBuilder {
22
22
  });
23
23
  }
24
24
 
25
- public async buildAsync(modifiedFileSet: Set<TNormPath>): Promise<{
25
+ async buildAsync(modifiedFileSet: Set<TNormPath>): Promise<{
26
26
  watchFileSet: Set<TNormPath>;
27
27
  affectedFileSet: Set<TNormPath>;
28
28
  results: ISdBuildMessage[];
@@ -1,4 +1,4 @@
1
- import { FsUtils, SdLogger, PathUtils, SdWorker, TNormPath } from "@simplysm/sd-core-node";
1
+ import { FsUtils, PathUtils, SdLogger, SdWorker, TNormPath } from "@simplysm/sd-core-node";
2
2
  import path from "path";
3
3
  import { EventEmitter } from "events";
4
4
  import { ISdServerPackageConfig } from "../types/config.types";
@@ -8,12 +8,12 @@ import { INpmConfig } from "../types/common-configs.types";
8
8
  import { ISdBuildRunnerWorkerRequest } from "../types/build-runner.types";
9
9
 
10
10
  export class SdMultiBuildRunner extends EventEmitter {
11
- #logger = SdLogger.get(["simplysm", "sd-cli", "SdMultiBuildRunner"]);
11
+ private _logger = SdLogger.get(["simplysm", "sd-cli", "SdMultiBuildRunner"]);
12
12
 
13
- #busyCount = 0;
13
+ private _busyCount = 0;
14
14
 
15
- #resultCache = new Map<TNormPath, ISdBuildMessage[]>();
16
- #serverInfoMap = new Map<
15
+ private _resultCache = new Map<TNormPath, ISdBuildMessage[]>();
16
+ private _serverInfoMap = new Map<
17
17
  string,
18
18
  {
19
19
  pkgInfo?: { path: string; conf: ISdServerPackageConfig } | { port: number }; // persist
@@ -33,9 +33,9 @@ export class SdMultiBuildRunner extends EventEmitter {
33
33
  }
34
34
  >();
35
35
 
36
- public override on(event: "change", listener: () => void): this;
37
- public override on(event: "complete", listener: (result: ISdBuildMessage[]) => void): this;
38
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
36
+ override on(event: "change", listener: () => void): this;
37
+ override on(event: "complete", listener: (result: ISdBuildMessage[]) => void): this;
38
+ override on(event: string | symbol, listener: (...args: any[]) => void): this {
39
39
  super.on(event, listener);
40
40
  return this;
41
41
  }
@@ -43,12 +43,13 @@ export class SdMultiBuildRunner extends EventEmitter {
43
43
  async runAsync(req: ISdBuildRunnerWorkerRequest & { cmd: "watch" }): Promise<void>;
44
44
  async runAsync(req: ISdBuildRunnerWorkerRequest & { cmd: "build" }): Promise<ISdBuildMessage[]>;
45
45
  async runAsync(req: ISdBuildRunnerWorkerRequest): Promise<ISdBuildMessage[] | void> {
46
- const worker = new SdWorker<TSdBuildRunnerWorkerType>(import.meta.resolve("../workers/build-runner.worker"))
46
+ const worker = new SdWorker<TSdBuildRunnerWorkerType>(import.meta.resolve(
47
+ "../workers/build-runner.worker"))
47
48
  .on("change", () => {
48
- if (this.#busyCount === 0) {
49
+ if (this._busyCount === 0) {
49
50
  this.emit("change");
50
51
  }
51
- this.#busyCount++;
52
+ this._busyCount++;
52
53
  })
53
54
  .on("complete", (result) => this.#onComplete(req, result));
54
55
 
@@ -78,15 +79,15 @@ export class SdMultiBuildRunner extends EventEmitter {
78
79
  }
79
80
 
80
81
  #onComplete(req: ISdBuildRunnerWorkerRequest, result: ISdBuildRunnerResult) {
81
- this.#resultCache.delete(req.pkgPath);
82
+ this._resultCache.delete(req.pkgPath);
82
83
  for (const affectedFilePath of result.affectedFilePathSet) {
83
84
  if (PathUtils.isChildPath(affectedFilePath, req.pkgPath)) {
84
- this.#resultCache.delete(affectedFilePath);
85
+ this._resultCache.delete(affectedFilePath);
85
86
  }
86
87
  }
87
88
 
88
89
  for (const buildMessage of result.buildMessages) {
89
- const cacheItem = this.#resultCache.getOrCreate(buildMessage.filePath ?? req.pkgPath, []);
90
+ const cacheItem = this._resultCache.getOrCreate(buildMessage.filePath ?? req.pkgPath, []);
90
91
  cacheItem.push(buildMessage);
91
92
  }
92
93
 
@@ -94,7 +95,7 @@ export class SdMultiBuildRunner extends EventEmitter {
94
95
 
95
96
  if (pkgConf.type === "server") {
96
97
  const pkgName = path.basename(req.pkgPath);
97
- const serverInfo = this.#serverInfoMap.getOrCreate(pkgName, {
98
+ const serverInfo = this._serverInfoMap.getOrCreate(pkgName, {
98
99
  hasChanges: true,
99
100
  clientChangedFileSet: new Set(),
100
101
  clients: {},
@@ -112,7 +113,7 @@ export class SdMultiBuildRunner extends EventEmitter {
112
113
  const pkgName = path.basename(req.pkgPath);
113
114
 
114
115
  if (pkgConf.server !== undefined) {
115
- const serverInfo = this.#serverInfoMap.getOrCreate(
116
+ const serverInfo = this._serverInfoMap.getOrCreate(
116
117
  typeof pkgConf.server === "string" ? pkgConf.server : pkgConf.server.port.toString(),
117
118
  {
118
119
  hasChanges: true,
@@ -133,7 +134,7 @@ export class SdMultiBuildRunner extends EventEmitter {
133
134
  serverInfo.clientChangedFileSet.adds(...result.emitFileSet);
134
135
  }
135
136
  else {
136
- const serverInfo = this.#serverInfoMap.getOrCreate(pkgName, {
137
+ const serverInfo = this._serverInfoMap.getOrCreate(pkgName, {
137
138
  hasChanges: true,
138
139
  clientChangedFileSet: new Set(),
139
140
  clients: {},
@@ -144,25 +145,28 @@ export class SdMultiBuildRunner extends EventEmitter {
144
145
  }
145
146
 
146
147
  setTimeout(async () => {
147
- this.#busyCount--;
148
- if (this.#busyCount === 0) {
149
- for (const serverPkgNameOrPort of this.#serverInfoMap.keys()) {
150
- const serverInfo = this.#serverInfoMap.get(serverPkgNameOrPort)!;
148
+ this._busyCount--;
149
+ if (this._busyCount === 0) {
150
+ for (const serverPkgNameOrPort of this._serverInfoMap.keys()) {
151
+ const serverInfo = this._serverInfoMap.get(serverPkgNameOrPort)!;
151
152
  if (serverInfo.pkgInfo && serverInfo.hasChanges) {
152
- this.#logger.debug("서버 재시작...");
153
+ this._logger.debug("서버 재시작...");
153
154
  try {
154
- const restartServerResult = await this.#restartServerAsync(serverInfo.pkgInfo, serverInfo.worker);
155
+ const restartServerResult = await this.#restartServerAsync(
156
+ serverInfo.pkgInfo,
157
+ serverInfo.worker,
158
+ );
155
159
  serverInfo.worker = restartServerResult.worker;
156
160
  serverInfo.port = restartServerResult.port;
157
161
  serverInfo.hasChanges = false;
158
162
  }
159
163
  catch (err) {
160
- this.#logger.error(err);
164
+ this._logger.error(err);
161
165
  }
162
166
  }
163
167
 
164
168
  if (serverInfo.worker) {
165
- this.#logger.debug("클라이언트 설정...");
169
+ this._logger.debug("클라이언트 설정...");
166
170
  await serverInfo.worker.run("setPathProxy", [
167
171
  {
168
172
  ...Object.keys(serverInfo.clients).toObject(
@@ -174,14 +178,14 @@ export class SdMultiBuildRunner extends EventEmitter {
174
178
  ]);
175
179
 
176
180
  if (serverInfo.clientChangedFileSet.size > 0) {
177
- this.#logger.debug("클라이언트 새로고침...");
181
+ this._logger.debug("클라이언트 새로고침...");
178
182
  await serverInfo.worker.run("broadcastReload", [serverInfo.clientChangedFileSet]);
179
183
  }
180
184
  }
181
185
  }
182
186
 
183
187
  const clientPaths: string[] = [];
184
- for (const serverInfo of this.#serverInfoMap.values()) {
188
+ for (const serverInfo of this._serverInfoMap.values()) {
185
189
  if (Object.keys(serverInfo.clients).length > 0) {
186
190
  for (const clientPkgName of Object.keys(serverInfo.clients)) {
187
191
  for (const buildType of serverInfo.clients[clientPkgName].buildTypes) {
@@ -199,10 +203,10 @@ export class SdMultiBuildRunner extends EventEmitter {
199
203
  }
200
204
  }
201
205
  if (clientPaths.length > 0) {
202
- this.#logger.info("클라이언트 개발 서버 접속 주소\n" + clientPaths.join("\n"));
206
+ this._logger.info("클라이언트 개발 서버 접속 주소\n" + clientPaths.join("\n"));
203
207
  }
204
208
 
205
- const messages = Array.from(this.#resultCache.values()).mapMany();
209
+ const messages = Array.from(this._resultCache.values()).mapMany();
206
210
  this.emit("complete", messages);
207
211
  }
208
212
  }, 300);
@@ -215,23 +219,34 @@ export class SdMultiBuildRunner extends EventEmitter {
215
219
  worker: SdWorker<TServerWorkerType>;
216
220
  port: number;
217
221
  }> {
218
- const logger = SdLogger.get(["simplysm", "sd-cli", "SdMultiBuildRunner", "#restartServerAsync"]);
222
+ const logger = SdLogger.get([
223
+ "simplysm",
224
+ "sd-cli",
225
+ "SdMultiBuildRunner",
226
+ "#restartServerAsync",
227
+ ]);
219
228
 
220
229
  if (prevWorker) {
221
230
  await prevWorker.killAsync();
222
231
  }
223
232
 
224
233
  const npmConf =
225
- "path" in pkgInfo ? (FsUtils.readJson(path.resolve(pkgInfo.path, "package.json")) as INpmConfig) : undefined;
226
-
227
- const worker = new SdWorker<TServerWorkerType>(import.meta.resolve("../workers/server.worker"), {
228
- env: {
229
- NODE_ENV: "development",
230
- TZ: "Asia/Seoul",
231
- SD_VERSION: npmConf?.version ?? "serverless",
232
- ...("path" in pkgInfo ? pkgInfo.conf.env : {}),
234
+ "path" in pkgInfo ? (FsUtils.readJson(path.resolve(
235
+ pkgInfo.path,
236
+ "package.json",
237
+ )) as INpmConfig) : undefined;
238
+
239
+ const worker = new SdWorker<TServerWorkerType>(
240
+ import.meta.resolve("../workers/server.worker"),
241
+ {
242
+ env: {
243
+ NODE_ENV: "development",
244
+ TZ: "Asia/Seoul",
245
+ SD_VERSION: npmConf?.version ?? "serverless",
246
+ ...("path" in pkgInfo ? pkgInfo.conf.env : {}),
247
+ },
233
248
  },
234
- });
249
+ );
235
250
  const port = await worker.run("listen", [pkgInfo]);
236
251
  logger.debug("서버가 시작되었습니다.");
237
252
 
@@ -14,7 +14,7 @@ export class SdServerBuildRunner extends EventEmitter {
14
14
  private _extModules?: { name: string; exists: boolean }[];
15
15
  private _watchScopePathSet: Set<TNormPath>;
16
16
 
17
- public constructor(
17
+ constructor(
18
18
  private readonly _projConf: ISdProjectConfig,
19
19
  private readonly _pkgPath: TNormPath,
20
20
  ) {
@@ -29,14 +29,14 @@ export class SdServerBuildRunner extends EventEmitter {
29
29
  );
30
30
  }
31
31
 
32
- public override on(event: "change", listener: () => void): this;
33
- public override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
34
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
32
+ override on(event: "change", listener: () => void): this;
33
+ override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
34
+ override on(event: string | symbol, listener: (...args: any[]) => void): this {
35
35
  super.on(event, listener);
36
36
  return this;
37
37
  }
38
38
 
39
- public async watchAsync(): Promise<void> {
39
+ async watchAsync(): Promise<void> {
40
40
  this.emit("change");
41
41
 
42
42
  this._debug("dist 초기화...");
@@ -79,7 +79,7 @@ export class SdServerBuildRunner extends EventEmitter {
79
79
  });
80
80
  }
81
81
 
82
- public async buildAsync(): Promise<ISdBuildRunnerResult> {
82
+ async buildAsync(): Promise<ISdBuildRunnerResult> {
83
83
  const projNpmConfig = FsUtils.readJson(path.resolve(
84
84
  process.cwd(),
85
85
  "package.json",