@modern-js/runtime 1.3.4 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/dist/js/modern/cli/index.js +4 -4
- package/dist/js/modern/common.js +1 -0
- package/dist/js/modern/exports/model.js +2 -1
- package/dist/js/modern/exports/router.js +2 -1
- package/dist/js/modern/exports/server.js +0 -1
- package/dist/js/modern/exports/ssr.js +2 -1
- package/dist/js/modern/router/cli/index.js +106 -0
- package/dist/js/modern/router/index.js +2 -0
- package/dist/js/modern/router/runtime/DefaultNotFound.js +13 -0
- package/dist/js/modern/router/runtime/index.js +4 -0
- package/dist/js/modern/router/runtime/plugin.js +88 -0
- package/dist/js/modern/router/runtime/utils.js +108 -0
- package/dist/js/modern/ssr/cli/index.js +120 -0
- package/dist/js/modern/ssr/index.js +109 -0
- package/dist/js/modern/ssr/index.node.js +78 -0
- package/dist/js/modern/ssr/prefetch.js +58 -0
- package/dist/js/modern/ssr/react/index.js +2 -0
- package/dist/js/modern/ssr/react/nossr/index.js +13 -0
- package/dist/js/modern/ssr/react/prerender/index.js +104 -0
- package/dist/js/modern/ssr/react/prerender/type.js +0 -0
- package/dist/js/modern/ssr/react/prerender/util.js +99 -0
- package/dist/js/modern/ssr/serverRender/entry.js +179 -0
- package/dist/js/modern/ssr/serverRender/helmet.js +46 -0
- package/dist/js/modern/ssr/serverRender/index.js +29 -0
- package/dist/js/modern/ssr/serverRender/loadable.js +48 -0
- package/dist/js/modern/ssr/serverRender/measure.js +11 -0
- package/dist/js/modern/ssr/serverRender/reduce.js +7 -0
- package/dist/js/modern/ssr/serverRender/styledComponent.js +8 -0
- package/dist/js/modern/ssr/serverRender/template.js +90 -0
- package/dist/js/modern/ssr/serverRender/type.js +8 -0
- package/dist/js/modern/ssr/utils.js +51 -0
- package/dist/js/modern/state/cli/index.js +110 -0
- package/dist/js/modern/state/index.js +2 -0
- package/dist/js/modern/state/plugins.js +7 -0
- package/dist/js/modern/state/runtime/index.js +4 -0
- package/dist/js/modern/state/runtime/plugin.js +71 -0
- package/dist/js/modern/state/types.js +1 -0
- package/dist/js/node/cli/index.js +5 -5
- package/dist/js/node/common.js +10 -0
- package/dist/js/node/exports/model.js +19 -5
- package/dist/js/node/exports/router.js +19 -5
- package/dist/js/node/exports/server.js +0 -17
- package/dist/js/node/exports/ssr.js +19 -5
- package/dist/js/node/router/cli/index.js +122 -0
- package/dist/js/node/router/index.js +30 -0
- package/dist/js/node/router/runtime/DefaultNotFound.js +26 -0
- package/dist/js/node/router/runtime/index.js +39 -0
- package/dist/js/node/router/runtime/plugin.js +111 -0
- package/dist/js/node/router/runtime/utils.js +128 -0
- package/dist/js/node/ssr/cli/index.js +136 -0
- package/dist/js/node/ssr/index.js +138 -0
- package/dist/js/node/ssr/index.node.js +105 -0
- package/dist/js/node/ssr/prefetch.js +75 -0
- package/dist/js/node/ssr/react/index.js +21 -0
- package/dist/js/node/ssr/react/nossr/index.js +28 -0
- package/dist/js/node/ssr/react/prerender/index.js +121 -0
- package/dist/js/node/ssr/react/prerender/type.js +0 -0
- package/dist/js/node/ssr/react/prerender/util.js +119 -0
- package/dist/js/node/ssr/serverRender/entry.js +208 -0
- package/dist/js/node/ssr/serverRender/helmet.js +52 -0
- package/dist/js/node/ssr/serverRender/index.js +46 -0
- package/dist/js/node/ssr/serverRender/loadable.js +60 -0
- package/dist/js/node/ssr/serverRender/measure.js +20 -0
- package/dist/js/node/ssr/serverRender/reduce.js +14 -0
- package/dist/js/node/ssr/serverRender/styledComponent.js +18 -0
- package/dist/js/node/ssr/serverRender/template.js +103 -0
- package/dist/js/node/ssr/serverRender/type.js +15 -0
- package/dist/js/node/ssr/utils.js +65 -0
- package/dist/js/node/state/cli/index.js +127 -0
- package/dist/js/node/state/index.js +30 -0
- package/dist/js/node/state/plugins.js +35 -0
- package/dist/js/node/state/runtime/index.js +61 -0
- package/dist/js/node/state/runtime/plugin.js +101 -0
- package/dist/js/node/state/types.js +5 -0
- package/dist/js/treeshaking/cli/index.js +4 -4
- package/dist/js/treeshaking/common.js +3 -0
- package/dist/js/treeshaking/exports/model.js +2 -1
- package/dist/js/treeshaking/exports/router.js +2 -1
- package/dist/js/treeshaking/exports/server.js +0 -1
- package/dist/js/treeshaking/exports/ssr.js +2 -1
- package/dist/js/treeshaking/router/cli/index.js +100 -0
- package/dist/js/treeshaking/router/index.js +2 -0
- package/dist/js/treeshaking/router/runtime/DefaultNotFound.js +15 -0
- package/dist/js/treeshaking/router/runtime/index.js +4 -0
- package/dist/js/treeshaking/router/runtime/plugin.js +89 -0
- package/dist/js/treeshaking/router/runtime/utils.js +106 -0
- package/dist/js/treeshaking/ssr/cli/index.js +113 -0
- package/dist/js/treeshaking/ssr/index.js +129 -0
- package/dist/js/treeshaking/ssr/index.node.js +100 -0
- package/dist/js/treeshaking/ssr/prefetch.js +97 -0
- package/dist/js/treeshaking/ssr/react/index.js +2 -0
- package/dist/js/treeshaking/ssr/react/nossr/index.js +16 -0
- package/dist/js/treeshaking/ssr/react/prerender/index.js +119 -0
- package/dist/js/treeshaking/ssr/react/prerender/type.js +0 -0
- package/dist/js/treeshaking/ssr/react/prerender/util.js +115 -0
- package/dist/js/treeshaking/ssr/serverRender/entry.js +267 -0
- package/dist/js/treeshaking/ssr/serverRender/helmet.js +37 -0
- package/dist/js/treeshaking/ssr/serverRender/index.js +69 -0
- package/dist/js/treeshaking/ssr/serverRender/loadable.js +59 -0
- package/dist/js/treeshaking/ssr/serverRender/measure.js +17 -0
- package/dist/js/treeshaking/ssr/serverRender/reduce.js +11 -0
- package/dist/js/treeshaking/ssr/serverRender/styledComponent.js +8 -0
- package/dist/js/treeshaking/ssr/serverRender/template.js +111 -0
- package/dist/js/treeshaking/ssr/serverRender/type.js +8 -0
- package/dist/js/treeshaking/ssr/utils.js +53 -0
- package/dist/js/treeshaking/state/cli/index.js +100 -0
- package/dist/js/treeshaking/state/index.js +2 -0
- package/dist/js/treeshaking/state/plugins.js +13 -0
- package/dist/js/treeshaking/state/runtime/index.js +4 -0
- package/dist/js/treeshaking/state/runtime/plugin.js +63 -0
- package/dist/js/treeshaking/state/types.js +1 -0
- package/dist/types/common.d.ts +1 -0
- package/dist/types/exports/model.d.ts +2 -1
- package/dist/types/exports/router.d.ts +2 -1
- package/dist/types/exports/server.d.ts +0 -1
- package/dist/types/exports/ssr.d.ts +2 -1
- package/dist/types/index.d.ts +8 -2
- package/dist/types/router/cli/index.d.ts +5 -0
- package/dist/types/router/index.d.ts +2 -0
- package/dist/types/router/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/router/runtime/index.d.ts +6 -0
- package/dist/types/router/runtime/plugin.d.ts +51 -0
- package/dist/types/router/runtime/utils.d.ts +6 -0
- package/dist/types/ssr/cli/index.d.ts +5 -0
- package/dist/types/ssr/index.d.ts +18 -0
- package/dist/types/ssr/index.node.d.ts +4 -0
- package/dist/types/ssr/prefetch.d.ts +13 -0
- package/dist/types/ssr/react/index.d.ts +2 -0
- package/dist/types/ssr/react/nossr/index.d.ts +2 -0
- package/dist/types/ssr/react/prerender/index.d.ts +1 -0
- package/dist/types/ssr/react/prerender/type.d.ts +29 -0
- package/dist/types/ssr/react/prerender/util.d.ts +6 -0
- package/dist/types/ssr/serverRender/entry.d.ts +20 -0
- package/dist/types/ssr/serverRender/helmet.d.ts +2 -0
- package/dist/types/ssr/serverRender/index.d.ts +8 -0
- package/dist/types/ssr/serverRender/loadable.d.ts +2 -0
- package/dist/types/ssr/serverRender/measure.d.ts +1 -0
- package/dist/types/ssr/serverRender/reduce.d.ts +3 -0
- package/dist/types/ssr/serverRender/styledComponent.d.ts +2 -0
- package/dist/types/ssr/serverRender/template.d.ts +14 -0
- package/dist/types/ssr/serverRender/type.d.ts +32 -0
- package/dist/types/ssr/utils.d.ts +8 -0
- package/dist/types/state/cli/index.d.ts +5 -0
- package/dist/types/state/index.d.ts +2 -0
- package/dist/types/state/plugins.d.ts +4 -0
- package/dist/types/state/runtime/index.d.ts +4 -0
- package/dist/types/state/runtime/plugin.d.ts +17 -0
- package/dist/types/state/types.d.ts +17 -0
- package/package.json +36 -20
- package/types/model.d.ts +1 -1
- package/types/state.d.ts +4 -0
- package/dist/js/modern/exports/request.js +0 -1
- package/dist/js/node/exports/request.js +0 -13
- package/dist/js/treeshaking/exports/request.js +0 -1
- package/dist/types/exports/request.d.ts +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
3
|
+
import "../types";
|
|
4
|
+
var PLUGIN_IDENTIFIER = 'state';
|
|
5
|
+
export default (function () {
|
|
6
|
+
return {
|
|
7
|
+
name: '@modern-js/plugin-state',
|
|
8
|
+
required: ['@modern-js/runtime'],
|
|
9
|
+
setup: function setup(api) {
|
|
10
|
+
var stateConfigMap = new Map();
|
|
11
|
+
var pluginsExportsUtils;
|
|
12
|
+
var stateModulePath = path.resolve(__dirname, '../');
|
|
13
|
+
return {
|
|
14
|
+
config: function config() {
|
|
15
|
+
var appContext = api.useAppContext();
|
|
16
|
+
pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'plugins');
|
|
17
|
+
return {
|
|
18
|
+
source: {
|
|
19
|
+
alias: {
|
|
20
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
modifyEntryImports: function modifyEntryImports(_ref) {
|
|
26
|
+
var _getEntryOptions;
|
|
27
|
+
|
|
28
|
+
var entrypoint = _ref.entrypoint,
|
|
29
|
+
imports = _ref.imports;
|
|
30
|
+
var entryName = entrypoint.entryName;
|
|
31
|
+
var userConfig = api.useResolvedConfigContext();
|
|
32
|
+
|
|
33
|
+
var _api$useAppContext = api.useAppContext(),
|
|
34
|
+
packageName = _api$useAppContext.packageName;
|
|
35
|
+
|
|
36
|
+
var stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
37
|
+
stateConfigMap.set(entryName, stateConfig);
|
|
38
|
+
|
|
39
|
+
var getEnabledPlugins = function getEnabledPlugins() {
|
|
40
|
+
var internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
|
|
41
|
+
return internalPlugins.filter(function (name) {
|
|
42
|
+
return stateConfig[name] !== false;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (stateConfig) {
|
|
47
|
+
imports.push({
|
|
48
|
+
value: '@modern-js/runtime/plugins',
|
|
49
|
+
specifiers: [{
|
|
50
|
+
imported: PLUGIN_IDENTIFIER
|
|
51
|
+
}]
|
|
52
|
+
});
|
|
53
|
+
imports.push({
|
|
54
|
+
value: '@modern-js/runtime/model',
|
|
55
|
+
specifiers: getEnabledPlugins().map(function (imported) {
|
|
56
|
+
return {
|
|
57
|
+
imported: imported
|
|
58
|
+
};
|
|
59
|
+
}),
|
|
60
|
+
initialize: "\n const createStatePlugins = (config) => {\n const plugins = [];\n\n ".concat(getEnabledPlugins().map(function (name) {
|
|
61
|
+
return "\n plugins.push(".concat(name, "(config['").concat(name, "']));\n ");
|
|
62
|
+
}).join('\n'), "\n\n return plugins;\n }\n ")
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
entrypoint: entrypoint,
|
|
68
|
+
imports: imports
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(_ref2) {
|
|
72
|
+
var entrypoint = _ref2.entrypoint,
|
|
73
|
+
plugins = _ref2.plugins;
|
|
74
|
+
var stateOptions = stateConfigMap.get(entrypoint.entryName);
|
|
75
|
+
|
|
76
|
+
if (stateOptions) {
|
|
77
|
+
var isBoolean = typeof stateOptions === 'boolean';
|
|
78
|
+
var options = isBoolean ? '{}' : JSON.stringify(stateOptions);
|
|
79
|
+
options = "".concat(options.substr(0, options.length - 1)).concat(isBoolean ? '' : ',', "plugins: createStatePlugins(").concat(JSON.stringify(stateConfigMap.get(entrypoint.entryName)), ")}");
|
|
80
|
+
plugins.push({
|
|
81
|
+
name: PLUGIN_IDENTIFIER,
|
|
82
|
+
options: options
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
entrypoint: entrypoint,
|
|
88
|
+
plugins: plugins
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
validateSchema: function validateSchema() {
|
|
92
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-state'];
|
|
93
|
+
},
|
|
94
|
+
addRuntimeExports: function addRuntimeExports() {
|
|
95
|
+
pluginsExportsUtils.addExport("export { default as state } from '".concat(stateModulePath, "'"));
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { plugin as effectsPlugin } from '@modern-js-reduck/plugin-effects';
|
|
2
|
+
import autoActionsPlugin from '@modern-js-reduck/plugin-auto-actions';
|
|
3
|
+
import immerPlugin from '@modern-js-reduck/plugin-immutable';
|
|
4
|
+
export { default as devtools } from '@modern-js-reduck/plugin-devtools';
|
|
5
|
+
export var effects = function effects() {
|
|
6
|
+
return effectsPlugin;
|
|
7
|
+
};
|
|
8
|
+
export var immer = function immer() {
|
|
9
|
+
return immerPlugin;
|
|
10
|
+
};
|
|
11
|
+
export var autoActions = function autoActions() {
|
|
12
|
+
return autoActionsPlugin;
|
|
13
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { RuntimeReactContext } from '@modern-js/runtime-core';
|
|
4
|
+
import { createStore } from '@modern-js-reduck/store';
|
|
5
|
+
import { Provider } from '@modern-js-reduck/react';
|
|
6
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
7
|
+
import { isBrowser } from "../../common";
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
var state = function state(config) {
|
|
11
|
+
return {
|
|
12
|
+
name: '@modern-js/plugin-state',
|
|
13
|
+
setup: function setup() {
|
|
14
|
+
return {
|
|
15
|
+
hoc: function hoc(_ref, next) {
|
|
16
|
+
var App = _ref.App;
|
|
17
|
+
|
|
18
|
+
var getStateApp = function getStateApp(props) {
|
|
19
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
20
|
+
var context = useContext(RuntimeReactContext);
|
|
21
|
+
return /*#__PURE__*/_jsx(Provider, {
|
|
22
|
+
store: context.store,
|
|
23
|
+
config: config,
|
|
24
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return next({
|
|
29
|
+
App: hoistNonReactStatics(getStateApp, App)
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
init: function init(_ref2, next) {
|
|
33
|
+
var context = _ref2.context;
|
|
34
|
+
var storeConfig = config || {};
|
|
35
|
+
|
|
36
|
+
if (isBrowser()) {
|
|
37
|
+
var _window, _window$_SSR_DATA, _window$_SSR_DATA$dat;
|
|
38
|
+
|
|
39
|
+
storeConfig.initialState = storeConfig.initialState || ((_window = window) === null || _window === void 0 ? void 0 : (_window$_SSR_DATA = _window._SSR_DATA) === null || _window$_SSR_DATA === void 0 ? void 0 : (_window$_SSR_DATA$dat = _window$_SSR_DATA.data) === null || _window$_SSR_DATA$dat === void 0 ? void 0 : _window$_SSR_DATA$dat.storeState) || {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
context.store = createStore(storeConfig);
|
|
43
|
+
next({
|
|
44
|
+
context: context
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
pickContext: function pickContext(_ref3, next) {
|
|
48
|
+
var context = _ref3.context,
|
|
49
|
+
pickedContext = _ref3.pickedContext;
|
|
50
|
+
return next({
|
|
51
|
+
context: context,
|
|
52
|
+
pickedContext: _objectSpread(_objectSpread({}, pickedContext), {}, {
|
|
53
|
+
store: context.store
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default state;
|
|
63
|
+
export * from "../plugins";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isBrowser: () => boolean;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { default as state } from '../state';
|
|
2
|
+
export * from '../state';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { default as router } from '../router';
|
|
2
|
+
export * from '../router';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { default as ssr } from '../ssr';
|
|
2
|
+
export * from '../ssr';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { StateConfig } from './state';
|
|
2
|
+
import type { RouterConfig } from './router';
|
|
3
3
|
export type { RuntimeContext, TRuntimeContext } from '@modern-js/runtime-core';
|
|
4
4
|
export { createApp, createPlugin, useLoader, bootstrap, RuntimeReactContext, registerPrefetch, defineConfig, registerInit, useRuntimeContext } from '@modern-js/runtime-core';
|
|
5
5
|
declare module '@modern-js/runtime-core' {
|
|
@@ -7,4 +7,10 @@ declare module '@modern-js/runtime-core' {
|
|
|
7
7
|
router?: RouterConfig | boolean;
|
|
8
8
|
state?: StateConfig | boolean;
|
|
9
9
|
}
|
|
10
|
+
}
|
|
11
|
+
declare module '@modern-js/core' {
|
|
12
|
+
interface RuntimeConfig {
|
|
13
|
+
router?: RouterConfig | boolean;
|
|
14
|
+
state?: StateConfig | boolean;
|
|
15
|
+
}
|
|
10
16
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { routerPlugin } from './plugin';
|
|
2
|
+
import type { SingleRouteConfig, HistoryConfig, RouterConfig } from './plugin';
|
|
3
|
+
export type { SingleRouteConfig, HistoryConfig, RouterConfig };
|
|
4
|
+
export default routerPlugin;
|
|
5
|
+
export * from 'react-router-dom';
|
|
6
|
+
export * from 'history';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { History, BrowserHistoryBuildOptions, HashHistoryBuildOptions } from 'history';
|
|
3
|
+
import { RouteProps } from 'react-router-dom';
|
|
4
|
+
import type { Plugin } from '@modern-js/runtime-core';
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
_SERVER_DATA?: {
|
|
8
|
+
router: {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
params: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare type SingleRouteConfig = RouteProps & {
|
|
16
|
+
redirect?: string;
|
|
17
|
+
routes?: SingleRouteConfig[];
|
|
18
|
+
key?: string;
|
|
19
|
+
/**
|
|
20
|
+
* layout component
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
layout?: React.ComponentType;
|
|
24
|
+
/**
|
|
25
|
+
* component would be rendered when route macthed.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
component?: React.ComponentType;
|
|
29
|
+
};
|
|
30
|
+
export declare type HistoryConfig = {
|
|
31
|
+
supportHtml5History: true;
|
|
32
|
+
historyOptions: BrowserHistoryBuildOptions;
|
|
33
|
+
} | {
|
|
34
|
+
supportHtml5History: false;
|
|
35
|
+
historyOptions: HashHistoryBuildOptions;
|
|
36
|
+
};
|
|
37
|
+
export declare type RouterConfig = Partial<HistoryConfig> & {
|
|
38
|
+
routesConfig?: {
|
|
39
|
+
globalApp?: React.ComponentType<any>;
|
|
40
|
+
routes?: SingleRouteConfig[];
|
|
41
|
+
};
|
|
42
|
+
history?: History;
|
|
43
|
+
serverBase?: string[];
|
|
44
|
+
};
|
|
45
|
+
export declare const routerPlugin: ({
|
|
46
|
+
serverBase,
|
|
47
|
+
history: customHistory,
|
|
48
|
+
supportHtml5History,
|
|
49
|
+
routesConfig,
|
|
50
|
+
historyOptions
|
|
51
|
+
}: RouterConfig) => Plugin;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RouterConfig } from './plugin';
|
|
3
|
+
export declare function renderRoutes(routesConfig: RouterConfig['routesConfig'], extraProps?: any): JSX.Element;
|
|
4
|
+
export declare function getLocation(serverContext: any): string;
|
|
5
|
+
export declare const urlJoin: (...parts: string[]) => string;
|
|
6
|
+
export declare function standardSlash(str: string): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from '@modern-js/runtime-core';
|
|
2
|
+
import { RenderLevel, SSRServerContext } from './serverRender/type';
|
|
3
|
+
declare module '@modern-js/runtime-core' {
|
|
4
|
+
interface RuntimeContext {
|
|
5
|
+
ssrContext: SSRServerContext;
|
|
6
|
+
}
|
|
7
|
+
interface TRuntimeContext {
|
|
8
|
+
request: SSRServerContext['request'];
|
|
9
|
+
response: SSRServerContext['response'];
|
|
10
|
+
}
|
|
11
|
+
interface SSRContainer {
|
|
12
|
+
renderLevel: RenderLevel;
|
|
13
|
+
context?: SSRServerContext;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
declare const ssr: () => Plugin;
|
|
17
|
+
export default ssr;
|
|
18
|
+
export * from './react';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RuntimeContext } from '@modern-js/runtime-core';
|
|
2
|
+
declare const prefetch: (App: React.ComponentType<any>, context: RuntimeContext) => Promise<{
|
|
3
|
+
initialData: any;
|
|
4
|
+
i18nData: any;
|
|
5
|
+
loadersData?: undefined;
|
|
6
|
+
storeState?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
loadersData: Record<string, import("@modern-js/runtime-core/src/loader/loaderManager").LoaderResult>;
|
|
9
|
+
initialData: any;
|
|
10
|
+
i18nData: any;
|
|
11
|
+
storeState: any;
|
|
12
|
+
}>;
|
|
13
|
+
export default prefetch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PreRender: any;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare type SprProps = {
|
|
2
|
+
interval: number;
|
|
3
|
+
staleLimit: number | boolean;
|
|
4
|
+
level: number;
|
|
5
|
+
includes: MetaKeyMap | null;
|
|
6
|
+
excludes: MetaKeyMap | null;
|
|
7
|
+
fallback: boolean;
|
|
8
|
+
matches: MetaKeyMatch | null;
|
|
9
|
+
};
|
|
10
|
+
export declare type GeneralizedProps = SprProps & {
|
|
11
|
+
[propName: string]: any;
|
|
12
|
+
};
|
|
13
|
+
export declare type SprConstructor = {
|
|
14
|
+
config: () => SprProps;
|
|
15
|
+
};
|
|
16
|
+
export declare type MetaKeyMap = {
|
|
17
|
+
header?: string[];
|
|
18
|
+
query?: string[];
|
|
19
|
+
};
|
|
20
|
+
declare type MatchMap = {
|
|
21
|
+
[propName: string]: {
|
|
22
|
+
[propName: string]: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare type MetaKeyMatch = {
|
|
26
|
+
header?: MatchMap;
|
|
27
|
+
query?: MatchMap;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GeneralizedProps, MetaKeyMap, MetaKeyMatch } from './type';
|
|
2
|
+
export declare const getInnermostProperty: (propsList: GeneralizedProps[], propName: string) => any;
|
|
3
|
+
export declare const getOutermostProperty: (propsList: GeneralizedProps[], propName: string) => any;
|
|
4
|
+
export declare const aggKeysFromPropsList: (propsList: GeneralizedProps[], propName: string) => MetaKeyMap;
|
|
5
|
+
export declare const aggMatchesFromPropsList: (propsList: GeneralizedProps[], propName: string) => MetaKeyMatch;
|
|
6
|
+
export declare function exist(target: any): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RuntimeContext } from '@modern-js/runtime-core';
|
|
2
|
+
import { ModernSSRReactComponent, SSRServerContext, RenderResult } from './type';
|
|
3
|
+
declare type EntryOptions = {
|
|
4
|
+
ctx: SSRServerContext;
|
|
5
|
+
App: ModernSSRReactComponent;
|
|
6
|
+
};
|
|
7
|
+
export default class Entry {
|
|
8
|
+
entryName: string;
|
|
9
|
+
result: RenderResult;
|
|
10
|
+
metrics: SSRServerContext['metrics'];
|
|
11
|
+
logger: SSRServerContext['logger'];
|
|
12
|
+
private readonly App;
|
|
13
|
+
private readonly fragments;
|
|
14
|
+
constructor(options: EntryOptions);
|
|
15
|
+
renderToHtml(context: RuntimeContext): Promise<string>;
|
|
16
|
+
private prefetch;
|
|
17
|
+
private renderToString;
|
|
18
|
+
private getSSRDataScript;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RuntimeContext } from '@modern-js/runtime-core';
|
|
2
|
+
import { ModernSSRReactComponent } from './type';
|
|
3
|
+
declare module '@modern-js/runtime' {
|
|
4
|
+
interface RuntimeContext {
|
|
5
|
+
ssrContext?: any;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare const render: (ctx: RuntimeContext, _: string | undefined, App: ModernSSRReactComponent) => Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const time: () => () => number;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare type Filter = (str: string) => string;
|
|
2
|
+
export declare class Fragment {
|
|
3
|
+
static filterMap: {
|
|
4
|
+
[key: string]: Filter;
|
|
5
|
+
};
|
|
6
|
+
isVariable: boolean;
|
|
7
|
+
content: string;
|
|
8
|
+
filters: Filter[];
|
|
9
|
+
path: string[];
|
|
10
|
+
constructor(template: string);
|
|
11
|
+
getValue(data: any): any;
|
|
12
|
+
}
|
|
13
|
+
export declare function toFragments(filename: string): Fragment[];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { RuntimeContext } from '@modern-js/runtime-core';
|
|
3
|
+
import type { BaseSSRServerContext } from '@modern-js/types';
|
|
4
|
+
export declare enum RenderLevel {
|
|
5
|
+
CLIENT_RENDER = 0,
|
|
6
|
+
SERVER_PREFETCH = 1,
|
|
7
|
+
SERVER_RENDER = 2,
|
|
8
|
+
}
|
|
9
|
+
export declare type SSRServerContext = BaseSSRServerContext & {
|
|
10
|
+
request: BaseSSRServerContext['request'] & {
|
|
11
|
+
userAgent: string;
|
|
12
|
+
cookie: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare type ModernSSRReactComponent = React.ComponentType<any> & {
|
|
16
|
+
init: (context: RuntimeContext) => Promise<void>;
|
|
17
|
+
prefetch: (context: RuntimeContext) => Promise<Record<string, any>>;
|
|
18
|
+
};
|
|
19
|
+
export interface RenderEntry {
|
|
20
|
+
entryName: string;
|
|
21
|
+
result: RenderResult;
|
|
22
|
+
loadableManifest: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare type RenderHandler = (jsx: React.ReactElement, renderer: RenderEntry, next: (jsx: React.ReactElement) => string) => string;
|
|
25
|
+
export declare type RenderResult = {
|
|
26
|
+
renderLevel: RenderLevel;
|
|
27
|
+
html?: string;
|
|
28
|
+
chunksMap: {
|
|
29
|
+
js: string;
|
|
30
|
+
css: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseSSRServerContext } from '@modern-js/types';
|
|
2
|
+
import { SSRServerContext } from './serverRender/type';
|
|
3
|
+
export declare const formatServer: (request: BaseSSRServerContext['request']) => SSRServerContext['request'];
|
|
4
|
+
export declare const formatClient: (request: BaseSSRServerContext['request']) => SSRServerContext['request'];
|
|
5
|
+
export declare const mockResponse: () => {
|
|
6
|
+
setHeader(): void;
|
|
7
|
+
status(): void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as devtools } from '@modern-js-reduck/plugin-devtools';
|
|
2
|
+
export declare const effects: () => (context: import("@modern-js-reduck/store/dist/types/types/plugin").PluginContext) => import("@modern-js-reduck/store/dist/types/types/plugin").PluginLifeCycle;
|
|
3
|
+
export declare const immer: () => (context: import("@modern-js-reduck/store/dist/types/types/plugin").PluginContext) => import("@modern-js-reduck/store/dist/types/types/plugin").PluginLifeCycle;
|
|
4
|
+
export declare const autoActions: () => (context: import("@modern-js-reduck/store/dist/types/types/plugin").PluginContext) => import("@modern-js-reduck/store/dist/types/types/plugin").PluginLifeCycle;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createStore, Store } from '@modern-js-reduck/store';
|
|
2
|
+
import type { Plugin } from '@modern-js/runtime-core';
|
|
3
|
+
declare module '@modern-js/runtime-core' {
|
|
4
|
+
interface RuntimeContext {
|
|
5
|
+
store: Store;
|
|
6
|
+
}
|
|
7
|
+
interface TRuntimeContext {
|
|
8
|
+
store: Store;
|
|
9
|
+
}
|
|
10
|
+
interface SSRData {
|
|
11
|
+
storeState: any;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare type StateConfig = Parameters<typeof createStore>[0];
|
|
15
|
+
declare const state: (config: StateConfig) => Plugin;
|
|
16
|
+
export default state;
|
|
17
|
+
export * from '../plugins';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createStore } from '@modern-js-reduck/store';
|
|
2
|
+
import { ReduxLoggerOptions } from 'redux-logger';
|
|
3
|
+
export declare type PluginOptions = Parameters<typeof createStore>[0] & {
|
|
4
|
+
/**
|
|
5
|
+
* If it's false, the logger will be disabled.
|
|
6
|
+
* If it's a object, it means options will pass to createLogger function
|
|
7
|
+
*/
|
|
8
|
+
logger?: false | ReduxLoggerOptions;
|
|
9
|
+
effects?: any;
|
|
10
|
+
/**
|
|
11
|
+
* Default: false
|
|
12
|
+
* When it's true, will remove immer plugin
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
disableImmer?: boolean;
|
|
16
|
+
devtools?: any;
|
|
17
|
+
};
|