@simplysm/sd-cli 10.0.47 → 10.0.50

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 (37) hide show
  1. package/dist/builders/SdCliClientBuilder.js +8 -3
  2. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  3. package/dist/commons.d.ts +4 -1
  4. package/dist/entry/SdCliElectron.js +2 -2
  5. package/dist/entry/SdCliElectron.js.map +1 -1
  6. package/dist/entry/SdCliLocalUpdate.d.ts +12 -0
  7. package/dist/entry/SdCliLocalUpdate.js +91 -0
  8. package/dist/entry/SdCliLocalUpdate.js.map +1 -0
  9. package/dist/entry/SdCliProject.js +26 -18
  10. package/dist/entry/SdCliProject.js.map +1 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.js +2 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/sd-cli.js +20 -1
  15. package/dist/sd-cli.js.map +1 -1
  16. package/dist/utils/SdCliViteElectronMainPlugin.js +0 -2
  17. package/dist/utils/SdCliViteElectronMainPlugin.js.map +1 -1
  18. package/dist/utils/SdCliViteExternalPlugin.d.ts +0 -2
  19. package/dist/utils/SdCliViteExternalPlugin.js +1 -17
  20. package/dist/utils/SdCliViteExternalPlugin.js.map +1 -1
  21. package/dist/utils/SdCliViteReactSwcPlugin.js +1 -1
  22. package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -1
  23. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.d.ts +2 -0
  24. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js +36 -0
  25. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js.map +1 -0
  26. package/package.json +5 -5
  27. package/src/builders/SdCliClientBuilder.ts +10 -4
  28. package/src/commons.ts +4 -1
  29. package/src/entry/SdCliElectron.ts +2 -2
  30. package/src/entry/SdCliLocalUpdate.ts +127 -0
  31. package/src/entry/SdCliProject.ts +27 -18
  32. package/src/index.ts +2 -0
  33. package/src/sd-cli.ts +24 -1
  34. package/src/utils/SdCliViteElectronMainPlugin.ts +89 -91
  35. package/src/utils/SdCliViteExternalPlugin.ts +78 -97
  36. package/src/utils/SdCliViteReactSwcPlugin.ts +6 -6
  37. package/src/utils/SdCliViteServeOptimizeExcludePlugin.ts +42 -0
package/src/sd-cli.ts CHANGED
@@ -6,6 +6,7 @@ import {SdCliProject} from "./entry/SdCliProject";
6
6
  import {Logger, LoggerSeverity} from "@simplysm/sd-core-node";
7
7
  import {EventEmitter} from "events";
8
8
  import {SdCliElectron} from "./entry/SdCliElectron";
9
+ import {SdCliLocalUpdate} from "./entry/SdCliLocalUpdate";
9
10
 
10
11
  Error.stackTraceLimit = Infinity;
11
12
  EventEmitter.defaultMaxListeners = 0;
@@ -21,6 +22,22 @@ const argv = (
21
22
  default: false
22
23
  }
23
24
  })
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
+ )
24
41
  .command(
25
42
  "watch",
26
43
  "프로젝트의 각 패키지에 대한 변경감지 빌드를 수행합니다.",
@@ -163,7 +180,13 @@ else {
163
180
  });
164
181
  }
165
182
 
166
- if (argv._[0] === "watch") {
183
+ if (argv._[0] === "local-update") {
184
+ await SdCliLocalUpdate.runAsync({
185
+ confFileRelPath: argv.config ?? "simplysm.cjs",
186
+ optNames: argv.options ?? [],
187
+ });
188
+ }
189
+ else if (argv._[0] === "watch") {
167
190
  await SdCliProject
168
191
  .watchAsync({
169
192
  confFileRelPath: argv.config ?? "simplysm.cjs",
@@ -5,100 +5,98 @@ import {SdCliViteLoggerPlugin} from "./SdCliViteLoggerPlugin";
5
5
  import {Logger} from "@simplysm/sd-core-node";
6
6
 
7
7
  export const SdCliViteElectronMainPlugin = (opt: {
8
- entry: string;
9
- distPath: string;
10
- cachePath: string;
8
+ entry: string;
9
+ distPath: string;
10
+ cachePath: string;
11
11
  }): PluginOption[] => {
12
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliViteElectronMainPlugin"]);
12
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliViteElectronMainPlugin"]);
13
13
 
14
- let mainConfig: UserConfig;
14
+ let mainConfig: UserConfig;
15
15
 
16
- return [
17
- {
18
- name: "sd-cli:vite:electron-main",
19
- apply: "serve",
20
- configureServer: (server) => {
21
- server.httpServer?.on("listening", async () => {
22
- mainConfig = defineConfig({
23
- mode: server.config.mode,
24
- define: server.config.define,
25
- root: server.config.root,
26
- optimizeDeps: {
27
- force: server.config.optimizeDeps?.force
28
- },
29
- build: {
30
- sourcemap: true,
31
- minify: false,
32
- outDir: opt.distPath,
33
- lib: {
34
- entry: opt.entry,
35
- formats: ["cjs"],
36
- fileName: () => "[name].js"
37
- },
38
- emptyOutDir: false
39
- },
40
- plugins: [
41
- SdCliViteLoggerPlugin({
42
- logger,
43
- name: path.basename(opt.entry)
44
- }),
45
- SdCliViteExternalPlugin({
46
- target: "node",
47
- cachePath: path.resolve(opt.cachePath, "externals"),
48
- nodeBuiltinModules: true,
49
- includes: ["electron"]
50
- }),
51
- {
52
- name: ":startup",
53
- closeBundle: () => {
54
- server.ws.send({type: "full-reload"});
55
- }
56
- }
57
- ]
58
- });
59
- await build(mainConfig);
60
- });
16
+ return [
17
+ {
18
+ name: "sd-cli:vite:electron-main",
19
+ apply: "serve",
20
+ configureServer: (server) => {
21
+ server.httpServer?.on("listening", async () => {
22
+ mainConfig = defineConfig({
23
+ mode: server.config.mode,
24
+ define: server.config.define,
25
+ root: server.config.root,
26
+ optimizeDeps: {
27
+ force: server.config.optimizeDeps?.force
61
28
  },
62
- },
63
- {
64
- name: "sd-cli:vite:electron-main",
65
- apply: "build",
66
- config: (config) => {
67
- mainConfig = defineConfig({
68
- mode: config.mode,
69
- define: config.define,
70
- root: config.root,
71
- optimizeDeps: {
72
- force: config.optimizeDeps?.force
73
- },
74
- build: {
75
- sourcemap: false,
76
- minify: true,
77
- outDir: opt.distPath,
78
- lib: {
79
- entry: opt.entry,
80
- formats: ["cjs"],
81
- fileName: () => "[name].js"
82
- },
83
- emptyOutDir: false
84
- },
85
- plugins: [
86
- SdCliViteLoggerPlugin({
87
- logger,
88
- name: path.basename(opt.entry)
89
- }),
90
- SdCliViteExternalPlugin({
91
- target: "node",
92
- cachePath: path.resolve(opt.cachePath, "externals"),
93
- nodeBuiltinModules: true,
94
- includes: ["electron"]
95
- }),
96
- ]
97
- });
29
+ build: {
30
+ sourcemap: true,
31
+ minify: false,
32
+ outDir: opt.distPath,
33
+ lib: {
34
+ entry: opt.entry,
35
+ formats: ["cjs"],
36
+ fileName: () => "[name].js"
37
+ },
38
+ emptyOutDir: false
98
39
  },
99
- closeBundle: async () => {
100
- await build(mainConfig);
101
- }
102
- }
103
- ];
40
+ plugins: [
41
+ SdCliViteLoggerPlugin({
42
+ logger,
43
+ name: path.basename(opt.entry)
44
+ }),
45
+ SdCliViteExternalPlugin({
46
+ target: "node",
47
+ cachePath: path.resolve(opt.cachePath, "externals"),
48
+ includes: ["electron"]
49
+ }),
50
+ {
51
+ name: ":startup",
52
+ closeBundle: () => {
53
+ server.ws.send({type: "full-reload"});
54
+ }
55
+ }
56
+ ]
57
+ });
58
+ await build(mainConfig);
59
+ });
60
+ },
61
+ },
62
+ {
63
+ name: "sd-cli:vite:electron-main",
64
+ apply: "build",
65
+ config: (config) => {
66
+ mainConfig = defineConfig({
67
+ mode: config.mode,
68
+ define: config.define,
69
+ root: config.root,
70
+ optimizeDeps: {
71
+ force: config.optimizeDeps?.force
72
+ },
73
+ build: {
74
+ sourcemap: false,
75
+ minify: true,
76
+ outDir: opt.distPath,
77
+ lib: {
78
+ entry: opt.entry,
79
+ formats: ["cjs"],
80
+ fileName: () => "[name].js"
81
+ },
82
+ emptyOutDir: false
83
+ },
84
+ plugins: [
85
+ SdCliViteLoggerPlugin({
86
+ logger,
87
+ name: path.basename(opt.entry)
88
+ }),
89
+ SdCliViteExternalPlugin({
90
+ target: "node",
91
+ cachePath: path.resolve(opt.cachePath, "externals"),
92
+ includes: ["electron"]
93
+ }),
94
+ ]
95
+ });
96
+ },
97
+ closeBundle: async () => {
98
+ await build(mainConfig);
99
+ }
100
+ }
101
+ ];
104
102
  };
@@ -1,117 +1,98 @@
1
1
  import {PluginOption} from "vite";
2
2
  import {builtinModules, createRequire} from "node:module";
3
3
  import {FsUtil, PathUtil} from "@simplysm/sd-core-node";
4
- import {INpmConfig} from "../commons";
5
4
  import path from "path";
6
5
  import {pathToFileURL} from "url";
7
6
  import libEsm from "lib-esm";
8
7
  import esbuild from "esbuild";
9
8
 
10
9
  export const SdCliViteExternalPlugin = (opt: {
11
- target: "browser" | "node";
12
- cachePath: string;
13
- nodeBuiltinModules?: boolean;
14
- dependencies?: boolean;
15
- includes?: string[];
10
+ target: "browser" | "node";
11
+ cachePath: string;
12
+ includes?: string[];
16
13
  }): PluginOption[] => {
17
- const externals = opt.includes ?? [];
14
+ const externals = opt.includes ?? [];
18
15
 
19
- const builtins = [
20
- ...builtinModules,
21
- ...builtinModules.map((item) => `node:${item}`)
22
- ];
16
+ const builtins = [
17
+ ...builtinModules,
18
+ ...builtinModules.map((item) => `node:${item}`)
19
+ ];
23
20
 
24
- return [
25
- opt.target === "node" ? {
26
- name: "sd-cli:vite:external",
27
- enforce: "pre",
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.includes(source)) {
41
- return {
42
- id: source,
43
- external: true
44
- };
45
- }
21
+ return [
22
+ opt.target === "node" ? {
23
+ name: "sd-cli:vite:external",
24
+ enforce: "pre",
25
+ resolveId: (source, importer) => {
26
+ if (importer === undefined) return;
46
27
 
47
- if (builtins.includes(source)) {
48
- return {
49
- id: `node:${source}`,
50
- external: true
51
- };
52
- }
28
+ if (externals.includes(source)) {
29
+ return {
30
+ id: source,
31
+ external: true
32
+ };
33
+ }
53
34
 
54
- return;
55
- }
56
- } : {
57
- name: "sd-cli:vite:external",
58
- enforce: "pre",
59
- config: (conf) => {
60
- if (opt.dependencies) {
61
- const npmConfigPath = FsUtil.findAllParentChildPaths("package.json", conf.root ?? opt.cachePath).first()!;
62
- const npmConfig = FsUtil.readJson(npmConfigPath) as INpmConfig;
63
- if (npmConfig.dependencies) {
64
- externals.push(...Object.keys(npmConfig.dependencies));
65
- }
66
- }
35
+ if (builtins.includes(source)) {
36
+ return {
37
+ id: `node:${source}`,
38
+ external: true
39
+ };
40
+ }
67
41
 
68
- async function _getSnippetsAsync(moduleName: string, importer?: string): Promise<string> {
69
- const myRequire = createRequire(pathToFileURL(importer ?? process.cwd()).toString());
70
- let realModuleName: string;
71
- try {
72
- realModuleName = moduleName;
73
- } catch {
74
- realModuleName = await _getPreBundleAsync(moduleName);
75
- }
76
- const module = myRequire(realModuleName);
77
- const members = Object.getOwnPropertyNames(module);
78
- const {exports} = libEsm({exports: members});
79
- return `const avoid_parse_require = require; const _M_ = avoid_parse_require("${PathUtil.posix(realModuleName)}"); ${exports}`;
80
- }
42
+ return;
43
+ }
44
+ } : {
45
+ name: "sd-cli:vite:external",
46
+ enforce: "pre",
47
+ config: () => {
48
+ async function _getSnippetsAsync(moduleName: string, importer?: string): Promise<string> {
49
+ const myRequire = createRequire(pathToFileURL(importer ?? process.cwd()).toString());
50
+ let realModuleName: string;
51
+ try {
52
+ realModuleName = moduleName;
53
+ }
54
+ catch {
55
+ realModuleName = await _getPreBundleAsync(moduleName);
56
+ }
57
+ const module = myRequire(realModuleName);
58
+ const members = Object.getOwnPropertyNames(module);
59
+ const {exports} = libEsm({exports: members});
60
+ return `const avoid_parse_require = require; const _M_ = avoid_parse_require("${PathUtil.posix(realModuleName)}"); ${exports}`;
61
+ }
81
62
 
82
- async function _getPreBundleAsync(moduleName: string): Promise<string> {
83
- const outfile = path.posix.join(opt.cachePath, moduleName) + ".cjs";
84
- await esbuild.build({
85
- entryPoints: [moduleName],
86
- outfile,
87
- target: 'node18',
88
- format: 'cjs',
89
- bundle: true,
90
- sourcemap: 'inline',
91
- platform: 'node',
92
- external: builtins
93
- });
63
+ async function _getPreBundleAsync(moduleName: string): Promise<string> {
64
+ const outfile = path.posix.join(opt.cachePath, moduleName) + ".cjs";
65
+ await esbuild.build({
66
+ entryPoints: [moduleName],
67
+ outfile,
68
+ target: 'node18',
69
+ format: 'cjs',
70
+ bundle: true,
71
+ sourcemap: 'inline',
72
+ platform: 'node',
73
+ external: builtins
74
+ });
94
75
 
95
- return outfile;
96
- }
76
+ return outfile;
77
+ }
97
78
 
98
- return {
99
- resolve: {
100
- alias: [{
101
- find: new RegExp(`^(${[...externals, ...builtins].join("|")})$`),
102
- replacement: "$1",
79
+ return {
80
+ resolve: {
81
+ alias: [{
82
+ find: new RegExp(`^(${[...externals, ...builtins].join("|")})$`),
83
+ replacement: "$1",
103
84
 
104
- customResolver: async (source, importer) => {
105
- const id = path.posix.join(opt.cachePath, source) + ".mjs";
106
- if (!FsUtil.exists(id)) {
107
- await FsUtil.writeFileAsync(id, await _getSnippetsAsync(source, importer));
108
- }
109
- return {id};
110
- }
111
- }],
112
- }
113
- };
114
- }
115
- }
116
- ];
85
+ customResolver: async (source, importer) => {
86
+ const id = path.posix.join(opt.cachePath, source) + ".mjs";
87
+ if (!FsUtil.exists(id)) {
88
+ await FsUtil.writeFileAsync(id, await _getSnippetsAsync(source, importer));
89
+ }
90
+ return {id};
91
+ }
92
+ }],
93
+ }
94
+ };
95
+ }
96
+ }
97
+ ];
117
98
  };
@@ -24,13 +24,13 @@ export const SdCliViteReactSwcPlugin = (): PluginOption[] => {
24
24
  config: () => ({
25
25
  esbuild: false,
26
26
  optimizeDeps: {
27
- include: [`react/jsx-dev-runtime`],
27
+ include: [`react/jsx-dev-runtime`, `react/jsx-runtime`],
28
28
  },
29
29
  }),
30
30
  transformIndexHtml: (html, ctx) => [
31
31
  {
32
32
  tag: "script",
33
- attrs: { type: "module" },
33
+ attrs: {type: "module"},
34
34
  children: `import { injectIntoGlobalHook } from "${ctx.server!.config.base + runtimePublicPath.slice(1)}";
35
35
  injectIntoGlobalHook(window);
36
36
  window.$RefreshReg$ = () => {};
@@ -70,7 +70,7 @@ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
70
70
 
71
71
  const sourceMap: SourceMapPayload = JSON.parse(result.map!);
72
72
  sourceMap.mappings = ";;;;;;;;" + sourceMap.mappings;
73
- return { code: result.code, map: sourceMap };
73
+ return {code: result.code, map: sourceMap};
74
74
  },
75
75
  },
76
76
  {
@@ -106,9 +106,9 @@ const transformWithOptions = async (
106
106
  dev: boolean
107
107
  ) => {
108
108
  const parser: ParserConfig | undefined =
109
- id.endsWith(".tsx") ? { syntax: "typescript", tsx: true, decorators: true }
110
- : id.endsWith(".ts") ? { syntax: "typescript", tsx: false, decorators: true }
111
- : id.endsWith(".jsx") ? { syntax: "ecmascript", jsx: true }
109
+ id.endsWith(".tsx") ? {syntax: "typescript", tsx: true, decorators: true}
110
+ : id.endsWith(".ts") ? {syntax: "typescript", tsx: false, decorators: true}
111
+ : id.endsWith(".jsx") ? {syntax: "ecmascript", jsx: true}
112
112
  : undefined;
113
113
  if (!parser) return;
114
114
 
@@ -0,0 +1,42 @@
1
+ import {PluginOption} from "vite";
2
+ import path from "path";
3
+ import {FsUtil} from "@simplysm/sd-core-node";
4
+ import {INpmConfig} from "../commons";
5
+
6
+ export const SdCliViteServeOptimizeExcludePlugin = (moduleGlobs: string[]): PluginOption[] => {
7
+ return [{
8
+ name: "sd-cli:vite:serve-optimize-exclude",
9
+ apply: "serve",
10
+ enforce: "pre",
11
+ config: (conf) => {
12
+ const pkgPath = path.resolve(conf.root!, "..");
13
+
14
+ const pkgNpmConf = FsUtil.readJson(path.resolve(pkgPath, "package.json")) as INpmConfig;
15
+ const pkgDeps = Object.keys(pkgNpmConf.dependencies ?? {});
16
+
17
+ const modulePaths = moduleGlobs.mapMany(item => FsUtil.glob(path.resolve(process.cwd(), "node_modules", item))).distinct();
18
+ const moduleNames = modulePaths.map(item => item.match(/[\\\/]node_modules[\\\/](.*)/)![1].replace(/\\/g, "/"))
19
+ .filter(item => pkgDeps.includes(item))
20
+ .distinct();
21
+
22
+ const subDeps: string[] = [];
23
+ for (const moduleName of moduleNames) {
24
+ const moduleNpmConf = FsUtil.readJson(path.resolve(process.cwd(), "node_modules", moduleName, "package.json")) as INpmConfig;
25
+ const depNames = Object.keys(moduleNpmConf.dependencies ?? {});
26
+ subDeps.push(...depNames.filter(item => !moduleNames.includes(item)));
27
+ }
28
+
29
+ return {
30
+ server: {
31
+ watch: {
32
+ ignored: moduleNames.map(item => `!**/node_modules/${item}/**`)
33
+ }
34
+ },
35
+ optimizeDeps: {
36
+ exclude: moduleNames,
37
+ include: subDeps
38
+ }
39
+ };
40
+ }
41
+ }];
42
+ };