@modern-js/prod-server 2.33.0 → 2.34.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.
- package/dist/cjs/libs/preload/flushServerHeader.js +3 -38
- package/dist/cjs/libs/preload/shouldFlushServerHeader.js +42 -0
- package/dist/cjs/libs/preload/transformLinks2String.js +115 -104
- package/dist/cjs/libs/render/index.js +4 -3
- package/dist/esm/libs/preload/flushServerHeader.js +0 -23
- package/dist/esm/libs/preload/shouldFlushServerHeader.js +23 -0
- package/dist/esm/libs/preload/transformLinks2String.js +130 -121
- package/dist/esm/libs/render/index.js +31 -20
- package/dist/esm-node/libs/preload/flushServerHeader.js +0 -23
- package/dist/esm-node/libs/preload/shouldFlushServerHeader.js +23 -0
- package/dist/esm-node/libs/preload/transformLinks2String.js +115 -104
- package/dist/esm-node/libs/render/index.js +2 -1
- package/dist/types/libs/context/context.d.ts +1 -1
- package/dist/types/libs/preload/flushServerHeader.d.ts +0 -2
- package/dist/types/libs/preload/parseLinks.d.ts +3 -0
- package/dist/types/libs/preload/shouldFlushServerHeader.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -1
- package/package.json +8 -8
- package/CHANGELOG.md +0 -1398
|
@@ -2,49 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
18
|
-
},
|
|
19
|
-
flushServerHeader: function() {
|
|
5
|
+
Object.defineProperty(exports, "flushServerHeader", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
20
8
|
return flushServerHeader;
|
|
21
9
|
}
|
|
22
10
|
});
|
|
23
11
|
const _parseLinks = require("./parseLinks");
|
|
24
12
|
const _transformLinks2String = require("./transformLinks2String");
|
|
25
|
-
function transformToRegExp(input) {
|
|
26
|
-
if (typeof input === "string") {
|
|
27
|
-
return new RegExp(input);
|
|
28
|
-
}
|
|
29
|
-
return input;
|
|
30
|
-
}
|
|
31
|
-
function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
32
|
-
const { ssr: ssrConf } = serverConf || {};
|
|
33
|
-
if (disablePreload) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
if (typeof ssrConf === "object" && ssrConf.preload) {
|
|
37
|
-
if (typeof ssrConf.preload === "object") {
|
|
38
|
-
const { userAgentFilter } = ssrConf.preload;
|
|
39
|
-
if (userAgentFilter && userAgent) {
|
|
40
|
-
return !transformToRegExp(userAgentFilter).test(userAgent);
|
|
41
|
-
}
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
13
|
async function flushServerHeader({ serverConf, ctx, distDir, template, headers }) {
|
|
49
14
|
const { ssr: ssrConf } = serverConf || {};
|
|
50
15
|
if (typeof ssrConf !== "object") {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
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;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
function transformToRegExp(input) {
|
|
21
|
+
if (typeof input === "string") {
|
|
22
|
+
return new RegExp(input);
|
|
23
|
+
}
|
|
24
|
+
return input;
|
|
25
|
+
}
|
|
26
|
+
function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
27
|
+
const { ssr: ssrConf } = serverConf || {};
|
|
28
|
+
if (disablePreload) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (typeof ssrConf === "object" && ssrConf.preload) {
|
|
32
|
+
if (typeof ssrConf.preload === "object") {
|
|
33
|
+
const { userAgentFilter } = ssrConf.preload;
|
|
34
|
+
if (userAgentFilter && userAgent) {
|
|
35
|
+
return !transformToRegExp(userAgentFilter).test(userAgent);
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
@@ -8,116 +8,127 @@ Object.defineProperty(exports, "transformLinks2String", {
|
|
|
8
8
|
return transformLinks2String;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _shouldFlushServerHeader = require("./shouldFlushServerHeader");
|
|
12
12
|
function transformLinks2String(links, preload) {
|
|
13
13
|
if (typeof preload === "boolean") {
|
|
14
|
-
return dedup(links)
|
|
14
|
+
return transformLinkToString(dedup(links));
|
|
15
15
|
}
|
|
16
16
|
const { include, exclude, attributes } = preload;
|
|
17
|
-
const resolveLinks = addAttributes(dedup(removeExclude(addInclude(links, include), exclude)), attributes);
|
|
18
|
-
return resolveLinks
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
uri: item,
|
|
67
|
-
as: type
|
|
68
|
-
};
|
|
69
|
-
}
|
|
17
|
+
const resolveLinks = transformLinkToString(addAttributes(dedup(removeExclude(addInclude(links, include), exclude)), attributes));
|
|
18
|
+
return resolveLinks;
|
|
19
|
+
}
|
|
20
|
+
function addInclude(links, include) {
|
|
21
|
+
var _include;
|
|
22
|
+
const images = [
|
|
23
|
+
"gif",
|
|
24
|
+
"jpg",
|
|
25
|
+
"jpeg",
|
|
26
|
+
"png",
|
|
27
|
+
"webp",
|
|
28
|
+
"bmp",
|
|
29
|
+
"tiff",
|
|
30
|
+
"anpg",
|
|
31
|
+
"ico"
|
|
32
|
+
];
|
|
33
|
+
const videos = [
|
|
34
|
+
"mp4",
|
|
35
|
+
"webm",
|
|
36
|
+
"ogm",
|
|
37
|
+
"ogv",
|
|
38
|
+
"ogg"
|
|
39
|
+
];
|
|
40
|
+
const fonts = [
|
|
41
|
+
"woff",
|
|
42
|
+
"woff2",
|
|
43
|
+
"eot",
|
|
44
|
+
"ttf",
|
|
45
|
+
"otf"
|
|
46
|
+
];
|
|
47
|
+
const includes = ((_include = include) === null || _include === void 0 ? void 0 : _include.map((item) => {
|
|
48
|
+
if (typeof item === "string") {
|
|
49
|
+
const type = (() => {
|
|
50
|
+
if (item.endsWith(".js")) {
|
|
51
|
+
return "script";
|
|
52
|
+
}
|
|
53
|
+
if (item.endsWith(".css")) {
|
|
54
|
+
return "style";
|
|
55
|
+
}
|
|
56
|
+
if (images.some((image) => item.endsWith(`.${image}`))) {
|
|
57
|
+
return "image";
|
|
58
|
+
}
|
|
59
|
+
if (videos.some((video) => item.endsWith(`.${video}`))) {
|
|
60
|
+
return "video";
|
|
61
|
+
}
|
|
62
|
+
if (fonts.some((font) => item.endsWith(`.${font}`))) {
|
|
63
|
+
return "font";
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
70
66
|
return {
|
|
71
|
-
uri: item
|
|
72
|
-
as:
|
|
67
|
+
uri: item,
|
|
68
|
+
as: type
|
|
73
69
|
};
|
|
74
|
-
}
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
function addAttributes(links2, attributes2) {
|
|
81
|
-
const parseAttributes = (_attributes) => {
|
|
82
|
-
return Object.entries(_attributes || {}).reduce((results, [key, value]) => {
|
|
83
|
-
if (typeof value === "boolean") {
|
|
84
|
-
value && results.push(`; ${key}`);
|
|
85
|
-
return results;
|
|
86
|
-
}
|
|
87
|
-
results.push(`; ${key}=${value}`);
|
|
88
|
-
return results;
|
|
89
|
-
}, []).join("");
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
uri: item.url,
|
|
73
|
+
as: item.as,
|
|
74
|
+
rel: item.rel
|
|
90
75
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return parseAttributes(font);
|
|
104
|
-
default:
|
|
105
|
-
return "";
|
|
106
|
-
}
|
|
107
|
-
})();
|
|
108
|
-
return `<${uri}>; rel=preload; as=${as}${attributesStr}`;
|
|
109
|
-
}
|
|
110
|
-
return `<${uri}>; rel=preload`;
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function dedup(links2) {
|
|
114
|
-
const set = /* @__PURE__ */ new Set();
|
|
115
|
-
return links2.filter(({ uri }) => {
|
|
116
|
-
if (set.has(uri)) {
|
|
117
|
-
return false;
|
|
76
|
+
})) || [];
|
|
77
|
+
return links.concat(includes);
|
|
78
|
+
}
|
|
79
|
+
function removeExclude(links, exclude) {
|
|
80
|
+
return exclude ? links.filter(({ uri }) => !(0, _shouldFlushServerHeader.transformToRegExp)(exclude).test(uri)) : links;
|
|
81
|
+
}
|
|
82
|
+
function addAttributes(links, attributes) {
|
|
83
|
+
const parseAttributes = (_attributes) => {
|
|
84
|
+
return Object.entries(_attributes || {}).reduce((results, [key, value]) => {
|
|
85
|
+
if (typeof value === "boolean") {
|
|
86
|
+
value && results.push(`; ${key}`);
|
|
87
|
+
return results;
|
|
118
88
|
}
|
|
119
|
-
|
|
120
|
-
return
|
|
121
|
-
});
|
|
122
|
-
}
|
|
89
|
+
results.push(`; ${key}=${value}`);
|
|
90
|
+
return results;
|
|
91
|
+
}, []).join("");
|
|
92
|
+
};
|
|
93
|
+
return links.map((link) => {
|
|
94
|
+
const { as } = link;
|
|
95
|
+
if (as) {
|
|
96
|
+
const attributesStr = (() => {
|
|
97
|
+
const { style, script, image, font } = attributes || {};
|
|
98
|
+
switch (as) {
|
|
99
|
+
case "script":
|
|
100
|
+
return parseAttributes(script);
|
|
101
|
+
case "style":
|
|
102
|
+
return parseAttributes(style);
|
|
103
|
+
case "image":
|
|
104
|
+
return parseAttributes(image);
|
|
105
|
+
case "font":
|
|
106
|
+
return parseAttributes(font);
|
|
107
|
+
default:
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
110
|
+
})();
|
|
111
|
+
return {
|
|
112
|
+
...link,
|
|
113
|
+
rest: attributesStr
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return link;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function dedup(links) {
|
|
120
|
+
const set = /* @__PURE__ */ new Set();
|
|
121
|
+
return links.filter(({ uri }) => {
|
|
122
|
+
if (set.has(uri)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
set.add(uri);
|
|
126
|
+
return true;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function transformLinkToString(links) {
|
|
130
|
+
return links.map(({ uri, as, rel: originalRel, rest }) => {
|
|
131
|
+
const rel = originalRel || "preload";
|
|
132
|
+
return as ? `<${uri}>; rel=${rel}; as=${as}${rest || ""}` : `<${uri}>; rel=${rel}${rest || ""}`;
|
|
133
|
+
}).join(", ");
|
|
123
134
|
}
|
|
@@ -13,7 +13,7 @@ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildc
|
|
|
13
13
|
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
14
14
|
const _utils = require("@modern-js/utils");
|
|
15
15
|
const _constants = require("../../constants");
|
|
16
|
-
const
|
|
16
|
+
const _shouldFlushServerHeader = require("../preload/shouldFlushServerHeader");
|
|
17
17
|
const _static = require("./static");
|
|
18
18
|
const _reader = require("./reader");
|
|
19
19
|
const _ssr = /* @__PURE__ */ _interop_require_wildcard._(require("./ssr"));
|
|
@@ -38,8 +38,9 @@ const createRenderHandler = ({ distDir, staticGenerate, conf, forceCSR, nonce, s
|
|
|
38
38
|
try {
|
|
39
39
|
const userAgent = ctx.getReqHeader("User-Agent");
|
|
40
40
|
const disablePreload = Boolean(ctx.headers[`x-${(0, _utils.cutNameByHyphen)(metaName)}-disable-preload`]);
|
|
41
|
-
if ((0,
|
|
42
|
-
(
|
|
41
|
+
if ((0, _shouldFlushServerHeader.shouldFlushServerHeader)(conf.server, userAgent, disablePreload)) {
|
|
42
|
+
const { flushServerHeader } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../preload")));
|
|
43
|
+
flushServerHeader({
|
|
43
44
|
serverConf: conf.server,
|
|
44
45
|
ctx,
|
|
45
46
|
distDir,
|
|
@@ -2,29 +2,6 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { parseLinks } from "./parseLinks";
|
|
4
4
|
import { transformLinks2String } from "./transformLinks2String";
|
|
5
|
-
export function transformToRegExp(input) {
|
|
6
|
-
if (typeof input === "string") {
|
|
7
|
-
return new RegExp(input);
|
|
8
|
-
}
|
|
9
|
-
return input;
|
|
10
|
-
}
|
|
11
|
-
export function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
12
|
-
var _ref = serverConf || {}, ssrConf = _ref.ssr;
|
|
13
|
-
if (disablePreload) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (typeof ssrConf === "object" && ssrConf.preload) {
|
|
17
|
-
if (typeof ssrConf.preload === "object") {
|
|
18
|
-
var userAgentFilter = ssrConf.preload.userAgentFilter;
|
|
19
|
-
if (userAgentFilter && userAgent) {
|
|
20
|
-
return !transformToRegExp(userAgentFilter).test(userAgent);
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
5
|
export function flushServerHeader(_) {
|
|
29
6
|
return _flushServerHeader.apply(this, arguments);
|
|
30
7
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function transformToRegExp(input) {
|
|
2
|
+
if (typeof input === "string") {
|
|
3
|
+
return new RegExp(input);
|
|
4
|
+
}
|
|
5
|
+
return input;
|
|
6
|
+
}
|
|
7
|
+
export function shouldFlushServerHeader(serverConf, userAgent, disablePreload) {
|
|
8
|
+
var _ref = serverConf || {}, ssrConf = _ref.ssr;
|
|
9
|
+
if (disablePreload) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (typeof ssrConf === "object" && ssrConf.preload) {
|
|
13
|
+
if (typeof ssrConf.preload === "object") {
|
|
14
|
+
var userAgentFilter = ssrConf.preload.userAgentFilter;
|
|
15
|
+
if (userAgentFilter && userAgent) {
|
|
16
|
+
return !transformToRegExp(userAgentFilter).test(userAgent);
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
@@ -1,129 +1,138 @@
|
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
1
3
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
|
-
import { transformToRegExp } from "./
|
|
4
|
+
import { transformToRegExp } from "./shouldFlushServerHeader";
|
|
3
5
|
export function transformLinks2String(links, preload) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
6
|
+
if (typeof preload === "boolean") {
|
|
7
|
+
return transformLinkToString(dedup(links));
|
|
8
|
+
}
|
|
9
|
+
var include = preload.include, exclude = preload.exclude, attributes = preload.attributes;
|
|
10
|
+
var resolveLinks = transformLinkToString(addAttributes(dedup(removeExclude(addInclude(links, include), exclude)), attributes));
|
|
11
|
+
return resolveLinks;
|
|
12
|
+
}
|
|
13
|
+
function addInclude(links, include) {
|
|
14
|
+
var _include;
|
|
15
|
+
var images = [
|
|
16
|
+
"gif",
|
|
17
|
+
"jpg",
|
|
18
|
+
"jpeg",
|
|
19
|
+
"png",
|
|
20
|
+
"webp",
|
|
21
|
+
"bmp",
|
|
22
|
+
"tiff",
|
|
23
|
+
"anpg",
|
|
24
|
+
"ico"
|
|
25
|
+
];
|
|
26
|
+
var videos = [
|
|
27
|
+
"mp4",
|
|
28
|
+
"webm",
|
|
29
|
+
"ogm",
|
|
30
|
+
"ogv",
|
|
31
|
+
"ogg"
|
|
32
|
+
];
|
|
33
|
+
var fonts = [
|
|
34
|
+
"woff",
|
|
35
|
+
"woff2",
|
|
36
|
+
"eot",
|
|
37
|
+
"ttf",
|
|
38
|
+
"otf"
|
|
39
|
+
];
|
|
40
|
+
var includes = ((_include = include) === null || _include === void 0 ? void 0 : _include.map(function(item) {
|
|
41
|
+
if (typeof item === "string") {
|
|
42
|
+
var type = function() {
|
|
43
|
+
if (item.endsWith(".js")) {
|
|
44
|
+
return "script";
|
|
45
|
+
}
|
|
46
|
+
if (item.endsWith(".css")) {
|
|
47
|
+
return "style";
|
|
48
|
+
}
|
|
49
|
+
if (images.some(function(image) {
|
|
50
|
+
return item.endsWith(".".concat(image));
|
|
51
|
+
})) {
|
|
52
|
+
return "image";
|
|
53
|
+
}
|
|
54
|
+
if (videos.some(function(video) {
|
|
55
|
+
return item.endsWith(".".concat(video));
|
|
56
|
+
})) {
|
|
57
|
+
return "video";
|
|
58
|
+
}
|
|
59
|
+
if (fonts.some(function(font) {
|
|
60
|
+
return item.endsWith(".".concat(font));
|
|
61
|
+
})) {
|
|
62
|
+
return "font";
|
|
63
|
+
}
|
|
64
|
+
}();
|
|
61
65
|
return {
|
|
62
|
-
uri: item
|
|
63
|
-
as:
|
|
66
|
+
uri: item,
|
|
67
|
+
as: type
|
|
64
68
|
};
|
|
65
|
-
}
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
var uri = param.uri;
|
|
71
|
-
return !transformToRegExp(exclude2).test(uri);
|
|
72
|
-
}) : links2;
|
|
73
|
-
};
|
|
74
|
-
var addAttributes = function addAttributes2(links2, attributes2) {
|
|
75
|
-
var parseAttributes = function(_attributes) {
|
|
76
|
-
return Object.entries(_attributes || {}).reduce(function(results, param) {
|
|
77
|
-
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
78
|
-
if (typeof value === "boolean") {
|
|
79
|
-
value && results.push("; ".concat(key));
|
|
80
|
-
return results;
|
|
81
|
-
}
|
|
82
|
-
results.push("; ".concat(key, "=").concat(value));
|
|
83
|
-
return results;
|
|
84
|
-
}, []).join("");
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
uri: item.url,
|
|
72
|
+
as: item.as,
|
|
73
|
+
rel: item.rel
|
|
85
74
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
}();
|
|
104
|
-
return "<".concat(uri, ">; rel=preload; as=").concat(as).concat(attributesStr);
|
|
105
|
-
}
|
|
106
|
-
return "<".concat(uri, ">; rel=preload");
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
var dedup = function dedup2(links2) {
|
|
110
|
-
var set = /* @__PURE__ */ new Set();
|
|
111
|
-
return links2.filter(function(param) {
|
|
112
|
-
var uri = param.uri;
|
|
113
|
-
if (set.has(uri)) {
|
|
114
|
-
return false;
|
|
75
|
+
})) || [];
|
|
76
|
+
return links.concat(includes);
|
|
77
|
+
}
|
|
78
|
+
function removeExclude(links, exclude) {
|
|
79
|
+
return exclude ? links.filter(function(param) {
|
|
80
|
+
var uri = param.uri;
|
|
81
|
+
return !transformToRegExp(exclude).test(uri);
|
|
82
|
+
}) : links;
|
|
83
|
+
}
|
|
84
|
+
function addAttributes(links, attributes) {
|
|
85
|
+
var parseAttributes = function(_attributes) {
|
|
86
|
+
return Object.entries(_attributes || {}).reduce(function(results, param) {
|
|
87
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
88
|
+
if (typeof value === "boolean") {
|
|
89
|
+
value && results.push("; ".concat(key));
|
|
90
|
+
return results;
|
|
115
91
|
}
|
|
116
|
-
|
|
117
|
-
return
|
|
118
|
-
});
|
|
92
|
+
results.push("; ".concat(key, "=").concat(value));
|
|
93
|
+
return results;
|
|
94
|
+
}, []).join("");
|
|
119
95
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
96
|
+
return links.map(function(link) {
|
|
97
|
+
var as = link.as;
|
|
98
|
+
if (as) {
|
|
99
|
+
var attributesStr = function() {
|
|
100
|
+
var _ref = attributes || {}, style = _ref.style, script = _ref.script, image = _ref.image, font = _ref.font;
|
|
101
|
+
switch (as) {
|
|
102
|
+
case "script":
|
|
103
|
+
return parseAttributes(script);
|
|
104
|
+
case "style":
|
|
105
|
+
return parseAttributes(style);
|
|
106
|
+
case "image":
|
|
107
|
+
return parseAttributes(image);
|
|
108
|
+
case "font":
|
|
109
|
+
return parseAttributes(font);
|
|
110
|
+
default:
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
}();
|
|
114
|
+
return _object_spread_props(_object_spread({}, link), {
|
|
115
|
+
rest: attributesStr
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return link;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function dedup(links) {
|
|
122
|
+
var set = /* @__PURE__ */ new Set();
|
|
123
|
+
return links.filter(function(param) {
|
|
124
|
+
var uri = param.uri;
|
|
125
|
+
if (set.has(uri)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
set.add(uri);
|
|
129
|
+
return true;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function transformLinkToString(links) {
|
|
133
|
+
return links.map(function(param) {
|
|
134
|
+
var uri = param.uri, as = param.as, originalRel = param.rel, rest = param.rest;
|
|
135
|
+
var rel = originalRel || "preload";
|
|
136
|
+
return as ? "<".concat(uri, ">; rel=").concat(rel, "; as=").concat(as).concat(rest || "") : "<".concat(uri, ">; rel=").concat(rel).concat(rest || "");
|
|
137
|
+
}).join(", ");
|
|
129
138
|
}
|