@cloudflare/pages-shared 0.11.41 → 0.11.42
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
1
2
|
import {
|
|
2
3
|
ANALYTICS_VERSION,
|
|
3
4
|
HEADERS_VERSION,
|
|
@@ -26,6 +27,8 @@ const noopLogger = {
|
|
|
26
27
|
export function createMetadataObject({
|
|
27
28
|
redirects,
|
|
28
29
|
headers,
|
|
30
|
+
redirectsFile,
|
|
31
|
+
headersFile,
|
|
29
32
|
webAnalyticsToken,
|
|
30
33
|
deploymentId,
|
|
31
34
|
failOpen,
|
|
@@ -33,14 +36,16 @@ export function createMetadataObject({
|
|
|
33
36
|
}: {
|
|
34
37
|
redirects?: ParsedRedirects;
|
|
35
38
|
headers?: ParsedHeaders;
|
|
39
|
+
redirectsFile?: string;
|
|
40
|
+
headersFile?: string;
|
|
36
41
|
webAnalyticsToken?: string;
|
|
37
42
|
deploymentId?: string;
|
|
38
43
|
failOpen?: boolean;
|
|
39
44
|
logger?: Logger;
|
|
40
45
|
}): Metadata {
|
|
41
46
|
return {
|
|
42
|
-
...constructRedirects({ redirects, logger }),
|
|
43
|
-
...constructHeaders({ headers, logger }),
|
|
47
|
+
...constructRedirects({ redirects, redirectsFile, logger }),
|
|
48
|
+
...constructHeaders({ headers, headersFile, logger }),
|
|
44
49
|
...constructWebAnalytics({ webAnalyticsToken, logger }),
|
|
45
50
|
deploymentId,
|
|
46
51
|
failOpen,
|
|
@@ -49,9 +54,11 @@ export function createMetadataObject({
|
|
|
49
54
|
|
|
50
55
|
function constructRedirects({
|
|
51
56
|
redirects,
|
|
57
|
+
redirectsFile,
|
|
52
58
|
logger,
|
|
53
59
|
}: {
|
|
54
60
|
redirects?: ParsedRedirects;
|
|
61
|
+
redirectsFile?: string;
|
|
55
62
|
logger: Logger;
|
|
56
63
|
}): Metadata {
|
|
57
64
|
if (!redirects) {
|
|
@@ -61,18 +68,31 @@ function constructRedirects({
|
|
|
61
68
|
const num_valid = redirects.rules.length;
|
|
62
69
|
const num_invalid = redirects.invalid.length;
|
|
63
70
|
|
|
71
|
+
// exhaustive check, since we could not have parsed `redirects` out of
|
|
72
|
+
// a non-existing redirects file
|
|
73
|
+
const redirectsRelativePath = redirectsFile
|
|
74
|
+
? relative(process.cwd(), redirectsFile)
|
|
75
|
+
: "";
|
|
76
|
+
|
|
64
77
|
logger.log(
|
|
65
|
-
|
|
78
|
+
`✨ Parsed ${num_valid} valid redirect rule${num_valid === 1 ? "" : "s"}.`
|
|
66
79
|
);
|
|
67
80
|
|
|
68
81
|
if (num_invalid > 0) {
|
|
69
|
-
|
|
82
|
+
let invalidRedirectRulesList = ``;
|
|
83
|
+
|
|
70
84
|
for (const { line, lineNumber, message } of redirects.invalid) {
|
|
85
|
+
invalidRedirectRulesList += `▶︎ ${message}\n`;
|
|
86
|
+
|
|
71
87
|
if (line) {
|
|
72
|
-
|
|
88
|
+
invalidRedirectRulesList += ` at ${redirectsRelativePath}${lineNumber ? `:${lineNumber}` : ""} | ${line}\n\n`;
|
|
73
89
|
}
|
|
74
|
-
logger.warn(` ${message}`);
|
|
75
90
|
}
|
|
91
|
+
|
|
92
|
+
logger.warn(
|
|
93
|
+
`Found ${num_invalid} invalid redirect rule${num_invalid === 1 ? "" : "s"}:\n` +
|
|
94
|
+
`${invalidRedirectRulesList}`
|
|
95
|
+
);
|
|
76
96
|
}
|
|
77
97
|
|
|
78
98
|
/* Better to return no Redirects object at all than one with empty rules */
|
|
@@ -114,9 +134,11 @@ function constructRedirects({
|
|
|
114
134
|
|
|
115
135
|
function constructHeaders({
|
|
116
136
|
headers,
|
|
137
|
+
headersFile,
|
|
117
138
|
logger,
|
|
118
139
|
}: {
|
|
119
140
|
headers?: ParsedHeaders;
|
|
141
|
+
headersFile?: string;
|
|
120
142
|
logger: Logger;
|
|
121
143
|
}): Metadata {
|
|
122
144
|
if (!headers) {
|
|
@@ -126,18 +148,31 @@ function constructHeaders({
|
|
|
126
148
|
const num_valid = headers.rules.length;
|
|
127
149
|
const num_invalid = headers.invalid.length;
|
|
128
150
|
|
|
151
|
+
// exhaustive check, since we could not have parsed `headers` out of
|
|
152
|
+
// a non-existing headers file
|
|
153
|
+
const headersRelativePath = headersFile
|
|
154
|
+
? relative(process.cwd(), headersFile)
|
|
155
|
+
: "";
|
|
156
|
+
|
|
129
157
|
logger.log(
|
|
130
|
-
|
|
158
|
+
`✨ Parsed ${num_valid} valid header rule${num_valid === 1 ? "" : "s"}.`
|
|
131
159
|
);
|
|
132
160
|
|
|
133
161
|
if (num_invalid > 0) {
|
|
134
|
-
|
|
162
|
+
let invalidHeaderRulesList = ``;
|
|
163
|
+
|
|
135
164
|
for (const { line, lineNumber, message } of headers.invalid) {
|
|
165
|
+
invalidHeaderRulesList += `▶︎ ${message}\n`;
|
|
166
|
+
|
|
136
167
|
if (line) {
|
|
137
|
-
|
|
168
|
+
invalidHeaderRulesList += ` at ${headersRelativePath}${lineNumber ? `:${lineNumber}` : ""} | ${line}\n\n`;
|
|
138
169
|
}
|
|
139
|
-
logger.warn(` ${message}`);
|
|
140
170
|
}
|
|
171
|
+
|
|
172
|
+
logger.warn(
|
|
173
|
+
`Found ${num_invalid} invalid header rule${num_invalid === 1 ? "" : "s"}:\n` +
|
|
174
|
+
`${invalidHeaderRulesList}`
|
|
175
|
+
);
|
|
141
176
|
}
|
|
142
177
|
|
|
143
178
|
/* Better to return no Headers object at all than one with empty rules */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/pages-shared",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.42",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/cloudflare/workers-sdk.git",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"metadata-generator/**/*"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"miniflare": "3.
|
|
16
|
+
"miniflare": "3.20240605.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@miniflare/storage-memory": "^2.14.2",
|
|
20
|
-
"@cloudflare/workers-types": "^4.
|
|
20
|
+
"@cloudflare/workers-types": "^4.20240605.0",
|
|
21
21
|
"@miniflare/cache": "^2.14.2",
|
|
22
22
|
"@miniflare/core": "^2.14.2",
|
|
23
23
|
"@miniflare/html-rewriter": "^2.14.2",
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"workers-sdk": {
|
|
29
29
|
"prerelease": true
|
|
30
30
|
},
|
|
31
|
+
"volta": {
|
|
32
|
+
"extends": "../../package.json"
|
|
33
|
+
},
|
|
31
34
|
"scripts": {
|
|
32
35
|
"check:type": "tsc",
|
|
33
36
|
"check:lint": "eslint .",
|