@modern-js/runtime 2.17.1 → 2.18.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 (67) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +6 -0
  3. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +6 -6
  4. package/dist/cjs/router/runtime/index.js +5 -5
  5. package/dist/cjs/router/runtime/plugin.js +2 -2
  6. package/dist/cjs/router/runtime/plugin.node.js +2 -2
  7. package/dist/cjs/router/runtime/utils.js +4 -5
  8. package/dist/cjs/ssr/cli/index.js +30 -15
  9. package/dist/cjs/ssr/cli/loadable-bundler-plugin.js +112 -0
  10. package/dist/cjs/ssr/index.js +3 -3
  11. package/dist/cjs/ssr/prefetch.js +2 -2
  12. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +2 -2
  13. package/dist/cjs/ssr/serverRender/renderToStream/index.js +2 -2
  14. package/dist/cjs/ssr/serverRender/renderToString/entry.js +3 -3
  15. package/dist/cjs/ssr/serverRender/renderToString/index.js +2 -2
  16. package/dist/esm/core/compatible.js +13 -13
  17. package/dist/esm/core/loader/loaderManager.js +7 -7
  18. package/dist/esm/core/loader/useLoader.js +2 -2
  19. package/dist/esm/core/plugin.js +6 -6
  20. package/dist/esm/document/Html.js +5 -5
  21. package/dist/esm/document/cli/index.js +6 -6
  22. package/dist/esm/document/constants.js +1 -1
  23. package/dist/esm/router/cli/index.js +6 -6
  24. package/dist/esm/router/runtime/DeferredDataScripts.node.js +4 -4
  25. package/dist/esm/router/runtime/PrefetchLink.js +7 -7
  26. package/dist/esm/router/runtime/index.js +2 -2
  27. package/dist/esm/router/runtime/plugin.js +10 -10
  28. package/dist/esm/router/runtime/plugin.node.js +8 -8
  29. package/dist/esm/router/runtime/utils.js +7 -8
  30. package/dist/esm/router/runtime/withRouter.js +4 -4
  31. package/dist/esm/ssr/cli/index.js +37 -22
  32. package/dist/esm/ssr/cli/loadable-bundler-plugin.js +209 -0
  33. package/dist/esm/ssr/index.js +14 -14
  34. package/dist/esm/ssr/index.node.js +9 -9
  35. package/dist/esm/ssr/prefetch.js +4 -4
  36. package/dist/esm/ssr/react/prerender/index.js +1 -1
  37. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +4 -4
  38. package/dist/esm/ssr/serverRender/renderToStream/index.js +1 -1
  39. package/dist/esm/ssr/serverRender/renderToStream/loadable.js +1 -1
  40. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +1 -1
  41. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +1 -1
  42. package/dist/esm/ssr/serverRender/renderToStream/template.js +2 -2
  43. package/dist/esm/ssr/serverRender/renderToString/entry.js +4 -4
  44. package/dist/esm/ssr/serverRender/renderToString/index.js +3 -3
  45. package/dist/esm/ssr/serverRender/renderToString/loadable.js +1 -1
  46. package/dist/esm/ssr/serverRender/renderToString/template.js +1 -1
  47. package/dist/esm/ssr/utils.js +4 -4
  48. package/dist/esm/state/cli/index.js +4 -4
  49. package/dist/esm/state/runtime/plugin.js +7 -7
  50. package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +1 -1
  51. package/dist/esm-node/router/runtime/index.js +2 -2
  52. package/dist/esm-node/router/runtime/plugin.js +1 -1
  53. package/dist/esm-node/router/runtime/plugin.node.js +1 -1
  54. package/dist/esm-node/router/runtime/utils.js +1 -2
  55. package/dist/esm-node/ssr/cli/index.js +30 -15
  56. package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +103 -0
  57. package/dist/esm-node/ssr/index.js +1 -1
  58. package/dist/esm-node/ssr/prefetch.js +1 -1
  59. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
  60. package/dist/esm-node/ssr/serverRender/renderToStream/index.js +1 -1
  61. package/dist/esm-node/ssr/serverRender/renderToString/entry.js +1 -1
  62. package/dist/esm-node/ssr/serverRender/renderToString/index.js +1 -1
  63. package/dist/types/router/runtime/index.d.ts +1 -1
  64. package/dist/types/router/runtime/utils.d.ts +1 -1
  65. package/dist/types/runtimeContext.d.ts +1 -1
  66. package/dist/types/ssr/cli/loadable-bundler-plugin.d.ts +10 -0
  67. package/package.json +9 -9
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "react-router-dom";
3
3
  import hoistNonReactStatics from "hoist-non-react-statics";
4
- import { parsedJSONFromElement } from "@modern-js/utils/runtime";
4
+ import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
5
5
  import { modifyRoutes as modifyRoutesHook } from "./hooks";
6
6
  import { deserializeErrors, renderRoutes, urlJoin } from "./utils";
7
7
  export let finalRouteConfig = {
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useContext } from "react";
3
- import { createStaticHandler } from "@modern-js/utils/universal/remix-router";
3
+ import { createStaticHandler } from "@modern-js/utils/runtime/router";
4
4
  import { createStaticRouter, StaticRouterProvider } from "react-router-dom/server";
5
5
  import hoistNonReactStatics from "hoist-non-react-statics";
6
6
  import { createRoutesFromElements } from "react-router-dom";
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Route } from "react-router-dom";
3
- import { ErrorResponse, isRouteErrorResponse } from "@modern-js/utils/universal/remix-router";
4
- import { renderNestedRoute } from "@modern-js/utils/universal/nestedRoutes";
3
+ import { ErrorResponse, isRouteErrorResponse, renderNestedRoute } from "@modern-js/utils/runtime/router";
5
4
  import { DefaultNotFound } from "./DefaultNotFound";
6
5
  import DeferredDataScripts from "./DeferredDataScripts";
7
6
  export function getRouteComponents(routes, { globalApp, ssrMode, props }) {
@@ -29,21 +29,36 @@ export default () => {
29
29
  config() {
30
30
  const appContext = api.useAppContext();
31
31
  pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
32
+ const userConfig = api.useResolvedConfigContext();
32
33
  const { bundlerType = "webpack" } = api.useAppContext();
33
- const babelConfig = bundlerType === "webpack" ? (config) => {
34
- var _config_plugins;
35
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
36
- const userConfig = api.useResolvedConfigContext();
37
- if (isUseSSRBundle(userConfig) && hasStringSSREntry(userConfig)) {
38
- var _config_plugins1;
39
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
34
+ const babelConfig = (() => {
35
+ if (bundlerType === "webpack") {
36
+ return (config) => {
37
+ var _config_plugins;
38
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
39
+ if (isUseSSRBundle(userConfig) && hasStringSSREntry(userConfig)) {
40
+ var _config_plugins1;
41
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
42
+ }
43
+ };
44
+ } else if (bundlerType === "rspack") {
45
+ if (isUseSSRBundle(userConfig)) {
46
+ return (config) => {
47
+ var _config_plugins;
48
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
49
+ if (hasStringSSREntry(userConfig)) {
50
+ var _config_plugins1;
51
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
52
+ }
53
+ };
54
+ }
40
55
  }
41
- } : void 0;
56
+ })();
42
57
  return {
43
58
  source: {
44
59
  alias: {
45
- // ensure that all packages use the same storage in @modern-js/utils/ssr
46
- "@modern-js/utils/ssr": require.resolve("@modern-js/utils/ssr"),
60
+ // ensure that all packages use the same storage in @modern-js/utils/runtime-node
61
+ "@modern-js/utils/runtime-node": require.resolve("@modern-js/utils/runtime-node"),
47
62
  "@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
48
63
  },
49
64
  globalVars: (values, { target }) => {
@@ -51,11 +66,11 @@ export default () => {
51
66
  }
52
67
  },
53
68
  tools: {
54
- webpackChain: (chain, { isServer, isServiceWorker, CHAIN_ID }) => {
55
- const userConfig = api.useResolvedConfigContext();
56
- if (isUseSSRBundle(userConfig) && !isServer && !isServiceWorker && hasStringSSREntry(userConfig)) {
57
- const LoadableWebpackPlugin = require("@loadable/webpack-plugin");
58
- chain.plugin(CHAIN_ID.PLUGIN.LOADABLE).use(LoadableWebpackPlugin, [
69
+ bundlerChain(chain, { isServer, isServiceWorker, CHAIN_ID }) {
70
+ const userConfig2 = api.useResolvedConfigContext();
71
+ if (isUseSSRBundle(userConfig2) && !isServer && !isServiceWorker && hasStringSSREntry(userConfig2)) {
72
+ const LoadableBundlerPlugin = require("./loadable-bundler-plugin.js");
73
+ chain.plugin(CHAIN_ID.PLUGIN.LOADABLE).use(LoadableBundlerPlugin, [
59
74
  {
60
75
  filename: LOADABLE_STATS_FILE
61
76
  }
@@ -0,0 +1,103 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ import path from "path";
15
+ import { fs } from "@modern-js/utils";
16
+ class LoadablePlugin {
17
+ apply(compiler) {
18
+ this.compiler = compiler;
19
+ compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
20
+ if (this.opts.outputAsset || this.opts.writeToDisk) {
21
+ compiler.hooks.make.tap(LoadablePlugin.name, (compilation) => {
22
+ compilation.hooks.processAssets.tap({
23
+ name: LoadablePlugin.name,
24
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
25
+ }, () => {
26
+ const asset = this.handleEmit(compilation);
27
+ if (asset) {
28
+ compilation.emitAsset(this.opts.filename, asset);
29
+ }
30
+ });
31
+ });
32
+ }
33
+ }
34
+ handleEmit(compilation) {
35
+ const stats = compilation.getStats().toJson({
36
+ all: false,
37
+ assets: true,
38
+ // rspack not support cachedAssets,
39
+ cachedAssets: true,
40
+ chunks: true,
41
+ chunkGroups: true,
42
+ entrypoints: true,
43
+ // rspack not support chunkGroupChildren.
44
+ chunkGroupChildren: true,
45
+ hash: true,
46
+ ids: true,
47
+ outputPath: true,
48
+ publicPath: true
49
+ });
50
+ const output = {
51
+ ...stats,
52
+ generator: "loadable-components",
53
+ chunks: [
54
+ ...stats.chunks || []
55
+ ].map((chunk) => {
56
+ return {
57
+ id: chunk.id,
58
+ files: [
59
+ ...chunk.files || []
60
+ ]
61
+ };
62
+ })
63
+ };
64
+ const result = JSON.stringify(output, null, 2);
65
+ if (this.opts.writeToDisk) {
66
+ this.writeAssetsFile(result);
67
+ }
68
+ if (this.opts.outputAsset) {
69
+ return {
70
+ source() {
71
+ return result;
72
+ },
73
+ size() {
74
+ return result.length;
75
+ }
76
+ };
77
+ }
78
+ return null;
79
+ }
80
+ writeAssetsFile(manifest) {
81
+ var _this_compiler;
82
+ const outputFolder = (_this_compiler = this.compiler) === null || _this_compiler === void 0 ? void 0 : _this_compiler.options.output.path;
83
+ const outputFile = path.resolve(outputFolder || "", this.opts.filename);
84
+ fs.outputFileSync(outputFile, manifest);
85
+ }
86
+ constructor({ filename = "loadable-stats.json", path: path2, writeToDisk, outputAsset = true, chunkLoadingGlobal = "__LOADABLE_LOADED_CHUNKS__" } = {
87
+ filename: "loadable-stats.json",
88
+ outputAsset: true,
89
+ chunkLoadingGlobal: "__LOADABLE_LOADED_CHUNKS__"
90
+ }) {
91
+ _define_property(this, "opts", void 0);
92
+ _define_property(this, "compiler", void 0);
93
+ this.opts = {
94
+ filename,
95
+ path: path2,
96
+ writeToDisk,
97
+ outputAsset,
98
+ chunkLoadingGlobal
99
+ };
100
+ this.compiler = null;
101
+ }
102
+ }
103
+ module.exports = LoadablePlugin;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { loadableReady } from "@loadable/component";
3
3
  import hoistNonReactStatics from "hoist-non-react-statics";
4
- import { parsedJSONFromElement } from "@modern-js/utils/runtime";
4
+ import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
5
5
  import { RenderLevel } from "./serverRender/types";
6
6
  import { WithCallback } from "./react/withCallback";
7
7
  import { formatClient, mockResponse, isReact18 } from "./utils";
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { renderToStaticMarkup } from "react-dom/server";
3
- import { run } from "@modern-js/utils/ssr";
3
+ import { run } from "@modern-js/utils/runtime-node";
4
4
  import { ChunkExtractor } from "@loadable/server";
5
5
  const prefetch = async (App, context) => {
6
6
  return run(context.ssrContext.request.headers, async () => {
@@ -1,4 +1,4 @@
1
- import { serializeJson } from "@modern-js/utils/universal/serialize";
1
+ import { serializeJson } from "@modern-js/utils/runtime-node";
2
2
  import { buildTemplate } from "./buildTemplate.share";
3
3
  export function buildShellAfterTemplate(afterAppTemplate, options) {
4
4
  const callbacks = [
@@ -1,5 +1,5 @@
1
1
  import { createElement } from "react";
2
- import { run } from "@modern-js/utils/ssr";
2
+ import { run } from "@modern-js/utils/runtime-node";
3
3
  import { PreRender } from "../../react/prerender";
4
4
  import { time } from "../time";
5
5
  import renderToPipe from "./renderToPipe";
@@ -13,7 +13,7 @@ function _define_property(obj, key, value) {
13
13
  }
14
14
  import React from "react";
15
15
  import ReactDomServer from "react-dom/server";
16
- import { serializeJson } from "@modern-js/utils/universal/serialize";
16
+ import { serializeJson } from "@modern-js/utils/runtime-node";
17
17
  import ReactHelmet from "react-helmet";
18
18
  import { serializeErrors } from "../../../router/runtime/utils";
19
19
  import helmetReplace from "../helmet";
@@ -1,4 +1,4 @@
1
- import { run } from "@modern-js/utils/ssr";
1
+ import { run } from "@modern-js/utils/runtime-node";
2
2
  import { PreRender } from "../../react/prerender";
3
3
  import { time } from "../time";
4
4
  import SSREntry from "./entry";
@@ -10,4 +10,4 @@ export type { LinkProps, NavLinkProps } from './PrefetchLink';
10
10
  export declare const useRouteLoaderData: typeof useRouteData;
11
11
  export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, FetcherWithComponents, BrowserRouterProps, HashRouterProps, HistoryRouterProps, FormProps, ScrollRestorationProps, SubmitFunction, ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To } from 'react-router-dom';
12
12
  export { createBrowserRouter, createHashRouter, createMemoryRouter, RouterProvider, BrowserRouter, HashRouter, MemoryRouter, Router, Await, Form, Navigate, Outlet, Route, Routes, ScrollRestoration, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRoutes, useSearchParams, useSubmit, createRoutesFromChildren, createRoutesFromElements, createSearchParams, generatePath, isRouteErrorResponse, matchPath, matchRoutes, renderMatches, resolvePath, createPath, unstable_useBlocker, unstable_usePrompt } from 'react-router-dom';
13
- export { defer, json, redirect } from '@modern-js/utils/universal/remix-router';
13
+ export { defer, json, redirect } from '@modern-js/utils/runtime/router';
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { type NestedRoute, type PageRoute, type SSRMode } from '@modern-js/types';
3
- import { type Router, type StaticHandlerContext } from '@modern-js/utils/universal/remix-router';
3
+ import { type Router, type StaticHandlerContext } from '@modern-js/utils/runtime/router';
4
4
  import { RouterConfig } from './types';
5
5
  export declare function getRouteComponents(routes: (NestedRoute | PageRoute)[], {
6
6
  globalApp,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Store } from '@modern-js-reduck/store';
3
- import type { StaticHandlerContext } from '@modern-js/utils/universal/remix-router';
3
+ import type { StaticHandlerContext } from '@modern-js/utils/runtime/router';
4
4
  import { createLoaderManager } from './core/loader/loaderManager';
5
5
  import { runtime } from './core/plugin';
6
6
  import { RouteManifest } from './router/runtime/types';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/gregberge/loadable-components
4
+ *
5
+ * MIT Licensed
6
+ * Author Greg Bergé
7
+ * Copyright 2019 Greg Bergé
8
+ * https://github.com/gregberge/loadable-components/blob/main/LICENSE
9
+ */
10
+ export {};
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.17.1",
18
+ "version": "2.18.1",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -162,9 +162,9 @@
162
162
  "react-side-effect": "^2.1.1",
163
163
  "redux-logger": "^3.0.6",
164
164
  "styled-components": "^5.3.1",
165
- "@modern-js/plugin": "2.17.1",
166
- "@modern-js/types": "2.17.1",
167
- "@modern-js/utils": "2.17.1"
165
+ "@modern-js/plugin": "2.18.1",
166
+ "@modern-js/types": "2.18.1",
167
+ "@modern-js/utils": "2.18.1"
168
168
  },
169
169
  "peerDependencies": {
170
170
  "react": ">=17",
@@ -184,11 +184,11 @@
184
184
  "react-dom": "^18",
185
185
  "ts-jest": "^29.0.5",
186
186
  "typescript": "^4",
187
- "@modern-js/app-tools": "2.17.1",
188
- "@modern-js/core": "2.17.1",
189
- "@modern-js/server-core": "2.17.1",
190
- "@scripts/build": "2.17.1",
191
- "@scripts/jest-config": "2.17.1"
187
+ "@modern-js/app-tools": "2.18.1",
188
+ "@modern-js/core": "2.18.1",
189
+ "@modern-js/server-core": "2.18.1",
190
+ "@scripts/build": "2.18.1",
191
+ "@scripts/jest-config": "2.18.1"
192
192
  },
193
193
  "sideEffects": false,
194
194
  "modernConfig": {},