@modern-js/runtime 2.60.3 → 2.60.5-alpha.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.
@@ -110,10 +110,15 @@ class LoadableCollector {
110
110
  nonce,
111
111
  ...scriptLoadingAtr
112
112
  }));
113
+ const jsScriptRegExp = /<script .*?src="([^"]+)".*?>/g;
114
+ const matchs = template.matchAll(jsScriptRegExp);
115
+ const existedScript = [];
116
+ for (const match of matchs) {
117
+ existedScript.push(match[1]);
118
+ }
113
119
  const scripts = await Promise.all(chunks.filter((chunk) => {
114
120
  var _this_existsAssets;
115
- const jsChunkReg = new RegExp(`<script .*src="${chunk.url}".*>`);
116
- return !jsChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
121
+ return !existedScript.includes(chunk.url) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
117
122
  }).map(async (chunk) => {
118
123
  const script = `<script${attributes} src="${chunk.url}"></script>`;
119
124
  if ((0, import_utils.checkIsNode)() && checkIsInline(chunk, enableInlineScripts)) {
@@ -130,10 +135,15 @@ class LoadableCollector {
130
135
  const { template, chunkSet, config } = this.options;
131
136
  const { enableInlineStyles } = config;
132
137
  const atrributes = (0, import_utils.attributesToString)(this.generateAttributes());
138
+ const linkRegExp = /<link .*?href="([^"]+)".*?>/g;
139
+ const matchs = template.matchAll(linkRegExp);
140
+ const existedLinks = [];
141
+ for (const match of matchs) {
142
+ existedLinks.push(match[1]);
143
+ }
133
144
  const css = await Promise.all(chunks.filter((chunk) => {
134
145
  var _this_existsAssets;
135
- const cssChunkReg = new RegExp(`<link .*href="${chunk.url}".*>`);
136
- return !cssChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
146
+ return !existedLinks.includes(chunk.url) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
137
147
  }).map(async (chunk) => {
138
148
  const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
139
149
  if ((0, import_utils.checkIsNode)() && checkIsInline(chunk, enableInlineStyles)) {
@@ -18,12 +18,15 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var hooks_exports = {};
20
20
  __export(hooks_exports, {
21
+ beforeCreateRouts: () => beforeCreateRouts,
21
22
  modifyRoutes: () => modifyRoutes
22
23
  });
23
24
  module.exports = __toCommonJS(hooks_exports);
24
25
  var import_plugin = require("@modern-js/plugin");
25
26
  const modifyRoutes = (0, import_plugin.createWaterfall)();
27
+ const beforeCreateRouts = (0, import_plugin.createAsyncInterruptWorkflow)();
26
28
  // Annotate the CommonJS export names for ESM import in node:
27
29
  0 && (module.exports = {
30
+ beforeCreateRouts,
28
31
  modifyRoutes
29
32
  });
@@ -61,7 +61,8 @@ const routerPlugin = (userConfig = {}) => {
61
61
  return {
62
62
  name: "@modern-js/plugin-router",
63
63
  registerHook: {
64
- modifyRoutes: import_hooks.modifyRoutes
64
+ modifyRoutes: import_hooks.modifyRoutes,
65
+ beforeCreateRouts: import_hooks.beforeCreateRouts
65
66
  },
66
67
  setup: (api) => {
67
68
  let finalRouteConfig = {};
@@ -84,6 +85,8 @@ const routerPlugin = (userConfig = {}) => {
84
85
  const { reporter } = context.ssrContext;
85
86
  const requestContext = (0, import_node.createRequestContext)((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
86
87
  requestContext.set(import_node.reporterCtx, reporter);
88
+ const runner = api.useHookRunners();
89
+ await runner.beforeCreateRouts(context);
87
90
  let routes = createRoutes ? createRoutes() : (0, import_router2.createRoutesFromElements)((0, import_utils.renderRoutes)({
88
91
  routesConfig: finalRouteConfig,
89
92
  ssrMode,
@@ -92,7 +95,6 @@ const routerPlugin = (userConfig = {}) => {
92
95
  },
93
96
  reporter
94
97
  }));
95
- const runner = api.useHookRunners();
96
98
  routes = runner.modifyRoutes(routes);
97
99
  const { query } = (0, import_remix_router.createStaticHandler)(routes, {
98
100
  basename: _basename
@@ -133,7 +133,7 @@ var LoadableCollector = /* @__PURE__ */ function() {
133
133
  _proto.emitScriptAssets = function emitScriptAssets(chunks) {
134
134
  var _this = this;
135
135
  return _async_to_generator(function() {
136
- var _this_options, template, nonce, chunkSet, config, _config_scriptLoading, scriptLoading, enableInlineScripts, scriptLoadingAtr, attributes, scripts;
136
+ var _this_options, template, nonce, chunkSet, config, _config_scriptLoading, scriptLoading, enableInlineScripts, scriptLoadingAtr, attributes, jsScriptRegExp, matchs, existedScript, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, match, scripts;
137
137
  return _ts_generator(this, function(_state) {
138
138
  switch (_state.label) {
139
139
  case 0:
@@ -147,12 +147,34 @@ var LoadableCollector = /* @__PURE__ */ function() {
147
147
  attributes = attributesToString(_this.generateAttributes(_object_spread({
148
148
  nonce
149
149
  }, scriptLoadingAtr)));
150
+ jsScriptRegExp = /<script .*?src="([^"]+)".*?>/g;
151
+ matchs = template.matchAll(jsScriptRegExp);
152
+ existedScript = [];
153
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
154
+ try {
155
+ for (_iterator = matchs[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
156
+ match = _step.value;
157
+ existedScript.push(match[1]);
158
+ }
159
+ } catch (err) {
160
+ _didIteratorError = true;
161
+ _iteratorError = err;
162
+ } finally {
163
+ try {
164
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
165
+ _iterator.return();
166
+ }
167
+ } finally {
168
+ if (_didIteratorError) {
169
+ throw _iteratorError;
170
+ }
171
+ }
172
+ }
150
173
  return [
151
174
  4,
152
175
  Promise.all(chunks.filter(function(chunk) {
153
176
  var _this_existsAssets;
154
- var jsChunkReg = new RegExp('<script .*src="'.concat(chunk.url, '".*>'));
155
- return !jsChunkReg.test(template) && !((_this_existsAssets = _this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
177
+ return !existedScript.includes(chunk.url) && !((_this_existsAssets = _this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
156
178
  }).map(function() {
157
179
  var _ref = _async_to_generator(function(chunk) {
158
180
  var script;
@@ -198,19 +220,41 @@ var LoadableCollector = /* @__PURE__ */ function() {
198
220
  _proto.emitStyleAssets = function emitStyleAssets(chunks) {
199
221
  var _this = this;
200
222
  return _async_to_generator(function() {
201
- var _this_options, template, chunkSet, config, enableInlineStyles, atrributes, css;
223
+ var _this_options, template, chunkSet, config, enableInlineStyles, atrributes, linkRegExp, matchs, existedLinks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, match, css;
202
224
  return _ts_generator(this, function(_state) {
203
225
  switch (_state.label) {
204
226
  case 0:
205
227
  _this_options = _this.options, template = _this_options.template, chunkSet = _this_options.chunkSet, config = _this_options.config;
206
228
  enableInlineStyles = config.enableInlineStyles;
207
229
  atrributes = attributesToString(_this.generateAttributes());
230
+ linkRegExp = /<link .*?href="([^"]+)".*?>/g;
231
+ matchs = template.matchAll(linkRegExp);
232
+ existedLinks = [];
233
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
234
+ try {
235
+ for (_iterator = matchs[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
236
+ match = _step.value;
237
+ existedLinks.push(match[1]);
238
+ }
239
+ } catch (err) {
240
+ _didIteratorError = true;
241
+ _iteratorError = err;
242
+ } finally {
243
+ try {
244
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
245
+ _iterator.return();
246
+ }
247
+ } finally {
248
+ if (_didIteratorError) {
249
+ throw _iteratorError;
250
+ }
251
+ }
252
+ }
208
253
  return [
209
254
  4,
210
255
  Promise.all(chunks.filter(function(chunk) {
211
256
  var _this_existsAssets;
212
- var cssChunkReg = new RegExp('<link .*href="'.concat(chunk.url, '".*>'));
213
- return !cssChunkReg.test(template) && !((_this_existsAssets = _this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
257
+ return !existedLinks.includes(chunk.url) && !((_this_existsAssets = _this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
214
258
  }).map(function() {
215
259
  var _ref = _async_to_generator(function(chunk) {
216
260
  var link;
@@ -1,5 +1,7 @@
1
- import { createWaterfall } from "@modern-js/plugin";
1
+ import { createAsyncInterruptWorkflow, createWaterfall } from "@modern-js/plugin";
2
2
  var modifyRoutes = createWaterfall();
3
+ var beforeCreateRouts = createAsyncInterruptWorkflow();
3
4
  export {
5
+ beforeCreateRouts,
4
6
  modifyRoutes
5
7
  };
@@ -16,7 +16,7 @@ import { JSX_SHELL_STREAM_END_MARK } from "../../common";
16
16
  import { RuntimeReactContext } from "../../core";
17
17
  import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
18
18
  import DeferredDataScripts from "./DeferredDataScripts.node";
19
- import { modifyRoutes as modifyRoutesHook } from "./hooks";
19
+ import { beforeCreateRouts as beforeCreateRoutsHook, modifyRoutes as modifyRoutesHook } from "./hooks";
20
20
  import { renderRoutes, urlJoin } from "./utils";
21
21
  function createRemixReuqest(request) {
22
22
  var method = "GET";
@@ -33,14 +33,15 @@ var routerPlugin = function() {
33
33
  return {
34
34
  name: "@modern-js/plugin-router",
35
35
  registerHook: {
36
- modifyRoutes: modifyRoutesHook
36
+ modifyRoutes: modifyRoutesHook,
37
+ beforeCreateRouts: beforeCreateRoutsHook
37
38
  },
38
39
  setup: function(api) {
39
40
  var finalRouteConfig = {};
40
41
  return {
41
42
  beforeRender: function beforeRender(context, interrupt) {
42
43
  return _async_to_generator(function() {
43
- var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1, pluginConfig, _merge, _merge_basename, basename, routesConfig, createRoutes, _context_ssrContext2, request, ssrMode, nonce, _context_ssrContext_loaderFailureMode, loaderFailureMode, baseUrl, _basename, reporter, requestContext, routes, runner, query, remixRequest, end, routerContext, cost, router;
44
+ var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1, pluginConfig, _merge, _merge_basename, basename, routesConfig, createRoutes, _context_ssrContext2, request, ssrMode, nonce, _context_ssrContext_loaderFailureMode, loaderFailureMode, baseUrl, _basename, reporter, requestContext, runner, routes, query, remixRequest, end, routerContext, cost, router;
44
45
  return _ts_generator(this, function(_state) {
45
46
  switch (_state.label) {
46
47
  case 0:
@@ -61,6 +62,13 @@ var routerPlugin = function() {
61
62
  reporter = context.ssrContext.reporter;
62
63
  requestContext = createRequestContext((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
63
64
  requestContext.set(reporterCtx, reporter);
65
+ runner = api.useHookRunners();
66
+ return [
67
+ 4,
68
+ runner.beforeCreateRouts(context)
69
+ ];
70
+ case 1:
71
+ _state.sent();
64
72
  routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
65
73
  routesConfig: finalRouteConfig,
66
74
  ssrMode,
@@ -69,7 +77,6 @@ var routerPlugin = function() {
69
77
  },
70
78
  reporter
71
79
  }));
72
- runner = api.useHookRunners();
73
80
  routes = runner.modifyRoutes(routes);
74
81
  query = createStaticHandler(routes, {
75
82
  basename: _basename
@@ -82,7 +89,7 @@ var routerPlugin = function() {
82
89
  requestContext
83
90
  })
84
91
  ];
85
- case 1:
92
+ case 2:
86
93
  routerContext = _state.sent();
87
94
  cost = end();
88
95
  (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : (_context_ssrContext_onTiming = _context_ssrContext1.onTiming) === null || _context_ssrContext_onTiming === void 0 ? void 0 : _context_ssrContext_onTiming.call(_context_ssrContext1, LOADER_REPORTER_NAME, cost);
@@ -77,10 +77,15 @@ class LoadableCollector {
77
77
  nonce,
78
78
  ...scriptLoadingAtr
79
79
  }));
80
+ const jsScriptRegExp = /<script .*?src="([^"]+)".*?>/g;
81
+ const matchs = template.matchAll(jsScriptRegExp);
82
+ const existedScript = [];
83
+ for (const match of matchs) {
84
+ existedScript.push(match[1]);
85
+ }
80
86
  const scripts = await Promise.all(chunks.filter((chunk) => {
81
87
  var _this_existsAssets;
82
- const jsChunkReg = new RegExp(`<script .*src="${chunk.url}".*>`);
83
- return !jsChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
88
+ return !existedScript.includes(chunk.url) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
84
89
  }).map(async (chunk) => {
85
90
  const script = `<script${attributes} src="${chunk.url}"></script>`;
86
91
  if (checkIsNode() && checkIsInline(chunk, enableInlineScripts)) {
@@ -97,10 +102,15 @@ class LoadableCollector {
97
102
  const { template, chunkSet, config } = this.options;
98
103
  const { enableInlineStyles } = config;
99
104
  const atrributes = attributesToString(this.generateAttributes());
105
+ const linkRegExp = /<link .*?href="([^"]+)".*?>/g;
106
+ const matchs = template.matchAll(linkRegExp);
107
+ const existedLinks = [];
108
+ for (const match of matchs) {
109
+ existedLinks.push(match[1]);
110
+ }
100
111
  const css = await Promise.all(chunks.filter((chunk) => {
101
112
  var _this_existsAssets;
102
- const cssChunkReg = new RegExp(`<link .*href="${chunk.url}".*>`);
103
- return !cssChunkReg.test(template) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
113
+ return !existedLinks.includes(chunk.url) && !((_this_existsAssets = this.existsAssets) === null || _this_existsAssets === void 0 ? void 0 : _this_existsAssets.includes(chunk.path));
104
114
  }).map(async (chunk) => {
105
115
  const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
106
116
  if (checkIsNode() && checkIsInline(chunk, enableInlineStyles)) {
@@ -1,5 +1,7 @@
1
- import { createWaterfall } from "@modern-js/plugin";
1
+ import { createAsyncInterruptWorkflow, createWaterfall } from "@modern-js/plugin";
2
2
  const modifyRoutes = createWaterfall();
3
+ const beforeCreateRouts = createAsyncInterruptWorkflow();
3
4
  export {
5
+ beforeCreateRouts,
4
6
  modifyRoutes
5
7
  };
@@ -11,7 +11,7 @@ import { JSX_SHELL_STREAM_END_MARK } from "../../common";
11
11
  import { RuntimeReactContext } from "../../core";
12
12
  import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
13
13
  import DeferredDataScripts from "./DeferredDataScripts.node";
14
- import { modifyRoutes as modifyRoutesHook } from "./hooks";
14
+ import { beforeCreateRouts as beforeCreateRoutsHook, modifyRoutes as modifyRoutesHook } from "./hooks";
15
15
  import { renderRoutes, urlJoin } from "./utils";
16
16
  function createRemixReuqest(request) {
17
17
  const method = "GET";
@@ -27,7 +27,8 @@ const routerPlugin = (userConfig = {}) => {
27
27
  return {
28
28
  name: "@modern-js/plugin-router",
29
29
  registerHook: {
30
- modifyRoutes: modifyRoutesHook
30
+ modifyRoutes: modifyRoutesHook,
31
+ beforeCreateRouts: beforeCreateRoutsHook
31
32
  },
32
33
  setup: (api) => {
33
34
  let finalRouteConfig = {};
@@ -50,6 +51,8 @@ const routerPlugin = (userConfig = {}) => {
50
51
  const { reporter } = context.ssrContext;
51
52
  const requestContext = createRequestContext((_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.loaderContext);
52
53
  requestContext.set(reporterCtx, reporter);
54
+ const runner = api.useHookRunners();
55
+ await runner.beforeCreateRouts(context);
53
56
  let routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
54
57
  routesConfig: finalRouteConfig,
55
58
  ssrMode,
@@ -58,7 +61,6 @@ const routerPlugin = (userConfig = {}) => {
58
61
  },
59
62
  reporter
60
63
  }));
61
- const runner = api.useHookRunners();
62
64
  routes = runner.modifyRoutes(routes);
63
65
  const { query } = createStaticHandler(routes, {
64
66
  basename: _basename
@@ -1,3 +1,5 @@
1
1
  import type { RouteObject } from '@modern-js/runtime-utils/router';
2
+ import type { RuntimeContext } from '../../core';
2
3
  declare const modifyRoutes: import("@modern-js/plugin").Waterfall<RouteObject[]>;
3
- export { modifyRoutes };
4
+ declare const beforeCreateRouts: import("@modern-js/plugin").AsyncInterruptWorkflow<RuntimeContext, void>;
5
+ export { modifyRoutes, beforeCreateRouts };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.60.3",
18
+ "version": "2.60.5-alpha.0",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -190,7 +190,7 @@
190
190
  "@types/loadable__component": "^5.13.4",
191
191
  "@types/react-helmet": "^6.1.2",
192
192
  "@types/styled-components": "^5.1.14",
193
- "cookie": "0.5.0",
193
+ "cookie": "0.7.2",
194
194
  "es-module-lexer": "^1.1.0",
195
195
  "esbuild": "0.17.19",
196
196
  "invariant": "^2.2.4",
@@ -199,11 +199,11 @@
199
199
  "react-is": "^18",
200
200
  "react-side-effect": "^2.1.1",
201
201
  "styled-components": "^5.3.1",
202
- "@modern-js/plugin": "2.60.3",
203
- "@modern-js/plugin-data-loader": "2.60.3",
204
- "@modern-js/runtime-utils": "2.60.3",
205
- "@modern-js/utils": "2.60.3",
206
- "@modern-js/types": "2.60.3"
202
+ "@modern-js/plugin": "2.60.4",
203
+ "@modern-js/runtime-utils": "2.60.4",
204
+ "@modern-js/types": "2.60.4",
205
+ "@modern-js/utils": "2.60.4",
206
+ "@modern-js/plugin-data-loader": "2.60.4"
207
207
  },
208
208
  "peerDependencies": {
209
209
  "react": ">=17",
@@ -221,21 +221,20 @@
221
221
  "@types/node": "^14",
222
222
  "@types/react-side-effect": "^1.1.1",
223
223
  "jest": "^29",
224
- "react": "^18",
225
- "react-dom": "^18",
224
+ "react": "^18.3.1",
225
+ "react-dom": "^18.3.1",
226
226
  "ts-jest": "^29.1.0",
227
227
  "typescript": "^5",
228
228
  "webpack": "^5.95.0",
229
- "@modern-js/app-tools": "2.60.3",
230
- "@scripts/build": "2.60.3",
231
- "@modern-js/core": "2.60.3",
232
- "@scripts/jest-config": "2.60.3"
229
+ "@modern-js/app-tools": "2.60.4",
230
+ "@scripts/build": "2.60.4",
231
+ "@modern-js/core": "2.60.4",
232
+ "@scripts/jest-config": "2.60.4"
233
233
  },
234
234
  "sideEffects": false,
235
235
  "publishConfig": {
236
236
  "registry": "https://registry.npmjs.org/",
237
- "access": "public",
238
- "provenance": true
237
+ "access": "public"
239
238
  },
240
239
  "scripts": {
241
240
  "dev": "modern-lib build --watch",