@modern-js/core 1.4.6 → 1.6.1
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/.eslintrc.js +8 -0
- package/CHANGELOG.md +47 -0
- package/dist/js/modern/config/defaults.js +4 -1
- package/dist/js/modern/config/index.js +2 -1
- package/dist/js/modern/config/types/index.js +0 -0
- package/dist/js/modern/config/types/less.js +0 -0
- package/dist/js/modern/config/types/sass.js +0 -0
- package/dist/js/modern/config/types/ssg.js +0 -0
- package/dist/js/modern/config/types/test.js +0 -0
- package/dist/js/modern/config/types/unbundle.js +0 -0
- package/dist/js/modern/context.js +18 -0
- package/dist/js/modern/index.js +9 -28
- package/dist/js/modern/initWatcher.js +1 -0
- package/dist/js/modern/loadPlugins.js +43 -48
- package/dist/js/modern/manager.js +28 -0
- package/dist/js/modern/pluginAPI.js +11 -0
- package/dist/js/node/config/defaults.js +4 -1
- package/dist/js/node/config/index.js +22 -1
- package/dist/js/node/config/types/index.js +0 -0
- package/dist/js/node/config/types/less.js +0 -0
- package/dist/js/node/config/types/sass.js +0 -0
- package/dist/js/node/config/types/ssg.js +0 -0
- package/dist/js/node/config/types/test.js +0 -0
- package/dist/js/node/config/types/unbundle.js +0 -0
- package/dist/js/node/context.js +22 -1
- package/dist/js/node/index.js +78 -67
- package/dist/js/node/initWatcher.js +1 -0
- package/dist/js/node/loadPlugins.js +42 -47
- package/dist/js/node/manager.js +45 -0
- package/dist/js/node/pluginAPI.js +54 -0
- package/dist/types/config/defaults.d.ts +3 -0
- package/dist/types/config/index.d.ts +3 -129
- package/dist/types/config/types/index.d.ts +231 -0
- package/dist/types/config/types/less.d.ts +10 -0
- package/dist/types/config/types/sass.d.ts +8 -0
- package/dist/types/config/types/ssg.d.ts +13 -0
- package/dist/types/config/types/test.d.ts +15 -0
- package/dist/types/config/types/unbundle.d.ts +28 -0
- package/dist/types/context.d.ts +19 -1
- package/dist/types/index.d.ts +6 -95
- package/dist/types/initWatcher.d.ts +1 -1
- package/dist/types/loadPlugins.d.ts +24 -13
- package/dist/types/manager.d.ts +74 -0
- package/dist/types/pluginAPI.d.ts +13 -0
- package/jest.config.js +0 -1
- package/package.json +13 -8
- package/tests/config.test.ts +1 -1
- package/tests/initWatcher.test.ts +1 -1
- package/tests/loadPlugin.test.ts +32 -43
- package/tests/pluginAPI.test.ts +19 -0
package/dist/js/node/index.js
CHANGED
|
@@ -4,16 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
+
cli: true,
|
|
8
|
+
initAppDir: true,
|
|
9
|
+
initAppContext: true,
|
|
7
10
|
manager: true,
|
|
8
|
-
createPlugin: true,
|
|
9
|
-
registerHook: true,
|
|
10
11
|
mountHook: true,
|
|
11
12
|
usePlugins: true,
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
createPlugin: true,
|
|
14
|
+
registerHook: true,
|
|
14
15
|
AppContext: true,
|
|
15
16
|
ConfigContext: true,
|
|
16
|
-
initAppContext: true,
|
|
17
17
|
ResolvedConfigContext: true,
|
|
18
18
|
useAppContext: true,
|
|
19
19
|
useConfigContext: true,
|
|
@@ -22,46 +22,75 @@ var _exportNames = {
|
|
|
22
22
|
Object.defineProperty(exports, "AppContext", {
|
|
23
23
|
enumerable: true,
|
|
24
24
|
get: function () {
|
|
25
|
-
return
|
|
25
|
+
return _pluginAPI.AppContext;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "ConfigContext", {
|
|
29
29
|
enumerable: true,
|
|
30
30
|
get: function () {
|
|
31
|
-
return
|
|
31
|
+
return _pluginAPI.ConfigContext;
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
Object.defineProperty(exports, "ResolvedConfigContext", {
|
|
35
35
|
enumerable: true,
|
|
36
36
|
get: function () {
|
|
37
|
-
return
|
|
37
|
+
return _pluginAPI.ResolvedConfigContext;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
exports.cli = void 0;
|
|
41
|
+
Object.defineProperty(exports, "createPlugin", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return _manager.createPlugin;
|
|
38
45
|
}
|
|
39
46
|
});
|
|
40
|
-
exports.createPlugin = exports.cli = void 0;
|
|
41
47
|
Object.defineProperty(exports, "initAppContext", {
|
|
42
48
|
enumerable: true,
|
|
43
49
|
get: function () {
|
|
44
50
|
return _context.initAppContext;
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
|
-
exports.
|
|
53
|
+
exports.initAppDir = void 0;
|
|
54
|
+
Object.defineProperty(exports, "manager", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _manager.manager;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "mountHook", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _manager.mountHook;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "registerHook", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _manager.registerHook;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
48
72
|
Object.defineProperty(exports, "useAppContext", {
|
|
49
73
|
enumerable: true,
|
|
50
74
|
get: function () {
|
|
51
|
-
return
|
|
75
|
+
return _pluginAPI.useAppContext;
|
|
52
76
|
}
|
|
53
77
|
});
|
|
54
78
|
Object.defineProperty(exports, "useConfigContext", {
|
|
55
79
|
enumerable: true,
|
|
56
80
|
get: function () {
|
|
57
|
-
return
|
|
81
|
+
return _pluginAPI.useConfigContext;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "usePlugins", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _manager.usePlugins;
|
|
58
88
|
}
|
|
59
89
|
});
|
|
60
|
-
exports.usePlugins = void 0;
|
|
61
90
|
Object.defineProperty(exports, "useResolvedConfigContext", {
|
|
62
91
|
enumerable: true,
|
|
63
92
|
get: function () {
|
|
64
|
-
return
|
|
93
|
+
return _pluginAPI.useResolvedConfigContext;
|
|
65
94
|
}
|
|
66
95
|
});
|
|
67
96
|
|
|
@@ -69,20 +98,6 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
69
98
|
|
|
70
99
|
var _utils = require("@modern-js/utils");
|
|
71
100
|
|
|
72
|
-
var _plugin = require("@modern-js/plugin");
|
|
73
|
-
|
|
74
|
-
Object.keys(_plugin).forEach(function (key) {
|
|
75
|
-
if (key === "default" || key === "__esModule") return;
|
|
76
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
77
|
-
if (key in exports && exports[key] === _plugin[key]) return;
|
|
78
|
-
Object.defineProperty(exports, key, {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return _plugin[key];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
101
|
var _node = require("@modern-js/plugin/node");
|
|
87
102
|
|
|
88
103
|
Object.keys(_node).forEach(function (key) {
|
|
@@ -121,6 +136,24 @@ var _initWatcher = require("./initWatcher");
|
|
|
121
136
|
|
|
122
137
|
var _loadEnv = require("./loadEnv");
|
|
123
138
|
|
|
139
|
+
var _manager = require("./manager");
|
|
140
|
+
|
|
141
|
+
var _plugin = require("@modern-js/plugin");
|
|
142
|
+
|
|
143
|
+
Object.keys(_plugin).forEach(function (key) {
|
|
144
|
+
if (key === "default" || key === "__esModule") return;
|
|
145
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
146
|
+
if (key in exports && exports[key] === _plugin[key]) return;
|
|
147
|
+
Object.defineProperty(exports, key, {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function () {
|
|
150
|
+
return _plugin[key];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
var _pluginAPI = require("./pluginAPI");
|
|
156
|
+
|
|
124
157
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
125
158
|
|
|
126
159
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -131,35 +164,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
131
164
|
|
|
132
165
|
_commander.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
133
166
|
|
|
134
|
-
const hooksMap = {
|
|
135
|
-
config: (0, _plugin.createParallelWorkflow)(),
|
|
136
|
-
resolvedConfig: (0, _plugin.createAsyncWaterfall)(),
|
|
137
|
-
validateSchema: (0, _plugin.createParallelWorkflow)(),
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
139
|
-
prepare: (0, _plugin.createAsyncWorkflow)(),
|
|
140
|
-
commands: (0, _plugin.createAsyncWorkflow)(),
|
|
141
|
-
watchFiles: (0, _plugin.createParallelWorkflow)(),
|
|
142
|
-
fileChange: (0, _plugin.createAsyncWorkflow)(),
|
|
143
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
144
|
-
beforeExit: (0, _plugin.createAsyncWorkflow)(),
|
|
145
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
146
|
-
beforeRestart: (0, _plugin.createAsyncWorkflow)()
|
|
147
|
-
};
|
|
148
|
-
const manager = (0, _plugin.createAsyncManager)(hooksMap);
|
|
149
|
-
exports.manager = manager;
|
|
150
|
-
const {
|
|
151
|
-
createPlugin,
|
|
152
|
-
registe: registerHook,
|
|
153
|
-
useRunner: mountHook
|
|
154
|
-
} = manager;
|
|
155
|
-
exports.mountHook = mountHook;
|
|
156
|
-
exports.registerHook = registerHook;
|
|
157
|
-
exports.createPlugin = createPlugin;
|
|
158
|
-
|
|
159
|
-
const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _utils.compatRequire)(require.resolve(plugin))));
|
|
160
|
-
|
|
161
|
-
exports.usePlugins = usePlugins;
|
|
162
|
-
|
|
163
167
|
const initAppDir = async cwd => {
|
|
164
168
|
if (!cwd) {
|
|
165
169
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -189,24 +193,27 @@ const createCli = () => {
|
|
|
189
193
|
var _options$options$meta, _options$options;
|
|
190
194
|
|
|
191
195
|
(0, _node.enable)();
|
|
192
|
-
|
|
196
|
+
|
|
197
|
+
_manager.manager.clear();
|
|
198
|
+
|
|
193
199
|
restartOptions = options;
|
|
194
200
|
const appDirectory = await initAppDir();
|
|
195
201
|
const metaName = (_options$options$meta = options === null || options === void 0 ? void 0 : (_options$options = options.options) === null || _options$options === void 0 ? void 0 : _options$options.metaName) !== null && _options$options$meta !== void 0 ? _options$options$meta : 'MODERN';
|
|
196
202
|
(0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
197
203
|
const loaded = await (0, _config.loadUserConfig)(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
|
|
198
204
|
const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
|
|
199
|
-
internalPlugins: options === null || options === void 0 ? void 0 : options.plugins
|
|
200
|
-
transformPlugin: options === null || options === void 0 ? void 0 : options.transformPlugin
|
|
205
|
+
internalPlugins: options === null || options === void 0 ? void 0 : options.plugins
|
|
201
206
|
});
|
|
202
|
-
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
207
|
+
plugins.forEach(plugin => plugin.cli && _manager.manager.usePlugin(plugin.cli));
|
|
203
208
|
const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
|
|
204
|
-
|
|
209
|
+
|
|
210
|
+
_manager.manager.run(() => {
|
|
205
211
|
_context.ConfigContext.set(loaded.config);
|
|
206
212
|
|
|
207
213
|
_context.AppContext.set(appContext);
|
|
208
214
|
});
|
|
209
|
-
|
|
215
|
+
|
|
216
|
+
hooksRunner = await _manager.manager.init();
|
|
210
217
|
['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
|
|
211
218
|
process.on(event, async err => {
|
|
212
219
|
await hooksRunner.beforeExit();
|
|
@@ -230,7 +237,7 @@ const createCli = () => {
|
|
|
230
237
|
resolved: config
|
|
231
238
|
}); // update context value
|
|
232
239
|
|
|
233
|
-
manager.run(() => {
|
|
240
|
+
_manager.manager.run(() => {
|
|
234
241
|
_context.ConfigContext.set(loaded.config);
|
|
235
242
|
|
|
236
243
|
_context.ResolvedConfigContext.set(resolved);
|
|
@@ -240,6 +247,7 @@ const createCli = () => {
|
|
|
240
247
|
distDirectory: (0, _utils.ensureAbsolutePath)(appDirectory, resolved.output.path)
|
|
241
248
|
}));
|
|
242
249
|
});
|
|
250
|
+
|
|
243
251
|
await hooksRunner.prepare();
|
|
244
252
|
return {
|
|
245
253
|
loadedConfig: loaded,
|
|
@@ -258,7 +266,8 @@ const createCli = () => {
|
|
|
258
266
|
program: _commander.program
|
|
259
267
|
});
|
|
260
268
|
(0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
261
|
-
|
|
269
|
+
|
|
270
|
+
_manager.manager.run(() => _commander.program.parse(process.argv));
|
|
262
271
|
}
|
|
263
272
|
|
|
264
273
|
async function restart() {
|
|
@@ -270,7 +279,9 @@ const createCli = () => {
|
|
|
270
279
|
_utils.logger.info('Restart...\n');
|
|
271
280
|
|
|
272
281
|
let hasGetError = false;
|
|
273
|
-
|
|
282
|
+
|
|
283
|
+
const runner = _manager.manager.useRunner();
|
|
284
|
+
|
|
274
285
|
await runner.beforeRestart();
|
|
275
286
|
|
|
276
287
|
try {
|
|
@@ -280,7 +291,7 @@ const createCli = () => {
|
|
|
280
291
|
hasGetError = true;
|
|
281
292
|
} finally {
|
|
282
293
|
if (!hasGetError) {
|
|
283
|
-
manager.run(() => _commander.program.parse(process.argv));
|
|
294
|
+
_manager.manager.run(() => _commander.program.parse(process.argv));
|
|
284
295
|
}
|
|
285
296
|
}
|
|
286
297
|
}
|
|
@@ -35,6 +35,7 @@ const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) =
|
|
|
35
35
|
|
|
36
36
|
const watcher = _chokidar.default.watch(watched, {
|
|
37
37
|
cwd: appDirectory,
|
|
38
|
+
ignoreInitial: true,
|
|
38
39
|
ignorePermissionErrors: true,
|
|
39
40
|
ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
|
|
40
41
|
});
|
|
@@ -8,11 +8,7 @@ exports.loadPlugins = void 0;
|
|
|
8
8
|
|
|
9
9
|
var _utils = require("@modern-js/utils");
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
|
|
15
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
var _manager = require("./manager");
|
|
16
12
|
|
|
17
13
|
const debug = (0, _utils.createDebugger)('load-plugins');
|
|
18
14
|
|
|
@@ -41,7 +37,7 @@ const tryResolve = (name, appDirectory) => {
|
|
|
41
37
|
return filePath;
|
|
42
38
|
};
|
|
43
39
|
|
|
44
|
-
function getAppPlugins(appDirectory,
|
|
40
|
+
function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
|
|
45
41
|
const allPlugins = internalPlugins || _utils.INTERNAL_PLUGINS;
|
|
46
42
|
const appPlugins = [...Object.keys(allPlugins).filter(name => {
|
|
47
43
|
const config = allPlugins[name];
|
|
@@ -52,46 +48,44 @@ function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
|
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
return (0, _utils.isDepExists)(appDirectory, name);
|
|
55
|
-
}).map(name => allPlugins[name]), ...
|
|
51
|
+
}).map(name => allPlugins[name]), ...oldPluginConfig];
|
|
56
52
|
return appPlugins;
|
|
57
53
|
}
|
|
54
|
+
|
|
55
|
+
const resolveCliPlugin = (p, appDirectory) => {
|
|
56
|
+
const pkg = typeof p === 'string' ? p : p[0];
|
|
57
|
+
const path = tryResolve(pkg, appDirectory);
|
|
58
|
+
const module = (0, _utils.compatRequire)(path);
|
|
59
|
+
|
|
60
|
+
if (typeof module === 'function') {
|
|
61
|
+
const pluginOptions = Array.isArray(p) ? p[1] : undefined;
|
|
62
|
+
const result = module(pluginOptions);
|
|
63
|
+
return (0, _manager.createPlugin)(result.setup, result);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return module;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const isOldPluginConfig = config => Array.isArray(config) && config.some(item => {
|
|
70
|
+
if (typeof item === 'string' || Array.isArray(item)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return 'cli' in item || 'server' in item;
|
|
75
|
+
});
|
|
58
76
|
/**
|
|
59
77
|
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
60
78
|
* @param appDirectory - Application root directory.
|
|
61
79
|
* @param userConfig - Resolved user config.
|
|
62
80
|
* @param options.internalPlugins - Internal plugins.
|
|
63
|
-
* @param options.transformPlugin - transform plugin before using it.
|
|
64
81
|
* @returns Plugin Objects has been required.
|
|
65
82
|
*/
|
|
66
83
|
|
|
67
84
|
|
|
68
85
|
const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} = options;
|
|
73
|
-
|
|
74
|
-
const resolvePlugin = p => {
|
|
75
|
-
const pkg = typeof p === 'string' ? p : p[0];
|
|
76
|
-
const path = tryResolve(pkg, appDirectory);
|
|
77
|
-
let module = (0, _utils.compatRequire)(path);
|
|
78
|
-
const pluginOptions = Array.isArray(p) ? p[1] : undefined;
|
|
79
|
-
|
|
80
|
-
if (transformPlugin) {
|
|
81
|
-
module = transformPlugin(module, userConfig, pluginOptions);
|
|
82
|
-
} else {
|
|
83
|
-
module = typeof module === 'function' ? module(pluginOptions) : module;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
pkg,
|
|
88
|
-
path,
|
|
89
|
-
module
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const plugins = getAppPlugins(appDirectory, userConfig.plugins || [], internalPlugins);
|
|
94
|
-
return plugins.map(plugin => {
|
|
86
|
+
const pluginConfig = userConfig.plugins;
|
|
87
|
+
const plugins = getAppPlugins(appDirectory, isOldPluginConfig(pluginConfig) ? pluginConfig : [], options.internalPlugins);
|
|
88
|
+
const loadedPlugins = plugins.map(plugin => {
|
|
95
89
|
const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
|
|
96
90
|
cli: plugin
|
|
97
91
|
} : plugin;
|
|
@@ -103,23 +97,12 @@ const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
103
97
|
const loadedPlugin = {};
|
|
104
98
|
|
|
105
99
|
if (cli) {
|
|
106
|
-
|
|
107
|
-
pkg,
|
|
108
|
-
path,
|
|
109
|
-
module
|
|
110
|
-
} = resolvePlugin(cli);
|
|
111
|
-
loadedPlugin.cli = _objectSpread(_objectSpread({}, module), {}, {
|
|
112
|
-
pluginPath: path
|
|
113
|
-
});
|
|
114
|
-
loadedPlugin.cliPkg = pkg;
|
|
100
|
+
loadedPlugin.cli = resolveCliPlugin(cli, appDirectory);
|
|
115
101
|
} // server plugins don't support to accept params
|
|
116
102
|
|
|
117
103
|
|
|
118
104
|
if (server && typeof server === 'string') {
|
|
119
|
-
|
|
120
|
-
loadedPlugin.server = {
|
|
121
|
-
pluginPath: path
|
|
122
|
-
};
|
|
105
|
+
loadedPlugin.server = server;
|
|
123
106
|
loadedPlugin.serverPkg = server;
|
|
124
107
|
}
|
|
125
108
|
|
|
@@ -129,6 +112,18 @@ const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
129
112
|
});
|
|
130
113
|
return loadedPlugin;
|
|
131
114
|
});
|
|
115
|
+
|
|
116
|
+
if (!isOldPluginConfig(pluginConfig)) {
|
|
117
|
+
const cliPlugins = Array.isArray(pluginConfig) ? pluginConfig : pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.cli;
|
|
118
|
+
|
|
119
|
+
if (cliPlugins !== null && cliPlugins !== void 0 && cliPlugins.length) {
|
|
120
|
+
loadedPlugins.push(...cliPlugins.map(item => ({
|
|
121
|
+
cli: (0, _manager.createPlugin)(item.setup, item)
|
|
122
|
+
})));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return loadedPlugins;
|
|
132
127
|
};
|
|
133
128
|
|
|
134
129
|
exports.loadPlugins = loadPlugins;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.usePlugins = exports.registerHook = exports.mountHook = exports.manager = exports.createPlugin = void 0;
|
|
7
|
+
|
|
8
|
+
var _plugin = require("@modern-js/plugin");
|
|
9
|
+
|
|
10
|
+
var _utils = require("@modern-js/utils");
|
|
11
|
+
|
|
12
|
+
var _pluginAPI = require("./pluginAPI");
|
|
13
|
+
|
|
14
|
+
const baseHooks = {
|
|
15
|
+
config: (0, _plugin.createParallelWorkflow)(),
|
|
16
|
+
resolvedConfig: (0, _plugin.createAsyncWaterfall)(),
|
|
17
|
+
validateSchema: (0, _plugin.createParallelWorkflow)(),
|
|
18
|
+
prepare: (0, _plugin.createAsyncWorkflow)(),
|
|
19
|
+
commands: (0, _plugin.createAsyncWorkflow)(),
|
|
20
|
+
watchFiles: (0, _plugin.createParallelWorkflow)(),
|
|
21
|
+
fileChange: (0, _plugin.createAsyncWorkflow)(),
|
|
22
|
+
beforeExit: (0, _plugin.createAsyncWorkflow)(),
|
|
23
|
+
beforeRestart: (0, _plugin.createAsyncWorkflow)()
|
|
24
|
+
};
|
|
25
|
+
/** All hooks of cli plugin. */
|
|
26
|
+
|
|
27
|
+
const manager = (0, _plugin.createAsyncManager)(baseHooks, _pluginAPI.pluginAPI);
|
|
28
|
+
/** Plugin options of a cli plugin. */
|
|
29
|
+
|
|
30
|
+
exports.manager = manager;
|
|
31
|
+
const {
|
|
32
|
+
createPlugin,
|
|
33
|
+
registerHook,
|
|
34
|
+
useRunner: mountHook
|
|
35
|
+
} = manager;
|
|
36
|
+
exports.mountHook = mountHook;
|
|
37
|
+
exports.registerHook = registerHook;
|
|
38
|
+
exports.createPlugin = createPlugin;
|
|
39
|
+
|
|
40
|
+
const usePlugins = plugins => plugins.forEach(pluginPath => {
|
|
41
|
+
const module = (0, _utils.compatRequire)(require.resolve(pluginPath));
|
|
42
|
+
manager.usePlugin(module);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
exports.usePlugins = usePlugins;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AppContext", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _context.AppContext;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ConfigContext", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _context.ConfigContext;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ResolvedConfigContext", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _context.ResolvedConfigContext;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
exports.pluginAPI = void 0;
|
|
25
|
+
Object.defineProperty(exports, "useAppContext", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _context.useAppContext;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "useConfigContext", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _context.useConfigContext;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "useResolvedConfigContext", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _context.useResolvedConfigContext;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
var _context = require("./context");
|
|
45
|
+
|
|
46
|
+
const pluginAPI = {
|
|
47
|
+
setAppContext: _context.setAppContext,
|
|
48
|
+
useAppContext: _context.useAppContext,
|
|
49
|
+
useConfigContext: _context.useConfigContext,
|
|
50
|
+
useResolvedConfigContext: _context.useResolvedConfigContext
|
|
51
|
+
};
|
|
52
|
+
/** all apis for cli plugin */
|
|
53
|
+
|
|
54
|
+
exports.pluginAPI = pluginAPI;
|
|
@@ -1,137 +1,11 @@
|
|
|
1
1
|
import { ErrorObject } from 'ajv';
|
|
2
|
-
import { MetaOptions } from '@modern-js/utils';
|
|
3
|
-
import { PluginConfig } from '../loadPlugins';
|
|
4
2
|
import { defaults } from './defaults';
|
|
5
3
|
import { mergeConfig, NormalizedConfig } from './mergeConfig';
|
|
6
4
|
import { PluginValidateSchema } from './schema';
|
|
5
|
+
import type { UserConfig, ConfigParam, LoadedConfig } from './types';
|
|
7
6
|
export { defaults as defaultsConfig };
|
|
8
7
|
export { mergeConfig };
|
|
9
|
-
|
|
10
|
-
entries?: Record<string, string | {
|
|
11
|
-
entry: string;
|
|
12
|
-
enableFileSystemRoutes?: boolean;
|
|
13
|
-
disableMount?: boolean;
|
|
14
|
-
}>;
|
|
15
|
-
disableDefaultEntries?: boolean;
|
|
16
|
-
entriesDir?: string;
|
|
17
|
-
configDir?: string;
|
|
18
|
-
apiDir?: string;
|
|
19
|
-
envVars?: Array<string>;
|
|
20
|
-
globalVars?: Record<string, string>;
|
|
21
|
-
alias?: Record<string, string> | ((aliases: Record<string, string>) => Record<string, unknown>);
|
|
22
|
-
moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => void) | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
|
|
23
|
-
include?: Array<string | RegExp>;
|
|
24
|
-
}
|
|
25
|
-
interface OutputConfig {
|
|
26
|
-
assetPrefix?: string;
|
|
27
|
-
htmlPath?: string;
|
|
28
|
-
jsPath?: string;
|
|
29
|
-
cssPath?: string;
|
|
30
|
-
mediaPath?: string;
|
|
31
|
-
path?: string;
|
|
32
|
-
title?: string;
|
|
33
|
-
titleByEntries?: Record<string, string>;
|
|
34
|
-
meta?: MetaOptions;
|
|
35
|
-
metaByEntries?: Record<string, MetaOptions>;
|
|
36
|
-
inject?: 'body' | 'head' | boolean;
|
|
37
|
-
injectByEntries?: Record<string, 'body' | 'head' | boolean>;
|
|
38
|
-
mountId?: string;
|
|
39
|
-
favicon?: string;
|
|
40
|
-
faviconByEntries?: Record<string, string | undefined>;
|
|
41
|
-
copy?: Array<Record<string, unknown> & {
|
|
42
|
-
from: string;
|
|
43
|
-
}>;
|
|
44
|
-
scriptExt?: Record<string, unknown>;
|
|
45
|
-
disableTsChecker?: boolean;
|
|
46
|
-
disableHtmlFolder?: boolean;
|
|
47
|
-
disableCssModuleExtension?: boolean;
|
|
48
|
-
disableCssExtract?: boolean;
|
|
49
|
-
enableCssModuleTSDeclaration?: boolean;
|
|
50
|
-
disableMinimize?: boolean;
|
|
51
|
-
enableInlineStyles?: boolean;
|
|
52
|
-
enableInlineScripts?: boolean;
|
|
53
|
-
disableSourceMap?: boolean;
|
|
54
|
-
disableInlineRuntimeChunk?: boolean;
|
|
55
|
-
disableAssetsCache?: boolean;
|
|
56
|
-
enableLatestDecorators?: boolean;
|
|
57
|
-
polyfill?: 'off' | 'usage' | 'entry' | 'ua';
|
|
58
|
-
dataUriLimit?: number;
|
|
59
|
-
templateParameters?: Record<string, unknown>;
|
|
60
|
-
templateParametersByEntries?: Record<string, Record<string, unknown> | undefined>;
|
|
61
|
-
cssModuleLocalIdentName?: string;
|
|
62
|
-
enableModernMode?: boolean;
|
|
63
|
-
federation?: boolean;
|
|
64
|
-
disableNodePolyfill?: boolean;
|
|
65
|
-
enableTsLoader?: boolean;
|
|
66
|
-
}
|
|
67
|
-
interface ServerConfig {
|
|
68
|
-
routes?: Record<string, string | {
|
|
69
|
-
route: string | string[];
|
|
70
|
-
disableSpa?: boolean;
|
|
71
|
-
}>;
|
|
72
|
-
publicRoutes?: {
|
|
73
|
-
[filepath: string]: string;
|
|
74
|
-
};
|
|
75
|
-
ssr?: boolean | Record<string, unknown>;
|
|
76
|
-
ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
|
|
77
|
-
baseUrl?: string | Array<string>;
|
|
78
|
-
port?: number;
|
|
79
|
-
logger?: Record<string, any>;
|
|
80
|
-
metrics?: Record<string, any>;
|
|
81
|
-
enableMicroFrontendDebug?: boolean;
|
|
82
|
-
}
|
|
83
|
-
interface DevConfig {
|
|
84
|
-
assetPrefix?: string | boolean;
|
|
85
|
-
https?: boolean;
|
|
86
|
-
}
|
|
87
|
-
interface MicroFrontend {
|
|
88
|
-
enableHtmlEntry?: boolean;
|
|
89
|
-
externalBasicLibrary?: boolean;
|
|
90
|
-
moduleApp?: string;
|
|
91
|
-
}
|
|
92
|
-
interface DeployConfig {
|
|
93
|
-
microFrontend?: false | MicroFrontend;
|
|
94
|
-
domain?: string | Array<string>;
|
|
95
|
-
domainByEntries?: Record<string, string | Array<string>>;
|
|
96
|
-
}
|
|
97
|
-
declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>) => Record<string, unknown> | void);
|
|
98
|
-
interface ToolsConfig {
|
|
99
|
-
webpack?: ConfigFunction;
|
|
100
|
-
babel?: ConfigFunction;
|
|
101
|
-
autoprefixer?: ConfigFunction;
|
|
102
|
-
postcss?: ConfigFunction;
|
|
103
|
-
styledComponents?: ConfigFunction;
|
|
104
|
-
lodash?: ConfigFunction;
|
|
105
|
-
devServer?: Record<string, unknown>;
|
|
106
|
-
tsLoader?: ConfigFunction;
|
|
107
|
-
terser?: ConfigFunction;
|
|
108
|
-
minifyCss?: ConfigFunction;
|
|
109
|
-
esbuild?: Record<string, unknown>;
|
|
110
|
-
}
|
|
111
|
-
declare type RuntimeConfig = Record<string, any>;
|
|
112
|
-
interface RuntimeByEntriesConfig {
|
|
113
|
-
[name: string]: RuntimeConfig;
|
|
114
|
-
}
|
|
115
|
-
interface UserConfig {
|
|
116
|
-
source?: SourceConfig;
|
|
117
|
-
output?: OutputConfig;
|
|
118
|
-
server?: ServerConfig;
|
|
119
|
-
dev?: DevConfig;
|
|
120
|
-
deploy?: DeployConfig;
|
|
121
|
-
tools?: ToolsConfig;
|
|
122
|
-
plugins?: PluginConfig;
|
|
123
|
-
runtime?: RuntimeConfig;
|
|
124
|
-
runtimeByEntries?: RuntimeByEntriesConfig;
|
|
125
|
-
}
|
|
126
|
-
declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
|
|
127
|
-
interface LoadedConfig {
|
|
128
|
-
config: UserConfig;
|
|
129
|
-
filePath: string | false;
|
|
130
|
-
dependencies: string[];
|
|
131
|
-
pkgConfig: UserConfig;
|
|
132
|
-
jsConfig: UserConfig;
|
|
133
|
-
}
|
|
8
|
+
export * from './types';
|
|
134
9
|
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
135
10
|
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
|
|
136
|
-
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void) => Promise<NormalizedConfig>;
|
|
137
|
-
export type { SourceConfig, OutputConfig, ServerConfig, DevConfig, DeployConfig, ToolsConfig, RuntimeConfig, RuntimeByEntriesConfig, UserConfig, ConfigParam, LoadedConfig };
|
|
11
|
+
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void) => Promise<NormalizedConfig>;
|