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