@modern-js/plugin-v2 0.0.0-next-20241113090110

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/dist/cjs/cli/api.js +107 -0
  4. package/dist/cjs/cli/context.js +75 -0
  5. package/dist/cjs/cli/hooks.js +65 -0
  6. package/dist/cjs/cli/index.js +43 -0
  7. package/dist/cjs/cli/run/config/createLoadedConfig.js +99 -0
  8. package/dist/cjs/cli/run/config/createResolvedConfig.js +40 -0
  9. package/dist/cjs/cli/run/config/loadConfig.js +117 -0
  10. package/dist/cjs/cli/run/create.js +125 -0
  11. package/dist/cjs/cli/run/index.js +29 -0
  12. package/dist/cjs/cli/run/run.js +58 -0
  13. package/dist/cjs/cli/run/types.js +16 -0
  14. package/dist/cjs/cli/run/utils/checkIsDuplicationPlugin.js +45 -0
  15. package/dist/cjs/cli/run/utils/commander.js +50 -0
  16. package/dist/cjs/cli/run/utils/createFileWatcher.js +114 -0
  17. package/dist/cjs/cli/run/utils/initAppDir.js +49 -0
  18. package/dist/cjs/cli/run/utils/loadEnv.js +53 -0
  19. package/dist/cjs/cli/run/utils/mergeConfig.js +62 -0
  20. package/dist/cjs/hooks.js +69 -0
  21. package/dist/cjs/index.js +38 -0
  22. package/dist/cjs/manager.js +141 -0
  23. package/dist/cjs/types/cli/api.js +16 -0
  24. package/dist/cjs/types/cli/context.js +16 -0
  25. package/dist/cjs/types/cli/hooks.js +16 -0
  26. package/dist/cjs/types/cli/index.js +16 -0
  27. package/dist/cjs/types/cli/plugin.js +16 -0
  28. package/dist/cjs/types/hooks.js +16 -0
  29. package/dist/cjs/types/index.js +24 -0
  30. package/dist/cjs/types/plugin.js +16 -0
  31. package/dist/cjs/types/utils.js +16 -0
  32. package/dist/esm/index.js +1499 -0
  33. package/dist/esm-node/cli/api.js +83 -0
  34. package/dist/esm-node/cli/context.js +40 -0
  35. package/dist/esm-node/cli/hooks.js +41 -0
  36. package/dist/esm-node/cli/index.js +14 -0
  37. package/dist/esm-node/cli/run/config/createLoadedConfig.js +74 -0
  38. package/dist/esm-node/cli/run/config/createResolvedConfig.js +16 -0
  39. package/dist/esm-node/cli/run/config/loadConfig.js +80 -0
  40. package/dist/esm-node/cli/run/create.js +101 -0
  41. package/dist/esm-node/cli/run/index.js +5 -0
  42. package/dist/esm-node/cli/run/run.js +34 -0
  43. package/dist/esm-node/cli/run/types.js +0 -0
  44. package/dist/esm-node/cli/run/utils/checkIsDuplicationPlugin.js +21 -0
  45. package/dist/esm-node/cli/run/utils/commander.js +24 -0
  46. package/dist/esm-node/cli/run/utils/createFileWatcher.js +80 -0
  47. package/dist/esm-node/cli/run/utils/initAppDir.js +15 -0
  48. package/dist/esm-node/cli/run/utils/loadEnv.js +19 -0
  49. package/dist/esm-node/cli/run/utils/mergeConfig.js +38 -0
  50. package/dist/esm-node/hooks.js +44 -0
  51. package/dist/esm-node/index.js +9 -0
  52. package/dist/esm-node/manager.js +117 -0
  53. package/dist/esm-node/types/cli/api.js +0 -0
  54. package/dist/esm-node/types/cli/context.js +0 -0
  55. package/dist/esm-node/types/cli/hooks.js +0 -0
  56. package/dist/esm-node/types/cli/index.js +0 -0
  57. package/dist/esm-node/types/cli/plugin.js +0 -0
  58. package/dist/esm-node/types/hooks.js +0 -0
  59. package/dist/esm-node/types/index.js +2 -0
  60. package/dist/esm-node/types/plugin.js +0 -0
  61. package/dist/esm-node/types/utils.js +0 -0
  62. package/dist/types/cli/api.d.ts +7 -0
  63. package/dist/types/cli/context.d.ts +18 -0
  64. package/dist/types/cli/hooks.d.ts +39 -0
  65. package/dist/types/cli/index.d.ts +6 -0
  66. package/dist/types/cli/run/config/createLoadedConfig.d.ts +6 -0
  67. package/dist/types/cli/run/config/createResolvedConfig.d.ts +3 -0
  68. package/dist/types/cli/run/config/loadConfig.d.ts +25 -0
  69. package/dist/types/cli/run/create.d.ts +7 -0
  70. package/dist/types/cli/run/index.d.ts +6 -0
  71. package/dist/types/cli/run/run.d.ts +2 -0
  72. package/dist/types/cli/run/types.d.ts +29 -0
  73. package/dist/types/cli/run/utils/checkIsDuplicationPlugin.d.ts +1 -0
  74. package/dist/types/cli/run/utils/commander.d.ts +5 -0
  75. package/dist/types/cli/run/utils/createFileWatcher.d.ts +2 -0
  76. package/dist/types/cli/run/utils/initAppDir.d.ts +1 -0
  77. package/dist/types/cli/run/utils/loadEnv.d.ts +1 -0
  78. package/dist/types/cli/run/utils/mergeConfig.d.ts +2 -0
  79. package/dist/types/hooks.d.ts +3 -0
  80. package/dist/types/index.d.ts +4 -0
  81. package/dist/types/manager.d.ts +2 -0
  82. package/dist/types/types/cli/api.d.ts +42 -0
  83. package/dist/types/types/cli/context.d.ts +40 -0
  84. package/dist/types/types/cli/hooks.d.ts +41 -0
  85. package/dist/types/types/cli/index.d.ts +3 -0
  86. package/dist/types/types/cli/plugin.d.ts +6 -0
  87. package/dist/types/types/hooks.d.ts +10 -0
  88. package/dist/types/types/index.d.ts +3 -0
  89. package/dist/types/types/plugin.d.ts +40 -0
  90. package/dist/types/types/utils.d.ts +5 -0
  91. package/package.json +85 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Modern.js
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ <p align="center">
2
+ <a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
3
+ </p>
4
+
5
+ <h1 align="center">Modern.js</h1>
6
+
7
+ <p align="center">
8
+ A Progressive React Framework for modern web development.
9
+ </p>
10
+
11
+ ## Getting Started
12
+
13
+ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
14
+
15
+ ## Documentation
16
+
17
+ - [English Documentation](https://modernjs.dev/en/)
18
+ - [中文文档](https://modernjs.dev)
19
+
20
+ ## Contributing
21
+
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
+
24
+ ## License
25
+
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var api_exports = {};
20
+ __export(api_exports, {
21
+ initPluginAPI: () => initPluginAPI
22
+ });
23
+ module.exports = __toCommonJS(api_exports);
24
+ var import_lodash = require("@modern-js/utils/lodash");
25
+ function initPluginAPI({ context }) {
26
+ const { hooks, extendsHooks, plugins } = context;
27
+ function getAppContext() {
28
+ if (context) {
29
+ const { hooks: hooks2, config, normalizedConfig, pluginAPI, ...appContext } = context;
30
+ return appContext;
31
+ }
32
+ throw new Error("Cannot access context");
33
+ }
34
+ function getConfig() {
35
+ if (context.config) {
36
+ return context.config;
37
+ }
38
+ throw new Error("Cannot access config");
39
+ }
40
+ function getNormalizedConfig() {
41
+ if (context.normalizedConfig) {
42
+ return context.normalizedConfig;
43
+ }
44
+ throw new Error("Cannot access normalized config");
45
+ }
46
+ function getHooks() {
47
+ return {
48
+ ...context.hooks,
49
+ ...context.extendsHooks
50
+ };
51
+ }
52
+ const extendsPluginApi = {};
53
+ function updateRegistryApi() {
54
+ plugins.forEach((plugin) => {
55
+ const { registryApi } = plugin;
56
+ if (registryApi) {
57
+ const apis = registryApi(context, updateAppContext);
58
+ Object.keys(apis).forEach((apiName) => {
59
+ extendsPluginApi[apiName] = apis[apiName];
60
+ });
61
+ }
62
+ });
63
+ }
64
+ updateRegistryApi();
65
+ Object.keys(extendsHooks).forEach((hookName) => {
66
+ extendsPluginApi[hookName] = extendsHooks[hookName].tap;
67
+ });
68
+ function updateAppContext(updateContext) {
69
+ context = (0, import_lodash.merge)(context, updateContext);
70
+ updateRegistryApi();
71
+ }
72
+ return {
73
+ getAppContext,
74
+ getConfig,
75
+ getNormalizedConfig,
76
+ getHooks,
77
+ updateAppContext,
78
+ config: hooks.config.tap,
79
+ modifyConfig: hooks.modifyConfig.tap,
80
+ modifyResolvedConfig: hooks.modifyResolvedConfig.tap,
81
+ modifyRsbuildConfig: hooks.modifyRsbuildConfig.tap,
82
+ modifyBundlerChain: hooks.modifyBundlerChain.tap,
83
+ modifyRspackConfig: hooks.modifyRspackConfig.tap,
84
+ modifyWebpackChain: hooks.modifyWebpackChain.tap,
85
+ modifyWebpackConfig: hooks.modifyWebpackConfig.tap,
86
+ modifyHtmlPartials: hooks.modifyHtmlPartials.tap,
87
+ addCommand: hooks.addCommand.tap,
88
+ onPrepare: hooks.onPrepare.tap,
89
+ onWatchFiles: hooks.addWatchFiles.tap,
90
+ onFileChanged: hooks.onFileChanged.tap,
91
+ onBeforeRestart: hooks.onBeforeRestart.tap,
92
+ onBeforeCreateCompiler: hooks.onBeforeCreateCompiler.tap,
93
+ onAfterCreateCompiler: hooks.onAfterCreateCompiler.tap,
94
+ onBeforeBuild: hooks.onBeforeBuild.tap,
95
+ onAfterBuild: hooks.onAfterBuild.tap,
96
+ onBeforeDev: hooks.onBeforeDev.tap,
97
+ onAfterDev: hooks.onAfterDev.tap,
98
+ onBeforeDeploy: hooks.onBeforeDeploy.tap,
99
+ onAfterDeploy: hooks.onAfterDeploy.tap,
100
+ onBeforeExit: hooks.onBeforeExit.tap,
101
+ ...extendsPluginApi
102
+ };
103
+ }
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ initPluginAPI
107
+ });
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var context_exports = {};
30
+ __export(context_exports, {
31
+ createContext: () => createContext,
32
+ initAppContext: () => initAppContext
33
+ });
34
+ module.exports = __toCommonJS(context_exports);
35
+ var import_path = __toESM(require("path"));
36
+ var import_hooks = require("./hooks");
37
+ function initAppContext(params) {
38
+ const { appDirectory, srcDir = "src", distDir = "dist" } = params;
39
+ return {
40
+ packageName: params.packageName,
41
+ configFile: params.configFile,
42
+ command: params.command,
43
+ isProd: process.env.NODE_ENV === "production",
44
+ appDirectory,
45
+ srcDirectory: import_path.default.resolve(appDirectory, srcDir),
46
+ distDirectory: import_path.default.resolve(appDirectory, distDir),
47
+ nodeModulesDirectory: import_path.default.resolve(appDirectory, "node_modules"),
48
+ plugins: params.plugins
49
+ };
50
+ }
51
+ async function createContext({ appContext, config, normalizedConfig }) {
52
+ const { plugins } = appContext;
53
+ const extendsHooks = {};
54
+ plugins.forEach((plugin) => {
55
+ const { registryHooks = {} } = plugin;
56
+ Object.keys(registryHooks).forEach((hookName) => {
57
+ extendsHooks[hookName] = registryHooks[hookName];
58
+ });
59
+ });
60
+ return {
61
+ ...appContext,
62
+ hooks: {
63
+ ...(0, import_hooks.initHooks)(),
64
+ ...extendsHooks
65
+ },
66
+ extendsHooks,
67
+ config,
68
+ normalizedConfig
69
+ };
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ createContext,
74
+ initAppContext
75
+ });
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var hooks_exports = {};
20
+ __export(hooks_exports, {
21
+ initHooks: () => initHooks
22
+ });
23
+ module.exports = __toCommonJS(hooks_exports);
24
+ var import_hooks = require("../hooks");
25
+ function initHooks() {
26
+ return {
27
+ /**
28
+ * add config for this cli plugin
29
+ */
30
+ config: (0, import_hooks.createCollectAsyncHook)(),
31
+ /**
32
+ * @private
33
+ * modify config for this cli plugin
34
+ */
35
+ modifyConfig: (0, import_hooks.createAsyncHook)(),
36
+ /**
37
+ * modify final config
38
+ */
39
+ modifyResolvedConfig: (0, import_hooks.createAsyncHook)(),
40
+ modifyRsbuildConfig: (0, import_hooks.createAsyncHook)(),
41
+ modifyBundlerChain: (0, import_hooks.createAsyncHook)(),
42
+ modifyRspackConfig: (0, import_hooks.createAsyncHook)(),
43
+ modifyWebpackChain: (0, import_hooks.createAsyncHook)(),
44
+ modifyWebpackConfig: (0, import_hooks.createAsyncHook)(),
45
+ modifyHtmlPartials: (0, import_hooks.createAsyncHook)(),
46
+ addCommand: (0, import_hooks.createAsyncHook)(),
47
+ addWatchFiles: (0, import_hooks.createCollectAsyncHook)(),
48
+ onPrepare: (0, import_hooks.createAsyncHook)(),
49
+ onFileChanged: (0, import_hooks.createAsyncHook)(),
50
+ onBeforeRestart: (0, import_hooks.createAsyncHook)(),
51
+ onBeforeCreateCompiler: (0, import_hooks.createAsyncHook)(),
52
+ onAfterCreateCompiler: (0, import_hooks.createAsyncHook)(),
53
+ onBeforeBuild: (0, import_hooks.createAsyncHook)(),
54
+ onAfterBuild: (0, import_hooks.createAsyncHook)(),
55
+ onBeforeDev: (0, import_hooks.createAsyncHook)(),
56
+ onAfterDev: (0, import_hooks.createAsyncHook)(),
57
+ onBeforeDeploy: (0, import_hooks.createAsyncHook)(),
58
+ onAfterDeploy: (0, import_hooks.createAsyncHook)(),
59
+ onBeforeExit: (0, import_hooks.createAsyncHook)()
60
+ };
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ initHooks
65
+ });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var cli_exports = {};
20
+ __export(cli_exports, {
21
+ cli: () => import_run.cli,
22
+ createLoadedConfig: () => import_createLoadedConfig.createLoadedConfig,
23
+ initAppContext: () => import_context.initAppContext,
24
+ initAppDir: () => import_initAppDir.initAppDir,
25
+ initHooks: () => import_hooks.initHooks,
26
+ initPluginAPI: () => import_api.initPluginAPI
27
+ });
28
+ module.exports = __toCommonJS(cli_exports);
29
+ var import_api = require("./api");
30
+ var import_context = require("./context");
31
+ var import_hooks = require("./hooks");
32
+ var import_run = require("./run");
33
+ var import_initAppDir = require("./run/utils/initAppDir");
34
+ var import_createLoadedConfig = require("../cli/run/config/createLoadedConfig");
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ cli,
38
+ createLoadedConfig,
39
+ initAppContext,
40
+ initAppDir,
41
+ initHooks,
42
+ initPluginAPI
43
+ });
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createLoadedConfig_exports = {};
20
+ __export(createLoadedConfig_exports, {
21
+ assignPkgConfig: () => assignPkgConfig,
22
+ createLoadedConfig: () => createLoadedConfig
23
+ });
24
+ module.exports = __toCommonJS(createLoadedConfig_exports);
25
+ var import_utils = require("@modern-js/utils");
26
+ var import_lodash = require("@modern-js/utils/lodash");
27
+ var import_mergeConfig = require("../utils/mergeConfig");
28
+ var import_loadConfig = require("./loadConfig");
29
+ async function getConfigObject(config) {
30
+ if (typeof config === "function") {
31
+ return await config({
32
+ env: (0, import_utils.getNodeEnv)(),
33
+ command: (0, import_utils.getCommand)()
34
+ }) || {};
35
+ }
36
+ return config || {};
37
+ }
38
+ async function loadLocalConfig(appDirectory, configFile) {
39
+ let localConfigFile = false;
40
+ if (typeof configFile === "string") {
41
+ for (const ext of import_utils.CONFIG_FILE_EXTENSIONS) {
42
+ if (configFile.endsWith(ext)) {
43
+ const replacedPath = configFile.replace(ext, `.local${ext}`);
44
+ if (import_utils.fs.existsSync(replacedPath)) {
45
+ localConfigFile = replacedPath;
46
+ }
47
+ }
48
+ }
49
+ }
50
+ if (localConfigFile) {
51
+ const loaded = await (0, import_loadConfig.loadConfig)(appDirectory, localConfigFile);
52
+ return getConfigObject(loaded.config);
53
+ }
54
+ return null;
55
+ }
56
+ function assignPkgConfig(userConfig, pkgConfig) {
57
+ return (0, import_lodash.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
58
+ if (objValue === void 0 && (0, import_utils.isPlainObject)(srcValue)) {
59
+ return {
60
+ ...srcValue
61
+ };
62
+ }
63
+ return void 0;
64
+ });
65
+ }
66
+ async function createLoadedConfig(appDirectory, configFilePath, packageJsonConfig, loadedConfig) {
67
+ const configFile = (0, import_loadConfig.getConfigFilePath)(appDirectory, configFilePath);
68
+ const loaded = await (0, import_loadConfig.loadConfig)(appDirectory, configFile, packageJsonConfig, loadedConfig);
69
+ if (!loaded.config && !loaded.pkgConfig) {
70
+ import_utils.logger.warn(`Can not find any config file in the current project, please check if you have a correct config file.`);
71
+ import_utils.logger.warn(`Current project path: ${import_utils.chalk.yellow(appDirectory)}`);
72
+ }
73
+ const config = await getConfigObject(loaded.config);
74
+ let mergedConfig = config;
75
+ if (loaded.pkgConfig) {
76
+ mergedConfig = assignPkgConfig(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig);
77
+ }
78
+ if ((0, import_utils.isDevCommand)()) {
79
+ const localConfig = await loadLocalConfig(appDirectory, configFile);
80
+ if (localConfig) {
81
+ mergedConfig = (0, import_mergeConfig.mergeConfig)([
82
+ mergedConfig,
83
+ localConfig
84
+ ]);
85
+ }
86
+ }
87
+ return {
88
+ packageName: loaded.packageName,
89
+ config: mergedConfig,
90
+ configFile: loaded.configFile,
91
+ pkgConfig: loaded.pkgConfig,
92
+ jsConfig: loaded.config
93
+ };
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ assignPkgConfig,
98
+ createLoadedConfig
99
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createResolvedConfig_exports = {};
20
+ __export(createResolvedConfig_exports, {
21
+ createResolveConfig: () => createResolveConfig
22
+ });
23
+ module.exports = __toCommonJS(createResolvedConfig_exports);
24
+ var import_utils = require("@modern-js/utils");
25
+ var import_mergeConfig = require("../utils/mergeConfig");
26
+ const debug = (0, import_utils.createDebugger)("resolve-config");
27
+ const createResolveConfig = async (loaded, configs) => {
28
+ const { config: userConfig } = loaded;
29
+ const resolved = (0, import_mergeConfig.mergeConfig)([
30
+ {},
31
+ ...configs,
32
+ userConfig
33
+ ]);
34
+ debug("resolved %o", resolved);
35
+ return resolved;
36
+ };
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ createResolveConfig
40
+ });
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var loadConfig_exports = {};
30
+ __export(loadConfig_exports, {
31
+ clearFilesOverTime: () => clearFilesOverTime,
32
+ getConfigFilePath: () => getConfigFilePath,
33
+ getPackageConfig: () => getPackageConfig,
34
+ loadConfig: () => loadConfig
35
+ });
36
+ module.exports = __toCommonJS(loadConfig_exports);
37
+ var import_path = __toESM(require("path"));
38
+ var import_node_bundle_require = require("@modern-js/node-bundle-require");
39
+ var import_utils = require("@modern-js/utils");
40
+ const getPackageConfig = (appDirectory, packageJsonConfig) => {
41
+ const json = JSON.parse(import_utils.fs.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8"));
42
+ return json[packageJsonConfig];
43
+ };
44
+ const getConfigFilePath = (appDirectory, configFilePath) => {
45
+ if (import_path.default.isAbsolute(configFilePath)) {
46
+ return configFilePath;
47
+ }
48
+ return import_path.default.resolve(appDirectory, configFilePath);
49
+ };
50
+ const clearFilesOverTime = async (targetDir, overtime) => {
51
+ try {
52
+ const files = await (0, import_utils.globby)(`${targetDir}/**/*`, {
53
+ stats: true,
54
+ absolute: true
55
+ });
56
+ const currentTime = Date.now();
57
+ if (files.length > 0) {
58
+ for (const file of files) {
59
+ if (currentTime - file.stats.birthtimeMs >= overtime * 1e3) {
60
+ import_utils.fs.unlinkSync(file.path);
61
+ }
62
+ }
63
+ }
64
+ } catch (err) {
65
+ }
66
+ };
67
+ const bundleRequireWithCatch = async (configFile, { appDirectory }) => {
68
+ try {
69
+ const mod = await (0, import_node_bundle_require.bundleRequire)(configFile, {
70
+ autoClear: false,
71
+ getOutputFile: async (filePath) => {
72
+ const defaultOutputFileName = import_path.default.basename(await (0, import_node_bundle_require.defaultGetOutputFile)(filePath));
73
+ const outputPath = import_path.default.join(appDirectory, import_utils.CONFIG_CACHE_DIR);
74
+ const timeLimit = 10 * 60;
75
+ await clearFilesOverTime(outputPath, timeLimit);
76
+ return import_path.default.join(outputPath, defaultOutputFileName);
77
+ }
78
+ });
79
+ return mod;
80
+ } catch (e) {
81
+ if (e instanceof Error) {
82
+ e.message = `Get Error while loading config file: ${configFile}, please check it and retry.
83
+ ${e.message || ""}`;
84
+ }
85
+ throw e;
86
+ }
87
+ };
88
+ const loadConfig = async (appDirectory, configFile, packageJsonConfig, loadedConfig) => {
89
+ let pkgConfig;
90
+ if (packageJsonConfig) {
91
+ pkgConfig = getPackageConfig(appDirectory, packageJsonConfig);
92
+ }
93
+ const packageName = require(import_path.default.resolve(appDirectory, "./package.json")).name;
94
+ let config;
95
+ if (loadedConfig) {
96
+ config = loadedConfig;
97
+ } else if (configFile) {
98
+ delete require.cache[configFile];
99
+ const mod = await bundleRequireWithCatch(configFile, {
100
+ appDirectory
101
+ });
102
+ config = mod.default || mod;
103
+ }
104
+ return {
105
+ packageName,
106
+ configFile,
107
+ config,
108
+ pkgConfig
109
+ };
110
+ };
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ clearFilesOverTime,
114
+ getConfigFilePath,
115
+ getPackageConfig,
116
+ loadConfig
117
+ });