@simplysm/sd-cli 12.5.21 → 12.5.22

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 +100 -95
  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/{build-tools → ts-builder}/SdTsCompiler.js +226 -212
  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/lib/dev-worker.cjs +5 -0
  92. package/package.json +7 -10
  93. package/src/entry/SdCliCordova.ts +363 -0
  94. package/src/entry/SdCliElectron.ts +96 -69
  95. package/src/entry/SdCliLocalUpdate.ts +43 -44
  96. package/src/entry/SdCliProject.ts +72 -417
  97. package/src/index.ts +23 -20
  98. package/src/pkg-builders/SdMultiBuildRunner.ts +250 -0
  99. package/src/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.ts +7 -7
  100. package/src/pkg-builders/client/SdClientBuildRunner.ts +191 -0
  101. package/src/{build-tools → pkg-builders/client}/SdNgBundler.ts +125 -121
  102. package/src/pkg-builders/client/SdNgBundlerContext.ts +111 -0
  103. package/src/{bundle-plugins/sdNgPlugin.ts → pkg-builders/client/createSdNgPlugin.ts} +43 -46
  104. package/src/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.ts +11 -11
  105. package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +105 -0
  106. package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +128 -0
  107. package/src/pkg-builders/lib/SdTsLibBuilder.ts +69 -0
  108. package/src/{builders/SdCliServerBuilder.ts → pkg-builders/server/SdServerBuildRunner.ts} +66 -78
  109. package/src/{build-tools → pkg-builders/server}/SdServerBundler.ts +40 -41
  110. package/src/pkg-builders/server/createSdServerPlugin.ts +77 -0
  111. package/src/sd-cli.ts +197 -211
  112. package/src/ts-builder/SdTsCompileWorker.ts +21 -0
  113. package/src/ts-builder/SdTsCompiler.ts +758 -0
  114. package/src/types/build-plugin.type.ts +16 -0
  115. package/src/types/build.type.ts +17 -0
  116. package/src/types/common-configs.type.ts +27 -0
  117. package/src/types/sd-configs.type.ts +114 -0
  118. package/src/types/ts-compiler.type.ts +29 -0
  119. package/src/types/workers.type.ts +27 -0
  120. package/src/utils/SdCliConvertMessageUtil.ts +177 -0
  121. package/src/workers/compile-worker.ts +31 -0
  122. package/src/workers/lint-worker.ts +44 -0
  123. package/src/workers/server-worker.ts +52 -0
  124. package/tsconfig.json +7 -1
  125. package/dist/build-cluster.js +0 -201
  126. package/dist/build-cluster.js.map +0 -1
  127. package/dist/build-tools/SdCliCordova.js.map +0 -1
  128. package/dist/build-tools/SdCliIndexFileGenerator.d.ts +0 -5
  129. package/dist/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  130. package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +0 -4
  131. package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +0 -1
  132. package/dist/build-tools/SdLinter.d.ts +0 -5
  133. package/dist/build-tools/SdLinter.js +0 -49
  134. package/dist/build-tools/SdLinter.js.map +0 -1
  135. package/dist/build-tools/SdNgBundler.d.ts +0 -29
  136. package/dist/build-tools/SdNgBundler.js.map +0 -1
  137. package/dist/build-tools/SdNgBundlerContext.js.map +0 -1
  138. package/dist/build-tools/SdReactBundler.d.ts +0 -25
  139. package/dist/build-tools/SdReactBundler.js +0 -295
  140. package/dist/build-tools/SdReactBundler.js.map +0 -1
  141. package/dist/build-tools/SdReactBundlerContext.d.ts +0 -14
  142. package/dist/build-tools/SdReactBundlerContext.js +0 -59
  143. package/dist/build-tools/SdReactBundlerContext.js.map +0 -1
  144. package/dist/build-tools/SdServerBundler.d.ts +0 -20
  145. package/dist/build-tools/SdServerBundler.js.map +0 -1
  146. package/dist/build-tools/SdTsCompiler.d.ts +0 -34
  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,6 +1,6 @@
1
- import ts, { DiagnosticCategory } from "typescript";
1
+ import ts from "typescript";
2
2
  import path from "path";
3
- import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
3
+ import { FsUtil, Logger, PathUtil, SdWorker } from "@simplysm/sd-core-node";
4
4
  import { StringUtil } from "@simplysm/sd-core-common";
5
5
  import { NgtscProgram, OptimizeFor } from "@angular/compiler-cli";
6
6
  import { ComponentStylesheetBundler } from "@angular/build/src/tools/esbuild/angular/component-stylesheets";
@@ -8,6 +8,7 @@ import { transformSupportedBrowsersToTargets } from "@angular/build/src/tools/es
8
8
  import browserslist from "browserslist";
9
9
  import { replaceBootstrap } from "@angular/build/src/tools/angular/transformers/jit-bootstrap-transformer";
10
10
  import { SdCliPerformanceTimer } from "../utils/SdCliPerformanceTime";
11
+ import { SdCliConvertMessageUtil } from "../utils/SdCliConvertMessageUtil";
11
12
  export class SdTsCompiler {
12
13
  #logger = Logger.get(["simplysm", "sd-cli", "SdTsCompiler"]);
13
14
  #parsedTsconfig;
@@ -21,6 +22,7 @@ export class SdTsCompiler {
21
22
  #ngProgram;
22
23
  #program;
23
24
  #modifiedFileSet = new Set();
25
+ #affectedFileSet = new Set();
24
26
  #watchFileSet = new Set();
25
27
  #stylesheetBundlingResultMap = new Map();
26
28
  #pkgPath;
@@ -28,9 +30,10 @@ export class SdTsCompiler {
28
30
  #globalStyleFilePath;
29
31
  #watchScopePaths;
30
32
  #isForBundle;
33
+ #lintWorker = new SdWorker(import.meta.resolve("../workers/lint-worker"));
31
34
  constructor(opt) {
32
35
  this.#pkgPath = opt.pkgPath;
33
- this.#globalStyleFilePath = opt.globalStyleFilePath != null ? path.normalize(opt.globalStyleFilePath) : undefined;
36
+ this.#globalStyleFilePath = opt.globalStyleFilePath;
34
37
  this.#isForBundle = opt.isForBundle;
35
38
  this.#watchScopePaths = opt.watchScopePaths;
36
39
  this.#debug("초기화...");
@@ -42,26 +45,26 @@ export class SdTsCompiler {
42
45
  ...tsconfig.angularCompilerOptions,
43
46
  ...opt.additionalOptions,
44
47
  });
45
- this.#distPath = this.#parsedTsconfig.options.outDir ?? path.resolve(opt.pkgPath, "dist");
48
+ this.#distPath = PathUtil.norm(this.#parsedTsconfig.options.outDir ?? path.resolve(opt.pkgPath, "dist"));
46
49
  //-- compilerHost
47
50
  this.#compilerHost = ts.createCompilerHost(this.#parsedTsconfig.options);
48
51
  const baseGetSourceFile = this.#compilerHost.getSourceFile;
49
52
  this.#compilerHost.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile, ...args) => {
50
- if (!shouldCreateNewSourceFile && this.#sourceFileCacheMap.has(path.normalize(fileName))) {
51
- return this.#sourceFileCacheMap.get(path.normalize(fileName));
53
+ if (!shouldCreateNewSourceFile && this.#sourceFileCacheMap.has(PathUtil.norm(fileName))) {
54
+ return this.#sourceFileCacheMap.get(PathUtil.norm(fileName));
52
55
  }
53
56
  const sf = baseGetSourceFile.call(this.#compilerHost, fileName, languageVersionOrOptions, onError, true, ...args);
54
57
  if (sf) {
55
- this.#sourceFileCacheMap.set(path.normalize(fileName), sf);
58
+ this.#sourceFileCacheMap.set(PathUtil.norm(fileName), sf);
56
59
  }
57
60
  else {
58
- this.#sourceFileCacheMap.delete(path.normalize(fileName));
61
+ this.#sourceFileCacheMap.delete(PathUtil.norm(fileName));
59
62
  }
60
63
  return sf;
61
64
  };
62
65
  const baseReadFile = this.#compilerHost.readFile;
63
66
  this.#compilerHost.readFile = (fileName) => {
64
- this.#watchFileSet.add(path.normalize(fileName));
67
+ this.#watchFileSet.add(PathUtil.norm(fileName));
65
68
  return baseReadFile.call(this.#compilerHost, fileName);
66
69
  };
67
70
  if (this.#isForAngular) {
@@ -94,7 +97,7 @@ export class SdTsCompiler {
94
97
  if (context.type !== "style") {
95
98
  return null;
96
99
  }
97
- const contents = await this.#bundleStylesheetAsync(data, context.containingFile, context.resourceFile);
100
+ const contents = await this.#bundleStylesheetAsync(data, PathUtil.norm(context.containingFile), context.resourceFile != null ? PathUtil.norm(context.resourceFile) : undefined);
98
101
  return StringUtil.isNullOrEmpty(contents) ? null : { content: contents };
99
102
  };
100
103
  this.#compilerHost.getModifiedResourceFiles = () => {
@@ -112,12 +115,12 @@ export class SdTsCompiler {
112
115
  : await this.#stylesheetBundler.bundleInline(data, containingFile, "scss");
113
116
  if (stylesheetResult.referencedFiles) {
114
117
  for (const referencedFile of stylesheetResult.referencedFiles) {
115
- const depCacheSet = this.#resourceDependencyCacheMap.getOrCreate(path.normalize(referencedFile), new Set());
116
- depCacheSet.add(path.normalize(resourceFile ?? containingFile));
118
+ const depCacheSet = this.#resourceDependencyCacheMap.getOrCreate(PathUtil.norm(referencedFile), new Set());
119
+ depCacheSet.add(resourceFile ?? containingFile);
117
120
  }
118
- this.#watchFileSet.adds(...Array.from(stylesheetResult.referencedFiles.values()).map((item) => path.normalize(item)));
121
+ this.#watchFileSet.adds(...Array.from(stylesheetResult.referencedFiles.values()).map((item) => PathUtil.norm(item)));
119
122
  }
120
- this.#stylesheetBundlingResultMap.set(path.normalize(resourceFile ?? containingFile), {
123
+ this.#stylesheetBundlingResultMap.set(PathUtil.norm(resourceFile ?? containingFile), {
121
124
  outputFiles: stylesheetResult.outputFiles,
122
125
  metafile: stylesheetResult.metafile,
123
126
  errors: stylesheetResult.errors,
@@ -125,29 +128,26 @@ export class SdTsCompiler {
125
128
  });
126
129
  return stylesheetResult.contents;
127
130
  }
128
- invalidate(modifiedFileSet) {
129
- this.#modifiedFileSet.adds(...Array.from(modifiedFileSet).map((item) => path.normalize(item)));
130
- }
131
- async buildAsync() {
132
- let perf = new SdCliPerformanceTimer("esbuild");
133
- const affectedFileSet = new Set();
134
- const emitFileSet = new Set();
131
+ async compileAsync(modifiedFileSet) {
132
+ let perf = new SdCliPerformanceTimer("esbuild compile");
133
+ this.#modifiedFileSet = modifiedFileSet ?? new Set();
134
+ this.#affectedFileSet = new Set();
135
135
  this.#debug(`get affected (old deps & old res deps)...`);
136
136
  perf.run("get affected", () => {
137
137
  for (const modifiedFile of this.#modifiedFileSet) {
138
- affectedFileSet.add(modifiedFile);
139
- affectedFileSet.adds(...(this.#revDependencyCacheMap.get(modifiedFile) ?? []));
140
- affectedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
141
- this.#emittedFilesCacheMap.delete(path.normalize(modifiedFile));
138
+ this.#affectedFileSet.add(modifiedFile);
139
+ this.#affectedFileSet.adds(...(this.#revDependencyCacheMap.get(modifiedFile) ?? []));
140
+ this.#affectedFileSet.adds(...(this.#resourceDependencyCacheMap.get(modifiedFile) ?? []));
141
+ this.#emittedFilesCacheMap.delete(modifiedFile);
142
142
  }
143
143
  });
144
144
  this.#debug(`invalidate & clear cache...`);
145
145
  perf.run("invalidate & clear cache", () => {
146
146
  this.#stylesheetBundler?.invalidate(this.#modifiedFileSet);
147
- for (const affectedFile of affectedFileSet) {
148
- this.#sourceFileCacheMap.delete(path.normalize(affectedFile));
149
- this.#stylesheetBundlingResultMap.delete(path.normalize(affectedFile));
150
- this.#watchFileSet.delete(path.normalize(affectedFile));
147
+ for (const affectedFile of this.#affectedFileSet) {
148
+ this.#sourceFileCacheMap.delete(affectedFile);
149
+ this.#stylesheetBundlingResultMap.delete(affectedFile);
150
+ this.#watchFileSet.delete(affectedFile);
151
151
  }
152
152
  this.#revDependencyCacheMap.clear();
153
153
  this.#resourceDependencyCacheMap.clear();
@@ -162,18 +162,6 @@ export class SdTsCompiler {
162
162
  this.#program = ts.createProgram(this.#parsedTsconfig.fileNames, this.#parsedTsconfig.options, this.#compilerHost, this.#program);
163
163
  }
164
164
  });
165
- /*const baseGetSourceFiles = this.#program.getSourceFiles;
166
- this.#program.getSourceFiles = function (...parameters) {
167
- const files: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(...parameters);
168
-
169
- for (const file of files) {
170
- if (file.version === undefined) {
171
- file.version = createHash("sha256").update(file.text).digest("hex");
172
- }
173
- }
174
-
175
- return files;
176
- };*/
177
165
  if (this.#ngProgram) {
178
166
  await perf.run("ng analyze", async () => {
179
167
  await this.#ngProgram.compiler.analyzeAsync();
@@ -187,7 +175,7 @@ export class SdTsCompiler {
187
175
  return sf;
188
176
  };
189
177
  this.#debug(`get affected (new deps)...`);
190
- const diagnostics = [];
178
+ const messages = [];
191
179
  perf.run("get affected (deps)", () => {
192
180
  const sourceFileSet = new Set(this.#program.getSourceFiles()
193
181
  .map((sf) => getOrgSourceFile(sf))
@@ -198,8 +186,8 @@ export class SdTsCompiler {
198
186
  continue;
199
187
  }
200
188
  const refs = this.#findDeps(sf);
201
- diagnostics.push(...refs.filter((item) => "category" in item));
202
- depMap.set(path.normalize(sf.fileName), refs
189
+ messages.push(...refs.filter((item) => "severity" in item));
190
+ depMap.set(PathUtil.norm(sf.fileName), refs
203
191
  .filter((item) => "fileName" in item)
204
192
  .filter((item) => this.#watchScopePaths.some((scopePath) => PathUtil.isChildPath(item.fileName, scopePath))));
205
193
  }
@@ -233,13 +221,18 @@ export class SdTsCompiler {
233
221
  return result;
234
222
  };
235
223
  for (const sf of sourceFileSet) {
236
- const deps = getAllDeps(path.normalize(sf.fileName));
237
- allDepMap.set(path.normalize(sf.fileName), deps);
238
- for (const dep of getAllDeps(path.normalize(sf.fileName))) {
239
- const depCache = this.#revDependencyCacheMap.getOrCreate(path.normalize(dep), new Set());
240
- depCache.add(path.normalize(sf.fileName));
241
- if (this.#modifiedFileSet.has(path.normalize(dep))) {
242
- affectedFileSet.add(path.normalize(sf.fileName));
224
+ const deps = getAllDeps(PathUtil.norm(sf.fileName));
225
+ allDepMap.set(PathUtil.norm(sf.fileName), deps);
226
+ for (const dep of getAllDeps(PathUtil.norm(sf.fileName))) {
227
+ const depCache = this.#revDependencyCacheMap.getOrCreate(dep, new Set());
228
+ depCache.add(PathUtil.norm(sf.fileName));
229
+ if (this.#modifiedFileSet.has(dep)) {
230
+ this.#affectedFileSet.add(PathUtil.norm(sf.fileName));
231
+ }
232
+ // dep이 emit된적이 없으면 affected에 추가해야함.
233
+ // dep파일이 추가된후 기존 파일에서 import하면 dep파일이 affected에 포함이 안되는 현상 때문
234
+ if (!this.#emittedFilesCacheMap.has(dep)) {
235
+ this.#affectedFileSet.add(dep);
243
236
  }
244
237
  }
245
238
  if (this.#ngProgram) {
@@ -247,16 +240,21 @@ export class SdTsCompiler {
247
240
  continue;
248
241
  }
249
242
  for (const dep of this.#ngProgram.compiler.getResourceDependencies(sf)) {
250
- const ref = this.#resourceDependencyCacheMap.getOrCreate(path.normalize(dep), new Set());
251
- ref.add(path.normalize(sf.fileName));
252
- if (this.#modifiedFileSet.has(path.normalize(dep))) {
253
- affectedFileSet.add(path.normalize(sf.fileName));
243
+ const ref = this.#resourceDependencyCacheMap.getOrCreate(PathUtil.norm(dep), new Set());
244
+ ref.add(PathUtil.norm(sf.fileName));
245
+ if (this.#modifiedFileSet.has(PathUtil.norm(dep))) {
246
+ this.#affectedFileSet.add(PathUtil.norm(sf.fileName));
247
+ }
248
+ // dep이 emit된적이 없으면 affected에 추가해야함.
249
+ // dep파일이 추가된후 기존 파일에서 import하면 dep파일이 affected에 포함이 안되는 현상 때문
250
+ if (!this.#emittedFilesCacheMap.has(PathUtil.norm(dep))) {
251
+ this.#affectedFileSet.add(PathUtil.norm(dep));
254
252
  }
255
253
  }
256
254
  }
257
255
  }
258
256
  });
259
- if (affectedFileSet.size === 0) {
257
+ if (this.#modifiedFileSet.size === 0) {
260
258
  this.#debug(`get affected (init)...`);
261
259
  perf.run("get affected (init)", () => {
262
260
  for (const sf of this.#program.getSourceFiles()) {
@@ -266,148 +264,156 @@ export class SdTsCompiler {
266
264
  const orgSf = getOrgSourceFile(sf);
267
265
  if (!orgSf)
268
266
  continue;
269
- affectedFileSet.add(path.normalize(orgSf.fileName));
267
+ this.#affectedFileSet.add(PathUtil.norm(orgSf.fileName));
270
268
  }
271
269
  });
272
270
  }
273
- this.#debug(`get diagnostics...`);
274
- perf.run("get program diagnostics", () => {
275
- diagnostics.push(...this.#program.getConfigFileParsingDiagnostics(), ...this.#program.getOptionsDiagnostics(), ...this.#program.getGlobalDiagnostics());
276
- if (this.#ngProgram) {
277
- diagnostics.push(...this.#ngProgram.compiler.getOptionDiagnostics());
278
- }
279
- });
280
- this.#debug(`get diagnostics of files...`);
281
- perf.run("get file diagnostics", () => {
282
- for (const affectedFile of affectedFileSet) {
283
- if (!PathUtil.isChildPath(affectedFile, this.#pkgPath)) {
284
- continue;
285
- }
286
- const affectedSourceFile = this.#program.getSourceFile(affectedFile);
287
- if (!affectedSourceFile ||
288
- (this.#ngProgram && this.#ngProgram.compiler.ignoreForDiagnostics.has(affectedSourceFile))) {
289
- continue;
290
- }
291
- // this.#debug(`get diagnostics of file ${affectedFile}...`);
292
- diagnostics.push(...this.#program.getSyntacticDiagnostics(affectedSourceFile), ...this.#program.getSemanticDiagnostics(affectedSourceFile));
293
- if (this.#ngProgram) {
294
- perf.run("get file diagnostics: ng", () => {
295
- if (affectedSourceFile.isDeclarationFile) {
296
- return;
297
- }
298
- diagnostics.push(...this.#ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram));
299
- });
300
- }
301
- }
302
- });
303
- perf.run("emit", () => {
304
- this.#debug(`prepare emit...`);
305
- let transformers = {};
306
- if (this.#ngProgram) {
307
- transformers = {
308
- ...transformers,
309
- ...this.#ngProgram.compiler.prepareEmit().transformers,
310
- };
311
- (transformers.before ??= []).push(replaceBootstrap(() => this.#program.getTypeChecker()));
312
- }
313
- // (transformers.before ??= []).push(transformKeys(this.#program));
314
- this.#debug(`emit for files...`);
315
- // affected에 새로 추가된 파일은 포함되지 않는 현상이 있어 getSourceFiles로 바꿈
316
- // 비교해보니, 딱히 getSourceFiles라서 더 느려지는것 같지는 않음
317
- // 그래도 affected로 다시 테스트
318
- for (const affectedFile of affectedFileSet) {
319
- if (this.#emittedFilesCacheMap.has(affectedFile)) {
320
- continue;
321
- }
322
- const sf = this.#program.getSourceFile(affectedFile);
323
- if (!sf) {
324
- continue;
325
- }
326
- // for (const sf of sourceFileSet) {
327
- /*if (this.#emittedFilesCacheMap.has(path.normalize(sf.fileName))) {
328
- continue;
329
- }*/
330
- if (sf.isDeclarationFile) {
331
- continue;
332
- }
333
- if (this.#ngProgram?.compiler.ignoreForEmit.has(sf)) {
334
- continue;
335
- }
336
- if (this.#ngProgram?.compiler.incrementalCompilation.safeToSkipEmit(sf) &&
337
- !affectedFileSet.has(path.normalize(sf.fileName))) {
338
- continue;
339
- }
340
- // esbuild를 통해 bundle로 묶어야 하는놈들은 모든 output이 있어야 함.
341
- if (!this.#isForBundle) {
342
- if (!PathUtil.isChildPath(sf.fileName, this.#pkgPath)) {
271
+ const emitFileSet = new Set();
272
+ const [lintResults] = await Promise.all([
273
+ this.#lintWorker.run("lint", [
274
+ {
275
+ cwd: this.#pkgPath,
276
+ fileSet: this.#affectedFileSet,
277
+ },
278
+ ]),
279
+ (async () => {
280
+ this.#debug(`get diagnostics...`);
281
+ const diagnostics = [];
282
+ perf.run("get program diagnostics", () => {
283
+ diagnostics.push(...this.#program.getConfigFileParsingDiagnostics(), ...this.#program.getOptionsDiagnostics(), ...this.#program.getGlobalDiagnostics());
284
+ if (this.#ngProgram) {
285
+ diagnostics.push(...this.#ngProgram.compiler.getOptionDiagnostics());
286
+ }
287
+ });
288
+ this.#debug(`get diagnostics of files...`);
289
+ for (const affectedFile of this.#affectedFileSet) {
290
+ if (!PathUtil.isChildPath(affectedFile, this.#pkgPath)) {
343
291
  continue;
344
292
  }
345
- }
346
- // this.#debug(`emit for`, sf.fileName);
347
- this.#program.emit(sf, (fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
348
- if (!sourceFiles || sourceFiles.length === 0) {
349
- this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
350
- return;
293
+ const affectedSourceFile = this.#program.getSourceFile(affectedFile);
294
+ if (!affectedSourceFile ||
295
+ (this.#ngProgram && this.#ngProgram.compiler.ignoreForDiagnostics.has(affectedSourceFile))) {
296
+ continue;
351
297
  }
352
- const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
298
+ // this.#debug(`get diagnostics of file ${affectedFile}...`);
299
+ perf.run("get file diagnostics", () => {
300
+ diagnostics.push(...this.#program.getSyntacticDiagnostics(affectedSourceFile), ...this.#program.getSemanticDiagnostics(affectedSourceFile));
301
+ });
353
302
  if (this.#ngProgram) {
354
- if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
355
- return;
356
- }
357
- this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
358
- }
359
- const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(path.normalize(sourceFile.fileName), []);
360
- if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
361
- let realFilePath = fileName;
362
- let realText = text;
363
- if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
364
- realFilePath = path.resolve(this.#distPath, path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath));
365
- if (fileName.endsWith(".js.map")) {
366
- const sourceMapContents = JSON.parse(realText);
367
- // remove "../../"
368
- sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
369
- realText = JSON.stringify(sourceMapContents);
303
+ perf.run("get file diagnostics: ng", () => {
304
+ if (affectedSourceFile.isDeclarationFile) {
305
+ return;
370
306
  }
371
- }
372
- emitFileInfoCaches.push({
373
- outAbsPath: realFilePath,
374
- text: realText,
307
+ diagnostics.push(...this.#ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, OptimizeFor.WholeProgram));
375
308
  });
376
309
  }
377
- else {
378
- emitFileInfoCaches.push({ text });
310
+ }
311
+ perf.run("emit", () => {
312
+ this.#debug(`prepare emit...`);
313
+ let transformers = {};
314
+ if (this.#ngProgram) {
315
+ transformers = {
316
+ ...transformers,
317
+ ...this.#ngProgram.compiler.prepareEmit().transformers,
318
+ };
319
+ (transformers.before ??= []).push(replaceBootstrap(() => this.#program.getTypeChecker()));
320
+ }
321
+ // (transformers.before ??= []).push(transformKeys(this.#program));
322
+ this.#debug(`emit for files...`);
323
+ // affected에 새로 추가된 파일은 포함되지 않는 현상이 있어 sourceFileSet으로 바꿈
324
+ // 비교해보니, 딱히 getSourceFiles라서 더 느려지는것 같지는 않음
325
+ // 그래도 affected로 다시 테스트
326
+ for (const affectedFile of this.#affectedFileSet) {
327
+ if (this.#emittedFilesCacheMap.has(affectedFile)) {
328
+ continue;
329
+ }
330
+ const sf = this.#program.getSourceFile(affectedFile);
331
+ if (!sf) {
332
+ continue;
333
+ }
334
+ if (sf.isDeclarationFile) {
335
+ continue;
336
+ }
337
+ if (this.#ngProgram?.compiler.ignoreForEmit.has(sf)) {
338
+ continue;
339
+ }
340
+ if (this.#ngProgram?.compiler.incrementalCompilation.safeToSkipEmit(sf)) {
341
+ continue;
342
+ }
343
+ // esbuild를 통해 bundle로 묶어야 하는놈들은 모든 output이 있어야 함.
344
+ if (!this.#isForBundle) {
345
+ if (!PathUtil.isChildPath(sf.fileName, this.#pkgPath)) {
346
+ continue;
347
+ }
348
+ }
349
+ // this.#debug(`emit for`, sf.fileName);
350
+ this.#program.emit(sf, (fileName, text, writeByteOrderMark, onError, sourceFiles, data) => {
351
+ if (!sourceFiles || sourceFiles.length === 0) {
352
+ this.#compilerHost.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
353
+ return;
354
+ }
355
+ const sourceFile = ts.getOriginalNode(sourceFiles[0], ts.isSourceFile);
356
+ if (this.#ngProgram) {
357
+ if (this.#ngProgram.compiler.ignoreForEmit.has(sourceFile)) {
358
+ return;
359
+ }
360
+ this.#ngProgram.compiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
361
+ }
362
+ const emitFileInfoCaches = this.#emittedFilesCacheMap.getOrCreate(PathUtil.norm(sourceFile.fileName), []);
363
+ if (PathUtil.isChildPath(sourceFile.fileName, this.#pkgPath)) {
364
+ let realFilePath = PathUtil.norm(fileName);
365
+ let realText = text;
366
+ if (PathUtil.isChildPath(realFilePath, path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"))) {
367
+ realFilePath = PathUtil.norm(this.#distPath, path.relative(path.resolve(this.#distPath, path.basename(this.#pkgPath), "src"), realFilePath));
368
+ if (fileName.endsWith(".js.map")) {
369
+ const sourceMapContents = JSON.parse(realText);
370
+ // remove "../../"
371
+ sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
372
+ realText = JSON.stringify(sourceMapContents);
373
+ }
374
+ }
375
+ emitFileInfoCaches.push({
376
+ outAbsPath: realFilePath,
377
+ text: realText,
378
+ });
379
+ }
380
+ else {
381
+ emitFileInfoCaches.push({ text });
382
+ }
383
+ emitFileSet.add(PathUtil.norm(sourceFile.fileName));
384
+ }, undefined, undefined, transformers);
379
385
  }
380
- emitFileSet.add(path.normalize(sourceFile.fileName));
381
- }, undefined, undefined, transformers);
382
- }
383
- });
384
- //-- global style
385
- if (this.#globalStyleFilePath != null &&
386
- FsUtil.exists(this.#globalStyleFilePath) &&
387
- !this.#emittedFilesCacheMap.has(this.#globalStyleFilePath)) {
388
- this.#debug(`bundle global style...`);
389
- await perf.run("bundle global style", async () => {
390
- const data = await FsUtil.readFileAsync(this.#globalStyleFilePath);
391
- const contents = await this.#bundleStylesheetAsync(data, this.#globalStyleFilePath, this.#globalStyleFilePath);
392
- const emitFileInfos = this.#emittedFilesCacheMap.getOrCreate(this.#globalStyleFilePath, []);
393
- emitFileInfos.push({
394
- outAbsPath: path.resolve(this.#pkgPath, path.relative(path.resolve(this.#pkgPath, "src"), this.#globalStyleFilePath).replace(/\.scss$/, ".css")),
395
- text: contents,
396
386
  });
397
- emitFileSet.add(this.#globalStyleFilePath);
398
- });
399
- }
400
- //-- init
401
- this.#modifiedFileSet.clear();
402
- this.#debug(`build completed`, perf.toString());
403
- //-- result
387
+ //-- global style
388
+ if (this.#globalStyleFilePath != null &&
389
+ FsUtil.exists(this.#globalStyleFilePath) &&
390
+ !this.#emittedFilesCacheMap.has(this.#globalStyleFilePath)) {
391
+ this.#debug(`bundle global style...`);
392
+ await perf.run("bundle global style", async () => {
393
+ const data = FsUtil.readFile(this.#globalStyleFilePath);
394
+ const contents = await this.#bundleStylesheetAsync(data, this.#globalStyleFilePath, this.#globalStyleFilePath);
395
+ const emitFileInfos = this.#emittedFilesCacheMap.getOrCreate(this.#globalStyleFilePath, []);
396
+ emitFileInfos.push({
397
+ outAbsPath: PathUtil.norm(this.#pkgPath, path
398
+ .relative(path.resolve(this.#pkgPath, "src"), this.#globalStyleFilePath)
399
+ .replace(/\.scss$/, ".css")),
400
+ text: contents,
401
+ });
402
+ emitFileSet.add(this.#globalStyleFilePath);
403
+ });
404
+ }
405
+ this.#debug(`build completed`, perf.toString());
406
+ //-- result
407
+ messages.push(...SdCliConvertMessageUtil.convertToBuildMessagesFromTsDiag(diagnostics));
408
+ })(),
409
+ ]);
410
+ messages.push(...SdCliConvertMessageUtil.convertToBuildMessagesFromEslint(lintResults));
404
411
  return {
405
- program: this.#program,
406
- typescriptDiagnostics: diagnostics,
412
+ messages,
413
+ watchFileSet: this.#watchFileSet,
414
+ affectedFileSet: this.#affectedFileSet,
407
415
  stylesheetBundlingResultMap: this.#stylesheetBundlingResultMap,
408
416
  emittedFilesCacheMap: this.#emittedFilesCacheMap,
409
- watchFileSet: this.#watchFileSet,
410
- affectedFileSet,
411
417
  emitFileSet,
412
418
  };
413
419
  }
@@ -422,25 +428,29 @@ export class SdTsCompiler {
422
428
  if (node.moduleSpecifier) {
423
429
  const moduleSymbol = tc.getSymbolAtLocation(node.moduleSpecifier);
424
430
  if (!moduleSymbol) {
431
+ const pos = ts.getLineAndCharacterOfPosition(sf, node.getStart());
425
432
  deps.push({
426
- category: DiagnosticCategory.Error,
427
- code: -1,
428
- file: sf,
429
- start: node.getStart(),
430
- length: node.getEnd() - node.getStart(),
431
- messageText: `export moduleSymbol not found`,
433
+ filePath: PathUtil.norm(sf.fileName),
434
+ line: pos.line,
435
+ char: pos.character,
436
+ code: undefined,
437
+ severity: "error",
438
+ message: "export moduleSymbol not found",
439
+ type: "deps",
432
440
  });
433
441
  return;
434
442
  }
435
443
  const decls = moduleSymbol.getDeclarations();
436
444
  if (!decls) {
445
+ const pos = ts.getLineAndCharacterOfPosition(sf, node.getStart());
437
446
  deps.push({
438
- category: DiagnosticCategory.Error,
439
- code: -1,
440
- file: sf,
441
- start: node.getStart(),
442
- length: node.getEnd() - node.getStart(),
443
- messageText: `export decls not found`,
447
+ filePath: PathUtil.norm(sf.fileName),
448
+ line: pos.line,
449
+ char: pos.character,
450
+ code: undefined,
451
+ severity: "error",
452
+ message: "export decls not found",
453
+ type: "deps",
444
454
  });
445
455
  return;
446
456
  }
@@ -449,7 +459,7 @@ export class SdTsCompiler {
449
459
  for (const el of namedBindings.elements) {
450
460
  for (const decl of decls) {
451
461
  deps.push({
452
- fileName: path.normalize(decl.getSourceFile().fileName),
462
+ fileName: PathUtil.norm(decl.getSourceFile().fileName),
453
463
  importName: el.name.text,
454
464
  exportName: el.propertyName?.text ?? el.name.text,
455
465
  });
@@ -458,20 +468,22 @@ export class SdTsCompiler {
458
468
  }
459
469
  else {
460
470
  if (!moduleSymbol.exports) {
471
+ const pos = ts.getLineAndCharacterOfPosition(sf, node.getStart());
461
472
  deps.push({
462
- category: DiagnosticCategory.Error,
463
- code: -1,
464
- file: sf,
465
- start: node.getStart(),
466
- length: node.getEnd() - node.getStart(),
467
- messageText: `moduleSymbol exports not found`,
473
+ filePath: PathUtil.norm(sf.fileName),
474
+ line: pos.line,
475
+ char: pos.character,
476
+ code: undefined,
477
+ severity: "error",
478
+ message: "moduleSymbol exports not found",
479
+ type: "deps",
468
480
  });
469
481
  return;
470
482
  }
471
483
  for (const decl of decls) {
472
484
  for (const key of moduleSymbol.exports.keys()) {
473
485
  deps.push({
474
- fileName: path.normalize(decl.getSourceFile().fileName),
486
+ fileName: PathUtil.norm(decl.getSourceFile().fileName),
475
487
  importName: key.toString(),
476
488
  exportName: key.toString(),
477
489
  });
@@ -485,7 +497,7 @@ export class SdTsCompiler {
485
497
  if (!moduleSymbol) {
486
498
  if (ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text.startsWith("./")) {
487
499
  deps.push({
488
- fileName: path.normalize(path.resolve(path.dirname(sf.fileName), node.moduleSpecifier.text)),
500
+ fileName: PathUtil.norm(path.resolve(path.dirname(sf.fileName), node.moduleSpecifier.text)),
489
501
  importName: "*",
490
502
  });
491
503
  }
@@ -496,13 +508,15 @@ export class SdTsCompiler {
496
508
  else {
497
509
  const decls = moduleSymbol.getDeclarations();
498
510
  if (!decls) {
511
+ const pos = ts.getLineAndCharacterOfPosition(sf, node.getStart());
499
512
  deps.push({
500
- category: DiagnosticCategory.Error,
501
- code: -1,
502
- file: sf,
503
- start: node.getStart(),
504
- length: node.getEnd() - node.getStart(),
505
- messageText: `import decls not found`,
513
+ filePath: PathUtil.norm(sf.fileName),
514
+ line: pos.line,
515
+ char: pos.character,
516
+ code: undefined,
517
+ severity: "error",
518
+ message: "import decls not found",
519
+ type: "deps",
506
520
  });
507
521
  return;
508
522
  }
@@ -511,7 +525,7 @@ export class SdTsCompiler {
511
525
  for (const el of namedBindings.elements) {
512
526
  for (const decl of decls) {
513
527
  deps.push({
514
- fileName: path.normalize(decl.getSourceFile().fileName),
528
+ fileName: PathUtil.norm(decl.getSourceFile().fileName),
515
529
  importName: el.name.text,
516
530
  });
517
531
  }
@@ -520,7 +534,7 @@ export class SdTsCompiler {
520
534
  else {
521
535
  for (const decl of decls) {
522
536
  deps.push({
523
- fileName: path.normalize(decl.getSourceFile().fileName),
537
+ fileName: PathUtil.norm(decl.getSourceFile().fileName),
524
538
  importName: "*",
525
539
  });
526
540
  }