@simplysm/sd-cli 12.5.21 → 12.5.23

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 (195) hide show
  1. package/dist/{build-tools → entry}/SdCliCordova.d.ts +5 -6
  2. package/dist/{build-tools → entry}/SdCliCordova.js +117 -99
  3. package/dist/entry/SdCliCordova.js.map +1 -0
  4. package/dist/entry/SdCliElectron.d.ts +2 -2
  5. package/dist/entry/SdCliElectron.js +50 -40
  6. package/dist/entry/SdCliElectron.js.map +1 -1
  7. package/dist/entry/SdCliLocalUpdate.d.ts +1 -2
  8. package/dist/entry/SdCliLocalUpdate.js +26 -27
  9. package/dist/entry/SdCliLocalUpdate.js.map +1 -1
  10. package/dist/entry/SdCliProject.d.ts +1 -5
  11. package/dist/entry/SdCliProject.js +62 -288
  12. package/dist/entry/SdCliProject.js.map +1 -1
  13. package/dist/index.d.ts +23 -20
  14. package/dist/index.js +23 -20
  15. package/dist/index.js.map +1 -1
  16. package/dist/pkg-builders/SdMultiBuildRunner.d.ts +21 -0
  17. package/dist/pkg-builders/SdMultiBuildRunner.js +174 -0
  18. package/dist/pkg-builders/SdMultiBuildRunner.js.map +1 -0
  19. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.d.ts +4 -0
  20. package/dist/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.js +7 -7
  21. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.js.map +1 -0
  22. package/dist/pkg-builders/client/SdClientBuildRunner.d.ts +20 -0
  23. package/dist/pkg-builders/client/SdClientBuildRunner.js +135 -0
  24. package/dist/pkg-builders/client/SdClientBuildRunner.js.map +1 -0
  25. package/dist/pkg-builders/client/SdNgBundler.d.ts +29 -0
  26. package/dist/{build-tools → pkg-builders/client}/SdNgBundler.js +107 -151
  27. package/dist/pkg-builders/client/SdNgBundler.js.map +1 -0
  28. package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.d.ts +1 -2
  29. package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.js +19 -45
  30. package/dist/pkg-builders/client/SdNgBundlerContext.js.map +1 -0
  31. package/dist/pkg-builders/client/createSdNgPlugin.d.ts +10 -0
  32. package/dist/{bundle-plugins/sdNgPlugin.js → pkg-builders/client/createSdNgPlugin.js} +32 -33
  33. package/dist/pkg-builders/client/createSdNgPlugin.js.map +1 -0
  34. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.d.ts +5 -0
  35. package/dist/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.js +11 -11
  36. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js.map +1 -0
  37. package/dist/pkg-builders/lib/SdJsLibBuildRunner.d.ts +16 -0
  38. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js +81 -0
  39. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js.map +1 -0
  40. package/dist/pkg-builders/lib/SdTsLibBuildRunner.d.ts +13 -0
  41. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js +89 -0
  42. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js.map +1 -0
  43. package/dist/pkg-builders/lib/SdTsLibBuilder.d.ts +14 -0
  44. package/dist/pkg-builders/lib/SdTsLibBuilder.js +54 -0
  45. package/dist/pkg-builders/lib/SdTsLibBuilder.js.map +1 -0
  46. package/dist/pkg-builders/server/SdServerBuildRunner.d.ts +17 -0
  47. package/dist/{builders/SdCliServerBuilder.js → pkg-builders/server/SdServerBuildRunner.js} +48 -53
  48. package/dist/pkg-builders/server/SdServerBuildRunner.js.map +1 -0
  49. package/dist/pkg-builders/server/SdServerBundler.d.ts +19 -0
  50. package/dist/{build-tools → pkg-builders/server}/SdServerBundler.js +25 -30
  51. package/dist/pkg-builders/server/SdServerBundler.js.map +1 -0
  52. package/dist/pkg-builders/server/createSdServerPlugin.d.ts +10 -0
  53. package/dist/pkg-builders/server/createSdServerPlugin.js +53 -0
  54. package/dist/pkg-builders/server/createSdServerPlugin.js.map +1 -0
  55. package/dist/sd-cli.js +61 -54
  56. package/dist/sd-cli.js.map +1 -1
  57. package/dist/ts-builder/SdTsCompileWorker.d.ts +9 -0
  58. package/dist/ts-builder/SdTsCompileWorker.js +16 -0
  59. package/dist/ts-builder/SdTsCompileWorker.js.map +1 -0
  60. package/dist/ts-builder/SdTsCompiler.d.ts +7 -0
  61. package/dist/ts-builder/SdTsCompiler.js +557 -0
  62. package/dist/ts-builder/SdTsCompiler.js.map +1 -0
  63. package/dist/types/build-plugin.type.d.ts +14 -0
  64. package/dist/types/build-plugin.type.js +2 -0
  65. package/dist/types/build-plugin.type.js.map +1 -0
  66. package/dist/types/build.type.d.ts +15 -0
  67. package/dist/types/build.type.js +2 -0
  68. package/dist/types/build.type.js.map +1 -0
  69. package/dist/types/common-configs.type.d.ts +22 -0
  70. package/dist/types/common-configs.type.js +2 -0
  71. package/dist/types/common-configs.type.js.map +1 -0
  72. package/dist/types/sd-configs.type.d.ts +99 -0
  73. package/dist/types/sd-configs.type.js +2 -0
  74. package/dist/types/sd-configs.type.js.map +1 -0
  75. package/dist/types/ts-compiler.type.d.ts +29 -0
  76. package/dist/types/ts-compiler.type.js +2 -0
  77. package/dist/types/ts-compiler.type.js.map +1 -0
  78. package/dist/types/workers.type.d.ts +49 -0
  79. package/dist/types/workers.type.js +2 -0
  80. package/dist/types/workers.type.js.map +1 -0
  81. package/dist/utils/SdCliConvertMessageUtil.d.ts +21 -0
  82. package/dist/utils/SdCliConvertMessageUtil.js +137 -0
  83. package/dist/utils/SdCliConvertMessageUtil.js.map +1 -0
  84. package/dist/workers/compile-worker.js +27 -0
  85. package/dist/workers/compile-worker.js.map +1 -0
  86. package/dist/workers/lint-worker.js +36 -0
  87. package/dist/workers/lint-worker.js.map +1 -0
  88. package/dist/workers/server-worker.d.ts +1 -0
  89. package/dist/workers/server-worker.js +49 -0
  90. package/dist/workers/server-worker.js.map +1 -0
  91. package/package.json +8 -11
  92. package/src/entry/SdCliCordova.ts +363 -0
  93. package/src/entry/SdCliElectron.ts +96 -69
  94. package/src/entry/SdCliLocalUpdate.ts +43 -44
  95. package/src/entry/SdCliProject.ts +72 -417
  96. package/src/index.ts +23 -20
  97. package/src/pkg-builders/SdMultiBuildRunner.ts +250 -0
  98. package/src/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.ts +7 -7
  99. package/src/pkg-builders/client/SdClientBuildRunner.ts +191 -0
  100. package/src/{build-tools → pkg-builders/client}/SdNgBundler.ts +135 -190
  101. package/src/pkg-builders/client/SdNgBundlerContext.ts +111 -0
  102. package/src/{bundle-plugins/sdNgPlugin.ts → pkg-builders/client/createSdNgPlugin.ts} +43 -46
  103. package/src/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.ts +11 -11
  104. package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +105 -0
  105. package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +128 -0
  106. package/src/pkg-builders/lib/SdTsLibBuilder.ts +69 -0
  107. package/src/{builders/SdCliServerBuilder.ts → pkg-builders/server/SdServerBuildRunner.ts} +66 -78
  108. package/src/{build-tools → pkg-builders/server}/SdServerBundler.ts +40 -41
  109. package/src/pkg-builders/server/createSdServerPlugin.ts +77 -0
  110. package/src/sd-cli.ts +197 -211
  111. package/src/ts-builder/SdTsCompileWorker.ts +21 -0
  112. package/src/ts-builder/SdTsCompiler.ts +775 -0
  113. package/src/types/build-plugin.type.ts +16 -0
  114. package/src/types/build.type.ts +17 -0
  115. package/src/types/common-configs.type.ts +27 -0
  116. package/src/types/sd-configs.type.ts +114 -0
  117. package/src/types/ts-compiler.type.ts +29 -0
  118. package/src/types/workers.type.ts +27 -0
  119. package/src/utils/SdCliConvertMessageUtil.ts +177 -0
  120. package/src/workers/compile-worker.ts +31 -0
  121. package/src/workers/lint-worker.ts +44 -0
  122. package/src/workers/server-worker.ts +52 -0
  123. package/tsconfig.json +7 -1
  124. package/dist/build-cluster.js +0 -201
  125. package/dist/build-cluster.js.map +0 -1
  126. package/dist/build-tools/SdCliCordova.js.map +0 -1
  127. package/dist/build-tools/SdCliIndexFileGenerator.d.ts +0 -5
  128. package/dist/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  129. package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +0 -4
  130. package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +0 -1
  131. package/dist/build-tools/SdLinter.d.ts +0 -5
  132. package/dist/build-tools/SdLinter.js +0 -49
  133. package/dist/build-tools/SdLinter.js.map +0 -1
  134. package/dist/build-tools/SdNgBundler.d.ts +0 -29
  135. package/dist/build-tools/SdNgBundler.js.map +0 -1
  136. package/dist/build-tools/SdNgBundlerContext.js.map +0 -1
  137. package/dist/build-tools/SdReactBundler.d.ts +0 -25
  138. package/dist/build-tools/SdReactBundler.js +0 -295
  139. package/dist/build-tools/SdReactBundler.js.map +0 -1
  140. package/dist/build-tools/SdReactBundlerContext.d.ts +0 -14
  141. package/dist/build-tools/SdReactBundlerContext.js +0 -59
  142. package/dist/build-tools/SdReactBundlerContext.js.map +0 -1
  143. package/dist/build-tools/SdServerBundler.d.ts +0 -20
  144. package/dist/build-tools/SdServerBundler.js.map +0 -1
  145. package/dist/build-tools/SdTsCompiler.d.ts +0 -34
  146. package/dist/build-tools/SdTsCompiler.js +0 -534
  147. package/dist/build-tools/SdTsCompiler.js.map +0 -1
  148. package/dist/build-tools/SdTsLibBundler.d.ts +0 -13
  149. package/dist/build-tools/SdTsLibBundler.js +0 -58
  150. package/dist/build-tools/SdTsLibBundler.js.map +0 -1
  151. package/dist/builders/SdCliClientBuilder.d.ts +0 -18
  152. package/dist/builders/SdCliClientBuilder.js +0 -172
  153. package/dist/builders/SdCliClientBuilder.js.map +0 -1
  154. package/dist/builders/SdCliJsLibLinter.d.ts +0 -13
  155. package/dist/builders/SdCliJsLibLinter.js +0 -60
  156. package/dist/builders/SdCliJsLibLinter.js.map +0 -1
  157. package/dist/builders/SdCliServerBuilder.d.ts +0 -15
  158. package/dist/builders/SdCliServerBuilder.js.map +0 -1
  159. package/dist/builders/SdCliTsLibBuilder.d.ts +0 -12
  160. package/dist/builders/SdCliTsLibBuilder.js +0 -90
  161. package/dist/builders/SdCliTsLibBuilder.js.map +0 -1
  162. package/dist/bundle-plugins/sdNgPlugin.d.ts +0 -16
  163. package/dist/bundle-plugins/sdNgPlugin.js.map +0 -1
  164. package/dist/bundle-plugins/sdReactPlugin.d.ts +0 -16
  165. package/dist/bundle-plugins/sdReactPlugin.js +0 -117
  166. package/dist/bundle-plugins/sdReactPlugin.js.map +0 -1
  167. package/dist/bundle-plugins/sdServerPlugin.d.ts +0 -16
  168. package/dist/bundle-plugins/sdServerPlugin.js +0 -63
  169. package/dist/bundle-plugins/sdServerPlugin.js.map +0 -1
  170. package/dist/commons.d.ts +0 -145
  171. package/dist/commons.js +0 -2
  172. package/dist/commons.js.map +0 -1
  173. package/dist/server-worker.js +0 -57
  174. package/dist/server-worker.js.map +0 -1
  175. package/dist/utils/SdCliBuildResultUtil.d.ts +0 -16
  176. package/dist/utils/SdCliBuildResultUtil.js +0 -54
  177. package/dist/utils/SdCliBuildResultUtil.js.map +0 -1
  178. package/src/build-cluster.ts +0 -212
  179. package/src/build-tools/SdCliCordova.ts +0 -340
  180. package/src/build-tools/SdLinter.ts +0 -65
  181. package/src/build-tools/SdNgBundlerContext.ts +0 -137
  182. package/src/build-tools/SdReactBundler.ts +0 -372
  183. package/src/build-tools/SdReactBundlerContext.ts +0 -71
  184. package/src/build-tools/SdTsCompiler.ts +0 -754
  185. package/src/build-tools/SdTsLibBundler.ts +0 -72
  186. package/src/builders/SdCliClientBuilder.ts +0 -233
  187. package/src/builders/SdCliJsLibLinter.ts +0 -72
  188. package/src/builders/SdCliTsLibBuilder.ts +0 -126
  189. package/src/bundle-plugins/sdReactPlugin.ts +0 -164
  190. package/src/bundle-plugins/sdServerPlugin.ts +0 -94
  191. package/src/commons.ts +0 -171
  192. package/src/server-worker.ts +0 -65
  193. package/src/utils/SdCliBuildResultUtil.ts +0 -63
  194. /package/dist/{build-cluster.d.ts → workers/compile-worker.d.ts} +0 -0
  195. /package/dist/{server-worker.d.ts → workers/lint-worker.d.ts} +0 -0
@@ -1,34 +1,28 @@
1
1
  import { EventEmitter } from "events";
2
- import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
3
- import {
4
- INpmConfig,
5
- ISdCliBuilderResult,
6
- ISdCliConfig,
7
- ISdCliPackageBuildResult,
8
- ISdCliServerPackageConfig,
9
- ITsConfig,
10
- } from "../commons";
2
+ import { FsUtil, Logger, PathUtil, SdFsWatcher, TNormPath } from "@simplysm/sd-core-node";
11
3
  import path from "path";
12
- import { SdLinter } from "../build-tools/SdLinter";
13
- import { FunctionQueue, ObjectUtil, StringUtil } from "@simplysm/sd-core-common";
14
- import { SdServerBundler } from "../build-tools/SdServerBundler";
15
-
16
- export class SdCliServerBuilder extends EventEmitter {
17
- #logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuilder"]);
18
- #pkgConf: ISdCliServerPackageConfig;
19
- #builder?: SdServerBundler;
4
+ import { ObjectUtil, StringUtil } from "@simplysm/sd-core-common";
5
+ import { SdServerBundler } from "./SdServerBundler";
6
+ import { ISdProjectConfig, ISdServerPackageConfig } from "../../types/sd-configs.type";
7
+ import { ISdBuildMessage, ISdBuildRunnerResult } from "../../types/build.type";
8
+ import { INpmConfig, ITsConfig } from "../../types/common-configs.type";
9
+
10
+ export class SdServerBuildRunner extends EventEmitter {
11
+ #logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuildRunner"]);
12
+ #pkgConf: ISdServerPackageConfig;
13
+ #serverBundler?: SdServerBundler;
20
14
  #extModules?: { name: string; exists: boolean }[];
21
15
 
22
16
  public constructor(
23
- private readonly _projConf: ISdCliConfig,
24
- private readonly _pkgPath: string,
17
+ private readonly _projConf: ISdProjectConfig,
18
+ private readonly _pkgPath: TNormPath,
25
19
  ) {
26
20
  super();
27
- this.#pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdCliServerPackageConfig;
21
+ this.#pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdServerPackageConfig;
28
22
  }
29
23
 
30
24
  public override on(event: "change", listener: () => void): this;
31
- public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
25
+ public override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
32
26
  public override on(event: string | symbol, listener: (...args: any[]) => void): this {
33
27
  super.on(event, listener);
34
28
  return this;
@@ -38,53 +32,47 @@ export class SdCliServerBuilder extends EventEmitter {
38
32
  this.emit("change");
39
33
 
40
34
  this._debug("dist 초기화...");
41
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
35
+ FsUtil.remove(path.resolve(this._pkgPath, "dist"));
42
36
 
43
37
  this._debug("GEN .config...");
44
38
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
45
- await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this.#pkgConf.configs ?? {}, undefined, 2));
39
+ FsUtil.writeFile(confDistPath, JSON.stringify(this.#pkgConf.configs ?? {}, undefined, 2));
46
40
 
47
- const result = await this._runAsync({ dev: true });
48
- this.emit("complete", {
49
- affectedFilePaths: Array.from(result.affectedFileSet),
50
- buildResults: result.buildResults,
51
- });
41
+ const result = await this._runAsync(true);
42
+ const res: ISdBuildRunnerResult = {
43
+ affectedFilePathSet: result.affectedFileSet,
44
+ buildMessages: result.buildMessages,
45
+ emitFileSet: result.emitFileSet,
46
+ };
47
+ this.emit("complete", res);
52
48
 
53
49
  this._debug("WATCH...");
54
- let changeFiles: string[] = [];
55
- const fnQ = new FunctionQueue();
56
- const watcher = SdFsWatcher.watch(Array.from(result.watchFileSet)).onChange({ delay: 100 }, (changeInfos) => {
57
- changeFiles.push(...changeInfos.map((item) => item.path));
58
-
59
- fnQ.runLast(async () => {
60
- const currChangeFiles = [...changeFiles];
61
- changeFiles = [];
62
-
63
- this.emit("change");
64
-
65
- this.#builder!.markForChanges(currChangeFiles);
50
+ const watcher = SdFsWatcher.watch(Array.from(result.watchFileSet)).onChange({ delay: 100 }, async (changeInfos) => {
51
+ this.emit("change");
52
+
53
+ const watchResult = await this._runAsync(true, new Set(changeInfos.map((item) => PathUtil.norm(item.path))));
54
+ const watchRes: ISdBuildRunnerResult = {
55
+ affectedFilePathSet: watchResult.affectedFileSet,
56
+ buildMessages: watchResult.buildMessages,
57
+ emitFileSet: watchResult.emitFileSet,
58
+ };
66
59
 
67
- const watchResult = await this._runAsync({ dev: true });
68
- this.emit("complete", {
69
- affectedFilePaths: Array.from(watchResult.affectedFileSet),
70
- buildResults: watchResult.buildResults,
71
- });
60
+ this.emit("complete", watchRes);
72
61
 
73
- watcher.add(watchResult.watchFileSet);
74
- });
62
+ watcher.replaceWatchPaths(watchResult.watchFileSet);
75
63
  });
76
64
  }
77
65
 
78
- public async buildAsync(): Promise<ISdCliBuilderResult> {
79
- const npmConfig = (await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "package.json"))) as INpmConfig;
66
+ public async buildAsync(): Promise<ISdBuildRunnerResult> {
67
+ const npmConfig = FsUtil.readJson(path.resolve(this._pkgPath, "package.json")) as INpmConfig;
80
68
  const extModules = await this._getExternalModulesAsync();
81
69
 
82
70
  this._debug("dist 초기화...");
83
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
71
+ FsUtil.remove(path.resolve(this._pkgPath, "dist"));
84
72
 
85
73
  this._debug("GEN .config.json...");
86
74
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
87
- await FsUtil.writeJsonAsync(confDistPath, this.#pkgConf.configs ?? {}, { space: 2 });
75
+ FsUtil.writeJson(confDistPath, this.#pkgConf.configs ?? {}, { space: 2 });
88
76
 
89
77
  this._debug("GEN package.json...");
90
78
  {
@@ -103,12 +91,12 @@ export class SdCliServerBuilder extends EventEmitter {
103
91
  distNpmConfig.scripts = { start: "pm2 start pm2.json" };
104
92
  }
105
93
 
106
- await FsUtil.writeJsonAsync(path.resolve(this._pkgPath, "dist/package.json"), distNpmConfig, { space: 2 });
94
+ FsUtil.writeJson(path.resolve(this._pkgPath, "dist/package.json"), distNpmConfig, { space: 2 });
107
95
  }
108
96
 
109
97
  this._debug("GEN openssl.cnf...");
110
98
  {
111
- await FsUtil.writeFileAsync(
99
+ FsUtil.writeFile(
112
100
  path.resolve(this._pkgPath, "dist/openssl.cnf"),
113
101
  `
114
102
  nodejs_conf = openssl_init
@@ -138,7 +126,7 @@ Options = UnsafeLegacyRenegotiation`.trim(),
138
126
  if (this.#pkgConf.pm2) {
139
127
  this._debug("GEN pm2.json...");
140
128
 
141
- await FsUtil.writeJsonAsync(
129
+ FsUtil.writeJson(
142
130
  path.resolve(this._pkgPath, "dist/pm2.json"),
143
131
  {
144
132
  name: this.#pkgConf.pm2.name ?? npmConfig.name.replace(/@/g, "").replace(/\//g, "-"),
@@ -172,7 +160,7 @@ Options = UnsafeLegacyRenegotiation`.trim(),
172
160
 
173
161
  const iisDistPath = path.resolve(this._pkgPath, "dist/web.config");
174
162
  const serverExeFilePath = this.#pkgConf.iis.nodeExeFilePath ?? "C:\\Program Files\\nodejs\\node.exe";
175
- await FsUtil.writeFileAsync(
163
+ FsUtil.writeFile(
176
164
  iisDistPath,
177
165
  `
178
166
  <configuration>
@@ -207,17 +195,22 @@ Options = UnsafeLegacyRenegotiation`.trim(),
207
195
  );
208
196
  }
209
197
 
210
- const result = await this._runAsync({ dev: false });
198
+ const result = await this._runAsync(false);
211
199
  return {
212
- affectedFilePaths: Array.from(result.affectedFileSet),
213
- buildResults: result.buildResults,
200
+ affectedFilePathSet: result.affectedFileSet,
201
+ buildMessages: result.buildMessages,
202
+ emitFileSet: result.emitFileSet,
214
203
  };
215
204
  }
216
205
 
217
- private async _runAsync(opt: { dev: boolean }): Promise<{
218
- watchFileSet: Set<string>;
219
- affectedFileSet: Set<string>;
220
- buildResults: ISdCliPackageBuildResult[];
206
+ private async _runAsync(
207
+ dev: boolean,
208
+ modifiedFileSet?: Set<TNormPath>,
209
+ ): Promise<{
210
+ watchFileSet: Set<TNormPath>;
211
+ affectedFileSet: Set<TNormPath>;
212
+ buildMessages: ISdBuildMessage[];
213
+ emitFileSet: Set<TNormPath>;
221
214
  }> {
222
215
  const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
223
216
  FsUtil.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
@@ -226,38 +219,36 @@ Options = UnsafeLegacyRenegotiation`.trim(),
226
219
  this._debug(`BUILD 준비...`);
227
220
  const tsConfig = FsUtil.readJson(path.resolve(this._pkgPath, "tsconfig.json")) as ITsConfig;
228
221
  this.#extModules = this.#extModules ?? (await this._getExternalModulesAsync());
229
- this.#builder =
230
- this.#builder ??
222
+ this.#serverBundler =
223
+ this.#serverBundler ??
231
224
  new SdServerBundler({
232
- dev: opt.dev,
225
+ dev,
233
226
  pkgPath: this._pkgPath,
234
227
  entryPoints: tsConfig.files
235
228
  ? tsConfig.files.map((item) => path.resolve(this._pkgPath, item))
236
229
  : [path.resolve(this._pkgPath, "src/main.ts")],
237
230
  external: this.#extModules.map((item) => item.name),
238
- watchScopePaths: [path.resolve(this._pkgPath, "../"), ...localUpdatePaths],
231
+ watchScopePaths: [path.resolve(this._pkgPath, "../"), ...localUpdatePaths].map((item) => PathUtil.norm(item)),
239
232
  });
240
233
 
241
- this._debug(`BUILD & CHECK...`);
242
- const buildResult = await this.#builder.bundleAsync();
234
+ this._debug(`BUILD...`);
235
+ const bundleResult = await this.#serverBundler.bundleAsync(modifiedFileSet);
243
236
 
244
237
  //-- filePaths
245
238
  const watchFileSet = new Set(
246
- Array.from(buildResult.watchFileSet).filter(
239
+ Array.from(bundleResult.watchFileSet).filter(
247
240
  (item) =>
248
241
  PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
249
242
  localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu)),
250
243
  ),
251
244
  );
252
245
 
253
- this._debug(`LINT...`);
254
- const lintResults = await SdLinter.lintAsync(this._pkgPath, buildResult.affectedFileSet, buildResult.program);
255
-
256
246
  this._debug(`빌드 완료`);
257
247
  return {
258
248
  watchFileSet,
259
- affectedFileSet: buildResult.affectedFileSet,
260
- buildResults: [...buildResult.results, ...lintResults],
249
+ affectedFileSet: bundleResult.affectedFileSet,
250
+ buildMessages: bundleResult.results,
251
+ emitFileSet: bundleResult.emitFileSet,
261
252
  };
262
253
  }
263
254
 
@@ -276,10 +267,7 @@ Options = UnsafeLegacyRenegotiation`.trim(),
276
267
  const npmConfigMap = new Map<string, INpmConfig>();
277
268
 
278
269
  const fn = async (currPath: string): Promise<void> => {
279
- const npmConfig = npmConfigMap.getOrCreate(
280
- currPath,
281
- await FsUtil.readJsonAsync(path.resolve(currPath, "package.json")),
282
- );
270
+ const npmConfig = npmConfigMap.getOrCreate(currPath, FsUtil.readJson(path.resolve(currPath, "package.json")));
283
271
 
284
272
  const deps = {
285
273
  defaults: [
@@ -1,40 +1,44 @@
1
- import { ISdCliPackageBuildResult } from "../commons";
2
1
  import esbuild from "esbuild";
3
2
  import path from "path";
4
- import { IServerPluginResultCache, sdServerPlugin } from "../bundle-plugins/sdServerPlugin";
5
- import ts from "typescript";
6
- import { Logger } from "@simplysm/sd-core-node";
3
+ import { FsUtil, Logger, PathUtil, TNormPath } from "@simplysm/sd-core-node";
4
+ import { SdCliConvertMessageUtil } from "../../utils/SdCliConvertMessageUtil";
5
+ import { ISdCliServerPluginResultCache } from "../../types/build-plugin.type";
6
+ import { ISdBuildMessage } from "../../types/build.type";
7
+ import { createSdServerPlugin } from "./createSdServerPlugin";
8
+ import { BuildOutputFile, BuildOutputFileType } from "@angular/build/src/tools/esbuild/bundler-context";
9
+ import { convertOutputFile } from "@angular/build/src/tools/esbuild/utils";
7
10
 
8
11
  export class SdServerBundler {
9
12
  readonly #logger = Logger.get(["simplysm", "sd-cli", "SdServerBundler"]);
10
13
 
11
14
  #context?: esbuild.BuildContext;
12
15
 
13
- #modifiedFileSet = new Set<string>();
14
- #resultCache: IServerPluginResultCache = {};
16
+ readonly #modifiedFileSet = new Set<TNormPath>();
17
+ readonly #resultCache: ISdCliServerPluginResultCache = {};
18
+
19
+ readonly #outputCache = new Map<TNormPath, string | number>();
15
20
 
16
21
  constructor(
17
22
  private readonly _opt: {
18
23
  dev: boolean;
19
- pkgPath: string;
24
+ pkgPath: TNormPath;
20
25
  entryPoints: string[];
21
26
  external?: string[];
22
- watchScopePaths: string[];
27
+ watchScopePaths: TNormPath[];
23
28
  },
24
29
  ) {}
25
30
 
26
- public markForChanges(filePaths: string[]): void {
27
- for (const filePath of filePaths) {
28
- this.#modifiedFileSet.add(path.normalize(filePath));
31
+ async bundleAsync(modifiedFileSet?: Set<TNormPath>): Promise<{
32
+ watchFileSet: Set<TNormPath>;
33
+ affectedFileSet: Set<TNormPath>;
34
+ results: ISdBuildMessage[];
35
+ emitFileSet: Set<TNormPath>;
36
+ }> {
37
+ this.#modifiedFileSet.clear();
38
+ if (modifiedFileSet) {
39
+ this.#modifiedFileSet.adds(...modifiedFileSet);
29
40
  }
30
- }
31
41
 
32
- async bundleAsync(): Promise<{
33
- program: ts.Program;
34
- watchFileSet: Set<string>;
35
- affectedFileSet: Set<string>;
36
- results: ISdCliPackageBuildResult[];
37
- }> {
38
42
  if (!this.#context) {
39
43
  this.#context = await esbuild.context({
40
44
  entryPoints: this._opt.entryPoints,
@@ -45,7 +49,7 @@ export class SdServerBundler {
45
49
  mainFields: ["es2020", "es2015", "module", "main"],
46
50
  conditions: ["es2020", "es2015", "module"],
47
51
  tsconfig: path.resolve(this._opt.pkgPath, "tsconfig.json"),
48
- write: true,
52
+ write: false,
49
53
  metafile: true,
50
54
  outdir: path.resolve(this._opt.pkgPath, "dist"),
51
55
  format: "esm",
@@ -92,7 +96,7 @@ const __filename = __fileURLToPath__(import.meta.url);
92
96
  const __dirname = __path__.dirname(__filename);`.trim(),
93
97
  },
94
98
  plugins: [
95
- sdServerPlugin({
99
+ createSdServerPlugin({
96
100
  modifiedFileSet: this.#modifiedFileSet,
97
101
  dev: this._opt.dev,
98
102
  pkgPath: this._opt.pkgPath,
@@ -103,9 +107,23 @@ const __dirname = __path__.dirname(__filename);`.trim(),
103
107
  });
104
108
  }
105
109
 
110
+ const emitFileSet = new Set<TNormPath>();
106
111
  let result: esbuild.BuildResult | esbuild.BuildFailure;
107
112
  try {
108
113
  result = await this.#context.rebuild();
114
+
115
+ const outputFiles: BuildOutputFile[] =
116
+ result.outputFiles?.map((file) => convertOutputFile(file, BuildOutputFileType.Root)) ?? [];
117
+
118
+ for (const outputFile of outputFiles) {
119
+ const distFilePath = PathUtil.norm(this._opt.pkgPath, outputFile.path);
120
+ const prev = this.#outputCache.get(distFilePath);
121
+ if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
122
+ FsUtil.writeFile(distFilePath, outputFile.contents);
123
+ this.#outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
124
+ emitFileSet.add(distFilePath);
125
+ }
126
+ }
109
127
  } catch (err) {
110
128
  result = err;
111
129
  for (const e of err.errors) {
@@ -116,29 +134,10 @@ const __dirname = __path__.dirname(__filename);`.trim(),
116
134
  }
117
135
 
118
136
  return {
119
- program: this.#resultCache.program!,
120
137
  watchFileSet: this.#resultCache.watchFileSet!,
121
138
  affectedFileSet: this.#resultCache.affectedFileSet!,
122
- results: [
123
- ...result.warnings.map((warn) => ({
124
- type: "build" as const,
125
- filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
126
- line: warn.location?.line,
127
- char: warn.location?.column,
128
- code: warn.text.slice(0, warn.text.indexOf(":")),
129
- severity: "warning" as const,
130
- message: `(${warn.pluginName}) ${warn.text.slice(warn.text.indexOf(":") + 1)}`,
131
- })),
132
- ...result.errors.map((err) => ({
133
- type: "build" as const,
134
- filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
135
- line: err.location?.line,
136
- char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
137
- code: err.text.slice(0, err.text.indexOf(":")),
138
- severity: "error" as const,
139
- message: `(${err.pluginName}) ${err.text.slice(err.text.indexOf(":") + 1)}`,
140
- })),
141
- ],
139
+ results: SdCliConvertMessageUtil.convertToBuildMessagesFromEsbuild(result, this._opt.pkgPath),
140
+ emitFileSet: emitFileSet,
142
141
  };
143
142
  }
144
143
  }
@@ -0,0 +1,77 @@
1
+ import esbuild from "esbuild";
2
+ import { SdCliConvertMessageUtil } from "../../utils/SdCliConvertMessageUtil";
3
+ import { ISdCliServerPluginResultCache } from "../../types/build-plugin.type";
4
+ import { PathUtil, TNormPath } from "@simplysm/sd-core-node";
5
+ import { SdTsCompileWorker } from "../../ts-builder/SdTsCompileWorker";
6
+ import { ISdTsCompilerResult } from "../../types/ts-compiler.type";
7
+
8
+ export function createSdServerPlugin(conf: {
9
+ pkgPath: TNormPath;
10
+ dev: boolean;
11
+ modifiedFileSet: Set<TNormPath>;
12
+ result: ISdCliServerPluginResultCache;
13
+ watchScopePaths: TNormPath[];
14
+ }): esbuild.Plugin {
15
+ return {
16
+ name: "sd-server-compile",
17
+ setup: async (build: esbuild.PluginBuild) => {
18
+ const tsCompiler = await SdTsCompileWorker.new({
19
+ pkgPath: conf.pkgPath,
20
+ additionalOptions: { declaration: false },
21
+ isDevMode: conf.dev,
22
+ isForBundle: true,
23
+ watchScopePaths: conf.watchScopePaths,
24
+ });
25
+
26
+ let tsCompileResult: ISdTsCompilerResult;
27
+
28
+ build.onStart(async () => {
29
+ tsCompileResult = await tsCompiler.compileAsync(conf.modifiedFileSet);
30
+
31
+ conf.result.watchFileSet = tsCompileResult.watchFileSet;
32
+ conf.result.affectedFileSet = tsCompileResult.affectedFileSet;
33
+
34
+ //-- return err/warn
35
+ return SdCliConvertMessageUtil.convertToEsbuildFromBuildMessages(tsCompileResult.messages, conf.pkgPath);
36
+ });
37
+
38
+ build.onLoad({ filter: /\.ts$/ }, (args) => {
39
+ const emittedJsFile = tsCompileResult.emittedFilesCacheMap.get(PathUtil.norm(args.path))?.last();
40
+ if (!emittedJsFile) {
41
+ throw new Error(`ts 빌더 결과 emit 파일이 존재하지 않습니다. ${args.path}`);
42
+ }
43
+
44
+ const contents = emittedJsFile.text;
45
+ return { contents, loader: "js" };
46
+ });
47
+
48
+ build.onLoad({ filter: /\.[cm]?js$/ }, (args) => {
49
+ conf.result.watchFileSet!.add(PathUtil.norm(args.path));
50
+ return null;
51
+ });
52
+
53
+ build.onLoad(
54
+ {
55
+ filter: new RegExp(
56
+ "(" +
57
+ Object.keys(build.initialOptions.loader!)
58
+ .map((item) => "\\" + item)
59
+ .join("|") +
60
+ ")$",
61
+ ),
62
+ },
63
+ (args) => {
64
+ conf.result.watchFileSet!.add(PathUtil.norm(args.path));
65
+ return null;
66
+ },
67
+ );
68
+
69
+ build.onEnd((result) => {
70
+ conf.result.outputFiles = result.outputFiles;
71
+ conf.result.metafile = result.metafile;
72
+
73
+ conf.modifiedFileSet.clear();
74
+ });
75
+ },
76
+ };
77
+ }