@simplysm/sd-cli 10.0.39 → 10.0.45

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