@modern-js/runtime 2.35.0 → 2.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/dist/cjs/cli/index.js +48 -30
  2. package/dist/cjs/common.js +27 -18
  3. package/dist/cjs/config.js +15 -3
  4. package/dist/cjs/core/appConfig.js +25 -15
  5. package/dist/cjs/core/compatible.js +69 -53
  6. package/dist/cjs/core/index.js +47 -40
  7. package/dist/cjs/core/loader/index.js +35 -9
  8. package/dist/cjs/core/loader/loaderManager.js +37 -18
  9. package/dist/cjs/core/loader/useLoader.js +53 -31
  10. package/dist/cjs/core/plugin.js +41 -34
  11. package/dist/cjs/core/types.js +15 -3
  12. package/dist/cjs/document/Body.js +35 -19
  13. package/dist/cjs/document/Comment.js +29 -14
  14. package/dist/cjs/document/DocumentContext.js +36 -10
  15. package/dist/cjs/document/DocumentStructureContext.js +36 -10
  16. package/dist/cjs/document/Head.js +40 -31
  17. package/dist/cjs/document/Html.js +37 -23
  18. package/dist/cjs/document/Links.js +28 -13
  19. package/dist/cjs/document/Root.js +37 -28
  20. package/dist/cjs/document/Script.js +29 -14
  21. package/dist/cjs/document/Scripts.js +28 -13
  22. package/dist/cjs/document/Style.js +29 -14
  23. package/dist/cjs/document/cli/index.js +72 -57
  24. package/dist/cjs/document/constants.js +64 -72
  25. package/dist/cjs/document/index.js +42 -15
  26. package/dist/cjs/exports/head.js +38 -11
  27. package/dist/cjs/exports/loadable.js +38 -11
  28. package/dist/cjs/exports/server.js +24 -7
  29. package/dist/cjs/exports/styled.js +38 -11
  30. package/dist/cjs/index.js +41 -38
  31. package/dist/cjs/router/cli/index.js +32 -24
  32. package/dist/cjs/router/index.js +39 -18
  33. package/dist/cjs/router/runtime/DefaultNotFound.js +26 -11
  34. package/dist/cjs/router/runtime/DeferredDataScripts.js +21 -8
  35. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +49 -38
  36. package/dist/cjs/router/runtime/PrefetchLink.js +64 -50
  37. package/dist/cjs/router/runtime/fetch.js +24 -7
  38. package/dist/cjs/router/runtime/fetch.node.js +25 -8
  39. package/dist/cjs/router/runtime/fetch.worker.js +24 -7
  40. package/dist/cjs/router/runtime/hooks.js +26 -9
  41. package/dist/cjs/router/runtime/index.js +155 -208
  42. package/dist/cjs/router/runtime/plugin.js +64 -50
  43. package/dist/cjs/router/runtime/plugin.node.js +66 -50
  44. package/dist/cjs/router/runtime/server.js +20 -4
  45. package/dist/cjs/router/runtime/types.js +15 -3
  46. package/dist/cjs/router/runtime/utils.js +64 -51
  47. package/dist/cjs/router/runtime/withRouter.js +30 -15
  48. package/dist/cjs/runtimeContext.js +28 -18
  49. package/dist/cjs/ssr/cli/babel-plugin-ssr-loader-id.js +40 -23
  50. package/dist/cjs/ssr/cli/index.js +57 -41
  51. package/dist/cjs/ssr/cli/loadable-bundler-plugin.js +31 -13
  52. package/dist/cjs/ssr/index.js +71 -52
  53. package/dist/cjs/ssr/index.node.js +45 -27
  54. package/dist/cjs/ssr/prefetch.js +31 -18
  55. package/dist/cjs/ssr/react/index.js +27 -17
  56. package/dist/cjs/ssr/react/nossr/index.js +38 -12
  57. package/dist/cjs/ssr/react/prerender/index.js +52 -27
  58. package/dist/cjs/ssr/react/prerender/type.js +15 -3
  59. package/dist/cjs/ssr/react/prerender/util.js +33 -28
  60. package/dist/cjs/ssr/react/withCallback/index.js +27 -11
  61. package/dist/cjs/ssr/serverRender/helmet.js +23 -15
  62. package/dist/cjs/ssr/serverRender/index.js +24 -11
  63. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +30 -13
  64. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.share.js +25 -15
  65. package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +48 -26
  66. package/dist/cjs/ssr/serverRender/renderToStream/index.js +49 -23
  67. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +35 -23
  68. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +33 -22
  69. package/dist/cjs/ssr/serverRender/renderToStream/template.js +28 -11
  70. package/dist/cjs/ssr/serverRender/renderToString/buildHtml.js +31 -24
  71. package/dist/cjs/ssr/serverRender/renderToString/entry.js +81 -59
  72. package/dist/cjs/ssr/serverRender/renderToString/index.js +44 -18
  73. package/dist/cjs/ssr/serverRender/renderToString/loadable.js +61 -33
  74. package/dist/cjs/ssr/serverRender/renderToString/render.js +39 -13
  75. package/dist/cjs/ssr/serverRender/renderToString/styledComponent.js +28 -11
  76. package/dist/cjs/ssr/serverRender/renderToString/type.js +24 -7
  77. package/dist/cjs/ssr/serverRender/tracker.js +27 -18
  78. package/dist/cjs/ssr/serverRender/types.js +25 -8
  79. package/dist/cjs/ssr/serverRender/utils.js +31 -24
  80. package/dist/cjs/ssr/utils.js +42 -25
  81. package/dist/cjs/state/cli/index.js +28 -19
  82. package/dist/cjs/state/index.js +39 -18
  83. package/dist/cjs/state/plugins.js +46 -29
  84. package/dist/cjs/state/runtime/index.js +39 -11
  85. package/dist/cjs/state/runtime/plugin.js +55 -28
  86. package/dist/esm/cli/index.js +6 -2
  87. package/dist/esm/common.js +8 -3
  88. package/dist/esm/config.js +0 -1
  89. package/dist/esm/core/appConfig.js +6 -2
  90. package/dist/esm/core/compatible.js +29 -25
  91. package/dist/esm/core/index.js +13 -3
  92. package/dist/esm/core/loader/index.js +4 -1
  93. package/dist/esm/core/loader/loaderManager.js +13 -9
  94. package/dist/esm/core/loader/useLoader.js +13 -10
  95. package/dist/esm/core/plugin.js +17 -13
  96. package/dist/esm/core/types.js +0 -1
  97. package/dist/esm/document/Body.js +4 -1
  98. package/dist/esm/document/Comment.js +4 -1
  99. package/dist/esm/document/DocumentContext.js +4 -1
  100. package/dist/esm/document/DocumentStructureContext.js +4 -1
  101. package/dist/esm/document/Head.js +6 -2
  102. package/dist/esm/document/Html.js +12 -10
  103. package/dist/esm/document/Links.js +4 -1
  104. package/dist/esm/document/Root.js +6 -2
  105. package/dist/esm/document/Script.js +4 -1
  106. package/dist/esm/document/Scripts.js +4 -1
  107. package/dist/esm/document/Style.js +4 -1
  108. package/dist/esm/document/cli/index.js +18 -14
  109. package/dist/esm/document/constants.js +42 -20
  110. package/dist/esm/exports/head.js +4 -1
  111. package/dist/esm/exports/loadable.js +4 -1
  112. package/dist/esm/exports/server.js +4 -1
  113. package/dist/esm/exports/styled.js +4 -1
  114. package/dist/esm/index.js +13 -2
  115. package/dist/esm/router/cli/index.js +12 -9
  116. package/dist/esm/router/index.js +6 -2
  117. package/dist/esm/router/runtime/DefaultNotFound.js +4 -1
  118. package/dist/esm/router/runtime/DeferredDataScripts.js +4 -1
  119. package/dist/esm/router/runtime/DeferredDataScripts.node.js +14 -13
  120. package/dist/esm/router/runtime/PrefetchLink.js +17 -17
  121. package/dist/esm/router/runtime/fetch.js +3 -1
  122. package/dist/esm/router/runtime/fetch.node.js +3 -1
  123. package/dist/esm/router/runtime/fetch.worker.js +3 -1
  124. package/dist/esm/router/runtime/hooks.js +3 -1
  125. package/dist/esm/router/runtime/index.js +72 -8
  126. package/dist/esm/router/runtime/plugin.js +26 -22
  127. package/dist/esm/router/runtime/plugin.node.js +26 -22
  128. package/dist/esm/router/runtime/server.js +1 -1
  129. package/dist/esm/router/runtime/types.js +0 -1
  130. package/dist/esm/router/runtime/utils.js +29 -20
  131. package/dist/esm/router/runtime/withRouter.js +8 -5
  132. package/dist/esm/runtimeContext.js +6 -2
  133. package/dist/esm/ssr/cli/babel-plugin-ssr-loader-id.js +107 -98
  134. package/dist/esm/ssr/cli/index.js +26 -24
  135. package/dist/esm/ssr/cli/loadable-bundler-plugin.js +105 -96
  136. package/dist/esm/ssr/index.js +19 -15
  137. package/dist/esm/ssr/index.node.js +15 -12
  138. package/dist/esm/ssr/prefetch.js +10 -7
  139. package/dist/esm/ssr/react/index.js +6 -2
  140. package/dist/esm/ssr/react/nossr/index.js +4 -1
  141. package/dist/esm/ssr/react/prerender/index.js +4 -1
  142. package/dist/esm/ssr/react/prerender/type.js +0 -1
  143. package/dist/esm/ssr/react/prerender/util.js +14 -9
  144. package/dist/esm/ssr/react/withCallback/index.js +4 -1
  145. package/dist/esm/ssr/serverRender/helmet.js +4 -1
  146. package/dist/esm/ssr/serverRender/index.js +4 -1
  147. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +8 -5
  148. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.share.js +6 -2
  149. package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +7 -6
  150. package/dist/esm/ssr/serverRender/renderToStream/index.js +6 -3
  151. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +9 -7
  152. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +9 -6
  153. package/dist/esm/ssr/serverRender/renderToStream/template.js +6 -3
  154. package/dist/esm/ssr/serverRender/renderToString/buildHtml.js +12 -5
  155. package/dist/esm/ssr/serverRender/renderToString/entry.js +7 -5
  156. package/dist/esm/ssr/serverRender/renderToString/index.js +8 -5
  157. package/dist/esm/ssr/serverRender/renderToString/loadable.js +37 -20
  158. package/dist/esm/ssr/serverRender/renderToString/render.js +4 -1
  159. package/dist/esm/ssr/serverRender/renderToString/styledComponent.js +4 -1
  160. package/dist/esm/ssr/serverRender/renderToString/type.js +4 -1
  161. package/dist/esm/ssr/serverRender/tracker.js +8 -3
  162. package/dist/esm/ssr/serverRender/types.js +3 -1
  163. package/dist/esm/ssr/serverRender/utils.js +12 -5
  164. package/dist/esm/ssr/utils.js +13 -7
  165. package/dist/esm/state/cli/index.js +10 -6
  166. package/dist/esm/state/index.js +6 -2
  167. package/dist/esm/state/plugins.js +10 -4
  168. package/dist/esm/state/runtime/index.js +4 -1
  169. package/dist/esm/state/runtime/plugin.js +10 -7
  170. package/dist/esm-node/cli/index.js +6 -2
  171. package/dist/esm-node/common.js +8 -3
  172. package/dist/esm-node/config.js +0 -1
  173. package/dist/esm-node/core/appConfig.js +6 -2
  174. package/dist/esm-node/core/compatible.js +17 -13
  175. package/dist/esm-node/core/index.js +13 -3
  176. package/dist/esm-node/core/loader/index.js +4 -1
  177. package/dist/esm-node/core/loader/loaderManager.js +6 -2
  178. package/dist/esm-node/core/loader/useLoader.js +12 -9
  179. package/dist/esm-node/core/plugin.js +11 -7
  180. package/dist/esm-node/core/types.js +0 -1
  181. package/dist/esm-node/document/Body.js +4 -1
  182. package/dist/esm-node/document/Comment.js +4 -1
  183. package/dist/esm-node/document/DocumentContext.js +4 -1
  184. package/dist/esm-node/document/DocumentStructureContext.js +4 -1
  185. package/dist/esm-node/document/Head.js +6 -2
  186. package/dist/esm-node/document/Html.js +7 -5
  187. package/dist/esm-node/document/Links.js +4 -1
  188. package/dist/esm-node/document/Root.js +6 -2
  189. package/dist/esm-node/document/Script.js +4 -1
  190. package/dist/esm-node/document/Scripts.js +4 -1
  191. package/dist/esm-node/document/Style.js +4 -1
  192. package/dist/esm-node/document/cli/index.js +12 -9
  193. package/dist/esm-node/document/constants.js +42 -20
  194. package/dist/esm-node/exports/head.js +4 -1
  195. package/dist/esm-node/exports/loadable.js +4 -1
  196. package/dist/esm-node/exports/server.js +4 -1
  197. package/dist/esm-node/exports/styled.js +4 -1
  198. package/dist/esm-node/index.js +13 -2
  199. package/dist/esm-node/router/cli/index.js +7 -4
  200. package/dist/esm-node/router/index.js +6 -2
  201. package/dist/esm-node/router/runtime/DefaultNotFound.js +4 -1
  202. package/dist/esm-node/router/runtime/DeferredDataScripts.js +4 -1
  203. package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +8 -7
  204. package/dist/esm-node/router/runtime/PrefetchLink.js +11 -11
  205. package/dist/esm-node/router/runtime/fetch.js +3 -1
  206. package/dist/esm-node/router/runtime/fetch.node.js +3 -1
  207. package/dist/esm-node/router/runtime/fetch.worker.js +3 -1
  208. package/dist/esm-node/router/runtime/hooks.js +3 -1
  209. package/dist/esm-node/router/runtime/index.js +72 -8
  210. package/dist/esm-node/router/runtime/plugin.js +14 -10
  211. package/dist/esm-node/router/runtime/plugin.node.js +14 -10
  212. package/dist/esm-node/router/runtime/server.js +1 -1
  213. package/dist/esm-node/router/runtime/types.js +0 -1
  214. package/dist/esm-node/router/runtime/utils.js +22 -13
  215. package/dist/esm-node/router/runtime/withRouter.js +5 -2
  216. package/dist/esm-node/runtimeContext.js +6 -2
  217. package/dist/esm-node/ssr/cli/babel-plugin-ssr-loader-id.js +108 -99
  218. package/dist/esm-node/ssr/cli/index.js +15 -13
  219. package/dist/esm-node/ssr/cli/loadable-bundler-plugin.js +92 -83
  220. package/dist/esm-node/ssr/index.js +7 -3
  221. package/dist/esm-node/ssr/index.node.js +7 -4
  222. package/dist/esm-node/ssr/prefetch.js +7 -4
  223. package/dist/esm-node/ssr/react/index.js +6 -2
  224. package/dist/esm-node/ssr/react/nossr/index.js +4 -1
  225. package/dist/esm-node/ssr/react/prerender/index.js +4 -1
  226. package/dist/esm-node/ssr/react/prerender/type.js +0 -1
  227. package/dist/esm-node/ssr/react/prerender/util.js +14 -9
  228. package/dist/esm-node/ssr/react/withCallback/index.js +4 -1
  229. package/dist/esm-node/ssr/serverRender/helmet.js +4 -1
  230. package/dist/esm-node/ssr/serverRender/index.js +4 -1
  231. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +5 -2
  232. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.share.js +6 -2
  233. package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +7 -8
  234. package/dist/esm-node/ssr/serverRender/renderToStream/index.js +6 -3
  235. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +9 -7
  236. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +8 -7
  237. package/dist/esm-node/ssr/serverRender/renderToStream/template.js +4 -1
  238. package/dist/esm-node/ssr/serverRender/renderToString/buildHtml.js +12 -5
  239. package/dist/esm-node/ssr/serverRender/renderToString/entry.js +5 -3
  240. package/dist/esm-node/ssr/serverRender/renderToString/index.js +6 -3
  241. package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +33 -19
  242. package/dist/esm-node/ssr/serverRender/renderToString/render.js +4 -1
  243. package/dist/esm-node/ssr/serverRender/renderToString/styledComponent.js +4 -1
  244. package/dist/esm-node/ssr/serverRender/renderToString/type.js +4 -1
  245. package/dist/esm-node/ssr/serverRender/tracker.js +8 -3
  246. package/dist/esm-node/ssr/serverRender/types.js +3 -1
  247. package/dist/esm-node/ssr/serverRender/utils.js +12 -5
  248. package/dist/esm-node/ssr/utils.js +10 -4
  249. package/dist/esm-node/state/cli/index.js +6 -2
  250. package/dist/esm-node/state/index.js +6 -2
  251. package/dist/esm-node/state/plugins.js +10 -4
  252. package/dist/esm-node/state/runtime/index.js +4 -1
  253. package/dist/esm-node/state/runtime/plugin.js +4 -1
  254. package/dist/types/router/runtime/PrefetchLink.d.ts +1 -1
  255. package/dist/types/router/runtime/hooks.d.ts +1 -1
  256. package/dist/types/router/runtime/index.d.ts +3 -3
  257. package/dist/types/router/runtime/server.d.ts +1 -1
  258. package/dist/types/router/runtime/types.d.ts +2 -2
  259. package/dist/types/router/runtime/utils.d.ts +1 -1
  260. package/dist/types/router/runtime/withRouter.d.ts +1 -1
  261. package/dist/types/runtimeContext.d.ts +1 -1
  262. package/dist/types/ssr/serverRender/renderToString/loadable.d.ts +1 -0
  263. package/package.json +10 -11
  264. package/dist/cjs/state/types.js +0 -4
  265. package/dist/esm/state/types.js +0 -1
  266. package/dist/esm-node/state/types.js +0 -1
  267. package/dist/types/state/types.d.ts +0 -16
@@ -1 +1 @@
1
- export * from "@modern-js/utils/runtime-node/router";
1
+ export * from "@modern-js/runtime-utils/node/router";
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Route, isRouteErrorResponse } from "@modern-js/utils/runtime/router";
3
- import { ErrorResponse } from "@modern-js/utils/runtime/remix-router";
4
- import { renderNestedRoute } from "@modern-js/utils/runtime/nested-routes";
2
+ import { Route, isRouteErrorResponse } from "@modern-js/runtime-utils/router";
3
+ import { ErrorResponse } from "@modern-js/runtime-utils/remix-router";
4
+ import { renderNestedRoute } from "@modern-js/runtime-utils/browser";
5
5
  import { DefaultNotFound } from "./DefaultNotFound";
6
6
  import DeferredDataScripts from "./DeferredDataScripts";
7
- export function getRouteComponents(routes, { globalApp, ssrMode, props, reporter }) {
7
+ function getRouteComponents(routes, { globalApp, ssrMode, props, reporter }) {
8
8
  const Layout = ({ Component, ...props2 }) => {
9
9
  const GlobalLayout = globalApp;
10
10
  if (!GlobalLayout) {
@@ -42,7 +42,7 @@ export function getRouteComponents(routes, { globalApp, ssrMode, props, reporter
42
42
  }, "*"));
43
43
  return routeElements;
44
44
  }
45
- export function renderRoutes({ routesConfig, props, ssrMode, reporter }) {
45
+ function renderRoutes({ routesConfig, props, ssrMode, reporter }) {
46
46
  if (!routesConfig) {
47
47
  return null;
48
48
  }
@@ -58,22 +58,22 @@ export function renderRoutes({ routesConfig, props, ssrMode, reporter }) {
58
58
  });
59
59
  return routeElements;
60
60
  }
61
- export function getLocation(serverContext) {
62
- var _serverContext, _url_replace, _url;
63
- const { pathname, url } = ((_serverContext = serverContext) === null || _serverContext === void 0 ? void 0 : _serverContext.request) || {};
64
- const cleanUrl = (_url = url) === null || _url === void 0 ? void 0 : (_url_replace = _url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
61
+ function getLocation(serverContext) {
62
+ var _url_replace;
63
+ const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
64
+ const cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
65
65
  const index = (cleanUrl || "").indexOf(pathname);
66
66
  if (index === -1) {
67
67
  return pathname;
68
68
  }
69
69
  return cleanUrl.substring(index);
70
70
  }
71
- export const urlJoin = (...parts) => {
71
+ const urlJoin = (...parts) => {
72
72
  const separator = "/";
73
73
  const replace = new RegExp(`${separator}{1,}`, "g");
74
74
  return standardSlash(parts.join(separator).replace(replace, separator));
75
75
  };
76
- export function standardSlash(str) {
76
+ function standardSlash(str) {
77
77
  let addr = str;
78
78
  if (!addr || typeof addr !== "string") {
79
79
  return addr;
@@ -89,7 +89,7 @@ export function standardSlash(str) {
89
89
  }
90
90
  return addr;
91
91
  }
92
- export function serializeErrors(errors) {
92
+ function serializeErrors(errors) {
93
93
  if (!errors) {
94
94
  return null;
95
95
  }
@@ -113,7 +113,7 @@ export function serializeErrors(errors) {
113
113
  }
114
114
  return serialized;
115
115
  }
116
- export function deserializeErrors(errors) {
116
+ function deserializeErrors(errors) {
117
117
  if (!errors) {
118
118
  return null;
119
119
  }
@@ -132,3 +132,12 @@ export function deserializeErrors(errors) {
132
132
  }
133
133
  return serialized;
134
134
  }
135
+ export {
136
+ deserializeErrors,
137
+ getLocation,
138
+ getRouteComponents,
139
+ renderRoutes,
140
+ serializeErrors,
141
+ standardSlash,
142
+ urlJoin
143
+ };
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useLocation, useNavigate, useParams } from "@modern-js/utils/runtime/router";
3
- export const withRouter = (Component) => {
2
+ import { useLocation, useNavigate, useParams } from "@modern-js/runtime-utils/router";
3
+ const withRouter = (Component) => {
4
4
  return (props) => {
5
5
  const location = useLocation();
6
6
  const params = useParams();
@@ -13,3 +13,6 @@ export const withRouter = (Component) => {
13
13
  });
14
14
  };
15
15
  };
16
+ export {
17
+ withRouter
18
+ };
@@ -1,3 +1,7 @@
1
1
  import { createContext } from "react";
2
- export const RuntimeReactContext = createContext({});
3
- export const ServerRouterContext = createContext({});
2
+ const RuntimeReactContext = createContext({});
3
+ const ServerRouterContext = createContext({});
4
+ export {
5
+ RuntimeReactContext,
6
+ ServerRouterContext
7
+ };
@@ -1,110 +1,119 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
1
5
  import crypto from "crypto";
2
- import { Buffer } from "buffer";
6
+ import { Buffer as Buffer2 } from "buffer";
3
7
  import * as t from "@babel/types";
4
8
  import { get } from "@modern-js/utils/lodash";
5
- const RUNTIME_PACKAGE_NAMES = [
6
- "@modern-js/runtime"
7
- ];
8
- const FUNCTION_USE_LOADER_NAME = "useLoader";
9
- function getHash(filepath) {
10
- const cwd = process.cwd();
11
- const point = filepath.indexOf(cwd);
12
- let relativePath = filepath;
13
- if (point !== -1) {
14
- relativePath = filepath.substring(point + cwd.length);
15
- }
16
- const fileBuf = Buffer.from(relativePath);
17
- const fsHash = crypto.createHash("md5");
18
- const md5 = fsHash.update(fileBuf).digest("hex");
19
- return md5;
20
- }
21
- function getUseLoaderPath(path, calleeName) {
22
- const { node } = path;
23
- if (!calleeName || node.callee.name !== calleeName) {
24
- return false;
25
- }
26
- const arg1 = get(node, "arguments.0");
27
- if (t.isFunction(arg1) || t.isFunctionExpression(arg1) || t.isArrowFunctionExpression(arg1) || t.isIdentifier(arg1) || t.isCallExpression(arg1) || t.isMemberExpression(arg1)) {
28
- const loaderPath = path.get("arguments.0");
29
- if (isDuplicateInnerLoader(loaderPath)) {
30
- return false;
31
- } else {
32
- return loaderPath;
33
- }
34
- }
35
- console.warn("useLoader 中 loaderId 生成失败,请检查 useLoader");
36
- throw path.buildCodeFrameError(`
37
- please check the usage of ${path.node.name}
38
- `);
39
- }
40
- function isDuplicateInnerLoader(path) {
41
- const { node } = path;
42
- if (t.isFunctionExpression(node.callee)) {
43
- if (t.isBlockStatement(node.callee.body)) {
44
- if (get(node.callee.body, "body.0.declarations.0.id.name") === "innerLoader" && get(node.callee.body, "body.2.argument.name") === "innerLoader") {
45
- return true;
9
+ var require_babel_plugin_ssr_loader_id = __commonJS({
10
+ "src/ssr/cli/babel-plugin-ssr-loader-id.ts"(exports, module) {
11
+ const RUNTIME_PACKAGE_NAMES = [
12
+ "@modern-js/runtime"
13
+ ];
14
+ const FUNCTION_USE_LOADER_NAME = "useLoader";
15
+ function getHash(filepath) {
16
+ const cwd = process.cwd();
17
+ const point = filepath.indexOf(cwd);
18
+ let relativePath = filepath;
19
+ if (point !== -1) {
20
+ relativePath = filepath.substring(point + cwd.length);
46
21
  }
22
+ const fileBuf = Buffer2.from(relativePath);
23
+ const fsHash = crypto.createHash("md5");
24
+ const md5 = fsHash.update(fileBuf).digest("hex");
25
+ return md5;
47
26
  }
48
- }
49
- return false;
50
- }
51
- function getSelfRunLoaderExpression(loaderExpression, id) {
52
- return t.callExpression(t.functionExpression(null, [], t.blockStatement([
53
- t.variableDeclaration("var", [
54
- t.variableDeclarator(t.identifier("innerLoader"), loaderExpression)
55
- ]),
56
- t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("innerLoader"), t.identifier("id")), t.stringLiteral(id))),
57
- t.returnStatement(t.identifier("innerLoader"))
58
- ])), []);
59
- }
60
- module.exports = function() {
61
- let useLoader = null;
62
- let hash = "";
63
- let index = 0;
64
- function genId() {
65
- return `${hash}_${index++}`;
66
- }
67
- return {
68
- name: "babel-plugin-ssr-loader-id",
69
- pre() {
70
- index = 0;
71
- useLoader = null;
72
- hash = "";
73
- },
74
- visitor: {
75
- ImportDeclaration(path, state) {
76
- if (useLoader) {
77
- return false;
78
- }
79
- if (!RUNTIME_PACKAGE_NAMES.includes(get(path, "node.source.value"))) {
27
+ function getUseLoaderPath(path, calleeName) {
28
+ const { node } = path;
29
+ if (!calleeName || node.callee.name !== calleeName) {
30
+ return false;
31
+ }
32
+ const arg1 = get(node, "arguments.0");
33
+ if (t.isFunction(arg1) || t.isFunctionExpression(arg1) || t.isArrowFunctionExpression(arg1) || t.isIdentifier(arg1) || t.isCallExpression(arg1) || t.isMemberExpression(arg1)) {
34
+ const loaderPath = path.get("arguments.0");
35
+ if (isDuplicateInnerLoader(loaderPath)) {
80
36
  return false;
37
+ } else {
38
+ return loaderPath;
81
39
  }
82
- hash = getHash(state.file.opts.filename);
83
- get(path, "node.specifiers", []).forEach(({ imported, local }) => {
84
- if (!imported) {
85
- throw path.buildCodeFrameError(`please \`import { useLoader } from ${RUNTIME_PACKAGE_NAMES[0]}\``);
86
- }
87
- if (!useLoader && imported.name === FUNCTION_USE_LOADER_NAME) {
88
- useLoader = local.name;
89
- }
90
- });
91
- return false;
92
- },
93
- CallExpression(path) {
94
- let loaderPath = getUseLoaderPath(path, useLoader);
95
- if (loaderPath) {
96
- if (!Array.isArray(loaderPath)) {
97
- loaderPath = [
98
- loaderPath
99
- ];
40
+ }
41
+ console.warn("useLoader loaderId 生成失败,请检查 useLoader");
42
+ throw path.buildCodeFrameError(`
43
+ please check the usage of ${path.node.name}
44
+ `);
45
+ }
46
+ function isDuplicateInnerLoader(path) {
47
+ const { node } = path;
48
+ if (t.isFunctionExpression(node.callee)) {
49
+ if (t.isBlockStatement(node.callee.body)) {
50
+ if (get(node.callee.body, "body.0.declarations.0.id.name") === "innerLoader" && get(node.callee.body, "body.2.argument.name") === "innerLoader") {
51
+ return true;
100
52
  }
101
- loaderPath.forEach((p) => {
102
- p.replaceWith(getSelfRunLoaderExpression(p.node, genId()));
103
- });
104
- return false;
105
53
  }
106
- return false;
107
54
  }
55
+ return false;
108
56
  }
109
- };
110
- };
57
+ function getSelfRunLoaderExpression(loaderExpression, id) {
58
+ return t.callExpression(t.functionExpression(null, [], t.blockStatement([
59
+ t.variableDeclaration("var", [
60
+ t.variableDeclarator(t.identifier("innerLoader"), loaderExpression)
61
+ ]),
62
+ t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier("innerLoader"), t.identifier("id")), t.stringLiteral(id))),
63
+ t.returnStatement(t.identifier("innerLoader"))
64
+ ])), []);
65
+ }
66
+ module.exports = function() {
67
+ let useLoader = null;
68
+ let hash = "";
69
+ let index = 0;
70
+ function genId() {
71
+ return `${hash}_${index++}`;
72
+ }
73
+ return {
74
+ name: "babel-plugin-ssr-loader-id",
75
+ pre() {
76
+ index = 0;
77
+ useLoader = null;
78
+ hash = "";
79
+ },
80
+ visitor: {
81
+ ImportDeclaration(path, state) {
82
+ if (useLoader) {
83
+ return false;
84
+ }
85
+ if (!RUNTIME_PACKAGE_NAMES.includes(get(path, "node.source.value"))) {
86
+ return false;
87
+ }
88
+ hash = getHash(state.file.opts.filename);
89
+ get(path, "node.specifiers", []).forEach(({ imported, local }) => {
90
+ if (!imported) {
91
+ throw path.buildCodeFrameError(`please \`import { useLoader } from ${RUNTIME_PACKAGE_NAMES[0]}\``);
92
+ }
93
+ if (!useLoader && imported.name === FUNCTION_USE_LOADER_NAME) {
94
+ useLoader = local.name;
95
+ }
96
+ });
97
+ return false;
98
+ },
99
+ CallExpression(path) {
100
+ let loaderPath = getUseLoaderPath(path, useLoader);
101
+ if (loaderPath) {
102
+ if (!Array.isArray(loaderPath)) {
103
+ loaderPath = [
104
+ loaderPath
105
+ ];
106
+ }
107
+ loaderPath.forEach((p) => {
108
+ p.replaceWith(getSelfRunLoaderExpression(p.node, genId()));
109
+ });
110
+ return false;
111
+ }
112
+ return false;
113
+ }
114
+ }
115
+ };
116
+ };
117
+ }
118
+ });
119
+ export default require_babel_plugin_ssr_loader_id();
@@ -2,13 +2,12 @@ import path from "path";
2
2
  import { getEntryOptions, SERVER_RENDER_FUNCTION_NAME, LOADABLE_STATS_FILE, isUseSSRBundle, createRuntimeExportsUtils, isSSGEntry } from "@modern-js/utils";
3
3
  const PLUGIN_IDENTIFIER = "ssr";
4
4
  const hasStringSSREntry = (userConfig) => {
5
- var _server, _server1;
6
5
  const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
7
6
  const { server, output } = userConfig;
8
- if ((((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) || output.ssg) && !isStreaming(server.ssr)) {
7
+ if (((server === null || server === void 0 ? void 0 : server.ssr) || output.ssg) && !isStreaming(server.ssr)) {
9
8
  return true;
10
9
  }
11
- if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && typeof server.ssrByEntries === "object") {
10
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
12
11
  for (const name of Object.keys(server.ssrByEntries)) {
13
12
  if (!isStreaming(server.ssrByEntries[name])) {
14
13
  return true;
@@ -18,11 +17,10 @@ const hasStringSSREntry = (userConfig) => {
18
17
  return false;
19
18
  };
20
19
  const checkUseStringSSR = (config) => {
21
- var _output;
22
20
  const { output } = config;
23
- return Boolean((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) || hasStringSSREntry(config);
21
+ return Boolean(output === null || output === void 0 ? void 0 : output.ssg) || hasStringSSREntry(config);
24
22
  };
25
- export const ssrPlugin = () => ({
23
+ const ssrPlugin = () => ({
26
24
  name: "@modern-js/plugin-ssr",
27
25
  required: [
28
26
  "@modern-js/runtime"
@@ -63,8 +61,8 @@ export const ssrPlugin = () => ({
63
61
  return {
64
62
  source: {
65
63
  alias: {
66
- // ensure that all packages use the same storage in @modern-js/utils/runtime-node
67
- "@modern-js/utils/runtime-node$": require.resolve("@modern-js/utils/runtime-node"),
64
+ // ensure that all packages use the same storage in @modern-js/runtime-utils/node
65
+ "@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node"),
68
66
  "@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
69
67
  },
70
68
  globalVars: (values, { target }) => {
@@ -94,9 +92,9 @@ export const ssrPlugin = () => ({
94
92
  pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`);
95
93
  const ssrConfig = getEntryOptions(entryName, isMainEntry, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
96
94
  if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
97
- var _this, _runtimeConfig;
95
+ var _this;
98
96
  const runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
99
- if (((_this = (_runtimeConfig = runtimeConfig) === null || _runtimeConfig === void 0 ? void 0 : _runtimeConfig.router) === null || _this === void 0 ? void 0 : _this.mode) === "react-router-5") {
97
+ if (((_this = runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) === null || _this === void 0 ? void 0 : _this.mode) === "react-router-5") {
100
98
  throw new Error(`router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'`);
101
99
  }
102
100
  if (fileSystemRoutes && !entrypoint.nestedRoutesEntry) {
@@ -122,8 +120,8 @@ export const ssrPlugin = () => ({
122
120
  },
123
121
  modifyEntryRuntimePlugins({ entrypoint, plugins, bundlerConfigs }) {
124
122
  if (ssrConfigMap.get(entrypoint.entryName)) {
125
- var _bundlerConfigs_find_output, _bundlerConfigs_find, _bundlerConfigs, _config_server;
126
- const chunkLoadingGlobal = (_bundlerConfigs = bundlerConfigs) === null || _bundlerConfigs === void 0 ? void 0 : (_bundlerConfigs_find = _bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
123
+ var _bundlerConfigs_find_output, _bundlerConfigs_find, _config_server;
124
+ const chunkLoadingGlobal = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : (_bundlerConfigs_find = bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
127
125
  const config = api.useResolvedConfigContext();
128
126
  const { crossorigin, scriptLoading } = config.html;
129
127
  const disablePrerender = typeof ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr) === "object" ? Boolean(config.server.ssr.disablePrerender) : false;
@@ -163,4 +161,8 @@ export const ssrPlugin = () => ({
163
161
  };
164
162
  }
165
163
  });
166
- export default ssrPlugin;
164
+ var cli_default = ssrPlugin;
165
+ export {
166
+ cli_default as default,
167
+ ssrPlugin
168
+ };
@@ -1,91 +1,100 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
1
5
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
6
  import path from "path";
3
7
  import { fs } from "@modern-js/utils";
4
- class LoadablePlugin {
5
- apply(compiler) {
6
- this.compiler = compiler;
7
- compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
8
- if (this.opts.outputAsset || this.opts.writeToDisk) {
9
- compiler.hooks.make.tap(LoadablePlugin.name, (compilation) => {
10
- compilation.hooks.processAssets.tap({
11
- name: LoadablePlugin.name,
12
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
13
- }, () => {
14
- const asset = this.handleEmit(compilation);
15
- if (asset) {
16
- compilation.emitAsset(this.opts.filename, asset);
17
- }
8
+ var require_loadable_bundler_plugin = __commonJS({
9
+ "src/ssr/cli/loadable-bundler-plugin.ts"(exports, module) {
10
+ class LoadablePlugin {
11
+ apply(compiler) {
12
+ this.compiler = compiler;
13
+ compiler.options.output.chunkLoadingGlobal = this.opts.chunkLoadingGlobal;
14
+ if (this.opts.outputAsset || this.opts.writeToDisk) {
15
+ compiler.hooks.make.tap(LoadablePlugin.name, (compilation) => {
16
+ compilation.hooks.processAssets.tap({
17
+ name: LoadablePlugin.name,
18
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
19
+ }, () => {
20
+ const asset = this.handleEmit(compilation);
21
+ if (asset) {
22
+ compilation.emitAsset(this.opts.filename, asset);
23
+ }
24
+ });
25
+ });
26
+ }
27
+ }
28
+ handleEmit(compilation) {
29
+ const stats = compilation.getStats().toJson({
30
+ all: false,
31
+ assets: true,
32
+ // rspack not support cachedAssets,
33
+ cachedAssets: true,
34
+ chunks: true,
35
+ chunkGroups: true,
36
+ entrypoints: true,
37
+ // rspack not support chunkGroupChildren.
38
+ chunkGroupChildren: true,
39
+ hash: true,
40
+ ids: true,
41
+ outputPath: true,
42
+ publicPath: true
18
43
  });
19
- });
20
- }
21
- }
22
- handleEmit(compilation) {
23
- const stats = compilation.getStats().toJson({
24
- all: false,
25
- assets: true,
26
- // rspack not support cachedAssets,
27
- cachedAssets: true,
28
- chunks: true,
29
- chunkGroups: true,
30
- entrypoints: true,
31
- // rspack not support chunkGroupChildren.
32
- chunkGroupChildren: true,
33
- hash: true,
34
- ids: true,
35
- outputPath: true,
36
- publicPath: true
37
- });
38
- const output = {
39
- ...stats,
40
- generator: "loadable-components",
41
- chunks: [
42
- ...stats.chunks || []
43
- ].map((chunk) => {
44
- return {
45
- id: chunk.id,
46
- files: [
47
- ...chunk.files || []
48
- ]
44
+ const output = {
45
+ ...stats,
46
+ generator: "loadable-components",
47
+ chunks: [
48
+ ...stats.chunks || []
49
+ ].map((chunk) => {
50
+ return {
51
+ id: chunk.id,
52
+ files: [
53
+ ...chunk.files || []
54
+ ]
55
+ };
56
+ })
49
57
  };
50
- })
51
- };
52
- const result = JSON.stringify(output, null, 2);
53
- if (this.opts.writeToDisk) {
54
- this.writeAssetsFile(result);
55
- }
56
- if (this.opts.outputAsset) {
57
- return {
58
- source() {
59
- return result;
60
- },
61
- size() {
62
- return result.length;
58
+ const result = JSON.stringify(output, null, 2);
59
+ if (this.opts.writeToDisk) {
60
+ this.writeAssetsFile(result);
63
61
  }
64
- };
62
+ if (this.opts.outputAsset) {
63
+ return {
64
+ source() {
65
+ return result;
66
+ },
67
+ size() {
68
+ return result.length;
69
+ }
70
+ };
71
+ }
72
+ return null;
73
+ }
74
+ writeAssetsFile(manifest) {
75
+ var _this_compiler;
76
+ const outputFolder = (_this_compiler = this.compiler) === null || _this_compiler === void 0 ? void 0 : _this_compiler.options.output.path;
77
+ const outputFile = path.resolve(outputFolder || "", this.opts.filename);
78
+ fs.outputFileSync(outputFile, manifest);
79
+ }
80
+ constructor({ filename = "loadable-stats.json", path: path2, writeToDisk, outputAsset = true, chunkLoadingGlobal = "__LOADABLE_LOADED_CHUNKS__" } = {
81
+ filename: "loadable-stats.json",
82
+ outputAsset: true,
83
+ chunkLoadingGlobal: "__LOADABLE_LOADED_CHUNKS__"
84
+ }) {
85
+ _define_property(this, "opts", void 0);
86
+ _define_property(this, "compiler", void 0);
87
+ this.opts = {
88
+ filename,
89
+ path: path2,
90
+ writeToDisk,
91
+ outputAsset,
92
+ chunkLoadingGlobal
93
+ };
94
+ this.compiler = null;
95
+ }
65
96
  }
66
- return null;
67
- }
68
- writeAssetsFile(manifest) {
69
- var _this_compiler;
70
- const outputFolder = (_this_compiler = this.compiler) === null || _this_compiler === void 0 ? void 0 : _this_compiler.options.output.path;
71
- const outputFile = path.resolve(outputFolder || "", this.opts.filename);
72
- fs.outputFileSync(outputFile, manifest);
73
- }
74
- constructor({ filename = "loadable-stats.json", path: path2, writeToDisk, outputAsset = true, chunkLoadingGlobal = "__LOADABLE_LOADED_CHUNKS__" } = {
75
- filename: "loadable-stats.json",
76
- outputAsset: true,
77
- chunkLoadingGlobal: "__LOADABLE_LOADED_CHUNKS__"
78
- }) {
79
- _define_property(this, "opts", void 0);
80
- _define_property(this, "compiler", void 0);
81
- this.opts = {
82
- filename,
83
- path: path2,
84
- writeToDisk,
85
- outputAsset,
86
- chunkLoadingGlobal
87
- };
88
- this.compiler = null;
97
+ module.exports = LoadablePlugin;
89
98
  }
90
- }
91
- module.exports = LoadablePlugin;
99
+ });
100
+ export default require_loadable_bundler_plugin();
@@ -1,12 +1,12 @@
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-browser";
4
+ import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
5
5
  import { RenderLevel } from "./serverRender/types";
6
6
  import { WithCallback } from "./react/withCallback";
7
7
  import { formatClient, mockResponse, isReact18 } from "./utils";
8
8
  import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "./serverRender/utils";
9
- export const ssr = (config) => ({
9
+ const ssr = (config) => ({
10
10
  name: "@modern-js/plugin-ssr",
11
11
  setup: () => {
12
12
  const mockResp = mockResponse();
@@ -128,5 +128,9 @@ export const ssr = (config) => ({
128
128
  };
129
129
  }
130
130
  });
131
- export default ssr;
131
+ var ssr_default = ssr;
132
132
  export * from "./react";
133
+ export {
134
+ ssr_default as default,
135
+ ssr
136
+ };
@@ -1,7 +1,7 @@
1
1
  import { formatServer } from "./utils";
2
2
  import render from "./serverRender";
3
3
  import { createSSRTracker } from "./serverRender/tracker";
4
- export const ssr = (config = {}) => ({
4
+ const ssr = (config = {}) => ({
5
5
  name: "@modern-js/plugin-ssr",
6
6
  setup: () => {
7
7
  return {
@@ -26,8 +26,7 @@ export const ssr = (config = {}) => ({
26
26
  });
27
27
  },
28
28
  pickContext: ({ context, pickedContext }, next) => {
29
- var _context;
30
- const { request, response } = (_context = context) === null || _context === void 0 ? void 0 : _context.ssrContext;
29
+ const { request, response } = context === null || context === void 0 ? void 0 : context.ssrContext;
31
30
  const { initialData } = context;
32
31
  return next({
33
32
  context,
@@ -42,5 +41,9 @@ export const ssr = (config = {}) => ({
42
41
  };
43
42
  }
44
43
  });
45
- export default ssr;
44
+ var index_node_default = ssr;
46
45
  export * from "./react";
46
+ export {
47
+ index_node_default as default,
48
+ ssr
49
+ };