@modern-js/server-core 2.63.2 → 2.63.3

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.
@@ -56,10 +56,10 @@ async function getHtmlTemplates(pwd, routes) {
56
56
  const templates = Object.fromEntries(htmls);
57
57
  return templates;
58
58
  }
59
- function injectTemplates(pwd, routes) {
59
+ function injectTemplates(pwd, routes, htmlTemplatePromise) {
60
60
  return async (c, next) => {
61
61
  if (routes && !c.get("templates")) {
62
- const templates = await getHtmlTemplates(pwd, routes);
62
+ const templates = await (htmlTemplatePromise || getHtmlTemplates(pwd, routes));
63
63
  c.set("templates", templates);
64
64
  }
65
65
  await next();
@@ -119,13 +119,18 @@ const injectResourcePlugin = () => ({
119
119
  return {
120
120
  async prepare() {
121
121
  const { middlewares, routes, distDirectory: pwd } = api.useAppContext();
122
+ let htmlTemplatePromise;
123
+ if ((0, import_utils.isProd)()) {
124
+ getServerManifest(pwd, routes || [], console);
125
+ htmlTemplatePromise = getHtmlTemplates(pwd, routes || []);
126
+ }
122
127
  middlewares.push({
123
128
  name: "inject-server-manifest",
124
129
  handler: injectServerManifest(pwd, routes)
125
130
  });
126
131
  middlewares.push({
127
132
  name: "inject-html",
128
- handler: injectTemplates(pwd, routes)
133
+ handler: injectTemplates(pwd, routes, htmlTemplatePromise)
129
134
  });
130
135
  }
131
136
  };
@@ -91,7 +91,7 @@ class IncomingMessgeProxy {
91
91
  }
92
92
  }
93
93
  function createRequestHandlerConfig(userConfig) {
94
- const { output, server, security, html } = userConfig;
94
+ const { output, server, security, html, source } = userConfig;
95
95
  return {
96
96
  ssr: server === null || server === void 0 ? void 0 : server.ssr,
97
97
  ssrByEntries: server === null || server === void 0 ? void 0 : server.ssrByEntries,
@@ -100,7 +100,8 @@ function createRequestHandlerConfig(userConfig) {
100
100
  enableInlineStyles: output === null || output === void 0 ? void 0 : output.enableInlineStyles,
101
101
  crossorigin: html === null || html === void 0 ? void 0 : html.crossorigin,
102
102
  scriptLoading: html === null || html === void 0 ? void 0 : html.scriptLoading,
103
- useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript
103
+ useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript,
104
+ enableAsyncEntry: source === null || source === void 0 ? void 0 : source.enableAsyncEntry
104
105
  };
105
106
  }
106
107
  // Annotate the CommonJS export names for ESM import in node:
@@ -3,7 +3,7 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import path from "path";
5
5
  import { fileReader } from "@modern-js/runtime-utils/fileReader";
6
- import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire } from "@modern-js/utils";
6
+ import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire, isProd } from "@modern-js/utils";
7
7
  import { uniqueKeyByRoute } from "../../../utils";
8
8
  function getHtmlTemplates(pwd, routes) {
9
9
  return _getHtmlTemplates.apply(this, arguments);
@@ -73,7 +73,7 @@ function _getHtmlTemplates() {
73
73
  });
74
74
  return _getHtmlTemplates.apply(this, arguments);
75
75
  }
76
- function injectTemplates(pwd, routes) {
76
+ function injectTemplates(pwd, routes, htmlTemplatePromise) {
77
77
  return function() {
78
78
  var _ref = _async_to_generator(function(c, next) {
79
79
  var templates;
@@ -87,7 +87,7 @@ function injectTemplates(pwd, routes) {
87
87
  ];
88
88
  return [
89
89
  4,
90
- getHtmlTemplates(pwd, routes)
90
+ htmlTemplatePromise || getHtmlTemplates(pwd, routes)
91
91
  ];
92
92
  case 1:
93
93
  templates = _state.sent();
@@ -331,16 +331,20 @@ var injectResourcePlugin = function() {
331
331
  return {
332
332
  prepare: function prepare() {
333
333
  return _async_to_generator(function() {
334
- var _api_useAppContext, middlewares, routes, pwd;
334
+ var _api_useAppContext, middlewares, routes, pwd, htmlTemplatePromise;
335
335
  return _ts_generator(this, function(_state) {
336
336
  _api_useAppContext = api.useAppContext(), middlewares = _api_useAppContext.middlewares, routes = _api_useAppContext.routes, pwd = _api_useAppContext.distDirectory;
337
+ if (isProd()) {
338
+ getServerManifest(pwd, routes || [], console);
339
+ htmlTemplatePromise = getHtmlTemplates(pwd, routes || []);
340
+ }
337
341
  middlewares.push({
338
342
  name: "inject-server-manifest",
339
343
  handler: injectServerManifest(pwd, routes)
340
344
  });
341
345
  middlewares.push({
342
346
  name: "inject-html",
343
- handler: injectTemplates(pwd, routes)
347
+ handler: injectTemplates(pwd, routes, htmlTemplatePromise)
344
348
  });
345
349
  return [
346
350
  2
@@ -115,7 +115,7 @@ var IncomingMessgeProxy = function IncomingMessgeProxy2(req) {
115
115
  this.url = getPathname(req);
116
116
  };
117
117
  function createRequestHandlerConfig(userConfig) {
118
- var output = userConfig.output, server = userConfig.server, security = userConfig.security, html = userConfig.html;
118
+ var output = userConfig.output, server = userConfig.server, security = userConfig.security, html = userConfig.html, source = userConfig.source;
119
119
  return {
120
120
  ssr: server === null || server === void 0 ? void 0 : server.ssr,
121
121
  ssrByEntries: server === null || server === void 0 ? void 0 : server.ssrByEntries,
@@ -124,7 +124,8 @@ function createRequestHandlerConfig(userConfig) {
124
124
  enableInlineStyles: output === null || output === void 0 ? void 0 : output.enableInlineStyles,
125
125
  crossorigin: html === null || html === void 0 ? void 0 : html.crossorigin,
126
126
  scriptLoading: html === null || html === void 0 ? void 0 : html.scriptLoading,
127
- useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript
127
+ useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript,
128
+ enableAsyncEntry: source === null || source === void 0 ? void 0 : source.enableAsyncEntry
128
129
  };
129
130
  }
130
131
  export {
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import { fileReader } from "@modern-js/runtime-utils/fileReader";
3
- import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire } from "@modern-js/utils";
3
+ import { fs, LOADABLE_STATS_FILE, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_MANIFEST_FILE, SERVER_BUNDLE_DIRECTORY, compatibleRequire, isProd } from "@modern-js/utils";
4
4
  import { uniqueKeyByRoute } from "../../../utils";
5
5
  async function getHtmlTemplates(pwd, routes) {
6
6
  const htmls = await Promise.all(routes.map(async (route) => {
@@ -19,10 +19,10 @@ async function getHtmlTemplates(pwd, routes) {
19
19
  const templates = Object.fromEntries(htmls);
20
20
  return templates;
21
21
  }
22
- function injectTemplates(pwd, routes) {
22
+ function injectTemplates(pwd, routes, htmlTemplatePromise) {
23
23
  return async (c, next) => {
24
24
  if (routes && !c.get("templates")) {
25
- const templates = await getHtmlTemplates(pwd, routes);
25
+ const templates = await (htmlTemplatePromise || getHtmlTemplates(pwd, routes));
26
26
  c.set("templates", templates);
27
27
  }
28
28
  await next();
@@ -82,13 +82,18 @@ const injectResourcePlugin = () => ({
82
82
  return {
83
83
  async prepare() {
84
84
  const { middlewares, routes, distDirectory: pwd } = api.useAppContext();
85
+ let htmlTemplatePromise;
86
+ if (isProd()) {
87
+ getServerManifest(pwd, routes || [], console);
88
+ htmlTemplatePromise = getHtmlTemplates(pwd, routes || []);
89
+ }
85
90
  middlewares.push({
86
91
  name: "inject-server-manifest",
87
92
  handler: injectServerManifest(pwd, routes)
88
93
  });
89
94
  middlewares.push({
90
95
  name: "inject-html",
91
- handler: injectTemplates(pwd, routes)
96
+ handler: injectTemplates(pwd, routes, htmlTemplatePromise)
92
97
  });
93
98
  }
94
99
  };
@@ -68,7 +68,7 @@ class IncomingMessgeProxy {
68
68
  }
69
69
  }
70
70
  function createRequestHandlerConfig(userConfig) {
71
- const { output, server, security, html } = userConfig;
71
+ const { output, server, security, html, source } = userConfig;
72
72
  return {
73
73
  ssr: server === null || server === void 0 ? void 0 : server.ssr,
74
74
  ssrByEntries: server === null || server === void 0 ? void 0 : server.ssrByEntries,
@@ -77,7 +77,8 @@ function createRequestHandlerConfig(userConfig) {
77
77
  enableInlineStyles: output === null || output === void 0 ? void 0 : output.enableInlineStyles,
78
78
  crossorigin: html === null || html === void 0 ? void 0 : html.crossorigin,
79
79
  scriptLoading: html === null || html === void 0 ? void 0 : html.scriptLoading,
80
- useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript
80
+ useJsonScript: server === null || server === void 0 ? void 0 : server.useJsonScript,
81
+ enableAsyncEntry: source === null || source === void 0 ? void 0 : source.enableAsyncEntry
81
82
  };
82
83
  }
83
84
  export {
@@ -1,7 +1,7 @@
1
1
  import type { Logger, ServerRoute } from '@modern-js/types';
2
2
  import type { Middleware, ServerEnv, ServerManifest, ServerPlugin } from '../../../types';
3
3
  export declare function getHtmlTemplates(pwd: string, routes: ServerRoute[]): Promise<Record<string, string>>;
4
- export declare function injectTemplates(pwd: string, routes?: ServerRoute[]): Middleware<ServerEnv>;
4
+ export declare function injectTemplates(pwd: string, routes?: ServerRoute[], htmlTemplatePromise?: ReturnType<typeof getHtmlTemplates>): Middleware<ServerEnv>;
5
5
  export declare function getServerManifest(pwd: string, routes: ServerRoute[], logger: Logger): Promise<ServerManifest>;
6
6
  export declare function injectServerManifest(pwd: string, routes?: ServerRoute[]): Middleware<ServerEnv>;
7
7
  export declare const injectResourcePlugin: () => ServerPlugin;
@@ -2,5 +2,6 @@ import type { Alias } from '@modern-js/utils';
2
2
  import type { ConfigChain } from './share';
3
3
  export interface SourceUserConfig {
4
4
  alias?: ConfigChain<Alias>;
5
+ enableAsyncEntry?: boolean;
5
6
  }
6
7
  export type SourceNormalizedConfig = SourceUserConfig;
@@ -1,5 +1,5 @@
1
1
  import type { Logger, Metrics, Reporter, ServerRoute } from '@modern-js/types';
2
- import type { ServerUserConfig } from './config';
2
+ import type { ServerUserConfig, SourceUserConfig } from './config';
3
3
  export type Resource = {
4
4
  loadableStats: Record<string, any>;
5
5
  routeManifest: Record<string, any>;
@@ -17,6 +17,7 @@ export type RequestHandlerConfig = {
17
17
  ssr?: ServerUserConfig['ssr'];
18
18
  ssrByEntries?: ServerUserConfig['ssrByEntries'];
19
19
  useJsonScript?: ServerUserConfig['useJsonScript'];
20
+ enableAsyncEntry?: SourceUserConfig['enableAsyncEntry'];
20
21
  };
21
22
  export type LoaderContext = Map<string, any>;
22
23
  export type OnError = (err: unknown) => void;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.63.2",
18
+ "version": "2.63.3",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -53,9 +53,9 @@
53
53
  "flatted": "^3.2.9",
54
54
  "hono": "^3.12.2",
55
55
  "ts-deepmerge": "7.0.2",
56
- "@modern-js/runtime-utils": "2.63.2",
57
- "@modern-js/plugin": "2.63.2",
58
- "@modern-js/utils": "2.63.2"
56
+ "@modern-js/runtime-utils": "2.63.3",
57
+ "@modern-js/utils": "2.63.3",
58
+ "@modern-js/plugin": "2.63.3"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/jest": "^29",
@@ -65,9 +65,9 @@
65
65
  "jest": "^29",
66
66
  "ts-jest": "^29.1.0",
67
67
  "typescript": "^5",
68
- "@scripts/build": "2.63.2",
69
- "@modern-js/types": "2.63.2",
70
- "@scripts/jest-config": "2.63.2"
68
+ "@scripts/build": "2.63.3",
69
+ "@scripts/jest-config": "2.63.3",
70
+ "@modern-js/types": "2.63.3"
71
71
  },
72
72
  "sideEffects": false,
73
73
  "publishConfig": {