@modern-js/core 1.3.0 → 1.4.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/CHANGELOG.md +56 -0
- package/dist/js/modern/config/index.js +9 -3
- package/dist/js/modern/context.js +29 -16
- package/dist/js/modern/index.js +18 -8
- package/dist/js/modern/initWatcher.js +19 -3
- package/dist/js/modern/loadPlugins.js +5 -4
- package/dist/js/node/config/index.js +9 -3
- package/dist/js/node/context.js +29 -16
- package/dist/js/node/index.js +27 -35
- package/dist/js/node/initWatcher.js +18 -2
- package/dist/js/node/loadPlugins.js +5 -4
- package/dist/types/config/index.d.ts +19 -13
- package/dist/types/context.d.ts +6 -1
- package/dist/types/index.d.ts +19 -5
- package/dist/types/initWatcher.d.ts +2 -1
- package/dist/types/loadPlugins.d.ts +3 -1
- package/package.json +6 -7
- package/tests/config.test.ts +94 -0
- package/tests/context.test.ts +42 -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/loadPlugin.test.ts +0 -1
- package/src/cli.ts +0 -36
- package/src/config/defaults.ts +0 -101
- package/src/config/index.ts +0 -302
- 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 -284
- package/src/initWatcher.ts +0 -77
- package/src/loadEnv.ts +0 -23
- package/src/loadPlugins.ts +0 -108
- package/src/types.d.ts +0 -0
- package/src/utils/commander.ts +0 -22
- package/src/utils/repeatKeyWarning.ts +0 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 53aca274: modify garfish-plugin config type
|
|
8
|
+
- 78279953: compiler entry bug fix and dev build console
|
|
9
|
+
- e116ace5: fix: coreOptions types
|
|
10
|
+
- 4d72edea: support dev compiler by entry
|
|
11
|
+
- Updated dependencies [78279953]
|
|
12
|
+
- Updated dependencies [4d72edea]
|
|
13
|
+
- @modern-js/utils@1.3.1
|
|
14
|
+
|
|
15
|
+
## 1.4.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- bada2879: refactor plugin-garfish:
|
|
20
|
+
- change @modern-js/plugin-micro-frontend => @modern-js/plugin-garfish
|
|
21
|
+
- remove disableCustomerRouter logic
|
|
22
|
+
- adding unit test
|
|
23
|
+
- fix plugin-garfish type error
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- d9cc5ea9: support resatrt options transfer
|
|
28
|
+
- bd819a8d: fix: file route changed not trigger hot reload
|
|
29
|
+
- d099e5c5: fix error when modify modern.config.js
|
|
30
|
+
- 24f616ca: feat: support custom meta info
|
|
31
|
+
- Updated dependencies [ec4dbffb]
|
|
32
|
+
- Updated dependencies [d099e5c5]
|
|
33
|
+
- Updated dependencies [bada2879]
|
|
34
|
+
- Updated dependencies [24f616ca]
|
|
35
|
+
- Updated dependencies [bd819a8d]
|
|
36
|
+
- @modern-js/utils@1.3.0
|
|
37
|
+
|
|
38
|
+
## 1.3.2
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- 83166714: change .npmignore
|
|
43
|
+
- c3de9882: fix: internalDirectory path
|
|
44
|
+
- 33ff48af: feat: extend CoreOptions
|
|
45
|
+
- Updated dependencies [83166714]
|
|
46
|
+
- @modern-js/load-config@1.2.1
|
|
47
|
+
- @modern-js/plugin@1.2.1
|
|
48
|
+
- @modern-js/utils@1.2.2
|
|
49
|
+
|
|
50
|
+
## 1.3.1
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 4584cc04: export DeployConfig interface
|
|
55
|
+
- 7c19fd94: use existing port number for AppContext when dev server is restarted
|
|
56
|
+
- Updated dependencies [823809c6]
|
|
57
|
+
- @modern-js/utils@1.2.1
|
|
58
|
+
|
|
3
59
|
## 1.3.0
|
|
4
60
|
|
|
5
61
|
### Minor Changes
|
|
@@ -45,7 +45,7 @@ const showAdditionalPropertiesError = error => {
|
|
|
45
45
|
/* eslint-disable max-statements, max-params */
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
export const resolveConfig = async (loaded, configs, schemas,
|
|
48
|
+
export const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv) => {
|
|
49
49
|
var _validate$errors;
|
|
50
50
|
|
|
51
51
|
const {
|
|
@@ -95,8 +95,14 @@ export const resolveConfig = async (loaded, configs, schemas, isRestart, argv) =
|
|
|
95
95
|
const resolved = mergeConfig([defaults, ...configs, userConfig]);
|
|
96
96
|
resolved._raw = loaded.config;
|
|
97
97
|
|
|
98
|
-
if (isDev() && argv[0] === 'dev'
|
|
99
|
-
|
|
98
|
+
if (isDev() && argv[0] === 'dev') {
|
|
99
|
+
if (restartWithExistingPort > 0) {
|
|
100
|
+
// dev server is restarted, should use existing port number
|
|
101
|
+
resolved.server.port = restartWithExistingPort;
|
|
102
|
+
} else {
|
|
103
|
+
// get port for new dev server
|
|
104
|
+
resolved.server.port = await getPort(resolved.server.port);
|
|
105
|
+
}
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
debug('resolved %o', resolved);
|
|
@@ -7,19 +7,32 @@ export const ResolvedConfigContext = createContext({});
|
|
|
7
7
|
export const useAppContext = () => AppContext.use().value;
|
|
8
8
|
export const useConfigContext = () => ConfigContext.use().value;
|
|
9
9
|
export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
10
|
-
export const initAppContext = (appDirectory, plugins, configFile) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
export const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
11
|
+
const {
|
|
12
|
+
metaName = 'modern-js',
|
|
13
|
+
srcDir = 'src',
|
|
14
|
+
distDir = '',
|
|
15
|
+
sharedDir = 'shared'
|
|
16
|
+
} = options || {};
|
|
17
|
+
return {
|
|
18
|
+
metaName,
|
|
19
|
+
appDirectory,
|
|
20
|
+
configFile,
|
|
21
|
+
ip: address.ip(),
|
|
22
|
+
port: 0,
|
|
23
|
+
packageName: require(path.resolve(appDirectory, './package.json')).name,
|
|
24
|
+
srcDirectory: path.resolve(appDirectory, srcDir),
|
|
25
|
+
distDirectory: distDir,
|
|
26
|
+
sharedDirectory: path.resolve(appDirectory, sharedDir),
|
|
27
|
+
nodeModulesDirectory: path.resolve(appDirectory, './node_modules'),
|
|
28
|
+
internalDirectory: path.resolve(appDirectory, `./node_modules/.${metaName}`),
|
|
29
|
+
plugins,
|
|
30
|
+
htmlTemplates: {},
|
|
31
|
+
serverRoutes: [],
|
|
32
|
+
entrypoints: [],
|
|
33
|
+
checkedEntries: [],
|
|
34
|
+
existSrc: true,
|
|
35
|
+
internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
|
|
36
|
+
internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
|
|
37
|
+
};
|
|
38
|
+
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -9,12 +9,12 @@ import { compatRequire, pkgUp, ensureAbsolutePath, logger } from '@modern-js/uti
|
|
|
9
9
|
import { createAsyncManager, createAsyncWorkflow, createParallelWorkflow, createAsyncWaterfall } from '@modern-js/plugin';
|
|
10
10
|
import { enable } from '@modern-js/plugin/node';
|
|
11
11
|
import { program } from "./utils/commander";
|
|
12
|
-
import { resolveConfig,
|
|
12
|
+
import { resolveConfig, loadUserConfig } from "./config";
|
|
13
13
|
import { loadPlugins } from "./loadPlugins";
|
|
14
14
|
import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from "./context";
|
|
15
15
|
import { initWatcher } from "./initWatcher";
|
|
16
16
|
import { loadEnv } from "./loadEnv";
|
|
17
|
-
export
|
|
17
|
+
export * from "./config";
|
|
18
18
|
export * from '@modern-js/plugin';
|
|
19
19
|
export * from '@modern-js/plugin/node';
|
|
20
20
|
program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
@@ -28,7 +28,9 @@ const hooksMap = {
|
|
|
28
28
|
watchFiles: createParallelWorkflow(),
|
|
29
29
|
fileChange: createAsyncWorkflow(),
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
31
|
-
beforeExit: createAsyncWorkflow()
|
|
31
|
+
beforeExit: createAsyncWorkflow(),
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
33
|
+
beforeRestart: createAsyncWorkflow()
|
|
32
34
|
};
|
|
33
35
|
export const manager = createAsyncManager(hooksMap);
|
|
34
36
|
export const {
|
|
@@ -37,7 +39,7 @@ export const {
|
|
|
37
39
|
useRunner: mountHook
|
|
38
40
|
} = manager;
|
|
39
41
|
export const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin(compatRequire(require.resolve(plugin))));
|
|
40
|
-
export {
|
|
42
|
+
export { AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
|
|
41
43
|
|
|
42
44
|
const initAppDir = async cwd => {
|
|
43
45
|
if (!cwd) {
|
|
@@ -59,10 +61,13 @@ const initAppDir = async cwd => {
|
|
|
59
61
|
const createCli = () => {
|
|
60
62
|
let hooksRunner;
|
|
61
63
|
let isRestart = false;
|
|
64
|
+
let restartWithExistingPort = 0;
|
|
65
|
+
let restartOptions; // eslint-disable-next-line max-statements
|
|
62
66
|
|
|
63
67
|
const init = async (argv = [], options) => {
|
|
64
68
|
enable();
|
|
65
69
|
manager.clear();
|
|
70
|
+
restartOptions = options;
|
|
66
71
|
const appDirectory = await initAppDir();
|
|
67
72
|
loadEnv(appDirectory);
|
|
68
73
|
const loaded = await loadUserConfig(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
|
|
@@ -73,7 +78,7 @@ const createCli = () => {
|
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
76
|
-
const appContext = initAppContext(appDirectory, plugins, loaded.filePath);
|
|
81
|
+
const appContext = initAppContext(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
|
|
77
82
|
manager.run(() => {
|
|
78
83
|
ConfigContext.set(loaded.config);
|
|
79
84
|
AppContext.set(appContext);
|
|
@@ -95,7 +100,7 @@ const createCli = () => {
|
|
|
95
100
|
});
|
|
96
101
|
const extraConfigs = await hooksRunner.config();
|
|
97
102
|
const extraSchemas = await hooksRunner.validateSchema();
|
|
98
|
-
const config = await resolveConfig(loaded, extraConfigs, extraSchemas,
|
|
103
|
+
const config = await resolveConfig(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv);
|
|
99
104
|
const {
|
|
100
105
|
resolved
|
|
101
106
|
} = await hooksRunner.resolvedConfig({
|
|
@@ -132,12 +137,17 @@ const createCli = () => {
|
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
async function restart() {
|
|
140
|
+
var _AppContext$use$value, _AppContext$use$value2;
|
|
141
|
+
|
|
135
142
|
isRestart = true;
|
|
143
|
+
restartWithExistingPort = isRestart ? (_AppContext$use$value = (_AppContext$use$value2 = 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;
|
|
136
144
|
logger.info('Restart...\n');
|
|
137
145
|
let hasGetError = false;
|
|
146
|
+
const runner = manager.useRunner();
|
|
147
|
+
await runner.beforeRestart();
|
|
138
148
|
|
|
139
149
|
try {
|
|
140
|
-
await init(process.argv.slice(2));
|
|
150
|
+
await init(process.argv.slice(2), restartOptions);
|
|
141
151
|
} catch (err) {
|
|
142
152
|
console.error(err);
|
|
143
153
|
hasGetError = true;
|
|
@@ -156,4 +166,4 @@ const createCli = () => {
|
|
|
156
166
|
};
|
|
157
167
|
|
|
158
168
|
export const cli = createCli();
|
|
159
|
-
export {
|
|
169
|
+
export { initAppDir, initAppContext };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { isDev, createDebugger } from '@modern-js/utils';
|
|
4
|
+
import { isDev, createDebugger, isTest } from '@modern-js/utils';
|
|
5
5
|
import chokidar from 'chokidar';
|
|
6
6
|
const debug = createDebugger('watch-files');
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ const md5 = data => crypto.createHash('md5').update(data).digest('hex');
|
|
|
10
10
|
const hashMap = new Map();
|
|
11
11
|
export const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
|
|
12
12
|
// only add fs watcher on dev mode.
|
|
13
|
-
if (isDev() && argv[0] === 'dev') {
|
|
13
|
+
if ((isDev() || isTest()) && argv[0] === 'dev') {
|
|
14
14
|
const extraFiles = await hooksRunner.watchFiles();
|
|
15
15
|
const configPath = path.join(appDirectory, configDir);
|
|
16
16
|
const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
|
|
@@ -28,19 +28,35 @@ export const initWatcher = async (loaded, appDirectory, configDir, hooksRunner,
|
|
|
28
28
|
debug(`file change: %s`, changed);
|
|
29
29
|
hashMap.set(changed, currentHash);
|
|
30
30
|
hooksRunner.fileChange({
|
|
31
|
-
filename: changed
|
|
31
|
+
filename: changed,
|
|
32
|
+
eventType: 'change'
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
});
|
|
36
|
+
watcher.on('add', name => {
|
|
37
|
+
debug(`add file: %s`, name);
|
|
38
|
+
const currentHash = md5(fs.readFileSync(path.join(appDirectory, name), 'utf8'));
|
|
39
|
+
hashMap.set(name, currentHash);
|
|
40
|
+
hooksRunner.fileChange({
|
|
41
|
+
filename: name,
|
|
42
|
+
eventType: 'add'
|
|
43
|
+
});
|
|
44
|
+
});
|
|
35
45
|
watcher.on('unlink', name => {
|
|
36
46
|
debug(`remove file: %s`, name);
|
|
37
47
|
|
|
38
48
|
if (hashMap.has(name)) {
|
|
39
49
|
hashMap.delete(name);
|
|
40
50
|
}
|
|
51
|
+
|
|
52
|
+
hooksRunner.fileChange({
|
|
53
|
+
filename: name,
|
|
54
|
+
eventType: 'unlink'
|
|
55
|
+
});
|
|
41
56
|
});
|
|
42
57
|
watcher.on('error', err => {
|
|
43
58
|
throw err;
|
|
44
59
|
});
|
|
60
|
+
return watcher;
|
|
45
61
|
}
|
|
46
62
|
};
|
|
@@ -81,12 +81,13 @@ export const loadPlugins = (appDirectory, pluginConfig, internalPlugins) => {
|
|
|
81
81
|
|
|
82
82
|
const cliPlugin = cli && _objectSpread(_objectSpread({}, compatRequire(cli)), {}, {
|
|
83
83
|
pluginPath: cli
|
|
84
|
-
});
|
|
84
|
+
}); // server plugin should be required by server
|
|
85
85
|
|
|
86
|
-
const serverPlugin = server && _objectSpread(_objectSpread({}, compatRequire(server)), {}, {
|
|
87
|
-
pluginPath: server
|
|
88
|
-
});
|
|
89
86
|
|
|
87
|
+
const serverPlugin = server && {
|
|
88
|
+
// ...compatRequire(server),
|
|
89
|
+
pluginPath: server
|
|
90
|
+
};
|
|
90
91
|
return {
|
|
91
92
|
cli: cliPlugin,
|
|
92
93
|
cliPath: typeof plugin === 'string' ? plugin : plugin.cli,
|
|
@@ -83,7 +83,7 @@ const showAdditionalPropertiesError = error => {
|
|
|
83
83
|
/* eslint-disable max-statements, max-params */
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
const resolveConfig = async (loaded, configs, schemas,
|
|
86
|
+
const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv) => {
|
|
87
87
|
var _validate$errors;
|
|
88
88
|
|
|
89
89
|
const {
|
|
@@ -136,8 +136,14 @@ const resolveConfig = async (loaded, configs, schemas, isRestart, argv) => {
|
|
|
136
136
|
const resolved = (0, _mergeConfig.mergeConfig)([_defaults.defaults, ...configs, userConfig]);
|
|
137
137
|
resolved._raw = loaded.config;
|
|
138
138
|
|
|
139
|
-
if ((0, _utils.isDev)() && argv[0] === 'dev'
|
|
140
|
-
|
|
139
|
+
if ((0, _utils.isDev)() && argv[0] === 'dev') {
|
|
140
|
+
if (restartWithExistingPort > 0) {
|
|
141
|
+
// dev server is restarted, should use existing port number
|
|
142
|
+
resolved.server.port = restartWithExistingPort;
|
|
143
|
+
} else {
|
|
144
|
+
// get port for new dev server
|
|
145
|
+
resolved.server.port = await (0, _utils.getPort)(resolved.server.port);
|
|
146
|
+
}
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
debug('resolved %o', resolved);
|
package/dist/js/node/context.js
CHANGED
|
@@ -32,21 +32,34 @@ const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
|
32
32
|
|
|
33
33
|
exports.useResolvedConfigContext = useResolvedConfigContext;
|
|
34
34
|
|
|
35
|
-
const initAppContext = (appDirectory, plugins, configFile) =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
36
|
+
const {
|
|
37
|
+
metaName = 'modern-js',
|
|
38
|
+
srcDir = 'src',
|
|
39
|
+
distDir = '',
|
|
40
|
+
sharedDir = 'shared'
|
|
41
|
+
} = options || {};
|
|
42
|
+
return {
|
|
43
|
+
metaName,
|
|
44
|
+
appDirectory,
|
|
45
|
+
configFile,
|
|
46
|
+
ip: _address.default.ip(),
|
|
47
|
+
port: 0,
|
|
48
|
+
packageName: require(_path.default.resolve(appDirectory, './package.json')).name,
|
|
49
|
+
srcDirectory: _path.default.resolve(appDirectory, srcDir),
|
|
50
|
+
distDirectory: distDir,
|
|
51
|
+
sharedDirectory: _path.default.resolve(appDirectory, sharedDir),
|
|
52
|
+
nodeModulesDirectory: _path.default.resolve(appDirectory, './node_modules'),
|
|
53
|
+
internalDirectory: _path.default.resolve(appDirectory, `./node_modules/.${metaName}`),
|
|
54
|
+
plugins,
|
|
55
|
+
htmlTemplates: {},
|
|
56
|
+
serverRoutes: [],
|
|
57
|
+
entrypoints: [],
|
|
58
|
+
checkedEntries: [],
|
|
59
|
+
existSrc: true,
|
|
60
|
+
internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
|
|
61
|
+
internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
|
|
62
|
+
};
|
|
63
|
+
};
|
|
51
64
|
|
|
52
65
|
exports.initAppContext = initAppContext;
|
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;
|
|
@@ -198,10 +182,13 @@ exports.initAppDir = initAppDir;
|
|
|
198
182
|
const createCli = () => {
|
|
199
183
|
let hooksRunner;
|
|
200
184
|
let isRestart = false;
|
|
185
|
+
let restartWithExistingPort = 0;
|
|
186
|
+
let restartOptions; // eslint-disable-next-line max-statements
|
|
201
187
|
|
|
202
188
|
const init = async (argv = [], options) => {
|
|
203
189
|
(0, _node.enable)();
|
|
204
190
|
manager.clear();
|
|
191
|
+
restartOptions = options;
|
|
205
192
|
const appDirectory = await initAppDir();
|
|
206
193
|
(0, _loadEnv.loadEnv)(appDirectory);
|
|
207
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);
|
|
@@ -212,7 +199,7 @@ const createCli = () => {
|
|
|
212
199
|
}
|
|
213
200
|
|
|
214
201
|
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
215
|
-
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);
|
|
216
203
|
manager.run(() => {
|
|
217
204
|
_context.ConfigContext.set(loaded.config);
|
|
218
205
|
|
|
@@ -235,7 +222,7 @@ const createCli = () => {
|
|
|
235
222
|
});
|
|
236
223
|
const extraConfigs = await hooksRunner.config();
|
|
237
224
|
const extraSchemas = await hooksRunner.validateSchema();
|
|
238
|
-
const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas,
|
|
225
|
+
const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv);
|
|
239
226
|
const {
|
|
240
227
|
resolved
|
|
241
228
|
} = await hooksRunner.resolvedConfig({
|
|
@@ -274,14 +261,19 @@ const createCli = () => {
|
|
|
274
261
|
}
|
|
275
262
|
|
|
276
263
|
async function restart() {
|
|
264
|
+
var _AppContext$use$value, _AppContext$use$value2;
|
|
265
|
+
|
|
277
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;
|
|
278
268
|
|
|
279
269
|
_utils.logger.info('Restart...\n');
|
|
280
270
|
|
|
281
271
|
let hasGetError = false;
|
|
272
|
+
const runner = manager.useRunner();
|
|
273
|
+
await runner.beforeRestart();
|
|
282
274
|
|
|
283
275
|
try {
|
|
284
|
-
await init(process.argv.slice(2));
|
|
276
|
+
await init(process.argv.slice(2), restartOptions);
|
|
285
277
|
} catch (err) {
|
|
286
278
|
console.error(err);
|
|
287
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
|
|
|
@@ -91,12 +91,13 @@ const loadPlugins = (appDirectory, pluginConfig, internalPlugins) => {
|
|
|
91
91
|
|
|
92
92
|
const cliPlugin = cli && _objectSpread(_objectSpread({}, (0, _utils.compatRequire)(cli)), {}, {
|
|
93
93
|
pluginPath: cli
|
|
94
|
-
});
|
|
94
|
+
}); // server plugin should be required by server
|
|
95
95
|
|
|
96
|
-
const serverPlugin = server && _objectSpread(_objectSpread({}, (0, _utils.compatRequire)(server)), {}, {
|
|
97
|
-
pluginPath: server
|
|
98
|
-
});
|
|
99
96
|
|
|
97
|
+
const serverPlugin = server && {
|
|
98
|
+
// ...compatRequire(server),
|
|
99
|
+
pluginPath: server
|
|
100
|
+
};
|
|
100
101
|
return {
|
|
101
102
|
cli: cliPlugin,
|
|
102
103
|
cliPath: typeof plugin === 'string' ? plugin : plugin.cli,
|
|
@@ -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?: string;
|
|
87
|
+
}
|
|
88
|
+
interface DeployConfig {
|
|
89
|
+
microFrontend?: false | 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[];
|
|
@@ -123,4 +128,5 @@ export interface LoadedConfig {
|
|
|
123
128
|
}
|
|
124
129
|
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
125
130
|
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
|
|
126
|
-
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[],
|
|
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;
|