@modern-js/server 1.4.7-canary.2 → 1.4.9-beta.peer.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 +41 -0
- package/dist/js/modern/dev-tools/babel/register.js +1 -0
- package/dist/js/modern/dev-tools/dev-server-plugin.js +2 -5
- package/dist/js/modern/dev-tools/watcher/index.js +1 -2
- package/dist/js/modern/server/dev-server.js +49 -2
- package/dist/js/node/dev-tools/babel/register.js +1 -0
- package/dist/js/node/dev-tools/dev-server-plugin.js +2 -5
- package/dist/js/node/dev-tools/watcher/index.js +1 -3
- package/dist/js/node/server/dev-server.js +49 -2
- package/dist/types/dev-tools/watcher/index.d.ts +2 -2
- package/dist/types/server/dev-server.d.ts +2 -0
- package/jest.config.js +0 -1
- package/package.json +23 -25
- package/tests/.eslintrc.js +0 -6
- package/tests/dev.test.ts +0 -130
- package/tests/fixtures/mock/exist/config/mock/index.ts +0 -11
- package/tests/fixtures/mock/module-error/config/mock/index.ts +0 -1
- package/tests/fixtures/mock/type-error/config/mock/index.ts +0 -3
- package/tests/fixtures/mock/zero/config/mock/index.ts +0 -1
- package/tests/fixtures/pure/config/mock/index.ts +0 -11
- package/tests/fixtures/pure/modern.config.js +0 -5
- package/tests/fixtures/pure/package.json +0 -21
- package/tests/fixtures/pure/src/App.css +0 -119
- package/tests/fixtures/pure/src/App.tsx +0 -43
- package/tests/fixtures/pure/tsconfig.json +0 -12
- package/tests/fixtures/watch/a.ts +0 -3
- package/tests/fixtures/watch/index.ts +0 -5
- package/tests/fixtures/watch/stats.txt +0 -1
- package/tests/helper.ts +0 -3
- package/tests/https.test.ts +0 -17
- package/tests/launch-editor.test.ts +0 -58
- package/tests/mock.test.ts +0 -150
- package/tests/server.test.ts +0 -238
- package/tests/tsconfig.json +0 -12
- package/tests/watcher.test.ts +0 -228
package/.eslintrc.js
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 1.4.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bebb39b6: chore: improve devDependencies and peerDependencies
|
|
8
|
+
- Updated dependencies [bebb39b6]
|
|
9
|
+
- Updated dependencies [afc836f4]
|
|
10
|
+
- Updated dependencies [132f7b53]
|
|
11
|
+
- @modern-js/prod-server@1.0.6
|
|
12
|
+
- @modern-js/server-utils@1.2.2
|
|
13
|
+
- @modern-js/hmr-client@1.2.3
|
|
14
|
+
- @modern-js/utils@1.3.7
|
|
15
|
+
|
|
16
|
+
## 1.4.8
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- a8df060e: support setup dev middleware first step
|
|
21
|
+
- d2d0fa11: fix: missing devServer.proxy typing
|
|
22
|
+
- 6a7acb81: modify devServer type and name
|
|
23
|
+
- Updated dependencies [c2046f37]
|
|
24
|
+
- Updated dependencies [d2d0fa11]
|
|
25
|
+
- @modern-js/utils@1.3.6
|
|
26
|
+
- @modern-js/prod-server@1.0.5
|
|
27
|
+
|
|
28
|
+
## 1.4.7
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- d95f28c3: remove server hook when api only
|
|
33
|
+
- d5bf095a: fix: disable load webpack when apiOnly mode
|
|
34
|
+
- 9229dfd1: support custom headers, fix hmr url concat
|
|
35
|
+
- Updated dependencies [5bf5868d]
|
|
36
|
+
- Updated dependencies [d95f28c3]
|
|
37
|
+
- Updated dependencies [d95f28c3]
|
|
38
|
+
- Updated dependencies [0923c182]
|
|
39
|
+
- Updated dependencies [2008fdbd]
|
|
40
|
+
- Updated dependencies [ca0bcf13]
|
|
41
|
+
- @modern-js/utils@1.3.5
|
|
42
|
+
- @modern-js/prod-server@1.0.4
|
|
43
|
+
|
|
3
44
|
## 1.4.6
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
|
@@ -26,10 +26,7 @@ export default class DevServerPlugin {
|
|
|
26
26
|
const path = `&path=${client.path}`;
|
|
27
27
|
const port = `&port=${client.port}`;
|
|
28
28
|
const clientEntry = `${require.resolve('@modern-js/hmr-client')}?${host}${path}${port}`;
|
|
29
|
-
|
|
30
|
-
const hotEntry = require.resolve('webpack/hot/dev-server');
|
|
31
|
-
|
|
32
|
-
const additionalEntries = [clientEntry, hotEntry]; // use a hook to add entries if available
|
|
29
|
+
const additionalEntries = [clientEntry]; // use a hook to add entries if available
|
|
33
30
|
|
|
34
31
|
for (const additionalEntry of additionalEntries) {
|
|
35
32
|
new EntryPlugin(compiler.context, additionalEntry, {
|
|
@@ -41,7 +38,7 @@ export default class DevServerPlugin {
|
|
|
41
38
|
const compilerOptions = compiler.options;
|
|
42
39
|
compilerOptions.plugins = compilerOptions.plugins || [];
|
|
43
40
|
|
|
44
|
-
if (
|
|
41
|
+
if (!compilerOptions.plugins.find(p => p.constructor === Webpack.HotModuleReplacementPlugin)) {
|
|
45
42
|
// apply the HMR plugin, if it didn't exist before.
|
|
46
43
|
const plugin = new Webpack.HotModuleReplacementPlugin();
|
|
47
44
|
plugin.apply(compiler);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { fs } from '@modern-js/utils';
|
|
3
|
-
import chokidar from 'chokidar';
|
|
2
|
+
import { fs, chokidar } from '@modern-js/utils';
|
|
4
3
|
import { DependencyTree } from "./dependency-tree";
|
|
5
4
|
import { StatsCache } from "./stats-cache";
|
|
6
5
|
export const getWatchedFiles = watcher => {
|
|
@@ -39,12 +39,24 @@ export class ModernDevServer extends ModernServer {
|
|
|
39
39
|
async onInit(runner) {
|
|
40
40
|
var _conf$tools, _conf$tools$devServer;
|
|
41
41
|
|
|
42
|
+
this.runner = runner;
|
|
42
43
|
const {
|
|
43
44
|
conf,
|
|
44
45
|
pwd,
|
|
45
46
|
compiler,
|
|
46
47
|
dev
|
|
47
|
-
} = this; //
|
|
48
|
+
} = this; // before dev handler
|
|
49
|
+
|
|
50
|
+
const beforeHandlers = await this.setupBeforeDevMiddleware();
|
|
51
|
+
beforeHandlers.forEach(handler => {
|
|
52
|
+
this.addHandler((ctx, next) => {
|
|
53
|
+
const {
|
|
54
|
+
req,
|
|
55
|
+
res
|
|
56
|
+
} = ctx;
|
|
57
|
+
return handler(req, res, next);
|
|
58
|
+
});
|
|
59
|
+
}); // mock handler
|
|
48
60
|
|
|
49
61
|
this.mockHandler = createMockHandler({
|
|
50
62
|
pwd
|
|
@@ -74,8 +86,19 @@ export class ModernDevServer extends ModernServer {
|
|
|
74
86
|
|
|
75
87
|
const devMiddlewareHandler = this.setupCompiler(compiler);
|
|
76
88
|
this.addHandler(devMiddlewareHandler);
|
|
77
|
-
}
|
|
89
|
+
} // after dev handler
|
|
90
|
+
|
|
78
91
|
|
|
92
|
+
const afterHandlers = await this.setupAfterDevMiddleware();
|
|
93
|
+
afterHandlers.forEach(handler => {
|
|
94
|
+
this.addHandler((ctx, next) => {
|
|
95
|
+
const {
|
|
96
|
+
req,
|
|
97
|
+
res
|
|
98
|
+
} = ctx;
|
|
99
|
+
return handler(req, res, next);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
79
102
|
await super.onInit(runner); // watch mock/ server/ api/ dir file change
|
|
80
103
|
|
|
81
104
|
if (dev.watch) {
|
|
@@ -252,6 +275,30 @@ export class ModernDevServer extends ModernServer {
|
|
|
252
275
|
};
|
|
253
276
|
}
|
|
254
277
|
|
|
278
|
+
async setupBeforeDevMiddleware() {
|
|
279
|
+
var _conf$tools$devServer2;
|
|
280
|
+
|
|
281
|
+
const {
|
|
282
|
+
runner,
|
|
283
|
+
conf
|
|
284
|
+
} = this;
|
|
285
|
+
const setupMids = ((_conf$tools$devServer2 = conf.tools.devServer) === null || _conf$tools$devServer2 === void 0 ? void 0 : _conf$tools$devServer2.before) || [];
|
|
286
|
+
const pluginMids = await runner.beforeDevServer(conf);
|
|
287
|
+
return [...setupMids, ...pluginMids].flat();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async setupAfterDevMiddleware() {
|
|
291
|
+
var _conf$tools$devServer3;
|
|
292
|
+
|
|
293
|
+
const {
|
|
294
|
+
runner,
|
|
295
|
+
conf
|
|
296
|
+
} = this;
|
|
297
|
+
const setupMids = ((_conf$tools$devServer3 = conf.tools.devServer) === null || _conf$tools$devServer3 === void 0 ? void 0 : _conf$tools$devServer3.after) || [];
|
|
298
|
+
const pluginMids = await runner.afterDevServer(conf);
|
|
299
|
+
return [...pluginMids, ...setupMids].flat();
|
|
300
|
+
}
|
|
301
|
+
|
|
255
302
|
cleanSSRCache() {
|
|
256
303
|
const {
|
|
257
304
|
distDir
|
|
@@ -38,10 +38,7 @@ class DevServerPlugin {
|
|
|
38
38
|
const path = `&path=${client.path}`;
|
|
39
39
|
const port = `&port=${client.port}`;
|
|
40
40
|
const clientEntry = `${require.resolve('@modern-js/hmr-client')}?${host}${path}${port}`;
|
|
41
|
-
|
|
42
|
-
const hotEntry = require.resolve('webpack/hot/dev-server');
|
|
43
|
-
|
|
44
|
-
const additionalEntries = [clientEntry, hotEntry]; // use a hook to add entries if available
|
|
41
|
+
const additionalEntries = [clientEntry]; // use a hook to add entries if available
|
|
45
42
|
|
|
46
43
|
for (const additionalEntry of additionalEntries) {
|
|
47
44
|
new EntryPlugin(compiler.context, additionalEntry, {
|
|
@@ -53,7 +50,7 @@ class DevServerPlugin {
|
|
|
53
50
|
const compilerOptions = compiler.options;
|
|
54
51
|
compilerOptions.plugins = compilerOptions.plugins || [];
|
|
55
52
|
|
|
56
|
-
if (
|
|
53
|
+
if (!compilerOptions.plugins.find(p => p.constructor === _webpack.default.HotModuleReplacementPlugin)) {
|
|
57
54
|
// apply the HMR plugin, if it didn't exist before.
|
|
58
55
|
const plugin = new _webpack.default.HotModuleReplacementPlugin();
|
|
59
56
|
plugin.apply(compiler);
|
|
@@ -9,8 +9,6 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("@modern-js/utils");
|
|
11
11
|
|
|
12
|
-
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
13
|
-
|
|
14
12
|
var _dependencyTree = require("./dependency-tree");
|
|
15
13
|
|
|
16
14
|
var _statsCache = require("./stats-cache");
|
|
@@ -41,7 +39,7 @@ class Watcher {
|
|
|
41
39
|
const filenames = watched.map(filename => filename.replace(/\\/g, '/'));
|
|
42
40
|
const cache = new _statsCache.StatsCache();
|
|
43
41
|
|
|
44
|
-
const watcher =
|
|
42
|
+
const watcher = _utils.chokidar.watch(filenames, options);
|
|
45
43
|
|
|
46
44
|
watcher.on('ready', () => {
|
|
47
45
|
cache.add(getWatchedFiles(watcher));
|
|
@@ -61,12 +61,24 @@ class ModernDevServer extends _prodServer.ModernServer {
|
|
|
61
61
|
async onInit(runner) {
|
|
62
62
|
var _conf$tools, _conf$tools$devServer;
|
|
63
63
|
|
|
64
|
+
this.runner = runner;
|
|
64
65
|
const {
|
|
65
66
|
conf,
|
|
66
67
|
pwd,
|
|
67
68
|
compiler,
|
|
68
69
|
dev
|
|
69
|
-
} = this; //
|
|
70
|
+
} = this; // before dev handler
|
|
71
|
+
|
|
72
|
+
const beforeHandlers = await this.setupBeforeDevMiddleware();
|
|
73
|
+
beforeHandlers.forEach(handler => {
|
|
74
|
+
this.addHandler((ctx, next) => {
|
|
75
|
+
const {
|
|
76
|
+
req,
|
|
77
|
+
res
|
|
78
|
+
} = ctx;
|
|
79
|
+
return handler(req, res, next);
|
|
80
|
+
});
|
|
81
|
+
}); // mock handler
|
|
70
82
|
|
|
71
83
|
this.mockHandler = (0, _mock.createMockHandler)({
|
|
72
84
|
pwd
|
|
@@ -96,8 +108,19 @@ class ModernDevServer extends _prodServer.ModernServer {
|
|
|
96
108
|
|
|
97
109
|
const devMiddlewareHandler = this.setupCompiler(compiler);
|
|
98
110
|
this.addHandler(devMiddlewareHandler);
|
|
99
|
-
}
|
|
111
|
+
} // after dev handler
|
|
112
|
+
|
|
100
113
|
|
|
114
|
+
const afterHandlers = await this.setupAfterDevMiddleware();
|
|
115
|
+
afterHandlers.forEach(handler => {
|
|
116
|
+
this.addHandler((ctx, next) => {
|
|
117
|
+
const {
|
|
118
|
+
req,
|
|
119
|
+
res
|
|
120
|
+
} = ctx;
|
|
121
|
+
return handler(req, res, next);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
101
124
|
await super.onInit(runner); // watch mock/ server/ api/ dir file change
|
|
102
125
|
|
|
103
126
|
if (dev.watch) {
|
|
@@ -276,6 +299,30 @@ class ModernDevServer extends _prodServer.ModernServer {
|
|
|
276
299
|
};
|
|
277
300
|
}
|
|
278
301
|
|
|
302
|
+
async setupBeforeDevMiddleware() {
|
|
303
|
+
var _conf$tools$devServer2;
|
|
304
|
+
|
|
305
|
+
const {
|
|
306
|
+
runner,
|
|
307
|
+
conf
|
|
308
|
+
} = this;
|
|
309
|
+
const setupMids = ((_conf$tools$devServer2 = conf.tools.devServer) === null || _conf$tools$devServer2 === void 0 ? void 0 : _conf$tools$devServer2.before) || [];
|
|
310
|
+
const pluginMids = await runner.beforeDevServer(conf);
|
|
311
|
+
return [...setupMids, ...pluginMids].flat();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async setupAfterDevMiddleware() {
|
|
315
|
+
var _conf$tools$devServer3;
|
|
316
|
+
|
|
317
|
+
const {
|
|
318
|
+
runner,
|
|
319
|
+
conf
|
|
320
|
+
} = this;
|
|
321
|
+
const setupMids = ((_conf$tools$devServer3 = conf.tools.devServer) === null || _conf$tools$devServer3 === void 0 ? void 0 : _conf$tools$devServer3.after) || [];
|
|
322
|
+
const pluginMids = await runner.afterDevServer(conf);
|
|
323
|
+
return [...pluginMids, ...setupMids].flat();
|
|
324
|
+
}
|
|
325
|
+
|
|
279
326
|
cleanSSRCache() {
|
|
280
327
|
const {
|
|
281
328
|
distDir
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const getWatchedFiles: (watcher:
|
|
1
|
+
import { FSWatcher, WatchOptions } from '@modern-js/utils';
|
|
2
|
+
export declare const getWatchedFiles: (watcher: FSWatcher) => string[];
|
|
3
3
|
export default class Watcher {
|
|
4
4
|
private dependencyTree;
|
|
5
5
|
private watcher;
|
|
@@ -25,6 +25,8 @@ export declare class ModernDevServer extends ModernServer {
|
|
|
25
25
|
private setupDevServerPlugin;
|
|
26
26
|
private setupHooks;
|
|
27
27
|
private setupDevMiddleware;
|
|
28
|
+
private setupBeforeDevMiddleware;
|
|
29
|
+
private setupAfterDevMiddleware;
|
|
28
30
|
private cleanSSRCache;
|
|
29
31
|
private startWatcher;
|
|
30
32
|
}
|
package/jest.config.js
CHANGED
|
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
|
|
|
2
2
|
|
|
3
3
|
/** @type {import('@jest/types').Config.InitialOptions} */
|
|
4
4
|
module.exports = {
|
|
5
|
-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
6
5
|
...sharedConfig,
|
|
7
6
|
testEnvironment: 'node',
|
|
8
7
|
rootDir: __dirname,
|
package/package.json
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.9-beta.peer.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
|
-
"types": "./
|
|
16
|
+
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
18
18
|
"module": "./dist/js/treeshaking/index.js",
|
|
19
19
|
"jsnext:modern": "./dist/js/modern/index.js",
|
|
@@ -27,22 +27,14 @@
|
|
|
27
27
|
"default": "./dist/js/treeshaking/index.js"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"prepare": "pnpm build",
|
|
32
|
-
"prepublishOnly": "pnpm build --platform",
|
|
33
|
-
"new": "modern new",
|
|
34
|
-
"build": "modern build",
|
|
35
|
-
"dev": "modern build --watch",
|
|
36
|
-
"test": "jest"
|
|
37
|
-
},
|
|
38
30
|
"dependencies": {
|
|
39
|
-
"@
|
|
31
|
+
"@babel/core": "7.16.7",
|
|
40
32
|
"@babel/register": "^7.15.3",
|
|
41
33
|
"@modern-js/bff-utils": "^1.2.2",
|
|
42
|
-
"@modern-js/hmr-client": "^1.2.
|
|
43
|
-
"@modern-js/server
|
|
44
|
-
"@modern-js/utils": "^1.
|
|
45
|
-
"
|
|
34
|
+
"@modern-js/hmr-client": "^1.2.4",
|
|
35
|
+
"@modern-js/prod-server": "^1.1.0",
|
|
36
|
+
"@modern-js/server-utils": "^1.2.2",
|
|
37
|
+
"@modern-js/utils": "^1.4.1",
|
|
46
38
|
"devcert": "^1.1.3",
|
|
47
39
|
"launch-editor": "^2.2.1",
|
|
48
40
|
"minimatch": "^3.0.4",
|
|
@@ -52,10 +44,11 @@
|
|
|
52
44
|
"ws": "^8.2.0"
|
|
53
45
|
},
|
|
54
46
|
"devDependencies": {
|
|
55
|
-
"@modern-js/
|
|
56
|
-
"@modern-js/core": "
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
47
|
+
"@modern-js/core": "1.7.1-beta.peer.1",
|
|
48
|
+
"@modern-js/server-core": "1.3.0",
|
|
49
|
+
"@modern-js/types": "^1.4.0",
|
|
50
|
+
"@scripts/build": "0.0.0",
|
|
51
|
+
"@scripts/jest-config": "0.0.0",
|
|
59
52
|
"@types/jest": "^26",
|
|
60
53
|
"@types/minimatch": "^3.0.5",
|
|
61
54
|
"@types/node": "^14",
|
|
@@ -63,8 +56,7 @@
|
|
|
63
56
|
"@types/ws": "^7.4.7",
|
|
64
57
|
"jest": "^27",
|
|
65
58
|
"typescript": "^4",
|
|
66
|
-
"webpack": "^5.
|
|
67
|
-
"@scripts/jest-config": "*",
|
|
59
|
+
"webpack": "^5.71.0",
|
|
68
60
|
"websocket": "^1"
|
|
69
61
|
},
|
|
70
62
|
"peerDependencies": {
|
|
@@ -78,7 +70,13 @@
|
|
|
78
70
|
},
|
|
79
71
|
"publishConfig": {
|
|
80
72
|
"registry": "https://registry.npmjs.org/",
|
|
81
|
-
"access": "public"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
"access": "public"
|
|
74
|
+
},
|
|
75
|
+
"scripts": {
|
|
76
|
+
"new": "modern new",
|
|
77
|
+
"build": "modern build",
|
|
78
|
+
"dev": "modern build --watch",
|
|
79
|
+
"test": "jest"
|
|
80
|
+
},
|
|
81
|
+
"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"
|
|
82
|
+
}
|
package/tests/.eslintrc.js
DELETED
package/tests/dev.test.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import http from 'http';
|
|
2
|
-
import { webpack, HotModuleReplacementPlugin } from 'webpack';
|
|
3
|
-
import SocketServer from '../src/dev-tools/socket-server';
|
|
4
|
-
import DevServerPlugin from '../src/dev-tools/dev-server-plugin';
|
|
5
|
-
|
|
6
|
-
function getRandomPort() {
|
|
7
|
-
return Math.floor(Math.random() * (8000 - 1024)) + 1024;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
describe('test dev tools', () => {
|
|
11
|
-
test('should socket server work correctly', () => {
|
|
12
|
-
const port = getRandomPort();
|
|
13
|
-
const socketServer: any = new SocketServer({
|
|
14
|
-
client: {
|
|
15
|
-
port: port.toString(),
|
|
16
|
-
overlay: false,
|
|
17
|
-
logging: 'error',
|
|
18
|
-
path: '/',
|
|
19
|
-
host: '127.0.0.1',
|
|
20
|
-
},
|
|
21
|
-
dev: {
|
|
22
|
-
writeToDisk: false,
|
|
23
|
-
},
|
|
24
|
-
watch: true,
|
|
25
|
-
hot: true,
|
|
26
|
-
liveReload: true,
|
|
27
|
-
});
|
|
28
|
-
const app = http.createServer((req, res) => {
|
|
29
|
-
res.end();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
socketServer.prepare(app);
|
|
33
|
-
expect(socketServer.app).toBe(app);
|
|
34
|
-
expect(socketServer.stats).toBeUndefined();
|
|
35
|
-
|
|
36
|
-
const mockStats = {
|
|
37
|
-
toJson: () => ({}),
|
|
38
|
-
};
|
|
39
|
-
socketServer.updateStats(mockStats);
|
|
40
|
-
expect(socketServer.stats).toBe(mockStats);
|
|
41
|
-
|
|
42
|
-
const socket = {
|
|
43
|
-
state: 1,
|
|
44
|
-
readyState: 1,
|
|
45
|
-
data: '',
|
|
46
|
-
close() {
|
|
47
|
-
socket.state = 0;
|
|
48
|
-
},
|
|
49
|
-
send(data: string) {
|
|
50
|
-
socket.data = data;
|
|
51
|
-
},
|
|
52
|
-
on() {
|
|
53
|
-
// empty
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
socketServer.onConnect(socket);
|
|
58
|
-
|
|
59
|
-
socketServer.sockets = [socket];
|
|
60
|
-
socketServer.sockWrite('test');
|
|
61
|
-
expect(socket.data).toBe(JSON.stringify({ type: 'test' }));
|
|
62
|
-
|
|
63
|
-
socketServer.singleWrite(socket, 'single');
|
|
64
|
-
expect(socket.data).toBe(JSON.stringify({ type: 'single' }));
|
|
65
|
-
|
|
66
|
-
socketServer.close();
|
|
67
|
-
expect(socket.state).toBe(0);
|
|
68
|
-
app.close();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('should dev server plugin work correctly with hot plugin', () => {
|
|
72
|
-
const compiler = webpack({
|
|
73
|
-
plugins: [new HotModuleReplacementPlugin()],
|
|
74
|
-
});
|
|
75
|
-
new DevServerPlugin({
|
|
76
|
-
client: {
|
|
77
|
-
port: '8080',
|
|
78
|
-
overlay: false,
|
|
79
|
-
logging: 'error',
|
|
80
|
-
path: '/',
|
|
81
|
-
host: '127.0.0.1',
|
|
82
|
-
},
|
|
83
|
-
dev: {
|
|
84
|
-
writeToDisk: false,
|
|
85
|
-
},
|
|
86
|
-
watch: true,
|
|
87
|
-
hot: true,
|
|
88
|
-
liveReload: true,
|
|
89
|
-
}).apply(compiler);
|
|
90
|
-
|
|
91
|
-
// expect(compiler.options.entry)
|
|
92
|
-
const entryPluginHook = compiler.hooks.compilation.taps.filter(
|
|
93
|
-
tap => tap.name === 'EntryPlugin',
|
|
94
|
-
);
|
|
95
|
-
const hotPluginHook = compiler.hooks.compilation.taps.filter(
|
|
96
|
-
tap => tap.name === 'HotModuleReplacementPlugin',
|
|
97
|
-
);
|
|
98
|
-
expect(entryPluginHook.length).toBe(3);
|
|
99
|
-
expect(hotPluginHook.length).toBe(1);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test('should dev server plugin work correctly', () => {
|
|
103
|
-
const compiler = webpack({});
|
|
104
|
-
new DevServerPlugin({
|
|
105
|
-
client: {
|
|
106
|
-
port: '8080',
|
|
107
|
-
overlay: false,
|
|
108
|
-
logging: 'error',
|
|
109
|
-
path: '/',
|
|
110
|
-
host: '127.0.0.1',
|
|
111
|
-
},
|
|
112
|
-
dev: {
|
|
113
|
-
writeToDisk: false,
|
|
114
|
-
},
|
|
115
|
-
watch: true,
|
|
116
|
-
hot: true,
|
|
117
|
-
liveReload: true,
|
|
118
|
-
}).apply(compiler);
|
|
119
|
-
|
|
120
|
-
// expect(compiler.options.entry)
|
|
121
|
-
const entryPluginHook = compiler.hooks.compilation.taps.filter(
|
|
122
|
-
tap => tap.name === 'EntryPlugin',
|
|
123
|
-
);
|
|
124
|
-
const hotPluginHook = compiler.hooks.compilation.taps.filter(
|
|
125
|
-
tap => tap.name === 'HotModuleReplacementPlugin',
|
|
126
|
-
);
|
|
127
|
-
expect(entryPluginHook.length).toBe(3);
|
|
128
|
-
expect(hotPluginHook.length).toBe(1);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default null;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "deploy",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"scripts": {
|
|
5
|
-
"reset": "del-cli node_modules",
|
|
6
|
-
"dev": "modern dev",
|
|
7
|
-
"build": "modern build",
|
|
8
|
-
"start": "modern start",
|
|
9
|
-
"new": "modern new",
|
|
10
|
-
"lint": "modern lint",
|
|
11
|
-
"deploy": "modern deploy"
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {},
|
|
14
|
-
"devDependencies": {},
|
|
15
|
-
"modernConfig": {
|
|
16
|
-
"runtime": {
|
|
17
|
-
"router": true,
|
|
18
|
-
"state": true
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|