@modern-js/server 1.4.13 → 1.4.16
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 +61 -0
- package/dist/js/modern/constants.js +19 -16
- package/dist/js/modern/dev-tools/dev-server-plugin.js +7 -14
- package/dist/js/modern/dev-tools/socket-server.js +14 -6
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +6 -2
- package/dist/js/modern/dev-tools/watcher/index.js +5 -2
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +5 -2
- package/dist/js/modern/server/dev-server.js +25 -16
- package/dist/js/node/constants.js +21 -17
- package/dist/js/node/dev-tools/dev-server-plugin.js +7 -15
- package/dist/js/node/dev-tools/socket-server.js +14 -6
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +6 -2
- package/dist/js/node/dev-tools/watcher/index.js +5 -2
- package/dist/js/node/dev-tools/watcher/stats-cache.js +5 -2
- package/dist/js/node/server/dev-server.js +24 -16
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/server/dev-server.d.ts +1 -0
- package/dist/types/types.d.ts +5 -5
- package/package.json +37 -20
- package/.eslintrc.js +0 -8
- package/dist/js/modern/dev-tools/launch-editor/index.js +0 -25
- package/dist/js/node/dev-tools/launch-editor/index.js +0 -35
- package/dist/types/dev-tools/launch-editor/index.d.ts +0 -2
- package/jest.config.js +0 -8
- package/modern.config.js +0 -6
- package/tsconfig.json +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,66 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 1.4.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f7cbc771: feat: prebundle webpack-dev-middleware
|
|
8
|
+
- cdc2df9c: fix(server): remove launch-editor
|
|
9
|
+
- b39b399e: lock devcert version
|
|
10
|
+
- 430d417e: optimize server side hot reload
|
|
11
|
+
- 437367c6: fix(server): hmr not working when using proxy
|
|
12
|
+
- Updated dependencies [5f7fccf0]
|
|
13
|
+
- Updated dependencies [02b0a22e]
|
|
14
|
+
- Updated dependencies [da65bf12]
|
|
15
|
+
- Updated dependencies [8854c600]
|
|
16
|
+
- Updated dependencies [d57e7622]
|
|
17
|
+
- Updated dependencies [f7cbc771]
|
|
18
|
+
- Updated dependencies [6451a098]
|
|
19
|
+
- Updated dependencies [f5c48c3f]
|
|
20
|
+
- Updated dependencies [430d417e]
|
|
21
|
+
- Updated dependencies [658b4dd5]
|
|
22
|
+
- Updated dependencies [d5a2cfd8]
|
|
23
|
+
- Updated dependencies [45d5643a]
|
|
24
|
+
- Updated dependencies [0d161fa8]
|
|
25
|
+
- Updated dependencies [437367c6]
|
|
26
|
+
- Updated dependencies [280eebf9]
|
|
27
|
+
- Updated dependencies [2ba8d62f]
|
|
28
|
+
- Updated dependencies [7394df61]
|
|
29
|
+
- @modern-js/webpack@1.9.0
|
|
30
|
+
- @modern-js/bff-utils@1.2.8
|
|
31
|
+
- @modern-js/utils@1.7.6
|
|
32
|
+
- @modern-js/prod-server@1.1.6
|
|
33
|
+
- @modern-js/server-utils@1.2.9
|
|
34
|
+
|
|
35
|
+
## 1.4.15
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- b8cfc42cd: feat: prebundle tsconfig-paths and nanoid
|
|
40
|
+
- Updated dependencies [b8cfc42cd]
|
|
41
|
+
- Updated dependencies [804a5bb8a]
|
|
42
|
+
- @modern-js/utils@1.7.4
|
|
43
|
+
- @modern-js/prod-server@1.1.5
|
|
44
|
+
- @modern-js/server-utils@1.2.6
|
|
45
|
+
|
|
46
|
+
## 1.4.14
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- d32f35134: chore: add modern/jest/eslint/ts config files to .npmignore
|
|
51
|
+
- Updated dependencies [d32f35134]
|
|
52
|
+
- Updated dependencies [86fe5a657]
|
|
53
|
+
- Updated dependencies [aeda91deb]
|
|
54
|
+
- Updated dependencies [6ae4a34ae]
|
|
55
|
+
- Updated dependencies [b80229c79]
|
|
56
|
+
- Updated dependencies [1a30be07b]
|
|
57
|
+
- Updated dependencies [948cc4436]
|
|
58
|
+
- @modern-js/bff-utils@1.2.6
|
|
59
|
+
- @modern-js/hmr-client@1.2.7
|
|
60
|
+
- @modern-js/prod-server@1.1.5
|
|
61
|
+
- @modern-js/server-utils@1.2.6
|
|
62
|
+
- @modern-js/utils@1.7.3
|
|
63
|
+
|
|
3
64
|
## 1.4.13
|
|
4
65
|
|
|
5
66
|
### Patch Changes
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { HMR_SOCK_PATH } from '@modern-js/utils';
|
|
2
|
-
export const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { getIpv4Interfaces, HMR_SOCK_PATH } from '@modern-js/utils';
|
|
2
|
+
export const getDefaultDevOptions = () => {
|
|
3
|
+
const network = getIpv4Interfaces().find(item => !item.internal);
|
|
4
|
+
return {
|
|
5
|
+
client: {
|
|
6
|
+
port: '8080',
|
|
7
|
+
overlay: false,
|
|
8
|
+
logging: 'none',
|
|
9
|
+
path: HMR_SOCK_PATH,
|
|
10
|
+
host: (network === null || network === void 0 ? void 0 : network.address) || 'localhost'
|
|
11
|
+
},
|
|
12
|
+
https: false,
|
|
13
|
+
devMiddleware: {
|
|
14
|
+
writeToDisk: true
|
|
15
|
+
},
|
|
16
|
+
watch: true,
|
|
17
|
+
hot: true,
|
|
18
|
+
liveReload: true
|
|
19
|
+
};
|
|
17
20
|
};
|
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
2
|
|
|
7
3
|
import Webpack from 'webpack';
|
|
8
|
-
import { DEFAULT_DEV_OPTIONS } from "../constants";
|
|
9
4
|
const {
|
|
10
5
|
EntryPlugin
|
|
11
6
|
} = Webpack;
|
|
12
7
|
export default class DevServerPlugin {
|
|
13
8
|
constructor(options) {
|
|
14
|
-
this
|
|
9
|
+
_defineProperty(this, "options", void 0);
|
|
10
|
+
|
|
15
11
|
this.options = options;
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
apply(compiler) {
|
|
19
15
|
const {
|
|
20
|
-
|
|
21
|
-
} = this;
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const host = `&host=${client.host}`;
|
|
26
|
-
const path = `&path=${client.path}`;
|
|
27
|
-
const port = `&port=${client.port}`;
|
|
16
|
+
client
|
|
17
|
+
} = this.options;
|
|
18
|
+
const host = client.host ? `&host=${client.host}` : '';
|
|
19
|
+
const path = client.path ? `&path=${client.path}` : '';
|
|
20
|
+
const port = client.port ? `&port=${client.port}` : '';
|
|
28
21
|
const clientEntry = `${require.resolve('@modern-js/hmr-client')}?${host}${path}${port}`;
|
|
29
22
|
const additionalEntries = [clientEntry]; // use a hook to add entries if available
|
|
30
23
|
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
import ws from 'ws';
|
|
2
4
|
import { logger } from '@modern-js/utils';
|
|
3
5
|
export default class SocketServer {
|
|
4
6
|
constructor(options) {
|
|
5
|
-
this
|
|
6
|
-
|
|
7
|
-
this
|
|
8
|
-
|
|
9
|
-
this
|
|
10
|
-
|
|
7
|
+
_defineProperty(this, "wsServer", void 0);
|
|
8
|
+
|
|
9
|
+
_defineProperty(this, "sockets", []);
|
|
10
|
+
|
|
11
|
+
_defineProperty(this, "options", void 0);
|
|
12
|
+
|
|
13
|
+
_defineProperty(this, "app", void 0);
|
|
14
|
+
|
|
15
|
+
_defineProperty(this, "stats", void 0);
|
|
16
|
+
|
|
17
|
+
_defineProperty(this, "timer", null);
|
|
18
|
+
|
|
11
19
|
this.options = options;
|
|
12
20
|
} // create socket, install socket handler, bind socket event
|
|
13
21
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
import minimatch from 'minimatch';
|
|
2
4
|
export const defaultIgnores = ['**/bower_components/**', '**/coverage/**', '**/node_modules/**', '**/.*/**', '**/*.d.ts', '**/*.log'];
|
|
3
5
|
|
|
@@ -8,8 +10,10 @@ export const defaultIgnores = ['**/bower_components/**', '**/coverage/**', '**/n
|
|
|
8
10
|
*/
|
|
9
11
|
export class DependencyTree {
|
|
10
12
|
constructor() {
|
|
11
|
-
this
|
|
12
|
-
|
|
13
|
+
_defineProperty(this, "tree", void 0);
|
|
14
|
+
|
|
15
|
+
_defineProperty(this, "ignore", void 0);
|
|
16
|
+
|
|
13
17
|
this.tree = new Map();
|
|
14
18
|
this.ignore = [...defaultIgnores];
|
|
15
19
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
import path from 'path';
|
|
2
4
|
import { fs, chokidar } from '@modern-js/utils';
|
|
3
5
|
import { DependencyTree } from "./dependency-tree";
|
|
@@ -14,8 +16,9 @@ export const getWatchedFiles = watcher => {
|
|
|
14
16
|
};
|
|
15
17
|
export default class Watcher {
|
|
16
18
|
constructor() {
|
|
17
|
-
this
|
|
18
|
-
|
|
19
|
+
_defineProperty(this, "dependencyTree", null);
|
|
20
|
+
|
|
21
|
+
_defineProperty(this, "watcher", void 0);
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
listen(files, options, callback) {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
import fs from 'fs';
|
|
2
4
|
import crypto from 'crypto';
|
|
3
5
|
export class StatsCache {
|
|
4
6
|
constructor() {
|
|
5
|
-
this
|
|
6
|
-
|
|
7
|
+
_defineProperty(this, "cachedHash", {});
|
|
8
|
+
|
|
9
|
+
_defineProperty(this, "cachedSize", {});
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
add(files) {
|
|
@@ -8,31 +8,44 @@ import { createServer } from 'http';
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import { createServer as createHttpsServer } from 'https';
|
|
10
10
|
import { API_DIR, SERVER_DIR, SHARED_DIR } from '@modern-js/utils';
|
|
11
|
-
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
11
|
+
import webpackDevMiddleware from '@modern-js/webpack/webpack-dev-middleware';
|
|
12
12
|
import { createProxyHandler, ModernServer, AGGRED_DIR } from '@modern-js/prod-server';
|
|
13
|
-
import {
|
|
13
|
+
import { getDefaultDevOptions } from "../constants";
|
|
14
14
|
import { createMockHandler } from "../dev-tools/mock";
|
|
15
15
|
import SocketServer from "../dev-tools/socket-server";
|
|
16
16
|
import DevServerPlugin from "../dev-tools/dev-server-plugin";
|
|
17
|
-
import { createLaunchEditorHandler } from "../dev-tools/launch-editor";
|
|
18
17
|
import { enableRegister } from "../dev-tools/babel/register";
|
|
19
18
|
import Watcher from "../dev-tools/watcher";
|
|
20
19
|
export class ModernDevServer extends ModernServer {
|
|
21
20
|
constructor(options) {
|
|
22
21
|
super(options); // dev server should work in pwd
|
|
23
22
|
|
|
24
|
-
this
|
|
25
|
-
|
|
26
|
-
this
|
|
27
|
-
|
|
28
|
-
this
|
|
29
|
-
|
|
23
|
+
_defineProperty(this, "mockHandler", null);
|
|
24
|
+
|
|
25
|
+
_defineProperty(this, "dev", void 0);
|
|
26
|
+
|
|
27
|
+
_defineProperty(this, "compiler", void 0);
|
|
28
|
+
|
|
29
|
+
_defineProperty(this, "socketServer", void 0);
|
|
30
|
+
|
|
31
|
+
_defineProperty(this, "watcher", void 0);
|
|
32
|
+
|
|
33
|
+
_defineProperty(this, "devMiddleware", void 0);
|
|
34
|
+
|
|
30
35
|
this.workDir = this.pwd; // set webpack compiler
|
|
31
36
|
|
|
32
37
|
this.compiler = options.compiler; // set dev server options, like webpack-dev-server
|
|
33
38
|
|
|
34
|
-
this.dev =
|
|
39
|
+
this.dev = this.getDevOptions(options);
|
|
35
40
|
enableRegister(this.pwd, this.conf);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getDevOptions(options) {
|
|
44
|
+
const devOptions = typeof options.dev === 'boolean' ? {} : options.dev;
|
|
45
|
+
const defaultOptions = getDefaultDevOptions();
|
|
46
|
+
return _objectSpread(_objectSpread(_objectSpread({}, defaultOptions), devOptions), {}, {
|
|
47
|
+
client: _objectSpread(_objectSpread({}, defaultOptions.client), devOptions === null || devOptions === void 0 ? void 0 : devOptions.client)
|
|
48
|
+
});
|
|
36
49
|
} // Complete the preparation of services
|
|
37
50
|
|
|
38
51
|
|
|
@@ -80,9 +93,7 @@ export class ModernDevServer extends ModernServer {
|
|
|
80
93
|
|
|
81
94
|
if (compiler) {
|
|
82
95
|
// init socket server
|
|
83
|
-
this.socketServer = new SocketServer(dev); //
|
|
84
|
-
|
|
85
|
-
this.addHandler(createLaunchEditorHandler()); // setup compiler in server, also add dev-middleware to handler static file in memory
|
|
96
|
+
this.socketServer = new SocketServer(dev); // setup compiler in server, also add dev-middleware to handler static file in memory
|
|
86
97
|
|
|
87
98
|
const devMiddlewareHandler = this.setupCompiler(compiler);
|
|
88
99
|
this.addHandler(devMiddlewareHandler);
|
|
@@ -132,9 +143,7 @@ export class ModernDevServer extends ModernServer {
|
|
|
132
143
|
|
|
133
144
|
this.cleanSSRCache(); // reset static file
|
|
134
145
|
|
|
135
|
-
this.reader.updateFile();
|
|
136
|
-
|
|
137
|
-
this.runner.reset();
|
|
146
|
+
this.reader.updateFile();
|
|
138
147
|
super.onRepack(options);
|
|
139
148
|
}
|
|
140
149
|
|
|
@@ -3,24 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getDefaultDevOptions = void 0;
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
const getDefaultDevOptions = () => {
|
|
11
|
+
const network = (0, _utils.getIpv4Interfaces)().find(item => !item.internal);
|
|
12
|
+
return {
|
|
13
|
+
client: {
|
|
14
|
+
port: '8080',
|
|
15
|
+
overlay: false,
|
|
16
|
+
logging: 'none',
|
|
17
|
+
path: _utils.HMR_SOCK_PATH,
|
|
18
|
+
host: (network === null || network === void 0 ? void 0 : network.address) || 'localhost'
|
|
19
|
+
},
|
|
20
|
+
https: false,
|
|
21
|
+
devMiddleware: {
|
|
22
|
+
writeToDisk: true
|
|
23
|
+
},
|
|
24
|
+
watch: true,
|
|
25
|
+
hot: true,
|
|
26
|
+
liveReload: true
|
|
27
|
+
};
|
|
25
28
|
};
|
|
26
|
-
|
|
29
|
+
|
|
30
|
+
exports.getDefaultDevOptions = getDefaultDevOptions;
|
|
@@ -7,14 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _webpack = _interopRequireDefault(require("webpack"));
|
|
9
9
|
|
|
10
|
-
var _constants = require("../constants");
|
|
11
|
-
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
11
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
12
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
13
|
|
|
20
14
|
const {
|
|
@@ -23,20 +17,18 @@ const {
|
|
|
23
17
|
|
|
24
18
|
class DevServerPlugin {
|
|
25
19
|
constructor(options) {
|
|
26
|
-
this
|
|
20
|
+
_defineProperty(this, "options", void 0);
|
|
21
|
+
|
|
27
22
|
this.options = options;
|
|
28
23
|
}
|
|
29
24
|
|
|
30
25
|
apply(compiler) {
|
|
31
26
|
const {
|
|
32
|
-
|
|
33
|
-
} = this;
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const host = `&host=${client.host}`;
|
|
38
|
-
const path = `&path=${client.path}`;
|
|
39
|
-
const port = `&port=${client.port}`;
|
|
27
|
+
client
|
|
28
|
+
} = this.options;
|
|
29
|
+
const host = client.host ? `&host=${client.host}` : '';
|
|
30
|
+
const path = client.path ? `&path=${client.path}` : '';
|
|
31
|
+
const port = client.port ? `&port=${client.port}` : '';
|
|
40
32
|
const clientEntry = `${require.resolve('@modern-js/hmr-client')}?${host}${path}${port}`;
|
|
41
33
|
const additionalEntries = [clientEntry]; // use a hook to add entries if available
|
|
42
34
|
|
|
@@ -11,14 +11,22 @@ var _utils = require("@modern-js/utils");
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
|
|
14
16
|
class SocketServer {
|
|
15
17
|
constructor(options) {
|
|
16
|
-
this
|
|
17
|
-
|
|
18
|
-
this
|
|
19
|
-
|
|
20
|
-
this
|
|
21
|
-
|
|
18
|
+
_defineProperty(this, "wsServer", void 0);
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "sockets", []);
|
|
21
|
+
|
|
22
|
+
_defineProperty(this, "options", void 0);
|
|
23
|
+
|
|
24
|
+
_defineProperty(this, "app", void 0);
|
|
25
|
+
|
|
26
|
+
_defineProperty(this, "stats", void 0);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "timer", null);
|
|
29
|
+
|
|
22
30
|
this.options = options;
|
|
23
31
|
} // create socket, install socket handler, bind socket event
|
|
24
32
|
|
|
@@ -9,6 +9,8 @@ var _minimatch = _interopRequireDefault(require("minimatch"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
|
|
12
14
|
const defaultIgnores = ['**/bower_components/**', '**/coverage/**', '**/node_modules/**', '**/.*/**', '**/*.d.ts', '**/*.log'];
|
|
13
15
|
exports.defaultIgnores = defaultIgnores;
|
|
14
16
|
|
|
@@ -19,8 +21,10 @@ exports.defaultIgnores = defaultIgnores;
|
|
|
19
21
|
*/
|
|
20
22
|
class DependencyTree {
|
|
21
23
|
constructor() {
|
|
22
|
-
this
|
|
23
|
-
|
|
24
|
+
_defineProperty(this, "tree", void 0);
|
|
25
|
+
|
|
26
|
+
_defineProperty(this, "ignore", void 0);
|
|
27
|
+
|
|
24
28
|
this.tree = new Map();
|
|
25
29
|
this.ignore = [...defaultIgnores];
|
|
26
30
|
}
|
|
@@ -15,6 +15,8 @@ var _statsCache = require("./stats-cache");
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
+
|
|
18
20
|
const getWatchedFiles = watcher => {
|
|
19
21
|
const watched = watcher.getWatched();
|
|
20
22
|
const files = [];
|
|
@@ -30,8 +32,9 @@ exports.getWatchedFiles = getWatchedFiles;
|
|
|
30
32
|
|
|
31
33
|
class Watcher {
|
|
32
34
|
constructor() {
|
|
33
|
-
this
|
|
34
|
-
|
|
35
|
+
_defineProperty(this, "dependencyTree", null);
|
|
36
|
+
|
|
37
|
+
_defineProperty(this, "watcher", void 0);
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
listen(files, options, callback) {
|
|
@@ -11,10 +11,13 @@ var _crypto = _interopRequireDefault(require("crypto"));
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
|
|
14
16
|
class StatsCache {
|
|
15
17
|
constructor() {
|
|
16
|
-
this
|
|
17
|
-
|
|
18
|
+
_defineProperty(this, "cachedHash", {});
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "cachedSize", {});
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
add(files) {
|
|
@@ -13,7 +13,7 @@ var _https = require("https");
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("@modern-js/utils");
|
|
15
15
|
|
|
16
|
-
var _webpackDevMiddleware = _interopRequireDefault(require("webpack-dev-middleware"));
|
|
16
|
+
var _webpackDevMiddleware = _interopRequireDefault(require("@modern-js/webpack/webpack-dev-middleware"));
|
|
17
17
|
|
|
18
18
|
var _prodServer = require("@modern-js/prod-server");
|
|
19
19
|
|
|
@@ -25,8 +25,6 @@ var _socketServer = _interopRequireDefault(require("../dev-tools/socket-server")
|
|
|
25
25
|
|
|
26
26
|
var _devServerPlugin = _interopRequireDefault(require("../dev-tools/dev-server-plugin"));
|
|
27
27
|
|
|
28
|
-
var _launchEditor = require("../dev-tools/launch-editor");
|
|
29
|
-
|
|
30
28
|
var _register = require("../dev-tools/babel/register");
|
|
31
29
|
|
|
32
30
|
var _watcher = _interopRequireDefault(require("../dev-tools/watcher"));
|
|
@@ -43,18 +41,32 @@ class ModernDevServer extends _prodServer.ModernServer {
|
|
|
43
41
|
constructor(options) {
|
|
44
42
|
super(options); // dev server should work in pwd
|
|
45
43
|
|
|
46
|
-
this
|
|
47
|
-
|
|
48
|
-
this
|
|
49
|
-
|
|
50
|
-
this
|
|
51
|
-
|
|
44
|
+
_defineProperty(this, "mockHandler", null);
|
|
45
|
+
|
|
46
|
+
_defineProperty(this, "dev", void 0);
|
|
47
|
+
|
|
48
|
+
_defineProperty(this, "compiler", void 0);
|
|
49
|
+
|
|
50
|
+
_defineProperty(this, "socketServer", void 0);
|
|
51
|
+
|
|
52
|
+
_defineProperty(this, "watcher", void 0);
|
|
53
|
+
|
|
54
|
+
_defineProperty(this, "devMiddleware", void 0);
|
|
55
|
+
|
|
52
56
|
this.workDir = this.pwd; // set webpack compiler
|
|
53
57
|
|
|
54
58
|
this.compiler = options.compiler; // set dev server options, like webpack-dev-server
|
|
55
59
|
|
|
56
|
-
this.dev =
|
|
60
|
+
this.dev = this.getDevOptions(options);
|
|
57
61
|
(0, _register.enableRegister)(this.pwd, this.conf);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getDevOptions(options) {
|
|
65
|
+
const devOptions = typeof options.dev === 'boolean' ? {} : options.dev;
|
|
66
|
+
const defaultOptions = (0, _constants.getDefaultDevOptions)();
|
|
67
|
+
return _objectSpread(_objectSpread(_objectSpread({}, defaultOptions), devOptions), {}, {
|
|
68
|
+
client: _objectSpread(_objectSpread({}, defaultOptions.client), devOptions === null || devOptions === void 0 ? void 0 : devOptions.client)
|
|
69
|
+
});
|
|
58
70
|
} // Complete the preparation of services
|
|
59
71
|
|
|
60
72
|
|
|
@@ -102,9 +114,7 @@ class ModernDevServer extends _prodServer.ModernServer {
|
|
|
102
114
|
|
|
103
115
|
if (compiler) {
|
|
104
116
|
// init socket server
|
|
105
|
-
this.socketServer = new _socketServer.default(dev); //
|
|
106
|
-
|
|
107
|
-
this.addHandler((0, _launchEditor.createLaunchEditorHandler)()); // setup compiler in server, also add dev-middleware to handler static file in memory
|
|
117
|
+
this.socketServer = new _socketServer.default(dev); // setup compiler in server, also add dev-middleware to handler static file in memory
|
|
108
118
|
|
|
109
119
|
const devMiddlewareHandler = this.setupCompiler(compiler);
|
|
110
120
|
this.addHandler(devMiddlewareHandler);
|
|
@@ -154,9 +164,7 @@ class ModernDevServer extends _prodServer.ModernServer {
|
|
|
154
164
|
|
|
155
165
|
this.cleanSSRCache(); // reset static file
|
|
156
166
|
|
|
157
|
-
this.reader.updateFile();
|
|
158
|
-
|
|
159
|
-
this.runner.reset();
|
|
167
|
+
this.reader.updateFile();
|
|
160
168
|
super.onRepack(options);
|
|
161
169
|
}
|
|
162
170
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { DevServerOptions } from './types';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const getDefaultDevOptions: () => DevServerOptions;
|
|
@@ -10,6 +10,7 @@ export declare class ModernDevServer extends ModernServer {
|
|
|
10
10
|
private watcher;
|
|
11
11
|
private devMiddleware;
|
|
12
12
|
constructor(options: ModernDevServerOptions);
|
|
13
|
+
private getDevOptions;
|
|
13
14
|
onInit(runner: ServerHookRunner): Promise<void>;
|
|
14
15
|
onClose(): Promise<void>;
|
|
15
16
|
onRepack(options?: BuildOptions): void;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { ModernServerOptions } from '@modern-js/prod-server';
|
|
|
2
2
|
import type Webpack from 'webpack';
|
|
3
3
|
export declare type DevServerOptions = {
|
|
4
4
|
client: {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
path?: string;
|
|
6
|
+
port?: string;
|
|
7
|
+
host?: string;
|
|
8
|
+
logging?: string;
|
|
9
|
+
overlay?: boolean;
|
|
10
10
|
progress?: boolean;
|
|
11
11
|
};
|
|
12
12
|
devMiddleware: {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.16",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -30,38 +30,32 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/core": "^7.17.0",
|
|
32
32
|
"@babel/register": "^7.15.3",
|
|
33
|
-
"@modern-js/bff-utils": "^1.2.
|
|
34
|
-
"@modern-js/hmr-client": "^1.2.
|
|
35
|
-
"@modern-js/prod-server": "^1.1.
|
|
36
|
-
"@modern-js/server-utils": "^1.2.
|
|
37
|
-
"@modern-js/
|
|
38
|
-
"
|
|
39
|
-
"
|
|
33
|
+
"@modern-js/bff-utils": "^1.2.8",
|
|
34
|
+
"@modern-js/hmr-client": "^1.2.7",
|
|
35
|
+
"@modern-js/prod-server": "^1.1.6",
|
|
36
|
+
"@modern-js/server-utils": "^1.2.9",
|
|
37
|
+
"@modern-js/webpack": "^1.9.0",
|
|
38
|
+
"@modern-js/utils": "^1.7.6",
|
|
39
|
+
"devcert": "1.2.0",
|
|
40
40
|
"minimatch": "^3.0.4",
|
|
41
41
|
"path-to-regexp": "^6.2.0",
|
|
42
|
-
"tsconfig-paths": "^3.11.0",
|
|
43
|
-
"webpack-dev-middleware": "^5.0.0",
|
|
44
42
|
"ws": "^8.2.0"
|
|
45
43
|
},
|
|
46
44
|
"devDependencies": {
|
|
47
|
-
"@modern-js/core": "1.
|
|
48
|
-
"@modern-js/server-core": "1.3.
|
|
49
|
-
"@modern-js/types": "1.5.
|
|
45
|
+
"@modern-js/core": "1.11.1",
|
|
46
|
+
"@modern-js/server-core": "1.3.5",
|
|
47
|
+
"@modern-js/types": "1.5.4",
|
|
50
48
|
"@scripts/build": "0.0.0",
|
|
51
49
|
"@scripts/jest-config": "0.0.0",
|
|
52
|
-
"@types/jest": "^
|
|
50
|
+
"@types/jest": "^27",
|
|
53
51
|
"@types/minimatch": "^3.0.5",
|
|
54
52
|
"@types/node": "^14",
|
|
55
|
-
"@types/webpack-dev-middleware": "^5.0.2",
|
|
56
53
|
"@types/ws": "^7.4.7",
|
|
57
54
|
"jest": "^27",
|
|
58
55
|
"typescript": "^4",
|
|
59
56
|
"webpack": "^5.71.0",
|
|
60
57
|
"websocket": "^1"
|
|
61
58
|
},
|
|
62
|
-
"peerDependencies": {
|
|
63
|
-
"webpack": "^5.54.0"
|
|
64
|
-
},
|
|
65
59
|
"sideEffects": false,
|
|
66
60
|
"modernConfig": {
|
|
67
61
|
"output": {
|
|
@@ -72,11 +66,34 @@
|
|
|
72
66
|
"registry": "https://registry.npmjs.org/",
|
|
73
67
|
"access": "public"
|
|
74
68
|
},
|
|
69
|
+
"wireit": {
|
|
70
|
+
"build": {
|
|
71
|
+
"command": "modern build",
|
|
72
|
+
"files": [
|
|
73
|
+
"src/**/*",
|
|
74
|
+
"tsconfig.json",
|
|
75
|
+
"package.json"
|
|
76
|
+
],
|
|
77
|
+
"output": [
|
|
78
|
+
"dist/**/*"
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
"test": {
|
|
82
|
+
"command": "jest",
|
|
83
|
+
"files": [
|
|
84
|
+
"src/**/*",
|
|
85
|
+
"tsconfig.json",
|
|
86
|
+
"package.json",
|
|
87
|
+
"tests/**/*"
|
|
88
|
+
],
|
|
89
|
+
"output": []
|
|
90
|
+
}
|
|
91
|
+
},
|
|
75
92
|
"scripts": {
|
|
76
93
|
"new": "modern new",
|
|
77
|
-
"build": "
|
|
94
|
+
"build": "wireit",
|
|
78
95
|
"dev": "modern build --watch",
|
|
79
|
-
"test": "
|
|
96
|
+
"test": "wireit"
|
|
80
97
|
},
|
|
81
98
|
"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
99
|
}
|
package/.eslintrc.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { LAUNCH_EDITOR_ENDPOINT, logger } from '@modern-js/utils';
|
|
2
|
-
export const createLaunchEditorHandler = // eslint-disable-next-line consistent-return
|
|
3
|
-
() => (ctx, next) => {
|
|
4
|
-
if (ctx.url.startsWith(LAUNCH_EDITOR_ENDPOINT)) {
|
|
5
|
-
const {
|
|
6
|
-
filename,
|
|
7
|
-
line = 1,
|
|
8
|
-
column = 1
|
|
9
|
-
} = ctx.query;
|
|
10
|
-
|
|
11
|
-
if (!filename) {
|
|
12
|
-
ctx.status = 500;
|
|
13
|
-
ctx.res.end(`launch-editor-middleware: required query param "filename" is missing.`);
|
|
14
|
-
} else {
|
|
15
|
-
require('launch-editor')(`${filename}:${line}:${column}`, 'code', (file, errorMessage) => {
|
|
16
|
-
logger.error(`Launch ${file} in editor failed.\n${errorMessage}`);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
ctx.status = 200;
|
|
20
|
-
ctx.res.end();
|
|
21
|
-
}
|
|
22
|
-
} else {
|
|
23
|
-
return next();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createLaunchEditorHandler = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
|
-
const createLaunchEditorHandler = // eslint-disable-next-line consistent-return
|
|
11
|
-
() => (ctx, next) => {
|
|
12
|
-
if (ctx.url.startsWith(_utils.LAUNCH_EDITOR_ENDPOINT)) {
|
|
13
|
-
const {
|
|
14
|
-
filename,
|
|
15
|
-
line = 1,
|
|
16
|
-
column = 1
|
|
17
|
-
} = ctx.query;
|
|
18
|
-
|
|
19
|
-
if (!filename) {
|
|
20
|
-
ctx.status = 500;
|
|
21
|
-
ctx.res.end(`launch-editor-middleware: required query param "filename" is missing.`);
|
|
22
|
-
} else {
|
|
23
|
-
require('launch-editor')(`${filename}:${line}:${column}`, 'code', (file, errorMessage) => {
|
|
24
|
-
_utils.logger.error(`Launch ${file} in editor failed.\n${errorMessage}`);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
ctx.status = 200;
|
|
28
|
-
ctx.res.end();
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
return next();
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
exports.createLaunchEditorHandler = createLaunchEditorHandler;
|
package/jest.config.js
DELETED
package/modern.config.js
DELETED