@modern-js/server 1.0.0-rc.2 → 1.0.0-rc.7
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 +74 -0
- package/README.md +1 -1
- package/dist/js/modern/dev-tools/babel/register.js +0 -19
- package/dist/js/modern/libs/render/index.js +2 -1
- package/dist/js/modern/libs/render/reader.js +1 -1
- package/dist/js/modern/libs/route/matcher.js +3 -2
- package/dist/js/modern/server/modern-server.js +17 -9
- package/dist/js/node/dev-tools/babel/register.js +0 -24
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +1 -1
- package/dist/js/node/libs/render/cache/util.js +5 -5
- package/dist/js/node/libs/render/index.js +3 -1
- package/dist/js/node/libs/render/modern/index.js +1 -1
- package/dist/js/node/libs/render/reader.js +2 -2
- package/dist/js/node/libs/route/matcher.js +4 -2
- package/dist/js/node/server/api-server.js +1 -1
- package/dist/js/node/server/modern-server.js +17 -9
- package/dist/js/node/server/web-server.js +1 -1
- package/dist/js/node/utils.js +1 -1
- package/dist/types/libs/render/reader.d.ts +2 -1
- package/dist/types/type.d.ts +2 -1
- package/package.json +14 -11
- package/src/dev-tools/babel/register.ts +0 -16
- package/src/libs/render/cache/index.ts +1 -1
- package/src/libs/render/index.ts +2 -1
- package/src/libs/render/reader.ts +3 -2
- package/src/libs/route/matcher.ts +3 -1
- package/src/server/modern-server.ts +12 -8
- package/src/type.ts +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @modern-js/server
|
|
2
|
+
|
|
3
|
+
## 1.0.0-rc.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 224f7fe: fix server route match
|
|
8
|
+
- 204c626: feat: initial
|
|
9
|
+
- Updated dependencies [224f7fe]
|
|
10
|
+
- Updated dependencies [204c626]
|
|
11
|
+
- @modern-js/core@1.0.0-rc.7
|
|
12
|
+
- @modern-js/hmr-client@1.0.0-rc.7
|
|
13
|
+
- @modern-js/server-plugin@1.0.0-rc.7
|
|
14
|
+
- @modern-js/plugin-polyfill@1.0.0-rc.7
|
|
15
|
+
- @modern-js/server-utils@1.0.0-rc.7
|
|
16
|
+
- @modern-js/utils@1.0.0-rc.7
|
|
17
|
+
|
|
18
|
+
## 1.0.0-rc.6
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 224f7fe: fix server route match
|
|
23
|
+
- 204c626: feat: initial
|
|
24
|
+
- Updated dependencies [224f7fe]
|
|
25
|
+
- Updated dependencies [204c626]
|
|
26
|
+
- @modern-js/core@1.0.0-rc.6
|
|
27
|
+
- @modern-js/hmr-client@1.0.0-rc.6
|
|
28
|
+
- @modern-js/server-plugin@1.0.0-rc.6
|
|
29
|
+
- @modern-js/plugin-polyfill@1.0.0-rc.6
|
|
30
|
+
- @modern-js/server-utils@1.0.0-rc.6
|
|
31
|
+
- @modern-js/utils@1.0.0-rc.6
|
|
32
|
+
|
|
33
|
+
## 1.0.0-rc.5
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 224f7fe: fix server route match
|
|
38
|
+
- 204c626: feat: initial
|
|
39
|
+
- Updated dependencies [224f7fe]
|
|
40
|
+
- Updated dependencies [204c626]
|
|
41
|
+
- @modern-js/core@1.0.0-rc.5
|
|
42
|
+
- @modern-js/hmr-client@1.0.0-rc.5
|
|
43
|
+
- @modern-js/server-plugin@1.0.0-rc.5
|
|
44
|
+
- @modern-js/plugin-polyfill@1.0.0-rc.5
|
|
45
|
+
- @modern-js/server-utils@1.0.0-rc.5
|
|
46
|
+
- @modern-js/utils@1.0.0-rc.5
|
|
47
|
+
|
|
48
|
+
## 1.0.0-rc.4
|
|
49
|
+
|
|
50
|
+
### Patch Changes
|
|
51
|
+
|
|
52
|
+
- fix server route match
|
|
53
|
+
- 204c626: feat: initial
|
|
54
|
+
- Updated dependencies [undefined]
|
|
55
|
+
- Updated dependencies [204c626]
|
|
56
|
+
- @modern-js/core@1.0.0-rc.4
|
|
57
|
+
- @modern-js/hmr-client@1.0.0-rc.4
|
|
58
|
+
- @modern-js/server-plugin@1.0.0-rc.4
|
|
59
|
+
- @modern-js/plugin-polyfill@1.0.0-rc.4
|
|
60
|
+
- @modern-js/server-utils@1.0.0-rc.4
|
|
61
|
+
- @modern-js/utils@1.0.0-rc.4
|
|
62
|
+
|
|
63
|
+
## 1.0.0-rc.3
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- feat: initial
|
|
68
|
+
- Updated dependencies [undefined]
|
|
69
|
+
- @modern-js/core@1.0.0-rc.3
|
|
70
|
+
- @modern-js/hmr-client@1.0.0-rc.3
|
|
71
|
+
- @modern-js/server-plugin@1.0.0-rc.3
|
|
72
|
+
- @modern-js/plugin-polyfill@1.0.0-rc.3
|
|
73
|
+
- @modern-js/server-utils@1.0.0-rc.3
|
|
74
|
+
- @modern-js/utils@1.0.0-rc.3
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
<p align="center">
|
|
3
|
-
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs.png" width="300" alt="Modern.js Logo" /></a>
|
|
3
|
+
<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>
|
|
4
4
|
</p>
|
|
5
5
|
|
|
6
6
|
<p align="center">现代 Web 工程体系</p>
|
|
@@ -5,27 +5,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
5
|
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
6
|
|
|
7
7
|
import path from 'path';
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import JSON5 from 'json5';
|
|
10
8
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
11
9
|
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
12
10
|
export const enableRegister = (projectRoot, config) => {
|
|
13
|
-
const tsConfigPath = path.join(projectRoot, 'tsconfig.json');
|
|
14
|
-
const isTsProject = fs.existsSync(tsConfigPath);
|
|
15
|
-
|
|
16
|
-
if (isTsProject) {
|
|
17
|
-
const tsConfig = fs.readFileSync(tsConfigPath).toString();
|
|
18
|
-
const tsConfigJson = JSON5.parse(tsConfig);
|
|
19
|
-
const {
|
|
20
|
-
compilerOptions
|
|
21
|
-
} = tsConfigJson;
|
|
22
|
-
|
|
23
|
-
require('tsconfig-paths').register({
|
|
24
|
-
baseUrl: compilerOptions.baseUrl || path.dirname(tsConfigPath),
|
|
25
|
-
paths: compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.paths ? compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.paths : {}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
11
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
30
12
|
const tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
31
13
|
const babelConfig = resolveBabelConfig(projectRoot, config, {
|
|
@@ -42,7 +24,6 @@ export const enableRegister = (projectRoot, config) => {
|
|
|
42
24
|
|
|
43
25
|
return registerDirs.some(registerDir => filePath.startsWith(path.join(projectRoot, registerDir)));
|
|
44
26
|
}],
|
|
45
|
-
// ignore: [/node_modules/],
|
|
46
27
|
extensions: ['.js', '.ts'],
|
|
47
28
|
babelrc: false,
|
|
48
29
|
root: projectRoot
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import mime from 'mime-types';
|
|
3
4
|
import { handleDirectory } from "./static";
|
|
4
5
|
import { readFile } from "./reader";
|
|
5
6
|
import * as ssr from "./ssr";
|
|
@@ -54,6 +55,6 @@ export const createRenderHandler = ({
|
|
|
54
55
|
|
|
55
56
|
return {
|
|
56
57
|
content,
|
|
57
|
-
contentType:
|
|
58
|
+
contentType: mime.contentType(path.extname(templateHTML))
|
|
58
59
|
};
|
|
59
60
|
};
|
|
@@ -7,7 +7,7 @@ const MB = 1024 * KB;
|
|
|
7
7
|
const getContentLength = cache => cache.content.length;
|
|
8
8
|
|
|
9
9
|
const createCacheItem = async (filepath, mtime) => {
|
|
10
|
-
const content = await fs.readFile(filepath
|
|
10
|
+
const content = await fs.readFile(filepath);
|
|
11
11
|
return {
|
|
12
12
|
content,
|
|
13
13
|
mtime
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { removeTailSlash } from '@modern-js/utils';
|
|
1
2
|
import { match, pathToRegexp } from 'path-to-regexp';
|
|
2
3
|
import { ModernRoute } from "./route"; // eslint-disable-next-line no-useless-escape
|
|
3
4
|
|
|
@@ -47,7 +48,7 @@ export class RouteMatcher {
|
|
|
47
48
|
} else {
|
|
48
49
|
if (urlWithoutSlash.startsWith(this.urlPath)) {
|
|
49
50
|
// avoid /abcd match /a
|
|
50
|
-
if (urlWithoutSlash.length > this.urlPath.length && !urlWithoutSlash.startsWith(`${this.urlPath}/`)) {
|
|
51
|
+
if (this.urlPath !== '/' && urlWithoutSlash.length > this.urlPath.length && !urlWithoutSlash.startsWith(`${this.urlPath}/`)) {
|
|
51
52
|
return false;
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -63,7 +64,7 @@ export class RouteMatcher {
|
|
|
63
64
|
const {
|
|
64
65
|
urlPath
|
|
65
66
|
} = this.spec;
|
|
66
|
-
this.urlPath = urlPath;
|
|
67
|
+
this.urlPath = urlPath === '/' ? urlPath : removeTailSlash(urlPath);
|
|
67
68
|
const useReg = regCharsDetector.test(urlPath);
|
|
68
69
|
|
|
69
70
|
if (useReg) {
|
|
@@ -73,6 +73,8 @@ export class ModernServer {
|
|
|
73
73
|
if (staticGenerate) {
|
|
74
74
|
this.staticGenerate = staticGenerate;
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
process.env.BUILD_TYPE = `${this.staticGenerate || false}`;
|
|
76
78
|
} // exposed requestHandler
|
|
77
79
|
|
|
78
80
|
|
|
@@ -319,16 +321,22 @@ export class ModernServer {
|
|
|
319
321
|
return;
|
|
320
322
|
}
|
|
321
323
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
templateAPI
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
324
|
+
let response = file.content;
|
|
325
|
+
|
|
326
|
+
if (route.entryName) {
|
|
327
|
+
const templateAPI = createTemplateAPI(file.content.toString());
|
|
328
|
+
await this.runner.afterRender({
|
|
329
|
+
context,
|
|
330
|
+
templateAPI
|
|
331
|
+
}, {
|
|
332
|
+
onLast: noop
|
|
333
|
+
});
|
|
334
|
+
await this.injectMicroFE(context, templateAPI);
|
|
335
|
+
response = templateAPI.get();
|
|
336
|
+
}
|
|
337
|
+
|
|
330
338
|
context.res.setHeader('content-type', file.contentType);
|
|
331
|
-
context.res.end(
|
|
339
|
+
context.res.end(response);
|
|
332
340
|
} // eslint-disable-next-line max-statements
|
|
333
341
|
|
|
334
342
|
|
|
@@ -7,10 +7,6 @@ exports.enableRegister = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
|
|
10
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
|
|
12
|
-
var _json = _interopRequireDefault(require("json5"));
|
|
13
|
-
|
|
14
10
|
var _serverUtils = require("@modern-js/server-utils");
|
|
15
11
|
|
|
16
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -24,25 +20,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
24
20
|
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
25
21
|
|
|
26
22
|
const enableRegister = (projectRoot, config) => {
|
|
27
|
-
const tsConfigPath = _path.default.join(projectRoot, 'tsconfig.json');
|
|
28
|
-
|
|
29
|
-
const isTsProject = _fs.default.existsSync(tsConfigPath);
|
|
30
|
-
|
|
31
|
-
if (isTsProject) {
|
|
32
|
-
const tsConfig = _fs.default.readFileSync(tsConfigPath).toString();
|
|
33
|
-
|
|
34
|
-
const tsConfigJson = _json.default.parse(tsConfig);
|
|
35
|
-
|
|
36
|
-
const {
|
|
37
|
-
compilerOptions
|
|
38
|
-
} = tsConfigJson;
|
|
39
|
-
|
|
40
|
-
require('tsconfig-paths').register({
|
|
41
|
-
baseUrl: compilerOptions.baseUrl || _path.default.dirname(tsConfigPath),
|
|
42
|
-
paths: compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.paths ? compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.paths : {}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
23
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
47
24
|
|
|
48
25
|
const tsconfigPath = _path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
@@ -61,7 +38,6 @@ const enableRegister = (projectRoot, config) => {
|
|
|
61
38
|
|
|
62
39
|
return registerDirs.some(registerDir => filePath.startsWith(_path.default.join(projectRoot, registerDir)));
|
|
63
40
|
}],
|
|
64
|
-
// ignore: [/node_modules/],
|
|
65
41
|
extensions: ['.js', '.ts'],
|
|
66
42
|
babelrc: false,
|
|
67
43
|
root: projectRoot
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.fname = fname;
|
|
6
|
+
exports.cacheAddition = cacheAddition;
|
|
8
7
|
exports.connectFactor = connectFactor;
|
|
9
|
-
exports.
|
|
8
|
+
exports.fname = fname;
|
|
10
9
|
exports.getTime = getTime;
|
|
11
|
-
exports.cacheAddition = cacheAddition;
|
|
12
|
-
exports.withCoalescedInvoke = withCoalescedInvoke;
|
|
13
10
|
exports.maybeSync = maybeSync;
|
|
11
|
+
exports.namespaceHash = namespaceHash;
|
|
12
|
+
exports.valueFactory = valueFactory;
|
|
13
|
+
exports.withCoalescedInvoke = withCoalescedInvoke;
|
|
14
14
|
|
|
15
15
|
var _url = _interopRequireDefault(require("url"));
|
|
16
16
|
|
|
@@ -9,6 +9,8 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
|
|
10
10
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
11
|
|
|
12
|
+
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
13
|
+
|
|
12
14
|
var _static = require("./static");
|
|
13
15
|
|
|
14
16
|
var _reader = require("./reader");
|
|
@@ -77,7 +79,7 @@ const createRenderHandler = ({
|
|
|
77
79
|
|
|
78
80
|
return {
|
|
79
81
|
content,
|
|
80
|
-
contentType:
|
|
82
|
+
contentType: _mimeTypes.default.contentType(_path.default.extname(templateHTML))
|
|
81
83
|
};
|
|
82
84
|
};
|
|
83
85
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.updateFile = exports.readFile = exports.init = exports.close = void 0;
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
@@ -18,7 +18,7 @@ const MB = 1024 * KB;
|
|
|
18
18
|
const getContentLength = cache => cache.content.length;
|
|
19
19
|
|
|
20
20
|
const createCacheItem = async (filepath, mtime) => {
|
|
21
|
-
const content = await _utils.fs.readFile(filepath
|
|
21
|
+
const content = await _utils.fs.readFile(filepath);
|
|
22
22
|
return {
|
|
23
23
|
content,
|
|
24
24
|
mtime
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.RouteMatcher = void 0;
|
|
7
7
|
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
|
|
8
10
|
var _pathToRegexp = require("path-to-regexp");
|
|
9
11
|
|
|
10
12
|
var _route = require("./route");
|
|
@@ -57,7 +59,7 @@ class RouteMatcher {
|
|
|
57
59
|
} else {
|
|
58
60
|
if (urlWithoutSlash.startsWith(this.urlPath)) {
|
|
59
61
|
// avoid /abcd match /a
|
|
60
|
-
if (urlWithoutSlash.length > this.urlPath.length && !urlWithoutSlash.startsWith(`${this.urlPath}/`)) {
|
|
62
|
+
if (this.urlPath !== '/' && urlWithoutSlash.length > this.urlPath.length && !urlWithoutSlash.startsWith(`${this.urlPath}/`)) {
|
|
61
63
|
return false;
|
|
62
64
|
}
|
|
63
65
|
|
|
@@ -73,7 +75,7 @@ class RouteMatcher {
|
|
|
73
75
|
const {
|
|
74
76
|
urlPath
|
|
75
77
|
} = this.spec;
|
|
76
|
-
this.urlPath = urlPath;
|
|
78
|
+
this.urlPath = urlPath === '/' ? urlPath : (0, _utils.removeTailSlash)(urlPath);
|
|
77
79
|
const useReg = regCharsDetector.test(urlPath);
|
|
78
80
|
|
|
79
81
|
if (useReg) {
|
|
@@ -101,6 +101,8 @@ class ModernServer {
|
|
|
101
101
|
if (staticGenerate) {
|
|
102
102
|
this.staticGenerate = staticGenerate;
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
process.env.BUILD_TYPE = `${this.staticGenerate || false}`;
|
|
104
106
|
} // exposed requestHandler
|
|
105
107
|
|
|
106
108
|
|
|
@@ -352,16 +354,22 @@ class ModernServer {
|
|
|
352
354
|
return;
|
|
353
355
|
}
|
|
354
356
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
templateAPI
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
357
|
+
let response = file.content;
|
|
358
|
+
|
|
359
|
+
if (route.entryName) {
|
|
360
|
+
const templateAPI = (0, _hookApi.createTemplateAPI)(file.content.toString());
|
|
361
|
+
await this.runner.afterRender({
|
|
362
|
+
context,
|
|
363
|
+
templateAPI
|
|
364
|
+
}, {
|
|
365
|
+
onLast: _utils2.noop
|
|
366
|
+
});
|
|
367
|
+
await this.injectMicroFE(context, templateAPI);
|
|
368
|
+
response = templateAPI.get();
|
|
369
|
+
}
|
|
370
|
+
|
|
363
371
|
context.res.setHeader('content-type', file.contentType);
|
|
364
|
-
context.res.end(
|
|
372
|
+
context.res.end(response);
|
|
365
373
|
} // eslint-disable-next-line max-statements
|
|
366
374
|
|
|
367
375
|
|
package/dist/js/node/utils.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.toMessage = exports.noop = exports.mergeExtension = exports.createErrorDocument = void 0;
|
|
7
7
|
|
|
8
8
|
const mergeExtension = (users, plugins) => {
|
|
9
9
|
const output = [];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const readFile: (filepath: string) => Promise<Buffer | undefined>;
|
|
2
3
|
export declare const updateFile: () => void;
|
|
3
4
|
export declare const init: () => void;
|
|
4
5
|
export declare const close: () => void;
|
package/dist/types/type.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type Webpack from 'webpack';
|
|
2
3
|
import { serverManager } from '@modern-js/server-plugin';
|
|
3
4
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
@@ -43,7 +44,7 @@ export declare type ModernServerOptions = {
|
|
|
43
44
|
webOnly?: boolean;
|
|
44
45
|
};
|
|
45
46
|
export declare type RenderResult = {
|
|
46
|
-
content: string;
|
|
47
|
+
content: string | Buffer;
|
|
47
48
|
contentType: string;
|
|
48
49
|
statusCode?: number;
|
|
49
50
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/server",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.7",
|
|
4
4
|
"jsnext:source": "./src/index.ts",
|
|
5
5
|
"types": "./dist/types/index.d.ts",
|
|
6
6
|
"main": "./dist/js/node/index.js",
|
|
@@ -21,19 +21,18 @@
|
|
|
21
21
|
"@babel/preset-typescript": "^7.15.0",
|
|
22
22
|
"@babel/register": "^7.15.3",
|
|
23
23
|
"@babel/runtime": "^7",
|
|
24
|
-
"@modern-js/core": "^1.0.0-rc.
|
|
25
|
-
"@modern-js/hmr-client": "^1.0.0-rc.
|
|
26
|
-
"@modern-js/plugin-polyfill": "^1.0.0-rc.
|
|
27
|
-
"@modern-js/server-plugin": "^1.0.0-rc.
|
|
28
|
-
"@modern-js/server-utils": "^1.0.0-rc.
|
|
29
|
-
"@modern-js/utils": "^1.0.0-rc.
|
|
24
|
+
"@modern-js/core": "^1.0.0-rc.7",
|
|
25
|
+
"@modern-js/hmr-client": "^1.0.0-rc.7",
|
|
26
|
+
"@modern-js/plugin-polyfill": "^1.0.0-rc.7",
|
|
27
|
+
"@modern-js/server-plugin": "^1.0.0-rc.7",
|
|
28
|
+
"@modern-js/server-utils": "^1.0.0-rc.7",
|
|
29
|
+
"@modern-js/utils": "^1.0.0-rc.7",
|
|
30
30
|
"axios": "^0.21.4",
|
|
31
31
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
32
32
|
"chokidar": "^3.5.2",
|
|
33
33
|
"compare-versions": "^3.6.0",
|
|
34
34
|
"fs-extra": "^10.0.0",
|
|
35
35
|
"http-proxy-middleware": "^2.0.1",
|
|
36
|
-
"json5": "^2.2.0",
|
|
37
36
|
"launch-editor": "^2.2.1",
|
|
38
37
|
"lru-cache": "^6.0.0",
|
|
39
38
|
"mime-types": "^2.1.32",
|
|
@@ -48,7 +47,7 @@
|
|
|
48
47
|
"ws": "^8.2.0"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@modern-js/types": "^1.0.0-rc.
|
|
50
|
+
"@modern-js/types": "^1.0.0-rc.7",
|
|
52
51
|
"@types/jest": "^26",
|
|
53
52
|
"@types/lru-cache": "^5.1.1",
|
|
54
53
|
"@types/mime-types": "^2.1.0",
|
|
@@ -64,8 +63,8 @@
|
|
|
64
63
|
"@types/ws": "^7.4.7",
|
|
65
64
|
"typescript": "^4",
|
|
66
65
|
"webpack": "^5.54.0",
|
|
67
|
-
"@modern-js/plugin-testing": "^1.0.0-rc.
|
|
68
|
-
"@modern-js/module-tools": "^1.0.0-rc.
|
|
66
|
+
"@modern-js/plugin-testing": "^1.0.0-rc.7",
|
|
67
|
+
"@modern-js/module-tools": "^1.0.0-rc.7"
|
|
69
68
|
},
|
|
70
69
|
"peerDependencies": {
|
|
71
70
|
"webpack": "^5.54.0"
|
|
@@ -76,6 +75,10 @@
|
|
|
76
75
|
"packageMode": "node-js"
|
|
77
76
|
}
|
|
78
77
|
},
|
|
78
|
+
"publishConfig": {
|
|
79
|
+
"registry": "https://registry.npmjs.org/",
|
|
80
|
+
"access": "public"
|
|
81
|
+
},
|
|
79
82
|
"scripts": {
|
|
80
83
|
"new": "modern new",
|
|
81
84
|
"build": "modern build",
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import JSON5 from 'json5';
|
|
4
2
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
5
3
|
import { ModernServerOptions } from '../../type';
|
|
6
4
|
|
|
@@ -10,19 +8,6 @@ export const enableRegister = (
|
|
|
10
8
|
projectRoot: string,
|
|
11
9
|
config: ModernServerOptions['config'],
|
|
12
10
|
) => {
|
|
13
|
-
const tsConfigPath = path.join(projectRoot, 'tsconfig.json');
|
|
14
|
-
const isTsProject = fs.existsSync(tsConfigPath);
|
|
15
|
-
if (isTsProject) {
|
|
16
|
-
const tsConfig = fs.readFileSync(tsConfigPath).toString();
|
|
17
|
-
const tsConfigJson = JSON5.parse(tsConfig);
|
|
18
|
-
const { compilerOptions } = tsConfigJson;
|
|
19
|
-
|
|
20
|
-
require('tsconfig-paths').register({
|
|
21
|
-
baseUrl: compilerOptions.baseUrl || path.dirname(tsConfigPath),
|
|
22
|
-
paths: compilerOptions?.paths ? compilerOptions?.paths : {},
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
11
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
27
12
|
const tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
28
13
|
|
|
@@ -45,7 +30,6 @@ export const enableRegister = (
|
|
|
45
30
|
);
|
|
46
31
|
},
|
|
47
32
|
],
|
|
48
|
-
// ignore: [/node_modules/],
|
|
49
33
|
extensions: ['.js', '.ts'],
|
|
50
34
|
babelrc: false,
|
|
51
35
|
root: projectRoot,
|
package/src/libs/render/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import mime from 'mime-types';
|
|
3
4
|
import { RenderResult } from '../../type';
|
|
4
5
|
import { ModernRoute } from '../route';
|
|
5
6
|
import { ModernServerContext } from '../context';
|
|
@@ -63,6 +64,6 @@ export const createRenderHandler = ({
|
|
|
63
64
|
|
|
64
65
|
return {
|
|
65
66
|
content,
|
|
66
|
-
contentType:
|
|
67
|
+
contentType: mime.contentType(path.extname(templateHTML)) as string,
|
|
67
68
|
};
|
|
68
69
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
1
2
|
import { fs } from '@modern-js/utils';
|
|
2
3
|
import LRU from 'lru-cache';
|
|
3
4
|
|
|
@@ -6,14 +7,14 @@ const KB = 1024 * Byte;
|
|
|
6
7
|
const MB = 1024 * KB;
|
|
7
8
|
|
|
8
9
|
type FileCache = {
|
|
9
|
-
content:
|
|
10
|
+
content: Buffer;
|
|
10
11
|
mtime: Date;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
const getContentLength = (cache: FileCache) => cache.content.length;
|
|
14
15
|
|
|
15
16
|
const createCacheItem = async (filepath: string, mtime: Date) => {
|
|
16
|
-
const content = await fs.readFile(filepath
|
|
17
|
+
const content = await fs.readFile(filepath);
|
|
17
18
|
|
|
18
19
|
return {
|
|
19
20
|
content,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { removeTailSlash } from '@modern-js/utils';
|
|
1
2
|
import {
|
|
2
3
|
MatchFunction,
|
|
3
4
|
MatchResult,
|
|
@@ -60,6 +61,7 @@ export class RouteMatcher {
|
|
|
60
61
|
if (urlWithoutSlash.startsWith(this.urlPath)) {
|
|
61
62
|
// avoid /abcd match /a
|
|
62
63
|
if (
|
|
64
|
+
this.urlPath !== '/' &&
|
|
63
65
|
urlWithoutSlash.length > this.urlPath.length &&
|
|
64
66
|
!urlWithoutSlash.startsWith(`${this.urlPath}/`)
|
|
65
67
|
) {
|
|
@@ -76,7 +78,7 @@ export class RouteMatcher {
|
|
|
76
78
|
// compiler urlPath to regexp if necessary
|
|
77
79
|
private setupUrlPath() {
|
|
78
80
|
const { urlPath } = this.spec;
|
|
79
|
-
this.urlPath = urlPath;
|
|
81
|
+
this.urlPath = urlPath === '/' ? urlPath : removeTailSlash(urlPath);
|
|
80
82
|
|
|
81
83
|
const useReg = regCharsDetector.test(urlPath);
|
|
82
84
|
if (useReg) {
|
|
@@ -112,6 +112,7 @@ export class ModernServer {
|
|
|
112
112
|
if (staticGenerate) {
|
|
113
113
|
this.staticGenerate = staticGenerate;
|
|
114
114
|
}
|
|
115
|
+
process.env.BUILD_TYPE = `${this.staticGenerate || false}`;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
// exposed requestHandler
|
|
@@ -356,16 +357,19 @@ export class ModernServer {
|
|
|
356
357
|
return;
|
|
357
358
|
}
|
|
358
359
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
360
|
+
let response = file.content;
|
|
361
|
+
if (route.entryName) {
|
|
362
|
+
const templateAPI = createTemplateAPI(file.content.toString());
|
|
363
|
+
await this.runner.afterRender(
|
|
364
|
+
{ context, templateAPI },
|
|
365
|
+
{ onLast: noop as any },
|
|
366
|
+
);
|
|
367
|
+
await this.injectMicroFE(context, templateAPI);
|
|
368
|
+
response = templateAPI.get();
|
|
369
|
+
}
|
|
366
370
|
|
|
367
371
|
context.res.setHeader('content-type', file.contentType);
|
|
368
|
-
context.res.end(
|
|
372
|
+
context.res.end(response);
|
|
369
373
|
}
|
|
370
374
|
|
|
371
375
|
// eslint-disable-next-line max-statements
|
package/src/type.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
1
2
|
import type Webpack from 'webpack';
|
|
2
3
|
import { serverManager } from '@modern-js/server-plugin';
|
|
3
4
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
@@ -50,7 +51,7 @@ export type ModernServerOptions = {
|
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
export type RenderResult = {
|
|
53
|
-
content: string;
|
|
54
|
+
content: string | Buffer;
|
|
54
55
|
contentType: string;
|
|
55
56
|
statusCode?: number;
|
|
56
57
|
};
|