@simplysm/sd-cli 10.0.37 → 10.0.40

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 +92 -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 +26 -12
  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 +457 -394
  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
@@ -0,0 +1,154 @@
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`],
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
+ if (!/\$Refresh(?:Reg|Sig)\$\(/.test(result.code)) {
46
+ return result;
47
+ }
48
+
49
+ result.code = `import * as RefreshRuntime from "${runtimePublicPath}";
50
+
51
+ if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
52
+ const prevRefreshReg = window.$RefreshReg$;
53
+ const prevRefreshSig = window.$RefreshSig$;
54
+ window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${realId}");
55
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
56
+
57
+ ${result.code}
58
+
59
+ window.$RefreshReg$ = prevRefreshReg;
60
+ window.$RefreshSig$ = prevRefreshSig;
61
+ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
62
+ RefreshRuntime.registerExportsForReactRefresh("${realId}", currentExports);
63
+ import.meta.hot.accept((nextExports) => {
64
+ if (!nextExports) return;
65
+ const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports);
66
+ if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
67
+ });
68
+ });
69
+ `;
70
+
71
+ const sourceMap: SourceMapPayload = JSON.parse(result.map!);
72
+ sourceMap.mappings = ";;;;;;;;" + sourceMap.mappings;
73
+ return { code: result.code, map: sourceMap };
74
+ },
75
+ },
76
+ {
77
+ name: "sd-cli:vite:react-swc",
78
+ apply: "build",
79
+ enforce: "pre", // Run before esbuild
80
+ config: () => ({
81
+ esbuild: {
82
+ minifyIdentifiers: false,
83
+ },
84
+ build: {
85
+ rollupOptions: {
86
+ onwarn: (warning, defaultHandler) => {
87
+ if (
88
+ warning.code === "MODULE_LEVEL_DIRECTIVE" &&
89
+ warning.message.includes("use client")
90
+ ) {
91
+ return;
92
+ }
93
+ defaultHandler(warning);
94
+ }
95
+ }
96
+ },
97
+ }),
98
+ transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, false)
99
+ }
100
+ ];
101
+ };
102
+
103
+ const transformWithOptions = async (
104
+ id: string,
105
+ code: string,
106
+ dev: boolean
107
+ ) => {
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 }
112
+ : undefined;
113
+ if (!parser) return;
114
+
115
+ let result: Output;
116
+ try {
117
+ result = await transform(code, {
118
+ filename: id,
119
+ swcrc: false,
120
+ configFile: false,
121
+ sourceMaps: true,
122
+ jsc: {
123
+ target: "es2021",
124
+ parser,
125
+ transform: {
126
+ useDefineForClassFields: true,
127
+ react: {
128
+ runtime: "automatic",
129
+ importSource: "react",
130
+ ...dev ? {
131
+ refresh: true,
132
+ development: true,
133
+ } : {}
134
+ },
135
+ decoratorMetadata: true
136
+ },
137
+ },
138
+ });
139
+ }
140
+ catch (e: any) {
141
+ const message: string = e.message;
142
+ const fileStartIndex = message.indexOf("╭─[");
143
+ if (fileStartIndex !== -1) {
144
+ const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)]/);
145
+ if (match) {
146
+ e.line = match[1];
147
+ e.column = match[2];
148
+ }
149
+ }
150
+ throw e;
151
+ }
152
+
153
+ return result;
154
+ };
@@ -0,0 +1,29 @@
1
+ import * as vite from "vite";
2
+ import { PluginOption } from "vite";
3
+ import path from "path";
4
+ import { INpmConfig } from "../commons";
5
+ import { FsUtil } from "@simplysm/sd-core-node";
6
+
7
+ export const SdCliViteServeWithResolutionsPlugin = (): PluginOption[] => {
8
+ const projNpmConfig: INpmConfig = FsUtil.readJson(path.resolve(process.cwd(), "package.json"));
9
+
10
+ return [
11
+ {
12
+ name: "sd-cli:vite:serve-with-resolutions",
13
+ apply: "serve",
14
+ enforce: "pre",
15
+ config: () => ({
16
+ server: {
17
+ fs: {
18
+ allow: [
19
+ vite.searchForWorkspaceRoot(process.cwd()),
20
+ ...projNpmConfig.resolutions
21
+ ? Object.values(projNpmConfig.resolutions).map((item) => vite.searchForWorkspaceRoot(path.resolve(process.cwd(), item.slice(7))))
22
+ : []
23
+ ].distinct()
24
+ },
25
+ },
26
+ }),
27
+ }
28
+ ];
29
+ };
@@ -0,0 +1,19 @@
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
+ };
@@ -0,0 +1,31 @@
1
+ import ts from "typescript";
2
+
3
+ export function sdCliTsDefineTransformer(_: ts.Program, args: { replace: Record<string, string> }): ts.TransformerFactory<ts.SourceFile> {
4
+ return (context) => {
5
+ return (sourceFile) => {
6
+ const visitor = (node: ts.Node): ts.Node => {
7
+ if (
8
+ ts.isCallExpression(node) ||
9
+ ts.isIdentifier(node) ||
10
+ ts.isExpressionStatement(node) ||
11
+ ts.isPropertyAccessExpression(node) ||
12
+ ts.isTypeOfExpression(node) ||
13
+ ts.isElementAccessExpression(node)
14
+ ) {
15
+ const regex = /\[["'`](.*)["'`]]/;
16
+ const replaceKey = node.getText().replace(new RegExp(regex, "g"), str => `.${str.match(regex)![1]}`);
17
+ const replaceValue = args.replace[replaceKey];
18
+ if (replaceValue !== undefined) {
19
+ return ts.factory.createIdentifier(replaceValue);
20
+ }
21
+
22
+ return node;
23
+ }
24
+
25
+ return ts.visitEachChild(node, visitor, context);
26
+ };
27
+
28
+ return ts.visitNode(sourceFile, visitor);
29
+ };
30
+ };
31
+ }
package/.eslintrc.cjs DELETED
@@ -1,18 +0,0 @@
1
- module.exports = {
2
- overrides: [
3
- {
4
- files: ["*.ts", "*.tsx"],
5
- parserOptions: {
6
- tsconfigRootDir: __dirname,
7
- project: "tsconfig.json"
8
- },
9
- settings: {
10
- "import/resolver": {
11
- "typescript": {
12
- project: "tsconfig.json"
13
- }
14
- }
15
- }
16
- }
17
- ]
18
- };
@@ -1,7 +0,0 @@
1
- import { ISdCliConfig } from "../commons";
2
- export declare class SdCliConfigUtil {
3
- static loadConfigAsync(confFilePath: string, isDev: boolean, opts?: string[]): Promise<ISdCliConfig>;
4
- private static _getConfigFromFileContent;
5
- private static _getPkgConfigFromFileContent;
6
- private static _mergeObj;
7
- }
@@ -1,69 +0,0 @@
1
- import { FsUtil } from "@simplysm/sd-core-node";
2
- import { ObjectUtil } from "@simplysm/sd-core-common";
3
- import path from "path";
4
- export class SdCliConfigUtil {
5
- static async loadConfigAsync(confFilePath, isDev, opts) {
6
- const confFileCont = await FsUtil.readJsonAsync(confFilePath);
7
- let conf = this._getConfigFromFileContent(confFileCont, isDev, opts);
8
- // extends
9
- if (conf.extends) {
10
- for (const extConfFilePath of conf.extends) {
11
- const extConf = await this.loadConfigAsync(path.resolve(path.dirname(confFilePath), extConfFilePath), isDev, opts);
12
- conf = this._mergeObj(extConf, conf);
13
- }
14
- }
15
- delete conf["extends"];
16
- return conf;
17
- }
18
- static _getConfigFromFileContent(confFileCont, isDev, opts) {
19
- const conf = ObjectUtil.clone(confFileCont);
20
- if (conf.packages) {
21
- for (const pkgName of Object.keys(conf.packages)) {
22
- conf.packages[pkgName] = this._getPkgConfigFromFileContent(conf, conf.packages[pkgName], isDev, opts);
23
- }
24
- }
25
- return conf;
26
- }
27
- static _getPkgConfigFromFileContent(confFileCont, pkgConfFileCont, isDev, opts) {
28
- let pkgConf = ObjectUtil.clone(pkgConfFileCont);
29
- // override
30
- const pkgOvrNames = pkgConf.overrides;
31
- if (pkgOvrNames) {
32
- for (const pkgOvrName of pkgOvrNames) {
33
- const rootOvr = confFileCont.overrides?.[pkgOvrName];
34
- if (rootOvr) {
35
- const ovrConf = this._getPkgConfigFromFileContent(confFileCont, rootOvr, isDev, opts);
36
- pkgConf = this._mergeObj(pkgConf, ovrConf);
37
- }
38
- }
39
- delete pkgConf.overrides;
40
- }
41
- // mode 처리
42
- const mode = isDev ? "dev" : "prod";
43
- if (pkgConf[mode] !== undefined) {
44
- const modeConf = this._getPkgConfigFromFileContent(confFileCont, pkgConf[mode], isDev, opts);
45
- pkgConf = this._mergeObj(pkgConf, modeConf);
46
- }
47
- delete pkgConf["dev"];
48
- delete pkgConf["prod"];
49
- // options
50
- if (opts && opts.length > 0) {
51
- const pkgOpts = Object.keys(pkgConf).filter((key) => key.startsWith("@") && opts.some((opt) => opt === key.slice(1)));
52
- for (const pkgOpt of pkgOpts) {
53
- const optConf = this._getPkgConfigFromFileContent(confFileCont, pkgConf[pkgOpt], isDev, opts);
54
- pkgConf = this._mergeObj(pkgConf, optConf);
55
- }
56
- for (const optKey of Object.keys(pkgConf).filter((item) => item.startsWith("@"))) {
57
- delete pkgConf[optKey];
58
- }
59
- }
60
- return pkgConf;
61
- }
62
- static _mergeObj(orig, target) {
63
- return ObjectUtil.merge(orig, target, {
64
- arrayProcess: "replace",
65
- useDelTargetNull: true
66
- });
67
- }
68
- }
69
- //# sourceMappingURL=SdCliConfigUtil.js.map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I,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAEtH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,4BAA4B,CAAC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;gBAC9F,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;aAC5C;YAED,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE;gBAChF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;aACxB;SACF;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,MAAM,CAAC,SAAS,CAAO,IAAO,EAAE,MAAS;QAC/C,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE;YACpC,YAAY,EAAE,SAAS;YACvB,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,94 +0,0 @@
1
- import { ISdCliConfig, TSdCliPackageConfig } from "../commons";
2
- import { FsUtil } from "@simplysm/sd-core-node";
3
- import { ObjectUtil } from "@simplysm/sd-core-common";
4
- import path from "path";
5
-
6
- export class SdCliConfigUtil {
7
- public static async loadConfigAsync(confFilePath: string, isDev: boolean, opts?: string[]): Promise<ISdCliConfig> {
8
- const confFileCont = await FsUtil.readJsonAsync(confFilePath);
9
- let conf = this._getConfigFromFileContent(confFileCont, isDev, opts);
10
-
11
- // extends
12
- if (conf.extends) {
13
- for (const extConfFilePath of conf.extends) {
14
- const extConf = await this.loadConfigAsync(path.resolve(path.dirname(confFilePath), extConfFilePath), isDev, opts);
15
- conf = this._mergeObj(extConf, conf);
16
- }
17
- }
18
- delete conf["extends"];
19
-
20
- return conf as ISdCliConfig;
21
- }
22
-
23
- private static _getConfigFromFileContent(confFileCont: ISdCliConfigFileContent, isDev: boolean, opts?: string[]): ISdCliConfigFileContent {
24
- const conf = ObjectUtil.clone(confFileCont);
25
-
26
- if (conf.packages) {
27
- for (const pkgName of Object.keys(conf.packages)) {
28
- conf.packages[pkgName] = this._getPkgConfigFromFileContent(conf, conf.packages[pkgName], isDev, opts);
29
- }
30
- }
31
- return conf;
32
- }
33
-
34
- private static _getPkgConfigFromFileContent(confFileCont: ISdCliConfigFileContent, pkgConfFileCont: TSdCliPackageConfigFileContent, isDev: boolean, opts?: string[]): TSdCliPackageConfig {
35
- let pkgConf = ObjectUtil.clone(pkgConfFileCont);
36
-
37
- // override
38
- const pkgOvrNames = pkgConf.overrides;
39
- if (pkgOvrNames) {
40
- for (const pkgOvrName of pkgOvrNames) {
41
- const rootOvr = confFileCont.overrides?.[pkgOvrName];
42
- if (rootOvr) {
43
- const ovrConf = this._getPkgConfigFromFileContent(confFileCont, rootOvr, isDev, opts);
44
- pkgConf = this._mergeObj(pkgConf, ovrConf);
45
- }
46
- }
47
- delete pkgConf.overrides;
48
- }
49
-
50
-
51
- // mode 처리
52
- const mode = isDev ? "dev" : "prod";
53
- if (pkgConf[mode] !== undefined) {
54
- const modeConf = this._getPkgConfigFromFileContent(confFileCont, pkgConf[mode], isDev, opts);
55
- pkgConf = this._mergeObj(pkgConf, modeConf);
56
- }
57
- delete pkgConf["dev"];
58
- delete pkgConf["prod"];
59
-
60
- // options
61
- if (opts && opts.length > 0) {
62
- const pkgOpts = Object.keys(pkgConf).filter((key) => key.startsWith("@") && opts.some((opt) => opt === key.slice(1)));
63
-
64
- for (const pkgOpt of pkgOpts) {
65
- const optConf = this._getPkgConfigFromFileContent(confFileCont, pkgConf[pkgOpt], isDev, opts);
66
- pkgConf = this._mergeObj(pkgConf, optConf);
67
- }
68
-
69
- for (const optKey of Object.keys(pkgConf).filter((item) => item.startsWith("@"))) {
70
- delete pkgConf[optKey];
71
- }
72
- }
73
-
74
- return pkgConf;
75
- }
76
-
77
- private static _mergeObj<A, B>(orig: A, target: B): A & B {
78
- return ObjectUtil.merge(orig, target, {
79
- arrayProcess: "replace",
80
- useDelTargetNull: true
81
- });
82
- }
83
- }
84
-
85
- interface ISdCliConfigFileContent {
86
- packages?: Record<string, TSdCliPackageConfigFileContent>;
87
- overrides?: Record<string, TSdCliPackageConfigFileContent>;
88
- extends?: string[];
89
- }
90
-
91
- type TSdCliPackageConfigFileContent =
92
- TSdCliPackageConfig
93
- & { overrides?: string[] }
94
- & Record<string, any>;