@modern-js/plugin-server 0.0.0-runtime-20211121141552 → 1.1.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/CHANGELOG.md +35 -10
- package/dist/js/modern/server.js +6 -14
- package/dist/js/node/server.js +6 -14
- package/dist/js/treeshaking/server.js +6 -14
- package/jest.config.js +8 -0
- package/package.json +28 -16
- package/tsconfig.json +1 -4
- package/src/cli.ts +0 -97
- package/src/modern-app-env.d.ts +0 -2
- package/src/server.ts +0 -79
package/CHANGELOG.md
CHANGED
@@ -1,18 +1,43 @@
|
|
1
1
|
# @modern-js/plugin-server
|
2
2
|
|
3
|
-
##
|
3
|
+
## 1.1.1
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
|
-
-
|
8
|
-
- Updated dependencies [
|
9
|
-
- Updated dependencies [
|
10
|
-
- Updated dependencies [
|
11
|
-
- @modern-js/core@
|
12
|
-
- @modern-js/server-plugin@
|
13
|
-
- @modern-js/server-utils@
|
14
|
-
- @modern-js/babel-compiler@
|
15
|
-
- @modern-js/utils@
|
7
|
+
- 83166714: change .npmignore
|
8
|
+
- Updated dependencies [83166714]
|
9
|
+
- Updated dependencies [c3de9882]
|
10
|
+
- Updated dependencies [33ff48af]
|
11
|
+
- @modern-js/core@1.3.2
|
12
|
+
- @modern-js/server-plugin@1.2.1
|
13
|
+
- @modern-js/server-utils@1.2.1
|
14
|
+
- @modern-js/babel-compiler@1.2.1
|
15
|
+
- @modern-js/utils@1.2.2
|
16
|
+
|
17
|
+
## 1.1.0
|
18
|
+
|
19
|
+
### Minor Changes
|
20
|
+
|
21
|
+
- cfe11628: Make Modern.js self bootstraping
|
22
|
+
|
23
|
+
### Patch Changes
|
24
|
+
|
25
|
+
- 146dcd85: modify server framework plugin hook types and hook context
|
26
|
+
- 146dcd85: modify server framework plugin hook types
|
27
|
+
- 146dcd85: fix test case in babel compiler
|
28
|
+
- Updated dependencies [2da09c69]
|
29
|
+
- Updated dependencies [fc71e36f]
|
30
|
+
- Updated dependencies [146dcd85]
|
31
|
+
- Updated dependencies [c3d46ee4]
|
32
|
+
- Updated dependencies [cfe11628]
|
33
|
+
- Updated dependencies [146dcd85]
|
34
|
+
- Updated dependencies [146dcd85]
|
35
|
+
- Updated dependencies [1ebc7ee2]
|
36
|
+
- @modern-js/utils@1.2.0
|
37
|
+
- @modern-js/core@1.3.0
|
38
|
+
- @modern-js/server-utils@1.2.0
|
39
|
+
- @modern-js/server-plugin@1.2.0
|
40
|
+
- @modern-js/babel-compiler@1.2.0
|
16
41
|
|
17
42
|
## 1.0.1
|
18
43
|
|
package/dist/js/modern/server.js
CHANGED
@@ -1,9 +1,3 @@
|
|
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
|
-
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
|
-
|
7
1
|
import path from 'path';
|
8
2
|
import { createPlugin } from '@modern-js/server-plugin';
|
9
3
|
import { useAppContext } from '@modern-js/core';
|
@@ -73,7 +67,7 @@ export default createPlugin(() => {
|
|
73
67
|
}, next) {
|
74
68
|
var _storage$hooks$before, _storage$hooks;
|
75
69
|
|
76
|
-
return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks,
|
70
|
+
return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks, context, next);
|
77
71
|
},
|
78
72
|
|
79
73
|
afterMatch({
|
@@ -82,9 +76,8 @@ export default createPlugin(() => {
|
|
82
76
|
}, next) {
|
83
77
|
var _storage$hooks$afterM, _storage$hooks2;
|
84
78
|
|
85
|
-
|
86
|
-
|
87
|
-
}), next);
|
79
|
+
context.router = routeAPI;
|
80
|
+
return (_storage$hooks$afterM = (_storage$hooks2 = storage.hooks).afterMatch) === null || _storage$hooks$afterM === void 0 ? void 0 : _storage$hooks$afterM.call(_storage$hooks2, context, next);
|
88
81
|
},
|
89
82
|
|
90
83
|
beforeRender({
|
@@ -92,7 +85,7 @@ export default createPlugin(() => {
|
|
92
85
|
}, next) {
|
93
86
|
var _storage$hooks$before2, _storage$hooks3;
|
94
87
|
|
95
|
-
return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3,
|
88
|
+
return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3, context, next);
|
96
89
|
},
|
97
90
|
|
98
91
|
afterRender({
|
@@ -101,9 +94,8 @@ export default createPlugin(() => {
|
|
101
94
|
}, next) {
|
102
95
|
var _storage$hooks$afterR, _storage$hooks4;
|
103
96
|
|
104
|
-
|
105
|
-
|
106
|
-
}), next);
|
97
|
+
context.template = templateAPI;
|
98
|
+
return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, context, next);
|
107
99
|
}
|
108
100
|
|
109
101
|
};
|
package/dist/js/node/server.js
CHANGED
@@ -15,12 +15,6 @@ var _utils = require("@modern-js/utils");
|
|
15
15
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
17
|
|
18
|
-
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; }
|
19
|
-
|
20
|
-
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; }
|
21
|
-
|
22
|
-
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; }
|
23
|
-
|
24
18
|
const WEB_APP_NAME = 'index';
|
25
19
|
|
26
20
|
class Storage {
|
@@ -89,7 +83,7 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
|
|
89
83
|
}, next) {
|
90
84
|
var _storage$hooks$before, _storage$hooks;
|
91
85
|
|
92
|
-
return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks,
|
86
|
+
return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks, context, next);
|
93
87
|
},
|
94
88
|
|
95
89
|
afterMatch({
|
@@ -98,9 +92,8 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
|
|
98
92
|
}, next) {
|
99
93
|
var _storage$hooks$afterM, _storage$hooks2;
|
100
94
|
|
101
|
-
|
102
|
-
|
103
|
-
}), next);
|
95
|
+
context.router = routeAPI;
|
96
|
+
return (_storage$hooks$afterM = (_storage$hooks2 = storage.hooks).afterMatch) === null || _storage$hooks$afterM === void 0 ? void 0 : _storage$hooks$afterM.call(_storage$hooks2, context, next);
|
104
97
|
},
|
105
98
|
|
106
99
|
beforeRender({
|
@@ -108,7 +101,7 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
|
|
108
101
|
}, next) {
|
109
102
|
var _storage$hooks$before2, _storage$hooks3;
|
110
103
|
|
111
|
-
return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3,
|
104
|
+
return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3, context, next);
|
112
105
|
},
|
113
106
|
|
114
107
|
afterRender({
|
@@ -117,9 +110,8 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
|
|
117
110
|
}, next) {
|
118
111
|
var _storage$hooks$afterR, _storage$hooks4;
|
119
112
|
|
120
|
-
|
121
|
-
|
122
|
-
}), next);
|
113
|
+
context.template = templateAPI;
|
114
|
+
return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, context, next);
|
123
115
|
}
|
124
116
|
|
125
117
|
};
|
@@ -1,9 +1,3 @@
|
|
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
|
-
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
|
-
|
7
1
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
8
2
|
|
9
3
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
@@ -86,31 +80,29 @@ export default createPlugin(function () {
|
|
86
80
|
var _storage$hooks$before, _storage$hooks;
|
87
81
|
|
88
82
|
var context = _ref2.context;
|
89
|
-
return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks,
|
83
|
+
return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks, context, next);
|
90
84
|
},
|
91
85
|
afterMatch: function afterMatch(_ref3, next) {
|
92
86
|
var _storage$hooks$afterM, _storage$hooks2;
|
93
87
|
|
94
88
|
var context = _ref3.context,
|
95
89
|
routeAPI = _ref3.routeAPI;
|
96
|
-
|
97
|
-
|
98
|
-
}), next);
|
90
|
+
context.router = routeAPI;
|
91
|
+
return (_storage$hooks$afterM = (_storage$hooks2 = storage.hooks).afterMatch) === null || _storage$hooks$afterM === void 0 ? void 0 : _storage$hooks$afterM.call(_storage$hooks2, context, next);
|
99
92
|
},
|
100
93
|
beforeRender: function beforeRender(_ref4, next) {
|
101
94
|
var _storage$hooks$before2, _storage$hooks3;
|
102
95
|
|
103
96
|
var context = _ref4.context;
|
104
|
-
return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3,
|
97
|
+
return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3, context, next);
|
105
98
|
},
|
106
99
|
afterRender: function afterRender(_ref5, next) {
|
107
100
|
var _storage$hooks$afterR, _storage$hooks4;
|
108
101
|
|
109
102
|
var context = _ref5.context,
|
110
103
|
templateAPI = _ref5.templateAPI;
|
111
|
-
|
112
|
-
|
113
|
-
}), next);
|
104
|
+
context.template = templateAPI;
|
105
|
+
return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, context, next);
|
114
106
|
}
|
115
107
|
};
|
116
108
|
}, {
|
package/jest.config.js
ADDED
package/package.json
CHANGED
@@ -11,38 +11,48 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "
|
14
|
+
"version": "1.1.1",
|
15
15
|
"types": "./dist/types/server.d.ts",
|
16
|
+
"jsnext:source": "./src/server.ts",
|
16
17
|
"main": "./dist/js/node/server.js",
|
17
18
|
"exports": {
|
18
19
|
".": {
|
19
20
|
"node": {
|
21
|
+
"jsnext:source": "./src/server.ts",
|
20
22
|
"import": "./dist/js/modern/server.js",
|
21
23
|
"require": "./dist/js/node/server.js"
|
22
24
|
},
|
23
25
|
"default": "./dist/js/treeshaking/server.js"
|
24
26
|
},
|
25
|
-
"./cli":
|
26
|
-
|
27
|
+
"./cli": {
|
28
|
+
"jsnext:source": "./src/cli.ts",
|
29
|
+
"default": "./dist/js/node/cli.js"
|
30
|
+
},
|
31
|
+
"./server": {
|
32
|
+
"jsnext:source": "./src/server.ts",
|
33
|
+
"default": "./dist/js/node/server.js"
|
34
|
+
}
|
27
35
|
},
|
28
36
|
"dependencies": {
|
29
37
|
"@babel/runtime": "^7",
|
30
|
-
"@modern-js/babel-compiler": "^
|
31
|
-
"@modern-js/server-utils": "^
|
32
|
-
"@modern-js/utils": "^
|
33
|
-
"@modern-js/server-plugin": "^
|
38
|
+
"@modern-js/babel-compiler": "^1.2.1",
|
39
|
+
"@modern-js/server-utils": "^1.2.1",
|
40
|
+
"@modern-js/utils": "^1.2.2",
|
41
|
+
"@modern-js/server-plugin": "^1.2.1"
|
34
42
|
},
|
35
43
|
"devDependencies": {
|
36
|
-
"@modern-js/core": "^
|
37
|
-
"@
|
38
|
-
"@modern-js/
|
44
|
+
"@modern-js/core": "^1.3.2",
|
45
|
+
"@scripts/build": "0.0.0",
|
46
|
+
"@modern-js/types": "^1.2.1",
|
39
47
|
"del-cli": "^4.0.1",
|
40
|
-
"typescript": "^4
|
48
|
+
"typescript": "^4",
|
41
49
|
"@types/jest": "^26.0.9",
|
42
|
-
"@types/node": "^14"
|
50
|
+
"@types/node": "^14",
|
51
|
+
"jest": "^27",
|
52
|
+
"@scripts/jest-config": "0.0.0"
|
43
53
|
},
|
44
54
|
"peerDependencies": {
|
45
|
-
"@modern-js/core": "^
|
55
|
+
"@modern-js/core": "^1.3.2"
|
46
56
|
},
|
47
57
|
"sideEffects": [
|
48
58
|
"*.css",
|
@@ -52,12 +62,14 @@
|
|
52
62
|
],
|
53
63
|
"publishConfig": {
|
54
64
|
"access": "public",
|
55
|
-
"registry": "https://registry.npmjs.org/"
|
65
|
+
"registry": "https://registry.npmjs.org/",
|
66
|
+
"types": "./dist/types/server.d.ts"
|
56
67
|
},
|
57
68
|
"scripts": {
|
58
69
|
"dev": "modern dev",
|
59
70
|
"build": "modern build",
|
60
71
|
"new": "modern new",
|
61
|
-
"test": "
|
62
|
-
}
|
72
|
+
"test": "jest --passWithNoTests"
|
73
|
+
},
|
74
|
+
"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"
|
63
75
|
}
|
package/tsconfig.json
CHANGED
package/src/cli.ts
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
import fs from 'fs';
|
2
|
-
import path from 'path';
|
3
|
-
import {
|
4
|
-
createPlugin,
|
5
|
-
useAppContext,
|
6
|
-
useResolvedConfigContext,
|
7
|
-
NormalizedConfig,
|
8
|
-
} from '@modern-js/core';
|
9
|
-
import { compiler } from '@modern-js/babel-compiler';
|
10
|
-
import { resolveBabelConfig } from '@modern-js/server-utils';
|
11
|
-
import { SHARED_DIR, SERVER_DIR } from '@modern-js/utils';
|
12
|
-
|
13
|
-
const TS_CONFIG_FILENAME = 'tsconfig.json';
|
14
|
-
const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
|
15
|
-
|
16
|
-
interface Pattern {
|
17
|
-
from: string;
|
18
|
-
to: string;
|
19
|
-
tsconfigPath?: string;
|
20
|
-
}
|
21
|
-
|
22
|
-
interface CompileOptions {
|
23
|
-
patterns: Pattern[];
|
24
|
-
}
|
25
|
-
|
26
|
-
const compile = async (
|
27
|
-
appDirectory: string,
|
28
|
-
modernConfig: NormalizedConfig,
|
29
|
-
compileOptions: CompileOptions,
|
30
|
-
) => {
|
31
|
-
const { patterns } = compileOptions;
|
32
|
-
const results = await Promise.all(
|
33
|
-
patterns.map(pattern => {
|
34
|
-
const { from, to, tsconfigPath } = pattern;
|
35
|
-
const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
|
36
|
-
tsconfigPath: tsconfigPath ? tsconfigPath : '',
|
37
|
-
syntax: 'es6+',
|
38
|
-
type: 'commonjs',
|
39
|
-
});
|
40
|
-
return compiler(
|
41
|
-
{
|
42
|
-
rootDir: appDirectory,
|
43
|
-
distDir: to,
|
44
|
-
sourceDir: from,
|
45
|
-
extensions: FILE_EXTENSIONS,
|
46
|
-
},
|
47
|
-
babelConfig,
|
48
|
-
);
|
49
|
-
}),
|
50
|
-
);
|
51
|
-
results.forEach(result => {
|
52
|
-
if (result.code === 1) {
|
53
|
-
throw new Error(result.message);
|
54
|
-
}
|
55
|
-
});
|
56
|
-
};
|
57
|
-
|
58
|
-
export default createPlugin(
|
59
|
-
() => ({
|
60
|
-
config() {
|
61
|
-
return {};
|
62
|
-
},
|
63
|
-
async afterBuild() {
|
64
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
65
|
-
const { appDirectory, distDirectory } = useAppContext();
|
66
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
67
|
-
const modernConfig = useResolvedConfigContext();
|
68
|
-
|
69
|
-
const distDir = path.resolve(distDirectory);
|
70
|
-
const serverDir = path.resolve(appDirectory, SERVER_DIR);
|
71
|
-
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
72
|
-
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
73
|
-
|
74
|
-
const patterns = [];
|
75
|
-
if (fs.existsSync(serverDir)) {
|
76
|
-
patterns.push({
|
77
|
-
from: serverDir,
|
78
|
-
to: distDir,
|
79
|
-
tsconfigPath,
|
80
|
-
});
|
81
|
-
}
|
82
|
-
|
83
|
-
if (fs.existsSync(sharedDir)) {
|
84
|
-
patterns.push({
|
85
|
-
from: sharedDir,
|
86
|
-
to: distDir,
|
87
|
-
tsconfigPath,
|
88
|
-
});
|
89
|
-
}
|
90
|
-
|
91
|
-
if (patterns.length > 0) {
|
92
|
-
await compile(appDirectory, modernConfig, { patterns });
|
93
|
-
}
|
94
|
-
},
|
95
|
-
}),
|
96
|
-
{ name: '@modern-js/plugin-server' },
|
97
|
-
) as any;
|
package/src/modern-app-env.d.ts
DELETED
package/src/server.ts
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { createPlugin } from '@modern-js/server-plugin';
|
3
|
-
import { useAppContext } from '@modern-js/core';
|
4
|
-
import { isProd, requireExistModule, SERVER_DIR } from '@modern-js/utils';
|
5
|
-
|
6
|
-
const WEB_APP_NAME = 'index';
|
7
|
-
|
8
|
-
type SF = (args: any, next: any) => void;
|
9
|
-
class Storage {
|
10
|
-
public middlewares: SF[] = [];
|
11
|
-
|
12
|
-
public hooks: Record<string, SF> = {};
|
13
|
-
|
14
|
-
reset() {
|
15
|
-
this.middlewares = [];
|
16
|
-
this.hooks = {};
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
const createTransformAPI = (storage: Storage) =>
|
21
|
-
new Proxy(
|
22
|
-
{},
|
23
|
-
{
|
24
|
-
get(target: any, name: string) {
|
25
|
-
if (name === 'addMiddleware') {
|
26
|
-
return (fn: SF) => storage.middlewares.push(fn);
|
27
|
-
}
|
28
|
-
return (fn: SF) => (storage.hooks[name] = fn);
|
29
|
-
},
|
30
|
-
},
|
31
|
-
);
|
32
|
-
|
33
|
-
export default createPlugin(
|
34
|
-
() => {
|
35
|
-
const { appDirectory, distDirectory } = useAppContext();
|
36
|
-
const pwd = isProd() ? distDirectory : appDirectory;
|
37
|
-
|
38
|
-
const serverPath = path.resolve(pwd, SERVER_DIR);
|
39
|
-
const webAppPath = path.resolve(serverPath, WEB_APP_NAME);
|
40
|
-
|
41
|
-
const storage = new Storage();
|
42
|
-
const transformAPI = createTransformAPI(storage);
|
43
|
-
|
44
|
-
const webMod = requireExistModule(webAppPath);
|
45
|
-
if (webMod) {
|
46
|
-
webMod(transformAPI);
|
47
|
-
}
|
48
|
-
|
49
|
-
return {
|
50
|
-
reset() {
|
51
|
-
storage.reset();
|
52
|
-
const newWebModule = requireExistModule(webAppPath);
|
53
|
-
if (newWebModule) {
|
54
|
-
newWebModule(transformAPI);
|
55
|
-
}
|
56
|
-
},
|
57
|
-
gather({ addWebMiddleware }) {
|
58
|
-
storage.middlewares.forEach(mid => {
|
59
|
-
addWebMiddleware(mid);
|
60
|
-
});
|
61
|
-
},
|
62
|
-
beforeMatch({ context }, next) {
|
63
|
-
return storage.hooks.beforeMatch?.({ ...context }, next);
|
64
|
-
},
|
65
|
-
afterMatch({ context, routeAPI }, next) {
|
66
|
-
return storage.hooks.afterMatch?.({ ...context, routeAPI }, next);
|
67
|
-
},
|
68
|
-
beforeRender({ context }, next) {
|
69
|
-
return storage.hooks.beforeRender?.({ ...context }, next);
|
70
|
-
},
|
71
|
-
afterRender({ context, templateAPI }, next) {
|
72
|
-
return storage.hooks.afterRender?.({ ...context, templateAPI }, next);
|
73
|
-
},
|
74
|
-
};
|
75
|
-
},
|
76
|
-
{
|
77
|
-
name: '@modern-js/plugin-server',
|
78
|
-
},
|
79
|
-
) as any;
|