@modern-js/prod-server 2.35.0 → 2.36.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.
Files changed (151) hide show
  1. package/dist/cjs/constants.js +33 -27
  2. package/dist/cjs/index.js +41 -33
  3. package/dist/cjs/libs/context/context.js +86 -36
  4. package/dist/cjs/libs/context/index.js +27 -17
  5. package/dist/cjs/libs/hook-api/base.js +49 -30
  6. package/dist/cjs/libs/hook-api/index.js +36 -28
  7. package/dist/cjs/libs/hook-api/index.worker.js +39 -31
  8. package/dist/cjs/libs/hook-api/route.js +28 -11
  9. package/dist/cjs/libs/hook-api/template.js +27 -17
  10. package/dist/cjs/libs/hook-api/templateForStream.js +31 -14
  11. package/dist/cjs/libs/loadConfig.js +46 -29
  12. package/dist/cjs/libs/metrics.js +24 -7
  13. package/dist/cjs/libs/preload/flushServerHeader.js +30 -13
  14. package/dist/cjs/libs/preload/index.js +22 -5
  15. package/dist/cjs/libs/preload/parseLinks.js +54 -30
  16. package/dist/cjs/libs/preload/shouldFlushServerHeader.js +25 -15
  17. package/dist/cjs/libs/preload/transformLinks2String.js +27 -11
  18. package/dist/cjs/libs/proxy.js +29 -19
  19. package/dist/cjs/libs/render/cache/__tests__/cache.fun.test.js +40 -22
  20. package/dist/cjs/libs/render/cache/__tests__/cache.test.js +33 -41
  21. package/dist/cjs/libs/render/cache/__tests__/cacheable.js +24 -7
  22. package/dist/cjs/libs/render/cache/__tests__/error-configuration.js +24 -7
  23. package/dist/cjs/libs/render/cache/__tests__/matched-cache.js +24 -7
  24. package/dist/cjs/libs/render/cache/index.js +30 -18
  25. package/dist/cjs/libs/render/cache/page-caches/index.js +26 -9
  26. package/dist/cjs/libs/render/cache/page-caches/lru.js +39 -13
  27. package/dist/cjs/libs/render/cache/spr.js +62 -44
  28. package/dist/cjs/libs/render/cache/type.js +15 -3
  29. package/dist/cjs/libs/render/cache/util.js +49 -36
  30. package/dist/cjs/libs/render/index.js +56 -30
  31. package/dist/cjs/libs/render/measure.js +27 -17
  32. package/dist/cjs/libs/render/reader.js +50 -35
  33. package/dist/cjs/libs/render/ssr.js +52 -26
  34. package/dist/cjs/libs/render/static.js +44 -18
  35. package/dist/cjs/libs/render/type.js +24 -7
  36. package/dist/cjs/libs/render/utils.js +29 -19
  37. package/dist/cjs/libs/reporter.js +24 -7
  38. package/dist/cjs/libs/route/index.js +30 -20
  39. package/dist/cjs/libs/route/matcher.js +37 -20
  40. package/dist/cjs/libs/route/route.js +34 -17
  41. package/dist/cjs/libs/serveFile.js +40 -21
  42. package/dist/cjs/libs/serverTiming.js +27 -10
  43. package/dist/cjs/renderHtml.js +17 -20
  44. package/dist/cjs/server/index.js +74 -50
  45. package/dist/cjs/server/modernServer.js +136 -113
  46. package/dist/cjs/server/modernServerSplit.js +29 -12
  47. package/dist/cjs/type.js +15 -3
  48. package/dist/cjs/utils.js +41 -38
  49. package/dist/cjs/workerServer.js +48 -39
  50. package/dist/esm/constants.js +14 -6
  51. package/dist/esm/index.js +11 -5
  52. package/dist/esm/libs/context/context.js +33 -6
  53. package/dist/esm/libs/context/index.js +5 -2
  54. package/dist/esm/libs/hook-api/base.js +6 -2
  55. package/dist/esm/libs/hook-api/index.js +11 -5
  56. package/dist/esm/libs/hook-api/index.worker.js +16 -10
  57. package/dist/esm/libs/hook-api/route.js +4 -1
  58. package/dist/esm/libs/hook-api/template.js +6 -2
  59. package/dist/esm/libs/hook-api/templateForStream.js +4 -1
  60. package/dist/esm/libs/loadConfig.js +8 -3
  61. package/dist/esm/libs/metrics.js +3 -1
  62. package/dist/esm/libs/preload/flushServerHeader.js +9 -6
  63. package/dist/esm/libs/preload/parseLinks.js +13 -11
  64. package/dist/esm/libs/preload/shouldFlushServerHeader.js +6 -2
  65. package/dist/esm/libs/preload/transformLinks2String.js +5 -3
  66. package/dist/esm/libs/proxy.js +9 -5
  67. package/dist/esm/libs/render/cache/__tests__/cache.test.js +12 -12
  68. package/dist/esm/libs/render/cache/__tests__/cacheable.js +4 -1
  69. package/dist/esm/libs/render/cache/__tests__/error-configuration.js +4 -1
  70. package/dist/esm/libs/render/cache/__tests__/matched-cache.js +4 -1
  71. package/dist/esm/libs/render/cache/index.js +6 -3
  72. package/dist/esm/libs/render/cache/page-caches/index.js +5 -2
  73. package/dist/esm/libs/render/cache/page-caches/lru.js +4 -1
  74. package/dist/esm/libs/render/cache/spr.js +13 -9
  75. package/dist/esm/libs/render/cache/type.js +0 -1
  76. package/dist/esm/libs/render/cache/util.js +18 -8
  77. package/dist/esm/libs/render/index.js +17 -11
  78. package/dist/esm/libs/render/measure.js +15 -11
  79. package/dist/esm/libs/render/reader.js +17 -10
  80. package/dist/esm/libs/render/ssr.js +11 -8
  81. package/dist/esm/libs/render/static.js +5 -2
  82. package/dist/esm/libs/render/type.js +4 -1
  83. package/dist/esm/libs/render/utils.js +6 -2
  84. package/dist/esm/libs/reporter.js +4 -1
  85. package/dist/esm/libs/route/index.js +5 -2
  86. package/dist/esm/libs/route/matcher.js +6 -3
  87. package/dist/esm/libs/route/route.js +4 -1
  88. package/dist/esm/libs/serveFile.js +6 -2
  89. package/dist/esm/libs/serverTiming.js +4 -1
  90. package/dist/esm/renderHtml.js +133 -124
  91. package/dist/esm/server/index.js +14 -13
  92. package/dist/esm/server/modernServer.js +39 -47
  93. package/dist/esm/server/modernServerSplit.js +4 -1
  94. package/dist/esm/type.js +0 -1
  95. package/dist/esm/utils.js +23 -12
  96. package/dist/esm/workerServer.js +25 -22
  97. package/dist/esm-node/constants.js +14 -6
  98. package/dist/esm-node/index.js +11 -5
  99. package/dist/esm-node/libs/context/context.js +33 -6
  100. package/dist/esm-node/libs/context/index.js +5 -2
  101. package/dist/esm-node/libs/hook-api/base.js +6 -2
  102. package/dist/esm-node/libs/hook-api/index.js +10 -4
  103. package/dist/esm-node/libs/hook-api/index.worker.js +10 -4
  104. package/dist/esm-node/libs/hook-api/route.js +4 -1
  105. package/dist/esm-node/libs/hook-api/template.js +6 -2
  106. package/dist/esm-node/libs/hook-api/templateForStream.js +4 -1
  107. package/dist/esm-node/libs/loadConfig.js +8 -3
  108. package/dist/esm-node/libs/metrics.js +3 -1
  109. package/dist/esm-node/libs/preload/flushServerHeader.js +6 -3
  110. package/dist/esm-node/libs/preload/parseLinks.js +11 -9
  111. package/dist/esm-node/libs/preload/shouldFlushServerHeader.js +6 -2
  112. package/dist/esm-node/libs/preload/transformLinks2String.js +5 -3
  113. package/dist/esm-node/libs/proxy.js +6 -2
  114. package/dist/esm-node/libs/render/cache/__tests__/cache.test.js +7 -12
  115. package/dist/esm-node/libs/render/cache/__tests__/cacheable.js +4 -1
  116. package/dist/esm-node/libs/render/cache/__tests__/error-configuration.js +4 -1
  117. package/dist/esm-node/libs/render/cache/__tests__/matched-cache.js +4 -1
  118. package/dist/esm-node/libs/render/cache/index.js +5 -3
  119. package/dist/esm-node/libs/render/cache/page-caches/index.js +4 -1
  120. package/dist/esm-node/libs/render/cache/page-caches/lru.js +4 -1
  121. package/dist/esm-node/libs/render/cache/spr.js +7 -4
  122. package/dist/esm-node/libs/render/cache/type.js +0 -1
  123. package/dist/esm-node/libs/render/cache/util.js +18 -8
  124. package/dist/esm-node/libs/render/index.js +7 -3
  125. package/dist/esm-node/libs/render/measure.js +6 -2
  126. package/dist/esm-node/libs/render/reader.js +13 -7
  127. package/dist/esm-node/libs/render/ssr.js +4 -1
  128. package/dist/esm-node/libs/render/static.js +4 -1
  129. package/dist/esm-node/libs/render/type.js +4 -1
  130. package/dist/esm-node/libs/render/utils.js +6 -2
  131. package/dist/esm-node/libs/reporter.js +4 -1
  132. package/dist/esm-node/libs/route/index.js +5 -2
  133. package/dist/esm-node/libs/route/matcher.js +6 -3
  134. package/dist/esm-node/libs/route/route.js +4 -1
  135. package/dist/esm-node/libs/serveFile.js +6 -2
  136. package/dist/esm-node/libs/serverTiming.js +4 -1
  137. package/dist/esm-node/renderHtml.js +72 -63
  138. package/dist/esm-node/server/index.js +11 -10
  139. package/dist/esm-node/server/modernServer.js +29 -28
  140. package/dist/esm-node/server/modernServerSplit.js +4 -1
  141. package/dist/esm-node/type.js +0 -1
  142. package/dist/esm-node/utils.js +20 -9
  143. package/dist/esm-node/workerServer.js +12 -9
  144. package/dist/types/libs/context/context.d.ts +2 -1
  145. package/dist/types/type.d.ts +1 -0
  146. package/dist/types/utils.d.ts +1 -1
  147. package/package.json +9 -8
  148. package/dist/cjs/libs/logger.js +0 -123
  149. package/dist/esm/libs/logger.js +0 -125
  150. package/dist/esm-node/libs/logger.js +0 -106
  151. package/dist/types/libs/logger.d.ts +0 -61
@@ -1,26 +1,47 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "parseLinks", {
6
- enumerable: true,
7
- get: function() {
8
- return parseLinks;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
17
  }
18
+ return to;
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
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var parseLinks_exports = {};
30
+ __export(parseLinks_exports, {
31
+ parseLinks: () => parseLinks
10
32
  });
11
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
13
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
14
- const _utils = require("@modern-js/utils");
15
- const _nodehtmlparser = require("node-html-parser");
16
- const _remixrouter = require("@modern-js/utils/runtime/remix-router");
17
- const _runtimenode = require("@modern-js/utils/runtime-node");
33
+ module.exports = __toCommonJS(parseLinks_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ var import_node_html_parser = require("node-html-parser");
37
+ var import_remix_router = require("@modern-js/runtime-utils/remix-router");
38
+ var import_node = require("@modern-js/runtime-utils/node");
18
39
  async function parseLinks({ pathname, distDir, template }) {
19
40
  const links = await parseLinksFromRoutes(pathname, distDir);
20
41
  return links.concat(parseLinksFromHtml(template));
21
42
  }
22
43
  function parseLinksFromHtml(html) {
23
- const root = (0, _nodehtmlparser.parse)(html);
44
+ const root = (0, import_node_html_parser.parse)(html);
24
45
  const scripts = root.querySelectorAll("script").filter((elem) => Boolean(elem.getAttribute("src")));
25
46
  const css = root.querySelectorAll("link").filter((elem) => {
26
47
  const href = elem.getAttribute("href");
@@ -50,18 +71,18 @@ function parseLinksFromHtml(html) {
50
71
  }
51
72
  async function parseLinksFromRoutes(pathname, distDir) {
52
73
  const noopLinks = [];
53
- const nestedRoutesSpec = _path.default.join(distDir, _utils.NESTED_ROUTE_SPEC_FILE);
54
- const routesJsonPath = _path.default.join(distDir, _utils.ROUTE_SPEC_FILE);
55
- const routeManifestPath = _path.default.join(distDir, _utils.ROUTE_MANIFEST_FILE);
56
- if (!_utils.fs.existsSync(nestedRoutesSpec) || !_utils.fs.existsSync(routesJsonPath) || !_utils.fs.existsSync(routeManifestPath)) {
74
+ const nestedRoutesSpec = import_path.default.join(distDir, import_utils.NESTED_ROUTE_SPEC_FILE);
75
+ const routesJsonPath = import_path.default.join(distDir, import_utils.ROUTE_SPEC_FILE);
76
+ const routeManifestPath = import_path.default.join(distDir, import_utils.ROUTE_MANIFEST_FILE);
77
+ if (!import_utils.fs.existsSync(nestedRoutesSpec) || !import_utils.fs.existsSync(routesJsonPath) || !import_utils.fs.existsSync(routeManifestPath)) {
57
78
  return noopLinks;
58
79
  }
59
- const routesJson = await Promise.resolve(routesJsonPath).then((p) => /* @__PURE__ */ _interop_require_wildcard._(require(p)));
80
+ const routesJson = await Promise.resolve().then(() => __toESM(require(routesJsonPath)));
60
81
  const serverRoutes = routesJson.routes;
61
- const entry = (0, _runtimenode.matchEntry)(pathname, serverRoutes);
82
+ const entry = (0, import_node.matchEntry)(pathname, serverRoutes);
62
83
  if (entry) {
63
- var _routeAssets_entryName, _matches, _assets_filter, _assets, _assets_filter1, _assets1;
64
- const routes = await Promise.resolve(nestedRoutesSpec).then((p) => /* @__PURE__ */ _interop_require_wildcard._(require(p)));
84
+ var _routeAssets_entryName, _assets_filter, _assets_filter1;
85
+ const routes = await Promise.resolve().then(() => __toESM(require(nestedRoutesSpec)));
65
86
  const { entryName } = entry;
66
87
  if (!entryName) {
67
88
  return noopLinks;
@@ -70,27 +91,26 @@ async function parseLinksFromRoutes(pathname, distDir) {
70
91
  if (!entryRoutes) {
71
92
  return noopLinks;
72
93
  }
73
- const routesManifest = await Promise.resolve(routeManifestPath).then((p) => /* @__PURE__ */ _interop_require_wildcard._(require(p)));
94
+ const routesManifest = await Promise.resolve().then(() => __toESM(require(routeManifestPath)));
74
95
  const { routeAssets } = routesManifest;
75
- const matches = (0, _remixrouter.matchRoutes)(entryRoutes, pathname, entry.urlPath);
96
+ const matches = (0, import_remix_router.matchRoutes)(entryRoutes, pathname, entry.urlPath);
76
97
  const entryAssets = (_routeAssets_entryName = routeAssets[entryName]) === null || _routeAssets_entryName === void 0 ? void 0 : _routeAssets_entryName.assets;
77
- const assets = (_matches = matches) === null || _matches === void 0 ? void 0 : _matches.reduce((acc, match) => {
98
+ const assets = matches === null || matches === void 0 ? void 0 : matches.reduce((acc, match) => {
78
99
  const routeId = match.route.id;
79
100
  if (routeId) {
80
- var _matchedManifest;
81
101
  const matchedManifest = routeAssets[routeId];
82
- const assets2 = (_matchedManifest = matchedManifest) === null || _matchedManifest === void 0 ? void 0 : _matchedManifest.assets;
102
+ const assets2 = matchedManifest === null || matchedManifest === void 0 ? void 0 : matchedManifest.assets;
83
103
  if (Array.isArray(assets2)) {
84
104
  acc.push(...assets2);
85
105
  }
86
106
  }
87
107
  return acc;
88
108
  }, []).concat(entryAssets || []);
89
- const cssLinks = (_assets = assets) === null || _assets === void 0 ? void 0 : (_assets_filter = _assets.filter((asset) => asset.endsWith(".css"))) === null || _assets_filter === void 0 ? void 0 : _assets_filter.map((uri) => ({
109
+ const cssLinks = assets === null || assets === void 0 ? void 0 : (_assets_filter = assets.filter((asset) => asset.endsWith(".css"))) === null || _assets_filter === void 0 ? void 0 : _assets_filter.map((uri) => ({
90
110
  uri,
91
111
  as: "style"
92
112
  }));
93
- const scriptLinks = (_assets1 = assets) === null || _assets1 === void 0 ? void 0 : (_assets_filter1 = _assets1.filter((asset) => asset.endsWith(".js"))) === null || _assets_filter1 === void 0 ? void 0 : _assets_filter1.map((uri) => ({
113
+ const scriptLinks = assets === null || assets === void 0 ? void 0 : (_assets_filter1 = assets.filter((asset) => asset.endsWith(".js"))) === null || _assets_filter1 === void 0 ? void 0 : _assets_filter1.map((uri) => ({
94
114
  uri,
95
115
  as: "script"
96
116
  }));
@@ -98,3 +118,7 @@ async function parseLinksFromRoutes(pathname, distDir) {
98
118
  }
99
119
  return noopLinks;
100
120
  }
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ parseLinks
124
+ });
@@ -1,22 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- transformToRegExp: function() {
14
- return transformToRegExp;
15
- },
16
- shouldFlushServerHeader: function() {
17
- return shouldFlushServerHeader;
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var shouldFlushServerHeader_exports = {};
20
+ __export(shouldFlushServerHeader_exports, {
21
+ shouldFlushServerHeader: () => shouldFlushServerHeader,
22
+ transformToRegExp: () => transformToRegExp
19
23
  });
24
+ module.exports = __toCommonJS(shouldFlushServerHeader_exports);
20
25
  function transformToRegExp(input) {
21
26
  if (typeof input === "string") {
22
27
  return new RegExp(input);
@@ -40,3 +45,8 @@ function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
40
45
  }
41
46
  return false;
42
47
  }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ shouldFlushServerHeader,
51
+ transformToRegExp
52
+ });
@@ -1,14 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "transformLinks2String", {
6
- enumerable: true,
7
- get: function() {
8
- return transformLinks2String;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var transformLinks2String_exports = {};
20
+ __export(transformLinks2String_exports, {
21
+ transformLinks2String: () => transformLinks2String
10
22
  });
11
- const _shouldFlushServerHeader = require("./shouldFlushServerHeader");
23
+ module.exports = __toCommonJS(transformLinks2String_exports);
24
+ var import_shouldFlushServerHeader = require("./shouldFlushServerHeader");
12
25
  function transformLinks2String(links, preload) {
13
26
  if (typeof preload === "boolean") {
14
27
  return transformLinkToString(dedup(links));
@@ -18,7 +31,6 @@ function transformLinks2String(links, preload) {
18
31
  return resolveLinks;
19
32
  }
20
33
  function addInclude(links, include) {
21
- var _include;
22
34
  const images = [
23
35
  "gif",
24
36
  "jpg",
@@ -44,7 +56,7 @@ function addInclude(links, include) {
44
56
  "ttf",
45
57
  "otf"
46
58
  ];
47
- const includes = ((_include = include) === null || _include === void 0 ? void 0 : _include.map((item) => {
59
+ const includes = (include === null || include === void 0 ? void 0 : include.map((item) => {
48
60
  if (typeof item === "string") {
49
61
  const type = (() => {
50
62
  if (item.endsWith(".js")) {
@@ -77,7 +89,7 @@ function addInclude(links, include) {
77
89
  return links.concat(includes);
78
90
  }
79
91
  function removeExclude(links, exclude) {
80
- return exclude ? links.filter(({ uri }) => !(0, _shouldFlushServerHeader.transformToRegExp)(exclude).test(uri)) : links;
92
+ return exclude ? links.filter(({ uri }) => !(0, import_shouldFlushServerHeader.transformToRegExp)(exclude).test(uri)) : links;
81
93
  }
82
94
  function addAttributes(links, attributes) {
83
95
  const parseAttributes = (_attributes) => {
@@ -132,3 +144,7 @@ function transformLinkToString(links) {
132
144
  return as ? `<${uri}>; rel=${rel}; as=${as}${rest || ""}` : `<${uri}>; rel=${rel}${rest || ""}`;
133
145
  }).join(", ");
134
146
  }
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ transformLinks2String
150
+ });
@@ -1,24 +1,29 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- formatProxyOptions: function() {
14
- return formatProxyOptions;
15
- },
16
- createProxyHandler: function() {
17
- return createProxyHandler;
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var proxy_exports = {};
20
+ __export(proxy_exports, {
21
+ createProxyHandler: () => createProxyHandler,
22
+ formatProxyOptions: () => formatProxyOptions
19
23
  });
20
- const _httpproxymiddleware = require("http-proxy-middleware/dist/http-proxy-middleware");
21
- const _utils = require("../utils");
24
+ module.exports = __toCommonJS(proxy_exports);
25
+ var import_http_proxy_middleware = require("http-proxy-middleware/dist/http-proxy-middleware");
26
+ var import_utils = require("../utils");
22
27
  function formatProxyOptions(proxyOptions) {
23
28
  const ret = [];
24
29
  if (Array.isArray(proxyOptions)) {
@@ -51,12 +56,12 @@ function formatProxyOptions(proxyOptions) {
51
56
  return ret;
52
57
  }
53
58
  const createProxyHandler = (proxyOptions) => {
54
- (0, _utils.debug)("createProxyHandler", proxyOptions);
59
+ (0, import_utils.debug)("createProxyHandler", proxyOptions);
55
60
  const formattedOptionsList = formatProxyOptions(proxyOptions);
56
61
  const proxies = [];
57
62
  const handlers = [];
58
63
  for (const opts of formattedOptionsList) {
59
- const proxy = new _httpproxymiddleware.HttpProxyMiddleware(opts.context, opts);
64
+ const proxy = new import_http_proxy_middleware.HttpProxyMiddleware(opts.context, opts);
60
65
  const handler = async (ctx, next) => {
61
66
  const { req, res } = ctx;
62
67
  const bypassUrl = typeof opts.bypass === "function" ? opts.bypass(req, res, opts) : null;
@@ -87,3 +92,8 @@ const createProxyHandler = (proxyOptions) => {
87
92
  handleUpgrade
88
93
  };
89
94
  };
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ createProxyHandler,
98
+ formatProxyOptions
99
+ });
@@ -1,49 +1,67 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6
- const _url = /* @__PURE__ */ _interop_require_default._(require("url"));
7
- const _spr = require("../spr");
8
- const _util = require("../util");
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_url = __toESM(require("url"));
25
+ var import_spr = require("../spr");
26
+ var import_util = require("../util");
9
27
  describe("test spr util functions", () => {
10
28
  it("should return value correctly", () => {
11
- expect((0, _util.connectFactor)("bar", "foo")).toBe("bar-foo");
12
- expect((0, _util.fname)(1)).toBe("f1");
13
- expect((0, _util.namespaceHash)("modern", "!@#$%^&")).toBe("modern/!@#$%^&");
29
+ expect((0, import_util.connectFactor)("bar", "foo")).toBe("bar-foo");
30
+ expect((0, import_util.fname)(1)).toBe("f1");
31
+ expect((0, import_util.namespaceHash)("modern", "!@#$%^&")).toBe("modern/!@#$%^&");
14
32
  });
15
33
  it("should create or destroy instance correctly", () => {
16
- const ins1 = (0, _spr.createCache)();
17
- const ins2 = (0, _spr.createCache)();
34
+ const ins1 = (0, import_spr.createCache)();
35
+ const ins2 = (0, import_spr.createCache)();
18
36
  expect(ins1 === ins2).toBe(true);
19
- (0, _spr.destroyCache)();
20
- const ins3 = (0, _spr.createCache)();
37
+ (0, import_spr.destroyCache)();
38
+ const ins3 = (0, import_spr.createCache)();
21
39
  expect(ins1 === ins3).toBe(false);
22
40
  expect(ins2 === ins3).toBe(false);
23
41
  });
24
42
  it("should return function correctly", () => {
25
- const urlParams = (() => new _url.default.URLSearchParams())();
43
+ const urlParams = (() => new import_url.default.URLSearchParams())();
26
44
  urlParams.set("name", "modern");
27
- const getParam = (0, _util.valueFactory)(urlParams);
45
+ const getParam = (0, import_util.valueFactory)(urlParams);
28
46
  expect(getParam("name")).toBe("modern");
29
47
  const headers = {
30
48
  age: "12345"
31
49
  };
32
- const getHeader = (0, _util.valueFactory)(headers);
50
+ const getHeader = (0, import_util.valueFactory)(headers);
33
51
  expect(getHeader("age")).toBe("12345");
34
52
  });
35
53
  it("should add target html content", () => {
36
54
  const contentNoHead = "<div>123</div>";
37
- const html = (0, _util.cacheAddition)(contentNoHead, Math.random().toString());
55
+ const html = (0, import_util.cacheAddition)(contentNoHead, Math.random().toString());
38
56
  expect(html).toBe(contentNoHead);
39
57
  const contentWithHead = "<head></head><div>123</div>";
40
58
  const hash = Math.random().toString();
41
- const htmlWithHead = (0, _util.cacheAddition)(contentWithHead, hash);
59
+ const htmlWithHead = (0, import_util.cacheAddition)(contentWithHead, hash);
42
60
  expect(htmlWithHead).toBe(`<head><meta name="x-moden-spr" content="${hash}"></head><div>123</div>`);
43
61
  });
44
62
  it("should only invoke func one time", async () => {
45
63
  let index = 0;
46
- const fn = (0, _util.withCoalescedInvoke)(async () => new Promise((resolve) => {
64
+ const fn = (0, import_util.withCoalescedInvoke)(async () => new Promise((resolve) => {
47
65
  setTimeout(() => {
48
66
  index += 1;
49
67
  resolve(index);
@@ -61,13 +79,13 @@ describe("test spr util functions", () => {
61
79
  });
62
80
  it("should invoke sync or async", async () => {
63
81
  const foo = "";
64
- const async = await (0, _util.maybeSync)(() => new Promise((resolve) => {
82
+ const async = await (0, import_util.maybeSync)(() => new Promise((resolve) => {
65
83
  setTimeout(() => {
66
84
  resolve(foo);
67
85
  }, 100);
68
86
  }))(false);
69
87
  expect(async).toBeUndefined();
70
- const sync = await (0, _util.maybeSync)(() => new Promise((resolve) => {
88
+ const sync = await (0, import_util.maybeSync)(() => new Promise((resolve) => {
71
89
  setTimeout(() => {
72
90
  resolve(foo);
73
91
  }, 100);
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _spr = require("../spr");
6
- const _errorconfiguration = require("./error-configuration");
7
- const _cacheable = require("./cacheable");
8
- const _matchedcache = require("./matched-cache");
2
+ var import_spr = require("../spr");
3
+ var import_error_configuration = require("./error-configuration");
4
+ var import_cacheable = require("./cacheable");
5
+ var import_matched_cache = require("./matched-cache");
9
6
  const createCacheConfig = (config = {}) => ({
10
7
  excludes: null,
11
8
  includes: null,
@@ -19,9 +16,8 @@ const createCacheConfig = (config = {}) => ({
19
16
  jest.setTimeout(6e4);
20
17
  describe("cache", () => {
21
18
  it("should cache correctly", async () => {
22
- var _cacheResult;
23
- (0, _spr.destroyCache)();
24
- const cache = (0, _spr.createCache)();
19
+ (0, import_spr.destroyCache)();
20
+ const cache = (0, import_spr.createCache)();
25
21
  const context = {
26
22
  entry: "",
27
23
  pathname: "",
@@ -33,12 +29,12 @@ describe("cache", () => {
33
29
  await cache.set(context, content, cacheConfig, true);
34
30
  const cacheResult = await cache.get(context);
35
31
  expect(cacheResult).not.toBe(null);
36
- expect((_cacheResult = cacheResult) === null || _cacheResult === void 0 ? void 0 : _cacheResult.content).toBe("hello");
32
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe("hello");
37
33
  });
38
34
  it("should ignore cache set when cache config not exist", async () => {
39
- (0, _spr.destroyCache)();
40
- (0, _spr.destroyCache)();
41
- const cache = (0, _spr.createCache)();
35
+ (0, import_spr.destroyCache)();
36
+ (0, import_spr.destroyCache)();
37
+ const cache = (0, import_spr.createCache)();
42
38
  const context = {
43
39
  entry: "",
44
40
  pathname: "",
@@ -50,10 +46,10 @@ describe("cache", () => {
50
46
  expect(shouldCache).toBe(false);
51
47
  });
52
48
  it("should calcual cache key error", async () => {
53
- (0, _spr.destroyCache)();
54
- const cache = (0, _spr.createCache)();
49
+ (0, import_spr.destroyCache)();
50
+ const cache = (0, import_spr.createCache)();
55
51
  const content = "hello";
56
- for (const config of _errorconfiguration.errorConfiguration) {
52
+ for (const config of import_error_configuration.errorConfiguration) {
57
53
  const cacheConfig = createCacheConfig(config);
58
54
  const tmpEntry = Math.random().toString();
59
55
  const context = {
@@ -67,8 +63,8 @@ describe("cache", () => {
67
63
  }
68
64
  });
69
65
  it("should get nothing for diff requestKey", async () => {
70
- (0, _spr.destroyCache)();
71
- const cache = (0, _spr.createCache)();
66
+ (0, import_spr.destroyCache)();
67
+ const cache = (0, import_spr.createCache)();
72
68
  const context = {
73
69
  entry: "",
74
70
  pathname: "",
@@ -95,8 +91,8 @@ describe("cache", () => {
95
91
  expect(cacheResult).toBe(null);
96
92
  });
97
93
  it("should get nothing for diff cacheHash", async () => {
98
- (0, _spr.destroyCache)();
99
- const cache = (0, _spr.createCache)();
94
+ (0, import_spr.destroyCache)();
95
+ const cache = (0, import_spr.createCache)();
100
96
  const context = {
101
97
  entry: "",
102
98
  pathname: "",
@@ -125,10 +121,9 @@ describe("cache", () => {
125
121
  expect(cacheResult).toBe(null);
126
122
  });
127
123
  it("should get cache correctly", async () => {
128
- (0, _spr.destroyCache)();
129
- const cache = (0, _spr.createCache)();
130
- for (const cacheable of _cacheable.cacheabelAry) {
131
- var _cacheResult;
124
+ (0, import_spr.destroyCache)();
125
+ const cache = (0, import_spr.createCache)();
126
+ for (const cacheable of import_cacheable.cacheabelAry) {
132
127
  const context = {
133
128
  entry: "",
134
129
  pathname: cacheable.requestOpt.url,
@@ -138,14 +133,13 @@ describe("cache", () => {
138
133
  const cacheConfig = createCacheConfig(cacheable.cacheConfig || {});
139
134
  await cache.set(context, cacheable.content, cacheConfig, true);
140
135
  const cacheResult = await cache.get(context);
141
- expect((_cacheResult = cacheResult) === null || _cacheResult === void 0 ? void 0 : _cacheResult.content).toBe(cacheable.content);
136
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(cacheable.content);
142
137
  }
143
138
  });
144
139
  it("should match cache correctly", async () => {
145
- (0, _spr.destroyCache)();
146
- const cache = (0, _spr.createCache)();
147
- for (const cacheable of _matchedcache.matchedCacheableAry) {
148
- var _cacheResult;
140
+ (0, import_spr.destroyCache)();
141
+ const cache = (0, import_spr.createCache)();
142
+ for (const cacheable of import_matched_cache.matchedCacheableAry) {
149
143
  const [baseCacheable, matchOne, ...other] = cacheable;
150
144
  const { requestOpt = {}, cacheConfig, content } = baseCacheable;
151
145
  const context = {
@@ -162,7 +156,7 @@ describe("cache", () => {
162
156
  headers: matchOne.headers
163
157
  };
164
158
  const cacheResult = await cache.get(matchContext);
165
- expect((_cacheResult = cacheResult) === null || _cacheResult === void 0 ? void 0 : _cacheResult.content).toBe(content);
159
+ expect(cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.content).toBe(content);
166
160
  for (const notMatch of other) {
167
161
  const notMatchContext = {
168
162
  entry: "",
@@ -176,9 +170,8 @@ describe("cache", () => {
176
170
  }
177
171
  });
178
172
  it("should stale cache correctly", async () => {
179
- var _freshResult, _staleResult;
180
- (0, _spr.destroyCache)();
181
- const cache = (0, _spr.createCache)();
173
+ (0, import_spr.destroyCache)();
174
+ const cache = (0, import_spr.createCache)();
182
175
  const context = {
183
176
  entry: "",
184
177
  pathname: "",
@@ -192,19 +185,18 @@ describe("cache", () => {
192
185
  const shouldCache = await cache.set(context, content, config, true);
193
186
  expect(shouldCache.value).toBe(true);
194
187
  const freshResult = await cache.get(context);
195
- expect((_freshResult = freshResult) === null || _freshResult === void 0 ? void 0 : _freshResult.isStale).toBe(false);
188
+ expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isStale).toBe(false);
196
189
  await new Promise((resolve) => {
197
190
  setTimeout(() => {
198
191
  resolve();
199
192
  }, 6e3);
200
193
  });
201
194
  const staleResult = await cache.get(context);
202
- expect((_staleResult = staleResult) === null || _staleResult === void 0 ? void 0 : _staleResult.isStale).toBe(true);
195
+ expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isStale).toBe(true);
203
196
  });
204
197
  it("should garbage cache correctly", async () => {
205
- var _freshResult, _staleResult;
206
- (0, _spr.destroyCache)();
207
- const cache = (0, _spr.createCache)();
198
+ (0, import_spr.destroyCache)();
199
+ const cache = (0, import_spr.createCache)();
208
200
  const context = {
209
201
  entry: "",
210
202
  pathname: "",
@@ -219,13 +211,13 @@ describe("cache", () => {
219
211
  const shouldCache = await cache.set(context, content, config, true);
220
212
  expect(shouldCache.value).toBe(true);
221
213
  const freshResult = await cache.get(context);
222
- expect((_freshResult = freshResult) === null || _freshResult === void 0 ? void 0 : _freshResult.isGarbage).toBe(false);
214
+ expect(freshResult === null || freshResult === void 0 ? void 0 : freshResult.isGarbage).toBe(false);
223
215
  await new Promise((resolve) => {
224
216
  setTimeout(() => {
225
217
  resolve();
226
218
  }, 1e4);
227
219
  });
228
220
  const staleResult = await cache.get(context);
229
- expect((_staleResult = staleResult) === null || _staleResult === void 0 ? void 0 : _staleResult.isGarbage).toBe(true);
221
+ expect(staleResult === null || staleResult === void 0 ? void 0 : staleResult.isGarbage).toBe(true);
230
222
  });
231
223
  });
@@ -1,13 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "cacheabelAry", {
6
- enumerable: true,
7
- get: function() {
8
- return cacheabelAry;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var cacheable_exports = {};
20
+ __export(cacheable_exports, {
21
+ cacheabelAry: () => cacheabelAry
10
22
  });
23
+ module.exports = __toCommonJS(cacheable_exports);
11
24
  const cacheabelAry = [
12
25
  {
13
26
  requestOpt: {
@@ -74,3 +87,7 @@ const cacheabelAry = [
74
87
  content: "level3"
75
88
  }
76
89
  ];
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ cacheabelAry
93
+ });