@modern-js/runtime 2.0.0-beta.1 → 2.0.0-beta.2

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,5 +1,86 @@
1
1
  # @modern-js/runtime
2
2
 
3
+ ## 2.0.0-beta.2
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Minor Changes
10
+
11
+ - c9e800d39a: feat: support React18 streaming SSR
12
+ feat: 支持 React18 流式 SSR
13
+ - 543be9558e: feat: compile server loader and support handle loader request
14
+ feat: 编译 server loader 并支持处理 loader 的请求
15
+
16
+ ### Patch Changes
17
+
18
+ - 2344eb2: fix: bootstrap function params type define
19
+
20
+ fix: 修复 bootstrap 函数参数类型定义
21
+
22
+ - a11fcf8: feat: fallback logic of streaming ssr
23
+ feat: streaming ssr 降级逻辑
24
+ - b18fa8f3ed: feat: remove @loadable/component in streaming ssr
25
+ feat: 移除 streaming ssr 中的 @loadable/component 逻辑
26
+ - 3e57f2b: feat: add document feature with plugin
27
+
28
+ feat: 增加 document 功能插件
29
+
30
+ - fbf5eed: fix: fix ssg failure due to lack of Web Response API
31
+ fix: 修复因为缺少 Web Response API 而导致 ssg 失败
32
+ - a2509bfbdb: feat: bump esbuild from 0.14.38 to 0.15.7
33
+
34
+ feat: 将 esbuild 从 0.14.38 版本升级至 0.15.7 版本
35
+
36
+ - e4357f1: fix: change default document file and name
37
+
38
+ fix: 重置默认的 document 文件和文件名
39
+
40
+ - 4369648ae2: fix: fix html template of streaming ssr
41
+ fix: 修复流式渲染的 html 模版
42
+ - 92c0994: chore: remove `registerPrefetch`
43
+ chore: 移除 `registerPrefetch`
44
+ - 6bda14ed71: feat: refactor router with react-router@6.4
45
+
46
+ feat: 使用 react-router@6.4 重构路由模块
47
+
48
+ - 92004d1: feat: support load chunks parallelly
49
+ feat: 支持并行加载 chunks
50
+ - 40ed587: feat: inject css chunk into html for streaming ssr
51
+ feat: streaming ssr 返回的 html 注入 css chunk
52
+ - 60d5378632: fix: function extname should not return array
53
+ fix: 函数 extname 不应该返回一个数组
54
+ - 8b8e1bb571: feat: support nested routes
55
+ feat: 支持嵌套路由
56
+ - 3bbea92b2a: feat: support Hook、Middleware new API
57
+ feat: 支持 Hook、Middleware 的新 API
58
+ - 18aaf42: fix: fix server loader redirects
59
+ fix: 修复 server loader 重定向错误
60
+ - fcace5b5b9: fix: remove overmuch `@modernjs/utils` dependency import in ssr runtime & SSR hydrate error
61
+ fix: 去除 ssr 运行时过多的 `@modernjs/utils` 依赖引入 & SSR hydrate 错误
62
+ - Updated dependencies [92f0ead]
63
+ - Updated dependencies [edd1cfb1af]
64
+ - Updated dependencies [cc971eabfc]
65
+ - Updated dependencies [5b9049f2e9]
66
+ - Updated dependencies [6bda14ed71]
67
+ - Updated dependencies [92004d1]
68
+ - Updated dependencies [b8bbe036c7]
69
+ - Updated dependencies [40ed587]
70
+ - Updated dependencies [87c1ff8]
71
+ - Updated dependencies [d5a31df781]
72
+ - Updated dependencies [dda38c9c3e]
73
+ - Updated dependencies [102d32e4ba]
74
+ - Updated dependencies [8b8e1bb571]
75
+ - Updated dependencies [3bbea92b2a]
76
+ - Updated dependencies [f179749]
77
+ - Updated dependencies [abf3421a75]
78
+ - Updated dependencies [543be9558e]
79
+ - Updated dependencies [14b712da84]
80
+ - @modern-js/utils@2.0.0-beta.2
81
+ - @modern-js/types@2.0.0-beta.2
82
+ - @modern-js/plugin@2.0.0-beta.2
83
+
3
84
  ## 2.0.0-beta.1
4
85
 
5
86
  ### Major Changes
@@ -25,7 +25,9 @@ export default (() => ({
25
25
  */
26
26
  'styled-components': require.resolve('styled-components')
27
27
  },
28
- envVars: ['IS_REACT18']
28
+ globalVars: {
29
+ 'process.env.IS_REACT18': process.env.IS_REACT18
30
+ }
29
31
  }
30
32
  };
31
33
  },
@@ -5,7 +5,6 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
5
5
  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; }
6
6
  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; }
7
7
  import React, { useContext, useMemo } from 'react';
8
- import defaultReactDOM from 'react-dom';
9
8
  import hoistNonReactStatics from 'hoist-non-react-statics';
10
9
  import { RuntimeReactContext } from "../runtime-context";
11
10
  import { runtime } from "./plugin";
@@ -95,7 +94,7 @@ id,
95
94
  /**
96
95
  * root.render need use root to run function
97
96
  */
98
- root, ReactDOM = defaultReactDOM
97
+ root, ReactDOM
99
98
  // eslint-disable-next-line consistent-return
100
99
  ) => {
101
100
  let App = BootApp;
@@ -153,7 +152,9 @@ root, ReactDOM = defaultReactDOM
153
152
  context.initialData = initialData;
154
153
  }
155
154
  const rootElement = typeof id !== 'string' ? id : document.getElementById(id || 'root');
156
-
155
+ if (!ReactDOM) {
156
+ throw Error('The `bootstrap` need provide `ReactDOM` parameter');
157
+ }
157
158
  // https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
158
159
  const ModernRender = App => {
159
160
  if (IS_REACT18) {
@@ -9,10 +9,15 @@ import { createDebugger, findExists } from '@modern-js/utils';
9
9
  import { DocumentContext } from "../DocumentContext";
10
10
  import { DOCUMENT_SCRIPTS_PLACEHOLDER, DOCUMENT_FILE_NAME, DOCUMENT_META_PLACEHOLDER, PLACEHOLDER_REPLACER_MAP, DOC_EXT, DOCUMENT_SSR_PLACEHOLDER, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, HTML_SEPARATOR } from "../constants";
11
11
  const debug = createDebugger('html_genarate');
12
- const getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName) {
12
+
13
+ // get the entry document file,
14
+ // if not exist, fallback to src/
15
+ const getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName, fallbackDir) {
13
16
  var _entrypoints$find;
14
17
  const entryDir = (_entrypoints$find = entrypoints.find(item => item.entryName === entryName)) === null || _entrypoints$find === void 0 ? void 0 : _entrypoints$find.absoluteEntryDir;
15
- const docFile = findExists(DOC_EXT.map(item => `${entryDir}${path.sep}${DOCUMENT_FILE_NAME}.${item}`));
18
+ const entryDirs = DOC_EXT.map(item => `${entryDir}${path.sep}${DOCUMENT_FILE_NAME}.${item}`);
19
+ const fallbackDirs = fallbackDir ? DOC_EXT.map(item => [fallbackDir, 'src', `${DOCUMENT_FILE_NAME}.${item}`].join(path.sep)) : [];
20
+ const docFile = findExists([...entryDirs, ...fallbackDirs]);
16
21
  return docFile || undefined;
17
22
  };
18
23
  export default (() => ({
@@ -39,14 +44,11 @@ export default (() => ({
39
44
  const documentEntry = (entryName, templateParameters) => {
40
45
  const {
41
46
  entrypoints,
42
- internalDirectory
47
+ internalDirectory,
48
+ appDirectory
43
49
  } = api.useAppContext();
44
50
  // search the document.[tsx|jsx|js|ts] under entry
45
- // if not, use main as default
46
- let documentFilePath = getDocumenByEntryName(entrypoints, entryName);
47
- if (!documentFilePath) {
48
- documentFilePath = getDocumenByEntryName(entrypoints, 'main');
49
- }
51
+ const documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
50
52
  // if no document file, do nothing as default
51
53
  if (!documentFilePath) {
52
54
  return null;
@@ -8,7 +8,7 @@ export const HTML_SSRDATASCRIPT_SEPARATOR = '<!--<?- SSRDataScript ?>-->';
8
8
  export const DOCUMENT_SSR_PLACEHOLDER = encodeURIComponent(HTML_SEPARATOR);
9
9
  export const DOCUMENT_CHUNKSMAP_PLACEHOLDER = encodeURIComponent(HTML_CHUNKSMAP_SEPARATOR);
10
10
  export const DOCUMENT_SSRDATASCRIPT_PLACEHOLDER = encodeURIComponent(HTML_SSRDATASCRIPT_SEPARATOR);
11
- export const DOCUMENT_FILE_NAME = 'document';
11
+ export const DOCUMENT_FILE_NAME = 'Document';
12
12
  export const DOCUMENT_SCRIPTS_PLACEHOLDER = encodeURIComponent('<!-- chunk scripts placeholder -->');
13
13
  export const DOCUMENT_NO_SCRIPTE_PLACEHOLDER = encodeURIComponent('<!-- no-script -->');
14
14
  export const PLACEHOLDER_REPLACER_MAP = {
@@ -1,5 +1,4 @@
1
1
  import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
2
- import "../types";
3
2
  const PLUGIN_IDENTIFIER = 'state';
4
3
  export default (() => ({
5
4
  name: '@modern-js/plugin-state',
@@ -32,7 +32,9 @@ var _default = () => ({
32
32
  */
33
33
  'styled-components': require.resolve('styled-components')
34
34
  },
35
- envVars: ['IS_REACT18']
35
+ globalVars: {
36
+ 'process.env.IS_REACT18': process.env.IS_REACT18
37
+ }
36
38
  }
37
39
  };
38
40
  },
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useRuntimeContext = exports.createApp = exports.bootstrap = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- var _reactDom = _interopRequireDefault(require("react-dom"));
9
8
  var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
10
9
  var _runtimeContext = require("../runtime-context");
11
10
  var _plugin = require("./plugin");
@@ -105,7 +104,7 @@ id,
105
104
  /**
106
105
  * root.render need use root to run function
107
106
  */
108
- root, ReactDOM = _reactDom.default
107
+ root, ReactDOM
109
108
  // eslint-disable-next-line consistent-return
110
109
  ) => {
111
110
  let App = BootApp;
@@ -163,7 +162,9 @@ root, ReactDOM = _reactDom.default
163
162
  context.initialData = initialData;
164
163
  }
165
164
  const rootElement = typeof id !== 'string' ? id : document.getElementById(id || 'root');
166
-
165
+ if (!ReactDOM) {
166
+ throw Error('The `bootstrap` need provide `ReactDOM` parameter');
167
+ }
167
168
  // https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
168
169
  const ModernRender = App => {
169
170
  if (IS_REACT18) {
@@ -18,10 +18,15 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
18
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
19
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
20
  const debug = (0, _utils.createDebugger)('html_genarate');
21
- const getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName) {
21
+
22
+ // get the entry document file,
23
+ // if not exist, fallback to src/
24
+ const getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName, fallbackDir) {
22
25
  var _entrypoints$find;
23
26
  const entryDir = (_entrypoints$find = entrypoints.find(item => item.entryName === entryName)) === null || _entrypoints$find === void 0 ? void 0 : _entrypoints$find.absoluteEntryDir;
24
- const docFile = (0, _utils.findExists)(_constants.DOC_EXT.map(item => `${entryDir}${_path.default.sep}${_constants.DOCUMENT_FILE_NAME}.${item}`));
27
+ const entryDirs = _constants.DOC_EXT.map(item => `${entryDir}${_path.default.sep}${_constants.DOCUMENT_FILE_NAME}.${item}`);
28
+ const fallbackDirs = fallbackDir ? _constants.DOC_EXT.map(item => [fallbackDir, 'src', `${_constants.DOCUMENT_FILE_NAME}.${item}`].join(_path.default.sep)) : [];
29
+ const docFile = (0, _utils.findExists)([...entryDirs, ...fallbackDirs]);
25
30
  return docFile || undefined;
26
31
  };
27
32
  var _default = () => ({
@@ -48,14 +53,11 @@ var _default = () => ({
48
53
  const documentEntry = (entryName, templateParameters) => {
49
54
  const {
50
55
  entrypoints,
51
- internalDirectory
56
+ internalDirectory,
57
+ appDirectory
52
58
  } = api.useAppContext();
53
59
  // search the document.[tsx|jsx|js|ts] under entry
54
- // if not, use main as default
55
- let documentFilePath = getDocumenByEntryName(entrypoints, entryName);
56
- if (!documentFilePath) {
57
- documentFilePath = getDocumenByEntryName(entrypoints, 'main');
58
- }
60
+ const documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
59
61
  // if no document file, do nothing as default
60
62
  if (!documentFilePath) {
61
63
  return null;
@@ -21,7 +21,7 @@ const DOCUMENT_CHUNKSMAP_PLACEHOLDER = encodeURIComponent(HTML_CHUNKSMAP_SEPARAT
21
21
  exports.DOCUMENT_CHUNKSMAP_PLACEHOLDER = DOCUMENT_CHUNKSMAP_PLACEHOLDER;
22
22
  const DOCUMENT_SSRDATASCRIPT_PLACEHOLDER = encodeURIComponent(HTML_SSRDATASCRIPT_SEPARATOR);
23
23
  exports.DOCUMENT_SSRDATASCRIPT_PLACEHOLDER = DOCUMENT_SSRDATASCRIPT_PLACEHOLDER;
24
- const DOCUMENT_FILE_NAME = 'document';
24
+ const DOCUMENT_FILE_NAME = 'Document';
25
25
  exports.DOCUMENT_FILE_NAME = DOCUMENT_FILE_NAME;
26
26
  const DOCUMENT_SCRIPTS_PLACEHOLDER = encodeURIComponent('<!-- chunk scripts placeholder -->');
27
27
  exports.DOCUMENT_SCRIPTS_PLACEHOLDER = DOCUMENT_SCRIPTS_PLACEHOLDER;
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _utils = require("@modern-js/utils");
8
- require("../types");
9
8
  const PLUGIN_IDENTIFIER = 'state';
10
9
  var _default = () => ({
11
10
  name: '@modern-js/plugin-state',
@@ -28,7 +28,9 @@ export default (function () {
28
28
  */
29
29
  'styled-components': require.resolve('styled-components')
30
30
  },
31
- envVars: ['IS_REACT18']
31
+ globalVars: {
32
+ 'process.env.IS_REACT18': process.env.IS_REACT18
33
+ }
32
34
  }
33
35
  };
34
36
  },
@@ -5,7 +5,6 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
5
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
6
6
  var _excluded = ["context"];
7
7
  import React, { useContext, useMemo } from 'react';
8
- import defaultReactDOM from 'react-dom';
9
8
  import hoistNonReactStatics from 'hoist-non-react-statics';
10
9
  import { RuntimeReactContext } from "../runtime-context";
11
10
  import { runtime } from "./plugin";
@@ -94,30 +93,14 @@ export var bootstrap = /*#__PURE__*/function () {
94
93
  /**
95
94
  * root.render need use root to run function
96
95
  */
97
- root) {
98
- var ReactDOM,
99
- App,
100
- runner,
101
- context,
102
- runInit,
103
- isBrowser,
104
- _ssrData$data,
105
- _ssrData$data2,
106
- ssrData,
107
- loadersData,
108
- initialLoadersState,
109
- initialData,
110
- _rootElement,
111
- ModernRender,
112
- ModernHydrate,
113
- isRedirectResponse,
114
- _initialData,
115
- _args = arguments;
96
+ root, ReactDOM
97
+ // eslint-disable-next-line consistent-return
98
+ ) {
99
+ var App, runner, context, runInit, isBrowser, _ssrData$data, _ssrData$data2, ssrData, loadersData, initialLoadersState, initialData, rootElement, ModernRender, ModernHydrate, isRedirectResponse, _initialData;
116
100
  return _regeneratorRuntime().wrap(function _callee$(_context2) {
117
101
  while (1) {
118
102
  switch (_context2.prev = _context2.next) {
119
103
  case 0:
120
- ReactDOM = _args.length > 3 && _args[3] !== undefined ? _args[3] : defaultReactDOM;
121
104
  App = BootApp;
122
105
  runner = runnerMap.get(App); // ensure Component used is created by `createApp`
123
106
  if (!runner) {
@@ -139,20 +122,20 @@ export var bootstrap = /*#__PURE__*/function () {
139
122
  });
140
123
  }; // don't mount the App, let user in charge of it.
141
124
  if (id) {
142
- _context2.next = 8;
125
+ _context2.next = 7;
143
126
  break;
144
127
  }
145
128
  return _context2.abrupt("return", /*#__PURE__*/React.createElement(App, {
146
129
  context: context
147
130
  }));
148
- case 8:
131
+ case 7:
149
132
  isBrowser = typeof window !== 'undefined' && window.name !== 'nodejs';
150
133
  if (!isBrowser) {
151
- _context2.next = 29;
134
+ _context2.next = 30;
152
135
  break;
153
136
  }
154
137
  if (!isClientArgs(id)) {
155
- _context2.next = 26;
138
+ _context2.next = 27;
156
139
  break;
157
140
  }
158
141
  ssrData = window._SSR_DATA;
@@ -173,20 +156,27 @@ export var bootstrap = /*#__PURE__*/function () {
173
156
  ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
174
157
  } : {}));
175
158
  context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData$data2 = ssrData.data) === null || _ssrData$data2 === void 0 ? void 0 : _ssrData$data2.initialData;
176
- _context2.next = 18;
159
+ _context2.next = 17;
177
160
  return runInit(context);
178
- case 18:
161
+ case 17:
179
162
  initialData = _context2.sent;
180
163
  if (initialData) {
181
164
  context.initialData = initialData;
182
165
  }
183
- _rootElement = typeof id !== 'string' ? id : document.getElementById(id || 'root'); // https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
166
+ rootElement = typeof id !== 'string' ? id : document.getElementById(id || 'root');
167
+ if (ReactDOM) {
168
+ _context2.next = 22;
169
+ break;
170
+ }
171
+ throw Error('The `bootstrap` need provide `ReactDOM` parameter');
172
+ case 22:
173
+ // https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
184
174
  ModernRender = function ModernRender(App) {
185
175
  if (IS_REACT18) {
186
176
  if (root) {
187
177
  root.render(App);
188
178
  } else if (ReactDOM.createRoot) {
189
- ReactDOM.createRoot(_rootElement).render(App);
179
+ ReactDOM.createRoot(rootElement).render(App);
190
180
  } else {
191
181
  throw Error('The `bootstrap` `ReactDOM` parameter needs to provide the `createRoot` method');
192
182
  }
@@ -194,7 +184,7 @@ export var bootstrap = /*#__PURE__*/function () {
194
184
  if (!ReactDOM.render) {
195
185
  throw Error('The `bootstrap` `ReactDOM` parameter needs to provide the `render` method');
196
186
  }
197
- ReactDOM.render(App, _rootElement);
187
+ ReactDOM.render(App, rootElement);
198
188
  }
199
189
  };
200
190
  ModernHydrate = function ModernHydrate(App, callback) {
@@ -202,12 +192,12 @@ export var bootstrap = /*#__PURE__*/function () {
202
192
  if (!ReactDOM.hydrateRoot) {
203
193
  throw Error('The `bootstrap` `ReactDOM` parameter needs to provide the `hydrateRoot` method');
204
194
  }
205
- ReactDOM.hydrateRoot(_rootElement, App);
195
+ ReactDOM.hydrateRoot(rootElement, App);
206
196
  } else {
207
197
  if (!ReactDOM.hydrate) {
208
198
  throw Error('The `bootstrap` `ReactDOM` parameter needs to provide the `hydrate` method');
209
199
  }
210
- ReactDOM.hydrate(App, _rootElement, callback);
200
+ ReactDOM.hydrate(App, rootElement, callback);
211
201
  }
212
202
  };
213
203
  return _context2.abrupt("return", runner.client({
@@ -223,12 +213,12 @@ export var bootstrap = /*#__PURE__*/function () {
223
213
  }));
224
214
  }
225
215
  }));
226
- case 26:
227
- throw Error('`bootstrap` needs id in browser environment, it needs to be string or element');
228
216
  case 27:
229
- _context2.next = 37;
217
+ throw Error('`bootstrap` needs id in browser environment, it needs to be string or element');
218
+ case 28:
219
+ _context2.next = 38;
230
220
  break;
231
- case 29:
221
+ case 30:
232
222
  Object.assign(context, {
233
223
  ssrContext: id,
234
224
  isBrowser: false,
@@ -257,12 +247,12 @@ export var bootstrap = /*#__PURE__*/function () {
257
247
  }
258
248
  return false;
259
249
  };
260
- _context2.next = 33;
250
+ _context2.next = 34;
261
251
  return runInit(context);
262
- case 33:
252
+ case 34:
263
253
  _initialData = _context2.sent;
264
254
  if (isRedirectResponse(_initialData)) {
265
- _context2.next = 37;
255
+ _context2.next = 38;
266
256
  break;
267
257
  }
268
258
  context.initialData = _initialData;
@@ -270,14 +260,14 @@ export var bootstrap = /*#__PURE__*/function () {
270
260
  App: App,
271
261
  context: context
272
262
  }));
273
- case 37:
263
+ case 38:
274
264
  case "end":
275
265
  return _context2.stop();
276
266
  }
277
267
  }
278
268
  }, _callee);
279
269
  }));
280
- return function bootstrap(_x, _x2, _x3) {
270
+ return function bootstrap(_x, _x2, _x3, _x4) {
281
271
  return _ref6.apply(this, arguments);
282
272
  };
283
273
  }();
@@ -1,6 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
5
  import path from 'path';
5
6
  import React from 'react';
6
7
  import ReactDomServer from 'react-dom/server';
@@ -9,14 +10,21 @@ import { createDebugger, findExists } from '@modern-js/utils';
9
10
  import { DocumentContext } from "../DocumentContext";
10
11
  import { DOCUMENT_SCRIPTS_PLACEHOLDER, DOCUMENT_FILE_NAME, DOCUMENT_META_PLACEHOLDER, PLACEHOLDER_REPLACER_MAP, DOC_EXT, DOCUMENT_SSR_PLACEHOLDER, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, HTML_SEPARATOR } from "../constants";
11
12
  var debug = createDebugger('html_genarate');
12
- var getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName) {
13
+
14
+ // get the entry document file,
15
+ // if not exist, fallback to src/
16
+ var getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName, fallbackDir) {
13
17
  var _entrypoints$find;
14
18
  var entryDir = (_entrypoints$find = entrypoints.find(function (item) {
15
19
  return item.entryName === entryName;
16
20
  })) === null || _entrypoints$find === void 0 ? void 0 : _entrypoints$find.absoluteEntryDir;
17
- var docFile = findExists(DOC_EXT.map(function (item) {
21
+ var entryDirs = DOC_EXT.map(function (item) {
18
22
  return "".concat(entryDir).concat(path.sep).concat(DOCUMENT_FILE_NAME, ".").concat(item);
19
- }));
23
+ });
24
+ var fallbackDirs = fallbackDir ? DOC_EXT.map(function (item) {
25
+ return [fallbackDir, 'src', "".concat(DOCUMENT_FILE_NAME, ".").concat(item)].join(path.sep);
26
+ }) : [];
27
+ var docFile = findExists([].concat(_toConsumableArray(entryDirs), _toConsumableArray(fallbackDirs)));
20
28
  return docFile || undefined;
21
29
  };
22
30
  export default (function () {
@@ -47,13 +55,10 @@ export default (function () {
47
55
  documentEntry = function documentEntry(entryName, templateParameters) {
48
56
  var _api$useAppContext = api.useAppContext(),
49
57
  entrypoints = _api$useAppContext.entrypoints,
50
- internalDirectory = _api$useAppContext.internalDirectory;
58
+ internalDirectory = _api$useAppContext.internalDirectory,
59
+ appDirectory = _api$useAppContext.appDirectory;
51
60
  // search the document.[tsx|jsx|js|ts] under entry
52
- // if not, use main as default
53
- var documentFilePath = getDocumenByEntryName(entrypoints, entryName);
54
- if (!documentFilePath) {
55
- documentFilePath = getDocumenByEntryName(entrypoints, 'main');
56
- }
61
+ var documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
57
62
  // if no document file, do nothing as default
58
63
  if (!documentFilePath) {
59
64
  return null;
@@ -10,7 +10,7 @@ export var HTML_SSRDATASCRIPT_SEPARATOR = '<!--<?- SSRDataScript ?>-->';
10
10
  export var DOCUMENT_SSR_PLACEHOLDER = encodeURIComponent(HTML_SEPARATOR);
11
11
  export var DOCUMENT_CHUNKSMAP_PLACEHOLDER = encodeURIComponent(HTML_CHUNKSMAP_SEPARATOR);
12
12
  export var DOCUMENT_SSRDATASCRIPT_PLACEHOLDER = encodeURIComponent(HTML_SSRDATASCRIPT_SEPARATOR);
13
- export var DOCUMENT_FILE_NAME = 'document';
13
+ export var DOCUMENT_FILE_NAME = 'Document';
14
14
  export var DOCUMENT_SCRIPTS_PLACEHOLDER = encodeURIComponent('<!-- chunk scripts placeholder -->');
15
15
  export var DOCUMENT_NO_SCRIPTE_PLACEHOLDER = encodeURIComponent('<!-- no-script -->');
16
16
  export var PLACEHOLDER_REPLACER_MAP = (_PLACEHOLDER_REPLACER = {}, _defineProperty(_PLACEHOLDER_REPLACER, DOCUMENT_NO_SCRIPTE_PLACEHOLDER, "We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue."), _defineProperty(_PLACEHOLDER_REPLACER, DOCUMENT_SSR_PLACEHOLDER, HTML_SEPARATOR), _defineProperty(_PLACEHOLDER_REPLACER, DOCUMENT_CHUNKSMAP_PLACEHOLDER, HTML_CHUNKSMAP_SEPARATOR), _defineProperty(_PLACEHOLDER_REPLACER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, HTML_SSRDATASCRIPT_SEPARATOR), _PLACEHOLDER_REPLACER);
@@ -1,5 +1,4 @@
1
1
  import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
2
- import "../types";
3
2
  var PLUGIN_IDENTIFIER = 'state';
4
3
  export default (function () {
5
4
  return {
@@ -1,3 +1,3 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- declare const _default: () => CliPlugin;
1
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
+ declare const _default: () => CliPlugin<AppTools>;
3
3
  export default _default;
@@ -1,4 +1,6 @@
1
1
  import React from 'react';
2
+ import type { Renderer } from 'react-dom';
3
+ import type { hydrateRoot, createRoot } from 'react-dom/client';
2
4
  import { RuntimeContext, TRuntimeContext } from '../runtime-context';
3
5
  import { Plugin } from './plugin';
4
6
  export declare type CreateAppOptions = {
@@ -7,15 +9,11 @@ export declare type CreateAppOptions = {
7
9
  export declare const createApp: ({
8
10
  plugins
9
11
  }: CreateAppOptions) => (App?: React.ComponentType<any>) => React.ComponentType<any>;
10
- interface HydrateFunc {
11
- (container: Element | Document, initialChildren: React.ReactNode): void;
12
- (initialChildren: React.ReactNode, container: Element | Document, callback?: () => void): void;
13
- }
14
12
  declare type BootStrap<T = unknown> = (App: React.ComponentType, id: string | HTMLElement | RuntimeContext, root?: any, ReactDOM?: {
15
- render?: (children: React.ReactNode, rootElement?: HTMLElement) => void;
16
- hydrate?: HydrateFunc;
17
- createRoot?: (rootElement: HTMLElement) => any;
18
- hydrateRoot?: HydrateFunc;
13
+ render?: Renderer;
14
+ hydrate?: Renderer;
15
+ createRoot?: typeof createRoot;
16
+ hydrateRoot?: typeof hydrateRoot;
19
17
  }) => Promise<T>;
20
18
  export declare const bootstrap: BootStrap;
21
19
  export declare const useRuntimeContext: () => TRuntimeContext;
@@ -14,8 +14,8 @@ declare const runtimeHooks: {
14
14
  client: import("@modern-js/plugin").AsyncPipeline<{
15
15
  App: React.ComponentType<any>;
16
16
  readonly context?: RuntimeContext | undefined;
17
- ModernRender: (App: React.ReactNode) => void;
18
- ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
17
+ ModernRender: (App: React.ReactElement) => void;
18
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
19
19
  }, void>;
20
20
  server: import("@modern-js/plugin").AsyncPipeline<{
21
21
  App: React.ComponentType<any>;
@@ -49,8 +49,8 @@ export declare const createRuntime: () => import("@modern-js/plugin").Manager<{
49
49
  client: import("@modern-js/plugin").AsyncPipeline<{
50
50
  App: React.ComponentType<any>;
51
51
  readonly context?: RuntimeContext | undefined;
52
- ModernRender: (App: React.ReactNode) => void;
53
- ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
52
+ ModernRender: (App: React.ReactElement) => void;
53
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
54
54
  }, void>;
55
55
  server: import("@modern-js/plugin").AsyncPipeline<{
56
56
  App: React.ComponentType<any>;
@@ -80,8 +80,8 @@ export declare const runtime: import("@modern-js/plugin").Manager<{
80
80
  client: import("@modern-js/plugin").AsyncPipeline<{
81
81
  App: React.ComponentType<any>;
82
82
  readonly context?: RuntimeContext | undefined;
83
- ModernRender: (App: React.ReactNode) => void;
84
- ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
83
+ ModernRender: (App: React.ReactElement) => void;
84
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
85
85
  }, void>;
86
86
  server: import("@modern-js/plugin").AsyncPipeline<{
87
87
  App: React.ComponentType<any>;
@@ -107,8 +107,8 @@ export declare const createPlugin: (setup?: Setup<{
107
107
  client: import("@modern-js/plugin").AsyncPipeline<{
108
108
  App: React.ComponentType<any>;
109
109
  readonly context?: RuntimeContext | undefined;
110
- ModernRender: (App: React.ReactNode) => void;
111
- ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
110
+ ModernRender: (App: React.ReactElement) => void;
111
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
112
112
  }, void>;
113
113
  server: import("@modern-js/plugin").AsyncPipeline<{
114
114
  App: React.ComponentType<any>;
@@ -133,8 +133,8 @@ export declare const createPlugin: (setup?: Setup<{
133
133
  client: import("@modern-js/plugin").AsyncPipeline<{
134
134
  App: React.ComponentType<any>;
135
135
  readonly context?: RuntimeContext | undefined;
136
- ModernRender: (App: React.ReactNode) => void;
137
- ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
136
+ ModernRender: (App: React.ReactElement) => void;
137
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
138
138
  }, void>;
139
139
  server: import("@modern-js/plugin").AsyncPipeline<{
140
140
  App: React.ComponentType<any>;
@@ -159,8 +159,8 @@ export declare const createPlugin: (setup?: Setup<{
159
159
  client: import("@modern-js/plugin").AsyncPipeline<{
160
160
  App: React.ComponentType<any>;
161
161
  readonly context?: RuntimeContext | undefined;
162
- ModernRender: (App: React.ReactNode) => void;
163
- ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
162
+ ModernRender: (App: React.ReactElement) => void;
163
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
164
164
  }, void>;
165
165
  server: import("@modern-js/plugin").AsyncPipeline<{
166
166
  App: React.ComponentType<any>;
@@ -173,7 +173,7 @@ export declare const createPlugin: (setup?: Setup<{
173
173
  context: RuntimeContext;
174
174
  pickedContext: TRuntimeContext;
175
175
  }, TRuntimeContext>;
176
- }, Record<string, never>>, Record<string, unknown>> | undefined) => import("@modern-js/plugin").Plugin<{
176
+ }, Record<string, never>>, Record<string, unknown>, any, any> | undefined) => import("@modern-js/plugin").Plugin<{
177
177
  hoc: import("@modern-js/plugin").Pipeline<{
178
178
  App: React.ComponentType<any>;
179
179
  }, React.ComponentType<any>>;
@@ -185,8 +185,8 @@ export declare const createPlugin: (setup?: Setup<{
185
185
  client: import("@modern-js/plugin").AsyncPipeline<{
186
186
  App: React.ComponentType<any>;
187
187
  readonly context?: RuntimeContext | undefined;
188
- ModernRender: (App: React.ReactNode) => void;
189
- ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
188
+ ModernRender: (App: React.ReactElement) => void;
189
+ ModernHydrate: (App: React.ReactElement, callback?: () => void) => void;
190
190
  }, void>;
191
191
  server: import("@modern-js/plugin").AsyncPipeline<{
192
192
  App: React.ComponentType<any>;
@@ -1,3 +1,3 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- declare const _default: () => CliPlugin;
1
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
+ declare const _default: () => CliPlugin<AppTools>;
3
3
  export default _default;
@@ -6,7 +6,7 @@ export declare const HTML_SSRDATASCRIPT_SEPARATOR = "<!--<?- SSRDataScript ?>-->
6
6
  export declare const DOCUMENT_SSR_PLACEHOLDER: string;
7
7
  export declare const DOCUMENT_CHUNKSMAP_PLACEHOLDER: string;
8
8
  export declare const DOCUMENT_SSRDATASCRIPT_PLACEHOLDER: string;
9
- export declare const DOCUMENT_FILE_NAME = "document";
9
+ export declare const DOCUMENT_FILE_NAME = "Document";
10
10
  export declare const DOCUMENT_SCRIPTS_PLACEHOLDER: string;
11
11
  export declare const DOCUMENT_NO_SCRIPTE_PLACEHOLDER: string;
12
12
  export declare const PLACEHOLDER_REPLACER_MAP: {
@@ -1,3 +1,3 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- declare const _default: () => CliPlugin;
1
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
+ declare const _default: () => CliPlugin<AppTools>;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- declare const _default: () => CliPlugin;
1
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
+ declare const _default: () => CliPlugin<AppTools>;
3
3
  export default _default;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { ServerConfig } from '@modern-js/core';
2
+ import { ServerUserConfig } from '@modern-js/app-tools';
3
3
  import type { RuntimeContext } from '../../core';
4
4
  import { RenderLevel } from './renderToString/type';
5
5
  export type { SSRServerContext } from './renderToString/type';
@@ -7,7 +7,7 @@ export declare type ModernSSRReactComponent = React.ComponentType<any>;
7
7
  export { RuntimeContext, RenderLevel };
8
8
  export declare type SSRPluginConfig = {
9
9
  crossorigin?: boolean | 'anonymous' | 'use-credentials';
10
- } & Exclude<ServerConfig['ssr'], boolean>;
10
+ } & Exclude<ServerUserConfig['ssr'], boolean>;
11
11
  export declare type ServerRenderOptions = {
12
12
  App: ModernSSRReactComponent;
13
13
  config: SSRPluginConfig;
@@ -1,3 +1,3 @@
1
- import type { CliPlugin } from '@modern-js/core';
2
- declare const _default: () => CliPlugin;
1
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
+ declare const _default: () => CliPlugin<AppTools>;
3
3
  export default _default;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.1",
14
+ "version": "2.0.0-beta.2",
15
15
  "engines": {
16
16
  "node": ">=14.17.6"
17
17
  },
@@ -143,9 +143,9 @@
143
143
  "redux-logger": "^3.0.6",
144
144
  "serialize-javascript": "^6.0.0",
145
145
  "styled-components": "^5.3.1",
146
- "@modern-js/plugin": "2.0.0-beta.1",
147
- "@modern-js/types": "2.0.0-beta.1",
148
- "@modern-js/utils": "2.0.0-beta.1"
146
+ "@modern-js/plugin": "2.0.0-beta.2",
147
+ "@modern-js/types": "2.0.0-beta.2",
148
+ "@modern-js/utils": "2.0.0-beta.2"
149
149
  },
150
150
  "peerDependencies": {
151
151
  "react": ">=17",
@@ -166,11 +166,12 @@
166
166
  "react-dom": "^18",
167
167
  "ts-jest": "^27.0.4",
168
168
  "typescript": "^4",
169
- "@modern-js/core": "2.0.0-beta.1",
170
- "@modern-js/server-core": "2.0.0-beta.1",
171
- "@modern-js/utils": "2.0.0-beta.1",
172
- "@scripts/build": "2.0.0-beta.1",
173
- "@scripts/jest-config": "2.0.0-beta.1"
169
+ "@modern-js/core": "2.0.0-beta.2",
170
+ "@modern-js/server-core": "2.0.0-beta.2",
171
+ "@modern-js/utils": "2.0.0-beta.2",
172
+ "@scripts/build": "2.0.0-beta.2",
173
+ "@modern-js/app-tools": "2.0.0-beta.2",
174
+ "@scripts/jest-config": "2.0.0-beta.2"
174
175
  },
175
176
  "sideEffects": false,
176
177
  "modernConfig": {},
@@ -179,9 +180,9 @@
179
180
  "access": "public"
180
181
  },
181
182
  "scripts": {
182
- "dev": "modern build --watch",
183
- "new": "modern new",
184
- "build": "modern build",
185
- "test": "jest --passWithNoTests"
183
+ "dev": "modern-lib build --watch",
184
+ "new": "modern-lib new",
185
+ "build": "modern-lib build",
186
+ "test": "jest"
186
187
  }
187
188
  }