@modern-js/runtime 2.70.8 → 2.71.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.
@@ -52,10 +52,32 @@ function getSSRMode(entry, config) {
52
52
  return ssr2.mode === "stream" ? "stream" : "string";
53
53
  }
54
54
  }
55
+ const normalizePreEntry = (preEntry) => {
56
+ if (!preEntry) {
57
+ return [];
58
+ }
59
+ if (Array.isArray(preEntry)) {
60
+ return preEntry.filter((v) => typeof v === "string" && v.length > 0);
61
+ }
62
+ if (typeof preEntry === "string") {
63
+ return preEntry ? [
64
+ preEntry
65
+ ] : [];
66
+ }
67
+ return [];
68
+ };
69
+ const resolvePreEntryImportPath = ({ preEntry, appDirectory, srcDirectory, internalSrcAlias }) => {
70
+ const absPath = import_path.default.isAbsolute(preEntry) ? preEntry : import_path.default.resolve(appDirectory, preEntry);
71
+ if (absPath.startsWith(srcDirectory)) {
72
+ return (0, import_utils.formatImportPath)(absPath.replace(srcDirectory, internalSrcAlias));
73
+ }
74
+ return (0, import_utils.formatImportPath)(absPath);
75
+ };
55
76
  const generateCode = async (entrypoints, appContext, config, hooks) => {
56
77
  const { mountId } = config.html;
57
- const { enableAsyncEntry } = config.source;
58
- const { runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory, serverRoutes } = appContext;
78
+ const { enableAsyncEntry, enableAsyncPreEntry, preEntry } = config.source;
79
+ const shouldInjectAsyncPreEntry = !!enableAsyncEntry && !!enableAsyncPreEntry;
80
+ const { appDirectory, runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory, serverRoutes } = appContext;
59
81
  await Promise.all(entrypoints.map(async (entrypoint) => {
60
82
  const { entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry } = entrypoint;
61
83
  const { plugins: runtimePlugins } = await hooks._internalRuntimePlugins.call({
@@ -88,6 +110,22 @@ const generateCode = async (entrypoints, appContext, config, hooks) => {
88
110
  isNestedRouter: !!entrypoint.nestedRoutesEntry
89
111
  });
90
112
  }
113
+ if (shouldInjectAsyncPreEntry) {
114
+ const preEntries = normalizePreEntry(preEntry);
115
+ if (preEntries.length > 0) {
116
+ const injected = preEntries.map((item) => {
117
+ const importPath = resolvePreEntryImportPath({
118
+ preEntry: item,
119
+ appDirectory,
120
+ srcDirectory,
121
+ internalSrcAlias
122
+ });
123
+ return `import '${importPath}';`;
124
+ }).join("\n");
125
+ indexCode = `${injected}
126
+ ${indexCode}`;
127
+ }
128
+ }
91
129
  const indexFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_FILE_NAME}`);
92
130
  await import_utils.fs.outputFile(indexFile, indexCode, "utf8");
93
131
  if (enableAsyncEntry) {
@@ -1,7 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
- import { fs } from "@modern-js/utils";
4
+ import { fs, formatImportPath } from "@modern-js/utils";
5
5
  import { ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, ENTRY_SERVER_BOOTSTRAP_FILE_NAME, INDEX_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME } from "./constants";
6
6
  import * as template from "./template";
7
7
  import * as serverTemplate from "./template.server";
@@ -21,20 +21,45 @@ function getSSRMode(entry, config) {
21
21
  return ssr2.mode === "stream" ? "stream" : "string";
22
22
  }
23
23
  }
24
+ var normalizePreEntry = function(preEntry) {
25
+ if (!preEntry) {
26
+ return [];
27
+ }
28
+ if (Array.isArray(preEntry)) {
29
+ return preEntry.filter(function(v) {
30
+ return typeof v === "string" && v.length > 0;
31
+ });
32
+ }
33
+ if (typeof preEntry === "string") {
34
+ return preEntry ? [
35
+ preEntry
36
+ ] : [];
37
+ }
38
+ return [];
39
+ };
40
+ var resolvePreEntryImportPath = function(param) {
41
+ var preEntry = param.preEntry, appDirectory = param.appDirectory, srcDirectory = param.srcDirectory, internalSrcAlias = param.internalSrcAlias;
42
+ var absPath = path.isAbsolute(preEntry) ? preEntry : path.resolve(appDirectory, preEntry);
43
+ if (absPath.startsWith(srcDirectory)) {
44
+ return formatImportPath(absPath.replace(srcDirectory, internalSrcAlias));
45
+ }
46
+ return formatImportPath(absPath);
47
+ };
24
48
  var generateCode = function() {
25
49
  var _ref = _async_to_generator(function(entrypoints, appContext, config, hooks) {
26
- var mountId, enableAsyncEntry, runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory, serverRoutes;
50
+ var mountId, _config_source, enableAsyncEntry, enableAsyncPreEntry, preEntry, shouldInjectAsyncPreEntry, appDirectory, runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory, serverRoutes;
27
51
  return _ts_generator(this, function(_state) {
28
52
  switch (_state.label) {
29
53
  case 0:
30
54
  mountId = config.html.mountId;
31
- enableAsyncEntry = config.source.enableAsyncEntry;
32
- runtimeConfigFile = appContext.runtimeConfigFile, internalDirectory = appContext.internalDirectory, internalSrcAlias = appContext.internalSrcAlias, metaName = appContext.metaName, srcDirectory = appContext.srcDirectory, serverRoutes = appContext.serverRoutes;
55
+ _config_source = config.source, enableAsyncEntry = _config_source.enableAsyncEntry, enableAsyncPreEntry = _config_source.enableAsyncPreEntry, preEntry = _config_source.preEntry;
56
+ shouldInjectAsyncPreEntry = !!enableAsyncEntry && !!enableAsyncPreEntry;
57
+ appDirectory = appContext.appDirectory, runtimeConfigFile = appContext.runtimeConfigFile, internalDirectory = appContext.internalDirectory, internalSrcAlias = appContext.internalSrcAlias, metaName = appContext.metaName, srcDirectory = appContext.srcDirectory, serverRoutes = appContext.serverRoutes;
33
58
  return [
34
59
  4,
35
60
  Promise.all(entrypoints.map(function() {
36
61
  var _ref2 = _async_to_generator(function(entrypoint) {
37
- var entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry, _ref3, runtimePlugins, ssrMode, indexCode, _serverRoutes_find, indexFile, bootstrapFile, bootstrapServerFile, indexServerCode, indexServerFile, indexServerFile1, indexServerCode1, registerCode, registerFile, registerRuntimeCode, registerRuntimeFile, contextCode, AppProxyPath, appProxyCode, contextServerCode, contextFile, contextFile1;
62
+ var entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry, _ref3, runtimePlugins, ssrMode, indexCode, _serverRoutes_find, preEntries, injected, indexFile, bootstrapFile, bootstrapServerFile, indexServerCode, indexServerFile, indexServerFile1, indexServerCode1, registerCode, registerFile, registerRuntimeCode, registerRuntimeFile, contextCode, AppProxyPath, appProxyCode, contextServerCode, contextFile, contextFile1;
38
63
  return _ts_generator(this, function(_state2) {
39
64
  switch (_state2.label) {
40
65
  case 0:
@@ -80,6 +105,21 @@ var generateCode = function() {
80
105
  isNestedRouter: !!entrypoint.nestedRoutesEntry
81
106
  });
82
107
  }
108
+ if (shouldInjectAsyncPreEntry) {
109
+ preEntries = normalizePreEntry(preEntry);
110
+ if (preEntries.length > 0) {
111
+ injected = preEntries.map(function(item) {
112
+ var importPath = resolvePreEntryImportPath({
113
+ preEntry: item,
114
+ appDirectory,
115
+ srcDirectory,
116
+ internalSrcAlias
117
+ });
118
+ return "import '".concat(importPath, "';");
119
+ }).join("\n");
120
+ indexCode = "".concat(injected, "\n").concat(indexCode);
121
+ }
122
+ }
83
123
  indexFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
84
124
  return [
85
125
  4,
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { fs } from "@modern-js/utils";
2
+ import { fs, formatImportPath } from "@modern-js/utils";
3
3
  import { ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_POINT_REGISTER_FILE_NAME, ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME, ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME, ENTRY_SERVER_BOOTSTRAP_FILE_NAME, INDEX_FILE_NAME, SERVER_ENTRY_POINT_FILE_NAME } from "./constants";
4
4
  import * as template from "./template";
5
5
  import * as serverTemplate from "./template.server";
@@ -19,10 +19,32 @@ function getSSRMode(entry, config) {
19
19
  return ssr2.mode === "stream" ? "stream" : "string";
20
20
  }
21
21
  }
22
+ const normalizePreEntry = (preEntry) => {
23
+ if (!preEntry) {
24
+ return [];
25
+ }
26
+ if (Array.isArray(preEntry)) {
27
+ return preEntry.filter((v) => typeof v === "string" && v.length > 0);
28
+ }
29
+ if (typeof preEntry === "string") {
30
+ return preEntry ? [
31
+ preEntry
32
+ ] : [];
33
+ }
34
+ return [];
35
+ };
36
+ const resolvePreEntryImportPath = ({ preEntry, appDirectory, srcDirectory, internalSrcAlias }) => {
37
+ const absPath = path.isAbsolute(preEntry) ? preEntry : path.resolve(appDirectory, preEntry);
38
+ if (absPath.startsWith(srcDirectory)) {
39
+ return formatImportPath(absPath.replace(srcDirectory, internalSrcAlias));
40
+ }
41
+ return formatImportPath(absPath);
42
+ };
22
43
  const generateCode = async (entrypoints, appContext, config, hooks) => {
23
44
  const { mountId } = config.html;
24
- const { enableAsyncEntry } = config.source;
25
- const { runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory, serverRoutes } = appContext;
45
+ const { enableAsyncEntry, enableAsyncPreEntry, preEntry } = config.source;
46
+ const shouldInjectAsyncPreEntry = !!enableAsyncEntry && !!enableAsyncPreEntry;
47
+ const { appDirectory, runtimeConfigFile, internalDirectory, internalSrcAlias, metaName, srcDirectory, serverRoutes } = appContext;
26
48
  await Promise.all(entrypoints.map(async (entrypoint) => {
27
49
  const { entryName, isAutoMount, entry, customEntry, customBootstrap, customServerEntry } = entrypoint;
28
50
  const { plugins: runtimePlugins } = await hooks._internalRuntimePlugins.call({
@@ -55,6 +77,22 @@ const generateCode = async (entrypoints, appContext, config, hooks) => {
55
77
  isNestedRouter: !!entrypoint.nestedRoutesEntry
56
78
  });
57
79
  }
80
+ if (shouldInjectAsyncPreEntry) {
81
+ const preEntries = normalizePreEntry(preEntry);
82
+ if (preEntries.length > 0) {
83
+ const injected = preEntries.map((item) => {
84
+ const importPath = resolvePreEntryImportPath({
85
+ preEntry: item,
86
+ appDirectory,
87
+ srcDirectory,
88
+ internalSrcAlias
89
+ });
90
+ return `import '${importPath}';`;
91
+ }).join("\n");
92
+ indexCode = `${injected}
93
+ ${indexCode}`;
94
+ }
95
+ }
58
96
  const indexFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
59
97
  await fs.outputFile(indexFile, indexCode, "utf8");
60
98
  if (enableAsyncEntry) {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.70.8",
18
+ "version": "2.71.0",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -218,13 +218,13 @@
218
218
  "react-is": "^18",
219
219
  "react-side-effect": "^2.1.2",
220
220
  "styled-components": "^5.3.1",
221
- "@modern-js/plugin": "2.70.8",
222
- "@modern-js/plugin-data-loader": "2.70.8",
223
- "@modern-js/plugin-v2": "2.70.8",
224
- "@modern-js/render": "2.70.8",
225
- "@modern-js/types": "2.70.8",
226
- "@modern-js/runtime-utils": "2.70.8",
227
- "@modern-js/utils": "2.70.8"
221
+ "@modern-js/plugin-data-loader": "2.71.0",
222
+ "@modern-js/plugin": "2.71.0",
223
+ "@modern-js/render": "2.71.0",
224
+ "@modern-js/runtime-utils": "2.71.0",
225
+ "@modern-js/plugin-v2": "2.71.0",
226
+ "@modern-js/types": "2.71.0",
227
+ "@modern-js/utils": "2.71.0"
228
228
  },
229
229
  "peerDependencies": {
230
230
  "react": ">=17",
@@ -232,7 +232,7 @@
232
232
  },
233
233
  "devDependencies": {
234
234
  "@remix-run/web-fetch": "^4.1.3",
235
- "@rsbuild/core": "1.7.3",
235
+ "@rsbuild/core": "1.7.5",
236
236
  "@testing-library/react": "^13.4.0",
237
237
  "@types/cookie": "0.6.0",
238
238
  "@types/invariant": "^2.2.30",
@@ -248,10 +248,10 @@
248
248
  "ts-node": "^10.9.1",
249
249
  "typescript": "^5",
250
250
  "webpack": "^5.103.0",
251
- "@modern-js/app-tools": "2.70.8",
251
+ "@modern-js/app-tools": "2.71.0",
252
252
  "@scripts/build": "2.66.0",
253
253
  "@scripts/jest-config": "2.66.0",
254
- "@modern-js/core": "2.70.8"
254
+ "@modern-js/core": "2.71.0"
255
255
  },
256
256
  "sideEffects": false,
257
257
  "publishConfig": {