@modern-js/runtime 1.4.2 → 1.5.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 +38 -0
- package/dist/js/modern/cli/index.js +1 -3
- package/dist/js/modern/core/app-config.js +10 -0
- package/dist/js/modern/core/compatible.js +218 -0
- package/dist/js/modern/core/index.js +7 -0
- package/dist/js/modern/core/loader/index.js +1 -0
- package/dist/js/modern/core/loader/loaderManager.js +189 -0
- package/dist/js/modern/core/loader/useLoader.js +105 -0
- package/dist/js/modern/core/plugin.js +63 -0
- package/dist/js/modern/core/runtime-context.js +2 -0
- package/dist/js/modern/exports/styled.js +2 -2
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/router/cli/index.js +1 -3
- package/dist/js/modern/router/runtime/plugin.js +1 -1
- package/dist/js/modern/router/runtime/utils.js +3 -1
- package/dist/js/modern/ssr/cli/index.js +1 -3
- package/dist/js/modern/ssr/index.node.js +1 -1
- package/dist/js/modern/ssr/prefetch.js +2 -2
- package/dist/js/modern/ssr/serverRender/index.js +1 -1
- package/dist/js/modern/ssr/serverRender/styledComponent.js +1 -1
- package/dist/js/modern/state/cli/index.js +1 -3
- package/dist/js/modern/state/runtime/plugin.js +1 -1
- package/dist/js/node/cli/index.js +1 -3
- package/dist/js/node/core/app-config.js +22 -0
- package/dist/js/node/core/compatible.js +247 -0
- package/dist/js/node/core/index.js +111 -0
- package/dist/js/node/core/loader/index.js +15 -0
- package/dist/js/node/core/loader/loaderManager.js +201 -0
- package/dist/js/node/core/loader/useLoader.js +118 -0
- package/dist/js/node/core/plugin.js +79 -0
- package/dist/js/node/core/runtime-context.js +11 -0
- package/dist/js/node/exports/styled.js +5 -5
- package/dist/js/node/index.js +10 -10
- package/dist/js/node/router/cli/index.js +1 -8
- package/dist/js/node/router/runtime/plugin.js +3 -3
- package/dist/js/node/router/runtime/utils.js +3 -1
- package/dist/js/node/ssr/cli/index.js +1 -8
- package/dist/js/node/ssr/index.node.js +2 -2
- package/dist/js/node/ssr/serverRender/index.js +2 -2
- package/dist/js/node/ssr/serverRender/styledComponent.js +2 -2
- package/dist/js/node/state/cli/index.js +1 -8
- package/dist/js/node/state/runtime/plugin.js +3 -3
- package/dist/js/treeshaking/cli/index.js +1 -3
- package/dist/js/treeshaking/core/app-config.js +13 -0
- package/dist/js/treeshaking/core/compatible.js +255 -0
- package/dist/js/treeshaking/core/index.js +7 -0
- package/dist/js/treeshaking/core/loader/index.js +1 -0
- package/dist/js/treeshaking/core/loader/loaderManager.js +267 -0
- package/dist/js/treeshaking/core/loader/useLoader.js +107 -0
- package/dist/js/treeshaking/core/plugin.js +105 -0
- package/dist/js/treeshaking/core/runtime-context.js +2 -0
- package/dist/js/treeshaking/exports/styled.js +2 -2
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/router/cli/index.js +1 -3
- package/dist/js/treeshaking/router/runtime/plugin.js +1 -1
- package/dist/js/treeshaking/router/runtime/utils.js +3 -1
- package/dist/js/treeshaking/ssr/cli/index.js +1 -3
- package/dist/js/treeshaking/ssr/index.node.js +1 -1
- package/dist/js/treeshaking/ssr/prefetch.js +2 -2
- package/dist/js/treeshaking/ssr/serverRender/index.js +1 -1
- package/dist/js/treeshaking/ssr/serverRender/styledComponent.js +1 -1
- package/dist/js/treeshaking/state/cli/index.js +1 -3
- package/dist/js/treeshaking/state/runtime/plugin.js +1 -1
- package/dist/types/core/app-config.d.ts +6 -0
- package/dist/types/core/compatible.d.ts +13 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/loader/index.d.ts +2 -0
- package/dist/types/core/loader/loaderManager.d.ts +57 -0
- package/dist/types/core/loader/useLoader.d.ts +54 -0
- package/dist/types/core/plugin.d.ts +208 -0
- package/dist/types/core/runtime-context.d.ts +13 -0
- package/dist/types/exports/styled.d.ts +2 -2
- package/dist/types/index.d.ts +4 -9
- package/dist/types/router/runtime/plugin.d.ts +1 -1
- package/dist/types/ssr/index.d.ts +2 -2
- package/dist/types/ssr/index.node.d.ts +1 -1
- package/dist/types/ssr/prefetch.d.ts +2 -2
- package/dist/types/ssr/serverRender/entry.d.ts +1 -1
- package/dist/types/ssr/serverRender/index.d.ts +1 -1
- package/dist/types/ssr/serverRender/type.d.ts +1 -1
- package/dist/types/state/runtime/plugin.d.ts +2 -2
- package/lib/types.d.ts +10 -0
- package/package.json +59 -25
|
@@ -4,7 +4,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
-
import path from 'path';
|
|
8
7
|
import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
9
8
|
const PLUGIN_IDENTIFIER = 'router';
|
|
10
9
|
const ROUTES_IDENTIFIER = 'routes';
|
|
@@ -14,7 +13,6 @@ export default (() => ({
|
|
|
14
13
|
setup: api => {
|
|
15
14
|
const runtimeConfigMap = new Map();
|
|
16
15
|
let pluginsExportsUtils;
|
|
17
|
-
const runtimeModulePath = path.resolve(__dirname, '../');
|
|
18
16
|
return {
|
|
19
17
|
config() {
|
|
20
18
|
const appContext = api.useAppContext();
|
|
@@ -98,7 +96,7 @@ export default (() => ({
|
|
|
98
96
|
},
|
|
99
97
|
|
|
100
98
|
addRuntimeExports() {
|
|
101
|
-
pluginsExportsUtils.addExport(`export { default as router } from '
|
|
99
|
+
pluginsExportsUtils.addExport(`export { default as router } from '@modern-js/runtime/runtime-router'`);
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
};
|
|
@@ -7,8 +7,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
7
7
|
import React, { useContext } from 'react';
|
|
8
8
|
import { createBrowserHistory, createHashHistory } from 'history';
|
|
9
9
|
import { Router, StaticRouter } from 'react-router-dom';
|
|
10
|
-
import { RuntimeReactContext } from '@modern-js/runtime-core';
|
|
11
10
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
11
|
+
import { RuntimeReactContext } from "../../core";
|
|
12
12
|
import { isBrowser } from "../../common";
|
|
13
13
|
import { renderRoutes, getLocation, urlJoin } from "./utils";
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -67,11 +67,13 @@ export function renderRoutes(routesConfig, extraProps = {}) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
export function getLocation(serverContext) {
|
|
70
|
+
var _url$replace;
|
|
71
|
+
|
|
70
72
|
const {
|
|
71
73
|
pathname,
|
|
72
74
|
url
|
|
73
75
|
} = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
|
|
74
|
-
const cleanUrl = url.replace('http://', '').replace('https://', '');
|
|
76
|
+
const cleanUrl = url === null || url === void 0 ? void 0 : (_url$replace = url.replace('http://', '')) === null || _url$replace === void 0 ? void 0 : _url$replace.replace('https://', '');
|
|
75
77
|
const index = (cleanUrl || '').indexOf(pathname);
|
|
76
78
|
|
|
77
79
|
if (index === -1) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { getEntryOptions, SERVER_RENDER_FUNCTION_NAME, LOADABLE_STATS_FILE, isUseSSRBundle, createRuntimeExportsUtils, isSingleEntry } from '@modern-js/utils';
|
|
3
2
|
const PLUGIN_IDENTIFIER = 'ssr';
|
|
4
3
|
export default (() => ({
|
|
@@ -7,7 +6,6 @@ export default (() => ({
|
|
|
7
6
|
setup: api => {
|
|
8
7
|
const ssrConfigMap = new Map();
|
|
9
8
|
let pluginsExportsUtils;
|
|
10
|
-
const ssrModulePath = path.resolve(__dirname, '../');
|
|
11
9
|
return {
|
|
12
10
|
config() {
|
|
13
11
|
const appContext = api.useAppContext();
|
|
@@ -57,7 +55,7 @@ export default (() => ({
|
|
|
57
55
|
packageName,
|
|
58
56
|
entrypoints
|
|
59
57
|
} = api.useAppContext();
|
|
60
|
-
pluginsExportsUtils.addExport(`export { default as ssr } from '
|
|
58
|
+
pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/runtime-ssr'`); // if use ssg then set ssr config to true
|
|
61
59
|
|
|
62
60
|
const ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
|
|
63
61
|
const ssgConfig = userConfig.output.ssg;
|
|
@@ -8,7 +8,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
8
8
|
|
|
9
9
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
10
10
|
import path from 'path';
|
|
11
|
-
import { registerPrefetch } from
|
|
11
|
+
import { registerPrefetch } from "../core";
|
|
12
12
|
import { isBrowser } from "../common";
|
|
13
13
|
import prefetch from "./prefetch";
|
|
14
14
|
import { formatServer } from "./utils";
|
|
@@ -3,10 +3,10 @@ import fs from 'fs';
|
|
|
3
3
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
4
4
|
import { run } from '@modern-js/utils/ssr';
|
|
5
5
|
import { LOADABLE_STATS_FILE } from '@modern-js/utils/constants';
|
|
6
|
-
import { ChunkExtractor } from '@loadable/server';
|
|
7
|
-
|
|
6
|
+
import { ChunkExtractor } from '@loadable/server';
|
|
8
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
8
|
|
|
9
|
+
// todo: SSRContext
|
|
10
10
|
const prefetch = async (App, context) => run(context.ssrContext.request.headers, async () => {
|
|
11
11
|
var _context$store;
|
|
12
12
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RuntimeContext } from '@modern-js/runtime-core';
|
|
2
1
|
import { run } from '@modern-js/utils/ssr';
|
|
2
|
+
import { RuntimeContext } from "../../core";
|
|
3
3
|
import { PreRender } from "../react/prerender";
|
|
4
4
|
import SSREntry from "./entry";
|
|
5
5
|
import { time } from "./measure";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
3
2
|
import "../types";
|
|
4
3
|
const PLUGIN_IDENTIFIER = 'state';
|
|
@@ -8,7 +7,6 @@ export default (() => ({
|
|
|
8
7
|
setup: api => {
|
|
9
8
|
const stateConfigMap = new Map();
|
|
10
9
|
let pluginsExportsUtils;
|
|
11
|
-
const stateModulePath = path.resolve(__dirname, '../');
|
|
12
10
|
return {
|
|
13
11
|
config() {
|
|
14
12
|
const appContext = api.useAppContext();
|
|
@@ -102,7 +100,7 @@ export default (() => ({
|
|
|
102
100
|
},
|
|
103
101
|
|
|
104
102
|
addRuntimeExports() {
|
|
105
|
-
pluginsExportsUtils.addExport(`export { default as state } from '
|
|
103
|
+
pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/runtime-state'`);
|
|
106
104
|
}
|
|
107
105
|
|
|
108
106
|
};
|
|
@@ -5,10 +5,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
7
|
import { useContext } from 'react';
|
|
8
|
-
import { RuntimeReactContext } from '@modern-js/runtime-core';
|
|
9
8
|
import { createStore } from '@modern-js-reduck/store';
|
|
10
9
|
import { Provider } from '@modern-js-reduck/react';
|
|
11
10
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
11
|
+
import { RuntimeReactContext } from "../../core";
|
|
12
12
|
import { isBrowser } from "../../common";
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
|
|
@@ -39,9 +39,7 @@ var _default = () => ({
|
|
|
39
39
|
* But it will not be installed under the user project.
|
|
40
40
|
* So need to add alias
|
|
41
41
|
*/
|
|
42
|
-
'styled-components': require.resolve('styled-components'
|
|
43
|
-
paths: [require.resolve('@modern-js/runtime-core')]
|
|
44
|
-
})
|
|
42
|
+
'styled-components': require.resolve('styled-components')
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getConfig = exports.defineConfig = void 0;
|
|
7
|
+
const APP_CONFIG_SYMBOL = 'config';
|
|
8
|
+
|
|
9
|
+
const getConfig = Component => // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
Component[APP_CONFIG_SYMBOL];
|
|
12
|
+
|
|
13
|
+
exports.getConfig = getConfig;
|
|
14
|
+
|
|
15
|
+
const defineConfig = (Component, config) => {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
Component[APP_CONFIG_SYMBOL] = config;
|
|
19
|
+
return Component;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.defineConfig = defineConfig;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useRuntimeContext = exports.createApp = exports.bootstrap = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
11
|
+
|
|
12
|
+
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
13
|
+
|
|
14
|
+
var _plugin = require("./plugin");
|
|
15
|
+
|
|
16
|
+
var _runtimeContext = require("./runtime-context");
|
|
17
|
+
|
|
18
|
+
var _loaderManager = require("./loader/loaderManager");
|
|
19
|
+
|
|
20
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
+
|
|
22
|
+
const _excluded = ["context"];
|
|
23
|
+
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
+
|
|
26
|
+
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); }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
30
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
31
|
+
|
|
32
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
function isClientArgs(id) {
|
|
41
|
+
return typeof id === 'string' || typeof HTMLElement !== 'undefined' && id instanceof HTMLElement;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const runnerMap = new WeakMap();
|
|
45
|
+
|
|
46
|
+
const getInitialContext = runner => ({
|
|
47
|
+
loaderManager: (0, _loaderManager.createLoaderManager)({}),
|
|
48
|
+
runner,
|
|
49
|
+
isBrowser: true
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const createApp = ({
|
|
53
|
+
plugins
|
|
54
|
+
}) => {
|
|
55
|
+
const appRuntime = _plugin.runtime.clone();
|
|
56
|
+
|
|
57
|
+
appRuntime.usePlugin(...plugins);
|
|
58
|
+
return App => {
|
|
59
|
+
const runner = appRuntime.init();
|
|
60
|
+
|
|
61
|
+
const WrapperComponent = props => {
|
|
62
|
+
const element = /*#__PURE__*/_react.default.createElement(App || _react.default.Fragment, _objectSpread({}, props), props.children);
|
|
63
|
+
|
|
64
|
+
const context = (0, _react.useContext)(_runtimeContext.RuntimeReactContext);
|
|
65
|
+
return runner.provide({
|
|
66
|
+
element,
|
|
67
|
+
props: _objectSpread({}, props),
|
|
68
|
+
context
|
|
69
|
+
}, {
|
|
70
|
+
onLast: ({
|
|
71
|
+
element
|
|
72
|
+
}) => element
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (App) {
|
|
77
|
+
(0, _hoistNonReactStatics.default)(WrapperComponent, App);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const HOCApp = runner.hoc({
|
|
81
|
+
App: WrapperComponent
|
|
82
|
+
}, {
|
|
83
|
+
onLast: ({
|
|
84
|
+
App
|
|
85
|
+
}) => {
|
|
86
|
+
const WrapComponent = _ref => {
|
|
87
|
+
var _contextValue;
|
|
88
|
+
|
|
89
|
+
let {
|
|
90
|
+
context
|
|
91
|
+
} = _ref,
|
|
92
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
93
|
+
|
|
94
|
+
let contextValue = context; // We should construct the context, when root component is not passed into `bootstrap`.
|
|
95
|
+
|
|
96
|
+
if (!((_contextValue = contextValue) !== null && _contextValue !== void 0 && _contextValue.runner)) {
|
|
97
|
+
contextValue = getInitialContext(runner);
|
|
98
|
+
runner.init({
|
|
99
|
+
context: contextValue
|
|
100
|
+
}, {
|
|
101
|
+
onLast: ({
|
|
102
|
+
context: context1
|
|
103
|
+
}) => {
|
|
104
|
+
var _App$init;
|
|
105
|
+
|
|
106
|
+
return App === null || App === void 0 ? void 0 : (_App$init = App.init) === null || _App$init === void 0 ? void 0 : _App$init.call(App, context1);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_runtimeContext.RuntimeReactContext.Provider, {
|
|
112
|
+
value: contextValue,
|
|
113
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return (0, _hoistNonReactStatics.default)(WrapComponent, App);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
runnerMap.set(HOCApp, runner);
|
|
121
|
+
return HOCApp;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
exports.createApp = createApp;
|
|
126
|
+
|
|
127
|
+
const bootstrap = async (BootApp,
|
|
128
|
+
/**
|
|
129
|
+
* When csr, id is root id.
|
|
130
|
+
* When ssr, id is serverContext
|
|
131
|
+
*/
|
|
132
|
+
id) => {
|
|
133
|
+
let App = BootApp;
|
|
134
|
+
let runner = runnerMap.get(App); // ensure Component used is created by `createApp`
|
|
135
|
+
|
|
136
|
+
if (!runner) {
|
|
137
|
+
App = createApp({
|
|
138
|
+
plugins: []
|
|
139
|
+
})(App);
|
|
140
|
+
runner = runnerMap.get(App);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const context = getInitialContext(runner);
|
|
144
|
+
|
|
145
|
+
const runInit = _context => runner.init({
|
|
146
|
+
context: _context
|
|
147
|
+
}, {
|
|
148
|
+
onLast: ({
|
|
149
|
+
context: context1
|
|
150
|
+
}) => {
|
|
151
|
+
var _App, _App$init2;
|
|
152
|
+
|
|
153
|
+
return (_App = App) === null || _App === void 0 ? void 0 : (_App$init2 = _App.init) === null || _App$init2 === void 0 ? void 0 : _App$init2.call(_App, context1);
|
|
154
|
+
}
|
|
155
|
+
}); // don't mount the App, let user in charge of it.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
if (!id) {
|
|
159
|
+
return /*#__PURE__*/_react.default.createElement(App, {
|
|
160
|
+
context
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const isBrowser = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
165
|
+
|
|
166
|
+
if (isBrowser) {
|
|
167
|
+
if (isClientArgs(id)) {
|
|
168
|
+
var _ssrData$data, _ssrData$data2;
|
|
169
|
+
|
|
170
|
+
const ssrData = window._SSR_DATA;
|
|
171
|
+
const loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData$data = ssrData.data) === null || _ssrData$data === void 0 ? void 0 : _ssrData$data.loadersData) || {};
|
|
172
|
+
const initialLoadersState = Object.keys(loadersData).reduce((res, key) => {
|
|
173
|
+
const loaderData = loadersData[key];
|
|
174
|
+
|
|
175
|
+
if (loaderData.loading !== false) {
|
|
176
|
+
return res;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
res[key] = loaderData;
|
|
180
|
+
return res;
|
|
181
|
+
}, {});
|
|
182
|
+
Object.assign(context, _objectSpread({
|
|
183
|
+
loaderManager: (0, _loaderManager.createLoaderManager)(initialLoadersState, {
|
|
184
|
+
skipStatic: true
|
|
185
|
+
})
|
|
186
|
+
}, ssrData ? {
|
|
187
|
+
ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
|
|
188
|
+
} : {}));
|
|
189
|
+
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData$data2 = ssrData.data) === null || _ssrData$data2 === void 0 ? void 0 : _ssrData$data2.initialData;
|
|
190
|
+
const initialData = await runInit(context);
|
|
191
|
+
|
|
192
|
+
if (initialData) {
|
|
193
|
+
context.initialData = initialData;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return runner.client({
|
|
197
|
+
App,
|
|
198
|
+
context,
|
|
199
|
+
rootElement: typeof id !== 'string' ? id : document.getElementById(id || 'root')
|
|
200
|
+
}, {
|
|
201
|
+
onLast: ({
|
|
202
|
+
App,
|
|
203
|
+
rootElement
|
|
204
|
+
}) => {
|
|
205
|
+
_reactDom.default.render( /*#__PURE__*/_react.default.createElement(App, {
|
|
206
|
+
context
|
|
207
|
+
}), rootElement);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
throw Error('`bootstrap` needs id in browser environment, it needs to be string or element');
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
Object.assign(context, {
|
|
215
|
+
ssrContext: id,
|
|
216
|
+
isBrowser: false,
|
|
217
|
+
loaderManager: (0, _loaderManager.createLoaderManager)({}, {
|
|
218
|
+
skipNonStatic: id.staticGenerate,
|
|
219
|
+
// if not static generate, only non-static loader can exec on prod env
|
|
220
|
+
skipStatic: process.env.NODE_ENV === 'production' && !id.staticGenerate
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
const initialData = await runInit(context);
|
|
224
|
+
context.initialData = initialData;
|
|
225
|
+
return runner.server({
|
|
226
|
+
App,
|
|
227
|
+
context
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
exports.bootstrap = bootstrap;
|
|
233
|
+
|
|
234
|
+
const useRuntimeContext = () => {
|
|
235
|
+
const context = (0, _react.useContext)(_runtimeContext.RuntimeReactContext);
|
|
236
|
+
const memoizedContext = (0, _react.useMemo)(() => context.runner.pickContext({
|
|
237
|
+
context,
|
|
238
|
+
pickedContext: {}
|
|
239
|
+
}, {
|
|
240
|
+
onLast: ({
|
|
241
|
+
pickedContext
|
|
242
|
+
}) => pickedContext
|
|
243
|
+
}), [context]);
|
|
244
|
+
return memoizedContext;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
exports.useRuntimeContext = useRuntimeContext;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
createPlugin: true,
|
|
8
|
+
createRuntime: true,
|
|
9
|
+
runtime: true,
|
|
10
|
+
registerInit: true,
|
|
11
|
+
registerPrefetch: true,
|
|
12
|
+
defineConfig: true,
|
|
13
|
+
getConfig: true,
|
|
14
|
+
RuntimeReactContext: true
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "RuntimeReactContext", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _runtimeContext.RuntimeReactContext;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "createPlugin", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _plugin.createPlugin;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "createRuntime", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _plugin.createRuntime;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "defineConfig", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return _appConfig.defineConfig;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "getConfig", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return _appConfig.getConfig;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "registerInit", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return _plugin.registerInit;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "registerPrefetch", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return _plugin.registerPrefetch;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(exports, "runtime", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () {
|
|
61
|
+
return _plugin.runtime;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
var _plugin = require("./plugin");
|
|
66
|
+
|
|
67
|
+
var _appConfig = require("./app-config");
|
|
68
|
+
|
|
69
|
+
var _compatible = require("./compatible");
|
|
70
|
+
|
|
71
|
+
Object.keys(_compatible).forEach(function (key) {
|
|
72
|
+
if (key === "default" || key === "__esModule") return;
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
74
|
+
if (key in exports && exports[key] === _compatible[key]) return;
|
|
75
|
+
Object.defineProperty(exports, key, {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () {
|
|
78
|
+
return _compatible[key];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
var _runtimeContext = require("./runtime-context");
|
|
84
|
+
|
|
85
|
+
var _loader = require("./loader");
|
|
86
|
+
|
|
87
|
+
Object.keys(_loader).forEach(function (key) {
|
|
88
|
+
if (key === "default" || key === "__esModule") return;
|
|
89
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
90
|
+
if (key in exports && exports[key] === _loader[key]) return;
|
|
91
|
+
Object.defineProperty(exports, key, {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return _loader[key];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
var _plugin2 = require("@modern-js/plugin");
|
|
100
|
+
|
|
101
|
+
Object.keys(_plugin2).forEach(function (key) {
|
|
102
|
+
if (key === "default" || key === "__esModule") return;
|
|
103
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
104
|
+
if (key in exports && exports[key] === _plugin2[key]) return;
|
|
105
|
+
Object.defineProperty(exports, key, {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () {
|
|
108
|
+
return _plugin2[key];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useLoader", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useLoader.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _useLoader = _interopRequireDefault(require("./useLoader"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|