@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
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { TSdCliConfigFn, ISdCliConfig } from "./commons";
package/src/sd-cli.ts CHANGED
@@ -1,157 +1,201 @@
1
- #!/usr/bin/env node --no-warnings --experimental-import-meta-resolve
1
+ #!/usr/bin/env node --es-module-specifier-resolution=node --no-warnings --experimental-import-meta-resolve
2
2
 
3
3
  import yargs from "yargs";
4
- import { hideBin } from "yargs/helpers";
5
- import { SdCliProject } from "./entry/SdCliProject";
6
- import { Logger, LoggerSeverity } from "@simplysm/sd-core-node";
7
- import { EventEmitter } from "events";
8
- import { SdCliLocalUpdate } from "./entry/SdCliLocalUpdate";
4
+ import {hideBin} from "yargs/helpers";
5
+ import {SdCliProject} from "./entry/SdCliProject";
6
+ import {Logger, LoggerSeverity} from "@simplysm/sd-core-node";
7
+ import {EventEmitter} from "events";
8
+ import {SdCliElectron} from "./entry/SdCliElectron";
9
+ import {SdCliLocalUpdate} from "./entry/SdCliLocalUpdate";
9
10
 
10
11
  Error.stackTraceLimit = Infinity;
11
12
  EventEmitter.defaultMaxListeners = 0;
12
13
 
13
14
  const argv = (
14
- await yargs(hideBin(process.argv))
15
- .help("help", "도움말")
16
- .alias("help", "h")
17
- .options({
18
- debug: {
19
- type: "boolean",
20
- describe: "디버그 로그를 표시할 것인지 여부",
21
- default: false
22
- }
23
- })
24
- .command(
25
- "watch",
26
- "프로젝트의 각 패키지에 대한 변경감지 빌드를 수행합니다.",
27
- (cmd) => cmd.version(false).hide("help").hide("debug")
15
+ await yargs(hideBin(process.argv))
16
+ .help("help", "도움말")
17
+ .alias("help", "h")
28
18
  .options({
29
- config: {
30
- string: true,
31
- describe: "simplysm.json 파일 경로"
32
- },
33
- options: {
34
- string: true,
35
- array: true,
36
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
37
- },
38
- packages: {
39
- string: true,
40
- array: true,
41
- describe: "수행할 패키지 설정"
42
- }
19
+ debug: {
20
+ type: "boolean",
21
+ describe: "디버그 로그를 표시할 것인지 여부",
22
+ default: false
23
+ }
43
24
  })
44
- )
45
- .command(
46
- "build",
47
- "프로젝트의 패키지에 대한 빌드를 수행합니다.",
48
- (cmd) => cmd.version(false).hide("help").hide("debug")
49
- .options({
50
- config: {
51
- string: true,
52
- describe: "simplysm.json 파일 경로"
53
- },
54
- options: {
55
- string: true,
56
- array: true,
57
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
58
- },
59
- packages: {
60
- string: true,
61
- array: true,
62
- describe: "수행할 패키지 설정"
63
- }
64
- })
65
- )
66
- .command(
67
- "publish",
68
- "프로젝트의 각 패키지를 배포합니다.",
69
- (cmd) => cmd.version(false).hide("help").hide("debug")
70
- .options({
71
- noBuild: {
72
- type: "boolean",
73
- describe: "빌드를 하지않고 배포합니다.",
74
- default: false
75
- },
76
- config: {
77
- type: "string",
78
- describe: "simplysm.json 파일 경로"
79
- },
80
- options: {
81
- type: "string",
82
- array: true,
83
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
84
- },
85
- packages: {
86
- type: "string",
87
- array: true,
88
- describe: "수행할 패키지 설정"
89
- }
90
- })
91
- )
92
- .command(
93
- "local-update",
94
- "로컬 라이브러리 업데이트를 수행합니다.",
95
- (cmd) => cmd.version(false).hide("help").hide("debug")
96
- .options({
97
- config: {
98
- type: "string",
99
- describe: "simplysm.json 파일 경로"
100
- }
101
- })
102
- )
103
- .parseAsync()
25
+ .command(
26
+ "local-update",
27
+ "로컬 라이브러리 업데이트를 수행합니다.",
28
+ (cmd) => cmd.version(false).hide("help").hide("debug")
29
+ .options({
30
+ config: {
31
+ string: true,
32
+ describe: "simplysm.cjs 파일 경로"
33
+ },
34
+ options: {
35
+ string: true,
36
+ array: true,
37
+ describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
38
+ },
39
+ })
40
+ )
41
+ .command(
42
+ "watch",
43
+ "프로젝트의 패키지에 대한 변경감지 빌드를 수행합니다.",
44
+ (cmd) => cmd.version(false).hide("help").hide("debug")
45
+ .options({
46
+ config: {
47
+ string: true,
48
+ describe: "simplysm.cjs 파일 경로"
49
+ },
50
+ options: {
51
+ string: true,
52
+ array: true,
53
+ describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
54
+ },
55
+ packages: {
56
+ string: true,
57
+ array: true,
58
+ describe: "수행할 패키지 설정"
59
+ },
60
+ withoutLint: {
61
+ type: "boolean",
62
+ default: false,
63
+ describe: "린트 수행 여부"
64
+ }
65
+ })
66
+ )
67
+ .command(
68
+ "build",
69
+ "프로젝트의 패키지에 대한 빌드를 수행합니다.",
70
+ (cmd) => cmd.version(false).hide("help").hide("debug")
71
+ .options({
72
+ config: {
73
+ string: true,
74
+ describe: "simplysm.cjs 파일 경로"
75
+ },
76
+ options: {
77
+ string: true,
78
+ array: true,
79
+ describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
80
+ },
81
+ packages: {
82
+ string: true,
83
+ array: true,
84
+ describe: "수행할 패키지 설정"
85
+ },
86
+ withoutLint: {
87
+ type: "boolean",
88
+ default: false,
89
+ describe: "린트 수행 여부"
90
+ }
91
+ })
92
+ )
93
+ .command(
94
+ "publish",
95
+ "프로젝트의 각 패키지를 배포합니다.",
96
+ (cmd) => cmd.version(false).hide("help").hide("debug")
97
+ .options({
98
+ noBuild: {
99
+ type: "boolean",
100
+ describe: "빌드를 하지않고 배포합니다.",
101
+ default: false
102
+ },
103
+ config: {
104
+ type: "string",
105
+ describe: "simplysm.cjs 파일 경로"
106
+ },
107
+ options: {
108
+ type: "string",
109
+ array: true,
110
+ describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
111
+ },
112
+ packages: {
113
+ type: "string",
114
+ array: true,
115
+ describe: "수행할 패키지 설정"
116
+ },
117
+ withoutLint: {
118
+ type: "boolean",
119
+ default: false,
120
+ describe: "린트 수행 여부"
121
+ }
122
+ })
123
+ )
124
+ .command(
125
+ "run-electron <package>",
126
+ "변경감지중인 플랫폼을 ELECTRON 앱 형태로 띄웁니다.",
127
+ (cmd) => cmd
128
+ .positional("package", {
129
+ type: "string",
130
+ describe: "패키지명",
131
+ demandOption: true
132
+ })
133
+ .options({
134
+ config: {
135
+ type: "string",
136
+ describe: "simplysm.json 파일 경로"
137
+ },
138
+ options: {
139
+ type: "string",
140
+ array: true,
141
+ describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
142
+ }
143
+ })
144
+ )
145
+ .parseAsync()
104
146
  ) as any;
105
147
 
106
148
  if (Boolean(argv.debug)) {
107
- process.env["SD_DEBUG"] = "true";
108
- Logger.setConfig({
109
- console: {
110
- level: LoggerSeverity.debug
111
- }
112
- });
113
- }
114
- else {
115
- Logger.setConfig({
116
- dot: true
117
- });
118
- }
119
-
120
- if (argv._[0] === "watch") {
121
- await SdCliProject
122
- .watchAsync({
123
- rootPath: process.cwd(),
124
- confFileRelPath: argv.config ?? "simplysm.json",
125
- optNames: argv.options ?? [],
126
- pkgNames: argv.packages ?? []
127
- });
128
- }
129
- else if (argv._[0] === "build") {
130
- await SdCliProject
131
- .buildAsync({
132
- rootPath: process.cwd(),
133
- confFileRelPath: argv.config ?? "simplysm.json",
134
- optNames: argv.options ?? [],
135
- pkgNames: argv.packages ?? []
136
- });
137
- }
138
- else if (argv._[0] === "publish") {
139
- await SdCliProject
140
- .publishAsync({
141
- rootPath: process.cwd(),
142
- noBuild: argv.noBuild,
143
- confFileRelPath: argv.config ?? "simplysm.json",
144
- optNames: argv.options ?? [],
145
- pkgNames: argv.packages ?? []
149
+ process.env["SD_DEBUG"] = "true";
150
+ Logger.setConfig({
151
+ console: {
152
+ level: LoggerSeverity.debug
153
+ }
146
154
  });
147
- }
148
- else if (argv._[0] === "local-update") {
149
- await SdCliLocalUpdate
150
- .runAsync({
151
- rootPath: process.cwd(),
152
- confFileRelPath: argv.config ?? "simplysm.json"
155
+ } else {
156
+ Logger.setConfig({
157
+ dot: true
153
158
  });
154
159
  }
155
- else {
156
- throw new Error(`명령어가 잘못 되었습니다.\n\t${argv._[0]}\n`);
160
+
161
+ if (argv._[0] === "watch") {
162
+ await SdCliProject
163
+ .watchAsync({
164
+ confFileRelPath: argv.config ?? "simplysm.cjs",
165
+ optNames: argv.options ?? [],
166
+ pkgNames: argv.packages ?? [],
167
+ withLint: argv.withoutLint !== true
168
+ });
169
+ } else if (argv._[0] === "build") {
170
+ await SdCliProject
171
+ .buildAsync({
172
+ confFileRelPath: argv.config ?? "simplysm.cjs",
173
+ optNames: argv.options ?? [],
174
+ pkgNames: argv.packages ?? [],
175
+ withLint: argv.withoutLint !== true
176
+ });
177
+ } else if (argv._[0] === "publish") {
178
+ await SdCliProject
179
+ .publishAsync({
180
+ noBuild: argv.noBuild,
181
+ confFileRelPath: argv.config ?? "simplysm.cjs",
182
+ optNames: argv.options ?? [],
183
+ pkgNames: argv.packages ?? [],
184
+ withLint: argv.withoutLint !== true
185
+ });
186
+ } else if (argv._[0] === "run-electron") {
187
+ await SdCliElectron
188
+ .runAsync({
189
+ confFileRelPath: argv.config ?? "simplysm.cjs",
190
+ optNames: argv.options ?? [],
191
+ pkgName: argv.package
192
+ });
193
+ } else if (argv._[0] === "local-update") {
194
+ await SdCliLocalUpdate
195
+ .runAsync({
196
+ confFileRelPath: argv.config ?? "simplysm.cjs",
197
+ optNames: argv.options ?? []
198
+ });
199
+ } else {
200
+ throw new Error(`명령어가 잘못 되었습니다.\n\t${argv._[0]}\n`);
157
201
  }
@@ -13,14 +13,13 @@ export class SdCliBuildResultUtil {
13
13
  const code = `TS${diag.code}`;
14
14
  const message = ts.flattenDiagnosticMessageText(diag.messageText, os.EOL);
15
15
 
16
-
17
16
  const filePath = diag.file ? path.resolve(diag.file.fileName) : undefined;
18
17
  const position = diag.file && diag.start !== undefined ? diag.file.getLineAndCharacterOfPosition(diag.start) : undefined;
19
18
  const line = position ? position.line + 1 : undefined;
20
19
  const char = position ? position.character + 1 : undefined;
21
20
 
22
21
  return {
23
- filePath,
22
+ filePath: filePath !== undefined ? path.resolve(filePath) : undefined,
24
23
  line,
25
24
  char,
26
25
  code,
@@ -0,0 +1,86 @@
1
+ import {build, defineConfig, PluginOption, UserConfig} from "vite";
2
+ import {SdCliViteExternalPlugin} from "./SdCliViteExternalPlugin";
3
+ import path from "path";
4
+
5
+ export const SdCliViteElectronMainPlugin = (opt: {
6
+ entry: string;
7
+ distPath: string;
8
+ cachePath: string;
9
+ }): PluginOption[] => {
10
+ let mainConfig: UserConfig;
11
+
12
+ return [
13
+ {
14
+ name: "sd-cli:vite:electron-main",
15
+ apply: "serve",
16
+ configureServer: (server) => {
17
+ server.httpServer?.on("listening", async () => {
18
+ mainConfig = defineConfig({
19
+ mode: server.config.mode,
20
+ define: server.config.define,
21
+ root: server.config.root,
22
+ optimizeDeps: {
23
+ force: server.config.optimizeDeps?.force
24
+ },
25
+ build: {
26
+ sourcemap: true,
27
+ minify: false,
28
+ outDir: opt.distPath,
29
+ lib: {
30
+ entry: opt.entry,
31
+ formats: ["cjs"],
32
+ fileName: () => "[name].js"
33
+ }
34
+ },
35
+ customLogger: server.config.customLogger,
36
+ plugins: [
37
+ SdCliViteExternalPlugin({
38
+ cachePath: path.resolve(opt.cachePath, "externals"),
39
+ nodeBuiltinModules: true,
40
+ includes: ["electron"]
41
+ }),
42
+ {
43
+ name: ":startup",
44
+ closeBundle: () => {
45
+ server.ws.send({type: "full-reload"});
46
+ }
47
+ }
48
+ ]
49
+ });
50
+ await build(mainConfig);
51
+ });
52
+ },
53
+ },
54
+ {
55
+ name: "sd-cli:vite:electron-main",
56
+ apply: "build",
57
+ config: (config) => {
58
+ mainConfig = defineConfig({
59
+ mode: config.mode,
60
+ define: config.define,
61
+ root: config.root,
62
+ resolve: {
63
+ alias: config.resolve?.alias
64
+ },
65
+ optimizeDeps: {
66
+ force: config.optimizeDeps?.force
67
+ },
68
+ build: {
69
+ sourcemap: false,
70
+ minify: true,
71
+ outDir: opt.distPath,
72
+ lib: {
73
+ entry: opt.entry,
74
+ formats: ["cjs"],
75
+ fileName: () => "[name].js"
76
+ }
77
+ },
78
+ customLogger: config.customLogger
79
+ });
80
+ },
81
+ closeBundle: async () => {
82
+ await build(mainConfig);
83
+ }
84
+ }
85
+ ];
86
+ };
@@ -0,0 +1,112 @@
1
+ import {PluginOption} from "vite";
2
+ import {builtinModules, createRequire} from "node:module";
3
+ import {FsUtil, PathUtil} from "@simplysm/sd-core-node";
4
+ import {INpmConfig} from "../commons";
5
+ import path from "path";
6
+ import {pathToFileURL} from "url";
7
+ import libEsm from "lib-esm";
8
+ import esbuild from "esbuild";
9
+
10
+ export const SdCliViteExternalPlugin = (opt: {
11
+ cachePath: string;
12
+ nodeBuiltinModules?: boolean;
13
+ dependencies?: boolean;
14
+ includes?: string[];
15
+ }): PluginOption[] => {
16
+ const externals = opt.includes ?? [];
17
+
18
+ const builtins =[
19
+ ...builtinModules,
20
+ ...builtinModules.map((item) => `node:${item}`)
21
+ ];
22
+
23
+ return [
24
+ {
25
+ name: "sd-cli:vite:external",
26
+ enforce: "pre",
27
+ apply: "build",
28
+ config: (conf) => {
29
+ if (opt.dependencies) {
30
+ const npmConfigPath = FsUtil.findAllParentChildPaths("package.json", conf.root ?? opt.cachePath).first()!;
31
+ const npmConfig = FsUtil.readJson(npmConfigPath) as INpmConfig;
32
+ if (npmConfig.dependencies) {
33
+ externals.push(...Object.keys(npmConfig.dependencies));
34
+ }
35
+ }
36
+ },
37
+ resolveId: (source, importer) => {
38
+ if (importer === undefined) return;
39
+
40
+ if ([...externals, ...builtins].includes(source)) {
41
+ return {
42
+ id: source,
43
+ external: true
44
+ };
45
+ }
46
+
47
+ return;
48
+ }
49
+ },
50
+ {
51
+ name: "sd-cli:vite:external",
52
+ enforce: "pre",
53
+ apply: "serve",
54
+ config: (conf) => {
55
+ if (opt.dependencies) {
56
+ const npmConfigPath = FsUtil.findAllParentChildPaths("package.json", conf.root ?? opt.cachePath).first()!;
57
+ const npmConfig = FsUtil.readJson(npmConfigPath) as INpmConfig;
58
+ if (npmConfig.dependencies) {
59
+ externals.push(...Object.keys(npmConfig.dependencies));
60
+ }
61
+ }
62
+
63
+ async function _getSnippetsAsync(moduleName: string, importer?: string): Promise<string> {
64
+ const myRequire = createRequire(pathToFileURL(importer ?? process.cwd()).toString());
65
+ let realModuleName: string;
66
+ try {
67
+ realModuleName = moduleName;
68
+ } catch {
69
+ realModuleName = await _getPreBundleAsync(moduleName);
70
+ }
71
+ const module = myRequire(realModuleName);
72
+ const members = Object.getOwnPropertyNames(module);
73
+ const {exports} = libEsm({exports: members});
74
+ return `const avoid_parse_require = require; const _M_ = avoid_parse_require("${PathUtil.posix(realModuleName)}"); ${exports}`;
75
+ }
76
+
77
+ async function _getPreBundleAsync(moduleName: string): Promise<string> {
78
+ const outfile = path.posix.join(opt.cachePath, moduleName) + ".cjs";
79
+ await esbuild.build({
80
+ entryPoints: [moduleName],
81
+ outfile,
82
+ target: 'node18',
83
+ format: 'cjs',
84
+ bundle: true,
85
+ sourcemap: 'inline',
86
+ platform: 'node',
87
+ external: builtins
88
+ });
89
+
90
+ return outfile;
91
+ }
92
+
93
+ return {
94
+ resolve: {
95
+ alias: [{
96
+ find: new RegExp(`^(${[...externals, ...builtins].join("|")})$`),
97
+ replacement: "$1",
98
+
99
+ customResolver: async (source, importer) => {
100
+ const id = path.posix.join(opt.cachePath, source) + ".mjs";
101
+ if (!FsUtil.exists(id)) {
102
+ await FsUtil.writeFileAsync(id, await _getSnippetsAsync(source, importer));
103
+ }
104
+ return {id};
105
+ }
106
+ }],
107
+ }
108
+ };
109
+ }
110
+ }
111
+ ];
112
+ };
@@ -0,0 +1,29 @@
1
+ import * as vite from "vite";
2
+ import {PluginOption} from "vite";
3
+ import {Logger} from "@simplysm/sd-core-node";
4
+
5
+ export const SdCliViteLoggerPlugin = (opt: {
6
+ logger: Logger,
7
+ name: string
8
+ }): PluginOption[] => {
9
+ return [
10
+ {
11
+ name: "sd-cli:vite:logger",
12
+ enforce: "pre",
13
+ config: () => ({
14
+ customLogger: {
15
+ ...vite.createLogger(),
16
+ info: (msg) => {
17
+ opt.logger.debug(`[${opt.name}] ${msg}`);
18
+ },
19
+ warn: (msg) => {
20
+ opt.logger.warn(`[${opt.name}] ${msg}`);
21
+ },
22
+ error: (msg) => {
23
+ opt.logger.error(`[${opt.name}] ${msg}`);
24
+ }
25
+ },
26
+ })
27
+ }
28
+ ];
29
+ };
@@ -0,0 +1,31 @@
1
+ import { PluginOption } from "vite";
2
+ import stdLibBrowser from "node-stdlib-browser";
3
+ import inject from "@rollup/plugin-inject";
4
+ import { fileURLToPath } from "url";
5
+
6
+ const esbuildShim = fileURLToPath(await import.meta.resolve!("node-stdlib-browser/helpers/esbuild/shim"));
7
+
8
+ export const SdCliViteNodeGlobalPlugin = (): PluginOption[] => {
9
+ return [
10
+ {
11
+ name: "sd-cli:vite:node-global",
12
+ enforce: "pre",
13
+ config: () => ({
14
+ optimizeDeps: {
15
+ include: ["buffer", "process"]
16
+ },
17
+ resolve: {
18
+ alias: stdLibBrowser
19
+ }
20
+ }),
21
+ },
22
+ {
23
+ ...inject({
24
+ global: [esbuildShim, 'global'],
25
+ process: [esbuildShim, 'process'],
26
+ Buffer: [esbuildShim, 'Buffer']
27
+ }),
28
+ enforce: 'post'
29
+ }
30
+ ];
31
+ };