@modern-js/plugin-server 1.0.2-rc.0 → 1.1.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 CHANGED
@@ -1,21 +1,29 @@
1
1
  # @modern-js/plugin-server
2
2
 
3
- ## 1.0.2-rc.0
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cfe11628: Make Modern.js self bootstraping
4
8
 
5
9
  ### Patch Changes
6
10
 
7
- - Updated dependencies [d927bc83]
8
- - Updated dependencies [d73ff455]
9
- - Updated dependencies [9c1ab865]
10
- - Updated dependencies [d73ff455]
11
- - Updated dependencies [d73ff455]
12
- - Updated dependencies [d73ff455]
13
- - Updated dependencies [d73ff455]
14
- - @modern-js/utils@1.1.4-rc.0
15
- - @modern-js/core@1.1.4-rc.0
16
- - @modern-js/server-utils@1.1.3-rc.0
17
- - @modern-js/babel-compiler@1.1.3-rc.0
18
- - @modern-js/server-plugin@1.1.2
11
+ - 146dcd85: modify server framework plugin hook types and hook context
12
+ - 146dcd85: modify server framework plugin hook types
13
+ - 146dcd85: fix test case in babel compiler
14
+ - Updated dependencies [2da09c69]
15
+ - Updated dependencies [fc71e36f]
16
+ - Updated dependencies [146dcd85]
17
+ - Updated dependencies [c3d46ee4]
18
+ - Updated dependencies [cfe11628]
19
+ - Updated dependencies [146dcd85]
20
+ - Updated dependencies [146dcd85]
21
+ - Updated dependencies [1ebc7ee2]
22
+ - @modern-js/utils@1.2.0
23
+ - @modern-js/core@1.3.0
24
+ - @modern-js/server-utils@1.2.0
25
+ - @modern-js/server-plugin@1.2.0
26
+ - @modern-js/babel-compiler@1.2.0
19
27
 
20
28
  ## 1.0.1
21
29
 
@@ -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, _objectSpread({}, context), next);
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
- return (_storage$hooks$afterM = (_storage$hooks2 = storage.hooks).afterMatch) === null || _storage$hooks$afterM === void 0 ? void 0 : _storage$hooks$afterM.call(_storage$hooks2, _objectSpread(_objectSpread({}, context), {}, {
86
- routeAPI
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, _objectSpread({}, context), next);
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
- return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, _objectSpread(_objectSpread({}, context), {}, {
105
- templateAPI
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
  };
@@ -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, _objectSpread({}, context), next);
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
- return (_storage$hooks$afterM = (_storage$hooks2 = storage.hooks).afterMatch) === null || _storage$hooks$afterM === void 0 ? void 0 : _storage$hooks$afterM.call(_storage$hooks2, _objectSpread(_objectSpread({}, context), {}, {
102
- routeAPI
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, _objectSpread({}, context), next);
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
- return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, _objectSpread(_objectSpread({}, context), {}, {
121
- templateAPI
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, _objectSpread({}, context), next);
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
- return (_storage$hooks$afterM = (_storage$hooks2 = storage.hooks).afterMatch) === null || _storage$hooks$afterM === void 0 ? void 0 : _storage$hooks$afterM.call(_storage$hooks2, _objectSpread(_objectSpread({}, context), {}, {
97
- routeAPI: routeAPI
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, _objectSpread({}, context), next);
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
- return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, _objectSpread(_objectSpread({}, context), {}, {
112
- templateAPI: templateAPI
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
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/package.json CHANGED
@@ -11,38 +11,48 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.0.2-rc.0",
14
+ "version": "1.1.0",
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": "./dist/js/node/cli.js",
26
- "./server": "./dist/js/node/server.js"
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": "^1.1.3-rc.0",
31
- "@modern-js/server-utils": "^1.1.3-rc.0",
32
- "@modern-js/utils": "^1.1.4-rc.0",
33
- "@modern-js/server-plugin": "^1.1.2"
38
+ "@modern-js/babel-compiler": "^1.2.0",
39
+ "@modern-js/server-utils": "^1.2.0",
40
+ "@modern-js/utils": "^1.2.0",
41
+ "@modern-js/server-plugin": "^1.2.0"
34
42
  },
35
43
  "devDependencies": {
36
- "@modern-js/core": "^1.1.4-rc.0",
37
- "@modern-js/module-tools": "^1.1.1",
38
- "@modern-js/plugin-testing": "^1.1.1",
44
+ "@modern-js/core": "^1.3.0",
45
+ "@scripts/build": "0.0.0",
46
+ "@modern-js/types": "^1.2.0",
39
47
  "del-cli": "^4.0.1",
40
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": "^1.1.4-rc.0"
55
+ "@modern-js/core": "^1.3.0"
46
56
  },
47
57
  "sideEffects": [
48
58
  "*.css",
@@ -52,13 +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": "modern test --passWithNoTests"
72
+ "test": "jest --passWithNoTests"
62
73
  },
63
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"
64
75
  }
package/src/server.ts CHANGED
@@ -2,6 +2,7 @@ import path from 'path';
2
2
  import { createPlugin } from '@modern-js/server-plugin';
3
3
  import { useAppContext } from '@modern-js/core';
4
4
  import { isProd, requireExistModule, SERVER_DIR } from '@modern-js/utils';
5
+ import { ModernServerContext } from '@modern-js/types';
5
6
 
6
7
  const WEB_APP_NAME = 'index';
7
8
 
@@ -30,6 +31,9 @@ const createTransformAPI = (storage: Storage) =>
30
31
  },
31
32
  );
32
33
 
34
+ type AfterMatchContext = ModernServerContext & { router: any };
35
+ type AfterRenderContext = ModernServerContext & { template: any };
36
+
33
37
  export default createPlugin(
34
38
  () => {
35
39
  const { appDirectory, distDirectory } = useAppContext();
@@ -60,16 +64,18 @@ export default createPlugin(
60
64
  });
61
65
  },
62
66
  beforeMatch({ context }, next) {
63
- return storage.hooks.beforeMatch?.({ ...context }, next);
67
+ return storage.hooks.beforeMatch?.(context, next);
64
68
  },
65
69
  afterMatch({ context, routeAPI }, next) {
66
- return storage.hooks.afterMatch?.({ ...context, routeAPI }, next);
70
+ (context as AfterMatchContext).router = routeAPI;
71
+ return storage.hooks.afterMatch?.(context, next);
67
72
  },
68
73
  beforeRender({ context }, next) {
69
- return storage.hooks.beforeRender?.({ ...context }, next);
74
+ return storage.hooks.beforeRender?.(context, next);
70
75
  },
71
76
  afterRender({ context, templateAPI }, next) {
72
- return storage.hooks.afterRender?.({ ...context, templateAPI }, next);
77
+ (context as AfterRenderContext).template = templateAPI;
78
+ return storage.hooks.afterRender?.(context, next);
73
79
  },
74
80
  };
75
81
  },
package/tsconfig.json CHANGED
@@ -4,10 +4,7 @@
4
4
  "declaration": false,
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
- "paths": {
8
- "@/*": ["./src/*"],
9
- "@style/*": ["./styles/*"]
10
- }
7
+ "paths": {}
11
8
  },
12
9
  "include": ["src"]
13
10
  }