@modern-js/server 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 +26 -0
- package/dist/js/modern/dev-tools/babel/register.js +1 -0
- package/dist/js/modern/dev-tools/dev-server-plugin.js +1 -2
- package/dist/js/modern/dev-tools/mock/getMockData.js +24 -1
- package/dist/js/modern/dev-tools/mock/index.js +1 -26
- package/dist/js/modern/dev-tools/socket-server.js +4 -2
- package/dist/js/modern/dev-tools/watcher/index.js +3 -4
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +32 -20
- package/dist/js/modern/libs/context/context.js +6 -0
- package/dist/js/modern/libs/hook-api/route.js +6 -4
- package/dist/js/modern/libs/render/index.js +1 -0
- package/dist/js/modern/libs/render/ssr.js +7 -2
- package/dist/js/modern/libs/route/index.js +0 -1
- package/dist/js/modern/libs/route/matcher.js +15 -3
- package/dist/js/modern/libs/route/route.js +1 -0
- package/dist/js/modern/server/dev-server/dev-server.js +3 -0
- package/dist/js/modern/server/index.js +5 -4
- package/dist/js/modern/server/modern-server-split.js +1 -1
- package/dist/js/modern/server/modern-server.js +9 -5
- package/dist/js/modern/utils.js +7 -0
- package/dist/js/node/dev-tools/babel/register.js +1 -0
- package/dist/js/node/dev-tools/dev-server-plugin.js +1 -2
- package/dist/js/node/dev-tools/mock/getMockData.js +29 -2
- package/dist/js/node/dev-tools/mock/index.js +5 -26
- package/dist/js/node/dev-tools/socket-server.js +4 -2
- package/dist/js/node/dev-tools/watcher/index.js +6 -2
- package/dist/js/node/dev-tools/watcher/stats-cache.js +33 -20
- package/dist/js/node/libs/context/context.js +6 -0
- package/dist/js/node/libs/hook-api/route.js +6 -4
- package/dist/js/node/libs/render/index.js +1 -0
- package/dist/js/node/libs/render/ssr.js +8 -2
- package/dist/js/node/libs/route/index.js +0 -1
- package/dist/js/node/libs/route/matcher.js +16 -3
- package/dist/js/node/libs/route/route.js +1 -0
- package/dist/js/node/server/dev-server/dev-server.js +3 -0
- package/dist/js/node/server/index.js +9 -6
- package/dist/js/node/server/modern-server-split.js +1 -1
- package/dist/js/node/server/modern-server.js +9 -5
- package/dist/js/node/utils.js +13 -2
- package/dist/types/dev-tools/mock/getMockData.d.ts +2 -1
- package/dist/types/dev-tools/socket-server.d.ts +1 -2
- package/dist/types/dev-tools/watcher/index.d.ts +2 -1
- package/dist/types/dev-tools/watcher/stats-cache.d.ts +3 -2
- package/dist/types/libs/context/context.d.ts +2 -0
- package/dist/types/libs/hook-api/route.d.ts +3 -2
- package/dist/types/libs/render/ssr.d.ts +1 -0
- package/dist/types/libs/route/matcher.d.ts +1 -1
- package/dist/types/libs/route/route.d.ts +1 -0
- package/dist/types/server/dev-server/dev-server-split.d.ts +3 -3
- package/dist/types/server/modern-server-split.d.ts +3 -3
- package/dist/types/server/modern-server.d.ts +1 -1
- package/dist/types/type.d.ts +5 -3
- package/dist/types/utils.d.ts +2 -1
- package/package.json +8 -6
- package/tests/context.test.ts +12 -1
- package/tests/dev.test.ts +300 -6
- package/tests/fixtures/mock/exist/config/mock/index.ts +11 -0
- package/tests/fixtures/mock/zero/config/mock/index.ts +1 -0
- package/tests/fixtures/route-spec/dynamic.json +13 -0
- package/tests/fixtures/ssr/bundle.js +5 -0
- package/tests/fixtures/watch/a.ts +3 -0
- package/tests/fixtures/watch/index.ts +5 -0
- package/tests/fixtures/watch/stats.txt +1 -0
- package/tests/hook.test.ts +1 -1
- package/tests/route.test.ts +26 -3
- package/tests/ssr.test.ts +34 -0
- package/tests/utils.test.ts +6 -0
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.getWatchedFiles = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
7
9
|
|
|
8
10
|
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
9
11
|
|
|
@@ -18,12 +20,14 @@ const getWatchedFiles = watcher => {
|
|
|
18
20
|
const files = [];
|
|
19
21
|
Object.keys(watched).forEach(dir => {
|
|
20
22
|
watched[dir].forEach(fileName => {
|
|
21
|
-
files.push(
|
|
23
|
+
files.push(_path.default.join(dir, fileName));
|
|
22
24
|
});
|
|
23
25
|
});
|
|
24
26
|
return files;
|
|
25
27
|
};
|
|
26
28
|
|
|
29
|
+
exports.getWatchedFiles = getWatchedFiles;
|
|
30
|
+
|
|
27
31
|
class Watcher {
|
|
28
32
|
constructor() {
|
|
29
33
|
this.dependencyTree = null;
|
|
@@ -7,24 +7,29 @@ exports.StatsCache = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
9
|
|
|
10
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
|
|
12
14
|
class StatsCache {
|
|
13
15
|
constructor() {
|
|
14
|
-
this.
|
|
16
|
+
this.cachedHash = {};
|
|
17
|
+
this.cachedSize = {};
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
add(files) {
|
|
18
21
|
const {
|
|
19
|
-
|
|
22
|
+
cachedHash,
|
|
23
|
+
cachedSize
|
|
20
24
|
} = this;
|
|
21
25
|
|
|
22
26
|
for (const filename of files) {
|
|
23
27
|
if (_fs.default.existsSync(filename)) {
|
|
24
|
-
const
|
|
28
|
+
const stats = _fs.default.statSync(filename);
|
|
25
29
|
|
|
26
|
-
if (
|
|
27
|
-
|
|
30
|
+
if (stats.isFile() && !cachedHash[filename]) {
|
|
31
|
+
cachedHash[filename] = this.hash(stats, filename);
|
|
32
|
+
cachedSize[filename] = stats.size;
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
}
|
|
@@ -32,34 +37,43 @@ class StatsCache {
|
|
|
32
37
|
|
|
33
38
|
refresh(filename) {
|
|
34
39
|
const {
|
|
35
|
-
|
|
40
|
+
cachedHash,
|
|
41
|
+
cachedSize
|
|
36
42
|
} = this;
|
|
37
43
|
|
|
38
44
|
if (_fs.default.existsSync(filename)) {
|
|
39
|
-
const
|
|
45
|
+
const stats = _fs.default.statSync(filename);
|
|
40
46
|
|
|
41
|
-
if (
|
|
42
|
-
|
|
47
|
+
if (stats.isFile()) {
|
|
48
|
+
cachedHash[filename] = this.hash(stats, filename);
|
|
49
|
+
cachedSize[filename] = stats.size;
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
del(filename) {
|
|
48
|
-
if (this.
|
|
49
|
-
delete this.
|
|
55
|
+
if (this.cachedHash[filename]) {
|
|
56
|
+
delete this.cachedHash[filename];
|
|
57
|
+
delete this.cachedSize[filename];
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
isDiff(filename) {
|
|
54
62
|
const {
|
|
55
|
-
|
|
63
|
+
cachedHash,
|
|
64
|
+
cachedSize
|
|
56
65
|
} = this;
|
|
57
66
|
|
|
58
|
-
const
|
|
67
|
+
const stats = _fs.default.statSync(filename);
|
|
68
|
+
|
|
69
|
+
const hash = cachedHash[filename];
|
|
70
|
+
const size = cachedSize[filename];
|
|
59
71
|
|
|
60
|
-
|
|
72
|
+
if (stats.size !== size) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
61
75
|
|
|
62
|
-
if (this.
|
|
76
|
+
if (this.hash(stats, filename) !== hash) {
|
|
63
77
|
return true;
|
|
64
78
|
}
|
|
65
79
|
|
|
@@ -67,12 +81,11 @@ class StatsCache {
|
|
|
67
81
|
}
|
|
68
82
|
|
|
69
83
|
has(filename) {
|
|
70
|
-
return Boolean(this.
|
|
71
|
-
}
|
|
72
|
-
|
|
84
|
+
return Boolean(this.cachedHash[filename]);
|
|
85
|
+
}
|
|
73
86
|
|
|
74
|
-
|
|
75
|
-
return
|
|
87
|
+
hash(stats, filename) {
|
|
88
|
+
return _crypto.default.createHash('md5').update(_fs.default.readFileSync(filename)).digest('hex');
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
}
|
|
@@ -31,10 +31,12 @@ class ModernServerContext {
|
|
|
31
31
|
this.params = {};
|
|
32
32
|
this.logger = void 0;
|
|
33
33
|
this.metrics = void 0;
|
|
34
|
+
this.serverData = void 0;
|
|
34
35
|
this.req = req;
|
|
35
36
|
this.res = res;
|
|
36
37
|
this.logger = req.logger;
|
|
37
38
|
this.metrics = req.metrics;
|
|
39
|
+
this.serverData = {};
|
|
38
40
|
this.bind();
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -53,6 +55,10 @@ class ModernServerContext {
|
|
|
53
55
|
this.params = params;
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
setServerData(key, value) {
|
|
59
|
+
this.serverData[key] = value;
|
|
60
|
+
}
|
|
61
|
+
|
|
56
62
|
getReqHeader(key) {
|
|
57
63
|
const {
|
|
58
64
|
req
|
|
@@ -6,15 +6,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createRouteAPI = void 0;
|
|
7
7
|
|
|
8
8
|
class RouteAPI {
|
|
9
|
-
constructor(matched, router) {
|
|
9
|
+
constructor(matched, router, url) {
|
|
10
10
|
this.router = void 0;
|
|
11
11
|
this.current = void 0;
|
|
12
|
+
this.url = void 0;
|
|
12
13
|
this.current = matched;
|
|
13
14
|
this.router = router;
|
|
15
|
+
this.url = url;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
cur() {
|
|
17
|
-
return this.current.generate();
|
|
19
|
+
return this.current.generate(this.url);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
get(entryName) {
|
|
@@ -22,7 +24,7 @@ class RouteAPI {
|
|
|
22
24
|
router
|
|
23
25
|
} = this;
|
|
24
26
|
const matched = router.matchEntry(entryName);
|
|
25
|
-
return matched ? matched.generate() : null;
|
|
27
|
+
return matched ? matched.generate(this.url) : null;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
use(entryName) {
|
|
@@ -41,6 +43,6 @@ class RouteAPI {
|
|
|
41
43
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
const createRouteAPI = (matched, router) => new RouteAPI(matched, router);
|
|
46
|
+
const createRouteAPI = (matched, router, url) => new RouteAPI(matched, router, url);
|
|
45
47
|
|
|
46
48
|
exports.createRouteAPI = createRouteAPI;
|
|
@@ -11,12 +11,15 @@ var _utils = require("@modern-js/utils");
|
|
|
11
11
|
|
|
12
12
|
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
13
13
|
|
|
14
|
+
var _cookie = _interopRequireDefault(require("cookie"));
|
|
15
|
+
|
|
14
16
|
var _cache = _interopRequireDefault(require("./cache"));
|
|
15
17
|
|
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
19
|
|
|
18
20
|
const render = async (ctx, renderOptions, runner) => {
|
|
19
21
|
const {
|
|
22
|
+
urlPath,
|
|
20
23
|
bundle,
|
|
21
24
|
distDir,
|
|
22
25
|
template,
|
|
@@ -28,11 +31,14 @@ const render = async (ctx, renderOptions, runner) => {
|
|
|
28
31
|
|
|
29
32
|
const context = {
|
|
30
33
|
request: {
|
|
34
|
+
baseUrl: urlPath,
|
|
31
35
|
params: ctx.params,
|
|
32
36
|
pathname: ctx.path,
|
|
37
|
+
host: ctx.host,
|
|
33
38
|
query: ctx.query,
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
url: ctx.href,
|
|
40
|
+
cookieMap: _cookie.default.parse(ctx.headers.cookie || ''),
|
|
41
|
+
headers: ctx.headers
|
|
36
42
|
},
|
|
37
43
|
redirection: {},
|
|
38
44
|
template,
|
|
@@ -9,6 +9,8 @@ var _utils = require("@modern-js/utils");
|
|
|
9
9
|
|
|
10
10
|
var _pathToRegexp = require("path-to-regexp");
|
|
11
11
|
|
|
12
|
+
var _utils2 = require("../../utils");
|
|
13
|
+
|
|
12
14
|
var _route = require("./route");
|
|
13
15
|
|
|
14
16
|
// eslint-disable-next-line no-useless-escape
|
|
@@ -25,8 +27,16 @@ class RouteMatcher {
|
|
|
25
27
|
} // generate modern route object
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
generate() {
|
|
29
|
-
|
|
30
|
+
generate(url) {
|
|
31
|
+
const route = new _route.ModernRoute(this.spec);
|
|
32
|
+
|
|
33
|
+
if (this.urlPath) {
|
|
34
|
+
const params = this.parseURLParams(url);
|
|
35
|
+
route.urlPath = (0, _utils2.toPath)(route.urlPath, params);
|
|
36
|
+
route.params = params;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return route;
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
parseURLParams(pathname) {
|
|
@@ -84,9 +94,12 @@ class RouteMatcher {
|
|
|
84
94
|
|
|
85
95
|
if (useReg) {
|
|
86
96
|
this.urlMatcher = (0, _pathToRegexp.match)(urlPath, {
|
|
97
|
+
end: false,
|
|
87
98
|
decode: decodeURIComponent
|
|
88
99
|
});
|
|
89
|
-
this.urlReg = (0, _pathToRegexp.pathToRegexp)(urlPath
|
|
100
|
+
this.urlReg = (0, _pathToRegexp.pathToRegexp)(urlPath, [], {
|
|
101
|
+
end: false
|
|
102
|
+
});
|
|
90
103
|
}
|
|
91
104
|
}
|
|
92
105
|
|
|
@@ -147,6 +147,8 @@ class ModernDevServer extends _modernServer.ModernServer {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
async close() {
|
|
150
|
+
var _this$socketServer2;
|
|
151
|
+
|
|
150
152
|
super.close();
|
|
151
153
|
await this.watcher.close();
|
|
152
154
|
await new Promise(resolve => {
|
|
@@ -158,6 +160,7 @@ class ModernDevServer extends _modernServer.ModernServer {
|
|
|
158
160
|
resolve();
|
|
159
161
|
}
|
|
160
162
|
});
|
|
163
|
+
(_this$socketServer2 = this.socketServer) === null || _this$socketServer2 === void 0 ? void 0 : _this$socketServer2.close();
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
async createHTTPServer(handler) {
|
|
@@ -7,7 +7,7 @@ exports.Server = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _serverCore = require("@modern-js/server-core");
|
|
11
11
|
|
|
12
12
|
var _utils = require("@modern-js/utils");
|
|
13
13
|
|
|
@@ -131,22 +131,25 @@ class Server {
|
|
|
131
131
|
const {
|
|
132
132
|
options
|
|
133
133
|
} = this;
|
|
134
|
+
|
|
135
|
+
_serverCore.serverManager.clear();
|
|
136
|
+
|
|
134
137
|
(_options$plugins = options.plugins) === null || _options$plugins === void 0 ? void 0 : _options$plugins.forEach(p => {
|
|
135
|
-
|
|
138
|
+
_serverCore.serverManager.usePlugin((0, _utils.compatRequire)(p.pluginPath));
|
|
136
139
|
});
|
|
137
140
|
const appContext = await this.initAppContext();
|
|
138
141
|
|
|
139
|
-
|
|
142
|
+
_serverCore.serverManager.run(() => {
|
|
140
143
|
var _options$config$outpu;
|
|
141
144
|
|
|
142
|
-
|
|
145
|
+
_serverCore.ConfigContext.set(this.options.config);
|
|
143
146
|
|
|
144
|
-
|
|
147
|
+
_serverCore.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
145
148
|
distDirectory: _path.default.join(options.pwd, ((_options$config$outpu = options.config.output) === null || _options$config$outpu === void 0 ? void 0 : _options$config$outpu.path) || 'dist')
|
|
146
149
|
}));
|
|
147
150
|
});
|
|
148
151
|
|
|
149
|
-
return
|
|
152
|
+
return _serverCore.serverManager.init({});
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
async initAppContext() {
|
|
@@ -388,7 +388,7 @@ class ModernServer {
|
|
|
388
388
|
return;
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
const routeAPI = (0, _route2.createRouteAPI)(matched, this.router);
|
|
391
|
+
const routeAPI = (0, _route2.createRouteAPI)(matched, this.router, context.url);
|
|
392
392
|
await this.emitRouteHook('afterMatch', {
|
|
393
393
|
context,
|
|
394
394
|
routeAPI
|
|
@@ -401,9 +401,12 @@ class ModernServer {
|
|
|
401
401
|
const {
|
|
402
402
|
current
|
|
403
403
|
} = routeAPI;
|
|
404
|
-
const route = current.generate();
|
|
405
|
-
|
|
406
|
-
context.
|
|
404
|
+
const route = current.generate(context.url);
|
|
405
|
+
context.setParams(route.params);
|
|
406
|
+
context.setServerData('router', {
|
|
407
|
+
baseUrl: route.urlPath,
|
|
408
|
+
params: route.params
|
|
409
|
+
}); // route is api service
|
|
407
410
|
|
|
408
411
|
if (route.isApi) {
|
|
409
412
|
this.handleAPI(context);
|
|
@@ -448,6 +451,7 @@ class ModernServer {
|
|
|
448
451
|
templateAPI
|
|
449
452
|
});
|
|
450
453
|
await this.injectMicroFE(context, templateAPI);
|
|
454
|
+
templateAPI.appendHead(`<script>window._SERVER_DATA=${JSON.stringify(context.serverData)}</script>`);
|
|
451
455
|
response = templateAPI.get();
|
|
452
456
|
}
|
|
453
457
|
|
|
@@ -590,7 +594,7 @@ class ModernServer {
|
|
|
590
594
|
const matched = this.router.match(statusPage) || this.router.match(customErrorPage); // if no custom status page find
|
|
591
595
|
|
|
592
596
|
if (matched) {
|
|
593
|
-
const route = matched.generate();
|
|
597
|
+
const route = matched.generate(context.url);
|
|
594
598
|
const {
|
|
595
599
|
entryName
|
|
596
600
|
} = route; // check entryName, aviod matched '/' route
|
package/dist/js/node/utils.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.toMessage = exports.noop = exports.mergeExtension = exports.createMiddlewareCollecter = exports.createErrorDocument = void 0;
|
|
6
|
+
exports.toPath = exports.toMessage = exports.noop = exports.mergeExtension = exports.createMiddlewareCollecter = exports.createErrorDocument = void 0;
|
|
7
|
+
|
|
8
|
+
var _pathToRegexp = require("path-to-regexp");
|
|
7
9
|
|
|
8
10
|
const mergeExtension = users => {
|
|
9
11
|
const output = [];
|
|
@@ -91,4 +93,13 @@ const createMiddlewareCollecter = () => {
|
|
|
91
93
|
};
|
|
92
94
|
};
|
|
93
95
|
|
|
94
|
-
exports.createMiddlewareCollecter = createMiddlewareCollecter;
|
|
96
|
+
exports.createMiddlewareCollecter = createMiddlewareCollecter;
|
|
97
|
+
|
|
98
|
+
const toPath = (reg, params) => {
|
|
99
|
+
const fn = (0, _pathToRegexp.compile)(reg, {
|
|
100
|
+
encode: encodeURIComponent
|
|
101
|
+
});
|
|
102
|
+
return fn(params);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
exports.toPath = toPath;
|
|
@@ -15,4 +15,5 @@ declare const createStaticDataHandler: (method: string, handler: Record<string,
|
|
|
15
15
|
|
|
16
16
|
declare const _default: (filepath: string) => MockApi[];
|
|
17
17
|
|
|
18
|
-
export default _default;
|
|
18
|
+
export default _default;
|
|
19
|
+
export declare const getMatched: (context: ModernServerContext, mockApiList: MockApi[]) => MockApi | undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Server } from 'http';
|
|
3
|
-
import ws from 'ws';
|
|
4
3
|
import type { Stats } from 'webpack';
|
|
5
4
|
import { DevServerOptions } from '../type';
|
|
6
5
|
export default class SocketServer {
|
|
@@ -13,7 +12,7 @@ export default class SocketServer {
|
|
|
13
12
|
prepare(app: Server): void;
|
|
14
13
|
updateStats(stats: Stats): void;
|
|
15
14
|
sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
|
|
16
|
-
close(
|
|
15
|
+
close(): void;
|
|
17
16
|
private getStats;
|
|
18
17
|
private sendStats;
|
|
19
18
|
private send;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export declare class StatsCache {
|
|
2
|
-
private readonly
|
|
2
|
+
private readonly cachedHash;
|
|
3
|
+
private readonly cachedSize;
|
|
3
4
|
add(files: string[]): void;
|
|
4
5
|
refresh(filename: string): void;
|
|
5
6
|
del(filename: string): void;
|
|
6
7
|
isDiff(filename: string): boolean;
|
|
7
8
|
has(filename: string): boolean;
|
|
8
|
-
private
|
|
9
|
+
private hash;
|
|
9
10
|
}
|
|
@@ -26,9 +26,11 @@ export declare class ModernServerContext implements ModernServerContextInterface
|
|
|
26
26
|
params: Record<string, string>;
|
|
27
27
|
logger: Logger;
|
|
28
28
|
metrics?: Metrics;
|
|
29
|
+
serverData: Record<string, any>;
|
|
29
30
|
constructor(req: IncomingMessage, res: ServerResponse);
|
|
30
31
|
private bind;
|
|
31
32
|
setParams(params: Record<string, string>): void;
|
|
33
|
+
setServerData(key: string, value: any): void;
|
|
32
34
|
getReqHeader(key: string): string | string[];
|
|
33
35
|
get headers(): import("http").IncomingHttpHeaders;
|
|
34
36
|
get method(): string;
|
|
@@ -3,11 +3,12 @@ import { RouteMatchManager, RouteMatcher } from '../route';
|
|
|
3
3
|
declare class RouteAPI {
|
|
4
4
|
private readonly router;
|
|
5
5
|
private current;
|
|
6
|
-
|
|
6
|
+
private readonly url;
|
|
7
|
+
constructor(matched: RouteMatcher, router: RouteMatchManager, url: string);
|
|
7
8
|
cur(): import("../route").ModernRoute;
|
|
8
9
|
get(entryName: string): import("../route").ModernRoute | null;
|
|
9
10
|
use(entryName: string): boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export declare const createRouteAPI: (matched: RouteMatcher, router: RouteMatchManager) => RouteAPI;
|
|
13
|
+
export declare const createRouteAPI: (matched: RouteMatcher, router: RouteMatchManager, url: string) => RouteAPI;
|
|
13
14
|
export {};
|
|
@@ -6,7 +6,7 @@ export declare class RouteMatcher {
|
|
|
6
6
|
urlMatcher?: MatchFunction;
|
|
7
7
|
urlReg?: RegExp;
|
|
8
8
|
constructor(spec: ModernRouteInterface);
|
|
9
|
-
generate(): ModernRoute;
|
|
9
|
+
generate(url: string): ModernRoute;
|
|
10
10
|
parseURLParams(pathname: string): Record<string, string>;
|
|
11
11
|
matchLength(pathname: string): number | null;
|
|
12
12
|
matchUrlPath(requestUrl: string): boolean;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { APIServerStartInput } from '@modern-js/server-
|
|
1
|
+
import type { APIServerStartInput } from '@modern-js/server-core';
|
|
2
2
|
import { mergeExtension } from '../../utils';
|
|
3
3
|
import { ModernRouteInterface } from '../../libs/route';
|
|
4
4
|
import { ApiServerMode } from '../../constants';
|
|
5
5
|
import { ModernDevServer } from './dev-server';
|
|
6
6
|
export declare class ModernSSRDevServer extends ModernDevServer {
|
|
7
7
|
protected prepareAPIHandler(_m: ApiServerMode, _: APIServerStartInput['config']): any;
|
|
8
|
-
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-
|
|
8
|
+
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-core").Adapter>;
|
|
9
9
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
10
10
|
}
|
|
11
11
|
export declare class ModernAPIDevServer extends ModernDevServer {
|
|
12
|
-
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-
|
|
12
|
+
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-core").Adapter>;
|
|
13
13
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
14
14
|
protected preServerInit(): Promise<void>;
|
|
15
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIServerStartInput } from '@modern-js/server-
|
|
1
|
+
import { APIServerStartInput } from '@modern-js/server-core';
|
|
2
2
|
import { mergeExtension } from '../utils';
|
|
3
3
|
import { ModernRoute, ModernRouteInterface, RouteMatcher } from '../libs/route';
|
|
4
4
|
import { ApiServerMode } from '../constants';
|
|
@@ -8,14 +8,14 @@ export declare class ModernSSRServer extends ModernServer {
|
|
|
8
8
|
protected warmupSSRBundle(): Promise<void>;
|
|
9
9
|
protected verifyMatch(context: ModernServerContext, matched: RouteMatcher): void;
|
|
10
10
|
protected prepareAPIHandler(_m: ApiServerMode, _: APIServerStartInput['config']): any;
|
|
11
|
-
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-
|
|
11
|
+
protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-core").Adapter>;
|
|
12
12
|
protected preServerInit(): Promise<void>;
|
|
13
13
|
}
|
|
14
14
|
export declare class ModernAPIServer extends ModernServer {
|
|
15
15
|
protected emitRouteHook(_: string, _input: any): Promise<void>;
|
|
16
16
|
protected warmupSSRBundle(): Promise<void>;
|
|
17
17
|
protected prepareWebHandler(_: ReturnType<typeof mergeExtension>): any;
|
|
18
|
-
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-
|
|
18
|
+
protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-core").Adapter>;
|
|
19
19
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
20
20
|
protected preServerInit(): Promise<void>;
|
|
21
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage, ServerResponse, Server } from 'http';
|
|
3
|
-
import { Adapter, APIServerStartInput } from '@modern-js/server-
|
|
3
|
+
import { Adapter, APIServerStartInput } from '@modern-js/server-core';
|
|
4
4
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
5
5
|
import { ModernServerOptions, NextFunction, ServerHookRunner, Metrics, Logger, ReadyOptions } from '../type';
|
|
6
6
|
import { RouteMatchManager, ModernRouteInterface, ModernRoute, RouteMatcher } from '../libs/route';
|
package/dist/types/type.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type Webpack from 'webpack';
|
|
3
|
-
import { serverManager } from '@modern-js/server-
|
|
3
|
+
import { serverManager } from '@modern-js/server-core';
|
|
4
4
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
5
5
|
import type { Metrics, Logger, NextFunction } from '@modern-js/types/server';
|
|
6
6
|
import { ModernRouteInterface } from './libs/route';
|
|
@@ -41,9 +41,11 @@ export declare type DevServerOptions = {
|
|
|
41
41
|
export declare type ModernServerOptions = {
|
|
42
42
|
pwd: string;
|
|
43
43
|
config: NormalizedConfig;
|
|
44
|
-
plugins?:
|
|
44
|
+
plugins?: {
|
|
45
|
+
pluginPath: string;
|
|
46
|
+
}[];
|
|
45
47
|
dev?: boolean | Partial<DevServerOptions>;
|
|
46
|
-
compiler?: Webpack.MultiCompiler | Webpack.Compiler;
|
|
48
|
+
compiler?: Webpack.MultiCompiler | Webpack.Compiler | null;
|
|
47
49
|
routes?: ModernRouteInterface[];
|
|
48
50
|
staticGenerate?: boolean;
|
|
49
51
|
customServer?: boolean;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ export declare const createMiddlewareCollecter: () => {
|
|
|
12
12
|
getMiddlewares: () => CollectMiddlewaresResult;
|
|
13
13
|
addWebMiddleware: (input: any) => void;
|
|
14
14
|
addAPIMiddleware: (input: any) => void;
|
|
15
|
-
};
|
|
15
|
+
};
|
|
16
|
+
export declare const toPath: (reg: string, params: Record<string, any>) => string;
|