@modern-js/core 1.3.2 → 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 +23 -0
- package/dist/js/modern/context.js +8 -4
- package/dist/js/modern/index.js +8 -2
- package/dist/js/modern/initWatcher.js +19 -3
- package/dist/js/modern/loadPlugins.js +5 -4
- package/dist/js/node/context.js +8 -4
- package/dist/js/node/index.js +8 -2
- package/dist/js/node/initWatcher.js +18 -2
- package/dist/js/node/loadPlugins.js +5 -4
- package/dist/types/config/index.d.ts +6 -1
- package/dist/types/context.d.ts +1 -1
- package/dist/types/index.d.ts +9 -0
- package/dist/types/initWatcher.d.ts +2 -1
- package/dist/types/loadPlugins.d.ts +3 -1
- package/package.json +3 -3
- package/tests/context.test.ts +10 -5
- package/tests/initWatcher.test.ts +63 -0
- package/tests/loadPlugin.test.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bada2879: refactor plugin-garfish:
|
|
8
|
+
- change @modern-js/plugin-micro-frontend => @modern-js/plugin-garfish
|
|
9
|
+
- remove disableCustomerRouter logic
|
|
10
|
+
- adding unit test
|
|
11
|
+
- fix plugin-garfish type error
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- d9cc5ea9: support resatrt options transfer
|
|
16
|
+
- bd819a8d: fix: file route changed not trigger hot reload
|
|
17
|
+
- d099e5c5: fix error when modify modern.config.js
|
|
18
|
+
- 24f616ca: feat: support custom meta info
|
|
19
|
+
- Updated dependencies [ec4dbffb]
|
|
20
|
+
- Updated dependencies [d099e5c5]
|
|
21
|
+
- Updated dependencies [bada2879]
|
|
22
|
+
- Updated dependencies [24f616ca]
|
|
23
|
+
- Updated dependencies [bd819a8d]
|
|
24
|
+
- @modern-js/utils@1.3.0
|
|
25
|
+
|
|
3
26
|
## 1.3.2
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -9,12 +9,13 @@ export const useConfigContext = () => ConfigContext.use().value;
|
|
|
9
9
|
export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
10
10
|
export const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
11
11
|
const {
|
|
12
|
+
metaName = 'modern-js',
|
|
12
13
|
srcDir = 'src',
|
|
13
14
|
distDir = '',
|
|
14
|
-
sharedDir = 'shared'
|
|
15
|
-
internalDir = '.modern-js'
|
|
15
|
+
sharedDir = 'shared'
|
|
16
16
|
} = options || {};
|
|
17
17
|
return {
|
|
18
|
+
metaName,
|
|
18
19
|
appDirectory,
|
|
19
20
|
configFile,
|
|
20
21
|
ip: address.ip(),
|
|
@@ -24,10 +25,13 @@ export const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
|
24
25
|
distDirectory: distDir,
|
|
25
26
|
sharedDirectory: path.resolve(appDirectory, sharedDir),
|
|
26
27
|
nodeModulesDirectory: path.resolve(appDirectory, './node_modules'),
|
|
27
|
-
internalDirectory: path.resolve(appDirectory, `./node_modules
|
|
28
|
+
internalDirectory: path.resolve(appDirectory, `./node_modules/.${metaName}`),
|
|
28
29
|
plugins,
|
|
29
30
|
htmlTemplates: {},
|
|
30
31
|
serverRoutes: [],
|
|
31
|
-
entrypoints: []
|
|
32
|
+
entrypoints: [],
|
|
33
|
+
existSrc: true,
|
|
34
|
+
internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
|
|
35
|
+
internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
|
|
32
36
|
};
|
|
33
37
|
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -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 {
|
|
@@ -60,10 +62,12 @@ const createCli = () => {
|
|
|
60
62
|
let hooksRunner;
|
|
61
63
|
let isRestart = false;
|
|
62
64
|
let restartWithExistingPort = 0;
|
|
65
|
+
let restartOptions;
|
|
63
66
|
|
|
64
67
|
const init = async (argv = [], options) => {
|
|
65
68
|
enable();
|
|
66
69
|
manager.clear();
|
|
70
|
+
restartOptions = options;
|
|
67
71
|
const appDirectory = await initAppDir();
|
|
68
72
|
loadEnv(appDirectory);
|
|
69
73
|
const loaded = await loadUserConfig(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
|
|
@@ -139,9 +143,11 @@ const createCli = () => {
|
|
|
139
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;
|
|
140
144
|
logger.info('Restart...\n');
|
|
141
145
|
let hasGetError = false;
|
|
146
|
+
const runner = manager.useRunner();
|
|
147
|
+
await runner.beforeRestart();
|
|
142
148
|
|
|
143
149
|
try {
|
|
144
|
-
await init(process.argv.slice(2));
|
|
150
|
+
await init(process.argv.slice(2), restartOptions);
|
|
145
151
|
} catch (err) {
|
|
146
152
|
console.error(err);
|
|
147
153
|
hasGetError = true;
|
|
@@ -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,
|
package/dist/js/node/context.js
CHANGED
|
@@ -34,12 +34,13 @@ exports.useResolvedConfigContext = useResolvedConfigContext;
|
|
|
34
34
|
|
|
35
35
|
const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
36
36
|
const {
|
|
37
|
+
metaName = 'modern-js',
|
|
37
38
|
srcDir = 'src',
|
|
38
39
|
distDir = '',
|
|
39
|
-
sharedDir = 'shared'
|
|
40
|
-
internalDir = '.modern-js'
|
|
40
|
+
sharedDir = 'shared'
|
|
41
41
|
} = options || {};
|
|
42
42
|
return {
|
|
43
|
+
metaName,
|
|
43
44
|
appDirectory,
|
|
44
45
|
configFile,
|
|
45
46
|
ip: _address.default.ip(),
|
|
@@ -49,11 +50,14 @@ const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
|
49
50
|
distDirectory: distDir,
|
|
50
51
|
sharedDirectory: _path.default.resolve(appDirectory, sharedDir),
|
|
51
52
|
nodeModulesDirectory: _path.default.resolve(appDirectory, './node_modules'),
|
|
52
|
-
internalDirectory: _path.default.resolve(appDirectory, `./node_modules
|
|
53
|
+
internalDirectory: _path.default.resolve(appDirectory, `./node_modules/.${metaName}`),
|
|
53
54
|
plugins,
|
|
54
55
|
htmlTemplates: {},
|
|
55
56
|
serverRoutes: [],
|
|
56
|
-
entrypoints: []
|
|
57
|
+
entrypoints: [],
|
|
58
|
+
existSrc: true,
|
|
59
|
+
internalDirAlias: `@_${metaName.replace(/-/g, '_')}_internal`,
|
|
60
|
+
internalSrcAlias: `@_${metaName.replace(/-/g, '_')}_src`
|
|
57
61
|
};
|
|
58
62
|
};
|
|
59
63
|
|
package/dist/js/node/index.js
CHANGED
|
@@ -141,7 +141,9 @@ const hooksMap = {
|
|
|
141
141
|
watchFiles: (0, _plugin.createParallelWorkflow)(),
|
|
142
142
|
fileChange: (0, _plugin.createAsyncWorkflow)(),
|
|
143
143
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
144
|
-
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)()
|
|
145
147
|
};
|
|
146
148
|
const manager = (0, _plugin.createAsyncManager)(hooksMap);
|
|
147
149
|
exports.manager = manager;
|
|
@@ -181,10 +183,12 @@ const createCli = () => {
|
|
|
181
183
|
let hooksRunner;
|
|
182
184
|
let isRestart = false;
|
|
183
185
|
let restartWithExistingPort = 0;
|
|
186
|
+
let restartOptions;
|
|
184
187
|
|
|
185
188
|
const init = async (argv = [], options) => {
|
|
186
189
|
(0, _node.enable)();
|
|
187
190
|
manager.clear();
|
|
191
|
+
restartOptions = options;
|
|
188
192
|
const appDirectory = await initAppDir();
|
|
189
193
|
(0, _loadEnv.loadEnv)(appDirectory);
|
|
190
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);
|
|
@@ -265,9 +269,11 @@ const createCli = () => {
|
|
|
265
269
|
_utils.logger.info('Restart...\n');
|
|
266
270
|
|
|
267
271
|
let hasGetError = false;
|
|
272
|
+
const runner = manager.useRunner();
|
|
273
|
+
await runner.beforeRestart();
|
|
268
274
|
|
|
269
275
|
try {
|
|
270
|
-
await init(process.argv.slice(2));
|
|
276
|
+
await init(process.argv.slice(2), restartOptions);
|
|
271
277
|
} catch (err) {
|
|
272
278
|
console.error(err);
|
|
273
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,
|
|
@@ -80,8 +80,13 @@ interface DevConfig {
|
|
|
80
80
|
assetPrefix?: string | boolean;
|
|
81
81
|
https?: boolean;
|
|
82
82
|
}
|
|
83
|
+
interface MicroFrontend {
|
|
84
|
+
enableHtmlEntry?: boolean;
|
|
85
|
+
externalBasicLibrary?: boolean;
|
|
86
|
+
moduleApp?: boolean;
|
|
87
|
+
}
|
|
83
88
|
interface DeployConfig {
|
|
84
|
-
microFrontend?: boolean
|
|
89
|
+
microFrontend?: boolean | MicroFrontend;
|
|
85
90
|
domain?: string | Array<string>;
|
|
86
91
|
domainByEntries?: Record<string, string | Array<string>>;
|
|
87
92
|
}
|
package/dist/types/context.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export declare const initAppContext: (appDirectory: string, plugins: Array<{
|
|
|
12
12
|
cli: any;
|
|
13
13
|
server: any;
|
|
14
14
|
}>, configFile: string | false, options?: {
|
|
15
|
+
metaName?: string | undefined;
|
|
15
16
|
srcDir?: string | undefined;
|
|
16
17
|
distDir?: string | undefined;
|
|
17
18
|
sharedDir?: string | undefined;
|
|
18
|
-
internalDir?: string | undefined;
|
|
19
19
|
} | undefined) => IAppContext;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare type HooksRunner = Progresses2Runners<{
|
|
|
21
21
|
watchFiles: ParallelWorkflow<void>;
|
|
22
22
|
fileChange: AsyncWorkflow<{
|
|
23
23
|
filename: string;
|
|
24
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
24
25
|
}, void>;
|
|
25
26
|
beforeExit: AsyncWorkflow<void, void>;
|
|
26
27
|
}>;
|
|
@@ -37,8 +38,10 @@ export declare const manager: import("@modern-js/plugin").AsyncManager<Hooks, {
|
|
|
37
38
|
watchFiles: ParallelWorkflow<void, unknown>;
|
|
38
39
|
fileChange: AsyncWorkflow<{
|
|
39
40
|
filename: string;
|
|
41
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
40
42
|
}, void>;
|
|
41
43
|
beforeExit: AsyncWorkflow<void, void>;
|
|
44
|
+
beforeRestart: AsyncWorkflow<void, void>;
|
|
42
45
|
}>;
|
|
43
46
|
export declare const createPlugin: (initializer: import("@modern-js/plugin").AsyncInitializer<Partial<import("@modern-js/plugin").Progresses2Threads<{
|
|
44
47
|
config: ParallelWorkflow<void, unknown>;
|
|
@@ -53,8 +56,10 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
|
|
|
53
56
|
watchFiles: ParallelWorkflow<void, unknown>;
|
|
54
57
|
fileChange: AsyncWorkflow<{
|
|
55
58
|
filename: string;
|
|
59
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
56
60
|
}, void>;
|
|
57
61
|
beforeExit: AsyncWorkflow<void, void>;
|
|
62
|
+
beforeRestart: AsyncWorkflow<void, void>;
|
|
58
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<{
|
|
59
64
|
config: ParallelWorkflow<void, unknown>;
|
|
60
65
|
resolvedConfig: AsyncWaterfall<{
|
|
@@ -68,8 +73,10 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
|
|
|
68
73
|
watchFiles: ParallelWorkflow<void, unknown>;
|
|
69
74
|
fileChange: AsyncWorkflow<{
|
|
70
75
|
filename: string;
|
|
76
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
71
77
|
}, void>;
|
|
72
78
|
beforeExit: AsyncWorkflow<void, void>;
|
|
79
|
+
beforeRestart: AsyncWorkflow<void, void>;
|
|
73
80
|
} & import("@modern-js/plugin").ClearDraftProgress<Hooks>>>>, registerHook: (newShape: Partial<Hooks>) => void, mountHook: () => Progresses2Runners<{
|
|
74
81
|
config: ParallelWorkflow<void, unknown>;
|
|
75
82
|
resolvedConfig: AsyncWaterfall<{
|
|
@@ -83,8 +90,10 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
|
|
|
83
90
|
watchFiles: ParallelWorkflow<void, unknown>;
|
|
84
91
|
fileChange: AsyncWorkflow<{
|
|
85
92
|
filename: string;
|
|
93
|
+
eventType: 'add' | 'change' | 'unlink';
|
|
86
94
|
}, void>;
|
|
87
95
|
beforeExit: AsyncWorkflow<void, void>;
|
|
96
|
+
beforeRestart: AsyncWorkflow<void, void>;
|
|
88
97
|
} & import("@modern-js/plugin").ClearDraftProgress<Hooks>>;
|
|
89
98
|
export declare const usePlugins: (plugins: string[]) => void;
|
|
90
99
|
export { AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
|
|
@@ -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>;
|
|
@@ -23,6 +23,8 @@ export declare const loadPlugins: (appDirectory: string, pluginConfig: PluginCon
|
|
|
23
23
|
} | undefined) => {
|
|
24
24
|
cli: any;
|
|
25
25
|
cliPath: string | undefined;
|
|
26
|
-
server:
|
|
26
|
+
server: "" | {
|
|
27
|
+
pluginPath: string;
|
|
28
|
+
} | undefined;
|
|
27
29
|
serverPath: string | undefined;
|
|
28
30
|
}[];
|
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",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@babel/runtime": "^7",
|
|
45
45
|
"@modern-js/load-config": "^1.2.1",
|
|
46
46
|
"@modern-js/plugin": "^1.2.1",
|
|
47
|
-
"@modern-js/utils": "^1.
|
|
47
|
+
"@modern-js/utils": "^1.3.0",
|
|
48
48
|
"address": "^1.1.2",
|
|
49
49
|
"ajv": "^8.6.2",
|
|
50
50
|
"ajv-keywords": "^5.0.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"btsm": "2.2.2",
|
|
64
64
|
"@types/babel__code-frame": "^7.0.3",
|
|
65
|
-
"@modern-js/types": "^1.
|
|
65
|
+
"@modern-js/types": "^1.3.0",
|
|
66
66
|
"@types/jest": "^26",
|
|
67
67
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
68
68
|
"@types/lodash.mergewith": "^4.6.6",
|
package/tests/context.test.ts
CHANGED
|
@@ -23,6 +23,10 @@ describe('context', () => {
|
|
|
23
23
|
htmlTemplates: {},
|
|
24
24
|
serverRoutes: [],
|
|
25
25
|
entrypoints: [],
|
|
26
|
+
existSrc: true,
|
|
27
|
+
internalDirAlias: '@_modern_js_internal',
|
|
28
|
+
internalSrcAlias: '@_modern_js_src',
|
|
29
|
+
metaName: 'modern-js',
|
|
26
30
|
});
|
|
27
31
|
});
|
|
28
32
|
|
|
@@ -36,7 +40,7 @@ describe('context', () => {
|
|
|
36
40
|
srcDir: 'source',
|
|
37
41
|
distDir: 'dist',
|
|
38
42
|
sharedDir: 'myShared',
|
|
39
|
-
|
|
43
|
+
metaName: 'jupiter',
|
|
40
44
|
};
|
|
41
45
|
|
|
42
46
|
const appContext = initAppContext(appDirectory, [], false, customOptions);
|
|
@@ -50,14 +54,15 @@ describe('context', () => {
|
|
|
50
54
|
distDirectory: 'dist',
|
|
51
55
|
sharedDirectory: path.resolve(appDirectory, './myShared'),
|
|
52
56
|
nodeModulesDirectory: expect.any(String),
|
|
53
|
-
internalDirectory: path.resolve(
|
|
54
|
-
appDirectory,
|
|
55
|
-
'./node_modules/myInternal',
|
|
56
|
-
),
|
|
57
|
+
internalDirectory: path.resolve(appDirectory, './node_modules/.jupiter'),
|
|
57
58
|
plugins: [],
|
|
58
59
|
htmlTemplates: {},
|
|
59
60
|
serverRoutes: [],
|
|
60
61
|
entrypoints: [],
|
|
62
|
+
existSrc: true,
|
|
63
|
+
internalDirAlias: '@_jupiter_internal',
|
|
64
|
+
internalSrcAlias: '@_jupiter_src',
|
|
65
|
+
metaName: 'jupiter',
|
|
61
66
|
});
|
|
62
67
|
});
|
|
63
68
|
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { fs, wait } from '@modern-js/utils';
|
|
3
|
+
import { initWatcher } from '../src/initWatcher';
|
|
4
|
+
|
|
5
|
+
jest.useRealTimers();
|
|
6
|
+
|
|
7
|
+
const mockAppDirectory = path.join(__dirname, './fixtures/index-test');
|
|
8
|
+
const mockConfigDir = './config';
|
|
9
|
+
const mockSrcDirectory = path.join(mockAppDirectory, './src');
|
|
10
|
+
|
|
11
|
+
describe('initWatcher', () => {
|
|
12
|
+
afterAll(() => {
|
|
13
|
+
const file = path.join(mockSrcDirectory, './index.ts');
|
|
14
|
+
if (fs.existsSync(file)) {
|
|
15
|
+
fs.unlinkSync(file);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('will trigger add event', async () => {
|
|
20
|
+
let triggeredType = '';
|
|
21
|
+
let triggeredFile = '';
|
|
22
|
+
const loaded = {
|
|
23
|
+
filePath: '',
|
|
24
|
+
dependencies: [],
|
|
25
|
+
};
|
|
26
|
+
const hooksRunner = {
|
|
27
|
+
watchFiles: async () => [mockSrcDirectory],
|
|
28
|
+
fileChange: jest.fn(({ filename, eventType }) => {
|
|
29
|
+
triggeredType = eventType;
|
|
30
|
+
triggeredFile = filename;
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (await fs.pathExists(mockSrcDirectory)) {
|
|
35
|
+
await fs.remove(mockSrcDirectory);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const watcher = await initWatcher(
|
|
39
|
+
loaded as any,
|
|
40
|
+
mockAppDirectory,
|
|
41
|
+
mockConfigDir,
|
|
42
|
+
hooksRunner as any,
|
|
43
|
+
['dev'],
|
|
44
|
+
);
|
|
45
|
+
await wait(100);
|
|
46
|
+
|
|
47
|
+
const file = path.join(mockSrcDirectory, './index.ts');
|
|
48
|
+
await fs.outputFile(file, '');
|
|
49
|
+
await wait(100);
|
|
50
|
+
// expect(hooksRunner.fileChange).toBeCalledTimes(1);
|
|
51
|
+
expect(triggeredType).toBe('add');
|
|
52
|
+
expect(file.includes(triggeredFile)).toBeTruthy();
|
|
53
|
+
|
|
54
|
+
await wait(100);
|
|
55
|
+
await fs.remove(file);
|
|
56
|
+
await wait(200);
|
|
57
|
+
expect(hooksRunner.fileChange).toBeCalledTimes(2);
|
|
58
|
+
expect(triggeredType).toBe('unlink');
|
|
59
|
+
expect(file.includes(triggeredFile)).toBeTruthy();
|
|
60
|
+
|
|
61
|
+
watcher?.close();
|
|
62
|
+
});
|
|
63
|
+
});
|