@modern-js/runtime 2.38.0 → 2.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -160,7 +160,7 @@ function deserializeErrors(errors) {
160
160
  const serialized = {};
161
161
  for (const [key, val] of entries) {
162
162
  if (val && val.__type === "RouteErrorResponse") {
163
- serialized[key] = new import_remix_router.ErrorResponse(val.status, val.statusText, val.data, val.internal === true);
163
+ serialized[key] = new import_remix_router.UNSAFE_ErrorResponseImpl(val.status, val.statusText, val.data, val.internal === true);
164
164
  } else if (val && val.__type === "Error") {
165
165
  const error = new Error(val.message);
166
166
  error.stack = val.stack;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var loadable_exports = {};
20
30
  __export(loadable_exports, {
@@ -23,8 +33,7 @@ __export(loadable_exports, {
23
33
  module.exports = __toCommonJS(loadable_exports);
24
34
  var import_define_property = require("@swc/helpers/_/_define_property");
25
35
  var import_server = require("@loadable/server");
26
- var import_utils = require("@modern-js/utils");
27
- var import_utils2 = require("../utils");
36
+ var import_utils = require("../utils");
28
37
  const extname = (uri) => {
29
38
  if (typeof uri !== "string" || !uri.includes(".")) {
30
39
  return "";
@@ -43,6 +52,10 @@ const checkIsInline = (chunk, enableInline) => {
43
52
  return false;
44
53
  }
45
54
  };
55
+ const checkIsNode = () => {
56
+ var _process_release;
57
+ return typeof process !== "undefined" && ((_process_release = process.release) === null || _process_release === void 0 ? void 0 : _process_release.name) === "node";
58
+ };
46
59
  class LoadableCollector {
47
60
  get existsAssets() {
48
61
  var _routeManifest_routeAssets_entryName, _routeManifest_routeAssets;
@@ -92,7 +105,7 @@ class LoadableCollector {
92
105
  defer: scriptLoading === "defer" ? true : void 0,
93
106
  type: scriptLoading === "module" ? "module" : void 0
94
107
  };
95
- const attributes = (0, import_utils2.attributesToString)(this.generateAttributes({
108
+ const attributes = (0, import_utils.attributesToString)(this.generateAttributes({
96
109
  nonce,
97
110
  ...scriptLoadingAtr
98
111
  }));
@@ -100,31 +113,37 @@ class LoadableCollector {
100
113
  var _this_existsAssets;
101
114
  const jsChunkReg = new RegExp(`<script .*src="${chunk.url}".*>`);
102
115
  return !jsChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
103
- }).map((chunk) => {
104
- if (checkIsInline(chunk, enableInlineScripts)) {
116
+ }).map(async (chunk) => {
117
+ if (checkIsInline(chunk, enableInlineScripts) && checkIsNode()) {
118
+ const fs = await Promise.resolve().then(() => __toESM(require("node:fs/promises")));
105
119
  const filepath = chunk.path;
106
- return import_utils.fs.readFile(filepath, "utf-8").then((content) => `<script>${content}</script>`);
120
+ return fs.readFile(filepath, "utf-8").then((content) => `<script>${content}</script>`).catch((_) => {
121
+ return "";
122
+ });
107
123
  } else {
108
124
  return `<script${attributes} src="${chunk.url}"></script>`;
109
125
  }
110
126
  }));
111
- chunksMap.js += scripts.join("");
127
+ chunksMap.js += scripts.filter((script) => Boolean(script)).join("");
112
128
  }
113
129
  async emitStyleAssets(chunks) {
114
130
  const { template, result: { chunksMap }, config: { enableInlineStyles } } = this.options;
115
- const atrributes = (0, import_utils2.attributesToString)(this.generateAttributes());
131
+ const atrributes = (0, import_utils.attributesToString)(this.generateAttributes());
116
132
  const css = await Promise.all(chunks.filter((chunk) => {
117
133
  var _this_existsAssets;
118
134
  const cssChunkReg = new RegExp(`<link .*href="${chunk.url}".*>`);
119
135
  return !cssChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
120
- }).map((chunk) => {
121
- if (checkIsInline(chunk, enableInlineStyles)) {
122
- return import_utils.fs.readFile(chunk.path).then((content) => `<style>${content}</style>`);
136
+ }).map(async (chunk) => {
137
+ if (checkIsInline(chunk, enableInlineStyles) && checkIsNode()) {
138
+ const fs = await Promise.resolve().then(() => __toESM(require("node:fs/promises")));
139
+ return fs.readFile(chunk.path).then((content) => `<style>${content}</style>`).catch((_) => {
140
+ return "";
141
+ });
123
142
  } else {
124
143
  return `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
125
144
  }
126
145
  }));
127
- chunksMap.css += css.join("");
146
+ chunksMap.css += css.filter((css2) => Boolean(css2)).join("");
128
147
  }
129
148
  generateAttributes(extraAtr = {}) {
130
149
  const { config } = this.options;
@@ -5,7 +5,7 @@ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_
5
5
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
7
  import { Route, isRouteErrorResponse } from "@modern-js/runtime-utils/router";
8
- import { ErrorResponse } from "@modern-js/runtime-utils/remix-router";
8
+ import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "@modern-js/runtime-utils/remix-router";
9
9
  import { renderNestedRoute } from "@modern-js/runtime-utils/browser";
10
10
  import { DefaultNotFound } from "./DefaultNotFound";
11
11
  import DeferredDataScripts from "./DeferredDataScripts";
@@ -167,7 +167,7 @@ function deserializeErrors(errors) {
167
167
  for (var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
168
168
  var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], val = _step_value[1];
169
169
  if (val && val.__type === "RouteErrorResponse") {
170
- serialized[key] = new ErrorResponse(val.status, val.statusText, val.data, val.internal === true);
170
+ serialized[key] = new ErrorResponseImpl(val.status, val.statusText, val.data, val.internal === true);
171
171
  } else if (val && val.__type === "Error") {
172
172
  var error = new Error(val.message);
173
173
  error.stack = val.stack;
@@ -6,7 +6,6 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
6
6
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
7
7
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
8
8
  import { ChunkExtractor } from "@loadable/server";
9
- import { fs } from "@modern-js/utils";
10
9
  import { attributesToString } from "../utils";
11
10
  var extname = function(uri) {
12
11
  if (typeof uri !== "string" || !uri.includes(".")) {
@@ -32,6 +31,10 @@ var checkIsInline = function(chunk, enableInline) {
32
31
  return false;
33
32
  }
34
33
  };
34
+ var checkIsNode = function() {
35
+ var _process_release;
36
+ return typeof process !== "undefined" && ((_process_release = process.release) === null || _process_release === void 0 ? void 0 : _process_release.name) === "node";
37
+ };
35
38
  var LoadableCollector = /* @__PURE__ */ function() {
36
39
  "use strict";
37
40
  function LoadableCollector2(options) {
@@ -146,20 +149,54 @@ var LoadableCollector = /* @__PURE__ */ function() {
146
149
  var _this_existsAssets;
147
150
  var jsChunkReg = new RegExp('<script .*src="'.concat(chunk.url, '".*>'));
148
151
  return !jsChunkReg.test(template) && !((_this_existsAssets = _this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
149
- }).map(function(chunk) {
150
- if (checkIsInline(chunk, enableInlineScripts)) {
151
- var filepath = chunk.path;
152
- return fs.readFile(filepath, "utf-8").then(function(content) {
153
- return "<script>".concat(content, "</script>");
152
+ }).map(function() {
153
+ var _ref = _async_to_generator(function(chunk) {
154
+ var fs, filepath;
155
+ return _ts_generator(this, function(_state2) {
156
+ switch (_state2.label) {
157
+ case 0:
158
+ if (!(checkIsInline(chunk, enableInlineScripts) && checkIsNode()))
159
+ return [
160
+ 3,
161
+ 2
162
+ ];
163
+ return [
164
+ 4,
165
+ import("node:fs/promises")
166
+ ];
167
+ case 1:
168
+ fs = _state2.sent();
169
+ filepath = chunk.path;
170
+ return [
171
+ 2,
172
+ fs.readFile(filepath, "utf-8").then(function(content) {
173
+ return "<script>".concat(content, "</script>");
174
+ }).catch(function(_) {
175
+ return "";
176
+ })
177
+ ];
178
+ case 2:
179
+ return [
180
+ 2,
181
+ "<script".concat(attributes, ' src="').concat(chunk.url, '"></script>')
182
+ ];
183
+ case 3:
184
+ return [
185
+ 2
186
+ ];
187
+ }
154
188
  });
155
- } else {
156
- return "<script".concat(attributes, ' src="').concat(chunk.url, '"></script>');
157
- }
158
- }))
189
+ });
190
+ return function(chunk) {
191
+ return _ref.apply(this, arguments);
192
+ };
193
+ }()))
159
194
  ];
160
195
  case 1:
161
196
  scripts = _state.sent();
162
- chunksMap.js += scripts.join("");
197
+ chunksMap.js += scripts.filter(function(script) {
198
+ return Boolean(script);
199
+ }).join("");
163
200
  return [
164
201
  2
165
202
  ];
@@ -185,19 +222,53 @@ var LoadableCollector = /* @__PURE__ */ function() {
185
222
  var _this_existsAssets;
186
223
  var cssChunkReg = new RegExp('<link .*href="'.concat(chunk.url, '".*>'));
187
224
  return !cssChunkReg.test(template) && !((_this_existsAssets = _this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
188
- }).map(function(chunk) {
189
- if (checkIsInline(chunk, enableInlineStyles)) {
190
- return fs.readFile(chunk.path).then(function(content) {
191
- return "<style>".concat(content, "</style>");
225
+ }).map(function() {
226
+ var _ref = _async_to_generator(function(chunk) {
227
+ var fs;
228
+ return _ts_generator(this, function(_state2) {
229
+ switch (_state2.label) {
230
+ case 0:
231
+ if (!(checkIsInline(chunk, enableInlineStyles) && checkIsNode()))
232
+ return [
233
+ 3,
234
+ 2
235
+ ];
236
+ return [
237
+ 4,
238
+ import("node:fs/promises")
239
+ ];
240
+ case 1:
241
+ fs = _state2.sent();
242
+ return [
243
+ 2,
244
+ fs.readFile(chunk.path).then(function(content) {
245
+ return "<style>".concat(content, "</style>");
246
+ }).catch(function(_) {
247
+ return "";
248
+ })
249
+ ];
250
+ case 2:
251
+ return [
252
+ 2,
253
+ "<link".concat(atrributes, ' href="').concat(chunk.url, '" rel="stylesheet" />')
254
+ ];
255
+ case 3:
256
+ return [
257
+ 2
258
+ ];
259
+ }
192
260
  });
193
- } else {
194
- return "<link".concat(atrributes, ' href="').concat(chunk.url, '" rel="stylesheet" />');
195
- }
196
- }))
261
+ });
262
+ return function(chunk) {
263
+ return _ref.apply(this, arguments);
264
+ };
265
+ }()))
197
266
  ];
198
267
  case 1:
199
268
  css = _state.sent();
200
- chunksMap.css += css.join("");
269
+ chunksMap.css += css.filter(function(css2) {
270
+ return Boolean(css2);
271
+ }).join("");
201
272
  return [
202
273
  2
203
274
  ];
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Route, isRouteErrorResponse } from "@modern-js/runtime-utils/router";
3
- import { ErrorResponse } from "@modern-js/runtime-utils/remix-router";
3
+ import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "@modern-js/runtime-utils/remix-router";
4
4
  import { renderNestedRoute } from "@modern-js/runtime-utils/browser";
5
5
  import { DefaultNotFound } from "./DefaultNotFound";
6
6
  import DeferredDataScripts from "./DeferredDataScripts";
@@ -121,7 +121,7 @@ function deserializeErrors(errors) {
121
121
  const serialized = {};
122
122
  for (const [key, val] of entries) {
123
123
  if (val && val.__type === "RouteErrorResponse") {
124
- serialized[key] = new ErrorResponse(val.status, val.statusText, val.data, val.internal === true);
124
+ serialized[key] = new ErrorResponseImpl(val.status, val.statusText, val.data, val.internal === true);
125
125
  } else if (val && val.__type === "Error") {
126
126
  const error = new Error(val.message);
127
127
  error.stack = val.stack;
@@ -1,6 +1,5 @@
1
1
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
2
  import { ChunkExtractor } from "@loadable/server";
3
- import { fs } from "@modern-js/utils";
4
3
  import { attributesToString } from "../utils";
5
4
  const extname = (uri) => {
6
5
  if (typeof uri !== "string" || !uri.includes(".")) {
@@ -20,6 +19,10 @@ const checkIsInline = (chunk, enableInline) => {
20
19
  return false;
21
20
  }
22
21
  };
22
+ const checkIsNode = () => {
23
+ var _process_release;
24
+ return typeof process !== "undefined" && ((_process_release = process.release) === null || _process_release === void 0 ? void 0 : _process_release.name) === "node";
25
+ };
23
26
  class LoadableCollector {
24
27
  get existsAssets() {
25
28
  var _routeManifest_routeAssets_entryName, _routeManifest_routeAssets;
@@ -77,15 +80,18 @@ class LoadableCollector {
77
80
  var _this_existsAssets;
78
81
  const jsChunkReg = new RegExp(`<script .*src="${chunk.url}".*>`);
79
82
  return !jsChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
80
- }).map((chunk) => {
81
- if (checkIsInline(chunk, enableInlineScripts)) {
83
+ }).map(async (chunk) => {
84
+ if (checkIsInline(chunk, enableInlineScripts) && checkIsNode()) {
85
+ const fs = await import("node:fs/promises");
82
86
  const filepath = chunk.path;
83
- return fs.readFile(filepath, "utf-8").then((content) => `<script>${content}</script>`);
87
+ return fs.readFile(filepath, "utf-8").then((content) => `<script>${content}</script>`).catch((_) => {
88
+ return "";
89
+ });
84
90
  } else {
85
91
  return `<script${attributes} src="${chunk.url}"></script>`;
86
92
  }
87
93
  }));
88
- chunksMap.js += scripts.join("");
94
+ chunksMap.js += scripts.filter((script) => Boolean(script)).join("");
89
95
  }
90
96
  async emitStyleAssets(chunks) {
91
97
  const { template, result: { chunksMap }, config: { enableInlineStyles } } = this.options;
@@ -94,14 +100,17 @@ class LoadableCollector {
94
100
  var _this_existsAssets;
95
101
  const cssChunkReg = new RegExp(`<link .*href="${chunk.url}".*>`);
96
102
  return !cssChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
97
- }).map((chunk) => {
98
- if (checkIsInline(chunk, enableInlineStyles)) {
99
- return fs.readFile(chunk.path).then((content) => `<style>${content}</style>`);
103
+ }).map(async (chunk) => {
104
+ if (checkIsInline(chunk, enableInlineStyles) && checkIsNode()) {
105
+ const fs = await import("node:fs/promises");
106
+ return fs.readFile(chunk.path).then((content) => `<style>${content}</style>`).catch((_) => {
107
+ return "";
108
+ });
100
109
  } else {
101
110
  return `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
102
111
  }
103
112
  }));
104
- chunksMap.css += css.join("");
113
+ chunksMap.css += css.filter((css2) => Boolean(css2)).join("");
105
114
  }
106
115
  generateAttributes(extraAtr = {}) {
107
116
  const { config } = this.options;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.38.0",
18
+ "version": "2.39.1",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -171,10 +171,10 @@
171
171
  "react-side-effect": "^2.1.1",
172
172
  "styled-components": "^5.3.1",
173
173
  "@swc/helpers": "0.5.1",
174
- "@modern-js/plugin": "2.38.0",
175
- "@modern-js/types": "2.38.0",
176
- "@modern-js/utils": "2.38.0",
177
- "@modern-js/runtime-utils": "2.38.0"
174
+ "@modern-js/plugin": "2.39.1",
175
+ "@modern-js/types": "2.39.1",
176
+ "@modern-js/utils": "2.39.1",
177
+ "@modern-js/runtime-utils": "2.39.1"
178
178
  },
179
179
  "peerDependencies": {
180
180
  "react": ">=17",
@@ -195,11 +195,11 @@
195
195
  "ts-jest": "^29.1.0",
196
196
  "typescript": "^5",
197
197
  "webpack": "^5.88.1",
198
- "@modern-js/app-tools": "2.38.0",
199
- "@modern-js/core": "2.38.0",
200
- "@modern-js/server-core": "2.38.0",
201
- "@scripts/build": "2.38.0",
202
- "@scripts/jest-config": "2.38.0"
198
+ "@modern-js/app-tools": "2.39.1",
199
+ "@modern-js/core": "2.39.1",
200
+ "@modern-js/server-core": "2.39.1",
201
+ "@scripts/build": "2.39.1",
202
+ "@scripts/jest-config": "2.39.1"
203
203
  },
204
204
  "sideEffects": false,
205
205
  "publishConfig": {