@modern-js/core 2.25.2 → 2.27.0
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/CHANGELOG.md +22 -0
- package/dist/bin.d.ts +1 -1
- package/dist/bin.js +5 -3
- package/dist/config/createDefaultConfig.d.ts +1 -1
- package/dist/config/createDefaultConfig.js +12 -6
- package/dist/config/createLoadedConfig.d.ts +1 -1
- package/dist/config/createLoadedConfig.js +80 -73
- package/dist/config/createResolvedConfig.d.ts +1 -1
- package/dist/config/createResolvedConfig.js +59 -72
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +7 -18
- package/dist/config/loadConfig.d.ts +5 -5
- package/dist/config/loadConfig.js +115 -112
- package/dist/context.d.ts +21 -14
- package/dist/context.js +74 -60
- package/dist/createCli.d.ts +13 -13
- package/dist/createCli.js +134 -113
- package/dist/index.d.ts +16 -16
- package/dist/index.js +59 -35
- package/dist/loadEnv.d.ts +1 -1
- package/dist/loadEnv.js +23 -17
- package/dist/loadPlugins.d.ts +4 -4
- package/dist/loadPlugins.js +54 -54
- package/dist/manager.d.ts +62 -62
- package/dist/manager.js +40 -23
- package/dist/nodeApi.d.ts +1 -1
- package/dist/nodeApi.js +25 -9
- package/dist/runBin.d.ts +2 -2
- package/dist/runBin.js +56 -53
- package/dist/schema/patchSchema.d.ts +15 -15
- package/dist/schema/patchSchema.js +56 -53
- package/dist/schema/testing.d.ts +11 -11
- package/dist/schema/testing.js +26 -8
- package/dist/schema/traverseSchema.d.ts +1 -1
- package/dist/schema/traverseSchema.js +25 -17
- package/dist/types/config/index.d.ts +37 -37
- package/dist/types/config/index.js +3 -1
- package/dist/types/config/testing.d.ts +11 -11
- package/dist/types/config/testing.js +3 -1
- package/dist/types/context.d.ts +27 -27
- package/dist/types/context.js +3 -1
- package/dist/types/coreOptions.d.ts +22 -22
- package/dist/types/coreOptions.js +3 -1
- package/dist/types/hooks.d.ts +41 -41
- package/dist/types/hooks.js +3 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +10 -21
- package/dist/types/plugin.d.ts +10 -10
- package/dist/types/plugin.js +3 -1
- package/dist/types/pluginAPI.d.ts +10 -10
- package/dist/types/pluginAPI.js +3 -1
- package/dist/utils/checkIsDuplicationPlugin.d.ts +1 -1
- package/dist/utils/checkIsDuplicationPlugin.js +24 -21
- package/dist/utils/commander.d.ts +1 -1
- package/dist/utils/commander.js +31 -17
- package/dist/utils/createFileWatcher.d.ts +1 -1
- package/dist/utils/createFileWatcher.js +85 -106
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +10 -21
- package/dist/utils/initAppDir.d.ts +1 -1
- package/dist/utils/initAppDir.js +22 -17
- package/dist/utils/mergeConfig.d.ts +1 -1
- package/dist/utils/mergeConfig.js +37 -27
- package/dist/utils/repeatKeyWarning.d.ts +1 -1
- package/dist/utils/repeatKeyWarning.js +29 -16
- package/package.json +11 -10
package/dist/createCli.js
CHANGED
|
@@ -1,122 +1,143 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
mergeOptions: function() {
|
|
14
|
+
return mergeOptions;
|
|
15
|
+
},
|
|
16
|
+
createCli: function() {
|
|
17
|
+
return createCli;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const _utils = require("@modern-js/utils");
|
|
21
|
+
const _utils1 = require("./utils");
|
|
22
|
+
const _loadPlugins = require("./loadPlugins");
|
|
23
|
+
const _context = require("./context");
|
|
24
|
+
const _loadEnv = require("./loadEnv");
|
|
25
|
+
const _manager = require("./manager");
|
|
26
|
+
const _config = require("./config");
|
|
27
|
+
const _checkIsDuplicationPlugin = require("./utils/checkIsDuplicationPlugin");
|
|
28
|
+
const setProgramVersion = (version = "unknown") => {
|
|
29
|
+
_utils.program.name("modern").usage("<command> [options]").version(version);
|
|
14
30
|
};
|
|
15
31
|
const mergeOptions = (options) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
const defaultOptions = {
|
|
33
|
+
serverConfigFile: _utils.DEFAULT_SERVER_CONFIG
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
...defaultOptions,
|
|
37
|
+
...options
|
|
38
|
+
};
|
|
23
39
|
};
|
|
24
|
-
exports.mergeOptions = mergeOptions;
|
|
25
40
|
const createCli = () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
await hooksRunner.beforeConfig();
|
|
70
|
-
const extraConfigs = await hooksRunner.config();
|
|
71
|
-
const extraSchemas = await hooksRunner.validateSchema();
|
|
72
|
-
const normalizedConfig = await (0, config_1.createResolveConfig)(loaded, extraConfigs, extraSchemas, options === null || options === void 0 ? void 0 : options.onSchemaError);
|
|
73
|
-
const { resolved } = await hooksRunner.resolvedConfig({
|
|
74
|
-
resolved: normalizedConfig,
|
|
75
|
-
});
|
|
76
|
-
// update context value
|
|
77
|
-
context_1.ConfigContext.set(loaded.config);
|
|
78
|
-
context_1.ResolvedConfigContext.set(resolved);
|
|
79
|
-
await hooksRunner.prepare();
|
|
80
|
-
await hooksRunner.afterPrepare();
|
|
81
|
-
return {
|
|
82
|
-
resolved,
|
|
83
|
-
appContext: (0, context_1.useAppContext)(),
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
async function run(options) {
|
|
87
|
-
var _a;
|
|
88
|
-
const { appContext } = await init(options);
|
|
89
|
-
await hooksRunner.commands({ program: utils_1.program });
|
|
90
|
-
await (0, utils_2.createFileWatcher)(appContext, hooksRunner);
|
|
91
|
-
utils_1.program.parse(process.argv);
|
|
92
|
-
if (!((_a = utils_1.program.commands) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
93
|
-
utils_1.logger.warn('No command found, please make sure you have registered plugins correctly.');
|
|
41
|
+
let hooksRunner;
|
|
42
|
+
let initOptions;
|
|
43
|
+
const init = async (options) => {
|
|
44
|
+
var _mergedOptions_options, _mergedOptions_internalPlugins, _mergedOptions_internalPlugins1, _mergedOptions_internalPlugins2;
|
|
45
|
+
_manager.manager.clear();
|
|
46
|
+
const mergedOptions = mergeOptions(options);
|
|
47
|
+
initOptions = mergedOptions;
|
|
48
|
+
const appDirectory = await (0, _utils1.initAppDir)(options === null || options === void 0 ? void 0 : options.cwd);
|
|
49
|
+
(0, _utils1.initCommandsMap)();
|
|
50
|
+
setProgramVersion(options === null || options === void 0 ? void 0 : options.version);
|
|
51
|
+
var _mergedOptions_options_metaName;
|
|
52
|
+
const metaName = (_mergedOptions_options_metaName = mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions_options = mergedOptions.options) === null || _mergedOptions_options === void 0 ? void 0 : _mergedOptions_options.metaName) !== null && _mergedOptions_options_metaName !== void 0 ? _mergedOptions_options_metaName : "MODERN";
|
|
53
|
+
(0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
54
|
+
const loaded = await (0, _config.createLoadedConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.loadedConfig);
|
|
55
|
+
const plugins = await (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
|
|
56
|
+
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions_internalPlugins = mergedOptions.internalPlugins) === null || _mergedOptions_internalPlugins === void 0 ? void 0 : _mergedOptions_internalPlugins.cli,
|
|
57
|
+
autoLoad: mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions_internalPlugins1 = mergedOptions.internalPlugins) === null || _mergedOptions_internalPlugins1 === void 0 ? void 0 : _mergedOptions_internalPlugins1.autoLoad,
|
|
58
|
+
forceAutoLoadPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.forceAutoLoadPlugins
|
|
59
|
+
});
|
|
60
|
+
(0, _checkIsDuplicationPlugin.checkIsDuplicationPlugin)(plugins.map((plugin) => plugin.name), loaded.config.autoLoadPlugins);
|
|
61
|
+
plugins.forEach((plugin) => plugin && _manager.manager.usePlugin(plugin));
|
|
62
|
+
const appContext = (0, _context.initAppContext)({
|
|
63
|
+
appDirectory,
|
|
64
|
+
plugins,
|
|
65
|
+
configFile: loaded.filePath,
|
|
66
|
+
options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
|
|
67
|
+
serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile,
|
|
68
|
+
serverInternalPlugins: (mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions_internalPlugins2 = mergedOptions.internalPlugins) === null || _mergedOptions_internalPlugins2 === void 0 ? void 0 : _mergedOptions_internalPlugins2.server) || _utils.INTERNAL_SERVER_PLUGINS
|
|
69
|
+
});
|
|
70
|
+
_context.ConfigContext.set(loaded.config);
|
|
71
|
+
_context.AppContext.set(appContext);
|
|
72
|
+
hooksRunner = await _manager.manager.init();
|
|
73
|
+
[
|
|
74
|
+
"SIGINT",
|
|
75
|
+
"SIGTERM",
|
|
76
|
+
"unhandledRejection",
|
|
77
|
+
"uncaughtException"
|
|
78
|
+
].forEach((event) => {
|
|
79
|
+
process.on(event, async (err) => {
|
|
80
|
+
hooksRunner.beforeExit();
|
|
81
|
+
if (err instanceof Error) {
|
|
82
|
+
_utils.logger.error(err.stack);
|
|
94
83
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
await hooksRunner.commands({ program: newProgram });
|
|
112
|
-
await newProgram.parseAsync(argv);
|
|
113
|
-
}
|
|
84
|
+
process.nextTick(() => {
|
|
85
|
+
process.exit(1);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
await hooksRunner.beforeConfig();
|
|
90
|
+
const extraConfigs = await hooksRunner.config();
|
|
91
|
+
const extraSchemas = await hooksRunner.validateSchema();
|
|
92
|
+
const normalizedConfig = await (0, _config.createResolveConfig)(loaded, extraConfigs, extraSchemas, options === null || options === void 0 ? void 0 : options.onSchemaError);
|
|
93
|
+
const { resolved } = await hooksRunner.resolvedConfig({
|
|
94
|
+
resolved: normalizedConfig
|
|
95
|
+
});
|
|
96
|
+
_context.ConfigContext.set(loaded.config);
|
|
97
|
+
_context.ResolvedConfigContext.set(resolved);
|
|
98
|
+
await hooksRunner.prepare();
|
|
99
|
+
await hooksRunner.afterPrepare();
|
|
114
100
|
return {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
test,
|
|
118
|
-
runCommand,
|
|
119
|
-
getPrevInitOptions: () => initOptions,
|
|
101
|
+
resolved,
|
|
102
|
+
appContext: (0, _context.useAppContext)()
|
|
120
103
|
};
|
|
104
|
+
};
|
|
105
|
+
async function run(options) {
|
|
106
|
+
var _program_commands;
|
|
107
|
+
const { appContext } = await init(options);
|
|
108
|
+
await hooksRunner.commands({
|
|
109
|
+
program: _utils.program
|
|
110
|
+
});
|
|
111
|
+
await (0, _utils1.createFileWatcher)(appContext, hooksRunner);
|
|
112
|
+
_utils.program.parse(process.argv);
|
|
113
|
+
if (!((_program_commands = _utils.program.commands) === null || _program_commands === void 0 ? void 0 : _program_commands.length)) {
|
|
114
|
+
_utils.logger.warn("No command found, please make sure you have registered plugins correctly.");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function runCommand(command, commandOptions = [], options) {
|
|
118
|
+
const argv = process.argv.slice(0, 2).concat(command).concat(commandOptions);
|
|
119
|
+
process.env.MODERN_ARGV = argv.join(" ");
|
|
120
|
+
const { appContext } = await init(options);
|
|
121
|
+
await hooksRunner.commands({
|
|
122
|
+
program: _utils.program
|
|
123
|
+
});
|
|
124
|
+
await (0, _utils1.createFileWatcher)(appContext, hooksRunner);
|
|
125
|
+
_utils.program.parse(argv);
|
|
126
|
+
}
|
|
127
|
+
async function test(argv, options) {
|
|
128
|
+
const newProgram = new _utils.Command();
|
|
129
|
+
const { coreOptions } = options !== null && options !== void 0 ? options : {};
|
|
130
|
+
await init(coreOptions);
|
|
131
|
+
await hooksRunner.commands({
|
|
132
|
+
program: newProgram
|
|
133
|
+
});
|
|
134
|
+
await newProgram.parseAsync(argv);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
init,
|
|
138
|
+
run,
|
|
139
|
+
test,
|
|
140
|
+
runCommand,
|
|
141
|
+
getPrevInitOptions: () => initOptions
|
|
142
|
+
};
|
|
121
143
|
};
|
|
122
|
-
exports.createCli = createCli;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,22 +2,22 @@ export * from './types';
|
|
|
2
2
|
export * from '@modern-js/plugin';
|
|
3
3
|
export { mergeConfig, initAppDir } from './utils';
|
|
4
4
|
export { manager, createPlugin, registerHook } from './manager';
|
|
5
|
-
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, initAppContext
|
|
5
|
+
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, initAppContext } from './context';
|
|
6
6
|
export declare const cli: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
init: (options?: import("./types").CoreOptions | undefined) => Promise<{
|
|
8
|
+
resolved: import("./types").NormalizedConfig<{}>;
|
|
9
|
+
appContext: import("./types").IAppContext;
|
|
10
|
+
}>;
|
|
11
|
+
run: (options?: import("./types").CoreOptions | undefined) => Promise<void>;
|
|
12
|
+
test: (argv: string[], options?: {
|
|
13
|
+
coreOptions?: import("./types").CoreOptions | undefined;
|
|
14
|
+
disableWatcher?: boolean | undefined;
|
|
15
|
+
} | undefined) => Promise<void>;
|
|
16
|
+
runCommand: (command: string, commandOptions?: string[], options?: import("./types").CoreOptions | undefined) => Promise<void>;
|
|
17
|
+
getPrevInitOptions: () => import("./types").CoreOptions | undefined;
|
|
18
18
|
};
|
|
19
19
|
declare module '@modern-js/utils/compiled/commander' {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
20
|
+
interface Command {
|
|
21
|
+
commandsMap: Map<string, Command>;
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
mergeConfig: function() {
|
|
14
|
+
return _utils.mergeConfig;
|
|
15
|
+
},
|
|
16
|
+
initAppDir: function() {
|
|
17
|
+
return _utils.initAppDir;
|
|
18
|
+
},
|
|
19
|
+
manager: function() {
|
|
20
|
+
return _manager.manager;
|
|
21
|
+
},
|
|
22
|
+
createPlugin: function() {
|
|
23
|
+
return _manager.createPlugin;
|
|
24
|
+
},
|
|
25
|
+
registerHook: function() {
|
|
26
|
+
return _manager.registerHook;
|
|
27
|
+
},
|
|
28
|
+
AppContext: function() {
|
|
29
|
+
return _context.AppContext;
|
|
30
|
+
},
|
|
31
|
+
ConfigContext: function() {
|
|
32
|
+
return _context.ConfigContext;
|
|
33
|
+
},
|
|
34
|
+
ResolvedConfigContext: function() {
|
|
35
|
+
return _context.ResolvedConfigContext;
|
|
36
|
+
},
|
|
37
|
+
useAppContext: function() {
|
|
38
|
+
return _context.useAppContext;
|
|
39
|
+
},
|
|
40
|
+
useConfigContext: function() {
|
|
41
|
+
return _context.useConfigContext;
|
|
42
|
+
},
|
|
43
|
+
useResolvedConfigContext: function() {
|
|
44
|
+
return _context.useResolvedConfigContext;
|
|
45
|
+
},
|
|
46
|
+
initAppContext: function() {
|
|
47
|
+
return _context.initAppContext;
|
|
48
|
+
},
|
|
49
|
+
cli: function() {
|
|
50
|
+
return cli;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const _export_star = require("@swc/helpers/_/_export_star");
|
|
54
|
+
const _createCli = require("./createCli");
|
|
55
|
+
_export_star._(require("./types"), exports);
|
|
56
|
+
_export_star._(require("@modern-js/plugin"), exports);
|
|
57
|
+
const _utils = require("./utils");
|
|
58
|
+
const _manager = require("./manager");
|
|
59
|
+
const _context = require("./context");
|
|
60
|
+
const cli = (0, _createCli.createCli)();
|
package/dist/loadEnv.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const loadEnv: (appDirectory: string, mode?: string) => void;
|
|
1
|
+
export declare const loadEnv: (appDirectory: string, mode?: string) => void;
|
package/dist/loadEnv.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "loadEnv", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return loadEnv;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
|
+
const _fs = /* @__PURE__ */ _interop_require_default._(require("fs"));
|
|
13
|
+
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
14
|
+
const _utils = require("@modern-js/utils");
|
|
10
15
|
const loadEnv = (appDirectory, mode = process.env.NODE_ENV) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
[
|
|
17
|
+
`.env.${mode}.local`,
|
|
18
|
+
".env.local",
|
|
19
|
+
`.env.${mode}`,
|
|
20
|
+
".env"
|
|
21
|
+
].map((name) => _path.default.resolve(appDirectory, name)).filter((filePath) => _fs.default.existsSync(filePath) && !_fs.default.statSync(filePath).isDirectory()).forEach((filePath) => {
|
|
22
|
+
const envConfig = _utils.dotenv.config({
|
|
23
|
+
path: filePath
|
|
19
24
|
});
|
|
25
|
+
(0, _utils.dotenvExpand)(envConfig);
|
|
26
|
+
});
|
|
20
27
|
};
|
|
21
|
-
exports.loadEnv = loadEnv;
|
package/dist/loadPlugins.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const isOldPluginConfig: (config?: PluginConfig) => config is Old
|
|
|
9
9
|
* @returns Plugin Objects has been required.
|
|
10
10
|
*/
|
|
11
11
|
export declare const loadPlugins: (appDirectory: string, userConfig: UserConfig, options?: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}) => Promise<CliPlugin[]>;
|
|
12
|
+
internalPlugins?: InternalPlugins;
|
|
13
|
+
autoLoad?: InternalPlugins;
|
|
14
|
+
forceAutoLoadPlugins?: boolean;
|
|
15
|
+
}) => Promise<CliPlugin[]>;
|
package/dist/loadPlugins.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
isOldPluginConfig: function() {
|
|
14
|
+
return isOldPluginConfig;
|
|
15
|
+
},
|
|
16
|
+
loadPlugins: function() {
|
|
17
|
+
return loadPlugins;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const _utils = require("@modern-js/utils");
|
|
21
|
+
const _manager = require("./manager");
|
|
22
|
+
const debug = (0, _utils.createDebugger)("load-plugins");
|
|
7
23
|
const resolveCliPlugin = async (p, appDirectory) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return module;
|
|
24
|
+
const pkg = typeof p === "string" ? p : p[0];
|
|
25
|
+
const pluginOptions = typeof p === "string" ? void 0 : p[1];
|
|
26
|
+
const path = (0, _utils.tryResolve)(pkg, appDirectory);
|
|
27
|
+
let module;
|
|
28
|
+
try {
|
|
29
|
+
module = (0, _utils.compatRequire)(path);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
({ default: module } = await (0, _utils.dynamicImport)(path));
|
|
32
|
+
}
|
|
33
|
+
if (typeof module === "function") {
|
|
34
|
+
const result = module(pluginOptions);
|
|
35
|
+
return (0, _manager.createPlugin)(result.setup, result);
|
|
36
|
+
}
|
|
37
|
+
return module;
|
|
24
38
|
};
|
|
25
|
-
const isOldPluginConfig = (config) => Array.isArray(config) &&
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
exports.isOldPluginConfig = isOldPluginConfig;
|
|
30
|
-
/**
|
|
31
|
-
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
32
|
-
* @param appDirectory - Application root directory.
|
|
33
|
-
* @param userConfig - Resolved user config.
|
|
34
|
-
* @param options.internalPlugins - Internal plugins.
|
|
35
|
-
* @returns Plugin Objects has been required.
|
|
36
|
-
*/
|
|
39
|
+
const isOldPluginConfig = (config) => Array.isArray(config) && config.some((item) => {
|
|
40
|
+
return typeof item === "string" || Array.isArray(item);
|
|
41
|
+
});
|
|
37
42
|
const loadPlugins = async (appDirectory, userConfig, options = {}) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}));
|
|
53
|
-
if (!(0, exports.isOldPluginConfig)(pluginConfig)) {
|
|
54
|
-
if (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.length) {
|
|
55
|
-
loadedPlugins.push(...pluginConfig.map(item => (0, manager_1.createPlugin)(item.setup, item)));
|
|
56
|
-
}
|
|
43
|
+
const pluginConfig = userConfig.plugins;
|
|
44
|
+
const plugins = [
|
|
45
|
+
...options.forceAutoLoadPlugins || userConfig.autoLoadPlugins ? (0, _utils.getInternalPlugins)(appDirectory, options.internalPlugins) : [],
|
|
46
|
+
...isOldPluginConfig(pluginConfig) ? pluginConfig : [],
|
|
47
|
+
...options.autoLoad ? (0, _utils.getInternalPlugins)(appDirectory, options.autoLoad) : []
|
|
48
|
+
];
|
|
49
|
+
const loadedPlugins = await Promise.all(plugins.map((plugin) => {
|
|
50
|
+
const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
|
51
|
+
debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
|
|
52
|
+
return loadedPlugin;
|
|
53
|
+
}));
|
|
54
|
+
if (!isOldPluginConfig(pluginConfig)) {
|
|
55
|
+
if (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.length) {
|
|
56
|
+
loadedPlugins.push(...pluginConfig.map((item) => (0, _manager.createPlugin)(item.setup, item)));
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
}
|
|
59
|
+
return loadedPlugins;
|
|
59
60
|
};
|
|
60
|
-
exports.loadPlugins = loadPlugins;
|