@simplysm/sd-cli 10.0.65 → 11.0.3

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 (74) hide show
  1. package/dist/build-cluster.js +15 -14
  2. package/dist/build-cluster.js.map +1 -1
  3. package/dist/build-tools/SdTsIncrementalBuilder.d.ts +2 -0
  4. package/dist/build-tools/SdTsIncrementalBuilder.js +60 -9
  5. package/dist/build-tools/SdTsIncrementalBuilder.js.map +1 -1
  6. package/dist/builders/SdCliClientBuilder.d.ts +6 -7
  7. package/dist/builders/SdCliClientBuilder.js +281 -245
  8. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  9. package/dist/builders/SdCliServerBuilder.d.ts +4 -3
  10. package/dist/builders/SdCliServerBuilder.js +3 -2
  11. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  12. package/dist/builders/SdCliTsLibBuilder.d.ts +4 -4
  13. package/dist/builders/SdCliTsLibBuilder.js +9 -61
  14. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  15. package/dist/commons.d.ts +4 -5
  16. package/dist/entry/SdCliProject.js +13 -12
  17. package/dist/entry/SdCliProject.js.map +1 -1
  18. package/dist/index.d.ts +0 -10
  19. package/dist/index.js +0 -10
  20. package/dist/index.js.map +1 -1
  21. package/dist/sd-cli.js +0 -19
  22. package/dist/sd-cli.js.map +1 -1
  23. package/package.json +14 -18
  24. package/src/build-cluster.ts +15 -14
  25. package/src/build-tools/SdTsIncrementalBuilder.ts +92 -10
  26. package/src/builders/SdCliClientBuilder.ts +310 -285
  27. package/src/builders/SdCliServerBuilder.ts +12 -7
  28. package/src/builders/SdCliTsLibBuilder.ts +11 -80
  29. package/src/commons.ts +5 -5
  30. package/src/entry/SdCliElectron.ts +3 -3
  31. package/src/entry/SdCliLocalUpdate.ts +3 -3
  32. package/src/entry/SdCliProject.ts +20 -18
  33. package/src/index.ts +0 -10
  34. package/src/sd-cli.ts +0 -23
  35. package/dist/entry/SdCliPwaAssets.d.ts +0 -6
  36. package/dist/entry/SdCliPwaAssets.js +0 -39
  37. package/dist/entry/SdCliPwaAssets.js.map +0 -1
  38. package/dist/utils/SdCliViteElectronMainPlugin.d.ts +0 -6
  39. package/dist/utils/SdCliViteElectronMainPlugin.js +0 -96
  40. package/dist/utils/SdCliViteElectronMainPlugin.js.map +0 -1
  41. package/dist/utils/SdCliViteExternalPlugin.d.ts +0 -6
  42. package/dist/utils/SdCliViteExternalPlugin.js +0 -85
  43. package/dist/utils/SdCliViteExternalPlugin.js.map +0 -1
  44. package/dist/utils/SdCliViteLazyImportPlugin.d.ts +0 -2
  45. package/dist/utils/SdCliViteLazyImportPlugin.js +0 -23
  46. package/dist/utils/SdCliViteLazyImportPlugin.js.map +0 -1
  47. package/dist/utils/SdCliViteLoggerPlugin.d.ts +0 -6
  48. package/dist/utils/SdCliViteLoggerPlugin.js +0 -24
  49. package/dist/utils/SdCliViteLoggerPlugin.js.map +0 -1
  50. package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +0 -2
  51. package/dist/utils/SdCliViteNodeGlobalPlugin.js +0 -29
  52. package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +0 -1
  53. package/dist/utils/SdCliViteReactSwcPlugin.d.ts +0 -2
  54. package/dist/utils/SdCliViteReactSwcPlugin.js +0 -139
  55. package/dist/utils/SdCliViteReactSwcPlugin.js.map +0 -1
  56. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.d.ts +0 -2
  57. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js +0 -36
  58. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js.map +0 -1
  59. package/dist/utils/getElectronReactExternals.d.ts +0 -1
  60. package/dist/utils/getElectronReactExternals.js +0 -17
  61. package/dist/utils/getElectronReactExternals.js.map +0 -1
  62. package/dist/utils/sdCliTsDefineTransformer.d.ts +0 -4
  63. package/dist/utils/sdCliTsDefineTransformer.js +0 -26
  64. package/dist/utils/sdCliTsDefineTransformer.js.map +0 -1
  65. package/src/entry/SdCliPwaAssets.ts +0 -50
  66. package/src/utils/SdCliViteElectronMainPlugin.ts +0 -102
  67. package/src/utils/SdCliViteExternalPlugin.ts +0 -98
  68. package/src/utils/SdCliViteLazyImportPlugin.ts +0 -26
  69. package/src/utils/SdCliViteLoggerPlugin.ts +0 -29
  70. package/src/utils/SdCliViteNodeGlobalPlugin.ts +0 -31
  71. package/src/utils/SdCliViteReactSwcPlugin.ts +0 -153
  72. package/src/utils/SdCliViteServeOptimizeExcludePlugin.ts +0 -42
  73. package/src/utils/getElectronReactExternals.ts +0 -19
  74. package/src/utils/sdCliTsDefineTransformer.ts +0 -33
@@ -1,98 +0,0 @@
1
- import {PluginOption} from "vite";
2
- import {builtinModules, createRequire} from "node:module";
3
- import {FsUtil, PathUtil} from "@simplysm/sd-core-node";
4
- import path from "path";
5
- import {pathToFileURL} from "url";
6
- import libEsm from "lib-esm";
7
- import esbuild from "esbuild";
8
-
9
- export const SdCliViteExternalPlugin = (opt: {
10
- target: "browser" | "node";
11
- cachePath: string;
12
- includes?: string[];
13
- }): PluginOption[] => {
14
- const externals = opt.includes ?? [];
15
-
16
- const builtins = [
17
- ...builtinModules,
18
- ...builtinModules.map((item) => `node:${item}`)
19
- ];
20
-
21
- return [
22
- opt.target === "node" ? {
23
- name: "sd-cli:vite:external",
24
- enforce: "pre",
25
- resolveId: (source, importer) => {
26
- if (importer === undefined) return;
27
-
28
- if (externals.includes(source)) {
29
- return {
30
- id: source,
31
- external: true
32
- };
33
- }
34
-
35
- if (builtins.includes(source)) {
36
- return {
37
- id: `node:${source}`,
38
- external: true
39
- };
40
- }
41
-
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
- }
62
-
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
- });
75
-
76
- return outfile;
77
- }
78
-
79
- return {
80
- resolve: {
81
- alias: [{
82
- find: new RegExp(`^(${[...externals, ...builtins].join("|")})$`),
83
- replacement: "$1",
84
-
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
- ];
98
- };
@@ -1,26 +0,0 @@
1
- import {PluginOption} from "vite";
2
- import path from "path";
3
- import {FsUtil, PathUtil} from "@simplysm/sd-core-node";
4
-
5
- export const SdCliViteLazyImportPlugin = (): PluginOption[] => {
6
- return [
7
- {
8
- name: "sd-cli:vite:lazy-import",
9
- apply: "serve",
10
- transform: (code, id) => {
11
- const realId = id.split("?").first()!;
12
- if (/[\\\/]AppPage\.tsx/.test(realId) && code.includes("lazy(")) {
13
- const pageFileRelPaths = FsUtil.glob(path.resolve(path.dirname(realId), "pages/**/*.tsx"))
14
- .map((item) => PathUtil.posix(path.relative(path.dirname(realId), item)));
15
-
16
- return `
17
- ${pageFileRelPaths.map((item) => `import ("./${item}");`).join("\n")}
18
-
19
- ${code}`;
20
- }
21
-
22
- return null;
23
- },
24
- }
25
- ];
26
- };
@@ -1,29 +0,0 @@
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
- };
@@ -1,31 +0,0 @@
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
- enforce: "post",
24
- ...inject({
25
- global: [esbuildShim, 'global'],
26
- process: [esbuildShim, 'process'],
27
- Buffer: [esbuildShim, 'Buffer']
28
- })
29
- } as PluginOption
30
- ];
31
- };
@@ -1,153 +0,0 @@
1
- import {PluginOption} from "vite";
2
- import {FsUtil} from "@simplysm/sd-core-node";
3
- import {SourceMapPayload} from "module";
4
- import {Output, ParserConfig, transform,} from "@swc/core";
5
- import path from "path";
6
-
7
- const runtimePublicPath = "/@react-refresh";
8
-
9
- export const SdCliViteReactSwcPlugin = (): PluginOption[] => {
10
- return [
11
- {
12
- name: "sd-cli:vite:react-swc:resolve-runtime",
13
- apply: "serve",
14
- enforce: "pre", // Run before Vite default resolve to avoid syscalls
15
- resolveId: (source) => (source === runtimePublicPath ? source : undefined),
16
- load: (id) => {
17
- if (id !== runtimePublicPath) return;
18
- return FsUtil.readFile(path.resolve(process.cwd(), "node_modules/@vitejs/plugin-react-swc/refresh-runtime.js"));
19
- }
20
- },
21
- {
22
- name: "sd-cli:vite:react-swc",
23
- apply: "serve",
24
- config: () => ({
25
- esbuild: false,
26
- optimizeDeps: {
27
- include: [`react/jsx-dev-runtime`, `react/jsx-runtime`],
28
- },
29
- }),
30
- transformIndexHtml: (html, ctx) => [
31
- {
32
- tag: "script",
33
- attrs: {type: "module"},
34
- children: `import { injectIntoGlobalHook } from "${ctx.server!.config.base + runtimePublicPath.slice(1)}";
35
- injectIntoGlobalHook(window);
36
- window.$RefreshReg$ = () => {};
37
- window.$RefreshSig$ = () => (type) => type;`,
38
- },
39
- ],
40
- transform: async (code, id) => {
41
- const realId = id.split("?").first()!;
42
-
43
- const result = await transformWithOptions(realId, code, true);
44
- if (!result) return;
45
-
46
- if (!/\$Refresh(?:Reg|Sig)\$\(/.test(result.code)) {
47
- return result;
48
- }
49
-
50
- result.code = `import * as RefreshRuntime from "${runtimePublicPath}";
51
-
52
- if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
53
- const prevRefreshReg = window.$RefreshReg$;
54
- const prevRefreshSig = window.$RefreshSig$;
55
- window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${realId}");
56
- window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
57
-
58
- ${result.code}
59
-
60
- window.$RefreshReg$ = prevRefreshReg;
61
- window.$RefreshSig$ = prevRefreshSig;
62
- RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
63
- RefreshRuntime.registerExportsForReactRefresh("${realId}", currentExports);
64
- import.meta.hot.accept((nextExports) => {
65
- if (!nextExports) return;
66
- const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports);
67
- if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
68
- });
69
- });
70
- `;
71
-
72
- const sourceMap: SourceMapPayload = JSON.parse(result.map!);
73
- sourceMap.mappings = ";;;;;;;;" + sourceMap.mappings;
74
- return {code: result.code, map: sourceMap};
75
- },
76
- },
77
- {
78
- name: "sd-cli:vite:react-swc",
79
- apply: "build",
80
- enforce: "pre", // Run before esbuild
81
- config: () => ({
82
- esbuild: {
83
- minifyIdentifiers: false,
84
- },
85
- build: {
86
- rollupOptions: {
87
- onwarn: (warning, defaultHandler) => {
88
- if (
89
- warning.code === "MODULE_LEVEL_DIRECTIVE" &&
90
- warning.message.includes("use client")
91
- ) {
92
- return;
93
- }
94
- defaultHandler(warning);
95
- }
96
- }
97
- },
98
- }),
99
- transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, false)
100
- }
101
- ];
102
- };
103
-
104
- const transformWithOptions = async (
105
- id: string,
106
- code: string,
107
- dev: boolean
108
- ) => {
109
- const parser: ParserConfig | undefined =
110
- id.endsWith(".tsx") ? {syntax: "typescript", tsx: true, decorators: true}
111
- : id.endsWith(".ts") ? {syntax: "typescript", tsx: false, decorators: true}
112
- : id.endsWith(".jsx") ? {syntax: "ecmascript", jsx: true}
113
- : undefined;
114
- if (!parser) return;
115
-
116
- let result: Output;
117
- try {
118
- result = await transform(code, {
119
- filename: id,
120
- swcrc: false,
121
- configFile: false,
122
- sourceMaps: true,
123
- jsc: {
124
- target: "es2021",
125
- parser,
126
- transform: {
127
- useDefineForClassFields: true,
128
- react: {
129
- runtime: "automatic",
130
- importSource: "react",
131
- refresh: dev,
132
- development: dev,
133
- },
134
- decoratorMetadata: true
135
- },
136
- },
137
- });
138
- }
139
- catch (e: any) {
140
- const message: string = e.message;
141
- const fileStartIndex = message.indexOf("╭─[");
142
- if (fileStartIndex !== -1) {
143
- const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)]/);
144
- if (match) {
145
- e.line = match[1];
146
- e.column = match[2];
147
- }
148
- }
149
- throw e;
150
- }
151
-
152
- return result;
153
- };
@@ -1,42 +0,0 @@
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
- };
@@ -1,19 +0,0 @@
1
- import {FsUtil} from "@simplysm/sd-core-node";
2
- import {INpmConfig} from "../commons";
3
-
4
- export const getElectronReactExternals = (pkgPath: string, deps: string[]): string[] => {
5
- const result: string[] = [];
6
- for (const dep of deps) {
7
- if (dep === "electron") continue;
8
-
9
- const depNpmConfFilePath = FsUtil.findAllParentChildPaths(`node_modules/${dep}/package.json`, pkgPath).first();
10
- if (depNpmConfFilePath === undefined) continue;
11
-
12
- const depNpmConf = FsUtil.readJson(depNpmConfFilePath) as INpmConfig;
13
- if (depNpmConf.dependencies && Object.keys(depNpmConf.dependencies).includes("react")) continue;
14
-
15
- result.push(dep);
16
- }
17
-
18
- return result;
19
- };
@@ -1,33 +0,0 @@
1
- import ts from "typescript";
2
-
3
- export function sdCliTsDefineTransformer(_: ts.Program, args: {
4
- replace: Record<string, string>
5
- }): ts.TransformerFactory<ts.SourceFile> {
6
- return (context: ts.TransformationContext) => {
7
- return (sourceFile: ts.SourceFile): ts.SourceFile => {
8
- const visitor = (node: ts.Node): ts.Node => {
9
- if (
10
- ts.isCallExpression(node) ||
11
- ts.isIdentifier(node) ||
12
- ts.isExpressionStatement(node) ||
13
- ts.isPropertyAccessExpression(node) ||
14
- ts.isTypeOfExpression(node) ||
15
- ts.isElementAccessExpression(node)
16
- ) {
17
- const regex = /\[["'`](.*)["'`]]/;
18
- const replaceKey = node.getText().replace(new RegExp(regex, "g"), (str) => `.${str.match(regex)![1]}`);
19
- const replaceValue = args.replace[replaceKey];
20
- if (replaceValue !== undefined) {
21
- return ts.factory.createIdentifier(replaceValue);
22
- }
23
-
24
- return node;
25
- }
26
-
27
- return ts.visitEachChild(node, visitor, context);
28
- };
29
-
30
- return ts.visitNode(sourceFile, visitor) as ts.SourceFile;
31
- };
32
- };
33
- }