@modern-js/runtime 1.20.1 → 1.21.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/js/modern/router/cli/index.js +1 -1
  3. package/dist/js/modern/router/index.js +1 -0
  4. package/dist/js/modern/ssr/cli/index.js +1 -1
  5. package/dist/js/modern/ssr/index.js +1 -3
  6. package/dist/js/modern/ssr/index.node.js +2 -4
  7. package/dist/js/modern/ssr/prefetch.js +5 -6
  8. package/dist/js/modern/ssr/serverRender/entry.js +4 -7
  9. package/dist/js/modern/ssr/serverRender/loadable.js +8 -5
  10. package/dist/js/modern/ssr/serverRender/template.js +4 -21
  11. package/dist/js/modern/state/cli/index.js +2 -27
  12. package/dist/js/modern/state/index.js +1 -0
  13. package/dist/js/modern/state/runtime/plugin.js +18 -2
  14. package/dist/js/node/router/cli/index.js +1 -1
  15. package/dist/js/node/router/index.js +9 -1
  16. package/dist/js/node/ssr/cli/index.js +1 -1
  17. package/dist/js/node/ssr/index.js +5 -2
  18. package/dist/js/node/ssr/index.node.js +7 -4
  19. package/dist/js/node/ssr/prefetch.js +5 -12
  20. package/dist/js/node/ssr/serverRender/entry.js +4 -9
  21. package/dist/js/node/ssr/serverRender/loadable.js +7 -7
  22. package/dist/js/node/ssr/serverRender/template.js +4 -23
  23. package/dist/js/node/state/cli/index.js +2 -27
  24. package/dist/js/node/state/index.js +9 -1
  25. package/dist/js/node/state/runtime/plugin.js +24 -8
  26. package/dist/js/treeshaking/router/cli/index.js +1 -1
  27. package/dist/js/treeshaking/router/index.js +1 -0
  28. package/dist/js/treeshaking/ssr/cli/index.js +1 -1
  29. package/dist/js/treeshaking/ssr/index.js +1 -3
  30. package/dist/js/treeshaking/ssr/index.node.js +2 -4
  31. package/dist/js/treeshaking/ssr/prefetch.js +5 -7
  32. package/dist/js/treeshaking/ssr/serverRender/entry.js +4 -7
  33. package/dist/js/treeshaking/ssr/serverRender/loadable.js +8 -5
  34. package/dist/js/treeshaking/ssr/serverRender/template.js +4 -21
  35. package/dist/js/treeshaking/state/cli/index.js +2 -23
  36. package/dist/js/treeshaking/state/index.js +1 -0
  37. package/dist/js/treeshaking/state/runtime/plugin.js +22 -2
  38. package/dist/types/router/index.d.ts +1 -0
  39. package/dist/types/ssr/index.d.ts +1 -1
  40. package/dist/types/ssr/index.node.d.ts +2 -2
  41. package/dist/types/ssr/serverRender/template.d.ts +1 -1
  42. package/dist/types/ssr/serverRender/type.d.ts +1 -1
  43. package/dist/types/state/index.d.ts +1 -0
  44. package/dist/types/state/runtime/plugin.d.ts +2 -2
  45. package/package.json +20 -44
  46. package/types/model.d.ts +1 -1
  47. package/dist/js/modern/exports/model.js +0 -2
  48. package/dist/js/modern/exports/router.js +0 -2
  49. package/dist/js/modern/exports/ssr.js +0 -2
  50. package/dist/js/node/exports/model.js +0 -32
  51. package/dist/js/node/exports/router.js +0 -32
  52. package/dist/js/node/exports/ssr.js +0 -32
  53. package/dist/js/treeshaking/exports/model.js +0 -2
  54. package/dist/js/treeshaking/exports/router.js +0 -2
  55. package/dist/js/treeshaking/exports/ssr.js +0 -2
  56. package/dist/types/exports/model.d.ts +0 -2
  57. package/dist/types/exports/router.d.ts +0 -2
  58. package/dist/types/exports/ssr.d.ts +0 -2
@@ -46,11 +46,6 @@ var _default = () => ({
46
46
  const stateConfig = (_getEntryOptions = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
47
47
  stateConfigMap.set(entryName, stateConfig);
48
48
 
49
- const getEnabledPlugins = () => {
50
- const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
51
- return internalPlugins.filter(name => stateConfig[name] !== false);
52
- };
53
-
54
49
  if (stateConfig) {
55
50
  imports.push({
56
51
  value: '@modern-js/runtime/plugins',
@@ -58,23 +53,6 @@ var _default = () => ({
58
53
  imported: PLUGIN_IDENTIFIER
59
54
  }]
60
55
  });
61
- imports.push({
62
- value: '@modern-js/runtime/model',
63
- specifiers: getEnabledPlugins().map(imported => ({
64
- imported
65
- })),
66
- initialize: `
67
- const createStatePlugins = (config) => {
68
- const plugins = [];
69
-
70
- ${getEnabledPlugins().map(name => `
71
- plugins.push(${name}(config['${name}']));
72
- `).join('\n')}
73
-
74
- return plugins;
75
- }
76
- `
77
- });
78
56
  }
79
57
 
80
58
  return {
@@ -90,12 +68,9 @@ var _default = () => ({
90
68
  const stateOptions = stateConfigMap.get(entrypoint.entryName);
91
69
 
92
70
  if (stateOptions) {
93
- const isBoolean = typeof stateOptions === 'boolean';
94
- let options = isBoolean ? '{}' : JSON.stringify(stateOptions);
95
- options = `${options.substr(0, options.length - 1)}${isBoolean ? '' : ','}plugins: createStatePlugins(${JSON.stringify(stateConfigMap.get(entrypoint.entryName))})}`;
96
71
  plugins.push({
97
72
  name: PLUGIN_IDENTIFIER,
98
- options
73
+ options: `${JSON.stringify(stateConfigMap.get(entrypoint.entryName))}`
99
74
  });
100
75
  }
101
76
 
@@ -110,7 +85,7 @@ var _default = () => ({
110
85
  },
111
86
 
112
87
  addRuntimeExports() {
113
- pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/runtime-state'`);
88
+ pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/model'`);
114
89
  }
115
90
 
116
91
  };
@@ -3,13 +3,21 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _exportNames = {};
6
+ var _exportNames = {
7
+ state: true
8
+ };
7
9
  Object.defineProperty(exports, "default", {
8
10
  enumerable: true,
9
11
  get: function () {
10
12
  return _runtime.default;
11
13
  }
12
14
  });
15
+ Object.defineProperty(exports, "state", {
16
+ enumerable: true,
17
+ get: function () {
18
+ return _runtime.default;
19
+ }
20
+ });
13
21
 
14
22
  var _runtime = _interopRequireWildcard(require("./runtime"));
15
23
 
@@ -14,12 +14,6 @@ var _react2 = require("@modern-js-reduck/react");
14
14
 
15
15
  var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
16
16
 
17
- var _core = require("../../core");
18
-
19
- var _common = require("../../common");
20
-
21
- var _jsxRuntime = require("react/jsx-runtime");
22
-
23
17
  var _plugins = require("../plugins");
24
18
 
25
19
  Object.keys(_plugins).forEach(function (key) {
@@ -34,6 +28,12 @@ Object.keys(_plugins).forEach(function (key) {
34
28
  });
35
29
  });
36
30
 
31
+ var _core = require("../../core");
32
+
33
+ var _common = require("../../common");
34
+
35
+ var _jsxRuntime = require("react/jsx-runtime");
36
+
37
37
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
38
 
39
39
  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; }
@@ -42,6 +42,22 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
42
42
 
43
43
  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; }
44
44
 
45
+ const StatePluginHandleMap = {
46
+ immer: _plugins.immer,
47
+ effects: _plugins.effects,
48
+ autoActions: _plugins.autoActions,
49
+ devtools: _plugins.devtools
50
+ };
51
+
52
+ const getStoreConfig = config => {
53
+ const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
54
+ const plugins = [];
55
+ internalPlugins.filter(plugin => config[plugin] !== false).forEach(plugin => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
56
+ return {
57
+ plugins
58
+ };
59
+ };
60
+
45
61
  const state = config => ({
46
62
  name: '@modern-js/plugin-state',
47
63
  setup: () => {
@@ -54,7 +70,7 @@ const state = config => ({
54
70
  const context = (0, _react.useContext)(_core.RuntimeReactContext);
55
71
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Provider, {
56
72
  store: context.store,
57
- config: config,
73
+ config: getStoreConfig(config),
58
74
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
59
75
  });
60
76
  };
@@ -67,7 +83,7 @@ const state = config => ({
67
83
  init({
68
84
  context
69
85
  }, next) {
70
- const storeConfig = config || {};
86
+ const storeConfig = getStoreConfig(config || {});
71
87
 
72
88
  if ((0, _common.isBrowser)()) {
73
89
  var _window, _window$_SSR_DATA, _window$_SSR_DATA$dat;
@@ -90,7 +90,7 @@ export default (function () {
90
90
  };
91
91
  },
92
92
  addRuntimeExports: function addRuntimeExports() {
93
- pluginsExportsUtils.addExport("export { default as router } from '@modern-js/runtime/runtime-router'");
93
+ pluginsExportsUtils.addExport("export { default as router } from '@modern-js/runtime/router'");
94
94
  }
95
95
  };
96
96
  }
@@ -1,2 +1,3 @@
1
+ export { default as router } from "./runtime";
1
2
  export { default } from "./runtime";
2
3
  export * from "./runtime";
@@ -52,7 +52,7 @@ export default (function () {
52
52
  packageName = _api$useAppContext.packageName,
53
53
  entrypoints = _api$useAppContext.entrypoints;
54
54
 
55
- pluginsExportsUtils.addExport("export { default as ssr } from '@modern-js/runtime/runtime-ssr'"); // if use ssg then set ssr config to true
55
+ pluginsExportsUtils.addExport("export { default as ssr } from '@modern-js/runtime/ssr'"); // if use ssg then set ssr config to true
56
56
 
57
57
  var ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
58
58
  var ssgConfig = userConfig.output.ssg;
@@ -8,8 +8,7 @@ import { WithCallback } from "./react/withCallback";
8
8
  import { formatClient, mockResponse } from "./utils";
9
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
10
  var IS_REACT18 = process.env.IS_REACT18 === 'true';
11
-
12
- var ssr = function ssr(_) {
11
+ export var ssr = function ssr(_) {
13
12
  return {
14
13
  name: '@modern-js/plugin-ssr',
15
14
  setup: function setup() {
@@ -136,6 +135,5 @@ var ssr = function ssr(_) {
136
135
  }
137
136
  };
138
137
  };
139
-
140
138
  export default ssr;
141
139
  export * from "./react";
@@ -6,8 +6,7 @@ import { render } from "./serverRender";
6
6
  import prefetch from "./prefetch";
7
7
  import { formatServer } from "./utils";
8
8
  var registeredApps = new WeakSet();
9
-
10
- var plugin = function plugin() {
9
+ export var ssr = function ssr() {
11
10
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
12
11
  return {
13
12
  name: '@modern-js/plugin-ssr',
@@ -82,6 +81,5 @@ var plugin = function plugin() {
82
81
  }
83
82
  };
84
83
  };
85
-
86
- export default plugin;
84
+ export default ssr;
87
85
  export * from "./react";
@@ -1,10 +1,7 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import path from 'path';
4
- import fs from 'fs';
5
3
  import { renderToStaticMarkup } from 'react-dom/server';
6
4
  import { run } from '@modern-js/utils/ssr';
7
- import { LOADABLE_STATS_FILE } from '@modern-js/utils/constants';
8
5
  import { ChunkExtractor } from '@loadable/server';
9
6
  import { jsx as _jsx } from "react/jsx-runtime";
10
7
 
@@ -18,17 +15,18 @@ var prefetch = /*#__PURE__*/function () {
18
15
  return _context2.abrupt("return", run(context.ssrContext.request.headers, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
19
16
  var _context$store;
20
17
 
21
- var ssrContext, loadablefile, extractor, loadersData;
18
+ var ssrContext, _ref3, loadableStats, extractor, loadersData;
19
+
22
20
  return _regeneratorRuntime().wrap(function _callee$(_context) {
23
21
  while (1) {
24
22
  switch (_context.prev = _context.next) {
25
23
  case 0:
26
24
  ssrContext = context.ssrContext;
27
- loadablefile = path.resolve(ssrContext.distDir, LOADABLE_STATS_FILE);
25
+ _ref3 = ssrContext, loadableStats = _ref3.loadableStats;
28
26
 
29
- if (fs.existsSync(loadablefile)) {
27
+ if (loadableStats) {
30
28
  extractor = new ChunkExtractor({
31
- statsFile: path.resolve(ssrContext.distDir, LOADABLE_STATS_FILE),
29
+ stats: loadableStats,
32
30
  entrypoints: [ssrContext.entryName].filter(Boolean)
33
31
  });
34
32
  renderToStaticMarkup(extractor.collectChunks( /*#__PURE__*/_jsx(App, {
@@ -4,8 +4,6 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
5
  import _createClass from "@babel/runtime/helpers/esm/createClass";
6
6
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
- import path from 'path';
8
- import { LOADABLE_STATS_FILE } from '@modern-js/utils/constants';
9
7
  import React from 'react';
10
8
  import ReactDomServer from 'react-dom/server';
11
9
  import serialize from 'serialize-javascript';
@@ -60,9 +58,9 @@ var Entry = /*#__PURE__*/function () {
60
58
  var ctx = options.ctx,
61
59
  config = options.config;
62
60
  var entryName = ctx.entryName,
63
- templateHTML = ctx.template,
61
+ template = ctx.template,
64
62
  host = ctx.request.host;
65
- this.fragments = toFragments(templateHTML);
63
+ this.fragments = toFragments(template, entryName);
66
64
  this.entryName = entryName;
67
65
  this.host = host;
68
66
  this.App = options.App;
@@ -237,10 +235,9 @@ var Entry = /*#__PURE__*/function () {
237
235
  context: Object.assign(context, {
238
236
  ssr: true
239
237
  })
240
- }); // Todo render Hook
241
-
238
+ });
242
239
  var renderContext = {
243
- loadableManifest: path.resolve(ssrContext.distDir, LOADABLE_STATS_FILE),
240
+ stats: ssrContext.loadableStats,
244
241
  host: this.host,
245
242
  result: this.result,
246
243
  entryName: this.entryName,
@@ -1,8 +1,11 @@
1
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
- import path from 'path';
3
2
  import { ChunkExtractor } from '@loadable/server';
4
3
  import { isCrossOrigin } from "../utils";
5
4
 
5
+ var extname = function extname(uri) {
6
+ return uri.match(/\.[^.]+$/) || '';
7
+ };
8
+
6
9
  function getLoadableScripts(extractor) {
7
10
  var check = function check(scripts) {
8
11
  return (scripts || '').includes('__LOADABLE_REQUIRED_CHUNKS___ext');
@@ -21,18 +24,18 @@ function getLoadableScripts(extractor) {
21
24
  }
22
25
 
23
26
  export var toHtml = function toHtml(jsx, renderer, next) {
24
- var loadableManifest = renderer.loadableManifest,
27
+ var stats = renderer.stats,
25
28
  chunksMap = renderer.result.chunksMap,
26
29
  host = renderer.host,
27
30
  _renderer$config = renderer.config,
28
31
  config = _renderer$config === void 0 ? {} : _renderer$config;
29
32
 
30
- if (!loadableManifest || chunksMap.js) {
33
+ if (!stats || chunksMap.js) {
31
34
  return next(jsx);
32
35
  }
33
36
 
34
37
  var extractor = new ChunkExtractor({
35
- statsFile: loadableManifest,
38
+ stats: stats,
36
39
  entrypoints: [renderer.entryName]
37
40
  });
38
41
  var html = next(extractor.collectChunks(jsx));
@@ -45,7 +48,7 @@ export var toHtml = function toHtml(jsx, renderer, next) {
45
48
  try {
46
49
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
47
50
  var v = _step.value;
48
- var fileType = path.extname(v.url).slice(1);
51
+ var fileType = extname(v.url).slice(1);
49
52
 
50
53
  if (fileType === 'js') {
51
54
  var props = [];
@@ -2,16 +2,6 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
4
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
- import fs from 'fs';
6
-
7
- var readFile = function readFile(filepath) {
8
- if (fs.existsSync(filepath)) {
9
- return fs.readFileSync(filepath, 'utf-8');
10
- } else {
11
- return null;
12
- }
13
- };
14
-
15
5
  var VARIABLE_REG_EXP = /<!--<\?([-=+])\s*(.*?)\s*\?>-->/;
16
6
  var VARIABLE_SPLITTER = /(<!--<\?.*?\?>-->)/;
17
7
  var ENCODE_HTML_RULES = {
@@ -89,16 +79,9 @@ _defineProperty(Fragment, "filterMap", {
89
79
  });
90
80
 
91
81
  var fragmentListMap = {};
92
- export function toFragments(filename) {
93
- if (fragmentListMap[filename]) {
94
- return fragmentListMap[filename];
95
- } // 未开启现代构建的项目无 -es6.html
96
-
97
-
98
- var template = readFile(filename);
99
-
100
- if (!template) {
101
- throw new Error("Could not find template file: ".concat(filename));
82
+ export function toFragments(template, entryName) {
83
+ if (fragmentListMap[entryName]) {
84
+ return fragmentListMap[entryName];
102
85
  }
103
86
 
104
87
  var fragmentList = template.split(VARIABLE_SPLITTER).filter(function (v) {
@@ -106,6 +89,6 @@ export function toFragments(filename) {
106
89
  }).map(function (v) {
107
90
  return new Fragment(v);
108
91
  });
109
- fragmentListMap[filename] = fragmentList;
92
+ fragmentListMap[entryName] = fragmentList;
110
93
  return fragmentList;
111
94
  }
@@ -34,13 +34,6 @@ export default (function () {
34
34
  var stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
35
35
  stateConfigMap.set(entryName, stateConfig);
36
36
 
37
- var getEnabledPlugins = function getEnabledPlugins() {
38
- var internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
39
- return internalPlugins.filter(function (name) {
40
- return stateConfig[name] !== false;
41
- });
42
- };
43
-
44
37
  if (stateConfig) {
45
38
  imports.push({
46
39
  value: '@modern-js/runtime/plugins',
@@ -48,17 +41,6 @@ export default (function () {
48
41
  imported: PLUGIN_IDENTIFIER
49
42
  }]
50
43
  });
51
- imports.push({
52
- value: '@modern-js/runtime/model',
53
- specifiers: getEnabledPlugins().map(function (imported) {
54
- return {
55
- imported: imported
56
- };
57
- }),
58
- initialize: "\n const createStatePlugins = (config) => {\n const plugins = [];\n\n ".concat(getEnabledPlugins().map(function (name) {
59
- return "\n plugins.push(".concat(name, "(config['").concat(name, "']));\n ");
60
- }).join('\n'), "\n\n return plugins;\n }\n ")
61
- });
62
44
  }
63
45
 
64
46
  return {
@@ -72,12 +54,9 @@ export default (function () {
72
54
  var stateOptions = stateConfigMap.get(entrypoint.entryName);
73
55
 
74
56
  if (stateOptions) {
75
- var isBoolean = typeof stateOptions === 'boolean';
76
- var options = isBoolean ? '{}' : JSON.stringify(stateOptions);
77
- options = "".concat(options.substr(0, options.length - 1)).concat(isBoolean ? '' : ',', "plugins: createStatePlugins(").concat(JSON.stringify(stateConfigMap.get(entrypoint.entryName)), ")}");
78
57
  plugins.push({
79
58
  name: PLUGIN_IDENTIFIER,
80
- options: options
59
+ options: "".concat(JSON.stringify(stateConfigMap.get(entrypoint.entryName)))
81
60
  });
82
61
  }
83
62
 
@@ -90,7 +69,7 @@ export default (function () {
90
69
  return PLUGIN_SCHEMAS['@modern-js/plugin-state'];
91
70
  },
92
71
  addRuntimeExports: function addRuntimeExports() {
93
- pluginsExportsUtils.addExport("export { default as state } from '@modern-js/runtime/runtime-state'");
72
+ pluginsExportsUtils.addExport("export { default as state } from '@modern-js/runtime/model'");
94
73
  }
95
74
  };
96
75
  }
@@ -1,2 +1,3 @@
1
+ export { default as state } from "./runtime";
1
2
  export { default } from "./runtime";
2
3
  export * from "./runtime";
@@ -3,9 +3,29 @@ import { useContext } from 'react';
3
3
  import { createStore } from '@modern-js-reduck/store';
4
4
  import { Provider } from '@modern-js-reduck/react';
5
5
  import hoistNonReactStatics from 'hoist-non-react-statics';
6
+ import { immer, effects, autoActions, devtools } from "../plugins";
6
7
  import { RuntimeReactContext } from "../../core";
7
8
  import { isBrowser } from "../../common";
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
+ var StatePluginHandleMap = {
11
+ immer: immer,
12
+ effects: effects,
13
+ autoActions: autoActions,
14
+ devtools: devtools
15
+ };
16
+
17
+ var getStoreConfig = function getStoreConfig(config) {
18
+ var internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
19
+ var plugins = [];
20
+ internalPlugins.filter(function (plugin) {
21
+ return config[plugin] !== false;
22
+ }).forEach(function (plugin) {
23
+ return plugins.push(StatePluginHandleMap[plugin](config[plugin]));
24
+ });
25
+ return {
26
+ plugins: plugins
27
+ };
28
+ };
9
29
 
10
30
  var state = function state(config) {
11
31
  return {
@@ -20,7 +40,7 @@ var state = function state(config) {
20
40
  var context = useContext(RuntimeReactContext);
21
41
  return /*#__PURE__*/_jsx(Provider, {
22
42
  store: context.store,
23
- config: config,
43
+ config: getStoreConfig(config),
24
44
  children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
25
45
  });
26
46
  };
@@ -31,7 +51,7 @@ var state = function state(config) {
31
51
  },
32
52
  init: function init(_ref2, next) {
33
53
  var context = _ref2.context;
34
- var storeConfig = config || {};
54
+ var storeConfig = getStoreConfig(config || {});
35
55
 
36
56
  if (isBrowser()) {
37
57
  var _window, _window$_SSR_DATA, _window$_SSR_DATA$dat;
@@ -1,2 +1,3 @@
1
+ export { default as router } from './runtime';
1
2
  export { default } from './runtime';
2
3
  export * from './runtime';
@@ -6,6 +6,6 @@ declare module '../core' {
6
6
  context?: SSRServerContext;
7
7
  }
8
8
  }
9
- declare const ssr: (_: SSRPluginConfig) => Plugin;
9
+ export declare const ssr: (_: SSRPluginConfig) => Plugin;
10
10
  export default ssr;
11
11
  export * from './react';
@@ -1,5 +1,5 @@
1
1
  import type { Plugin } from '../core';
2
2
  import type { SSRPluginConfig } from './serverRender/type';
3
- declare const plugin: (config?: SSRPluginConfig) => Plugin;
4
- export default plugin;
3
+ export declare const ssr: (config?: SSRPluginConfig) => Plugin;
4
+ export default ssr;
5
5
  export * from './react';
@@ -10,5 +10,5 @@ export declare class Fragment {
10
10
  constructor(template: string);
11
11
  getValue(data: any): any;
12
12
  }
13
- export declare function toFragments(filename: string): Fragment[];
13
+ export declare function toFragments(template: string, entryName: string): Fragment[];
14
14
  export {};
@@ -20,7 +20,7 @@ export interface RenderEntry {
20
20
  entryName: string;
21
21
  host: string;
22
22
  result: RenderResult;
23
- loadableManifest: string | undefined;
23
+ stats: Record<string, any>;
24
24
  config: SSRPluginConfig;
25
25
  }
26
26
  export declare type RenderHandler = (jsx: React.ReactElement, renderer: RenderEntry, next: (jsx: React.ReactElement) => string) => string;
@@ -1,2 +1,3 @@
1
+ export { default as state } from './runtime';
1
2
  export { default } from './runtime';
2
3
  export * from './runtime';
@@ -1,6 +1,6 @@
1
- import { createStore } from '@modern-js-reduck/store';
2
1
  import type { Plugin } from '../../core';
3
- export declare type StateConfig = Parameters<typeof createStore>[0];
2
+ export declare type StatePluginType = 'immer' | 'effects' | 'autoActions' | 'devtools';
3
+ export declare type StateConfig = Record<Partial<StatePluginType>, boolean>;
4
4
  declare const state: (config: StateConfig) => Plugin;
5
5
  export default state;
6
6
  export * from '../plugins';
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.20.1",
14
+ "version": "1.21.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./type.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -50,38 +50,23 @@
50
50
  "default": "./dist/js/treeshaking/exports/server.js"
51
51
  },
52
52
  "./router": {
53
- "jsnext:source": "./src/exports/router.ts",
54
- "node": "./dist/js/node/exports/router.js",
55
- "default": "./dist/js/treeshaking/exports/router.js"
56
- },
57
- "./ssr": {
58
- "jsnext:source": "./src/exports/ssr.ts",
59
- "node": "./dist/js/node/exports/ssr.js",
60
- "default": "./dist/js/treeshaking/exports/ssr.js"
61
- },
62
- "./model": {
63
- "jsnext:source": "./src/exports/model.ts",
64
- "node": "./dist/js/node/exports/model.js",
65
- "default": "./dist/js/treeshaking/exports/model.js"
66
- },
67
- "./cli": {
68
- "jsnext:source": "./src/cli/index.ts",
69
- "default": "./dist/js/node/cli/index.js"
70
- },
71
- "./runtime-router": {
72
53
  "jsnext:source": "./src/router/index.ts",
73
54
  "node": "./dist/js/node/router/index",
74
55
  "default": "./dist/js/treeshaking/router/index.js"
75
56
  },
76
- "./runtime-state": {
57
+ "./ssr": {
58
+ "jsnext:source": "./src/ssr/index.ts",
59
+ "node": "./dist/js/node/ssr/index",
60
+ "default": "./dist/js/treeshaking/ssr/index.js"
61
+ },
62
+ "./model": {
77
63
  "jsnext:source": "./src/state/index.ts",
78
64
  "node": "./dist/js/node/state/index",
79
65
  "default": "./dist/js/treeshaking/state/index.js"
80
66
  },
81
- "./runtime-ssr": {
82
- "jsnext:source": "./src/ssr/index.ts",
83
- "node": "./dist/js/node/ssr/index",
84
- "default": "./dist/js/treeshaking/ssr/index.js"
67
+ "./cli": {
68
+ "jsnext:source": "./src/cli/index.ts",
69
+ "default": "./dist/js/node/cli/index.js"
85
70
  }
86
71
  },
87
72
  "typesVersions": {
@@ -105,22 +90,13 @@
105
90
  "./dist/types/exports/server.d.ts"
106
91
  ],
107
92
  "ssr": [
108
- "./dist/types/exports/ssr.d.ts"
93
+ "./dist/types/ssr/index.d.ts"
109
94
  ],
110
95
  "router": [
111
- "./dist/types/exports/router.d.ts"
96
+ "./dist/types/router/index.d.ts"
112
97
  ],
113
98
  "model": [
114
99
  "./types/model.d.ts"
115
- ],
116
- "runtime-router": [
117
- "./dist/types/router/index.d.ts"
118
- ],
119
- "runtime-state": [
120
- "./dist/types/state/index.d.ts"
121
- ],
122
- "runtime-ssr": [
123
- "./dist/types/ssr/index.d.ts"
124
100
  ]
125
101
  }
126
102
  },
@@ -140,9 +116,9 @@
140
116
  "@loadable/babel-plugin": "^5.13.2",
141
117
  "@loadable/server": "^5.15.1",
142
118
  "@loadable/component": "^5.15.0",
143
- "@modern-js/plugin": "1.20.1",
144
- "@modern-js/webpack": "1.20.1",
145
- "@modern-js/utils": "1.20.1",
119
+ "@modern-js/plugin": "1.21.1",
120
+ "@modern-js/webpack": "1.21.1",
121
+ "@modern-js/utils": "1.21.1",
146
122
  "@modern-js-reduck/plugin-auto-actions": "^1.0.2",
147
123
  "@modern-js-reduck/plugin-devtools": "^1.0.3",
148
124
  "@modern-js-reduck/plugin-effects": "^1.0.2",
@@ -166,16 +142,16 @@
166
142
  "ts-jest": "^27.0.4",
167
143
  "typescript": "^4",
168
144
  "jest": "^27",
169
- "@modern-js/core": "1.20.1",
170
- "@modern-js/types": "1.20.1",
171
- "@modern-js/utils": "1.20.1",
145
+ "@modern-js/core": "1.21.1",
146
+ "@modern-js/types": "1.21.1",
147
+ "@modern-js/utils": "1.21.1",
172
148
  "@types/jest": "^27",
173
149
  "@types/node": "^14",
174
150
  "@types/react-side-effect": "^1.1.1",
175
151
  "@types/loadable__webpack-plugin": "^5.7.3",
176
152
  "@types/serialize-javascript": "^5.0.1",
177
- "@scripts/build": "1.20.1",
178
- "@scripts/jest-config": "1.20.1",
153
+ "@scripts/build": "1.21.1",
154
+ "@scripts/jest-config": "1.21.1",
179
155
  "@testing-library/react": "^12.0.0",
180
156
  "@testing-library/react-hooks": "^7.0.1",
181
157
  "@types/hoist-non-react-statics": "^3.3.1",
package/types/model.d.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  /// <reference types="@modern-js-reduck/plugin-effects" />
4
4
  /// <reference types="@modern-js-reduck/plugin-immutable" />
5
5
 
6
- export * from '../dist/types/exports/model';
6
+ export * from '../dist/types/state';
@@ -1,2 +0,0 @@
1
- export { default as state } from "../state";
2
- export * from "../state";