@simplysm/sd-cli 10.0.36 → 10.0.39

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 (87) hide show
  1. package/dist/SdLinter.js.map +1 -1
  2. package/dist/SdTsIncrementalBuilder.d.ts +17 -4
  3. package/dist/SdTsIncrementalBuilder.js +29 -33
  4. package/dist/SdTsIncrementalBuilder.js.map +1 -1
  5. package/dist/build-cluster.js +98 -30
  6. package/dist/build-cluster.js.map +1 -1
  7. package/dist/builders/SdCliClientBuilder.d.ts +6 -2
  8. package/dist/builders/SdCliClientBuilder.js +107 -97
  9. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  10. package/dist/builders/SdCliJsLibLinter.js.map +1 -1
  11. package/dist/builders/SdCliServerBuilder.d.ts +2 -1
  12. package/dist/builders/SdCliServerBuilder.js +68 -13
  13. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  14. package/dist/builders/SdCliTsLibBuilder.d.ts +5 -2
  15. package/dist/builders/SdCliTsLibBuilder.js +64 -10
  16. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  17. package/dist/commons.d.ts +28 -2
  18. package/dist/commons.js.map +1 -1
  19. package/dist/entry/SdCliElectron.d.ts +7 -0
  20. package/dist/entry/SdCliElectron.js +42 -0
  21. package/dist/entry/SdCliElectron.js.map +1 -0
  22. package/dist/entry/SdCliLocalUpdate.d.ts +3 -3
  23. package/dist/entry/SdCliLocalUpdate.js +20 -26
  24. package/dist/entry/SdCliLocalUpdate.js.map +1 -1
  25. package/dist/entry/SdCliProject.d.ts +3 -3
  26. package/dist/entry/SdCliProject.js +87 -36
  27. package/dist/entry/SdCliProject.js.map +1 -1
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.js +2 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/sd-cli.d.ts +1 -1
  32. package/dist/sd-cli.js +62 -16
  33. package/dist/sd-cli.js.map +1 -1
  34. package/dist/server-worker.js.map +1 -1
  35. package/dist/utils/SdCliBuildResultUtil.js +1 -1
  36. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  37. package/dist/utils/SdCliViteElectronMainPlugin.d.ts +6 -0
  38. package/dist/utils/SdCliViteElectronMainPlugin.js +81 -0
  39. package/dist/utils/SdCliViteElectronMainPlugin.js.map +1 -0
  40. package/dist/utils/SdCliViteExternalPlugin.d.ts +7 -0
  41. package/dist/utils/SdCliViteExternalPlugin.js +98 -0
  42. package/dist/utils/SdCliViteExternalPlugin.js.map +1 -0
  43. package/dist/utils/SdCliViteLoggerPlugin.d.ts +6 -0
  44. package/dist/utils/SdCliViteLoggerPlugin.js +24 -0
  45. package/dist/utils/SdCliViteLoggerPlugin.js.map +1 -0
  46. package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +2 -0
  47. package/dist/utils/SdCliViteNodeGlobalPlugin.js +29 -0
  48. package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +1 -0
  49. package/dist/utils/SdCliViteReactSwcPlugin.d.ts +2 -0
  50. package/dist/utils/SdCliViteReactSwcPlugin.js +141 -0
  51. package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -0
  52. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.d.ts +2 -0
  53. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js +26 -0
  54. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js.map +1 -0
  55. package/dist/utils/getElectronReactExternals.d.ts +1 -0
  56. package/dist/utils/getElectronReactExternals.js +17 -0
  57. package/dist/utils/getElectronReactExternals.js.map +1 -0
  58. package/dist/utils/sdCliTsDefineTransformer.d.ts +4 -0
  59. package/dist/utils/sdCliTsDefineTransformer.js +26 -0
  60. package/dist/utils/sdCliTsDefineTransformer.js.map +1 -0
  61. package/package.json +25 -10
  62. package/src/SdLinter.ts +2 -2
  63. package/src/SdTsIncrementalBuilder.ts +116 -94
  64. package/src/build-cluster.ts +173 -111
  65. package/src/builders/SdCliClientBuilder.ts +226 -204
  66. package/src/builders/SdCliServerBuilder.ts +311 -240
  67. package/src/builders/SdCliTsLibBuilder.ts +160 -89
  68. package/src/commons.ts +66 -34
  69. package/src/entry/SdCliElectron.ts +55 -0
  70. package/src/entry/SdCliLocalUpdate.ts +104 -101
  71. package/src/entry/SdCliProject.ts +452 -401
  72. package/src/index.ts +1 -0
  73. package/src/sd-cli.ts +185 -141
  74. package/src/utils/SdCliBuildResultUtil.ts +1 -2
  75. package/src/utils/SdCliViteElectronMainPlugin.ts +86 -0
  76. package/src/utils/SdCliViteExternalPlugin.ts +112 -0
  77. package/src/utils/SdCliViteLoggerPlugin.ts +29 -0
  78. package/src/utils/SdCliViteNodeGlobalPlugin.ts +31 -0
  79. package/src/utils/SdCliViteReactSwcPlugin.ts +154 -0
  80. package/src/utils/SdCliViteWatchWithResolutionsPlugin.ts +29 -0
  81. package/src/utils/getElectronReactExternals.ts +19 -0
  82. package/src/utils/sdCliTsDefineTransformer.ts +31 -0
  83. package/.eslintrc.cjs +0 -18
  84. package/dist/utils/SdCliConfigUtil.d.ts +0 -7
  85. package/dist/utils/SdCliConfigUtil.js +0 -69
  86. package/dist/utils/SdCliConfigUtil.js.map +0 -1
  87. package/src/utils/SdCliConfigUtil.ts +0 -94
@@ -1,58 +1,68 @@
1
- import { EventEmitter } from "events";
2
- import { FsUtil, Logger } from "@simplysm/sd-core-node";
3
- import { INpmConfig, ISdCliBuilderResult, ISdCliServerPackageConfig } from "../commons";
1
+ import {EventEmitter} from "events";
2
+ import {FsUtil, Logger} from "@simplysm/sd-core-node";
3
+ import {INpmConfig, ISdCliBuilderResult, ISdCliServerPackageConfig} from "../commons";
4
4
  import esbuild from "esbuild";
5
5
  import path from "path";
6
- import { SdTsIncrementalBuilder } from "../SdTsIncrementalBuilder";
7
- import { SdLinter } from "../SdLinter";
8
- import { StringUtil } from "@simplysm/sd-core-common";
6
+ import {SdTsIncrementalBuilder} from "../SdTsIncrementalBuilder";
7
+ import {SdLinter} from "../SdLinter";
8
+ import {StringUtil} from "@simplysm/sd-core-common";
9
+ import esbuildPluginTsc from 'esbuild-plugin-tsc';
9
10
 
10
11
  export class SdCliServerBuilder extends EventEmitter {
11
- private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuilder"]);
12
-
13
- public constructor(private readonly _pkgPath: string,
14
- private readonly _pkgConf: ISdCliServerPackageConfig) {
15
- super();
16
- }
17
-
18
- public override on(event: "change", listener: () => void): this;
19
- public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
20
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
21
- super.on(event, listener);
22
- return this;
23
- }
24
-
25
- public async watchAsync(): Promise<void> {
26
- this._debug("빌드 준비...");
27
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, false);
28
-
29
- this._debug("dist 초기화...");
30
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
31
-
32
- this.emit("change");
33
-
34
- this._debug(`BUILD...`);
35
- const extModules = await this._getExternalModulesAsync();
36
- let isFirst = true;
37
- const ctx = await esbuild.context({
38
- entryPoints: {
39
- index: path.resolve(this._pkgPath, "src", "main.ts")
40
- },
41
- bundle: true,
42
- target: "node20",
43
- mainFields: ["es2021", "es2020", "module", "main"],
44
- conditions: ["es2021", "es2020", "es2015", "module"],
45
- tsconfig: path.resolve(this._pkgPath, "tsconfig.json"),
46
- write: true,
47
- format: "esm",
48
- // outExtension: { ".js": ".mjs" },
49
- resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
50
- platform: "node",
51
- logLevel: "silent",
52
- outfile: path.resolve(this._pkgPath, "dist", "main.js"),
53
- external: extModules.map((item) => item.name),
54
- banner: {
55
- js: `
12
+ private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuilder"]);
13
+
14
+ public constructor(private readonly _pkgPath: string,
15
+ private readonly _pkgConf: ISdCliServerPackageConfig,
16
+ private readonly _withLint: boolean) {
17
+ super();
18
+ }
19
+
20
+ public override on(event: "change", listener: () => void): this;
21
+ public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
22
+ public override on(event: string | symbol, listener: (...args: any[]) => void): this {
23
+ super.on(event, listener);
24
+ return this;
25
+ }
26
+
27
+ public async watchAsync(): Promise<void> {
28
+ this._debug("빌드 준비...");
29
+ const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
30
+
31
+ this._debug("dist 초기화...");
32
+ await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
33
+
34
+ this.emit("change");
35
+
36
+ this._debug("GEN .config...");
37
+ const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
38
+ await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
39
+
40
+ this._debug(`BUILD...`);
41
+ const extModules = await this._getExternalModulesAsync();
42
+ let isFirst = true;
43
+ const ctx = await esbuild.context({
44
+ entryPoints: {
45
+ index: path.resolve(this._pkgPath, "src", "main.ts")
46
+ },
47
+ keepNames: true,
48
+ bundle: true,
49
+ target: "node20",
50
+ mainFields: ["es2021", "es2020", "module", "main"],
51
+ conditions: ["es2021", "es2020", "es2015", "module"],
52
+ tsconfig: path.resolve(this._pkgPath, "tsconfig.json"),
53
+ write: true,
54
+ format: "esm",
55
+ // outExtension: { ".js": ".mjs" },
56
+ resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
57
+ loader: {
58
+ ".pfx": "binary"
59
+ },
60
+ platform: "node",
61
+ logLevel: "silent",
62
+ outfile: path.resolve(this._pkgPath, "dist", "main.js"),
63
+ external: extModules.map((item) => item.name),
64
+ banner: {
65
+ js: `
56
66
  import __path__ from 'path';
57
67
  import { fileURLToPath as __fileURLToPath__ } from 'url';
58
68
  import { createRequire as __createRequire__ } from 'module';
@@ -60,90 +70,115 @@ import { createRequire as __createRequire__ } from 'module';
60
70
  const require = __createRequire__(import.meta.url);
61
71
  const __filename = __fileURLToPath__(import.meta.url);
62
72
  const __dirname = __path__.dirname(__filename);`.trim()
63
- },
64
- plugins: [
65
- {
66
- name: "sd-additional",
67
- setup: ({ onEnd, onStart }) => {
68
- onStart(() => {
69
- if (!isFirst) {
70
- this.emit("change");
71
- this._debug(`BUILD...`);
72
- }
73
- isFirst = false;
74
- });
75
-
76
- onEnd(async (result) => {
77
- try {
78
- const buildResults = [
79
- ...result.warnings.map((warn) => ({
80
- filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
81
- line: warn.location?.line,
82
- char: warn.location?.column,
83
- code: undefined,
84
- severity: "warning" as const,
85
- message: warn.text
86
- })),
87
- ...result.errors.map((err) => ({
88
- filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
89
- line: err.location?.line,
90
- char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
91
- code: undefined,
92
- severity: "error" as const,
93
- message: err.text
94
- }))
95
- ];
96
-
97
- this._debug("CHECK...");
98
- const checkResult = await sdTsProgram.buildAsync();
99
-
100
- this._debug("LINT...");
101
- const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
102
-
103
- this._debug(`빌드 완료`);
104
- this.emit("complete", {
105
- affectedFilePaths: checkResult.affectedFilePaths,
106
- buildResults: [...buildResults, ...checkResult.results, ...lintResults]
107
- });
108
- }
109
- catch (err) {
110
- this._logger.error(err);
111
- }
112
- });
113
- }
114
- }
115
- ]
116
- });
117
- await ctx.watch();
118
- }
119
-
120
- public async buildAsync(): Promise<ISdCliBuilderResult> {
121
- this._debug("빌드 준비...");
122
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, false);
123
-
124
- this._debug("dist 초기화...");
125
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
126
-
127
- this._debug("BUILD...");
128
- const extModules = await this._getExternalModulesAsync();
129
- const esbuildResult = await esbuild.build({
130
- entryPoints: {
131
- index: path.resolve(this._pkgPath, "src", "main.ts")
132
- },
133
- bundle: true,
134
- target: "node20",
135
- mainFields: ["es2021", "es2020", "module", "main"],
136
- conditions: ["es2021", "es2020", "es2015", "module"],
137
- tsconfig: path.resolve(this._pkgPath, "tsconfig.json"),
138
- write: true,
139
- format: "esm",
140
- // outExtension: { ".js": ".mjs" },
141
- platform: "node",
142
- logLevel: "silent",
143
- outfile: path.resolve(this._pkgPath, "dist", "main.js"),
144
- external: extModules.map((item) => item.name),
145
- banner: {
146
- js: `
73
+ },
74
+ plugins: [
75
+ esbuildPluginTsc(),
76
+ {
77
+ name: "sd-additional",
78
+ setup: ({
79
+ onEnd,
80
+ onStart
81
+ }) => {
82
+ onStart(() => {
83
+ if (!isFirst) {
84
+ this.emit("change");
85
+ this._debug(`BUILD...`);
86
+ }
87
+ isFirst = false;
88
+ });
89
+
90
+ onEnd(async (result) => {
91
+ try {
92
+ const buildResults = [
93
+ ...result.warnings.map((warn) => ({
94
+ filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
95
+ line: warn.location?.line,
96
+ char: warn.location?.column,
97
+ code: undefined,
98
+ severity: "warning" as const,
99
+ message: warn.text
100
+ })),
101
+ ...result.errors.map((err) => ({
102
+ filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
103
+ line: err.location?.line,
104
+ char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
105
+ code: undefined,
106
+ severity: "error" as const,
107
+ message: err.text
108
+ }))
109
+ ];
110
+
111
+ this._debug("CHECK...");
112
+ const checkResult = await sdTsProgram.buildAsync();
113
+
114
+ this._debug("LINT...");
115
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
116
+
117
+ this._debug(`빌드 완료`);
118
+ this.emit("complete", {
119
+ affectedFilePaths: checkResult.affectedFilePaths,
120
+ buildResults: [...buildResults, ...checkResult.results, ...lintResults]
121
+ });
122
+ } catch (err) {
123
+ this._logger.error(err);
124
+ }
125
+ });
126
+ },
127
+ },
128
+ {
129
+ name: "jsdom-patch",
130
+ setup: ({onLoad}) => {
131
+ onLoad({filter: /XMLHttpRequest-impl\.js$/}, async (args) => {
132
+ let contents = await FsUtil.readFileAsync(args.path);
133
+ contents = contents.replace(
134
+ './xhr-sync-worker.js',
135
+ 'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
136
+ );
137
+ return {contents};
138
+ });
139
+ },
140
+ }
141
+ ]
142
+ });
143
+ await ctx.watch();
144
+ }
145
+
146
+ public async buildAsync(): Promise<ISdCliBuilderResult> {
147
+ this._debug("빌드 준비...");
148
+ const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
149
+
150
+ this._debug("dist 초기화...");
151
+ await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
152
+
153
+ this._debug("GEN .config...");
154
+ const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
155
+ await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
156
+
157
+ this._debug("BUILD...");
158
+ const extModules = await this._getExternalModulesAsync();
159
+ const esbuildResult = await esbuild.build({
160
+ entryPoints: {
161
+ index: path.resolve(this._pkgPath, "src", "main.ts")
162
+ },
163
+ keepNames: true,
164
+ bundle: true,
165
+ target: "node20",
166
+ mainFields: ["es2021", "es2020", "module", "main"],
167
+ conditions: ["es2021", "es2020", "es2015", "module"],
168
+ tsconfig: path.resolve(this._pkgPath, "tsconfig.json"),
169
+ write: true,
170
+ format: "esm",
171
+ // outExtension: { ".js": ".mjs" },
172
+ resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
173
+ loader: {
174
+ ".pfx": "binary"
175
+ },
176
+ platform: "node",
177
+ logLevel: "silent",
178
+ outfile: path.resolve(this._pkgPath, "dist", "main.js"),
179
+ external: extModules.map((item) => item.name),
180
+ banner: {
181
+ js: `
147
182
  import __path__ from 'path';
148
183
  import { fileURLToPath as __fileURLToPath__ } from 'url';
149
184
  import { createRequire as __createRequire__ } from 'module';
@@ -151,109 +186,145 @@ import { createRequire as __createRequire__ } from 'module';
151
186
  const require = __createRequire__(import.meta.url);
152
187
  const __filename = __fileURLToPath__(import.meta.url);
153
188
  const __dirname = __path__.dirname(__filename);`.trim()
154
- },
155
- });
156
-
157
- const buildResults = [
158
- ...esbuildResult.warnings.map((warn) => ({
159
- filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
160
- line: warn.location?.line,
161
- char: warn.location?.column,
162
- code: undefined,
163
- severity: "warning" as const,
164
- message: warn.text
165
- })),
166
- ...esbuildResult.errors.map((err) => ({
167
- filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
168
- line: err.location?.line,
169
- char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
170
- code: undefined,
171
- severity: "warning" as const,
172
- message: err.text
173
- }))
174
- ];
175
-
176
- this._debug("CHECK...");
177
- const checkResult = await sdTsProgram.buildAsync();
178
-
179
- this._debug("LINT...");
180
- const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
181
-
182
- this._debug(`빌드 완료`);
183
- return {
184
- affectedFilePaths: checkResult.affectedFilePaths,
185
- buildResults: [...buildResults, ...checkResult.results, ...lintResults]
186
- };
187
- }
188
-
189
- private async _getExternalModulesAsync(): Promise<{ name: string; exists: boolean }[]> {
190
- const loadedModuleNames: string[] = [];
191
- const results: { name: string; exists: boolean }[] = [];
192
-
193
- const npmConfigMap = new Map<string, INpmConfig>();
194
-
195
- const fn = async (currPath: string): Promise<void> => {
196
- const npmConfig = npmConfigMap.getOrCreate(currPath, await FsUtil.readJsonAsync(path.resolve(currPath, "package.json")));
197
-
198
- const deps = {
199
- defaults: [
200
- ...Object.keys(npmConfig.dependencies ?? {}),
201
- ...Object.keys(npmConfig.peerDependencies ?? {}).filter((item) => !npmConfig.peerDependenciesMeta?.[item]?.optional)
202
- ].distinct(),
203
- optionals: [
204
- ...Object.keys(npmConfig.optionalDependencies ?? {}),
205
- ...Object.keys(npmConfig.peerDependencies ?? {}).filter((item) => npmConfig.peerDependenciesMeta?.[item]?.optional)
206
- ].distinct()
207
- };
208
-
209
- for (const moduleName of deps.defaults) {
210
- if (loadedModuleNames.includes(moduleName)) continue;
211
- loadedModuleNames.push(moduleName);
212
-
213
- const modulePath = FsUtil.findAllParentChildDirPaths("node_modules/" + moduleName, currPath, path.resolve(this._pkgPath, "../../")).first();
214
- if (StringUtil.isNullOrEmpty(modulePath)) {
215
- continue;
216
- }
217
-
218
- if (FsUtil.glob(path.resolve(modulePath, "**/binding.gyp")).length > 0) {
219
- results.push({ name: moduleName, exists: true });
220
- }
221
-
222
- if (this._pkgConf.externals?.includes(moduleName)) {
223
- results.push({ name: moduleName, exists: true });
224
- }
225
-
226
- await fn(modulePath);
227
- }
228
-
229
- for (const optModuleName of deps.optionals) {
230
- if (loadedModuleNames.includes(optModuleName)) continue;
231
- loadedModuleNames.push(optModuleName);
232
-
233
- const optModulePath = FsUtil.findAllParentChildDirPaths("node_modules/" + optModuleName, currPath, path.resolve(this._pkgPath, "../../")).first();
234
- if (StringUtil.isNullOrEmpty(optModulePath)) {
235
- results.push({ name: optModuleName, exists: false });
236
- continue;
237
- }
238
-
239
- if (FsUtil.glob(path.resolve(optModulePath, "**/binding.gyp")).length > 0) {
240
- results.push({ name: optModuleName, exists: true });
241
- }
242
-
243
- if (this._pkgConf.externals?.includes(optModuleName)) {
244
- results.push({ name: optModuleName, exists: true });
245
- }
246
-
247
- await fn(optModulePath);
248
- }
249
- };
250
-
251
- await fn(this._pkgPath);
252
-
253
- return results;
254
- }
255
-
256
- private _debug(msg: string): void {
257
- this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
258
- }
189
+ },
190
+ plugins: [
191
+ {
192
+ name: "jsdom-patch",
193
+ setup: ({onLoad}) => {
194
+ onLoad({filter: /XMLHttpRequest-impl\.js$/}, async (args) => {
195
+ let contents = await FsUtil.readFileAsync(args.path);
196
+ contents = contents.replace(
197
+ './xhr-sync-worker.js',
198
+ 'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
199
+ );
200
+ return {contents};
201
+ });
202
+ },
203
+ }
204
+ ]
205
+ });
206
+
207
+ const buildResults = [
208
+ ...esbuildResult.warnings.map((warn) => ({
209
+ filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
210
+ line: warn.location?.line,
211
+ char: warn.location?.column,
212
+ code: undefined,
213
+ severity: "warning" as const,
214
+ message: warn.text
215
+ })),
216
+ ...esbuildResult.errors.map((err) => ({
217
+ filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
218
+ line: err.location?.line,
219
+ char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
220
+ code: undefined,
221
+ severity: "warning" as const,
222
+ message: err.text
223
+ }))
224
+ ];
225
+
226
+ this._debug("CHECK...");
227
+ const checkResult = await sdTsProgram.buildAsync();
228
+
229
+ this._debug("LINT...");
230
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
231
+
232
+ this._debug(`빌드 완료`);
233
+ return {
234
+ affectedFilePaths: checkResult.affectedFilePaths,
235
+ buildResults: [...buildResults, ...checkResult.results, ...lintResults]
236
+ };
237
+ }
238
+
239
+ private async _getExternalModulesAsync(): Promise<{
240
+ name: string;
241
+ exists: boolean
242
+ }[]> {
243
+ const loadedModuleNames: string[] = [];
244
+ const results: {
245
+ name: string;
246
+ exists: boolean
247
+ }[] = [];
248
+
249
+ const npmConfigMap = new Map<string, INpmConfig>();
250
+
251
+ const fn = async (currPath: string): Promise<void> => {
252
+ const npmConfig = npmConfigMap.getOrCreate(currPath, await FsUtil.readJsonAsync(path.resolve(currPath, "package.json")));
253
+
254
+ const deps = {
255
+ defaults: [
256
+ ...Object.keys(npmConfig.dependencies ?? {}),
257
+ ...Object.keys(npmConfig.peerDependencies ?? {}).filter((item) => !npmConfig.peerDependenciesMeta?.[item]?.optional)
258
+ ].distinct(),
259
+ optionals: [
260
+ ...Object.keys(npmConfig.optionalDependencies ?? {}),
261
+ ...Object.keys(npmConfig.peerDependencies ?? {}).filter((item) => npmConfig.peerDependenciesMeta?.[item]?.optional)
262
+ ].distinct()
263
+ };
264
+
265
+ for (const moduleName of deps.defaults) {
266
+ if (loadedModuleNames.includes(moduleName)) continue;
267
+ loadedModuleNames.push(moduleName);
268
+
269
+ const modulePath = FsUtil.findAllParentChildPaths("node_modules/" + moduleName, currPath, path.resolve(this._pkgPath, "../../")).first();
270
+ if (StringUtil.isNullOrEmpty(modulePath)) {
271
+ continue;
272
+ }
273
+
274
+ if (FsUtil.glob(path.resolve(modulePath, "**/binding.gyp")).length > 0) {
275
+ results.push({
276
+ name: moduleName,
277
+ exists: true
278
+ });
279
+ }
280
+
281
+ if (this._pkgConf.externals?.includes(moduleName)) {
282
+ results.push({
283
+ name: moduleName,
284
+ exists: true
285
+ });
286
+ }
287
+
288
+ await fn(modulePath);
289
+ }
290
+
291
+ for (const optModuleName of deps.optionals) {
292
+ if (loadedModuleNames.includes(optModuleName)) continue;
293
+ loadedModuleNames.push(optModuleName);
294
+
295
+ const optModulePath = FsUtil.findAllParentChildPaths("node_modules/" + optModuleName, currPath, path.resolve(this._pkgPath, "../../")).first();
296
+ if (StringUtil.isNullOrEmpty(optModulePath)) {
297
+ results.push({
298
+ name: optModuleName,
299
+ exists: false
300
+ });
301
+ continue;
302
+ }
303
+
304
+ if (FsUtil.glob(path.resolve(optModulePath, "**/binding.gyp")).length > 0) {
305
+ results.push({
306
+ name: optModuleName,
307
+ exists: true
308
+ });
309
+ }
310
+
311
+ if (this._pkgConf.externals?.includes(optModuleName)) {
312
+ results.push({
313
+ name: optModuleName,
314
+ exists: true
315
+ });
316
+ }
317
+
318
+ await fn(optModulePath);
319
+ }
320
+ };
321
+
322
+ await fn(this._pkgPath);
323
+
324
+ return results;
325
+ }
326
+
327
+ private _debug(msg: string): void {
328
+ this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
329
+ }
259
330
  }