@simplysm/sd-cli 10.0.40 → 10.0.47

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 (63) 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 +91 -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 +110 -11
  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 +28 -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 +85 -22
  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/SdCliViteReactSwcPlugin.js +2 -4
  37. package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -1
  38. package/dist/utils/sdCliTsDefineTransformer.js.map +1 -1
  39. package/package.json +14 -13
  40. package/src/build-tools/SdCliIndexFileGenerator.ts +62 -0
  41. package/src/{SdLinter.ts → build-tools/SdLinter.ts} +3 -2
  42. package/src/{SdTsIncrementalBuilder.ts → build-tools/SdTsIncrementalBuilder.ts} +2 -2
  43. package/src/builders/SdCliClientBuilder.ts +305 -203
  44. package/src/builders/SdCliJsLibLinter.ts +1 -1
  45. package/src/builders/SdCliServerBuilder.ts +420 -306
  46. package/src/builders/SdCliTsLibBuilder.ts +135 -133
  47. package/src/commons.ts +84 -61
  48. package/src/entry/SdCliElectron.ts +124 -48
  49. package/src/entry/SdCliProject.ts +537 -455
  50. package/src/index.ts +19 -1
  51. package/src/sd-cli.ts +190 -179
  52. package/src/utils/SdCliBuildResultUtil.ts +4 -3
  53. package/src/utils/SdCliViteElectronMainPlugin.ts +25 -7
  54. package/src/utils/SdCliViteExternalPlugin.ts +12 -7
  55. package/src/utils/SdCliViteReactSwcPlugin.ts +6 -8
  56. package/src/utils/sdCliTsDefineTransformer.ts +23 -23
  57. package/tsconfig.json +7 -1
  58. package/dist/SdLinter.js.map +0 -1
  59. package/dist/SdTsIncrementalBuilder.js.map +0 -1
  60. package/dist/entry/SdCliLocalUpdate.d.ts +0 -12
  61. package/dist/entry/SdCliLocalUpdate.js +0 -94
  62. package/dist/entry/SdCliLocalUpdate.js.map +0 -1
  63. package/src/entry/SdCliLocalUpdate.ts +0 -125
@@ -1,68 +1,82 @@
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";
8
- import {StringUtil} from "@simplysm/sd-core-common";
6
+ import {SdTsIncrementalBuilder} from "../build-tools/SdTsIncrementalBuilder";
7
+ import {SdLinter} from "../build-tools/SdLinter";
8
+ import {ObjectUtil, 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
+ resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
57
+ loader: {
58
+ ".xlsx": "binary",
59
+ ".xls": "binary",
60
+ ".docx": "binary",
61
+ ".doc": "binary",
62
+ ".pptx": "binary",
63
+ ".ppt": "binary",
64
+ ".woff": "binary",
65
+ ".woff2": "binary",
66
+ ".ttf": "binary",
67
+ ".eot": "binary",
68
+ ".otf": "binary",
69
+ ".csv": "binary",
70
+ ".zip": "binary",
71
+ ".pfx": "binary",
72
+ ".pkl": "binary",
73
+ },
74
+ platform: "node",
75
+ logLevel: "silent",
76
+ outfile: path.resolve(this._pkgPath, "dist", "main.js"),
77
+ external: extModules.map((item) => item.name),
78
+ banner: {
79
+ js: `
66
80
  import __path__ from 'path';
67
81
  import { fileURLToPath as __fileURLToPath__ } from 'url';
68
82
  import { createRequire as __createRequire__ } from 'module';
@@ -70,115 +84,212 @@ import { createRequire as __createRequire__ } from 'module';
70
84
  const require = __createRequire__(import.meta.url);
71
85
  const __filename = __fileURLToPath__(import.meta.url);
72
86
  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();
87
+ },
88
+ plugins: [
89
+ esbuildPluginTsc(),
90
+ {
91
+ name: "sd-additional",
92
+ setup: ({
93
+ onEnd,
94
+ onStart
95
+ }) => {
96
+ onStart(() => {
97
+ if (!isFirst) {
98
+ this.emit("change");
99
+ this._debug(`BUILD...`);
100
+ }
101
+ isFirst = false;
102
+ });
103
+
104
+ onEnd(async (result) => {
105
+ try {
106
+ const buildResults = [
107
+ ...result.warnings.map((warn) => ({
108
+ filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
109
+ line: warn.location?.line,
110
+ char: warn.location?.column,
111
+ code: undefined,
112
+ severity: "warning" as const,
113
+ message: warn.text
114
+ })),
115
+ ...result.errors.map((err) => ({
116
+ filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
117
+ line: err.location?.line,
118
+ char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
119
+ code: undefined,
120
+ severity: "error" as const,
121
+ message: err.text
122
+ }))
123
+ ];
124
+
125
+ this._debug("CHECK...");
126
+ const checkResult = await sdTsProgram.buildAsync();
127
+
128
+ this._debug("LINT...");
129
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
130
+
131
+ this._debug(`빌드 완료`);
132
+ this.emit("complete", {
133
+ affectedFilePaths: checkResult.affectedFilePaths,
134
+ buildResults: [...buildResults, ...checkResult.results, ...lintResults]
135
+ });
136
+ }
137
+ catch (err) {
138
+ this._logger.error(err);
139
+ }
140
+ });
141
+ },
142
+ },
143
+ {
144
+ name: "jsdom-patch",
145
+ setup: ({onLoad}) => {
146
+ onLoad({filter: /XMLHttpRequest-impl\.js$/}, async (args) => {
147
+ let contents = await FsUtil.readFileAsync(args.path);
148
+ contents = contents.replace(
149
+ './xhr-sync-worker.js',
150
+ 'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
151
+ );
152
+ return {contents};
153
+ });
154
+ },
155
+ }
156
+ ]
157
+ });
158
+ await ctx.watch();
159
+ }
160
+
161
+ public async buildAsync(): Promise<ISdCliBuilderResult> {
162
+ const npmConfig = (await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "package.json"))) as INpmConfig;
163
+ const extModules = await this._getExternalModulesAsync();
164
+
165
+ this._debug("빌드 준비...");
166
+ const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
167
+
168
+ this._debug("dist 초기화...");
169
+ await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
170
+
171
+ this._debug("GEN .config.json...");
172
+ const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
173
+ await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
174
+
175
+ if (this._pkgConf.pm2) {
176
+ this._debug("GEN pm2.json...");
177
+
178
+ await FsUtil.writeFileAsync(
179
+ path.resolve(this._pkgPath, "dist/pm2.json"),
180
+ JSON.stringify({
181
+ name: npmConfig.name.replace(/@/g, "").replace(/\//g, "-"),
182
+ script: "main.js",
183
+ watch: true,
184
+ watch_delay: 2000,
185
+ ignore_watch: [
186
+ "node_modules",
187
+ "www",
188
+ ...this._pkgConf.pm2.ignoreWatchPaths ?? []
189
+ ],
190
+ ...this._pkgConf.pm2.noInterpreter ? {} : {
191
+ "interpreter": "node@" + process.versions.node,
192
+ },
193
+ "env": {
194
+ NODE_ENV: "production",
195
+ TZ: "Asia/Seoul",
196
+ SD_VERSION: npmConfig.version,
197
+ ...this._pkgConf.env
198
+ },
199
+ arrayProcess: "concat",
200
+ useDelTargetNull: true
201
+ }, undefined, 2)
202
+ );
203
+ }
204
+
205
+ this._debug("GEN web.config...");
206
+ if (this._pkgConf.iis) {
207
+ const iisDistPath = path.resolve(this._pkgPath, "dist/web.config");
208
+ const serverExeFilePath = this._pkgConf.iis.nodeExeFilePath ?? "C:\\Program Files\\nodejs\\node.exe";
209
+ await FsUtil.writeFileAsync(iisDistPath, `
210
+ <configuration>
211
+ <system.webServer>
212
+ <handlers>
213
+ <add name="iisnode" path="main.js" verb="*" modules="iisnode" />
214
+ </handlers>
215
+ <iisnode nodeProcessCommandLine="${serverExeFilePath}"
216
+ watchedFiles="web.config;*.js"
217
+ loggingEnabled="true"
218
+ devErrorsEnabled="true" />
219
+ <rewrite>
220
+ <rules>
221
+ <rule name="main">
222
+ <action type="Rewrite" url="main.js" />
223
+ </rule>
224
+ </rules>
225
+ </rewrite>
226
+ <httpErrors errorMode="Detailed" />
227
+ </system.webServer>
228
+ </configuration>
229
+
230
+ `.trim());
144
231
  }
145
232
 
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: `
233
+ this._debug("GEN package.json...");
234
+ {
235
+ const deps = extModules.filter((item) => item.exists).map((item) => item.name);
236
+
237
+ const distNpmConfig = ObjectUtil.clone(npmConfig);
238
+ distNpmConfig.dependencies = {};
239
+ for (const dep of deps) {
240
+ distNpmConfig.dependencies[dep] = "*";
241
+ }
242
+ delete distNpmConfig.optionalDependencies;
243
+ delete distNpmConfig.devDependencies;
244
+ delete distNpmConfig.peerDependencies;
245
+
246
+ if (this._pkgConf.pm2 && !this._pkgConf.pm2.noStartScript) {
247
+ distNpmConfig.scripts = {"start": "pm2 start pm2.json"};
248
+ }
249
+
250
+ await FsUtil.writeFileAsync(
251
+ path.resolve(this._pkgPath, "dist/package.json"),
252
+ JSON.stringify(distNpmConfig, undefined, 2)
253
+ );
254
+ }
255
+
256
+ this._debug("BUILD...");
257
+ const esbuildResult = await esbuild.build({
258
+ entryPoints: {
259
+ index: path.resolve(this._pkgPath, "src", "main.ts")
260
+ },
261
+ keepNames: true,
262
+ bundle: true,
263
+ target: "node20",
264
+ mainFields: ["es2021", "es2020", "module", "main"],
265
+ conditions: ["es2021", "es2020", "es2015", "module"],
266
+ tsconfig: path.resolve(this._pkgPath, "tsconfig.json"),
267
+ write: true,
268
+ format: "esm",
269
+ resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
270
+ loader: {
271
+ ".xlsx": "binary",
272
+ ".xls": "binary",
273
+ ".docx": "binary",
274
+ ".doc": "binary",
275
+ ".pptx": "binary",
276
+ ".ppt": "binary",
277
+ ".woff": "binary",
278
+ ".woff2": "binary",
279
+ ".ttf": "binary",
280
+ ".eot": "binary",
281
+ ".otf": "binary",
282
+ ".csv": "binary",
283
+ ".zip": "binary",
284
+ ".pfx": "binary",
285
+ ".pkl": "binary",
286
+ },
287
+ platform: "node",
288
+ logLevel: "silent",
289
+ outfile: path.resolve(this._pkgPath, "dist", "main.js"),
290
+ external: extModules.map((item) => item.name),
291
+ banner: {
292
+ js: `
182
293
  import __path__ from 'path';
183
294
  import { fileURLToPath as __fileURLToPath__ } from 'url';
184
295
  import { createRequire as __createRequire__ } from 'module';
@@ -186,145 +297,148 @@ import { createRequire as __createRequire__ } from 'module';
186
297
  const require = __createRequire__(import.meta.url);
187
298
  const __filename = __fileURLToPath__(import.meta.url);
188
299
  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
- }
300
+ },
301
+ plugins: [
302
+ esbuildPluginTsc(),
303
+ {
304
+ name: "jsdom-patch",
305
+ setup: ({onLoad}) => {
306
+ onLoad({filter: /XMLHttpRequest-impl\.js$/}, async (args) => {
307
+ let contents = await FsUtil.readFileAsync(args.path);
308
+ contents = contents.replace(
309
+ './xhr-sync-worker.js',
310
+ 'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
311
+ );
312
+ return {contents};
313
+ });
314
+ },
315
+ }
316
+ ]
317
+ });
318
+
319
+ const buildResults: ISdCliPackageBuildResult[] = [
320
+ ...esbuildResult.warnings.map((warn) => ({
321
+ filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
322
+ line: warn.location?.line,
323
+ char: warn.location?.column,
324
+ code: undefined,
325
+ severity: "warning" as const,
326
+ message: warn.text,
327
+ type: "build" as const
328
+ })),
329
+ ...esbuildResult.errors.map((err) => ({
330
+ filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
331
+ line: err.location?.line,
332
+ char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
333
+ code: undefined,
334
+ severity: "warning" as const,
335
+ message: err.text,
336
+ type: "build" as const
337
+ }))
338
+ ];
339
+
340
+ this._debug("CHECK...");
341
+ const checkResult = await sdTsProgram.buildAsync();
342
+
343
+ this._debug("LINT...");
344
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
345
+
346
+ this._debug(`빌드 완료`);
347
+ return {
348
+ affectedFilePaths: checkResult.affectedFilePaths,
349
+ buildResults: [...buildResults, ...checkResult.results, ...lintResults]
350
+ };
351
+ }
352
+
353
+ private async _getExternalModulesAsync(): Promise<{
354
+ name: string;
355
+ exists: boolean
356
+ }[]> {
357
+ const loadedModuleNames: string[] = [];
358
+ const results: {
359
+ name: string;
360
+ exists: boolean
361
+ }[] = [];
362
+
363
+ const npmConfigMap = new Map<string, INpmConfig>();
364
+
365
+ const fn = async (currPath: string): Promise<void> => {
366
+ const npmConfig = npmConfigMap.getOrCreate(currPath, await FsUtil.readJsonAsync(path.resolve(currPath, "package.json")));
367
+
368
+ const deps = {
369
+ defaults: [
370
+ ...Object.keys(npmConfig.dependencies ?? {}),
371
+ ...Object.keys(npmConfig.peerDependencies ?? {}).filter((item) => !npmConfig.peerDependenciesMeta?.[item]?.optional)
372
+ ].distinct(),
373
+ optionals: [
374
+ ...Object.keys(npmConfig.optionalDependencies ?? {}),
375
+ ...Object.keys(npmConfig.peerDependencies ?? {}).filter((item) => npmConfig.peerDependenciesMeta?.[item]?.optional)
376
+ ].distinct()
377
+ };
378
+
379
+ for (const moduleName of deps.defaults) {
380
+ if (loadedModuleNames.includes(moduleName)) continue;
381
+ loadedModuleNames.push(moduleName);
382
+
383
+ const modulePath = FsUtil.findAllParentChildPaths("node_modules/" + moduleName, currPath, path.resolve(this._pkgPath, "../../")).first();
384
+ if (StringUtil.isNullOrEmpty(modulePath)) {
385
+ continue;
386
+ }
387
+
388
+ if (FsUtil.glob(path.resolve(modulePath, "**/binding.gyp")).length > 0) {
389
+ results.push({
390
+ name: moduleName,
391
+ exists: true
392
+ });
393
+ }
394
+
395
+ if (this._pkgConf.externals?.includes(moduleName)) {
396
+ results.push({
397
+ name: moduleName,
398
+ exists: true
399
+ });
400
+ }
401
+
402
+ await fn(modulePath);
403
+ }
404
+
405
+ for (const optModuleName of deps.optionals) {
406
+ if (loadedModuleNames.includes(optModuleName)) continue;
407
+ loadedModuleNames.push(optModuleName);
408
+
409
+ const optModulePath = FsUtil.findAllParentChildPaths("node_modules/" + optModuleName, currPath, path.resolve(this._pkgPath, "../../")).first();
410
+ if (StringUtil.isNullOrEmpty(optModulePath)) {
411
+ results.push({
412
+ name: optModuleName,
413
+ exists: false
414
+ });
415
+ continue;
416
+ }
417
+
418
+ if (FsUtil.glob(path.resolve(optModulePath, "**/binding.gyp")).length > 0) {
419
+ results.push({
420
+ name: optModuleName,
421
+ exists: true
422
+ });
423
+ }
424
+
425
+ if (this._pkgConf.externals?.includes(optModuleName)) {
426
+ results.push({
427
+ name: optModuleName,
428
+ exists: true
429
+ });
430
+ }
431
+
432
+ await fn(optModulePath);
433
+ }
434
+ };
435
+
436
+ await fn(this._pkgPath);
437
+
438
+ return results;
439
+ }
440
+
441
+ private _debug(msg: string): void {
442
+ this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
443
+ }
330
444
  }