@modern-js/runtime 3.9.0 → 3.9.2

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 (77) hide show
  1. package/dist/cjs/cli/template.server.js +1 -2
  2. package/dist/cjs/core/browser/hydrate.js +13 -11
  3. package/dist/cjs/core/server/stream/beforeTemplate.js +3 -3
  4. package/dist/cjs/core/server/string/loadable.js +4 -4
  5. package/dist/cjs/router/cli/code/nestedRoutes.js +1 -2
  6. package/dist/cjs/router/cli/code/templates.js +1 -1
  7. package/dist/cjs/router/cli/code/utils.js +2 -2
  8. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +10 -9
  9. package/dist/cjs/router/runtime/plugin.node.js +2 -3
  10. package/dist/esm/cli/template.server.mjs +1 -2
  11. package/dist/esm/core/browser/hydrate.mjs +13 -11
  12. package/dist/esm/core/server/stream/beforeTemplate.mjs +3 -3
  13. package/dist/esm/core/server/string/loadable.mjs +4 -4
  14. package/dist/esm/router/cli/code/nestedRoutes.mjs +1 -2
  15. package/dist/esm/router/cli/code/templates.mjs +1 -1
  16. package/dist/esm/router/cli/code/utils.mjs +2 -2
  17. package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +10 -9
  18. package/dist/esm/router/runtime/plugin.node.mjs +2 -3
  19. package/dist/esm-node/cli/template.server.mjs +1 -2
  20. package/dist/esm-node/core/browser/hydrate.mjs +13 -11
  21. package/dist/esm-node/core/server/stream/beforeTemplate.mjs +3 -3
  22. package/dist/esm-node/core/server/string/loadable.mjs +4 -4
  23. package/dist/esm-node/router/cli/code/nestedRoutes.mjs +1 -2
  24. package/dist/esm-node/router/cli/code/templates.mjs +1 -1
  25. package/dist/esm-node/router/cli/code/utils.mjs +2 -2
  26. package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +10 -9
  27. package/dist/esm-node/router/runtime/plugin.node.mjs +2 -3
  28. package/dist/types/cli/index.d.ts +4 -4
  29. package/dist/types/common.d.ts +1 -1
  30. package/dist/types/core/browser/hydrate.d.ts +1 -1
  31. package/dist/types/core/browser/index.d.ts +1 -1
  32. package/dist/types/core/compat/hooks.d.ts +1 -1
  33. package/dist/types/core/compat/index.d.ts +1 -1
  34. package/dist/types/core/compat/requestContext.d.ts +3 -3
  35. package/dist/types/core/config.d.ts +1 -1
  36. package/dist/types/core/context/index.d.ts +6 -6
  37. package/dist/types/core/context/runtime.d.ts +2 -2
  38. package/dist/types/core/context/serverPayload/index.d.ts +1 -1
  39. package/dist/types/core/index.d.ts +5 -5
  40. package/dist/types/core/plugin/index.d.ts +1 -1
  41. package/dist/types/core/plugin/types.d.ts +2 -2
  42. package/dist/types/core/react/wrapper.d.ts +1 -1
  43. package/dist/types/core/server/index.d.ts +2 -2
  44. package/dist/types/core/server/react/index.d.ts +2 -2
  45. package/dist/types/core/server/requestHandler.d.ts +1 -1
  46. package/dist/types/core/server/server.d.ts +4 -4
  47. package/dist/types/core/server/shared.d.ts +1 -1
  48. package/dist/types/core/server/stream/afterTemplate.d.ts +4 -4
  49. package/dist/types/core/server/stream/beforeTemplate.d.ts +2 -2
  50. package/dist/types/core/server/stream/createReadableStream.d.ts +1 -1
  51. package/dist/types/core/server/stream/createReadableStream.worker.d.ts +1 -1
  52. package/dist/types/core/server/stream/index.d.ts +1 -1
  53. package/dist/types/core/server/stream/shared.d.ts +3 -3
  54. package/dist/types/core/server/stream/template.d.ts +2 -2
  55. package/dist/types/core/server/string/index.d.ts +1 -1
  56. package/dist/types/core/server/string/loadable.d.ts +1 -1
  57. package/dist/types/core/server/string/ssrData.d.ts +4 -4
  58. package/dist/types/core/server/string/types.d.ts +1 -1
  59. package/dist/types/core/server/utils.d.ts +1 -1
  60. package/dist/types/core/types.d.ts +1 -1
  61. package/dist/types/document/index.d.ts +12 -12
  62. package/dist/types/exports/config-routes.d.ts +1 -1
  63. package/dist/types/index.d.ts +9 -9
  64. package/dist/types/internal.d.ts +2 -2
  65. package/dist/types/react-server.d.ts +3 -3
  66. package/dist/types/router/cli/code/getClientRoutes/index.d.ts +1 -1
  67. package/dist/types/router/cli/index.d.ts +2 -2
  68. package/dist/types/router/index.d.ts +1 -1
  69. package/dist/types/router/internal.d.ts +2 -2
  70. package/dist/types/router/runtime/hooks.d.ts +1 -1
  71. package/dist/types/router/runtime/index.d.ts +4 -4
  72. package/dist/types/router/runtime/internal.d.ts +5 -5
  73. package/dist/types/router/runtime/plugin.d.ts +3 -3
  74. package/dist/types/router/runtime/plugin.node.d.ts +3 -3
  75. package/dist/types/router/runtime/rsc-router.d.ts +2 -2
  76. package/dist/types/router/runtime/utils.d.ts +1 -1
  77. package/package.json +10 -10
@@ -141,8 +141,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
141
141
  return `
142
142
  export * from '${realEntryPath}';
143
143
  export { default as requestHandler } from '${realEntryPath}'`;
144
- }
145
- {
144
+ } else {
146
145
  const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
147
146
  const serverEntry = transformServerEntry(entrySource, {
148
147
  metaName: metaName || 'modern-js',
@@ -59,7 +59,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
59
59
  if ('stream' === renderMode) return streamSSRHydrate();
60
60
  function streamSSRHydrate() {
61
61
  if (renderLevel !== external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
62
- {
62
+ else {
63
63
  const SSRApp = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_withCallback_js_namespaceObject.WithCallback, {
64
64
  callback: callback,
65
65
  children: App
@@ -70,19 +70,21 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
70
70
  return stringSSRHydrate();
71
71
  function stringSSRHydrate() {
72
72
  if (renderLevel === external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER) return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
73
- if (renderLevel === external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
74
- (0, component_namespaceObject.loadableReady)(()=>{
75
- const SSRApp = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_withCallback_js_namespaceObject.WithCallback, {
76
- callback: callback,
77
- children: App
73
+ else {
74
+ if (renderLevel === external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
75
+ (0, component_namespaceObject.loadableReady)(()=>{
76
+ const SSRApp = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_withCallback_js_namespaceObject.WithCallback, {
77
+ callback: callback,
78
+ children: App
79
+ });
80
+ ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SSRApp, {}), hydrateContext)).then((root)=>{
81
+ resolve(root);
78
82
  });
79
- ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SSRApp, {}), hydrateContext)).then((root)=>{
80
- resolve(root);
81
83
  });
82
84
  });
83
- });
84
- console.warn(`unknow render level: ${renderLevel}, execute render()`);
85
- return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
85
+ console.warn(`unknow render level: ${renderLevel}, execute render()`);
86
+ return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
87
+ }
86
88
  }
87
89
  }
88
90
  exports.hydrateRoot = __webpack_exports__.hydrateRoot;
@@ -54,8 +54,8 @@ const readAsset = async (chunk)=>{
54
54
  };
55
55
  const checkIsInline = (chunk, enableInline)=>{
56
56
  if ('production' !== process.env.NODE_ENV) return false;
57
- if (enableInline instanceof RegExp) return enableInline.test(chunk);
58
- return Boolean(enableInline);
57
+ else if (enableInline instanceof RegExp) return enableInline.test(chunk);
58
+ else return Boolean(enableInline);
59
59
  };
60
60
  async function buildShellBeforeTemplate(beforeAppTemplate, options) {
61
61
  const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
@@ -96,7 +96,7 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
96
96
  const styles = await Promise.all(cssChunks.map(async (chunk)=>{
97
97
  const link = `<link href="${chunk}" rel="stylesheet" />`;
98
98
  if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
99
- return link;
99
+ else return link;
100
100
  }));
101
101
  return `${styles.join('')}`;
102
102
  }
@@ -39,8 +39,8 @@ const extname = (uri)=>{
39
39
  const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
40
40
  const checkIsInline = (chunk, enableInline)=>{
41
41
  if ('production' !== process.env.NODE_ENV) return false;
42
- if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
43
- return Boolean(enableInline);
42
+ else if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
43
+ else return Boolean(enableInline);
44
44
  };
45
45
  const readAsset = async (chunk)=>{
46
46
  const fs = await import("fs/promises");
@@ -108,7 +108,7 @@ class LoadableCollector {
108
108
  const scripts = await Promise.all(chunks.filter((chunk)=>!existedScript.includes(chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
109
109
  const script = `<script${attributes} src="${chunk.url}"></script>`;
110
110
  if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<script>${content}</script>`).catch((_)=>script);
111
- return script;
111
+ else return script;
112
112
  }));
113
113
  chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
114
114
  }
@@ -119,7 +119,7 @@ class LoadableCollector {
119
119
  const css = await Promise.all(chunks.filter((chunk)=>!(0, external_utils_js_namespaceObject.hasStylesheetLink)(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
120
120
  const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
121
121
  if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
122
- return link;
122
+ else return link;
123
123
  }));
124
124
  chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
125
125
  }
@@ -76,8 +76,7 @@ const optimizeRoute = (routeTree)=>{
76
76
  children: optimizedChildren
77
77
  }
78
78
  ];
79
- }
80
- {
79
+ } else {
81
80
  const newRoutes = children.map((child)=>{
82
81
  const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ''}` : child.path || '';
83
82
  const newRoute = {
@@ -419,7 +419,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
419
419
  enableRsc: true,
420
420
  });
421
421
  `;
422
- return `${imports.join('\n')}
422
+ else return `${imports.join('\n')}
423
423
 
424
424
  import { routes } from './routes';
425
425
 
@@ -61,7 +61,7 @@ const walkDirectory = (dir)=>external_fs_default().readdirSync(dir).reduce((prev
61
61
  ...previous,
62
62
  ...walkDirectory(filePath)
63
63
  ];
64
- return [
64
+ else return [
65
65
  ...previous,
66
66
  filePath
67
67
  ];
@@ -78,7 +78,7 @@ const isPageComponentFile = (filePath)=>{
78
78
  };
79
79
  const replaceWithAlias = (base, filePath, alias)=>{
80
80
  if (filePath.includes(base)) return (0, utils_namespaceObject.normalizeToPosixPath)(external_path_default().join(alias, external_path_default().relative(base, filePath)));
81
- return filePath;
81
+ else return filePath;
82
82
  };
83
83
  const parseModule = async ({ source, filename })=>{
84
84
  let content = source;
@@ -68,7 +68,7 @@ const DeferredDataScripts = (props)=>{
68
68
  (0, node_namespaceObject.serializeJson)(key)
69
69
  ]
70
70
  };
71
- {
71
+ else {
72
72
  const trackedPromise = deferredData.data[key];
73
73
  if (void 0 !== trackedPromise._error) {
74
74
  const error = {
@@ -83,15 +83,16 @@ const DeferredDataScripts = (props)=>{
83
83
  (0, node_namespaceObject.serializeJson)(error)
84
84
  ]
85
85
  };
86
+ } else {
87
+ if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
88
+ return {
89
+ key,
90
+ routerDataFnName: 'p',
91
+ routerDataFnArgs: [
92
+ (0, node_namespaceObject.serializeJson)(trackedPromise._data)
93
+ ]
94
+ };
86
95
  }
87
- if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
88
- return {
89
- key,
90
- routerDataFnName: 'p',
91
- routerDataFnArgs: [
92
- (0, node_namespaceObject.serializeJson)(trackedPromise._data)
93
- ]
94
- };
95
96
  }
96
97
  });
97
98
  return {
@@ -57,11 +57,10 @@ const external_utils_js_namespaceObject = require("./utils.js");
57
57
  function createRemixRequest(request) {
58
58
  const method = 'GET';
59
59
  const { headers } = request;
60
- const controller = new AbortController();
61
60
  return new Request(request.url, {
62
61
  method,
63
62
  headers,
64
- signal: controller.signal
63
+ signal: request.signal
65
64
  });
66
65
  }
67
66
  const routerPlugin = (userConfig = {})=>({
@@ -150,7 +149,7 @@ const routerPlugin = (userConfig = {})=>({
150
149
  }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_rsc_router_js_namespaceObject.RSCStaticRouter, {
151
150
  basename: basename
152
151
  });
153
- {
152
+ else {
154
153
  const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
155
154
  children: [
156
155
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(router_namespaceObject.StaticRouterProvider, {
@@ -108,8 +108,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
108
108
  return `
109
109
  export * from '${realEntryPath}';
110
110
  export { default as requestHandler } from '${realEntryPath}'`;
111
- }
112
- {
111
+ } else {
113
112
  const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
114
113
  const serverEntry = transformServerEntry(entrySource, {
115
114
  metaName: metaName || 'modern-js',
@@ -26,7 +26,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
26
26
  if ('stream' === renderMode) return streamSSRHydrate();
27
27
  function streamSSRHydrate() {
28
28
  if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
29
- {
29
+ else {
30
30
  const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
31
31
  callback: callback,
32
32
  children: App
@@ -37,19 +37,21 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
37
37
  return stringSSRHydrate();
38
38
  function stringSSRHydrate() {
39
39
  if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
40
- if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
41
- loadableReady(()=>{
42
- const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
43
- callback: callback,
44
- children: App
40
+ else {
41
+ if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
42
+ loadableReady(()=>{
43
+ const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
44
+ callback: callback,
45
+ children: App
46
+ });
47
+ ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
48
+ resolve(root);
45
49
  });
46
- ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
47
- resolve(root);
48
50
  });
49
51
  });
50
- });
51
- console.warn(`unknow render level: ${renderLevel}, execute render()`);
52
- return ModernRender(wrapRuntimeContextProvider(App, context));
52
+ console.warn(`unknow render level: ${renderLevel}, execute render()`);
53
+ return ModernRender(wrapRuntimeContextProvider(App, context));
54
+ }
53
55
  }
54
56
  }
55
57
  export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot };
@@ -12,8 +12,8 @@ const readAsset = async (chunk)=>{
12
12
  };
13
13
  const checkIsInline = (chunk, enableInline)=>{
14
14
  if ('production' !== process.env.NODE_ENV) return false;
15
- if (enableInline instanceof RegExp) return enableInline.test(chunk);
16
- return Boolean(enableInline);
15
+ else if (enableInline instanceof RegExp) return enableInline.test(chunk);
16
+ else return Boolean(enableInline);
17
17
  };
18
18
  async function buildShellBeforeTemplate(beforeAppTemplate, options) {
19
19
  const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
@@ -54,7 +54,7 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
54
54
  const styles = await Promise.all(cssChunks.map(async (chunk)=>{
55
55
  const link = `<link href="${chunk}" rel="stylesheet" />`;
56
56
  if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
57
- return link;
57
+ else return link;
58
58
  }));
59
59
  return `${styles.join('')}`;
60
60
  }
@@ -7,8 +7,8 @@ const extname = (uri)=>{
7
7
  const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
8
8
  const checkIsInline = (chunk, enableInline)=>{
9
9
  if ('production' !== process.env.NODE_ENV) return false;
10
- if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
11
- return Boolean(enableInline);
10
+ else if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
11
+ else return Boolean(enableInline);
12
12
  };
13
13
  const readAsset = async (chunk)=>{
14
14
  const fs = await import("fs/promises");
@@ -76,7 +76,7 @@ class LoadableCollector {
76
76
  const scripts = await Promise.all(chunks.filter((chunk)=>!existedScript.includes(chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
77
77
  const script = `<script${attributes} src="${chunk.url}"></script>`;
78
78
  if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<script>${content}</script>`).catch((_)=>script);
79
- return script;
79
+ else return script;
80
80
  }));
81
81
  chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
82
82
  }
@@ -87,7 +87,7 @@ class LoadableCollector {
87
87
  const css = await Promise.all(chunks.filter((chunk)=>!hasStylesheetLink(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
88
88
  const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
89
89
  if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
90
- return link;
90
+ else return link;
91
91
  }));
92
92
  chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
93
93
  }
@@ -42,8 +42,7 @@ const optimizeRoute = (routeTree)=>{
42
42
  children: optimizedChildren
43
43
  }
44
44
  ];
45
- }
46
- {
45
+ } else {
47
46
  const newRoutes = children.map((child)=>{
48
47
  const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ''}` : child.path || '';
49
48
  const newRoute = {
@@ -374,7 +374,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
374
374
  enableRsc: true,
375
375
  });
376
376
  `;
377
- return `${imports.join('\n')}
377
+ else return `${imports.join('\n')}
378
378
 
379
379
  import { routes } from './routes';
380
380
 
@@ -10,7 +10,7 @@ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
10
10
  ...previous,
11
11
  ...walkDirectory(filePath)
12
12
  ];
13
- return [
13
+ else return [
14
14
  ...previous,
15
15
  filePath
16
16
  ];
@@ -27,7 +27,7 @@ const isPageComponentFile = (filePath)=>{
27
27
  };
28
28
  const replaceWithAlias = (base, filePath, alias)=>{
29
29
  if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
30
- return filePath;
30
+ else return filePath;
31
31
  };
32
32
  const parseModule = async ({ source, filename })=>{
33
33
  let content = source;
@@ -36,7 +36,7 @@ const DeferredDataScripts = (props)=>{
36
36
  serializeJson(key)
37
37
  ]
38
38
  };
39
- {
39
+ else {
40
40
  const trackedPromise = deferredData.data[key];
41
41
  if (void 0 !== trackedPromise._error) {
42
42
  const error = {
@@ -51,15 +51,16 @@ const DeferredDataScripts = (props)=>{
51
51
  serializeJson(error)
52
52
  ]
53
53
  };
54
+ } else {
55
+ if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
56
+ return {
57
+ key,
58
+ routerDataFnName: 'p',
59
+ routerDataFnArgs: [
60
+ serializeJson(trackedPromise._data)
61
+ ]
62
+ };
54
63
  }
55
- if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
56
- return {
57
- key,
58
- routerDataFnName: 'p',
59
- routerDataFnArgs: [
60
- serializeJson(trackedPromise._data)
61
- ]
62
- };
63
64
  }
64
65
  });
65
66
  return {
@@ -14,11 +14,10 @@ import { createRouteObjectsFromConfig, renderRoutes, urlJoin } from "./utils.mjs
14
14
  function createRemixRequest(request) {
15
15
  const method = 'GET';
16
16
  const { headers } = request;
17
- const controller = new AbortController();
18
17
  return new Request(request.url, {
19
18
  method,
20
19
  headers,
21
- signal: controller.signal
20
+ signal: request.signal
22
21
  });
23
22
  }
24
23
  const routerPlugin = (userConfig = {})=>({
@@ -107,7 +106,7 @@ const routerPlugin = (userConfig = {})=>({
107
106
  }) : /*#__PURE__*/ jsx(RSCStaticRouter, {
108
107
  basename: basename
109
108
  });
110
- {
109
+ else {
111
110
  const routerWrapper = /*#__PURE__*/ jsxs(Fragment, {
112
111
  children: [
113
112
  /*#__PURE__*/ jsx(StaticRouterProvider, {
@@ -109,8 +109,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
109
109
  return `
110
110
  export * from '${realEntryPath}';
111
111
  export { default as requestHandler } from '${realEntryPath}'`;
112
- }
113
- {
112
+ } else {
114
113
  const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
115
114
  const serverEntry = transformServerEntry(entrySource, {
116
115
  metaName: metaName || 'modern-js',
@@ -27,7 +27,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
27
27
  if ('stream' === renderMode) return streamSSRHydrate();
28
28
  function streamSSRHydrate() {
29
29
  if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
30
- {
30
+ else {
31
31
  const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
32
32
  callback: callback,
33
33
  children: App
@@ -38,19 +38,21 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
38
38
  return stringSSRHydrate();
39
39
  function stringSSRHydrate() {
40
40
  if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
41
- if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
42
- loadableReady(()=>{
43
- const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
44
- callback: callback,
45
- children: App
41
+ else {
42
+ if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
43
+ loadableReady(()=>{
44
+ const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
45
+ callback: callback,
46
+ children: App
47
+ });
48
+ ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
49
+ resolve(root);
46
50
  });
47
- ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
48
- resolve(root);
49
51
  });
50
52
  });
51
- });
52
- console.warn(`unknow render level: ${renderLevel}, execute render()`);
53
- return ModernRender(wrapRuntimeContextProvider(App, context));
53
+ console.warn(`unknow render level: ${renderLevel}, execute render()`);
54
+ return ModernRender(wrapRuntimeContextProvider(App, context));
55
+ }
54
56
  }
55
57
  }
56
58
  export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot };
@@ -16,8 +16,8 @@ const readAsset = async (chunk)=>{
16
16
  };
17
17
  const checkIsInline = (chunk, enableInline)=>{
18
18
  if ('production' !== process.env.NODE_ENV) return false;
19
- if (enableInline instanceof RegExp) return enableInline.test(chunk);
20
- return Boolean(enableInline);
19
+ else if (enableInline instanceof RegExp) return enableInline.test(chunk);
20
+ else return Boolean(enableInline);
21
21
  };
22
22
  async function buildShellBeforeTemplate(beforeAppTemplate, options) {
23
23
  const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
@@ -58,7 +58,7 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
58
58
  const styles = await Promise.all(cssChunks.map(async (chunk)=>{
59
59
  const link = `<link href="${chunk}" rel="stylesheet" />`;
60
60
  if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
61
- return link;
61
+ else return link;
62
62
  }));
63
63
  return `${styles.join('')}`;
64
64
  }
@@ -11,8 +11,8 @@ const extname = (uri)=>{
11
11
  const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
12
12
  const checkIsInline = (chunk, enableInline)=>{
13
13
  if ('production' !== process.env.NODE_ENV) return false;
14
- if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
15
- return Boolean(enableInline);
14
+ else if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
15
+ else return Boolean(enableInline);
16
16
  };
17
17
  const readAsset = async (chunk)=>{
18
18
  const fs = await import("fs/promises");
@@ -80,7 +80,7 @@ class LoadableCollector {
80
80
  const scripts = await Promise.all(chunks.filter((chunk)=>!existedScript.includes(chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
81
81
  const script = `<script${attributes} src="${chunk.url}"></script>`;
82
82
  if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<script>${content}</script>`).catch((_)=>script);
83
- return script;
83
+ else return script;
84
84
  }));
85
85
  chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
86
86
  }
@@ -91,7 +91,7 @@ class LoadableCollector {
91
91
  const css = await Promise.all(chunks.filter((chunk)=>!hasStylesheetLink(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
92
92
  const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
93
93
  if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
94
- return link;
94
+ else return link;
95
95
  }));
96
96
  chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
97
97
  }
@@ -43,8 +43,7 @@ const optimizeRoute = (routeTree)=>{
43
43
  children: optimizedChildren
44
44
  }
45
45
  ];
46
- }
47
- {
46
+ } else {
48
47
  const newRoutes = children.map((child)=>{
49
48
  const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ''}` : child.path || '';
50
49
  const newRoute = {
@@ -376,7 +376,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
376
376
  enableRsc: true,
377
377
  });
378
378
  `;
379
- return `${imports.join('\n')}
379
+ else return `${imports.join('\n')}
380
380
 
381
381
  import { routes } from './routes';
382
382
 
@@ -11,7 +11,7 @@ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
11
11
  ...previous,
12
12
  ...walkDirectory(filePath)
13
13
  ];
14
- return [
14
+ else return [
15
15
  ...previous,
16
16
  filePath
17
17
  ];
@@ -28,7 +28,7 @@ const isPageComponentFile = (filePath)=>{
28
28
  };
29
29
  const replaceWithAlias = (base, filePath, alias)=>{
30
30
  if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
31
- return filePath;
31
+ else return filePath;
32
32
  };
33
33
  const parseModule = async ({ source, filename })=>{
34
34
  let content = source;
@@ -37,7 +37,7 @@ const DeferredDataScripts = (props)=>{
37
37
  serializeJson(key)
38
38
  ]
39
39
  };
40
- {
40
+ else {
41
41
  const trackedPromise = deferredData.data[key];
42
42
  if (void 0 !== trackedPromise._error) {
43
43
  const error = {
@@ -52,15 +52,16 @@ const DeferredDataScripts = (props)=>{
52
52
  serializeJson(error)
53
53
  ]
54
54
  };
55
+ } else {
56
+ if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
57
+ return {
58
+ key,
59
+ routerDataFnName: 'p',
60
+ routerDataFnArgs: [
61
+ serializeJson(trackedPromise._data)
62
+ ]
63
+ };
55
64
  }
56
- if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
57
- return {
58
- key,
59
- routerDataFnName: 'p',
60
- routerDataFnArgs: [
61
- serializeJson(trackedPromise._data)
62
- ]
63
- };
64
65
  }
65
66
  });
66
67
  return {
@@ -15,11 +15,10 @@ import { createRouteObjectsFromConfig, renderRoutes, urlJoin } from "./utils.mjs
15
15
  function createRemixRequest(request) {
16
16
  const method = 'GET';
17
17
  const { headers } = request;
18
- const controller = new AbortController();
19
18
  return new Request(request.url, {
20
19
  method,
21
20
  headers,
22
- signal: controller.signal
21
+ signal: request.signal
23
22
  });
24
23
  }
25
24
  const routerPlugin = (userConfig = {})=>({
@@ -108,7 +107,7 @@ const routerPlugin = (userConfig = {})=>({
108
107
  }) : /*#__PURE__*/ jsx(RSCStaticRouter, {
109
108
  basename: basename
110
109
  });
111
- {
110
+ else {
112
111
  const routerWrapper = /*#__PURE__*/ jsxs(Fragment, {
113
112
  children: [
114
113
  /*#__PURE__*/ jsx(StaticRouterProvider, {
@@ -1,8 +1,8 @@
1
1
  import type { AppTools, CliPlugin } from '@modern-js/app-tools';
2
- import { documentPlugin } from '../document/cli';
3
- import { routerPlugin } from '../router/cli';
4
- import { ssrPlugin } from './ssr';
5
- export { isRuntimeEntry } from './entry';
2
+ import { documentPlugin } from '../document/cli/index.js';
3
+ import { routerPlugin } from '../router/cli/index.js';
4
+ import { ssrPlugin } from './ssr/index.js';
5
+ export { isRuntimeEntry } from './entry.js';
6
6
  export { ssrPlugin, routerPlugin, documentPlugin };
7
7
  export declare const runtimePlugin: (params?: {
8
8
  plugins?: CliPlugin<AppTools>[];
@@ -1,4 +1,4 @@
1
- import type { RuntimePlugin } from './core/plugin';
1
+ import type { RuntimePlugin } from './core/plugin/index.js';
2
2
  export declare const isBrowser: () => boolean;
3
3
  export interface RuntimeConfig {
4
4
  plugins?: RuntimePlugin[];
@@ -1,5 +1,5 @@
1
1
  import type React from 'react';
2
2
  import { type Root } from 'react-dom/client';
3
- import type { TRuntimeContext } from '../context/runtime';
3
+ import type { TRuntimeContext } from '../context/runtime.js';
4
4
  export declare function hydrateWithReact(App: React.ReactElement, rootElement: HTMLElement): Promise<Root>;
5
5
  export declare function hydrateRoot(App: React.ReactElement, context: TRuntimeContext, ModernRender: (App: React.ReactElement) => Promise<HTMLElement | Root>, ModernHydrate: (App: React.ReactElement) => Promise<HTMLElement | Root>): Promise<HTMLElement | Root>;
@@ -1,5 +1,5 @@
1
1
  import type React from 'react';
2
- import { hydrateWithReact } from './hydrate';
2
+ import { hydrateWithReact } from './hydrate.js';
3
3
  export { hydrateWithReact };
4
4
  export type RenderFunc = typeof render;
5
5
  export declare function render(App: React.ReactElement<{