@modern-js/runtime 0.0.0-next-20231103131234 → 0.0.0-next-20231106062815

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.
@@ -85,29 +85,6 @@ const runtimePlugin = () => ({
85
85
  }
86
86
  };
87
87
  },
88
- validateSchema() {
89
- return [
90
- {
91
- target: "runtime",
92
- schema: {
93
- type: "object",
94
- additionalProperties: false
95
- }
96
- },
97
- {
98
- target: "runtimeByEntries",
99
- schema: {
100
- type: "object",
101
- patternProperties: {
102
- [import_utils.ENTRY_NAME_PATTERN]: {
103
- type: "object"
104
- }
105
- },
106
- additionalProperties: false
107
- }
108
- }
109
- ];
110
- },
111
88
  async beforeRestart() {
112
89
  (0, import_utils.cleanRequireCache)([
113
90
  require.resolve("../state/cli"),
@@ -53,19 +53,6 @@ const routerPlugin = () => ({
53
53
  }
54
54
  };
55
55
  },
56
- validateSchema() {
57
- return [
58
- {
59
- target: "runtime.router",
60
- schema: {
61
- type: [
62
- "boolean",
63
- "object"
64
- ]
65
- }
66
- }
67
- ];
68
- },
69
56
  modifyEntryImports({ entrypoint, imports }) {
70
57
  const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
71
58
  const userConfig = api.useResolvedConfigContext();
@@ -52,6 +52,12 @@ const checkIsInline = (chunk, enableInline) => {
52
52
  return false;
53
53
  }
54
54
  };
55
+ const readAsset = async (chunk) => {
56
+ const fs = await Promise.resolve().then(() => __toESM(require("node:fs/promises")));
57
+ const path = await Promise.resolve().then(() => __toESM(require("node:path")));
58
+ const filepath = path.resolve(__dirname, chunk.filename);
59
+ return fs.readFile(filepath, "utf-8");
60
+ };
55
61
  const checkIsNode = () => {
56
62
  var _process_release;
57
63
  return typeof process !== "undefined" && ((_process_release = process.release) === null || _process_release === void 0 ? void 0 : _process_release.name) === "node";
@@ -114,14 +120,13 @@ class LoadableCollector {
114
120
  const jsChunkReg = new RegExp(`<script .*src="${chunk.url}".*>`);
115
121
  return !jsChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
116
122
  }).map(async (chunk) => {
123
+ const script = `<script${attributes} src="${chunk.url}"></script>`;
117
124
  if (checkIsInline(chunk, enableInlineScripts) && checkIsNode()) {
118
- const fs = await Promise.resolve().then(() => __toESM(require("node:fs/promises")));
119
- const filepath = chunk.path;
120
- return fs.readFile(filepath, "utf-8").then((content) => `<script>${content}</script>`).catch((_) => {
121
- return "";
125
+ return readAsset(chunk).then((content) => `<script>${content}</script>`).catch((_) => {
126
+ return script;
122
127
  });
123
128
  } else {
124
- return `<script${attributes} src="${chunk.url}"></script>`;
129
+ return script;
125
130
  }
126
131
  }));
127
132
  chunksMap.js += scripts.filter((script) => Boolean(script)).join("");
@@ -134,13 +139,13 @@ class LoadableCollector {
134
139
  const cssChunkReg = new RegExp(`<link .*href="${chunk.url}".*>`);
135
140
  return !cssChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
136
141
  }).map(async (chunk) => {
142
+ const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
137
143
  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 "";
144
+ return readAsset(chunk).then((content) => `<style>${content}</style>`).catch((_) => {
145
+ return link;
141
146
  });
142
147
  } else {
143
- return `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
148
+ return link;
144
149
  }
145
150
  }));
146
151
  chunksMap.css += css.filter((css2) => Boolean(css2)).join("");
@@ -79,19 +79,6 @@ const statePlugin = () => ({
79
79
  plugins
80
80
  };
81
81
  },
82
- validateSchema() {
83
- return [
84
- {
85
- target: "runtime.state",
86
- schema: {
87
- type: [
88
- "boolean",
89
- "object"
90
- ]
91
- }
92
- }
93
- ];
94
- },
95
82
  addRuntimeExports() {
96
83
  pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/model'`);
97
84
  }
@@ -1,8 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
3
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
3
  import path from "path";
5
- import { isReact18, cleanRequireCache, ENTRY_NAME_PATTERN } from "@modern-js/utils";
4
+ import { isReact18, cleanRequireCache } from "@modern-js/utils";
6
5
  import { statePlugin } from "../state/cli";
7
6
  import { ssrPlugin } from "../ssr/cli";
8
7
  import { routerPlugin } from "../router/cli";
@@ -55,27 +54,6 @@ var runtimePlugin = function() {
55
54
  }
56
55
  };
57
56
  },
58
- validateSchema: function validateSchema() {
59
- return [
60
- {
61
- target: "runtime",
62
- schema: {
63
- type: "object",
64
- additionalProperties: false
65
- }
66
- },
67
- {
68
- target: "runtimeByEntries",
69
- schema: {
70
- type: "object",
71
- patternProperties: _define_property({}, ENTRY_NAME_PATTERN, {
72
- type: "object"
73
- }),
74
- additionalProperties: false
75
- }
76
- }
77
- ];
78
- },
79
57
  beforeRestart: function beforeRestart() {
80
58
  return _async_to_generator(function() {
81
59
  return _ts_generator(this, function(_state) {
@@ -32,19 +32,6 @@ var routerPlugin = function() {
32
32
  }
33
33
  };
34
34
  },
35
- validateSchema: function validateSchema() {
36
- return [
37
- {
38
- target: "runtime.router",
39
- schema: {
40
- type: [
41
- "boolean",
42
- "object"
43
- ]
44
- }
45
- }
46
- ];
47
- },
48
35
  modifyEntryImports: function modifyEntryImports(param) {
49
36
  var entrypoint = param.entrypoint, imports = param.imports;
50
37
  var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, fileSystemRoutes = entrypoint.fileSystemRoutes;
@@ -31,6 +31,36 @@ var checkIsInline = function(chunk, enableInline) {
31
31
  return false;
32
32
  }
33
33
  };
34
+ var readAsset = function() {
35
+ var _ref = _async_to_generator(function(chunk) {
36
+ var fs, path, filepath;
37
+ return _ts_generator(this, function(_state) {
38
+ switch (_state.label) {
39
+ case 0:
40
+ return [
41
+ 4,
42
+ import("node:fs/promises")
43
+ ];
44
+ case 1:
45
+ fs = _state.sent();
46
+ return [
47
+ 4,
48
+ import("node:path")
49
+ ];
50
+ case 2:
51
+ path = _state.sent();
52
+ filepath = path.resolve(__dirname, chunk.filename);
53
+ return [
54
+ 2,
55
+ fs.readFile(filepath, "utf-8")
56
+ ];
57
+ }
58
+ });
59
+ });
60
+ return function readAsset2(chunk) {
61
+ return _ref.apply(this, arguments);
62
+ };
63
+ }();
34
64
  var checkIsNode = function() {
35
65
  var _process_release;
36
66
  return typeof process !== "undefined" && ((_process_release = process.release) === null || _process_release === void 0 ? void 0 : _process_release.name) === "node";
@@ -151,40 +181,27 @@ var LoadableCollector = /* @__PURE__ */ function() {
151
181
  return !jsChunkReg.test(template) && !((_this_existsAssets = _this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
152
182
  }).map(function() {
153
183
  var _ref = _async_to_generator(function(chunk) {
154
- var fs, filepath;
184
+ var script;
155
185
  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
- ];
186
+ script = "<script".concat(attributes, ' src="').concat(chunk.url, '"></script>');
187
+ if (checkIsInline(chunk, enableInlineScripts) && checkIsNode()) {
188
+ return [
189
+ 2,
190
+ readAsset(chunk).then(function(content) {
191
+ return "<script>".concat(content, "</script>");
192
+ }).catch(function(_) {
193
+ return script;
194
+ })
195
+ ];
196
+ } else {
197
+ return [
198
+ 2,
199
+ script
200
+ ];
187
201
  }
202
+ return [
203
+ 2
204
+ ];
188
205
  });
189
206
  });
190
207
  return function(chunk) {
@@ -224,39 +241,27 @@ var LoadableCollector = /* @__PURE__ */ function() {
224
241
  return !cssChunkReg.test(template) && !((_this_existsAssets = _this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
225
242
  }).map(function() {
226
243
  var _ref = _async_to_generator(function(chunk) {
227
- var fs;
244
+ var link;
228
245
  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
- ];
246
+ link = "<link".concat(atrributes, ' href="').concat(chunk.url, '" rel="stylesheet" />');
247
+ if (checkIsInline(chunk, enableInlineStyles) && checkIsNode()) {
248
+ return [
249
+ 2,
250
+ readAsset(chunk).then(function(content) {
251
+ return "<style>".concat(content, "</style>");
252
+ }).catch(function(_) {
253
+ return link;
254
+ })
255
+ ];
256
+ } else {
257
+ return [
258
+ 2,
259
+ link
260
+ ];
259
261
  }
262
+ return [
263
+ 2
264
+ ];
260
265
  });
261
266
  });
262
267
  return function(chunk) {
@@ -58,19 +58,6 @@ var statePlugin = function() {
58
58
  plugins
59
59
  };
60
60
  },
61
- validateSchema: function validateSchema() {
62
- return [
63
- {
64
- target: "runtime.state",
65
- schema: {
66
- type: [
67
- "boolean",
68
- "object"
69
- ]
70
- }
71
- }
72
- ];
73
- },
74
61
  addRuntimeExports: function addRuntimeExports() {
75
62
  pluginsExportsUtils.addExport("export { default as state } from '@modern-js/runtime/model'");
76
63
  }
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { isReact18, cleanRequireCache, ENTRY_NAME_PATTERN } from "@modern-js/utils";
2
+ import { isReact18, cleanRequireCache } from "@modern-js/utils";
3
3
  import { statePlugin } from "../state/cli";
4
4
  import { ssrPlugin } from "../ssr/cli";
5
5
  import { routerPlugin } from "../router/cli";
@@ -51,29 +51,6 @@ const runtimePlugin = () => ({
51
51
  }
52
52
  };
53
53
  },
54
- validateSchema() {
55
- return [
56
- {
57
- target: "runtime",
58
- schema: {
59
- type: "object",
60
- additionalProperties: false
61
- }
62
- },
63
- {
64
- target: "runtimeByEntries",
65
- schema: {
66
- type: "object",
67
- patternProperties: {
68
- [ENTRY_NAME_PATTERN]: {
69
- type: "object"
70
- }
71
- },
72
- additionalProperties: false
73
- }
74
- }
75
- ];
76
- },
77
54
  async beforeRestart() {
78
55
  cleanRequireCache([
79
56
  require.resolve("../state/cli"),
@@ -29,19 +29,6 @@ const routerPlugin = () => ({
29
29
  }
30
30
  };
31
31
  },
32
- validateSchema() {
33
- return [
34
- {
35
- target: "runtime.router",
36
- schema: {
37
- type: [
38
- "boolean",
39
- "object"
40
- ]
41
- }
42
- }
43
- ];
44
- },
45
32
  modifyEntryImports({ entrypoint, imports }) {
46
33
  const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
47
34
  const userConfig = api.useResolvedConfigContext();
@@ -19,6 +19,12 @@ const checkIsInline = (chunk, enableInline) => {
19
19
  return false;
20
20
  }
21
21
  };
22
+ const readAsset = async (chunk) => {
23
+ const fs = await import("node:fs/promises");
24
+ const path = await import("node:path");
25
+ const filepath = path.resolve(__dirname, chunk.filename);
26
+ return fs.readFile(filepath, "utf-8");
27
+ };
22
28
  const checkIsNode = () => {
23
29
  var _process_release;
24
30
  return typeof process !== "undefined" && ((_process_release = process.release) === null || _process_release === void 0 ? void 0 : _process_release.name) === "node";
@@ -81,14 +87,13 @@ class LoadableCollector {
81
87
  const jsChunkReg = new RegExp(`<script .*src="${chunk.url}".*>`);
82
88
  return !jsChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
83
89
  }).map(async (chunk) => {
90
+ const script = `<script${attributes} src="${chunk.url}"></script>`;
84
91
  if (checkIsInline(chunk, enableInlineScripts) && checkIsNode()) {
85
- const fs = await import("node:fs/promises");
86
- const filepath = chunk.path;
87
- return fs.readFile(filepath, "utf-8").then((content) => `<script>${content}</script>`).catch((_) => {
88
- return "";
92
+ return readAsset(chunk).then((content) => `<script>${content}</script>`).catch((_) => {
93
+ return script;
89
94
  });
90
95
  } else {
91
- return `<script${attributes} src="${chunk.url}"></script>`;
96
+ return script;
92
97
  }
93
98
  }));
94
99
  chunksMap.js += scripts.filter((script) => Boolean(script)).join("");
@@ -101,13 +106,13 @@ class LoadableCollector {
101
106
  const cssChunkReg = new RegExp(`<link .*href="${chunk.url}".*>`);
102
107
  return !cssChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
103
108
  }).map(async (chunk) => {
109
+ const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
104
110
  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 "";
111
+ return readAsset(chunk).then((content) => `<style>${content}</style>`).catch((_) => {
112
+ return link;
108
113
  });
109
114
  } else {
110
- return `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
115
+ return link;
111
116
  }
112
117
  }));
113
118
  chunksMap.css += css.filter((css2) => Boolean(css2)).join("");
@@ -55,19 +55,6 @@ const statePlugin = () => ({
55
55
  plugins
56
56
  };
57
57
  },
58
- validateSchema() {
59
- return [
60
- {
61
- target: "runtime.state",
62
- schema: {
63
- type: [
64
- "boolean",
65
- "object"
66
- ]
67
- }
68
- }
69
- ];
70
- },
71
58
  addRuntimeExports() {
72
59
  pluginsExportsUtils.addExport(`export { default as state } from '@modern-js/runtime/model'`);
73
60
  }
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-next-20231103131234",
18
+ "version": "0.0.0-next-20231106062815",
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": "0.0.0-next-20231103131234",
175
- "@modern-js/utils": "0.0.0-next-20231103131234",
176
- "@modern-js/types": "0.0.0-next-20231103131234",
177
- "@modern-js/runtime-utils": "0.0.0-next-20231103131234"
174
+ "@modern-js/plugin": "0.0.0-next-20231106062815",
175
+ "@modern-js/types": "0.0.0-next-20231106062815",
176
+ "@modern-js/utils": "0.0.0-next-20231106062815",
177
+ "@modern-js/runtime-utils": "0.0.0-next-20231106062815"
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": "0.0.0-next-20231103131234",
199
- "@modern-js/core": "0.0.0-next-20231103131234",
200
- "@modern-js/server-core": "0.0.0-next-20231103131234",
201
- "@scripts/build": "0.0.0-next-20231103131234",
202
- "@scripts/jest-config": "0.0.0-next-20231103131234"
198
+ "@modern-js/app-tools": "0.0.0-next-20231106062815",
199
+ "@modern-js/core": "0.0.0-next-20231106062815",
200
+ "@modern-js/server-core": "0.0.0-next-20231106062815",
201
+ "@scripts/build": "0.0.0-next-20231106062815",
202
+ "@scripts/jest-config": "0.0.0-next-20231106062815"
203
203
  },
204
204
  "sideEffects": false,
205
205
  "publishConfig": {