@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.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/cjs/cli/api.js +107 -0
- package/dist/cjs/cli/context.js +75 -0
- package/dist/cjs/cli/hooks.js +65 -0
- package/dist/cjs/cli/index.js +43 -0
- package/dist/cjs/cli/run/config/createLoadedConfig.js +99 -0
- package/dist/cjs/cli/run/config/createResolvedConfig.js +40 -0
- package/dist/cjs/cli/run/config/loadConfig.js +117 -0
- package/dist/cjs/cli/run/create.js +125 -0
- package/dist/cjs/cli/run/index.js +29 -0
- package/dist/cjs/cli/run/run.js +58 -0
- package/dist/cjs/cli/run/types.js +16 -0
- package/dist/cjs/cli/run/utils/checkIsDuplicationPlugin.js +45 -0
- package/dist/cjs/cli/run/utils/commander.js +50 -0
- package/dist/cjs/cli/run/utils/createFileWatcher.js +114 -0
- package/dist/cjs/cli/run/utils/initAppDir.js +49 -0
- package/dist/cjs/cli/run/utils/loadEnv.js +53 -0
- package/dist/cjs/cli/run/utils/mergeConfig.js +62 -0
- package/dist/cjs/hooks.js +69 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/manager.js +141 -0
- package/dist/cjs/types/cli/api.js +16 -0
- package/dist/cjs/types/cli/context.js +16 -0
- package/dist/cjs/types/cli/hooks.js +16 -0
- package/dist/cjs/types/cli/index.js +16 -0
- package/dist/cjs/types/cli/plugin.js +16 -0
- package/dist/cjs/types/hooks.js +16 -0
- package/dist/cjs/types/index.js +24 -0
- package/dist/cjs/types/plugin.js +16 -0
- package/dist/cjs/types/utils.js +16 -0
- package/dist/esm/index.js +1499 -0
- package/dist/esm-node/cli/api.js +83 -0
- package/dist/esm-node/cli/context.js +40 -0
- package/dist/esm-node/cli/hooks.js +41 -0
- package/dist/esm-node/cli/index.js +14 -0
- package/dist/esm-node/cli/run/config/createLoadedConfig.js +74 -0
- package/dist/esm-node/cli/run/config/createResolvedConfig.js +16 -0
- package/dist/esm-node/cli/run/config/loadConfig.js +80 -0
- package/dist/esm-node/cli/run/create.js +101 -0
- package/dist/esm-node/cli/run/index.js +5 -0
- package/dist/esm-node/cli/run/run.js +34 -0
- package/dist/esm-node/cli/run/types.js +0 -0
- package/dist/esm-node/cli/run/utils/checkIsDuplicationPlugin.js +21 -0
- package/dist/esm-node/cli/run/utils/commander.js +24 -0
- package/dist/esm-node/cli/run/utils/createFileWatcher.js +80 -0
- package/dist/esm-node/cli/run/utils/initAppDir.js +15 -0
- package/dist/esm-node/cli/run/utils/loadEnv.js +19 -0
- package/dist/esm-node/cli/run/utils/mergeConfig.js +38 -0
- package/dist/esm-node/hooks.js +44 -0
- package/dist/esm-node/index.js +9 -0
- package/dist/esm-node/manager.js +117 -0
- package/dist/esm-node/types/cli/api.js +0 -0
- package/dist/esm-node/types/cli/context.js +0 -0
- package/dist/esm-node/types/cli/hooks.js +0 -0
- package/dist/esm-node/types/cli/index.js +0 -0
- package/dist/esm-node/types/cli/plugin.js +0 -0
- package/dist/esm-node/types/hooks.js +0 -0
- package/dist/esm-node/types/index.js +2 -0
- package/dist/esm-node/types/plugin.js +0 -0
- package/dist/esm-node/types/utils.js +0 -0
- package/dist/types/cli/api.d.ts +7 -0
- package/dist/types/cli/context.d.ts +18 -0
- package/dist/types/cli/hooks.d.ts +39 -0
- package/dist/types/cli/index.d.ts +6 -0
- package/dist/types/cli/run/config/createLoadedConfig.d.ts +6 -0
- package/dist/types/cli/run/config/createResolvedConfig.d.ts +3 -0
- package/dist/types/cli/run/config/loadConfig.d.ts +25 -0
- package/dist/types/cli/run/create.d.ts +7 -0
- package/dist/types/cli/run/index.d.ts +6 -0
- package/dist/types/cli/run/run.d.ts +2 -0
- package/dist/types/cli/run/types.d.ts +29 -0
- package/dist/types/cli/run/utils/checkIsDuplicationPlugin.d.ts +1 -0
- package/dist/types/cli/run/utils/commander.d.ts +5 -0
- package/dist/types/cli/run/utils/createFileWatcher.d.ts +2 -0
- package/dist/types/cli/run/utils/initAppDir.d.ts +1 -0
- package/dist/types/cli/run/utils/loadEnv.d.ts +1 -0
- package/dist/types/cli/run/utils/mergeConfig.d.ts +2 -0
- package/dist/types/hooks.d.ts +3 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/manager.d.ts +2 -0
- package/dist/types/types/cli/api.d.ts +42 -0
- package/dist/types/types/cli/context.d.ts +40 -0
- package/dist/types/types/cli/hooks.d.ts +41 -0
- package/dist/types/types/cli/index.d.ts +3 -0
- package/dist/types/types/cli/plugin.d.ts +6 -0
- package/dist/types/types/hooks.d.ts +10 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/plugin.d.ts +40 -0
- package/dist/types/types/utils.d.ts +5 -0
- package/package.json +85 -0
|
@@ -0,0 +1,125 @@
|
|
|
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 create_exports = {};
|
|
20
|
+
__export(create_exports, {
|
|
21
|
+
createCli: () => createCli
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(create_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
|
+
var import_commander = require("@modern-js/utils/commander");
|
|
26
|
+
var import_manager = require("../../manager");
|
|
27
|
+
var import_api = require("../api");
|
|
28
|
+
var import_context = require("../context");
|
|
29
|
+
var import_createLoadedConfig = require("./config/createLoadedConfig");
|
|
30
|
+
var import_createResolvedConfig = require("./config/createResolvedConfig");
|
|
31
|
+
var import_checkIsDuplicationPlugin = require("./utils/checkIsDuplicationPlugin");
|
|
32
|
+
var import_commander2 = require("./utils/commander");
|
|
33
|
+
var import_createFileWatcher = require("./utils/createFileWatcher");
|
|
34
|
+
var import_initAppDir = require("./utils/initAppDir");
|
|
35
|
+
var import_loadEnv = require("./utils/loadEnv");
|
|
36
|
+
const createCli = () => {
|
|
37
|
+
const pluginManager = (0, import_manager.createPluginManager)();
|
|
38
|
+
async function init(options) {
|
|
39
|
+
const { metaName = "MODERN", configFile, command, version, packageJsonConfig, loadedConfig, internalPlugins, handleSetupResult } = options;
|
|
40
|
+
const appDirectory = await (0, import_initAppDir.initAppDir)(options === null || options === void 0 ? void 0 : options.cwd);
|
|
41
|
+
(0, import_commander2.initCommandsMap)();
|
|
42
|
+
(0, import_commander2.setProgramVersion)(version);
|
|
43
|
+
(0, import_loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
44
|
+
const loaded = await (0, import_createLoadedConfig.createLoadedConfig)(appDirectory, configFile, packageJsonConfig, loadedConfig);
|
|
45
|
+
const allPlugins = [
|
|
46
|
+
...internalPlugins || [],
|
|
47
|
+
...loaded.config.plugins || []
|
|
48
|
+
];
|
|
49
|
+
(0, import_checkIsDuplicationPlugin.checkIsDuplicationPlugin)(allPlugins.map((plugin) => plugin.name), loaded.config.autoLoadPlugins);
|
|
50
|
+
pluginManager.addPlugins(allPlugins);
|
|
51
|
+
const plugins = await pluginManager.getPlugins();
|
|
52
|
+
const context = await (0, import_context.createContext)({
|
|
53
|
+
appContext: (0, import_context.initAppContext)({
|
|
54
|
+
packageName: loaded.packageName,
|
|
55
|
+
configFile: loaded.configFile,
|
|
56
|
+
command,
|
|
57
|
+
appDirectory,
|
|
58
|
+
plugins
|
|
59
|
+
}),
|
|
60
|
+
config: loaded.config,
|
|
61
|
+
normalizedConfig: {}
|
|
62
|
+
});
|
|
63
|
+
const pluginAPI = (0, import_api.initPluginAPI)({
|
|
64
|
+
context,
|
|
65
|
+
pluginManager
|
|
66
|
+
});
|
|
67
|
+
context.pluginAPI = pluginAPI;
|
|
68
|
+
for (const plugin of plugins) {
|
|
69
|
+
const setupResult = await plugin.setup(pluginAPI);
|
|
70
|
+
if (handleSetupResult) {
|
|
71
|
+
await handleSetupResult(setupResult, pluginAPI);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
[
|
|
75
|
+
"SIGINT",
|
|
76
|
+
"SIGTERM",
|
|
77
|
+
"unhandledRejection",
|
|
78
|
+
"uncaughtException"
|
|
79
|
+
].forEach((event) => {
|
|
80
|
+
process.on(event, async (err) => {
|
|
81
|
+
await context.hooks.onBeforeExit.call();
|
|
82
|
+
let hasError = false;
|
|
83
|
+
if (err instanceof Error) {
|
|
84
|
+
import_utils.logger.error(err.stack);
|
|
85
|
+
hasError = true;
|
|
86
|
+
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
87
|
+
console.trace("Unknown Error", err);
|
|
88
|
+
hasError = true;
|
|
89
|
+
}
|
|
90
|
+
process.nextTick(() => {
|
|
91
|
+
process.exit(hasError ? 1 : 0);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
const extraConfigs = await context.hooks.config.call();
|
|
96
|
+
const normalizedConfig = await (0, import_createResolvedConfig.createResolveConfig)(loaded, extraConfigs);
|
|
97
|
+
const resolved = await context.hooks.modifyResolvedConfig.call(normalizedConfig);
|
|
98
|
+
context.normalizedConfig = resolved[0] || normalizedConfig;
|
|
99
|
+
await pluginAPI.updateAppContext(context);
|
|
100
|
+
await context.hooks.onPrepare.call();
|
|
101
|
+
return {
|
|
102
|
+
appContext: context
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function run(options) {
|
|
106
|
+
var _program_commands;
|
|
107
|
+
const { appContext } = await init(options);
|
|
108
|
+
await appContext.hooks.addCommand.call({
|
|
109
|
+
program: import_commander.program
|
|
110
|
+
});
|
|
111
|
+
await (0, import_createFileWatcher.createFileWatcher)(appContext);
|
|
112
|
+
import_commander.program.parse(process.argv);
|
|
113
|
+
if (!((_program_commands = import_commander.program.commands) === null || _program_commands === void 0 ? void 0 : _program_commands.length)) {
|
|
114
|
+
import_utils.logger.warn("No command found, please make sure you have registered plugins correctly.");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
init,
|
|
119
|
+
run
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
createCli
|
|
125
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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 run_exports = {};
|
|
20
|
+
__export(run_exports, {
|
|
21
|
+
cli: () => cli
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(run_exports);
|
|
24
|
+
var import_create = require("./create");
|
|
25
|
+
const cli = (0, import_create.createCli)();
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
cli
|
|
29
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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 run_exports = {};
|
|
20
|
+
__export(run_exports, {
|
|
21
|
+
run: () => run
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(run_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
|
+
var import__ = require(".");
|
|
26
|
+
const run = async (options) => {
|
|
27
|
+
const { initialLog, version, cwd, configFile, ...params } = options;
|
|
28
|
+
if (initialLog) {
|
|
29
|
+
import_utils.logger.greet(` ${initialLog}
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
const command = process.argv[2];
|
|
33
|
+
if (!process.env.NODE_ENV) {
|
|
34
|
+
if ([
|
|
35
|
+
"build",
|
|
36
|
+
"serve",
|
|
37
|
+
"deploy",
|
|
38
|
+
"analyze"
|
|
39
|
+
].includes(command)) {
|
|
40
|
+
process.env.NODE_ENV = "production";
|
|
41
|
+
} else if (command === "test") {
|
|
42
|
+
process.env.NODE_ENV = "test";
|
|
43
|
+
} else {
|
|
44
|
+
process.env.NODE_ENV = "development";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await import__.cli.run({
|
|
48
|
+
version,
|
|
49
|
+
cwd,
|
|
50
|
+
command,
|
|
51
|
+
configFile,
|
|
52
|
+
...params
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
run
|
|
58
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,45 @@
|
|
|
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 checkIsDuplicationPlugin_exports = {};
|
|
20
|
+
__export(checkIsDuplicationPlugin_exports, {
|
|
21
|
+
checkIsDuplicationPlugin: () => checkIsDuplicationPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(checkIsDuplicationPlugin_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
|
+
function checkIsDuplicationPlugin(plugins, autoLoadPlugin = false) {
|
|
26
|
+
const set = /* @__PURE__ */ new Set();
|
|
27
|
+
const duplicationPlugins = [];
|
|
28
|
+
plugins.filter((plugin) => typeof plugin === "string").forEach((plugin) => {
|
|
29
|
+
if (set.has(plugin)) {
|
|
30
|
+
duplicationPlugins.push(plugin);
|
|
31
|
+
} else {
|
|
32
|
+
set.add(plugin);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (duplicationPlugins.length > 0) {
|
|
36
|
+
import_utils.logger.warn(`Duplicate registration plugins: ${duplicationPlugins.join(",")}.`);
|
|
37
|
+
if (autoLoadPlugin) {
|
|
38
|
+
import_utils.logger.warn("This is probably because you enabled `autoLoadPlugin` configuration and also registered these plugins manually");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
checkIsDuplicationPlugin
|
|
45
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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 commander_exports = {};
|
|
20
|
+
__export(commander_exports, {
|
|
21
|
+
initCommandsMap: () => initCommandsMap,
|
|
22
|
+
program: () => import_utils.program,
|
|
23
|
+
setProgramVersion: () => setProgramVersion
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(commander_exports);
|
|
26
|
+
var import_utils = require("@modern-js/utils");
|
|
27
|
+
const setProgramVersion = (version = "unknown") => {
|
|
28
|
+
const name = process.argv[1];
|
|
29
|
+
import_utils.program.name(name).usage("<command> [options]").version(version);
|
|
30
|
+
};
|
|
31
|
+
function initCommandsMap() {
|
|
32
|
+
if (!import_utils.program.hasOwnProperty("commandsMap")) {
|
|
33
|
+
Object.defineProperty(import_utils.program, "commandsMap", {
|
|
34
|
+
get() {
|
|
35
|
+
const map = /* @__PURE__ */ new Map();
|
|
36
|
+
for (const command of import_utils.program.commands) {
|
|
37
|
+
map.set(command._name, command);
|
|
38
|
+
}
|
|
39
|
+
return map;
|
|
40
|
+
},
|
|
41
|
+
configurable: false
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
initCommandsMap,
|
|
48
|
+
program,
|
|
49
|
+
setProgramVersion
|
|
50
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
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 createFileWatcher_exports = {};
|
|
30
|
+
__export(createFileWatcher_exports, {
|
|
31
|
+
createFileWatcher: () => createFileWatcher
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(createFileWatcher_exports);
|
|
34
|
+
var import_crypto = __toESM(require("crypto"));
|
|
35
|
+
var fs = __toESM(require("fs"));
|
|
36
|
+
var path = __toESM(require("path"));
|
|
37
|
+
var import_utils = require("@modern-js/utils");
|
|
38
|
+
const debug = (0, import_utils.createDebugger)("watch-files");
|
|
39
|
+
const hashMap = /* @__PURE__ */ new Map();
|
|
40
|
+
const md5 = (data) => import_crypto.default.createHash("md5").update(data).digest("hex");
|
|
41
|
+
const createFileWatcher = async (appContext) => {
|
|
42
|
+
if ((0, import_utils.isDevCommand)()) {
|
|
43
|
+
const { appDirectory } = appContext;
|
|
44
|
+
const extraFiles = await appContext.hooks.addWatchFiles.call();
|
|
45
|
+
const watched = extraFiles.filter((extra) => {
|
|
46
|
+
return Array.isArray(extra);
|
|
47
|
+
}).flat();
|
|
48
|
+
const privateWatched = extraFiles.filter((extra) => {
|
|
49
|
+
return !Array.isArray(extra) && extra.isPrivate;
|
|
50
|
+
}).map((extra) => {
|
|
51
|
+
return extra.files;
|
|
52
|
+
}).flat();
|
|
53
|
+
const isPrivate = (filename) => privateWatched.some((ff) => {
|
|
54
|
+
return path.resolve(appDirectory, filename).startsWith(ff);
|
|
55
|
+
});
|
|
56
|
+
debug(`watched: %o`, watched);
|
|
57
|
+
const watcher = import_utils.chokidar.watch([
|
|
58
|
+
...watched,
|
|
59
|
+
...privateWatched
|
|
60
|
+
], {
|
|
61
|
+
cwd: appDirectory,
|
|
62
|
+
ignoreInitial: true,
|
|
63
|
+
ignorePermissionErrors: true,
|
|
64
|
+
ignored: [
|
|
65
|
+
"**/__test__/**",
|
|
66
|
+
"**/*.test.(js|jsx|ts|tsx)",
|
|
67
|
+
"**/*.spec.(js|jsx|ts|tsx)",
|
|
68
|
+
"**/*.stories.(js|jsx|ts|tsx)"
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
watcher.on("change", (changed) => {
|
|
72
|
+
const lastHash = hashMap.get(changed);
|
|
73
|
+
const currentHash = md5(fs.readFileSync(path.join(appDirectory, changed), "utf8"));
|
|
74
|
+
if (currentHash !== lastHash) {
|
|
75
|
+
debug(`file change: %s`, changed);
|
|
76
|
+
hashMap.set(changed, currentHash);
|
|
77
|
+
appContext.hooks.onFileChanged.call({
|
|
78
|
+
filename: changed,
|
|
79
|
+
eventType: "change",
|
|
80
|
+
isPrivate: isPrivate(changed)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
watcher.on("add", (changed) => {
|
|
85
|
+
debug(`add file: %s`, changed);
|
|
86
|
+
const currentHash = md5(fs.readFileSync(path.join(appDirectory, changed), "utf8"));
|
|
87
|
+
hashMap.set(changed, currentHash);
|
|
88
|
+
appContext.hooks.onFileChanged.call({
|
|
89
|
+
filename: changed,
|
|
90
|
+
eventType: "add",
|
|
91
|
+
isPrivate: isPrivate(changed)
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
watcher.on("unlink", (changed) => {
|
|
95
|
+
debug(`remove file: %s`, changed);
|
|
96
|
+
if (hashMap.has(changed)) {
|
|
97
|
+
hashMap.delete(changed);
|
|
98
|
+
}
|
|
99
|
+
appContext.hooks.onFileChanged.call({
|
|
100
|
+
filename: changed,
|
|
101
|
+
eventType: "unlink",
|
|
102
|
+
isPrivate: isPrivate(changed)
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
watcher.on("error", (err) => {
|
|
106
|
+
throw err;
|
|
107
|
+
});
|
|
108
|
+
return watcher;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
createFileWatcher
|
|
114
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
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 initAppDir_exports = {};
|
|
30
|
+
__export(initAppDir_exports, {
|
|
31
|
+
initAppDir: () => initAppDir
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(initAppDir_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
const initAppDir = async (currentDir) => {
|
|
37
|
+
const cwd = currentDir || process.cwd();
|
|
38
|
+
const pkg = await (0, import_utils.pkgUp)({
|
|
39
|
+
cwd
|
|
40
|
+
});
|
|
41
|
+
if (!pkg) {
|
|
42
|
+
throw new Error(`no package.json found in current work dir: ${cwd}`);
|
|
43
|
+
}
|
|
44
|
+
return import_path.default.dirname(pkg);
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
initAppDir
|
|
49
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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 loadEnv_exports = {};
|
|
30
|
+
__export(loadEnv_exports, {
|
|
31
|
+
loadEnv: () => loadEnv
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(loadEnv_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
37
|
+
const loadEnv = (appDirectory, mode = process.env.NODE_ENV) => {
|
|
38
|
+
[
|
|
39
|
+
`.env.${mode}.local`,
|
|
40
|
+
".env.local",
|
|
41
|
+
`.env.${mode}`,
|
|
42
|
+
".env"
|
|
43
|
+
].map((name) => import_path.default.resolve(appDirectory, name)).filter((filePath) => import_fs.default.existsSync(filePath) && !import_fs.default.statSync(filePath).isDirectory()).forEach((filePath) => {
|
|
44
|
+
const envConfig = import_utils.dotenv.config({
|
|
45
|
+
path: filePath
|
|
46
|
+
});
|
|
47
|
+
(0, import_utils.dotenvExpand)(envConfig);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
loadEnv
|
|
53
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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 mergeConfig_exports = {};
|
|
20
|
+
__export(mergeConfig_exports, {
|
|
21
|
+
mergeConfig: () => mergeConfig
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(mergeConfig_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
|
+
var import_lodash = require("@modern-js/utils/lodash");
|
|
26
|
+
const mergeConfig = (configs) => (0, import_lodash.mergeWith)({}, ...configs, (target, source, key) => {
|
|
27
|
+
if (key === "designSystem" || key === "tailwindcss" && typeof source === "object") {
|
|
28
|
+
return (0, import_lodash.mergeWith)({}, target !== null && target !== void 0 ? target : {}, source !== null && source !== void 0 ? source : {});
|
|
29
|
+
}
|
|
30
|
+
if ((0, import_utils.isOverriddenConfigKey)(key)) {
|
|
31
|
+
return source !== null && source !== void 0 ? source : target;
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(target) || Array.isArray(source)) {
|
|
34
|
+
if (target === void 0) {
|
|
35
|
+
return source;
|
|
36
|
+
}
|
|
37
|
+
if (source === void 0) {
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
return [
|
|
41
|
+
...(0, import_utils.ensureArray)(target),
|
|
42
|
+
...(0, import_utils.ensureArray)(source)
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
if ((0, import_lodash.isFunction)(target) || (0, import_lodash.isFunction)(source)) {
|
|
46
|
+
if (source === void 0) {
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
if (target === void 0) {
|
|
50
|
+
return source;
|
|
51
|
+
}
|
|
52
|
+
return [
|
|
53
|
+
target,
|
|
54
|
+
source
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
return void 0;
|
|
58
|
+
});
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
mergeConfig
|
|
62
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
createAsyncHook: () => createAsyncHook,
|
|
22
|
+
createCollectAsyncHook: () => createCollectAsyncHook
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
25
|
+
function createAsyncHook() {
|
|
26
|
+
const callbacks = [];
|
|
27
|
+
const tap = (cb) => {
|
|
28
|
+
callbacks.push(cb);
|
|
29
|
+
};
|
|
30
|
+
const call = async (...params) => {
|
|
31
|
+
for (const callback of callbacks) {
|
|
32
|
+
const result = await callback(...params);
|
|
33
|
+
if (result !== void 0) {
|
|
34
|
+
params[0] = result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return params[0] || [];
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
tap,
|
|
41
|
+
call
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createCollectAsyncHook() {
|
|
45
|
+
const callbacks = [];
|
|
46
|
+
const tap = (cb) => {
|
|
47
|
+
callbacks.push(cb);
|
|
48
|
+
};
|
|
49
|
+
const call = async (...params) => {
|
|
50
|
+
const results = [];
|
|
51
|
+
for (const callback of callbacks) {
|
|
52
|
+
const result = await callback(...params);
|
|
53
|
+
if (result !== void 0) {
|
|
54
|
+
params[0] = result;
|
|
55
|
+
results.push(result);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return results;
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
tap,
|
|
62
|
+
call
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
createAsyncHook,
|
|
68
|
+
createCollectAsyncHook
|
|
69
|
+
});
|