@simplysm/sd-cli 12.5.7 → 12.5.8

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 (51) hide show
  1. package/dist/build-tools/SdCliIndexFileGenerator.js +4 -7
  2. package/dist/build-tools/SdCliIndexFileGenerator.js.map +1 -1
  3. package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +2 -2
  4. package/dist/build-tools/SdCliNgRoutesFileGenerator.js +22 -13
  5. package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +1 -1
  6. package/dist/build-tools/SdLinter.js +2 -1
  7. package/dist/build-tools/SdLinter.js.map +1 -1
  8. package/dist/build-tools/SdNgBundler.d.ts +0 -1
  9. package/dist/build-tools/SdNgBundler.js +4 -2
  10. package/dist/build-tools/SdNgBundler.js.map +1 -1
  11. package/dist/build-tools/SdReactBundler.d.ts +24 -0
  12. package/dist/build-tools/SdReactBundler.js +251 -0
  13. package/dist/build-tools/SdReactBundler.js.map +1 -0
  14. package/dist/build-tools/SdReactBundlerContext.d.ts +14 -0
  15. package/dist/build-tools/SdReactBundlerContext.js +59 -0
  16. package/dist/build-tools/SdReactBundlerContext.js.map +1 -0
  17. package/dist/build-tools/SdTsCompiler.js +32 -29
  18. package/dist/build-tools/SdTsCompiler.js.map +1 -1
  19. package/dist/build-tools/SdTsLibBundler.js +4 -3
  20. package/dist/build-tools/SdTsLibBundler.js.map +1 -1
  21. package/dist/builders/SdCliClientBuilder.js +53 -32
  22. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  23. package/dist/builders/SdCliTsLibBuilder.js +8 -11
  24. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  25. package/dist/bundle-plugins/sdNgPlugin.js +21 -11
  26. package/dist/bundle-plugins/sdNgPlugin.js.map +1 -1
  27. package/dist/bundle-plugins/sdReactPlugin.d.ts +15 -0
  28. package/dist/bundle-plugins/sdReactPlugin.js +111 -0
  29. package/dist/bundle-plugins/sdReactPlugin.js.map +1 -0
  30. package/dist/commons.d.ts +1 -2
  31. package/dist/entry/SdCliProject.js +1 -0
  32. package/dist/entry/SdCliProject.js.map +1 -1
  33. package/dist/index.d.ts +3 -0
  34. package/dist/index.js +3 -0
  35. package/dist/index.js.map +1 -1
  36. package/package.json +12 -5
  37. package/src/build-tools/SdCliIndexFileGenerator.ts +10 -12
  38. package/src/build-tools/SdCliNgRoutesFileGenerator.ts +33 -22
  39. package/src/build-tools/SdLinter.ts +2 -1
  40. package/src/build-tools/SdNgBundler.ts +4 -3
  41. package/src/build-tools/SdReactBundler.ts +325 -0
  42. package/src/build-tools/SdReactBundlerContext.ts +71 -0
  43. package/src/build-tools/SdTsCompiler.ts +146 -129
  44. package/src/build-tools/SdTsLibBundler.ts +9 -13
  45. package/src/builders/SdCliClientBuilder.ts +108 -69
  46. package/src/builders/SdCliTsLibBuilder.ts +35 -32
  47. package/src/bundle-plugins/sdNgPlugin.ts +59 -56
  48. package/src/bundle-plugins/sdReactPlugin.ts +157 -0
  49. package/src/commons.ts +1 -2
  50. package/src/entry/SdCliProject.ts +1 -0
  51. package/src/index.ts +3 -0
@@ -1,19 +1,20 @@
1
- import {EventEmitter} from "events";
2
- import {FsUtil, Logger, PathUtil, SdFsWatcher} from "@simplysm/sd-core-node";
1
+ import { EventEmitter } from "events";
2
+ import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
3
3
  import {
4
4
  INpmConfig,
5
5
  ISdCliBuilderResult,
6
6
  ISdCliClientPackageConfig,
7
7
  ISdCliConfig,
8
- ISdCliPackageBuildResult
8
+ ISdCliPackageBuildResult,
9
9
  } from "../commons";
10
- import {FunctionQueue} from "@simplysm/sd-core-common";
10
+ import { FunctionQueue } from "@simplysm/sd-core-common";
11
11
  import path from "path";
12
- import {SdNgBundler} from "../build-tools/SdNgBundler";
13
- import {SdCliCordova} from "../build-tools/SdCliCordova";
14
- import {SdCliNgRoutesFileGenerator} from "../build-tools/SdCliNgRoutesFileGenerator";
15
- import {SdLinter} from "../build-tools/SdLinter";
16
- import {SdCliElectron} from "../entry/SdCliElectron";
12
+ import { SdNgBundler } from "../build-tools/SdNgBundler";
13
+ import { SdCliCordova } from "../build-tools/SdCliCordova";
14
+ import { SdCliNgRoutesFileGenerator } from "../build-tools/SdCliNgRoutesFileGenerator";
15
+ import { SdLinter } from "../build-tools/SdLinter";
16
+ import { SdCliElectron } from "../entry/SdCliElectron";
17
+ import { SdReactBundler } from "../build-tools/SdReactBundler";
17
18
 
18
19
  // import ts from "typescript";
19
20
 
@@ -21,13 +22,15 @@ export class SdCliClientBuilder extends EventEmitter {
21
22
  private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliClientBuilder"]);
22
23
  private readonly _pkgConf: ISdCliClientPackageConfig;
23
24
  private readonly _npmConf: INpmConfig;
24
- private _builders?: SdNgBundler[];
25
+ private _builders?: (SdNgBundler | SdReactBundler)[];
25
26
  private _cordova?: SdCliCordova;
26
27
 
27
28
  // #program?: ts.Program;
28
29
 
29
- public constructor(private readonly _projConf: ISdCliConfig,
30
- private readonly _pkgPath: string) {
30
+ public constructor(
31
+ private readonly _projConf: ISdCliConfig,
32
+ private readonly _pkgPath: string,
33
+ ) {
31
34
  super();
32
35
  this._pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdCliClientPackageConfig;
33
36
  this._npmConf = FsUtil.readJson(path.resolve(_pkgPath, "package.json")) as INpmConfig;
@@ -46,17 +49,17 @@ export class SdCliClientBuilder extends EventEmitter {
46
49
 
47
50
  if (this._npmConf.dependencies && Object.keys(this._npmConf.dependencies).includes("@angular/router")) {
48
51
  this._debug(`GEN routes.ts...`);
49
- await SdCliNgRoutesFileGenerator.runAsync(this._pkgPath);
52
+ await SdCliNgRoutesFileGenerator.runAsync(this._pkgPath, undefined, this._pkgConf.noLazyRoute);
50
53
  }
51
54
 
52
55
  this._debug("GEN .config...");
53
56
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
54
57
  await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
55
58
 
56
- const result = await this._runAsync({dev: false});
59
+ const result = await this._runAsync({ dev: false });
57
60
  return {
58
61
  affectedFilePaths: Array.from(result.affectedFileSet),
59
- buildResults: result.buildResults
62
+ buildResults: result.buildResults,
60
63
  };
61
64
  }
62
65
 
@@ -68,89 +71,116 @@ export class SdCliClientBuilder extends EventEmitter {
68
71
 
69
72
  if (this._npmConf.dependencies && Object.keys(this._npmConf.dependencies).includes("@angular/router")) {
70
73
  this._debug(`WATCH GEN routes.ts...`);
71
- await SdCliNgRoutesFileGenerator.watchAsync(this._pkgPath);
74
+ await SdCliNgRoutesFileGenerator.watchAsync(this._pkgPath, this._pkgConf.noLazyRoute);
72
75
  }
73
76
 
74
77
  this._debug("GEN .config...");
75
78
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
76
79
  await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
77
80
 
78
- const result = await this._runAsync({dev: true});
81
+ const result = await this._runAsync({ dev: true });
79
82
  this.emit("complete", {
80
83
  affectedFilePaths: Array.from(result.affectedFileSet),
81
- buildResults: result.buildResults
84
+ buildResults: result.buildResults,
82
85
  });
83
86
 
84
87
  this._debug("WATCH...");
85
88
  let changeFiles: string[] = [];
86
89
  const fnQ = new FunctionQueue();
87
- const watcher = SdFsWatcher
88
- .watch(Array.from(result.watchFileSet))
89
- .onChange({delay: 100}, (changeInfos) => {
90
- changeFiles.push(...changeInfos.map((item) => item.path));
90
+ const watcher = SdFsWatcher.watch(Array.from(result.watchFileSet)).onChange({ delay: 100 }, (changeInfos) => {
91
+ changeFiles.push(...changeInfos.map((item) => item.path));
91
92
 
92
- fnQ.runLast(async () => {
93
- const currChangeFiles = [...changeFiles];
94
- changeFiles = [];
93
+ fnQ.runLast(async () => {
94
+ const currChangeFiles = [...changeFiles];
95
+ changeFiles = [];
95
96
 
96
- this.emit("change");
97
+ this.emit("change");
97
98
 
98
- for (const builder of this._builders!) {
99
- // builder.removeCache(currChangeFiles);
100
- builder.markForChanges(currChangeFiles);
101
- }
99
+ for (const builder of this._builders!) {
100
+ // builder.removeCache(currChangeFiles);
101
+ builder.markForChanges(currChangeFiles);
102
+ }
102
103
 
103
- const watchResult = await this._runAsync({dev: true});
104
- this.emit("complete", {
105
- affectedFilePaths: Array.from(watchResult.affectedFileSet),
106
- buildResults: watchResult.buildResults
107
- });
108
-
109
- watcher.add(watchResult.watchFileSet);
104
+ const watchResult = await this._runAsync({ dev: true });
105
+ this.emit("complete", {
106
+ affectedFilePaths: Array.from(watchResult.affectedFileSet),
107
+ buildResults: watchResult.buildResults,
110
108
  });
109
+
110
+ watcher.add(watchResult.watchFileSet);
111
111
  });
112
+ });
112
113
  }
113
114
 
114
- private async _runAsync(opt: {
115
- dev: boolean;
116
- }): Promise<{
115
+ private async _runAsync(opt: { dev: boolean }): Promise<{
117
116
  watchFileSet: Set<string>;
118
117
  affectedFileSet: Set<string>;
119
118
  buildResults: ISdCliPackageBuildResult[];
120
119
  }> {
121
- const builderTypes = (Object.keys(this._pkgConf.builder ?? {web: {}}) as ("web" | "electron" | "cordova")[]);
120
+ const builderTypes = Object.keys(this._pkgConf.builder ?? { web: {} }) as ("web" | "electron" | "cordova")[];
122
121
  if (this._pkgConf.builder?.cordova && !this._cordova) {
123
122
  this._debug("CORDOVA 준비...");
124
123
  this._cordova = new SdCliCordova({
125
124
  pkgPath: this._pkgPath,
126
- config: this._pkgConf.builder.cordova
125
+ config: this._pkgConf.builder.cordova,
127
126
  });
128
127
  await this._cordova.initializeAsync();
129
128
  }
130
129
 
131
130
  if (!this._builders) {
132
131
  this._debug(`BUILD 준비...`);
133
- this._builders = builderTypes.map((builderType) => new SdNgBundler({
134
- dev: opt.dev,
135
- builderType: builderType,
136
- pkgPath: this._pkgPath,
137
- outputPath: builderType === "web" ? path.resolve(this._pkgPath, "dist")
138
- : builderType === "electron" && !opt.dev ? path.resolve(this._pkgPath, ".electron/src")
139
- : builderType === "cordova" && !opt.dev ? path.resolve(this._pkgPath, ".cordova/www")
140
- : path.resolve(this._pkgPath, "dist", builderType),
141
- env: {
142
- ...this._pkgConf.env,
143
- ...this._pkgConf.builder?.[builderType]?.env
144
- },
145
- browserslist: this._pkgConf.builder?.[builderType]?.browserslist,
146
- cordovaConfig: builderType === "cordova" ? this._pkgConf.builder!.cordova : undefined,
147
- }));
132
+
133
+ if (this._npmConf.dependencies && Object.keys(this._npmConf.dependencies).includes("react")) {
134
+ this._builders = builderTypes.map(
135
+ (builderType) =>
136
+ new SdReactBundler({
137
+ dev: opt.dev,
138
+ builderType: builderType,
139
+ pkgPath: this._pkgPath,
140
+ outputPath:
141
+ builderType === "web"
142
+ ? path.resolve(this._pkgPath, "dist")
143
+ : builderType === "electron" && !opt.dev
144
+ ? path.resolve(this._pkgPath, ".electron/src")
145
+ : builderType === "cordova" && !opt.dev
146
+ ? path.resolve(this._pkgPath, ".cordova/www")
147
+ : path.resolve(this._pkgPath, "dist", builderType),
148
+ env: {
149
+ ...this._pkgConf.env,
150
+ ...this._pkgConf.builder?.[builderType]?.env,
151
+ },
152
+ cordovaConfig: builderType === "cordova" ? this._pkgConf.builder!.cordova : undefined,
153
+ }),
154
+ );
155
+ } else {
156
+ this._builders = builderTypes.map(
157
+ (builderType) =>
158
+ new SdNgBundler({
159
+ dev: opt.dev,
160
+ builderType: builderType,
161
+ pkgPath: this._pkgPath,
162
+ outputPath:
163
+ builderType === "web"
164
+ ? path.resolve(this._pkgPath, "dist")
165
+ : builderType === "electron" && !opt.dev
166
+ ? path.resolve(this._pkgPath, ".electron/src")
167
+ : builderType === "cordova" && !opt.dev
168
+ ? path.resolve(this._pkgPath, ".cordova/www")
169
+ : path.resolve(this._pkgPath, "dist", builderType),
170
+ env: {
171
+ ...this._pkgConf.env,
172
+ ...this._pkgConf.builder?.[builderType]?.env,
173
+ },
174
+ cordovaConfig: builderType === "cordova" ? this._pkgConf.builder!.cordova : undefined,
175
+ }),
176
+ );
177
+ }
148
178
  }
149
179
 
150
180
  this._debug(`BUILD & CHECK...`);
151
181
  const buildResults = await Promise.all(this._builders.map((builder) => builder.bundleAsync()));
152
- const watchFileSet = new Set(buildResults.mapMany(item => Array.from(item.watchFileSet)));
153
- const affectedFileSet = new Set(buildResults.mapMany(item => Array.from(item.affectedFileSet)));
182
+ const watchFileSet = new Set(buildResults.mapMany((item) => Array.from(item.watchFileSet)));
183
+ const affectedFileSet = new Set(buildResults.mapMany((item) => Array.from(item.affectedFileSet)));
154
184
  const results = buildResults.mapMany((item) => item.results).distinct();
155
185
  const firstProgram = buildResults.first()?.program;
156
186
 
@@ -163,7 +193,10 @@ export class SdCliClientBuilder extends EventEmitter {
163
193
  // oldProgram: this.#program
164
194
  // });
165
195
  // const pkgFilePaths = filePaths.filter(item => PathUtil.isChildPath(item, this._pkgPath));
166
- const lintResults = await SdLinter.lintAsync(Array.from(affectedFileSet).filter(item => PathUtil.isChildPath(item, this._pkgPath)), firstProgram);
196
+ const lintResults = await SdLinter.lintAsync(
197
+ Array.from(affectedFileSet).filter((item) => PathUtil.isChildPath(item, this._pkgPath)),
198
+ firstProgram,
199
+ );
167
200
 
168
201
  if (!opt.dev && this._cordova) {
169
202
  this._debug("CORDOVA BUILD...");
@@ -174,25 +207,31 @@ export class SdCliClientBuilder extends EventEmitter {
174
207
  this._debug("ELECTRON BUILD...");
175
208
  await SdCliElectron.buildAsync({
176
209
  pkgPath: this._pkgPath,
177
- config: this._pkgConf.builder.electron
210
+ config: this._pkgConf.builder.electron,
178
211
  });
179
212
  }
180
213
 
181
214
  this._debug(`빌드 완료`);
182
- const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {})
183
- .mapMany((key) => FsUtil.glob(path.resolve(this._pkgPath, "../../node_modules", key)));
184
- const currWatchFileSet = new Set(Array.from(watchFileSet).filter(item =>
185
- PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
186
- localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu))
187
- ));
215
+ const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
216
+ FsUtil.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
217
+ );
218
+ const currWatchFileSet = new Set(
219
+ Array.from(watchFileSet).filter(
220
+ (item) =>
221
+ PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
222
+ localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu)),
223
+ ),
224
+ );
188
225
  return {
189
226
  watchFileSet: currWatchFileSet,
190
227
  affectedFileSet,
191
- buildResults: [...results, ...lintResults].filter(item => item.filePath !== path.resolve(this._pkgPath, "src/routes.ts"))
228
+ buildResults: [...results, ...lintResults].filter(
229
+ (item) => item.filePath !== path.resolve(this._pkgPath, "src/routes.ts"),
230
+ ),
192
231
  };
193
232
  }
194
233
 
195
234
  private _debug(msg: string): void {
196
235
  this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
197
236
  }
198
- }
237
+ }
@@ -1,11 +1,11 @@
1
- import {FsUtil, Logger, PathUtil, SdFsWatcher} from "@simplysm/sd-core-node";
1
+ import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
2
2
  import path from "path";
3
- import {ISdCliBuilderResult, ISdCliConfig, ISdCliLibPackageConfig, ISdCliPackageBuildResult} from "../commons";
4
- import {EventEmitter} from "events";
5
- import {SdTsLibBundler} from "../build-tools/SdTsLibBundler";
6
- import {SdLinter} from "../build-tools/SdLinter";
7
- import {FunctionQueue} from "@simplysm/sd-core-common";
8
- import {SdCliIndexFileGenerator} from "../build-tools/SdCliIndexFileGenerator";
3
+ import { ISdCliBuilderResult, ISdCliConfig, ISdCliLibPackageConfig, ISdCliPackageBuildResult } from "../commons";
4
+ import { EventEmitter } from "events";
5
+ import { SdTsLibBundler } from "../build-tools/SdTsLibBundler";
6
+ import { SdLinter } from "../build-tools/SdLinter";
7
+ import { FunctionQueue } from "@simplysm/sd-core-common";
8
+ import { SdCliIndexFileGenerator } from "../build-tools/SdCliIndexFileGenerator";
9
9
 
10
10
  export class SdCliTsLibBuilder extends EventEmitter {
11
11
  readonly #logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
@@ -16,8 +16,7 @@ export class SdCliTsLibBuilder extends EventEmitter {
16
16
 
17
17
  #bundler?: SdTsLibBundler;
18
18
 
19
- public constructor(projConf: ISdCliConfig,
20
- pkgPath: string) {
19
+ public constructor(projConf: ISdCliConfig, pkgPath: string) {
21
20
  super();
22
21
  this.#projConf = projConf;
23
22
  this.#pkgPath = pkgPath;
@@ -44,7 +43,7 @@ export class SdCliTsLibBuilder extends EventEmitter {
44
43
  const result = await this._runAsync(false);
45
44
  return {
46
45
  affectedFilePaths: Array.from(result.affectedFileSet),
47
- buildResults: result.buildResults
46
+ buildResults: result.buildResults,
48
47
  };
49
48
  }
50
49
 
@@ -62,28 +61,26 @@ export class SdCliTsLibBuilder extends EventEmitter {
62
61
  const result = await this._runAsync(true);
63
62
  this.emit("complete", {
64
63
  affectedFilePaths: Array.from(result.affectedFileSet),
65
- buildResults: result.buildResults
64
+ buildResults: result.buildResults,
66
65
  });
67
66
 
68
67
  this._debug("WATCH...");
69
68
  const fnQ = new FunctionQueue();
70
- const watcher = SdFsWatcher
71
- .watch(Array.from(result.watchFileSet))
72
- .onChange({delay: 100,}, (changeInfos) => {
73
- this.#bundler!.markChanges(new Set(changeInfos.map((item) => item.path)));
69
+ const watcher = SdFsWatcher.watch(Array.from(result.watchFileSet)).onChange({ delay: 100 }, (changeInfos) => {
70
+ this.#bundler!.markChanges(new Set(changeInfos.map((item) => item.path)));
74
71
 
75
- fnQ.runLast(async () => {
76
- this.emit("change");
72
+ fnQ.runLast(async () => {
73
+ this.emit("change");
77
74
 
78
- const watchResult = await this._runAsync(true);
79
- this.emit("complete", {
80
- affectedFilePaths: Array.from(watchResult.affectedFileSet),
81
- buildResults: watchResult.buildResults
82
- });
83
-
84
- watcher.add(watchResult.watchFileSet);
75
+ const watchResult = await this._runAsync(true);
76
+ this.emit("complete", {
77
+ affectedFilePaths: Array.from(watchResult.affectedFileSet),
78
+ buildResults: watchResult.buildResults,
85
79
  });
80
+
81
+ watcher.add(watchResult.watchFileSet);
86
82
  });
83
+ });
87
84
  }
88
85
 
89
86
  private async _runAsync(dev: boolean): Promise<{
@@ -96,21 +93,27 @@ export class SdCliTsLibBuilder extends EventEmitter {
96
93
  const buildResult = await this.#bundler.buildAsync();
97
94
 
98
95
  this._debug("LINT...");
99
- const lintFilePaths = Array.from(buildResult.affectedFileSet).filter(item => PathUtil.isChildPath(item, this.#pkgPath));
96
+ const lintFilePaths = Array.from(buildResult.affectedFileSet).filter((item) =>
97
+ PathUtil.isChildPath(item, this.#pkgPath),
98
+ );
100
99
  const lintResults = await SdLinter.lintAsync(lintFilePaths, buildResult.program);
101
100
 
102
101
  this._debug(`빌드 완료`);
103
- const localUpdatePaths = Object.keys(this.#projConf.localUpdates ?? {})
104
- .mapMany((key) => FsUtil.glob(path.resolve(this.#pkgPath, "../../node_modules", key)));
105
- const watchFileSet = new Set(Array.from(buildResult.watchFileSet).filter(item =>
106
- PathUtil.isChildPath(item, path.resolve(this.#pkgPath, "../")) ||
107
- localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu))
108
- ));
102
+ const localUpdatePaths = Object.keys(this.#projConf.localUpdates ?? {}).mapMany((key) =>
103
+ FsUtil.glob(path.resolve(this.#pkgPath, "../../node_modules", key)),
104
+ );
105
+ const watchFileSet = new Set(
106
+ Array.from(buildResult.watchFileSet).filter(
107
+ (item) =>
108
+ PathUtil.isChildPath(item, path.resolve(this.#pkgPath, "../")) ||
109
+ localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu)),
110
+ ),
111
+ );
109
112
 
110
113
  return {
111
114
  watchFileSet,
112
115
  affectedFileSet: buildResult.affectedFileSet,
113
- buildResults: [...buildResult.results, ...lintResults]
116
+ buildResults: [...buildResult.results, ...lintResults],
114
117
  };
115
118
  }
116
119
 
@@ -2,9 +2,9 @@ import esbuild from "esbuild";
2
2
  import ts from "typescript";
3
3
  import path from "path";
4
4
  import os from "os";
5
- import {ISdTsCompilerResult, SdTsCompiler} from "../build-tools/SdTsCompiler";
6
- import {JavaScriptTransformer} from "@angular/build/src/tools/esbuild/javascript-transformer";
7
- import {convertTypeScriptDiagnostic} from "@angular/build/src/tools/esbuild/angular/diagnostics";
5
+ import { ISdTsCompilerResult, SdTsCompiler } from "../build-tools/SdTsCompiler";
6
+ import { JavaScriptTransformer } from "@angular/build/src/tools/esbuild/javascript-transformer";
7
+ import { convertTypeScriptDiagnostic } from "@angular/build/src/tools/esbuild/angular/diagnostics";
8
8
 
9
9
  export function sdNgPlugin(conf: {
10
10
  pkgPath: string;
@@ -15,18 +15,21 @@ export function sdNgPlugin(conf: {
15
15
  return {
16
16
  name: "sd-ng-compiler",
17
17
  setup: (build: esbuild.PluginBuild) => {
18
- const compiler = new SdTsCompiler(conf.pkgPath, {declaration: false}, conf.dev);
18
+ const compiler = new SdTsCompiler(conf.pkgPath, { declaration: false }, conf.dev);
19
19
 
20
20
  let buildResult: ISdTsCompilerResult;
21
21
  const outputContentsCacheMap = new Map<string, Uint8Array>();
22
22
 
23
23
  //-- js babel transformer
24
- const javascriptTransformer = new JavaScriptTransformer({
25
- thirdPartySourcemaps: conf.dev,
26
- sourcemap: true, //conf.dev,
27
- jit: false,
28
- advancedOptimizations: true
29
- }, os.cpus().length);
24
+ const javascriptTransformer = new JavaScriptTransformer(
25
+ {
26
+ thirdPartySourcemaps: conf.dev,
27
+ sourcemap: true, //conf.dev,
28
+ jit: false,
29
+ advancedOptimizations: true,
30
+ },
31
+ os.cpus().length,
32
+ );
30
33
 
31
34
  //---------------------------
32
35
 
@@ -45,20 +48,24 @@ export function sdNgPlugin(conf: {
45
48
  //-- return err/warn
46
49
  return {
47
50
  errors: [
48
- ...buildResult.typescriptDiagnostics.filter(item => item.category === ts.DiagnosticCategory.Error).map(item => convertTypeScriptDiagnostic(ts, item)),
49
- ...Array.from(buildResult.stylesheetBundlingResultMap.values()).flatMap(item => item.errors)
51
+ ...buildResult.typescriptDiagnostics
52
+ .filter((item) => item.category === ts.DiagnosticCategory.Error)
53
+ .map((item) => convertTypeScriptDiagnostic(ts, item)),
54
+ ...Array.from(buildResult.stylesheetBundlingResultMap.values()).flatMap((item) => item.errors),
50
55
  ].filterExists(),
51
56
  warnings: [
52
- ...buildResult.typescriptDiagnostics.filter(item => item.category !== ts.DiagnosticCategory.Error).map(item => convertTypeScriptDiagnostic(ts, item)),
57
+ ...buildResult.typescriptDiagnostics
58
+ .filter((item) => item.category !== ts.DiagnosticCategory.Error)
59
+ .map((item) => convertTypeScriptDiagnostic(ts, item)),
53
60
  // ...Array.from(buildResult.stylesheetResultMap.values()).flatMap(item => item.warnings)
54
61
  ],
55
62
  };
56
63
  });
57
64
 
58
- build.onLoad({filter: /\.ts$/}, async (args) => {
65
+ build.onLoad({ filter: /\.ts$/ }, async (args) => {
59
66
  const output = outputContentsCacheMap.get(path.normalize(args.path));
60
67
  if (output != null) {
61
- return {contents: output, loader: "js"};
68
+ return { contents: output, loader: "js" };
62
69
  }
63
70
 
64
71
  const emittedJsFile = buildResult.emittedFilesCacheMap.get(path.normalize(args.path))?.last();
@@ -68,69 +75,65 @@ export function sdNgPlugin(conf: {
68
75
 
69
76
  const contents = emittedJsFile.text;
70
77
 
71
- const {sideEffects} = await build.resolve(args.path, {
72
- kind: 'import-statement',
73
- resolveDir: build.initialOptions.absWorkingDir ?? '',
78
+ const { sideEffects } = await build.resolve(args.path, {
79
+ kind: "import-statement",
80
+ resolveDir: build.initialOptions.absWorkingDir ?? "",
74
81
  });
75
82
 
76
- const newContents = await javascriptTransformer.transformData(
77
- args.path,
78
- contents,
79
- true,
80
- sideEffects
81
- );
83
+ const newContents = await javascriptTransformer.transformData(args.path, contents, true, sideEffects);
82
84
 
83
85
  outputContentsCacheMap.set(path.normalize(args.path), newContents);
84
86
 
85
- return {contents: newContents, loader: "js"};
87
+ return { contents: newContents, loader: "js" };
86
88
  });
87
89
 
88
- build.onLoad(
89
- {filter: /\.[cm]?js$/},
90
- async (args) => {
91
- conf.result.watchFileSet!.add(path.normalize(args.path));
90
+ build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
91
+ conf.result.watchFileSet!.add(path.normalize(args.path));
92
92
 
93
- const output = outputContentsCacheMap.get(path.normalize(args.path));
94
- if (output != null) {
95
- return {contents: output, loader: "js"};
96
- }
93
+ const output = outputContentsCacheMap.get(path.normalize(args.path));
94
+ if (output != null) {
95
+ return { contents: output, loader: "js" };
96
+ }
97
97
 
98
- const {sideEffects} = await build.resolve(args.path, {
99
- kind: 'import-statement',
100
- resolveDir: build.initialOptions.absWorkingDir ?? '',
101
- });
98
+ const { sideEffects } = await build.resolve(args.path, {
99
+ kind: "import-statement",
100
+ resolveDir: build.initialOptions.absWorkingDir ?? "",
101
+ });
102
102
 
103
- const newContents = await javascriptTransformer.transformFile(
104
- args.path,
105
- false,
106
- sideEffects
107
- );
103
+ const newContents = await javascriptTransformer.transformFile(args.path, false, sideEffects);
108
104
 
109
- outputContentsCacheMap.set(path.normalize(args.path), newContents);
105
+ outputContentsCacheMap.set(path.normalize(args.path), newContents);
110
106
 
111
- return {
112
- contents: newContents,
113
- loader: 'js',
114
- };
115
- }
116
- );
107
+ return {
108
+ contents: newContents,
109
+ loader: "js",
110
+ };
111
+ });
117
112
 
118
113
  build.onLoad(
119
- {filter: new RegExp("(" + Object.keys(build.initialOptions.loader!).map(item => "\\" + item).join("|") + ")$")},
114
+ {
115
+ filter: new RegExp(
116
+ "(" +
117
+ Object.keys(build.initialOptions.loader!)
118
+ .map((item) => "\\" + item)
119
+ .join("|") +
120
+ ")$",
121
+ ),
122
+ },
120
123
  (args) => {
121
124
  conf.result.watchFileSet!.add(path.normalize(args.path));
122
125
  return null;
123
- }
126
+ },
124
127
  );
125
128
 
126
129
  build.onEnd((result) => {
127
- for (const {outputFiles, metafile} of buildResult.stylesheetBundlingResultMap.values()) {
130
+ for (const { outputFiles, metafile } of buildResult.stylesheetBundlingResultMap.values()) {
128
131
  result.outputFiles = result.outputFiles ?? [];
129
132
  result.outputFiles.push(...outputFiles);
130
133
 
131
134
  if (result.metafile && metafile) {
132
- result.metafile.inputs = {...result.metafile.inputs, ...metafile.inputs};
133
- result.metafile.outputs = {...result.metafile.outputs, ...metafile.outputs};
135
+ result.metafile.inputs = { ...result.metafile.inputs, ...metafile.inputs };
136
+ result.metafile.outputs = { ...result.metafile.outputs, ...metafile.outputs };
134
137
  }
135
138
  }
136
139
 
@@ -139,7 +142,7 @@ export function sdNgPlugin(conf: {
139
142
 
140
143
  conf.modifiedFileSet.clear();
141
144
  });
142
- }
145
+ },
143
146
  };
144
147
  }
145
148
 
@@ -149,4 +152,4 @@ export interface INgPluginResultCache {
149
152
  program?: ts.Program;
150
153
  outputFiles?: esbuild.OutputFile[];
151
154
  metafile?: esbuild.Metafile;
152
- }
155
+ }