@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
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { TSdCliConfigFn, ISdCliConfig } from "./commons";
package/src/sd-cli.ts CHANGED
@@ -1,138 +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";
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";
8
10
 
9
11
  Error.stackTraceLimit = Infinity;
10
12
  EventEmitter.defaultMaxListeners = 0;
11
13
 
12
14
  const argv = (
13
- await yargs(hideBin(process.argv))
14
- .help("help", "도움말")
15
- .alias("help", "h")
16
- .options({
17
- debug: {
18
- type: "boolean",
19
- describe: "디버그 로그를 표시할 것인지 여부",
20
- default: false
21
- }
22
- })
23
- .command(
24
- "watch",
25
- "프로젝트의 각 패키지에 대한 변경감지 빌드를 수행합니다.",
26
- (cmd) => cmd.version(false).hide("help").hide("debug")
15
+ await yargs(hideBin(process.argv))
16
+ .help("help", "도움말")
17
+ .alias("help", "h")
27
18
  .options({
28
- config: {
29
- string: true,
30
- describe: "simplysm.json 파일 경로"
31
- },
32
- options: {
33
- string: true,
34
- array: true,
35
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
36
- },
37
- packages: {
38
- string: true,
39
- array: true,
40
- describe: "수행할 패키지 설정"
41
- }
19
+ debug: {
20
+ type: "boolean",
21
+ describe: "디버그 로그를 표시할 것인지 여부",
22
+ default: false
23
+ }
42
24
  })
43
- )
44
- .command(
45
- "build",
46
- "프로젝트의 패키지에 대한 빌드를 수행합니다.",
47
- (cmd) => cmd.version(false).hide("help").hide("debug")
48
- .options({
49
- config: {
50
- string: true,
51
- describe: "simplysm.json 파일 경로"
52
- },
53
- options: {
54
- string: true,
55
- array: true,
56
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
57
- },
58
- packages: {
59
- string: true,
60
- array: true,
61
- describe: "수행할 패키지 설정"
62
- }
63
- })
64
- )
65
- .command(
66
- "publish",
67
- "프로젝트의 각 패키지를 배포합니다.",
68
- (cmd) => cmd.version(false).hide("help").hide("debug")
69
- .options({
70
- noBuild: {
71
- type: "boolean",
72
- describe: "빌드를 하지않고 배포합니다.",
73
- default: false
74
- },
75
- config: {
76
- type: "string",
77
- describe: "simplysm.json 파일 경로"
78
- },
79
- options: {
80
- type: "string",
81
- array: true,
82
- describe: "옵션 설정 (설정파일에서 @로 시작하는 부분)"
83
- },
84
- packages: {
85
- type: "string",
86
- array: true,
87
- describe: "수행할 패키지 설정"
88
- }
89
- })
90
- )
91
- .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()
92
146
  ) as any;
93
147
 
94
148
  if (Boolean(argv.debug)) {
95
- process.env["SD_DEBUG"] = "true";
96
- Logger.setConfig({
97
- console: {
98
- level: LoggerSeverity.debug
99
- }
100
- });
101
- }
102
- else {
103
- Logger.setConfig({
104
- dot: true
105
- });
106
- }
107
-
108
- if (argv._[0] === "watch") {
109
- await SdCliProject
110
- .watchAsync({
111
- rootPath: process.cwd(),
112
- confFileRelPath: argv.config ?? "simplysm.json",
113
- optNames: argv.options ?? [],
114
- pkgNames: argv.packages ?? []
115
- });
116
- }
117
- else if (argv._[0] === "build") {
118
- await SdCliProject
119
- .buildAsync({
120
- rootPath: process.cwd(),
121
- confFileRelPath: argv.config ?? "simplysm.json",
122
- optNames: argv.options ?? [],
123
- pkgNames: argv.packages ?? []
149
+ process.env["SD_DEBUG"] = "true";
150
+ Logger.setConfig({
151
+ console: {
152
+ level: LoggerSeverity.debug
153
+ }
124
154
  });
125
- }
126
- else if (argv._[0] === "publish") {
127
- await SdCliProject
128
- .publishAsync({
129
- rootPath: process.cwd(),
130
- noBuild: argv.noBuild,
131
- confFileRelPath: argv.config ?? "simplysm.json",
132
- optNames: argv.options ?? [],
133
- pkgNames: argv.packages ?? []
155
+ } else {
156
+ Logger.setConfig({
157
+ dot: true
134
158
  });
135
159
  }
136
- else {
137
- 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`);
138
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
+ };