@modern-js/core 1.2.1-rc.0 → 1.4.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 +57 -5
- package/dist/js/modern/cli.js +29 -0
- package/dist/js/modern/config/index.js +11 -5
- package/dist/js/modern/context.js +28 -16
- package/dist/js/modern/index.js +27 -12
- package/dist/js/modern/initWatcher.js +19 -3
- package/dist/js/modern/loadPlugins.js +21 -6
- package/dist/js/node/cli.js +35 -0
- package/dist/js/node/config/index.js +11 -5
- package/dist/js/node/context.js +28 -16
- package/dist/js/node/index.js +36 -39
- package/dist/js/node/initWatcher.js +18 -2
- package/dist/js/node/loadPlugins.js +22 -5
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config/index.d.ts +20 -14
- package/dist/types/context.d.ts +6 -1
- package/dist/types/index.d.ts +22 -7
- package/dist/types/initWatcher.d.ts +2 -1
- package/dist/types/loadPlugins.d.ts +8 -1
- package/jest.config.js +8 -0
- package/modern.config.js +0 -7
- package/package.json +17 -10
- package/tests/btsm.test.ts +20 -0
- package/tests/config.test.ts +137 -0
- package/tests/context.test.ts +68 -0
- package/tests/fixtures/index-test/package.json +3 -0
- package/tests/index.test.ts +74 -0
- package/tests/initWatcher.test.ts +63 -0
- package/tests/loadEnv.test.ts +1 -1
- package/tests/loadPlugin.test.ts +36 -2
- package/tests/mergeConfig.test.ts +1 -1
- package/tests/repeatKeyWarning.test.ts +2 -2
- package/tests/schema.test.ts +1 -1
- package/tests/tsconfig.json +1 -3
- package/tests/utils.test.ts +8 -0
- package/tsconfig.json +1 -3
- package/src/config/defaults.ts +0 -101
- package/src/config/index.ts +0 -297
- package/src/config/mergeConfig.ts +0 -69
- package/src/config/schema/deploy.ts +0 -17
- package/src/config/schema/index.ts +0 -116
- package/src/config/schema/output.ts +0 -65
- package/src/config/schema/server.ts +0 -106
- package/src/config/schema/source.ts +0 -34
- package/src/config/schema/tools.ts +0 -15
- package/src/context.ts +0 -46
- package/src/index.ts +0 -277
- package/src/initWatcher.ts +0 -77
- package/src/loadEnv.ts +0 -23
- package/src/loadPlugins.ts +0 -91
- package/src/types.d.ts +0 -0
- package/src/utils/commander.ts +0 -22
- package/src/utils/repeatKeyWarning.ts +0 -29
package/dist/js/node/index.js
CHANGED
|
@@ -11,10 +11,6 @@ var _exportNames = {
|
|
|
11
11
|
usePlugins: true,
|
|
12
12
|
cli: true,
|
|
13
13
|
initAppDir: true,
|
|
14
|
-
defineConfig: true,
|
|
15
|
-
loadUserConfig: true,
|
|
16
|
-
defaultsConfig: true,
|
|
17
|
-
mergeConfig: true,
|
|
18
14
|
AppContext: true,
|
|
19
15
|
ConfigContext: true,
|
|
20
16
|
initAppContext: true,
|
|
@@ -42,39 +38,13 @@ Object.defineProperty(exports, "ResolvedConfigContext", {
|
|
|
42
38
|
}
|
|
43
39
|
});
|
|
44
40
|
exports.createPlugin = exports.cli = void 0;
|
|
45
|
-
Object.defineProperty(exports, "defaultsConfig", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
get: function () {
|
|
48
|
-
return _config.defaultsConfig;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(exports, "defineConfig", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return _config.defineConfig;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
41
|
Object.defineProperty(exports, "initAppContext", {
|
|
58
42
|
enumerable: true,
|
|
59
43
|
get: function () {
|
|
60
44
|
return _context.initAppContext;
|
|
61
45
|
}
|
|
62
46
|
});
|
|
63
|
-
exports.initAppDir = void 0;
|
|
64
|
-
Object.defineProperty(exports, "loadUserConfig", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function () {
|
|
67
|
-
return _config.loadUserConfig;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
exports.manager = void 0;
|
|
71
|
-
Object.defineProperty(exports, "mergeConfig", {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function () {
|
|
74
|
-
return _config.mergeConfig;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
exports.registerHook = exports.mountHook = void 0;
|
|
47
|
+
exports.registerHook = exports.mountHook = exports.manager = exports.initAppDir = void 0;
|
|
78
48
|
Object.defineProperty(exports, "useAppContext", {
|
|
79
49
|
enumerable: true,
|
|
80
50
|
get: function () {
|
|
@@ -131,6 +101,18 @@ var _commander = require("./utils/commander");
|
|
|
131
101
|
|
|
132
102
|
var _config = require("./config");
|
|
133
103
|
|
|
104
|
+
Object.keys(_config).forEach(function (key) {
|
|
105
|
+
if (key === "default" || key === "__esModule") return;
|
|
106
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
107
|
+
if (key in exports && exports[key] === _config[key]) return;
|
|
108
|
+
Object.defineProperty(exports, key, {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () {
|
|
111
|
+
return _config[key];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
134
116
|
var _loadPlugins = require("./loadPlugins");
|
|
135
117
|
|
|
136
118
|
var _context = require("./context");
|
|
@@ -159,7 +141,9 @@ const hooksMap = {
|
|
|
159
141
|
watchFiles: (0, _plugin.createParallelWorkflow)(),
|
|
160
142
|
fileChange: (0, _plugin.createAsyncWorkflow)(),
|
|
161
143
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
162
|
-
beforeExit: (0, _plugin.createAsyncWorkflow)()
|
|
144
|
+
beforeExit: (0, _plugin.createAsyncWorkflow)(),
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
146
|
+
beforeRestart: (0, _plugin.createAsyncWorkflow)()
|
|
163
147
|
};
|
|
164
148
|
const manager = (0, _plugin.createAsyncManager)(hooksMap);
|
|
165
149
|
exports.manager = manager;
|
|
@@ -176,13 +160,18 @@ const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _u
|
|
|
176
160
|
|
|
177
161
|
exports.usePlugins = usePlugins;
|
|
178
162
|
|
|
179
|
-
const initAppDir = async
|
|
163
|
+
const initAppDir = async cwd => {
|
|
164
|
+
if (!cwd) {
|
|
165
|
+
// eslint-disable-next-line no-param-reassign
|
|
166
|
+
cwd = process.cwd();
|
|
167
|
+
}
|
|
168
|
+
|
|
180
169
|
const pkg = await (0, _utils.pkgUp)({
|
|
181
|
-
cwd
|
|
170
|
+
cwd
|
|
182
171
|
});
|
|
183
172
|
|
|
184
173
|
if (!pkg) {
|
|
185
|
-
throw new Error(`no package.json found in current work dir: ${
|
|
174
|
+
throw new Error(`no package.json found in current work dir: ${cwd}`);
|
|
186
175
|
}
|
|
187
176
|
|
|
188
177
|
return _path.default.dirname(pkg);
|
|
@@ -193,13 +182,16 @@ exports.initAppDir = initAppDir;
|
|
|
193
182
|
const createCli = () => {
|
|
194
183
|
let hooksRunner;
|
|
195
184
|
let isRestart = false;
|
|
185
|
+
let restartWithExistingPort = 0;
|
|
186
|
+
let restartOptions;
|
|
196
187
|
|
|
197
188
|
const init = async (argv = [], options) => {
|
|
198
189
|
(0, _node.enable)();
|
|
199
190
|
manager.clear();
|
|
191
|
+
restartOptions = options;
|
|
200
192
|
const appDirectory = await initAppDir();
|
|
201
193
|
(0, _loadEnv.loadEnv)(appDirectory);
|
|
202
|
-
const loaded = await (0, _config.loadUserConfig)(appDirectory, options === null || options === void 0 ? void 0 : options.configFile);
|
|
194
|
+
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);
|
|
203
195
|
let plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config.plugins || [], options === null || options === void 0 ? void 0 : options.plugins);
|
|
204
196
|
|
|
205
197
|
if (options !== null && options !== void 0 && options.beforeUsePlugins) {
|
|
@@ -207,7 +199,7 @@ const createCli = () => {
|
|
|
207
199
|
}
|
|
208
200
|
|
|
209
201
|
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
210
|
-
const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath);
|
|
202
|
+
const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
|
|
211
203
|
manager.run(() => {
|
|
212
204
|
_context.ConfigContext.set(loaded.config);
|
|
213
205
|
|
|
@@ -230,7 +222,7 @@ const createCli = () => {
|
|
|
230
222
|
});
|
|
231
223
|
const extraConfigs = await hooksRunner.config();
|
|
232
224
|
const extraSchemas = await hooksRunner.validateSchema();
|
|
233
|
-
const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas,
|
|
225
|
+
const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv);
|
|
234
226
|
const {
|
|
235
227
|
resolved
|
|
236
228
|
} = await hooksRunner.resolvedConfig({
|
|
@@ -269,14 +261,19 @@ const createCli = () => {
|
|
|
269
261
|
}
|
|
270
262
|
|
|
271
263
|
async function restart() {
|
|
264
|
+
var _AppContext$use$value, _AppContext$use$value2;
|
|
265
|
+
|
|
272
266
|
isRestart = true;
|
|
267
|
+
restartWithExistingPort = isRestart ? (_AppContext$use$value = (_AppContext$use$value2 = _context.AppContext.use().value) === null || _AppContext$use$value2 === void 0 ? void 0 : _AppContext$use$value2.port) !== null && _AppContext$use$value !== void 0 ? _AppContext$use$value : 0 : 0;
|
|
273
268
|
|
|
274
269
|
_utils.logger.info('Restart...\n');
|
|
275
270
|
|
|
276
271
|
let hasGetError = false;
|
|
272
|
+
const runner = manager.useRunner();
|
|
273
|
+
await runner.beforeRestart();
|
|
277
274
|
|
|
278
275
|
try {
|
|
279
|
-
await init(process.argv.slice(2));
|
|
276
|
+
await init(process.argv.slice(2), restartOptions);
|
|
280
277
|
} catch (err) {
|
|
281
278
|
console.error(err);
|
|
282
279
|
hasGetError = true;
|
|
@@ -25,7 +25,7 @@ const hashMap = new Map();
|
|
|
25
25
|
|
|
26
26
|
const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
|
|
27
27
|
// only add fs watcher on dev mode.
|
|
28
|
-
if ((0, _utils.isDev)() && argv[0] === 'dev') {
|
|
28
|
+
if (((0, _utils.isDev)() || (0, _utils.isTest)()) && argv[0] === 'dev') {
|
|
29
29
|
const extraFiles = await hooksRunner.watchFiles();
|
|
30
30
|
|
|
31
31
|
const configPath = _path.default.join(appDirectory, configDir);
|
|
@@ -47,20 +47,36 @@ const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) =
|
|
|
47
47
|
debug(`file change: %s`, changed);
|
|
48
48
|
hashMap.set(changed, currentHash);
|
|
49
49
|
hooksRunner.fileChange({
|
|
50
|
-
filename: changed
|
|
50
|
+
filename: changed,
|
|
51
|
+
eventType: 'change'
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
});
|
|
55
|
+
watcher.on('add', name => {
|
|
56
|
+
debug(`add file: %s`, name);
|
|
57
|
+
const currentHash = md5(_fs.default.readFileSync(_path.default.join(appDirectory, name), 'utf8'));
|
|
58
|
+
hashMap.set(name, currentHash);
|
|
59
|
+
hooksRunner.fileChange({
|
|
60
|
+
filename: name,
|
|
61
|
+
eventType: 'add'
|
|
62
|
+
});
|
|
63
|
+
});
|
|
54
64
|
watcher.on('unlink', name => {
|
|
55
65
|
debug(`remove file: %s`, name);
|
|
56
66
|
|
|
57
67
|
if (hashMap.has(name)) {
|
|
58
68
|
hashMap.delete(name);
|
|
59
69
|
}
|
|
70
|
+
|
|
71
|
+
hooksRunner.fileChange({
|
|
72
|
+
filename: name,
|
|
73
|
+
eventType: 'unlink'
|
|
74
|
+
});
|
|
60
75
|
});
|
|
61
76
|
watcher.on('error', err => {
|
|
62
77
|
throw err;
|
|
63
78
|
});
|
|
79
|
+
return watcher;
|
|
64
80
|
}
|
|
65
81
|
};
|
|
66
82
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getAppPlugins = getAppPlugins;
|
|
6
7
|
exports.loadPlugins = void 0;
|
|
7
8
|
|
|
8
9
|
var _utils = require("@modern-js/utils");
|
|
@@ -53,6 +54,21 @@ const resolvePlugin = (appDirectory, plugin) => {
|
|
|
53
54
|
|
|
54
55
|
return resolved;
|
|
55
56
|
};
|
|
57
|
+
|
|
58
|
+
function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
|
|
59
|
+
const allPlugins = internalPlugins || _utils.INTERNAL_PLUGINS;
|
|
60
|
+
const appPlugins = [...Object.keys(allPlugins).filter(name => {
|
|
61
|
+
const config = allPlugins[name];
|
|
62
|
+
|
|
63
|
+
if (config.forced === true) {
|
|
64
|
+
// 参考 packages/cli/core/src/cli.ts 文件
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (0, _utils.isDepExists)(appDirectory, name);
|
|
69
|
+
}).map(name => allPlugins[name]), ...pluginConfig];
|
|
70
|
+
return appPlugins;
|
|
71
|
+
}
|
|
56
72
|
/**
|
|
57
73
|
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
58
74
|
* @param appDirectory - Application root directory.
|
|
@@ -62,7 +78,7 @@ const resolvePlugin = (appDirectory, plugin) => {
|
|
|
62
78
|
|
|
63
79
|
|
|
64
80
|
const loadPlugins = (appDirectory, pluginConfig, internalPlugins) => {
|
|
65
|
-
const plugins =
|
|
81
|
+
const plugins = getAppPlugins(appDirectory, pluginConfig, internalPlugins);
|
|
66
82
|
return plugins.map(plugin => {
|
|
67
83
|
const {
|
|
68
84
|
cli,
|
|
@@ -75,12 +91,13 @@ const loadPlugins = (appDirectory, pluginConfig, internalPlugins) => {
|
|
|
75
91
|
|
|
76
92
|
const cliPlugin = cli && _objectSpread(_objectSpread({}, (0, _utils.compatRequire)(cli)), {}, {
|
|
77
93
|
pluginPath: cli
|
|
78
|
-
});
|
|
94
|
+
}); // server plugin should be required by server
|
|
79
95
|
|
|
80
|
-
const serverPlugin = server && _objectSpread(_objectSpread({}, (0, _utils.compatRequire)(server)), {}, {
|
|
81
|
-
pluginPath: server
|
|
82
|
-
});
|
|
83
96
|
|
|
97
|
+
const serverPlugin = server && {
|
|
98
|
+
// ...compatRequire(server),
|
|
99
|
+
pluginPath: server
|
|
100
|
+
};
|
|
84
101
|
return {
|
|
85
102
|
cli: cliPlugin,
|
|
86
103
|
cliPath: typeof plugin === 'string' ? plugin : plugin.cli,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,7 +5,7 @@ import { mergeConfig, NormalizedConfig } from './mergeConfig';
|
|
|
5
5
|
import { PluginValidateSchema } from './schema';
|
|
6
6
|
export { defaults as defaultsConfig };
|
|
7
7
|
export { mergeConfig };
|
|
8
|
-
|
|
8
|
+
interface SourceConfig {
|
|
9
9
|
entries?: Record<string, string | {
|
|
10
10
|
entry: string;
|
|
11
11
|
enableFileSystemRoutes?: boolean;
|
|
@@ -21,7 +21,7 @@ export interface SourceConfig {
|
|
|
21
21
|
moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
|
|
22
22
|
include?: Array<string | RegExp>;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
interface OutputConfig {
|
|
25
25
|
assetPrefix?: string;
|
|
26
26
|
htmlPath?: string;
|
|
27
27
|
jsPath?: string;
|
|
@@ -60,7 +60,7 @@ export interface OutputConfig {
|
|
|
60
60
|
disableNodePolyfill?: boolean;
|
|
61
61
|
enableTsLoader?: boolean;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
interface ServerConfig {
|
|
64
64
|
routes?: Record<string, string | {
|
|
65
65
|
route: string | string[];
|
|
66
66
|
disableSpa?: boolean;
|
|
@@ -76,17 +76,22 @@ export interface ServerConfig {
|
|
|
76
76
|
metrics?: Record<string, any>;
|
|
77
77
|
enableMicroFrontendDebug?: boolean;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
interface DevConfig {
|
|
80
80
|
assetPrefix?: string | boolean;
|
|
81
81
|
https?: boolean;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
interface MicroFrontend {
|
|
84
|
+
enableHtmlEntry?: boolean;
|
|
85
|
+
externalBasicLibrary?: boolean;
|
|
86
|
+
moduleApp?: boolean;
|
|
87
|
+
}
|
|
88
|
+
interface DeployConfig {
|
|
89
|
+
microFrontend?: boolean | MicroFrontend;
|
|
85
90
|
domain?: string | Array<string>;
|
|
86
91
|
domainByEntries?: Record<string, string | Array<string>>;
|
|
87
92
|
}
|
|
88
93
|
declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>) => Record<string, unknown> | void);
|
|
89
|
-
|
|
94
|
+
interface ToolsConfig {
|
|
90
95
|
webpack?: ConfigFunction;
|
|
91
96
|
babel?: ConfigFunction;
|
|
92
97
|
autoprefixer?: ConfigFunction;
|
|
@@ -98,11 +103,11 @@ export interface ToolsConfig {
|
|
|
98
103
|
minifyCss?: ConfigFunction;
|
|
99
104
|
esbuild?: Record<string, unknown>;
|
|
100
105
|
}
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
declare type RuntimeConfig = Record<string, any>;
|
|
107
|
+
interface RuntimeByEntriesConfig {
|
|
103
108
|
[name: string]: RuntimeConfig;
|
|
104
109
|
}
|
|
105
|
-
|
|
110
|
+
interface UserConfig {
|
|
106
111
|
source?: SourceConfig;
|
|
107
112
|
output?: OutputConfig;
|
|
108
113
|
server?: ServerConfig;
|
|
@@ -113,8 +118,8 @@ export interface UserConfig {
|
|
|
113
118
|
runtime?: RuntimeConfig;
|
|
114
119
|
runtimeByEntries?: RuntimeByEntriesConfig;
|
|
115
120
|
}
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
|
|
122
|
+
interface LoadedConfig {
|
|
118
123
|
config: UserConfig;
|
|
119
124
|
filePath: string | false;
|
|
120
125
|
dependencies: string[];
|
|
@@ -122,5 +127,6 @@ export interface LoadedConfig {
|
|
|
122
127
|
jsConfig: UserConfig;
|
|
123
128
|
}
|
|
124
129
|
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
125
|
-
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined) => Promise<LoadedConfig>;
|
|
126
|
-
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[],
|
|
130
|
+
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
|
|
131
|
+
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[]) => Promise<NormalizedConfig>;
|
|
132
|
+
export type { SourceConfig, OutputConfig, ServerConfig, DevConfig, DeployConfig, ToolsConfig, RuntimeConfig, RuntimeByEntriesConfig, UserConfig, ConfigParam, LoadedConfig };
|
package/dist/types/context.d.ts
CHANGED
|
@@ -11,4 +11,9 @@ export declare const useResolvedConfigContext: () => NormalizedConfig;
|
|
|
11
11
|
export declare const initAppContext: (appDirectory: string, plugins: Array<{
|
|
12
12
|
cli: any;
|
|
13
13
|
server: any;
|
|
14
|
-
}>, configFile: string | false
|
|
14
|
+
}>, configFile: string | false, options?: {
|
|
15
|
+
metaName?: string | undefined;
|
|
16
|
+
srcDir?: string | undefined;
|
|
17
|
+
distDir?: string | undefined;
|
|
18
|
+
sharedDir?: string | undefined;
|
|
19
|
+
} | undefined) => IAppContext;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import { INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
|
2
2
|
import { ParallelWorkflow, AsyncWorkflow, Progresses2Runners, AsyncWaterfall } from '@modern-js/plugin';
|
|
3
3
|
import type { Hooks } from '@modern-js/types';
|
|
4
4
|
import { Command } from './utils/commander';
|
|
5
|
-
import { defineConfig, loadUserConfig, UserConfig, ToolsConfig } from './config';
|
|
6
5
|
import { AppContext, ConfigContext, IAppContext, initAppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from './context';
|
|
7
6
|
import { NormalizedConfig } from './config/mergeConfig';
|
|
8
7
|
export type { Hooks };
|
|
9
|
-
export
|
|
8
|
+
export * from './config';
|
|
10
9
|
export * from '@modern-js/plugin';
|
|
11
10
|
export * from '@modern-js/plugin/node';
|
|
12
11
|
export declare type HooksRunner = Progresses2Runners<{
|
|
@@ -22,6 +21,7 @@ export declare type HooksRunner = Progresses2Runners<{
|
|
|
22
21
|
watchFiles: ParallelWorkflow<void>;
|
|
23
22
|
fileChange: AsyncWorkflow<{
|
|
24
23
|
filename: string;
|
|
24
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
25
25
|
}, void>;
|
|
26
26
|
beforeExit: AsyncWorkflow<void, void>;
|
|
27
27
|
}>;
|
|
@@ -38,8 +38,10 @@ export declare const manager: import("@modern-js/plugin").AsyncManager<Hooks, {
|
|
|
38
38
|
watchFiles: ParallelWorkflow<void, unknown>;
|
|
39
39
|
fileChange: AsyncWorkflow<{
|
|
40
40
|
filename: string;
|
|
41
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
41
42
|
}, void>;
|
|
42
43
|
beforeExit: AsyncWorkflow<void, void>;
|
|
44
|
+
beforeRestart: AsyncWorkflow<void, void>;
|
|
43
45
|
}>;
|
|
44
46
|
export declare const createPlugin: (initializer: import("@modern-js/plugin").AsyncInitializer<Partial<import("@modern-js/plugin").Progresses2Threads<{
|
|
45
47
|
config: ParallelWorkflow<void, unknown>;
|
|
@@ -54,8 +56,10 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
|
|
|
54
56
|
watchFiles: ParallelWorkflow<void, unknown>;
|
|
55
57
|
fileChange: AsyncWorkflow<{
|
|
56
58
|
filename: string;
|
|
59
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
57
60
|
}, void>;
|
|
58
61
|
beforeExit: AsyncWorkflow<void, void>;
|
|
62
|
+
beforeRestart: AsyncWorkflow<void, void>;
|
|
59
63
|
} & import("@modern-js/plugin").ClearDraftProgress<Hooks>>>>, options?: import("@modern-js/plugin").PluginOptions | undefined) => import("@modern-js/plugin").AsyncPlugin<Partial<import("@modern-js/plugin").Progresses2Threads<{
|
|
60
64
|
config: ParallelWorkflow<void, unknown>;
|
|
61
65
|
resolvedConfig: AsyncWaterfall<{
|
|
@@ -69,8 +73,10 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
|
|
|
69
73
|
watchFiles: ParallelWorkflow<void, unknown>;
|
|
70
74
|
fileChange: AsyncWorkflow<{
|
|
71
75
|
filename: string;
|
|
76
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
72
77
|
}, void>;
|
|
73
78
|
beforeExit: AsyncWorkflow<void, void>;
|
|
79
|
+
beforeRestart: AsyncWorkflow<void, void>;
|
|
74
80
|
} & import("@modern-js/plugin").ClearDraftProgress<Hooks>>>>, registerHook: (newShape: Partial<Hooks>) => void, mountHook: () => Progresses2Runners<{
|
|
75
81
|
config: ParallelWorkflow<void, unknown>;
|
|
76
82
|
resolvedConfig: AsyncWaterfall<{
|
|
@@ -84,22 +90,31 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
|
|
|
84
90
|
watchFiles: ParallelWorkflow<void, unknown>;
|
|
85
91
|
fileChange: AsyncWorkflow<{
|
|
86
92
|
filename: string;
|
|
93
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
87
94
|
}, void>;
|
|
88
95
|
beforeExit: AsyncWorkflow<void, void>;
|
|
96
|
+
beforeRestart: AsyncWorkflow<void, void>;
|
|
89
97
|
} & import("@modern-js/plugin").ClearDraftProgress<Hooks>>;
|
|
90
98
|
export declare const usePlugins: (plugins: string[]) => void;
|
|
91
|
-
export {
|
|
92
|
-
export type { NormalizedConfig, IAppContext
|
|
93
|
-
declare const initAppDir: () => Promise<string>;
|
|
99
|
+
export { AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
|
|
100
|
+
export type { NormalizedConfig, IAppContext };
|
|
101
|
+
declare const initAppDir: (cwd?: string | undefined) => Promise<string>;
|
|
94
102
|
export interface CoreOptions {
|
|
95
103
|
configFile?: string;
|
|
104
|
+
packageJsonConfig?: string;
|
|
96
105
|
plugins?: typeof INTERNAL_PLUGINS;
|
|
97
|
-
beforeUsePlugins
|
|
106
|
+
beforeUsePlugins?: (plugins: any, config: any) => {
|
|
98
107
|
cli: any;
|
|
99
108
|
cliPath: any;
|
|
100
109
|
server: any;
|
|
101
110
|
serverPath: any;
|
|
102
111
|
}[];
|
|
112
|
+
options?: {
|
|
113
|
+
srcDir?: string;
|
|
114
|
+
distDir?: string;
|
|
115
|
+
sharedDir?: string;
|
|
116
|
+
internalDir?: string;
|
|
117
|
+
};
|
|
103
118
|
}
|
|
104
119
|
export declare const cli: {
|
|
105
120
|
init: (argv?: string[], options?: CoreOptions | undefined) => Promise<{
|
|
@@ -110,4 +125,4 @@ export declare const cli: {
|
|
|
110
125
|
run: (argv: string[], options?: CoreOptions | undefined) => Promise<void>;
|
|
111
126
|
restart: () => Promise<void>;
|
|
112
127
|
};
|
|
113
|
-
export {
|
|
128
|
+
export { initAppDir, initAppContext };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import chokidar from 'chokidar';
|
|
1
2
|
import { LoadedConfig } from './config';
|
|
2
3
|
import { HooksRunner } from '.';
|
|
3
|
-
export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, configDir: string | undefined, hooksRunner: HooksRunner, argv: string[]) => Promise<
|
|
4
|
+
export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, configDir: string | undefined, hooksRunner: HooksRunner, argv: string[]) => Promise<chokidar.FSWatcher | undefined>;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
1
2
|
export interface PluginConfigItem {
|
|
2
3
|
cli?: string;
|
|
3
4
|
server?: string;
|
|
4
5
|
}
|
|
5
6
|
export declare type PluginConfig = Array<PluginConfigItem>;
|
|
7
|
+
export declare function getAppPlugins(appDirectory: string, pluginConfig: PluginConfig, internalPlugins?: typeof INTERNAL_PLUGINS): {
|
|
8
|
+
cli?: string | undefined;
|
|
9
|
+
server?: string | undefined;
|
|
10
|
+
}[];
|
|
6
11
|
/**
|
|
7
12
|
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
8
13
|
* @param appDirectory - Application root directory.
|
|
@@ -18,6 +23,8 @@ export declare const loadPlugins: (appDirectory: string, pluginConfig: PluginCon
|
|
|
18
23
|
} | undefined) => {
|
|
19
24
|
cli: any;
|
|
20
25
|
cliPath: string | undefined;
|
|
21
|
-
server:
|
|
26
|
+
server: "" | {
|
|
27
|
+
pluginPath: string;
|
|
28
|
+
} | undefined;
|
|
22
29
|
serverPath: string | undefined;
|
|
23
30
|
}[];
|
package/jest.config.js
ADDED
package/modern.config.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.4.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -20,12 +20,16 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"node": {
|
|
23
|
+
"jsnext:source": "./src/index.ts",
|
|
23
24
|
"import": "./dist/js/modern/index.js",
|
|
24
25
|
"require": "./dist/js/node/index.js"
|
|
25
26
|
},
|
|
26
27
|
"default": "./dist/js/treeshaking/index.js"
|
|
27
28
|
},
|
|
28
|
-
"./bin":
|
|
29
|
+
"./bin": {
|
|
30
|
+
"jsnext:source": "./src/cli.ts",
|
|
31
|
+
"default": "./bin/modern-js.js"
|
|
32
|
+
}
|
|
29
33
|
},
|
|
30
34
|
"typesVersions": {
|
|
31
35
|
"*": {
|
|
@@ -38,9 +42,9 @@
|
|
|
38
42
|
"dependencies": {
|
|
39
43
|
"@babel/code-frame": "^7.14.5",
|
|
40
44
|
"@babel/runtime": "^7",
|
|
41
|
-
"@modern-js/load-config": "^1.
|
|
42
|
-
"@modern-js/plugin": "^1.1
|
|
43
|
-
"@modern-js/utils": "^1.
|
|
45
|
+
"@modern-js/load-config": "^1.2.1",
|
|
46
|
+
"@modern-js/plugin": "^1.2.1",
|
|
47
|
+
"@modern-js/utils": "^1.3.0",
|
|
44
48
|
"address": "^1.1.2",
|
|
45
49
|
"ajv": "^8.6.2",
|
|
46
50
|
"ajv-keywords": "^5.0.0",
|
|
@@ -56,8 +60,9 @@
|
|
|
56
60
|
"v8-compile-cache": "^2.3.0"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
|
63
|
+
"btsm": "2.2.2",
|
|
59
64
|
"@types/babel__code-frame": "^7.0.3",
|
|
60
|
-
"@modern-js/types": "^1.
|
|
65
|
+
"@modern-js/types": "^1.3.0",
|
|
61
66
|
"@types/jest": "^26",
|
|
62
67
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
63
68
|
"@types/lodash.mergewith": "^4.6.6",
|
|
@@ -66,8 +71,9 @@
|
|
|
66
71
|
"@types/react-dom": "^17",
|
|
67
72
|
"@types/signale": "^1.4.2",
|
|
68
73
|
"typescript": "^4",
|
|
69
|
-
"
|
|
70
|
-
"@
|
|
74
|
+
"jest": "^27",
|
|
75
|
+
"@scripts/build": "0.0.0",
|
|
76
|
+
"@scripts/jest-config": "0.0.0"
|
|
71
77
|
},
|
|
72
78
|
"sideEffects": false,
|
|
73
79
|
"modernConfig": {
|
|
@@ -77,13 +83,14 @@
|
|
|
77
83
|
},
|
|
78
84
|
"publishConfig": {
|
|
79
85
|
"registry": "https://registry.npmjs.org/",
|
|
80
|
-
"access": "public"
|
|
86
|
+
"access": "public",
|
|
87
|
+
"types": "./dist/types/index.d.ts"
|
|
81
88
|
},
|
|
82
89
|
"scripts": {
|
|
83
90
|
"new": "modern new",
|
|
84
91
|
"build": "modern build",
|
|
85
92
|
"dev": "modern build --watch",
|
|
86
|
-
"test": "
|
|
93
|
+
"test": "jest"
|
|
87
94
|
},
|
|
88
95
|
"readme": "\n<p align=\"center\">\n <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>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
89
96
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { spawnSync } from 'child_process';
|
|
3
|
+
|
|
4
|
+
const kPackageDir = path.resolve(__dirname, '..');
|
|
5
|
+
|
|
6
|
+
describe('jsnext:source', () => {
|
|
7
|
+
test('process exit status is 0', () => {
|
|
8
|
+
const { status, stdout, stderr } = spawnSync(
|
|
9
|
+
process.execPath,
|
|
10
|
+
['--conditions=jsnext:source', '-r', 'btsm', 'src/cli.ts'],
|
|
11
|
+
{
|
|
12
|
+
cwd: kPackageDir,
|
|
13
|
+
encoding: 'utf-8',
|
|
14
|
+
},
|
|
15
|
+
);
|
|
16
|
+
expect(stdout).toBe('');
|
|
17
|
+
expect(stderr.startsWith('Usage: modern <command> [options]')).toBe(true);
|
|
18
|
+
expect(status).toBe(1);
|
|
19
|
+
});
|
|
20
|
+
});
|