@modern-js/runtime 2.63.2 → 2.63.4

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 (42) hide show
  1. package/dist/cjs/cli/code.js +2 -2
  2. package/dist/cjs/cli/index.js +102 -108
  3. package/dist/cjs/cli/ssr/index.js +49 -52
  4. package/dist/cjs/core/server/string/loadable.js +13 -3
  5. package/dist/cjs/document/cli/index.js +32 -34
  6. package/dist/cjs/router/cli/code/index.js +5 -5
  7. package/dist/cjs/router/cli/handler.js +6 -6
  8. package/dist/cjs/router/cli/index.js +76 -78
  9. package/dist/cjs/router/runtime/plugin.js +1 -4
  10. package/dist/cjs/state/cli/index.js +22 -24
  11. package/dist/esm/cli/code.js +3 -3
  12. package/dist/esm/cli/index.js +120 -130
  13. package/dist/esm/cli/ssr/index.js +50 -53
  14. package/dist/esm/core/server/string/loadable.js +17 -5
  15. package/dist/esm/document/cli/index.js +28 -30
  16. package/dist/esm/router/cli/code/index.js +8 -8
  17. package/dist/esm/router/cli/handler.js +6 -6
  18. package/dist/esm/router/cli/index.js +161 -157
  19. package/dist/esm/router/runtime/plugin.js +1 -4
  20. package/dist/esm/state/cli/index.js +23 -25
  21. package/dist/esm-node/cli/code.js +2 -2
  22. package/dist/esm-node/cli/index.js +102 -108
  23. package/dist/esm-node/cli/ssr/index.js +49 -52
  24. package/dist/esm-node/core/server/string/loadable.js +13 -3
  25. package/dist/esm-node/document/cli/index.js +32 -34
  26. package/dist/esm-node/router/cli/code/index.js +5 -5
  27. package/dist/esm-node/router/cli/handler.js +6 -6
  28. package/dist/esm-node/router/cli/index.js +76 -78
  29. package/dist/esm-node/router/runtime/plugin.js +1 -4
  30. package/dist/esm-node/state/cli/index.js +22 -24
  31. package/dist/types/cli/code.d.ts +2 -9
  32. package/dist/types/cli/index.d.ts +3 -3
  33. package/dist/types/cli/ssr/index.d.ts +2 -2
  34. package/dist/types/core/server/string/loadable.d.ts +3 -2
  35. package/dist/types/document/cli/index.d.ts +2 -2
  36. package/dist/types/router/cli/code/index.d.ts +3 -3
  37. package/dist/types/router/cli/code/templates.d.ts +2 -2
  38. package/dist/types/router/cli/handler.d.ts +4 -4
  39. package/dist/types/router/cli/index.d.ts +2 -2
  40. package/dist/types/router/runtime/types.d.ts +0 -10
  41. package/dist/types/state/cli/index.d.ts +2 -2
  42. package/package.json +11 -11
@@ -48,7 +48,7 @@ var ssrBuilderPlugin = function(modernAPI) {
48
48
  api.modifyEnvironmentConfig(function(config, param) {
49
49
  var name = param.name, mergeEnvironmentConfig = param.mergeEnvironmentConfig;
50
50
  var isServerEnvironment = config.output.target === "node" || name === "workerSSR";
51
- var userConfig = modernAPI.useResolvedConfigContext();
51
+ var userConfig = modernAPI.getNormalizedConfig();
52
52
  var useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
53
53
  return mergeEnvironmentConfig(config, {
54
54
  source: {
@@ -78,61 +78,58 @@ var ssrPlugin = function() {
78
78
  "@modern-js/runtime"
79
79
  ],
80
80
  setup: function(api) {
81
- var appContext = api.useAppContext();
82
- return {
83
- // for bundle
84
- config: function config() {
85
- var _api_useAppContext = api.useAppContext(), _api_useAppContext_bundlerType = _api_useAppContext.bundlerType, bundlerType = _api_useAppContext_bundlerType === void 0 ? "webpack" : _api_useAppContext_bundlerType;
86
- var babelHandler = function() {
87
- if (bundlerType === "webpack") {
88
- return function(config2) {
89
- var _config_plugins;
90
- var userConfig = api.useResolvedConfigContext();
91
- (_config_plugins = config2.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
92
- if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
93
- var _config_plugins1;
94
- (_config_plugins1 = config2.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
95
- }
96
- };
97
- } else if (bundlerType === "rspack") {
98
- return function(config2) {
99
- var userConfig = api.useResolvedConfigContext();
100
- if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
101
- var _config_plugins, _config_plugins1;
102
- (_config_plugins = config2.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
103
- (_config_plugins1 = config2.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
104
- }
105
- };
106
- }
107
- }();
108
- return {
109
- builderPlugins: [
110
- ssrBuilderPlugin(api)
111
- ],
112
- source: {
113
- alias: {
114
- // ensure that all packages use the same storage in @modern-js/runtime-utils/node
115
- "@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
81
+ var appContext = api.getAppContext();
82
+ api.config(function() {
83
+ var _api_getAppContext = api.getAppContext(), _api_getAppContext_bundlerType = _api_getAppContext.bundlerType, bundlerType = _api_getAppContext_bundlerType === void 0 ? "webpack" : _api_getAppContext_bundlerType;
84
+ var babelHandler = function() {
85
+ if (bundlerType === "webpack") {
86
+ return function(config) {
87
+ var _config_plugins;
88
+ var userConfig = api.getNormalizedConfig();
89
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
90
+ if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
91
+ var _config_plugins1;
92
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
116
93
  }
117
- },
118
- tools: {
119
- babel: babelHandler,
120
- bundlerChain: function(chain, param) {
121
- var isServer = param.isServer;
122
- if (isServer && appContext.moduleType === "module") {
123
- chain.output.libraryTarget("module").set("chunkFormat", "module");
124
- chain.output.library({
125
- type: "module"
126
- });
127
- chain.experiments(_object_spread_props(_object_spread({}, chain.get("experiments")), {
128
- outputModule: true
129
- }));
130
- }
94
+ };
95
+ } else if (bundlerType === "rspack") {
96
+ return function(config) {
97
+ var userConfig = api.useResolvedConfigContext();
98
+ if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
99
+ var _config_plugins, _config_plugins1;
100
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
101
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
131
102
  }
103
+ };
104
+ }
105
+ }();
106
+ return {
107
+ builderPlugins: [
108
+ ssrBuilderPlugin(api)
109
+ ],
110
+ source: {
111
+ alias: {
112
+ // ensure that all packages use the same storage in @modern-js/runtime-utils/node
113
+ "@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
132
114
  }
133
- };
134
- }
135
- };
115
+ },
116
+ tools: {
117
+ babel: babelHandler,
118
+ bundlerChain: function(chain, param) {
119
+ var isServer = param.isServer;
120
+ if (isServer && appContext.moduleType === "module") {
121
+ chain.output.libraryTarget("module").set("chunkFormat", "module");
122
+ chain.output.library({
123
+ type: "module"
124
+ });
125
+ chain.experiments(_object_spread_props(_object_spread({}, chain.get("experiments")), {
126
+ outputModule: true
127
+ }));
128
+ }
129
+ }
130
+ }
131
+ };
132
+ });
136
133
  }
137
134
  };
138
135
  };
@@ -3,6 +3,7 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
3
3
  import { _ as _create_class } from "@swc/helpers/_/_create_class";
4
4
  import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
5
5
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
6
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
7
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
8
  import { ChunkExtractor } from "@loadable/server";
8
9
  import { attributesToString, checkIsNode } from "../utils";
@@ -83,7 +84,7 @@ var LoadableCollector = /* @__PURE__ */ function() {
83
84
  _proto.effect = function effect() {
84
85
  var _this = this;
85
86
  return _async_to_generator(function() {
86
- var extractor, chunks, scriptChunks, styleChunks;
87
+ var extractor, options, entryName, config, asyncChunks, _asyncChunks, chunks, scriptChunks, styleChunks;
87
88
  return _ts_generator(this, function(_state) {
88
89
  switch (_state.label) {
89
90
  case 0:
@@ -92,8 +93,19 @@ var LoadableCollector = /* @__PURE__ */ function() {
92
93
  2
93
94
  ];
94
95
  }
95
- extractor = _this.extractor;
96
- chunks = extractor.getChunkAssets(extractor.chunks);
96
+ extractor = _this.extractor, options = _this.options;
97
+ entryName = options.entryName, config = options.config;
98
+ asyncChunks = [];
99
+ if (config.enableAsyncEntry) {
100
+ try {
101
+ ;
102
+ (_asyncChunks = asyncChunks).push.apply(_asyncChunks, _to_consumable_array(extractor.getChunkAssets([
103
+ "async-".concat(entryName)
104
+ ])));
105
+ } catch (e) {
106
+ }
107
+ }
108
+ chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
97
109
  scriptChunks = generateChunks(chunks, "js");
98
110
  styleChunks = generateChunks(chunks, "css");
99
111
  _this.emitLoadableScripts(extractor);
@@ -220,11 +232,11 @@ var LoadableCollector = /* @__PURE__ */ function() {
220
232
  _proto.emitStyleAssets = function emitStyleAssets(chunks) {
221
233
  var _this = this;
222
234
  return _async_to_generator(function() {
223
- var _this_options, template, chunkSet, config, enableInlineStyles, atrributes, linkRegExp, matchs, existedLinks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, match, css;
235
+ var _this_options, template, chunkSet, config, entryName, enableInlineStyles, atrributes, linkRegExp, matchs, existedLinks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, match, css;
224
236
  return _ts_generator(this, function(_state) {
225
237
  switch (_state.label) {
226
238
  case 0:
227
- _this_options = _this.options, template = _this_options.template, chunkSet = _this_options.chunkSet, config = _this_options.config;
239
+ _this_options = _this.options, template = _this_options.template, chunkSet = _this_options.chunkSet, config = _this_options.config, entryName = _this_options.entryName;
228
240
  enableInlineStyles = config.enableInlineStyles;
229
241
  atrributes = attributesToString(_this.generateAttributes());
230
242
  linkRegExp = /<link .*?href="([^"]+)".*?>/g;
@@ -50,7 +50,7 @@ var documentPlugin = function() {
50
50
  }
51
51
  return _ts_generator(this, function(_state) {
52
52
  documentEntry = function(entryName, templateParameters) {
53
- var _api_useAppContext = api.useAppContext(), entrypoints = _api_useAppContext.entrypoints, internalDirectory = _api_useAppContext.internalDirectory, appDirectory = _api_useAppContext.appDirectory;
53
+ var _api_getAppContext = api.getAppContext(), entrypoints = _api_getAppContext.entrypoints, internalDirectory = _api_getAppContext.internalDirectory, appDirectory = _api_getAppContext.appDirectory;
54
54
  var documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
55
55
  if (!documentFilePath) {
56
56
  return null;
@@ -62,7 +62,7 @@ var documentPlugin = function() {
62
62
  switch (_state2.label) {
63
63
  case 0:
64
64
  htmlWebpackPlugin = param.htmlWebpackPlugin;
65
- config = api.useResolvedConfigContext();
65
+ config = api.getNormalizedConfig();
66
66
  documentParams = getDocParams({
67
67
  config,
68
68
  entryName,
@@ -156,7 +156,7 @@ var documentPlugin = function() {
156
156
  }, React.createElement(Document, null));
157
157
  html = ReactDomServer.renderToStaticMarkup(HTMLElement);
158
158
  debug("entry %s's document jsx rendered html: %o", entryName, html);
159
- partialsByEntrypoint = api.useAppContext().partialsByEntrypoint;
159
+ partialsByEntrypoint = api.getAppContext().partialsByEntrypoint;
160
160
  scripts = [
161
161
  htmlWebpackPlugin.tags.headTags.filter(function(item) {
162
162
  return item.tagName === "script";
@@ -218,35 +218,33 @@ var documentPlugin = function() {
218
218
  };
219
219
  }();
220
220
  };
221
- return [
222
- 2,
223
- {
224
- config: function() {
225
- var _userConfig_tools;
226
- var userConfig = api.useConfigContext();
227
- if (((_userConfig_tools = userConfig.tools) === null || _userConfig_tools === void 0 ? void 0 : _userConfig_tools.htmlPlugin) === false) {
228
- return {};
221
+ api.config(function() {
222
+ var _userConfig_tools;
223
+ var userConfig = api.getConfig();
224
+ if (((_userConfig_tools = userConfig.tools) === null || _userConfig_tools === void 0 ? void 0 : _userConfig_tools.htmlPlugin) === false) {
225
+ return {};
226
+ }
227
+ return {
228
+ tools: {
229
+ htmlPlugin: function(options, entry) {
230
+ var hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : _object_spread({}, options === null || options === void 0 ? void 0 : options.templateParameters);
231
+ var templateContent = documentEntry(
232
+ entry.entryName,
233
+ // options,
234
+ hackParameters
235
+ );
236
+ var documentHtmlOptions = templateContent ? {
237
+ templateContent,
238
+ // Note: the behavior of inject/modify tags in afterTemplateExecution hook will not take effect
239
+ inject: false
240
+ } : {};
241
+ return _object_spread({}, options, documentHtmlOptions);
229
242
  }
230
- return {
231
- tools: {
232
- htmlPlugin: function(options, entry) {
233
- var hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : _object_spread({}, options === null || options === void 0 ? void 0 : options.templateParameters);
234
- var templateContent = documentEntry(
235
- entry.entryName,
236
- // options,
237
- hackParameters
238
- );
239
- var documentHtmlOptions = templateContent ? {
240
- templateContent,
241
- // Note: the behavior of inject/modify tags in afterTemplateExecution hook will not take effect
242
- inject: false
243
- } : {};
244
- return _object_spread({}, options, documentHtmlOptions);
245
- }
246
- }
247
- };
248
243
  }
249
- }
244
+ };
245
+ });
246
+ return [
247
+ 2
250
248
  ];
251
249
  });
252
250
  });
@@ -13,18 +13,18 @@ import * as templates from "./templates";
13
13
  import { getServerCombinedModueFile, getServerLoadersFile } from "./utils";
14
14
  var generateCode = function() {
15
15
  var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
16
- var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, getRoutes, oldVersion;
16
+ var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hooks, isV5, getRoutes, oldVersion;
17
17
  function generateEntryCode(entrypoint) {
18
18
  return _generateEntryCode.apply(this, arguments);
19
19
  }
20
20
  function _generateEntryCode() {
21
21
  _generateEntryCode = _async_to_generator(function(entrypoint) {
22
- var entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry, metaName, _config_output, initialRoutes, nestedRoutes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, _$config, ssrByRouteIds, clonedRoutes, markedRoutes, routes, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, _config_output1, routesServerFile, filtedRoutesForServer, routesForServerLoaderMatches, code1, serverRoutesCode, serverLoaderCombined, serverLoaderFile;
22
+ var entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry, metaName, _config_output, initialRoutes, nestedRoutes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, _$config, ssrByRouteIds, clonedRoutes, markedRoutes, routes, ssr, useSSG, mode, hasPageRoute, code, _, _1, _tmp, _config_output1, routesServerFile, filtedRoutesForServer, routesForServerLoaderMatches, code1, serverRoutesCode, serverLoaderCombined, serverLoaderFile;
23
23
  return _ts_generator(this, function(_state) {
24
24
  switch (_state.label) {
25
25
  case 0:
26
26
  entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, isAutoMount = entrypoint.isAutoMount, pageRoutesEntry = entrypoint.pageRoutesEntry, nestedRoutesEntry = entrypoint.nestedRoutesEntry;
27
- metaName = api.useAppContext().metaName;
27
+ metaName = api.getAppContext().metaName;
28
28
  if (!isAutoMount)
29
29
  return [
30
30
  3,
@@ -89,13 +89,13 @@ var generateCode = function() {
89
89
  }
90
90
  _state.label = 2;
91
91
  case 2:
92
- _$config = api.useResolvedConfigContext();
92
+ _$config = api.getNormalizedConfig();
93
93
  ssrByRouteIds = _$config.server.ssrByRouteIds || [];
94
94
  clonedRoutes = cloneDeep(initialRoutes);
95
95
  markedRoutes = ssrByRouteIds.length > 0 ? markRoutes(clonedRoutes, ssrByRouteIds) : initialRoutes;
96
96
  return [
97
97
  4,
98
- hookRunners.modifyFileSystemRoutes({
98
+ hooks.modifyFileSystemRoutes.call({
99
99
  entrypoint,
100
100
  routes: markedRoutes
101
101
  })
@@ -116,7 +116,7 @@ var generateCode = function() {
116
116
  process.exit(1);
117
117
  }
118
118
  }
119
- _ = hookRunners.beforeGenerateRoutes;
119
+ _1 = (_ = hooks.onBeforeGenerateRoutes).call;
120
120
  _tmp = {
121
121
  entrypoint
122
122
  };
@@ -135,7 +135,7 @@ var generateCode = function() {
135
135
  case 4:
136
136
  return [
137
137
  4,
138
- _.apply(hookRunners, [
138
+ _1.apply(_, [
139
139
  (_tmp.code = _state.sent(), _tmp)
140
140
  ])
141
141
  ];
@@ -221,7 +221,7 @@ var generateCode = function() {
221
221
  switch (_state.label) {
222
222
  case 0:
223
223
  internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
224
- hookRunners = api.useHookRunners();
224
+ hooks = api.getHooks();
225
225
  isV5 = isRouterV5(config);
226
226
  getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
227
227
  oldVersion = _type_of(config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
@@ -13,7 +13,7 @@ function _handleModifyEntrypoints() {
13
13
  _handleModifyEntrypoints = _async_to_generator(function(api, entrypoints) {
14
14
  var config;
15
15
  return _ts_generator(this, function(_state) {
16
- config = api.useResolvedConfigContext();
16
+ config = api.getNormalizedConfig();
17
17
  return [
18
18
  2,
19
19
  modifyEntrypoints(entrypoints, config)
@@ -31,9 +31,9 @@ function _handleGeneratorEntryCode() {
31
31
  return _ts_generator(this, function(_state) {
32
32
  switch (_state.label) {
33
33
  case 0:
34
- appContext = api.useAppContext();
35
- internalDirectory = api.useAppContext().internalDirectory;
36
- resolvedConfig = api.useResolvedConfigContext();
34
+ appContext = api.getAppContext();
35
+ internalDirectory = appContext.internalDirectory;
36
+ resolvedConfig = api.getNormalizedConfig();
37
37
  return [
38
38
  4,
39
39
  import("./code")
@@ -111,7 +111,7 @@ function _handleFileChange() {
111
111
  return _ts_generator(this, function(_state) {
112
112
  switch (_state.label) {
113
113
  case 0:
114
- appContext = api.useAppContext();
114
+ appContext = api.getAppContext();
115
115
  appDirectory = appContext.appDirectory, entrypoints = appContext.entrypoints;
116
116
  filename = e.filename, eventType = e.eventType;
117
117
  nestedRouteEntries = entrypoints.map(function(point) {
@@ -134,7 +134,7 @@ function _handleFileChange() {
134
134
  3,
135
135
  3
136
136
  ];
137
- resolvedConfig = api.useResolvedConfigContext();
137
+ resolvedConfig = api.getNormalizedConfig();
138
138
  return [
139
139
  4,
140
140
  import("./code")