@simplysm/sd-cli 11.0.12 → 11.0.14

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 (35) hide show
  1. package/dist/build-tools/SdLinter.js +2 -2
  2. package/dist/build-tools/SdLinter.js.map +1 -1
  3. package/dist/build-tools/SdNgBundler.d.ts +2 -3
  4. package/dist/build-tools/SdNgBundler.js +59 -74
  5. package/dist/build-tools/SdNgBundler.js.map +1 -1
  6. package/dist/build-tools/SdNgBundlerContext.d.ts +16 -0
  7. package/dist/build-tools/SdNgBundlerContext.js +98 -0
  8. package/dist/build-tools/SdNgBundlerContext.js.map +1 -0
  9. package/dist/build-tools/SdTsBundler.js +4 -4
  10. package/dist/build-tools/SdTsBundler.js.map +1 -1
  11. package/dist/builders/SdCliClientBuilder.js +2 -2
  12. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  13. package/dist/entry/SdCliProject.js +20 -15
  14. package/dist/entry/SdCliProject.js.map +1 -1
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +1 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/utils/SdCliBuildResultUtil.js +3 -3
  19. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  20. package/dist/utils/SdMemoryLoadResultCache.js +1 -5
  21. package/dist/utils/SdMemoryLoadResultCache.js.map +1 -1
  22. package/dist/utils/SdSourceFileCache.d.ts +2 -1
  23. package/dist/utils/SdSourceFileCache.js +7 -1
  24. package/dist/utils/SdSourceFileCache.js.map +1 -1
  25. package/package.json +11 -11
  26. package/src/build-tools/SdLinter.ts +2 -2
  27. package/src/build-tools/SdNgBundler.ts +215 -234
  28. package/src/build-tools/SdNgBundlerContext.ts +116 -0
  29. package/src/build-tools/SdTsBundler.ts +4 -4
  30. package/src/builders/SdCliClientBuilder.ts +2 -2
  31. package/src/entry/SdCliProject.ts +22 -15
  32. package/src/index.ts +1 -0
  33. package/src/utils/SdCliBuildResultUtil.ts +3 -3
  34. package/src/utils/SdMemoryLoadResultCache.ts +1 -5
  35. package/src/utils/SdSourceFileCache.ts +9 -1
@@ -0,0 +1,116 @@
1
+ import esbuild from "esbuild";
2
+ import path from "path";
3
+ import {InitialFileRecord} from "@angular-devkit/build-angular/src/tools/esbuild/bundler-context";
4
+ import {ISdCliPackageBuildResult} from "../commons";
5
+
6
+ export class SdNgBundlerContext {
7
+ private _context?: esbuild.BuildContext;
8
+
9
+ public constructor(private readonly _pkgPath: string,
10
+ private readonly _esbuildOptions: esbuild.BuildOptions) {
11
+ }
12
+
13
+ public async bundleAsync() {
14
+ if (this._context == null) {
15
+ this._context = await esbuild.context(this._esbuildOptions);
16
+ }
17
+
18
+ let buildResult: esbuild.BuildResult;
19
+
20
+ try {
21
+ buildResult = await this._context.rebuild();
22
+ }
23
+ catch (err) {
24
+ if ("warnings" in err || "errors" in err) {
25
+ buildResult = err;
26
+ }
27
+ else {
28
+ throw err;
29
+ }
30
+ }
31
+
32
+ const results = [
33
+ ...buildResult.warnings.map((warn) => ({
34
+ filePath: warn.location?.file !== undefined ? path.resolve(this._pkgPath, warn.location.file) : undefined,
35
+ line: warn.location?.line,
36
+ char: warn.location?.column,
37
+ code: warn.text.slice(0, warn.text.indexOf(":")),
38
+ severity: "warning",
39
+ message: `(${warn.pluginName}) ${warn.text.slice(warn.text.indexOf(":") + 1)}`,
40
+ type: "build"
41
+ })),
42
+ ...buildResult.errors?.map((err) => ({
43
+ filePath: err.location?.file !== undefined ? path.resolve(this._pkgPath, err.location.file) : undefined,
44
+ line: err.location?.line,
45
+ char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
46
+ code: err.text.slice(0, err.text.indexOf(":")),
47
+ severity: "error",
48
+ message: `(${err.pluginName}) ${err.text.slice(err.text.indexOf(":") + 1)}`,
49
+ type: "build"
50
+ }))
51
+ ] as ISdCliPackageBuildResult[];
52
+
53
+ const initialFiles = new Map<string, InitialFileRecord>();
54
+
55
+ for (const outputFile of buildResult.outputFiles ?? []) {
56
+ const relativeFilePath = path.relative(this._pkgPath, outputFile.path);
57
+ const entryPoint = buildResult.metafile?.outputs[relativeFilePath]?.entryPoint;
58
+
59
+ outputFile.path = relativeFilePath;
60
+
61
+ if (entryPoint != null) {
62
+ const name = path.basename(relativeFilePath).split('.', 1)[0];
63
+ const type = path.extname(relativeFilePath) === '.css' ? 'style' : 'script';
64
+
65
+ if (this._esbuildOptions.entryPoints?.[name] != null) {
66
+ initialFiles.set(relativeFilePath, {
67
+ name,
68
+ type,
69
+ entrypoint: true,
70
+ });
71
+ }
72
+ }
73
+ }
74
+
75
+ const files = [...initialFiles.keys()];
76
+ for (const file of files) {
77
+ for (const initialImport of buildResult.metafile?.outputs[file]?.imports ?? []) {
78
+ if (initialFiles.has(initialImport.path)) {
79
+ continue;
80
+ }
81
+
82
+ if (initialImport.kind === 'import-statement' || initialImport.kind === 'import-rule') {
83
+ const record: InitialFileRecord = {
84
+ type: initialImport.kind === 'import-rule' ? 'style' : 'script',
85
+ entrypoint: false,
86
+ external: initialImport.external,
87
+ };
88
+
89
+ initialFiles.set(initialImport.path, record);
90
+
91
+ if (!initialImport.external) {
92
+ files.push(initialImport.path);
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ const dependencyMap = new Map<string, Set<string>>();
99
+ if (buildResult.metafile) {
100
+ for (const [key, val] of Object.entries(buildResult.metafile.inputs)) {
101
+ for (const imp of val.imports) {
102
+ const deps = dependencyMap.getOrCreate(path.resolve(this._pkgPath, imp.path), new Set<string>());
103
+ deps.add(path.resolve(this._pkgPath, key));
104
+ }
105
+ }
106
+ }
107
+
108
+ return {
109
+ results,
110
+ initialFiles,
111
+ outputFiles: buildResult.outputFiles,
112
+ dependencyMap,
113
+ metafile: buildResult.metafile
114
+ };
115
+ }
116
+ }
@@ -88,18 +88,18 @@ const __dirname = __path__.dirname(__filename);`.trim()
88
88
  filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
89
89
  line: warn.location?.line,
90
90
  char: warn.location?.column,
91
- code: undefined,
91
+ code: warn.text.slice(0, warn.text.indexOf(":")),
92
92
  severity: "warning" as const,
93
- message: warn.text
93
+ message: `(${warn.pluginName}) ${warn.text.slice(warn.text.indexOf(":") + 1)}`,
94
94
  })),
95
95
  ...result.errors.map((err) => ({
96
96
  type: "build" as const,
97
97
  filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
98
98
  line: err.location?.line,
99
99
  char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
100
- code: undefined,
100
+ code: err.text.slice(0, err.text.indexOf(":")),
101
101
  severity: "error" as const,
102
- message: err.text
102
+ message: `(${err.pluginName}) ${err.text.slice(err.text.indexOf(":") + 1)}`,
103
103
  }))
104
104
  ]
105
105
  };
@@ -101,7 +101,6 @@ export class SdCliClientBuilder extends EventEmitter {
101
101
  dev: opt.dev,
102
102
  builderType: builderType,
103
103
  pkgPath: this._pkgPath,
104
- cordovaPlatforms: builderType === "cordova" ? Object.keys(this._pkgConf.builder!.cordova!.platform ?? {browser: {}}) : undefined,
105
104
  outputPath: builderType === "web" ? path.resolve(this._pkgPath, "dist")
106
105
  : builderType === "electron" ? path.resolve(this._pkgPath, ".electron/src")
107
106
  : builderType === "cordova" && !opt.dev ? path.resolve(this._pkgPath, ".cordova/www")
@@ -109,7 +108,8 @@ export class SdCliClientBuilder extends EventEmitter {
109
108
  env: {
110
109
  ...this._pkgConf.env,
111
110
  ...this._pkgConf.builder?.[builderType]?.env
112
- }
111
+ },
112
+ cordovaConfig: builderType === "cordova" ? this._pkgConf.builder!.cordova : undefined,
113
113
  }));
114
114
  }
115
115
 
@@ -67,6 +67,7 @@ export class SdCliProject {
67
67
  worker?: cp.ChildProcess; // persist
68
68
  port?: number;
69
69
  hasChanges: boolean;
70
+ hasClientChanges: boolean;
70
71
 
71
72
  //client
72
73
  pathProxy: Record<string, string | number | undefined>; // persist
@@ -95,6 +96,7 @@ export class SdCliProject {
95
96
  const pkgName = path.basename(message.req.pkgPath);
96
97
  const serverInfo = serverInfoMap.getOrCreate(pkgName, {
97
98
  hasChanges: false,
99
+ hasClientChanges: false,
98
100
  pathProxy: {},
99
101
  // changeFilePaths: []
100
102
  });
@@ -108,25 +110,28 @@ export class SdCliProject {
108
110
  if (pkgConf.server !== undefined) {
109
111
  const serverInfo = serverInfoMap.getOrCreate(pkgConf.server, {
110
112
  hasChanges: false,
113
+ hasClientChanges: false,
111
114
  pathProxy: {},
112
115
  // changeFilePaths: []
113
116
  });
114
117
  serverInfo.pathProxy[pkgName] = path.resolve(message.req.pkgPath, "dist");
115
- //message.result!.port;
116
118
  // serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
117
119
 
118
- serverInfo.worker?.send({type: "broadcastReload"});
120
+ serverInfo.hasClientChanges = true;
121
+ // serverInfo.worker?.send({type: "broadcastReload"});
119
122
  }
120
123
  else {
121
124
  const serverInfo = serverInfoMap.getOrCreate(pkgName, {
122
125
  hasChanges: false,
126
+ hasClientChanges: false,
123
127
  pathProxy: {},
124
128
  // changeFilePaths: []
125
129
  });
126
130
  serverInfo.port = message.result!.port;
127
131
  // serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
128
132
 
129
- serverInfo.worker?.send({type: "broadcastReload"});
133
+ serverInfo.hasClientChanges = true;
134
+ // serverInfo.worker?.send({type: "broadcastReload"});
130
135
  }
131
136
  }
132
137
 
@@ -158,6 +163,11 @@ export class SdCliProject {
158
163
  type: "setPathProxy",
159
164
  pathProxy: serverInfo.pathProxy
160
165
  });
166
+
167
+ if (serverInfo.hasClientChanges) {
168
+ logger.debug("클라이언트 새로고침...");
169
+ serverInfo.worker.send({type: "broadcastReload"});
170
+ }
161
171
  }
162
172
  }
163
173
 
@@ -448,22 +458,19 @@ export class SdCliProject {
448
458
  }
449
459
 
450
460
  private static _logging(buildResults: ISdCliPackageBuildResult[], logger: Logger): void {
451
- const messages = buildResults.filter((item) => item.severity === "message").distinct();
452
- const suggestions = buildResults.filter((item) => item.severity === "suggestion").distinct();
453
- const warnings = buildResults.filter((item) => item.severity === "warning").distinct();
454
- const errors = buildResults.filter((item) => item.severity === "error").distinct();
461
+ const messageMap = buildResults.toSetMap(item => item.severity, item => SdCliBuildResultUtil.getMessage(item));
455
462
 
456
- if (messages.length > 0) {
457
- logger.log("\n" + messages.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
463
+ if (messageMap.has("message")) {
464
+ logger.log(`알림\n${[...messageMap.get("message")!].join("\n")}`);
458
465
  }
459
- if (suggestions.length > 0) {
460
- logger.info("\n" + suggestions.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
466
+ if (messageMap.has("suggestion")) {
467
+ logger.info(`제안\n${[...messageMap.get("suggestion")!].join("\n")}`);
461
468
  }
462
- if (warnings.length > 0) {
463
- logger.warn("\n" + warnings.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
469
+ if (messageMap.has("warning")) {
470
+ logger.warn(`경고\n${[...messageMap.get("warning")!].join("\n")}`);
464
471
  }
465
- if (errors.length > 0) {
466
- logger.error("\n" + errors.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
472
+ if (messageMap.has("error")) {
473
+ logger.error(`오류\n${[...messageMap.get("error")!].join("\n")}`);
467
474
  }
468
475
 
469
476
  logger.info("모든 빌드가 완료되었습니다.");
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./build-tools/SdCliIndexFileGenerator";
3
3
  export * from "./build-tools/SdCliNgRoutesFileGenerator";
4
4
  export * from "./build-tools/SdLinter";
5
5
  export * from "./build-tools/SdNgBundler";
6
+ export * from "./build-tools/SdNgBundlerContext";
6
7
  export * from "./build-tools/SdTsBundler";
7
8
  export * from "./build-tools/SdTsCompiler";
8
9
  export * from "./builders/SdCliClientBuilder";
@@ -34,9 +34,9 @@ export class SdCliBuildResultUtil {
34
34
  if (result.filePath !== undefined) {
35
35
  str += `${result.filePath}(${result.line ?? 0}, ${result.char ?? 0}): `;
36
36
  }
37
- // if (result.code !== undefined) {
38
- // str += `${result.code}: `;
39
- // }
37
+ if (result.code !== undefined) {
38
+ str += `${result.code}: `;
39
+ }
40
40
  str += `(${result.type}) ${result.severity} ${result.message}`;
41
41
 
42
42
  return str;
@@ -16,11 +16,7 @@ export class SdMemoryLoadResultCache extends MemoryLoadResultCache {
16
16
  for (const watchFile of result.watchFiles) {
17
17
  // Normalize the watch file path to ensure OS consistent paths
18
18
  const watchFilePath = path.resolve(watchFile);
19
- let affected = this.fileDependencies.get(watchFilePath);
20
- if (affected === undefined) {
21
- affected = new Set();
22
- this.fileDependencies.set(watchFilePath, affected);
23
- }
19
+ let affected = this.fileDependencies.getOrCreate(watchFilePath, new Set());
24
20
  affected.add(putPath);
25
21
  }
26
22
  }
@@ -1,6 +1,14 @@
1
- import {SourceFileCache} from "@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin";
2
1
  import {SdMemoryLoadResultCache} from "./SdMemoryLoadResultCache";
2
+ import {SourceFileCache} from "@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin";
3
3
 
4
4
  export class SdSourceFileCache extends SourceFileCache {
5
5
  override readonly loadResultCache = new SdMemoryLoadResultCache();
6
+
7
+ override invalidate(files: Iterable<string>): void {
8
+ super.invalidate(files);
9
+
10
+ for (let file of files) {
11
+ this.loadResultCache.invalidate(file);
12
+ }
13
+ }
6
14
  }