@modern-js/plugin-server 0.0.0-canary-202112061746 → 0.0.0-runtime-2021112193858

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 ADDED
@@ -0,0 +1,38 @@
1
+ # @modern-js/plugin-server
2
+
3
+ ## 0.0.0-runtime-2021112193858
4
+
5
+ ### Patch Changes
6
+
7
+ - 8698465e: fix: dependence version
8
+ - Updated dependencies [8698465e]
9
+ - Updated dependencies [e04914ce]
10
+ - Updated dependencies [e04914ce]
11
+ - @modern-js/core@0.0.0-runtime-2021112193858
12
+ - @modern-js/server-plugin@0.0.0-runtime-2021112193858
13
+ - @modern-js/server-utils@0.0.0-runtime-2021112193858
14
+ - @modern-js/babel-compiler@0.0.0-runtime-2021112193858
15
+ - @modern-js/utils@0.0.0-runtime-2021112193858
16
+
17
+ ## 1.0.1
18
+
19
+ ### Patch Changes
20
+
21
+ - 085a6a58: refactor server plugin
22
+ - 085a6a58: refactor server plugin
23
+ - 085a6a58: refactor server conifg
24
+ - 085a6a58: support server runtime
25
+ - 085a6a58: feat: refactor server plugin
26
+ - Updated dependencies [085a6a58]
27
+ - Updated dependencies [085a6a58]
28
+ - Updated dependencies [085a6a58]
29
+ - Updated dependencies [d280ea33]
30
+ - Updated dependencies [d4fcc73a]
31
+ - Updated dependencies [085a6a58]
32
+ - Updated dependencies [ed1f6b12]
33
+ - Updated dependencies [a5ebbb00]
34
+ - Updated dependencies [085a6a58]
35
+ - @modern-js/core@1.1.3
36
+ - @modern-js/server-plugin@1.1.2
37
+ - @modern-js/server-utils@1.1.2
38
+ - @modern-js/utils@1.1.3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Modern.js
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,30 +1,30 @@
1
- # Your Package
2
1
 
3
- ## Get Started
2
+ <p align="center">
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
+ </p>
5
+ <p align="center">
6
+ 现代 Web 工程体系
7
+ <br/>
8
+ <a href="https://modernjs.dev" target="blank">
9
+ modernjs.dev
10
+ </a>
11
+ </p>
12
+ <p align="center">
13
+ The meta-framework suite designed from scratch for frontend-focused modern web development
14
+ </p>
4
15
 
5
- 按开发环境的要求,运行和调试项目
16
+ # Introduction
6
17
 
7
- 运行和调试组件
18
+ > 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.
8
19
 
9
- ```
10
- pnpm run dev
11
- ```
20
+ - [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
12
21
 
13
- 运行测试用例
22
+ ## Getting Started
14
23
 
15
- ```
16
- pnpm run test
17
- ```
24
+ - [Quick Start](https://modernjs.dev/docs/start)
25
+ - [Guides](https://modernjs.dev/docs/guides)
26
+ - [API References](https://modernjs.dev/docs/apis)
18
27
 
19
- 按照社区规范和最佳实践,生成构建产物
20
-
21
- ```
22
- pnpm run build
23
- ```
24
-
25
- 继续创建更多项目要素
26
-
27
- ```
28
- pnpm run new
29
- ```
28
+ ## Contributing
30
29
 
30
+ - [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)
@@ -3,8 +3,7 @@ import path from 'path';
3
3
  import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
4
4
  import { compiler } from '@modern-js/babel-compiler';
5
5
  import { resolveBabelConfig } from '@modern-js/server-utils';
6
- const SERVER_DIR = './server';
7
- const SHARED_DIR = './shared';
6
+ import { SHARED_DIR, SERVER_DIR } from '@modern-js/utils';
8
7
  const TS_CONFIG_FILENAME = 'tsconfig.json';
9
8
  const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
10
9
 
@@ -1,8 +1,13 @@
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
+
1
7
  import path from 'path';
2
8
  import { createPlugin } from '@modern-js/server-plugin';
3
9
  import { useAppContext } from '@modern-js/core';
4
- import { requireModule } from "./requireModule";
5
- const SERVER_DIR_PATH = 'server';
10
+ import { isProd, requireExistModule, SERVER_DIR } from '@modern-js/utils';
6
11
  const WEB_APP_NAME = 'index';
7
12
 
8
13
  class Storage {
@@ -31,13 +36,15 @@ const createTransformAPI = storage => new Proxy({}, {
31
36
 
32
37
  export default createPlugin(() => {
33
38
  const {
34
- appDirectory
39
+ appDirectory,
40
+ distDirectory
35
41
  } = useAppContext();
36
- const serverPath = path.resolve(appDirectory, SERVER_DIR_PATH);
42
+ const pwd = isProd() ? distDirectory : appDirectory;
43
+ const serverPath = path.resolve(pwd, SERVER_DIR);
37
44
  const webAppPath = path.resolve(serverPath, WEB_APP_NAME);
38
45
  const storage = new Storage();
39
46
  const transformAPI = createTransformAPI(storage);
40
- const webMod = requireModule(webAppPath);
47
+ const webMod = requireExistModule(webAppPath);
41
48
 
42
49
  if (webMod) {
43
50
  webMod(transformAPI);
@@ -46,7 +53,7 @@ export default createPlugin(() => {
46
53
  return {
47
54
  reset() {
48
55
  storage.reset();
49
- const newWebModule = requireModule(webAppPath);
56
+ const newWebModule = requireExistModule(webAppPath);
50
57
 
51
58
  if (newWebModule) {
52
59
  newWebModule(transformAPI);
@@ -66,21 +73,18 @@ export default createPlugin(() => {
66
73
  }, next) {
67
74
  var _storage$hooks$before, _storage$hooks;
68
75
 
69
- return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks, {
70
- context
71
- }, next);
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);
72
77
  },
73
78
 
74
79
  afterMatch({
75
80
  context,
76
- routeApi
81
+ routeAPI
77
82
  }, next) {
78
83
  var _storage$hooks$afterM, _storage$hooks2;
79
84
 
80
- return (_storage$hooks$afterM = (_storage$hooks2 = storage.hooks).afterMatch) === null || _storage$hooks$afterM === void 0 ? void 0 : _storage$hooks$afterM.call(_storage$hooks2, {
81
- context,
82
- routeApi
83
- }, next);
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);
84
88
  },
85
89
 
86
90
  beforeRender({
@@ -88,9 +92,7 @@ export default createPlugin(() => {
88
92
  }, next) {
89
93
  var _storage$hooks$before2, _storage$hooks3;
90
94
 
91
- return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3, {
92
- context
93
- }, next);
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);
94
96
  },
95
97
 
96
98
  afterRender({
@@ -99,10 +101,9 @@ export default createPlugin(() => {
99
101
  }, next) {
100
102
  var _storage$hooks$afterR, _storage$hooks4;
101
103
 
102
- return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, {
103
- context,
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), {}, {
104
105
  templateAPI
105
- }, next);
106
+ }), next);
106
107
  }
107
108
 
108
109
  };
@@ -15,10 +15,10 @@ var _babelCompiler = require("@modern-js/babel-compiler");
15
15
 
16
16
  var _serverUtils = require("@modern-js/server-utils");
17
17
 
18
+ var _utils = require("@modern-js/utils");
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
- const SERVER_DIR = './server';
21
- const SHARED_DIR = './shared';
22
22
  const TS_CONFIG_FILENAME = 'tsconfig.json';
23
23
  const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
24
24
 
@@ -67,9 +67,9 @@ var _default = (0, _core.createPlugin)(() => ({
67
67
 
68
68
  const distDir = _path.default.resolve(distDirectory);
69
69
 
70
- const serverDir = _path.default.resolve(appDirectory, SERVER_DIR);
70
+ const serverDir = _path.default.resolve(appDirectory, _utils.SERVER_DIR);
71
71
 
72
- const sharedDir = _path.default.resolve(appDirectory, SHARED_DIR);
72
+ const sharedDir = _path.default.resolve(appDirectory, _utils.SHARED_DIR);
73
73
 
74
74
  const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
75
75
 
@@ -11,11 +11,16 @@ var _serverPlugin = require("@modern-js/server-plugin");
11
11
 
12
12
  var _core = require("@modern-js/core");
13
13
 
14
- var _requireModule = require("./requireModule");
14
+ var _utils = require("@modern-js/utils");
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- const SERVER_DIR_PATH = 'server';
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
+
19
24
  const WEB_APP_NAME = 'index';
20
25
 
21
26
  class Storage {
@@ -44,16 +49,18 @@ const createTransformAPI = storage => new Proxy({}, {
44
49
 
45
50
  var _default = (0, _serverPlugin.createPlugin)(() => {
46
51
  const {
47
- appDirectory
52
+ appDirectory,
53
+ distDirectory
48
54
  } = (0, _core.useAppContext)();
55
+ const pwd = (0, _utils.isProd)() ? distDirectory : appDirectory;
49
56
 
50
- const serverPath = _path.default.resolve(appDirectory, SERVER_DIR_PATH);
57
+ const serverPath = _path.default.resolve(pwd, _utils.SERVER_DIR);
51
58
 
52
59
  const webAppPath = _path.default.resolve(serverPath, WEB_APP_NAME);
53
60
 
54
61
  const storage = new Storage();
55
62
  const transformAPI = createTransformAPI(storage);
56
- const webMod = (0, _requireModule.requireModule)(webAppPath);
63
+ const webMod = (0, _utils.requireExistModule)(webAppPath);
57
64
 
58
65
  if (webMod) {
59
66
  webMod(transformAPI);
@@ -62,7 +69,7 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
62
69
  return {
63
70
  reset() {
64
71
  storage.reset();
65
- const newWebModule = (0, _requireModule.requireModule)(webAppPath);
72
+ const newWebModule = (0, _utils.requireExistModule)(webAppPath);
66
73
 
67
74
  if (newWebModule) {
68
75
  newWebModule(transformAPI);
@@ -82,21 +89,18 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
82
89
  }, next) {
83
90
  var _storage$hooks$before, _storage$hooks;
84
91
 
85
- return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks, {
86
- context
87
- }, next);
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);
88
93
  },
89
94
 
90
95
  afterMatch({
91
96
  context,
92
- routeApi
97
+ routeAPI
93
98
  }, next) {
94
99
  var _storage$hooks$afterM, _storage$hooks2;
95
100
 
96
- return (_storage$hooks$afterM = (_storage$hooks2 = storage.hooks).afterMatch) === null || _storage$hooks$afterM === void 0 ? void 0 : _storage$hooks$afterM.call(_storage$hooks2, {
97
- context,
98
- routeApi
99
- }, next);
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);
100
104
  },
101
105
 
102
106
  beforeRender({
@@ -104,9 +108,7 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
104
108
  }, next) {
105
109
  var _storage$hooks$before2, _storage$hooks3;
106
110
 
107
- return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3, {
108
- context
109
- }, next);
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);
110
112
  },
111
113
 
112
114
  afterRender({
@@ -115,10 +117,9 @@ var _default = (0, _serverPlugin.createPlugin)(() => {
115
117
  }, next) {
116
118
  var _storage$hooks$afterR, _storage$hooks4;
117
119
 
118
- return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, {
119
- context,
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), {}, {
120
121
  templateAPI
121
- }, next);
122
+ }), next);
122
123
  }
123
124
 
124
125
  };
@@ -9,8 +9,7 @@ import path from 'path';
9
9
  import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
10
10
  import { compiler } from '@modern-js/babel-compiler';
11
11
  import { resolveBabelConfig } from '@modern-js/server-utils';
12
- var SERVER_DIR = './server';
13
- var SHARED_DIR = './shared';
12
+ import { SHARED_DIR, SERVER_DIR } from '@modern-js/utils';
14
13
  var TS_CONFIG_FILENAME = 'tsconfig.json';
15
14
  var FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
16
15
 
@@ -1,14 +1,19 @@
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
+
1
7
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
8
 
3
9
  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); } }
4
10
 
5
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
11
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
12
 
7
13
  import path from 'path';
8
14
  import { createPlugin } from '@modern-js/server-plugin';
9
15
  import { useAppContext } from '@modern-js/core';
10
- import { requireModule } from "./requireModule";
11
- var SERVER_DIR_PATH = 'server';
16
+ import { isProd, requireExistModule, SERVER_DIR } from '@modern-js/utils';
12
17
  var WEB_APP_NAME = 'index';
13
18
 
14
19
  var Storage = /*#__PURE__*/function () {
@@ -48,13 +53,15 @@ var createTransformAPI = function createTransformAPI(storage) {
48
53
 
49
54
  export default createPlugin(function () {
50
55
  var _useAppContext = useAppContext(),
51
- appDirectory = _useAppContext.appDirectory;
56
+ appDirectory = _useAppContext.appDirectory,
57
+ distDirectory = _useAppContext.distDirectory;
52
58
 
53
- var serverPath = path.resolve(appDirectory, SERVER_DIR_PATH);
59
+ var pwd = isProd() ? distDirectory : appDirectory;
60
+ var serverPath = path.resolve(pwd, SERVER_DIR);
54
61
  var webAppPath = path.resolve(serverPath, WEB_APP_NAME);
55
62
  var storage = new Storage();
56
63
  var transformAPI = createTransformAPI(storage);
57
- var webMod = requireModule(webAppPath);
64
+ var webMod = requireExistModule(webAppPath);
58
65
 
59
66
  if (webMod) {
60
67
  webMod(transformAPI);
@@ -63,7 +70,7 @@ export default createPlugin(function () {
63
70
  return {
64
71
  reset: function reset() {
65
72
  storage.reset();
66
- var newWebModule = requireModule(webAppPath);
73
+ var newWebModule = requireExistModule(webAppPath);
67
74
 
68
75
  if (newWebModule) {
69
76
  newWebModule(transformAPI);
@@ -79,37 +86,31 @@ export default createPlugin(function () {
79
86
  var _storage$hooks$before, _storage$hooks;
80
87
 
81
88
  var context = _ref2.context;
82
- return (_storage$hooks$before = (_storage$hooks = storage.hooks).beforeMatch) === null || _storage$hooks$before === void 0 ? void 0 : _storage$hooks$before.call(_storage$hooks, {
83
- context: context
84
- }, next);
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);
85
90
  },
86
91
  afterMatch: function afterMatch(_ref3, next) {
87
92
  var _storage$hooks$afterM, _storage$hooks2;
88
93
 
89
94
  var context = _ref3.context,
90
- routeApi = _ref3.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, {
92
- context: context,
93
- routeApi: routeApi
94
- }, next);
95
+ 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);
95
99
  },
96
100
  beforeRender: function beforeRender(_ref4, next) {
97
101
  var _storage$hooks$before2, _storage$hooks3;
98
102
 
99
103
  var context = _ref4.context;
100
- return (_storage$hooks$before2 = (_storage$hooks3 = storage.hooks).beforeRender) === null || _storage$hooks$before2 === void 0 ? void 0 : _storage$hooks$before2.call(_storage$hooks3, {
101
- context: context
102
- }, 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, _objectSpread({}, context), next);
103
105
  },
104
106
  afterRender: function afterRender(_ref5, next) {
105
107
  var _storage$hooks$afterR, _storage$hooks4;
106
108
 
107
109
  var context = _ref5.context,
108
110
  templateAPI = _ref5.templateAPI;
109
- return (_storage$hooks$afterR = (_storage$hooks4 = storage.hooks).afterRender) === null || _storage$hooks$afterR === void 0 ? void 0 : _storage$hooks$afterR.call(_storage$hooks4, {
110
- context: context,
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), {}, {
111
112
  templateAPI: templateAPI
112
- }, next);
113
+ }), next);
113
114
  }
114
115
  };
115
116
  }, {
File without changes
package/package.json CHANGED
@@ -1,49 +1,48 @@
1
1
  {
2
2
  "name": "@modern-js/plugin-server",
3
- "version": "0.0.0-canary-202112061746",
4
- "jsnext:source": "./src/index.ts",
5
- "types": "./dist/types/index.d.ts",
6
- "main": "./dist/js/node/index.js",
7
- "module": "./dist/js/treeshaking/index.js",
8
- "jsnext:modern": "./dist/js/modern/index.js",
3
+ "description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
4
+ "homepage": "https://modernjs.dev",
5
+ "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
+ "repository": "modern-js-dev/modern.js",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "react",
10
+ "framework",
11
+ "modern",
12
+ "modern.js"
13
+ ],
14
+ "version": "0.0.0-runtime-2021112193858",
15
+ "types": "./dist/types/server.d.ts",
16
+ "main": "./dist/js/node/server.js",
9
17
  "exports": {
10
18
  ".": {
11
19
  "node": {
12
- "import": "./dist/js/modern/index.js",
13
- "require": "./dist/js/node/index.js"
20
+ "import": "./dist/js/modern/server.js",
21
+ "require": "./dist/js/node/server.js"
14
22
  },
15
- "default": "./dist/js/treeshaking/index.js"
23
+ "default": "./dist/js/treeshaking/server.js"
16
24
  },
17
- "./cli": "./dist/js/node/index.js",
25
+ "./cli": "./dist/js/node/cli.js",
18
26
  "./server": "./dist/js/node/server.js"
19
27
  },
20
- "scripts": {
21
- "prepare": "modern build",
22
- "prepublishOnly": "modern build --platform",
23
- "dev": "modern dev",
24
- "build": "modern build",
25
- "new": "modern new",
26
- "test": "modern test --passWithNoTests"
27
- },
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7",
30
- "@modern-js/babel-compiler": "^1.1.2",
31
- "@modern-js/server-utils": "^1.1.1",
32
- "@modern-js/utils": "^1.1.2",
33
- "@modern-js/server-plugin": "^1.1.1"
30
+ "@modern-js/babel-compiler": "^0.0.0-runtime-2021112193858",
31
+ "@modern-js/server-utils": "^0.0.0-runtime-2021112193858",
32
+ "@modern-js/utils": "^0.0.0-runtime-2021112193858",
33
+ "@modern-js/server-plugin": "^0.0.0-runtime-2021112193858"
34
34
  },
35
35
  "devDependencies": {
36
- "@modern-js/core": "^1.1.2",
37
- "@modern-js/plugin-jarvis": "^1.0.0",
38
- "@modern-js/module-tools": "^1.0.0",
39
- "@modern-js/plugin-testing": "^1.0.0",
36
+ "@modern-js/core": "^0.0.0-runtime-2021112193858",
37
+ "@modern-js/module-tools": "^0.0.0-runtime-2021112193858",
38
+ "@modern-js/plugin-testing": "^0.0.0-runtime-2021112193858",
40
39
  "del-cli": "^4.0.1",
41
- "typescript": "^4",
40
+ "typescript": "^4.4.4",
42
41
  "@types/jest": "^26.0.9",
43
42
  "@types/node": "^14"
44
43
  },
45
44
  "peerDependencies": {
46
- "@modern-js/core": "^1.1.2"
45
+ "@modern-js/core": "^0.0.0-runtime-2021112193858"
47
46
  },
48
47
  "sideEffects": [
49
48
  "*.css",
@@ -54,5 +53,11 @@
54
53
  "publishConfig": {
55
54
  "access": "public",
56
55
  "registry": "https://registry.npmjs.org/"
56
+ },
57
+ "scripts": {
58
+ "dev": "modern dev",
59
+ "build": "modern build",
60
+ "new": "modern new",
61
+ "test": "modern test --passWithNoTests"
57
62
  }
58
- }
63
+ }
@@ -8,9 +8,8 @@ import {
8
8
  } from '@modern-js/core';
9
9
  import { compiler } from '@modern-js/babel-compiler';
10
10
  import { resolveBabelConfig } from '@modern-js/server-utils';
11
+ import { SHARED_DIR, SERVER_DIR } from '@modern-js/utils';
11
12
 
12
- const SERVER_DIR = './server';
13
- const SHARED_DIR = './shared';
14
13
  const TS_CONFIG_FILENAME = 'tsconfig.json';
15
14
  const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
16
15
 
package/src/server.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  import path from 'path';
2
2
  import { createPlugin } from '@modern-js/server-plugin';
3
3
  import { useAppContext } from '@modern-js/core';
4
- import { requireModule } from './requireModule';
4
+ import { isProd, requireExistModule, SERVER_DIR } from '@modern-js/utils';
5
5
 
6
- const SERVER_DIR_PATH = 'server';
7
6
  const WEB_APP_NAME = 'index';
8
7
 
9
8
  type SF = (args: any, next: any) => void;
10
-
11
9
  class Storage {
12
10
  public middlewares: SF[] = [];
13
11
 
@@ -34,15 +32,16 @@ const createTransformAPI = (storage: Storage) =>
34
32
 
35
33
  export default createPlugin(
36
34
  () => {
37
- const { appDirectory } = useAppContext();
35
+ const { appDirectory, distDirectory } = useAppContext();
36
+ const pwd = isProd() ? distDirectory : appDirectory;
38
37
 
39
- const serverPath = path.resolve(appDirectory, SERVER_DIR_PATH);
38
+ const serverPath = path.resolve(pwd, SERVER_DIR);
40
39
  const webAppPath = path.resolve(serverPath, WEB_APP_NAME);
41
40
 
42
41
  const storage = new Storage();
43
42
  const transformAPI = createTransformAPI(storage);
44
43
 
45
- const webMod = requireModule(webAppPath);
44
+ const webMod = requireExistModule(webAppPath);
46
45
  if (webMod) {
47
46
  webMod(transformAPI);
48
47
  }
@@ -50,7 +49,7 @@ export default createPlugin(
50
49
  return {
51
50
  reset() {
52
51
  storage.reset();
53
- const newWebModule = requireModule(webAppPath);
52
+ const newWebModule = requireExistModule(webAppPath);
54
53
  if (newWebModule) {
55
54
  newWebModule(transformAPI);
56
55
  }
@@ -61,16 +60,16 @@ export default createPlugin(
61
60
  });
62
61
  },
63
62
  beforeMatch({ context }, next) {
64
- return storage.hooks.beforeMatch?.({ context }, next);
63
+ return storage.hooks.beforeMatch?.({ ...context }, next);
65
64
  },
66
- afterMatch({ context, routeApi }, next) {
67
- return storage.hooks.afterMatch?.({ context, routeApi }, next);
65
+ afterMatch({ context, routeAPI }, next) {
66
+ return storage.hooks.afterMatch?.({ ...context, routeAPI }, next);
68
67
  },
69
68
  beforeRender({ context }, next) {
70
- return storage.hooks.beforeRender?.({ context }, next);
69
+ return storage.hooks.beforeRender?.({ ...context }, next);
71
70
  },
72
71
  afterRender({ context, templateAPI }, next) {
73
- return storage.hooks.afterRender?.({ context, templateAPI }, next);
72
+ return storage.hooks.afterRender?.({ ...context, templateAPI }, next);
74
73
  },
75
74
  };
76
75
  },
@@ -1,12 +0,0 @@
1
- import { findExists, compatRequire } from '@modern-js/utils';
2
- const FILE_EXTENSIONS = ['.ts', '.js'];
3
- export const requireModule = filename => {
4
- const exist = findExists(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
5
-
6
- if (!exist) {
7
- return null;
8
- } // throw errors directly if require fail
9
-
10
-
11
- return compatRequire(exist);
12
- };
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.requireModule = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- const FILE_EXTENSIONS = ['.ts', '.js'];
11
-
12
- const requireModule = filename => {
13
- const exist = (0, _utils.findExists)(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
14
-
15
- if (!exist) {
16
- return null;
17
- } // throw errors directly if require fail
18
-
19
-
20
- return (0, _utils.compatRequire)(exist);
21
- };
22
-
23
- exports.requireModule = requireModule;
@@ -1,14 +0,0 @@
1
- import { findExists, compatRequire } from '@modern-js/utils';
2
- var FILE_EXTENSIONS = ['.ts', '.js'];
3
- export var requireModule = function requireModule(filename) {
4
- var exist = findExists(FILE_EXTENSIONS.map(function (ext) {
5
- return "".concat(filename).concat(ext);
6
- }));
7
-
8
- if (!exist) {
9
- return null;
10
- } // throw errors directly if require fail
11
-
12
-
13
- return compatRequire(exist);
14
- };
@@ -1 +0,0 @@
1
- export declare const requireModule: (filename: string) => any;
@@ -1,14 +0,0 @@
1
- import { findExists, compatRequire } from '@modern-js/utils';
2
-
3
- const FILE_EXTENSIONS = ['.ts', '.js'];
4
-
5
- export const requireModule = (filename: string) => {
6
- const exist = findExists(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
7
-
8
- if (!exist) {
9
- return null;
10
- }
11
-
12
- // throw errors directly if require fail
13
- return compatRequire(exist);
14
- };
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: '@modern-js',
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -1,9 +0,0 @@
1
- import main from '@/index';
2
-
3
- describe('Default cases', () => {
4
- test('Have returns', () => {
5
- const drink = jest.fn(main);
6
- drink();
7
- expect(drink).toHaveReturned();
8
- });
9
- });
@@ -1,2 +0,0 @@
1
- ///<reference types="@modern-js/module-tools/types" />
2
- ///<reference types="@modern-js/plugin-testing/type" />
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../tsconfig.json",
3
- "compilerOptions": {
4
- "baseUrl": "../"
5
- },
6
- "include": ["**/*"]
7
- }