@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,14 +1,11 @@
1
1
  import path from "path";
2
2
  import esbuild, { Metafile } from "esbuild";
3
- import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
3
+ import { FsUtil, Logger, PathUtil, TNormPath } from "@simplysm/sd-core-node";
4
4
  import { fileURLToPath } from "url";
5
5
  import nodeStdLibBrowser from "node-stdlib-browser";
6
6
  import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
7
- import { INpmConfig, ISdCliClientBuilderCordovaConfig, ISdCliPackageBuildResult } from "../commons";
8
7
  import browserslist from "browserslist";
9
8
  import { SdNgBundlerContext } from "./SdNgBundlerContext";
10
- import { INgPluginResultCache, sdNgPlugin } from "../bundle-plugins/sdNgPlugin";
11
- import ts from "typescript";
12
9
  import { MemoryLoadResultCache } from "@angular/build/src/tools/esbuild/load-result-cache";
13
10
  import {
14
11
  convertOutputFile,
@@ -21,14 +18,9 @@ import {
21
18
  InitialFileRecord,
22
19
  } from "@angular/build/src/tools/esbuild/bundler-context";
23
20
  import { extractLicenses } from "@angular/build/src/tools/esbuild/license-extractor";
24
- import {
25
- HintMode,
26
- IndexHtmlGenerator,
27
- IndexHtmlProcessResult,
28
- } from "@angular/build/src/utils/index-file/index-html-generator";
21
+ import { IndexHtmlGenerator, IndexHtmlProcessResult } from "@angular/build/src/utils/index-file/index-html-generator";
29
22
  import { Entrypoint } from "@angular/build/src/utils/index-file/augment-index-html";
30
23
  import { CrossOrigin } from "@angular/build/src/builders/application/schema";
31
- import { InlineCriticalCssProcessor } from "@angular/build/src/utils/index-file/inline-critical-css";
32
24
  import { augmentAppWithServiceWorkerEsbuild } from "@angular/build/src/utils/service-worker";
33
25
  import { createSourcemapIgnorelistPlugin } from "@angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin";
34
26
  import { StylesheetPluginFactory } from "@angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory";
@@ -36,27 +28,26 @@ import { SassStylesheetLanguage } from "@angular/build/src/tools/esbuild/stylesh
36
28
  import { CssStylesheetLanguage } from "@angular/build/src/tools/esbuild/stylesheets/css-language";
37
29
  import { createCssResourcePlugin } from "@angular/build/src/tools/esbuild/stylesheets/css-resource-plugin";
38
30
  import { resolveAssets } from "@angular/build/src/utils/resolve-assets";
39
- import { SdCliPerformanceTimer } from "../utils/SdCliPerformanceTime";
31
+ import { createSdNgPlugin } from "./createSdNgPlugin";
32
+ import { SdCliPerformanceTimer } from "../../utils/SdCliPerformanceTime";
33
+ import { INpmConfig } from "../../types/common-configs.type";
34
+ import { ISdClientBuilderCordovaConfig } from "../../types/sd-configs.type";
35
+ import { ISdCliNgPluginResultCache } from "../../types/build-plugin.type";
36
+ import { ISdBuildMessage } from "../../types/build.type";
40
37
 
41
38
  export class SdNgBundler {
42
39
  readonly #logger = Logger.get(["simplysm", "sd-cli", "SdNgBundler"]);
43
40
 
44
- // private readonly _sourceFileCache = new SourceFileCache(
45
- // path.resolve(this.#opt.pkgPath, ".cache")
46
- // );
47
-
48
- readonly #modifiedFileSet = new Set<string>();
49
- readonly #ngResultCache: INgPluginResultCache = {
50
- affectedFileSet: new Set<string>(),
51
- watchFileSet: new Set<string>(),
41
+ readonly #modifiedFileSet = new Set<TNormPath>();
42
+ readonly #ngResultCache: ISdCliNgPluginResultCache = {
43
+ affectedFileSet: new Set<TNormPath>(),
44
+ watchFileSet: new Set<TNormPath>(),
52
45
  };
53
46
  readonly #styleLoadResultCache = new MemoryLoadResultCache();
54
47
 
55
48
  #contexts: SdNgBundlerContext[] | undefined;
56
49
 
57
- readonly #outputCache = new Map<string, string | number>();
58
-
59
- readonly #opt: IOptions;
50
+ readonly #outputCache = new Map<TNormPath, string | number>();
60
51
 
61
52
  readonly #pkgNpmConf: INpmConfig;
62
53
  readonly #mainFilePath: string;
@@ -67,34 +58,45 @@ export class SdNgBundler {
67
58
  readonly #pkgName: string;
68
59
  readonly #baseHref: string;
69
60
 
70
- // #loadFilePathSet = new Set<string>();
71
-
72
- public constructor(opt: IOptions) {
73
- this.#opt = opt;
74
- this.#pkgNpmConf = FsUtil.readJson(path.resolve(opt.pkgPath, "package.json"));
75
- this.#mainFilePath = path.resolve(opt.pkgPath, "src/main.ts");
76
- this.#tsConfigFilePath = path.resolve(opt.pkgPath, "tsconfig.json");
77
- this.#swConfFilePath = path.resolve(opt.pkgPath, "ngsw-config.json");
61
+ public constructor(
62
+ private _opt: {
63
+ dev: boolean;
64
+ outputPath: TNormPath;
65
+ pkgPath: TNormPath;
66
+ builderType: string;
67
+ env: Record<string, string> | undefined;
68
+ cordovaConfig: ISdClientBuilderCordovaConfig | undefined;
69
+ watchScopePaths: TNormPath[];
70
+ },
71
+ ) {
72
+ this.#pkgNpmConf = FsUtil.readJson(path.resolve(this._opt.pkgPath, "package.json"));
73
+ this.#mainFilePath = path.resolve(this._opt.pkgPath, "src/main.ts");
74
+ this.#tsConfigFilePath = path.resolve(this._opt.pkgPath, "tsconfig.json");
75
+ this.#swConfFilePath = path.resolve(this._opt.pkgPath, "ngsw-config.json");
78
76
  this.#browserTarget = transformSupportedBrowsersToTargets(browserslist(["Chrome > 78"]));
79
- this.#indexHtmlFilePath = path.resolve(opt.pkgPath, "src/index.html");
80
- this.#pkgName = path.basename(opt.pkgPath);
77
+ this.#indexHtmlFilePath = path.resolve(this._opt.pkgPath, "src/index.html");
78
+ this.#pkgName = path.basename(this._opt.pkgPath);
81
79
  this.#baseHref =
82
- opt.builderType === "web" ? `/${this.#pkgName}/` : opt.dev ? `/${this.#pkgName}/${opt.builderType}/` : ``;
80
+ this._opt.builderType === "web"
81
+ ? `/${this.#pkgName}/`
82
+ : this._opt.dev
83
+ ? `/${this.#pkgName}/${this._opt.builderType}/`
84
+ : ``;
83
85
  }
84
86
 
85
87
  public markForChanges(filePaths: string[]): void {
86
88
  for (const filePath of filePaths) {
87
- this.#modifiedFileSet.add(path.normalize(filePath));
88
- this.#styleLoadResultCache.invalidate(path.normalize(filePath));
89
+ this.#modifiedFileSet.add(PathUtil.norm(filePath));
90
+ this.#styleLoadResultCache.invalidate(PathUtil.norm(filePath));
89
91
  }
90
92
  // this._sourceFileCache.invalidate(filePaths);
91
93
  }
92
94
 
93
95
  public async bundleAsync(): Promise<{
94
- program?: ts.Program;
95
- watchFileSet: Set<string>;
96
- affectedFileSet: Set<string>;
97
- results: ISdCliPackageBuildResult[];
96
+ watchFileSet: Set<TNormPath>;
97
+ affectedFileSet: Set<TNormPath>;
98
+ results: ISdBuildMessage[];
99
+ emitFileSet: Set<TNormPath>;
98
100
  }> {
99
101
  const perf = new SdCliPerformanceTimer("ng bundle");
100
102
 
@@ -104,14 +106,14 @@ export class SdNgBundler {
104
106
  this.#contexts = perf.run("get contexts", () => [
105
107
  this._getAppContext(),
106
108
  this._getStyleContext(),
107
- ...(this.#opt.builderType === "electron" ? [this._getElectronMainContext()] : []),
109
+ ...(this._opt.builderType === "electron" ? [this._getElectronMainContext()] : []),
108
110
  ]);
109
111
  }
110
112
 
111
113
  this.#debug(`build...`);
112
114
 
113
115
  const bundlingResults = await perf.run("build", async () => {
114
- return await this.#contexts!.mapAsync(async (ctx, i) => await ctx.bundleAsync());
116
+ return await this.#contexts!.mapAsync(async (ctx) => await ctx.bundleAsync());
115
117
  });
116
118
 
117
119
  //-- results
@@ -138,13 +140,13 @@ export class SdNgBundler {
138
140
  const assetFiles: { source: string; destination: string }[] = [];
139
141
 
140
142
  //-- cordova empty
141
- if (this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins) {
143
+ if (this._opt.builderType === "cordova" && this._opt.cordovaConfig?.plugins) {
142
144
  outputFiles.push(createOutputFile("cordova-empty.js", "export default {};", BuildOutputFileType.Root));
143
145
  }
144
146
 
145
147
  this.#debug(`create index.html...`);
146
148
  await perf.run("create index.html", async () => {
147
- const genIndexHtmlResult = await this._genIndexHtmlAsync(outputFiles, initialFiles);
149
+ const genIndexHtmlResult = await this._genIndexHtmlAsync(initialFiles);
148
150
  for (const warning of genIndexHtmlResult.warnings) {
149
151
  results.push({
150
152
  filePath: undefined,
@@ -152,8 +154,8 @@ export class SdNgBundler {
152
154
  char: undefined,
153
155
  code: undefined,
154
156
  severity: "warning",
155
- message: `(gen-index) ${warning}`,
156
- type: "build",
157
+ message: `${warning}`,
158
+ type: "gen-index",
157
159
  });
158
160
  }
159
161
  for (const error of genIndexHtmlResult.errors) {
@@ -163,8 +165,8 @@ export class SdNgBundler {
163
165
  char: undefined,
164
166
  code: undefined,
165
167
  severity: "error",
166
- message: `(gen-index) ${error}`,
167
- type: "build",
168
+ message: `${error}`,
169
+ type: "gen-index",
168
170
  });
169
171
  }
170
172
  outputFiles.push(createOutputFile("index.html", genIndexHtmlResult.csrContent, BuildOutputFileType.Root));
@@ -175,11 +177,11 @@ export class SdNgBundler {
175
177
  assetFiles.push(...(await this._copyAssetsAsync()));
176
178
 
177
179
  //-- extract 3rdpartylicenses
178
- if (!this.#opt.dev) {
180
+ if (!this._opt.dev) {
179
181
  outputFiles.push(
180
182
  createOutputFile(
181
183
  "3rdpartylicenses.txt",
182
- await extractLicenses(metafile, this.#opt.pkgPath),
184
+ await extractLicenses(metafile, this._opt.pkgPath),
183
185
  BuildOutputFileType.Root,
184
186
  ),
185
187
  );
@@ -202,8 +204,8 @@ export class SdNgBundler {
202
204
  char: undefined,
203
205
  code: undefined,
204
206
  severity: "error",
205
- message: `(gen-sw) ${err.toString()}`,
206
- type: "build",
207
+ message: `${err.toString()}`,
208
+ type: "gen-sw",
207
209
  });
208
210
  }
209
211
  });
@@ -212,21 +214,24 @@ export class SdNgBundler {
212
214
  //-- write
213
215
  this.#debug(`write output files...(${outputFiles.length})`);
214
216
 
215
- await perf.run("write output file", async () => {
217
+ const emitFileSet = new Set<TNormPath>();
218
+ perf.run("write output file", () => {
216
219
  for (const outputFile of outputFiles) {
217
- const distFilePath = path.resolve(this.#opt.outputPath, outputFile.path);
220
+ const distFilePath = PathUtil.norm(this._opt.outputPath, outputFile.path);
218
221
  const prev = this.#outputCache.get(distFilePath);
219
222
  if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
220
- await FsUtil.writeFileAsync(distFilePath, outputFile.contents);
223
+ FsUtil.writeFile(distFilePath, outputFile.contents);
221
224
  this.#outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
225
+ emitFileSet.add(PathUtil.norm(outputFile.path));
222
226
  }
223
227
  }
224
228
  for (const assetFile of assetFiles) {
225
- const prev = this.#outputCache.get(assetFile.source);
229
+ const prev = this.#outputCache.get(PathUtil.norm(assetFile.source));
226
230
  const curr = FsUtil.lstat(assetFile.source).mtime.getTime();
227
231
  if (prev !== curr) {
228
- await FsUtil.copyAsync(assetFile.source, path.resolve(this.#opt.outputPath, assetFile.destination));
229
- this.#outputCache.set(assetFile.source, curr);
232
+ FsUtil.copy(assetFile.source, path.resolve(this._opt.outputPath, assetFile.destination));
233
+ this.#outputCache.set(PathUtil.norm(assetFile.source), curr);
234
+ emitFileSet.add(PathUtil.norm(assetFile.destination));
230
235
  }
231
236
  }
232
237
  });
@@ -234,71 +239,41 @@ export class SdNgBundler {
234
239
  this.#debug(perf.toString());
235
240
 
236
241
  return {
237
- program: this.#ngResultCache.program,
238
242
  watchFileSet: new Set([
239
243
  ...this.#ngResultCache.watchFileSet!,
240
- ...this.#styleLoadResultCache.watchFiles,
241
- this.#indexHtmlFilePath,
244
+ ...this.#styleLoadResultCache.watchFiles.map((item) => PathUtil.norm(item)),
245
+ PathUtil.norm(this.#indexHtmlFilePath),
242
246
  ]),
243
247
  affectedFileSet: this.#ngResultCache.affectedFileSet!,
244
248
  results,
249
+ emitFileSet: emitFileSet,
245
250
  };
246
251
  }
247
252
 
248
- private async _genIndexHtmlAsync(
249
- outputFiles: esbuild.OutputFile[],
250
- initialFiles: Map<string, InitialFileRecord>,
251
- ): Promise<IndexHtmlProcessResult> {
252
- const readAsset = (filePath: string): Promise<string> => {
253
- const relFilePath = path.relative("/", filePath);
254
- const currFile = outputFiles.find((outputFile) => outputFile.path === relFilePath);
255
- if (currFile) {
256
- return Promise.resolve(currFile.text);
257
- }
258
-
259
- throw new Error(`Output file does not exist: ${relFilePath}`);
260
- };
261
-
253
+ private async _genIndexHtmlAsync(initialFiles: Map<string, InitialFileRecord>): Promise<IndexHtmlProcessResult> {
262
254
  const indexHtmlGenerator = new IndexHtmlGenerator({
263
255
  indexPath: this.#indexHtmlFilePath,
264
256
  entrypoints: [
265
- ["runtime", true],
266
257
  ["polyfills", true],
267
258
  ["styles", false],
268
- ["vendor", true],
269
259
  ["main", true],
270
- ...(this.#opt.builderType === "cordova" ? [["cordova-entry", true] as Entrypoint] : []),
260
+ ...(this._opt.builderType === "cordova" ? [["cordova-entry", true] as Entrypoint] : []),
271
261
  ],
262
+ sri: false,
272
263
  optimization: {
273
- scripts: !this.#opt.dev,
274
- fonts: { inline: !this.#opt.dev },
264
+ scripts: !this._opt.dev,
275
265
  styles: {
276
- minify: !this.#opt.dev,
277
- inlineCritical: false,
266
+ minify: !this._opt.dev,
267
+ inlineCritical: !this._opt.dev,
268
+ removeSpecialComments: !this._opt.dev,
278
269
  },
270
+ fonts: { inline: !this._opt.dev },
279
271
  },
280
272
  crossOrigin: CrossOrigin.None,
273
+ generateDedicatedSSRContent: false,
281
274
  });
282
- indexHtmlGenerator.readAsset = readAsset;
283
-
284
- const hints: { url: string; mode: HintMode; as?: string }[] = [];
285
- if (!this.#opt.dev) {
286
- for (const [key, value] of initialFiles) {
287
- if (value.entrypoint) {
288
- continue;
289
- }
290
-
291
- if (value.type === "script") {
292
- hints.push({ url: key, mode: "modulepreload" as const });
293
- }
294
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
295
- else if (value.type === "style") {
296
- hints.push({ url: key, mode: "preload" as const, as: "style" });
297
- }
298
- }
299
- }
300
275
 
301
- const transformResult = await indexHtmlGenerator.process({
276
+ return await indexHtmlGenerator.process({
302
277
  baseHref: this.#baseHref,
303
278
  lang: undefined,
304
279
  outputPath: "/",
@@ -307,29 +282,9 @@ export class SdNgBundler {
307
282
  file,
308
283
  extension: path.extname(file),
309
284
  })),
310
- hints,
311
285
  });
312
-
313
- if (this.#opt.dev) {
314
- return transformResult;
315
- } else {
316
- const inlineCriticalCssProcessor = new InlineCriticalCssProcessor({
317
- minify: false,
318
- readAsset,
319
- });
320
- const { content, errors, warnings } = await inlineCriticalCssProcessor.process(transformResult.csrContent, {
321
- outputPath: "/",
322
- });
323
-
324
- return {
325
- warnings: [...transformResult.warnings, ...warnings],
326
- errors: [...transformResult.errors, ...errors],
327
- csrContent: content,
328
- };
329
- }
330
286
  }
331
287
 
332
- //TODO: index.html 파일에 manifest.json 정보 추가? manifest.webmanifest ? PWA?
333
288
  private async _copyAssetsAsync(): Promise<
334
289
  {
335
290
  source: string;
@@ -338,13 +293,10 @@ export class SdNgBundler {
338
293
  > {
339
294
  return await resolveAssets(
340
295
  [
341
- { input: "src", glob: "favicon.ico", output: "" },
342
- { input: "src", glob: "manifest.webmanifest", output: "" },
343
- { input: "src", glob: "manifest.json", output: "" },
344
- { input: "src/assets", glob: "**/*", output: "assets" },
345
- ...(this.#opt.dev ? [{ input: "src/assets-dev", glob: "**/*", output: "assets-dev" }] : []),
346
- ...(this.#opt.dev && this.#opt.builderType === "cordova"
347
- ? Object.keys(this.#opt.cordovaConfig?.platform ?? { browser: {} }).mapMany((platform) => [
296
+ { input: "public", glob: "**/*", output: "." },
297
+ ...(this._opt.dev ? [{ input: "public-dev", glob: "**/*", output: "." }] : []),
298
+ ...(this._opt.dev && this._opt.builderType === "cordova"
299
+ ? Object.keys(this._opt.cordovaConfig?.platform ?? { browser: {} }).mapMany((platform) => [
348
300
  {
349
301
  input: `.cordova/platforms/${platform}/platform_www/plugins`,
350
302
  glob: "**/*",
@@ -368,7 +320,7 @@ export class SdNgBundler {
368
320
  ])
369
321
  : []),
370
322
  ],
371
- this.#opt.pkgPath,
323
+ this._opt.pkgPath,
372
324
  );
373
325
  }
374
326
 
@@ -386,7 +338,7 @@ export class SdNgBundler {
386
338
  }[];
387
339
  }> {
388
340
  return await augmentAppWithServiceWorkerEsbuild(
389
- this.#opt.pkgPath,
341
+ this._opt.pkgPath,
390
342
  this.#swConfFilePath,
391
343
  this.#baseHref,
392
344
  "index.html",
@@ -396,12 +348,12 @@ export class SdNgBundler {
396
348
  }
397
349
 
398
350
  private _getAppContext() {
399
- const workerEntries = FsUtil.glob(path.resolve(this.#opt.pkgPath, "src/workers/*.ts")).toObject(
351
+ const workerEntries = FsUtil.glob(path.resolve(this._opt.pkgPath, "src/workers/*.ts")).toObject(
400
352
  (p) => "worker/" + path.basename(p, path.extname(p)),
401
353
  );
402
354
 
403
- return new SdNgBundlerContext(this.#opt.pkgPath, {
404
- absWorkingDir: this.#opt.pkgPath,
355
+ return new SdNgBundlerContext(this._opt.pkgPath, {
356
+ absWorkingDir: this._opt.pkgPath,
405
357
  bundle: true,
406
358
  keepNames: true,
407
359
  format: "esm",
@@ -409,32 +361,32 @@ export class SdNgBundler {
409
361
  conditions: ["es2020", "es2015", "module"],
410
362
  resolveExtensions: [".js", ".mjs", ".cjs", ".ts"],
411
363
  metafile: true,
412
- legalComments: this.#opt.dev ? "eof" : "none",
364
+ legalComments: this._opt.dev ? "eof" : "none",
413
365
  logLevel: "silent",
414
- minifyIdentifiers: !this.#opt.dev,
415
- minifySyntax: !this.#opt.dev,
416
- minifyWhitespace: !this.#opt.dev,
366
+ minifyIdentifiers: !this._opt.dev,
367
+ minifySyntax: !this._opt.dev,
368
+ minifyWhitespace: !this._opt.dev,
417
369
  pure: ["forwardRef"],
418
- outdir: this.#opt.pkgPath,
370
+ outdir: this._opt.pkgPath,
419
371
  outExtension: undefined,
420
- sourcemap: true, //this.#opt.dev,
372
+ sourcemap: true, //this._opt.dev,
421
373
  splitting: true,
422
374
  chunkNames: "[name]-[hash]",
423
375
  tsconfig: this.#tsConfigFilePath,
424
376
  write: false,
425
377
  preserveSymlinks: false,
426
378
  define: {
427
- ...(!this.#opt.dev ? { ngDevMode: "false" } : {}),
379
+ ...(!this._opt.dev ? { ngDevMode: "false" } : {}),
428
380
  "ngJitMode": "false",
429
381
  "global": "global",
430
382
  "process": "process",
431
383
  "Buffer": "Buffer",
432
384
  "process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
433
- "process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
434
- ...(this.#opt.env
435
- ? Object.keys(this.#opt.env).toObject(
385
+ "process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
386
+ ...(this._opt.env
387
+ ? Object.keys(this._opt.env).toObject(
436
388
  (key) => `process.env.${key}`,
437
- (key) => JSON.stringify(this.#opt.env![key]),
389
+ (key) => JSON.stringify(this._opt.env![key]),
438
390
  )
439
391
  : {}),
440
392
  },
@@ -444,10 +396,13 @@ export class SdNgBundler {
444
396
  entryPoints: {
445
397
  main: this.#mainFilePath,
446
398
  // polyfills: 'angular:polyfills',
447
- polyfills: path.resolve(this.#opt.pkgPath, "src/polyfills.ts"),
448
- ...(this.#opt.builderType === "cordova"
399
+ polyfills: path.resolve(this._opt.pkgPath, "src/polyfills.ts"),
400
+ ...(this._opt.builderType === "cordova"
449
401
  ? {
450
- "cordova-entry": path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../lib/cordova-entry.js`),
402
+ "cordova-entry": path.resolve(
403
+ path.dirname(fileURLToPath(import.meta.url)),
404
+ `../../../lib/cordova-entry.js`,
405
+ ),
451
406
  }
452
407
  : {}),
453
408
  ...workerEntries,
@@ -484,12 +439,12 @@ export class SdNgBundler {
484
439
  },
485
440
  inject: [PathUtil.posix(fileURLToPath(import.meta.resolve("node-stdlib-browser/helpers/esbuild/shim")))],
486
441
  plugins: [
487
- ...(this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins
442
+ ...(this._opt.builderType === "cordova" && this._opt.cordovaConfig?.plugins
488
443
  ? [
489
444
  {
490
445
  name: "cordova:plugin-empty",
491
446
  setup: ({ onResolve }) => {
492
- onResolve({ filter: new RegExp("(" + this.#opt.cordovaConfig!.plugins!.join("|") + ")") }, () => {
447
+ onResolve({ filter: new RegExp("(" + this._opt.cordovaConfig!.plugins!.join("|") + ")") }, () => {
493
448
  return {
494
449
  path: `./cordova-empty.js`,
495
450
  external: true,
@@ -504,19 +459,19 @@ export class SdNgBundler {
504
459
  // loadContent: () => ({
505
460
  // contents: `import "./src/polyfills.ts";`,
506
461
  // loader: 'js',
507
- // resolveDir: this.#opt.pkgPath
462
+ // resolveDir: this._opt.pkgPath
508
463
  // })
509
464
  // }) as esbuild.Plugin,
510
465
  createSourcemapIgnorelistPlugin(),
511
- sdNgPlugin({
466
+ createSdNgPlugin({
512
467
  modifiedFileSet: this.#modifiedFileSet,
513
- dev: this.#opt.dev,
514
- pkgPath: this.#opt.pkgPath,
468
+ dev: this._opt.dev,
469
+ pkgPath: this._opt.pkgPath,
515
470
  result: this.#ngResultCache,
516
- watchScopePaths: this.#opt.watchScopePaths,
471
+ watchScopePaths: this._opt.watchScopePaths,
517
472
  }),
518
473
  // createCompilerPlugin({
519
- // sourcemap: this.#opt.dev,
474
+ // sourcemap: this._opt.dev,
520
475
  // tsconfig: this._tsConfigFilePath,
521
476
  // jit: false,
522
477
  // advancedOptimizations: true,
@@ -524,11 +479,11 @@ export class SdNgBundler {
524
479
  // fileReplacements: undefined,
525
480
  // sourceFileCache: this._sourceFileCache,
526
481
  // loadResultCache: this._sourceFileCache.loadResultCache,
527
- // incremental: this.#opt.dev
482
+ // incremental: this._opt.dev
528
483
  // }, {
529
- // workspaceRoot: this.#opt.pkgPath,
530
- // optimization: !this.#opt.dev,
531
- // sourcemap: this.#opt.dev ? 'inline' : false,
484
+ // workspaceRoot: this._opt.pkgPath,
485
+ // optimization: !this._opt.dev,
486
+ // sourcemap: this._opt.dev ? 'inline' : false,
532
487
  // outputNames: {bundles: '[name]', media: 'media/[name]'},
533
488
  // includePaths: [],
534
489
  // externalDependencies: [],
@@ -554,22 +509,22 @@ export class SdNgBundler {
554
509
  private _getStyleContext(): SdNgBundlerContext {
555
510
  const pluginFactory = new StylesheetPluginFactory(
556
511
  {
557
- sourcemap: true, //this.#opt.dev,
512
+ sourcemap: true, //this._opt.dev,
558
513
  includePaths: [],
559
514
  },
560
515
  this.#styleLoadResultCache,
561
516
  );
562
517
 
563
- return new SdNgBundlerContext(this.#opt.pkgPath, {
564
- absWorkingDir: this.#opt.pkgPath,
518
+ return new SdNgBundlerContext(this._opt.pkgPath, {
519
+ absWorkingDir: this._opt.pkgPath,
565
520
  bundle: true,
566
521
  entryNames: "[name]",
567
522
  assetNames: "media/[name]",
568
523
  logLevel: "silent",
569
- minify: !this.#opt.dev,
524
+ minify: !this._opt.dev,
570
525
  metafile: true,
571
- sourcemap: true, //this.#opt.dev,
572
- outdir: this.#opt.pkgPath,
526
+ sourcemap: true, //this._opt.dev,
527
+ outdir: this._opt.pkgPath,
573
528
  write: false,
574
529
  platform: "browser",
575
530
  target: this.#browserTarget,
@@ -577,10 +532,10 @@ export class SdNgBundler {
577
532
  external: [],
578
533
  conditions: ["style", "sass"],
579
534
  mainFields: ["style", "sass"],
580
- legalComments: !this.#opt.dev ? "none" : "eof",
535
+ legalComments: !this._opt.dev ? "none" : "eof",
581
536
  entryPoints: {
582
537
  // styles: 'angular:styles/global;styles'
583
- styles: path.resolve(this.#opt.pkgPath, "src/styles.scss"),
538
+ styles: path.resolve(this._opt.pkgPath, "src/styles.scss"),
584
539
  },
585
540
  plugins: [
586
541
  // createVirtualModulePlugin({
@@ -589,7 +544,7 @@ export class SdNgBundler {
589
544
  // loadContent: () => ({
590
545
  // contents: `@import 'src/styles.scss';`,
591
546
  // loader: 'css',
592
- // resolveDir: this.#opt.pkgPath
547
+ // resolveDir: this._opt.pkgPath
593
548
  // }),
594
549
  // }) as esbuild.Plugin,
595
550
  pluginFactory.create(SassStylesheetLanguage) as esbuild.Plugin,
@@ -600,52 +555,42 @@ export class SdNgBundler {
600
555
  }
601
556
 
602
557
  private _getElectronMainContext() {
603
- return new SdNgBundlerContext(this.#opt.pkgPath, {
604
- absWorkingDir: this.#opt.pkgPath,
558
+ return new SdNgBundlerContext(this._opt.pkgPath, {
559
+ absWorkingDir: this._opt.pkgPath,
605
560
  bundle: true,
606
561
  entryNames: "[name]",
607
562
  assetNames: "media/[name]",
608
563
  conditions: ["es2020", "es2015", "module"],
609
564
  resolveExtensions: [".js", ".mjs", ".cjs", ".ts"],
610
565
  metafile: true,
611
- legalComments: this.#opt.dev ? "eof" : "none",
566
+ legalComments: this._opt.dev ? "eof" : "none",
612
567
  logLevel: "silent",
613
- minify: !this.#opt.dev,
614
- outdir: this.#opt.pkgPath,
615
- sourcemap: true, //this.#opt.dev,
568
+ minify: !this._opt.dev,
569
+ outdir: this._opt.pkgPath,
570
+ sourcemap: true, //this._opt.dev,
616
571
  tsconfig: this.#tsConfigFilePath,
617
572
  write: false,
618
573
  preserveSymlinks: false,
619
574
  external: ["electron"],
620
575
  define: {
621
- ...(!this.#opt.dev ? { ngDevMode: "false" } : {}),
576
+ ...(!this._opt.dev ? { ngDevMode: "false" } : {}),
622
577
  "process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
623
- "process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
624
- ...(this.#opt.env
625
- ? Object.keys(this.#opt.env).toObject(
578
+ "process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
579
+ ...(this._opt.env
580
+ ? Object.keys(this._opt.env).toObject(
626
581
  (key) => `process.env.${key}`,
627
- (key) => JSON.stringify(this.#opt.env![key]),
582
+ (key) => JSON.stringify(this._opt.env![key]),
628
583
  )
629
584
  : {}),
630
585
  },
631
586
  platform: "node",
632
587
  entryPoints: {
633
- "electron-main": path.resolve(this.#opt.pkgPath, "src/electron-main.ts"),
588
+ "electron-main": path.resolve(this._opt.pkgPath, "src/electron-main.ts"),
634
589
  },
635
590
  });
636
591
  }
637
592
 
638
593
  #debug(...msg: any[]): void {
639
- this.#logger.debug(`[${path.basename(this.#opt.pkgPath)}]`, ...msg);
594
+ this.#logger.debug(`[${path.basename(this._opt.pkgPath)}]`, ...msg);
640
595
  }
641
596
  }
642
-
643
- interface IOptions {
644
- dev: boolean;
645
- outputPath: string;
646
- pkgPath: string;
647
- builderType: string;
648
- env: Record<string, string> | undefined;
649
- cordovaConfig: ISdCliClientBuilderCordovaConfig | undefined;
650
- watchScopePaths: string[];
651
- }