@cloudflare/vite-plugin 1.5.0 → 1.6.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/asset-workers/asset-worker.js +18 -13
- package/dist/asset-workers/router-worker.js +114 -35
- package/dist/index.js +371 -233
- package/package.json +8 -8
|
@@ -4728,6 +4728,7 @@ var normalizeConfiguration = (configuration) => {
|
|
|
4728
4728
|
version: 2,
|
|
4729
4729
|
rules: {}
|
|
4730
4730
|
},
|
|
4731
|
+
has_static_routing: configuration?.has_static_routing ?? false,
|
|
4731
4732
|
account_id: configuration?.account_id ?? -1,
|
|
4732
4733
|
script_id: configuration?.script_id ?? -1,
|
|
4733
4734
|
debug: configuration?.debug ?? false
|
|
@@ -4906,24 +4907,27 @@ var replacer = (str, replacements) => {
|
|
|
4906
4907
|
}
|
|
4907
4908
|
return str;
|
|
4908
4909
|
};
|
|
4910
|
+
var generateRuleRegExp = (rule) => {
|
|
4911
|
+
rule = rule.split("*").map(escapeRegex).join("(?<splat>.*)");
|
|
4912
|
+
const host_matches = rule.matchAll(HOST_PLACEHOLDER_REGEX);
|
|
4913
|
+
for (const host_match of host_matches) {
|
|
4914
|
+
rule = rule.split(host_match[0]).join(`(?<${host_match[1]}>[^/.]+)`);
|
|
4915
|
+
}
|
|
4916
|
+
const path_matches = rule.matchAll(PLACEHOLDER_REGEX);
|
|
4917
|
+
for (const path_match of path_matches) {
|
|
4918
|
+
rule = rule.split(path_match[0]).join(`(?<${path_match[1]}>[^/]+)`);
|
|
4919
|
+
}
|
|
4920
|
+
rule = "^" + rule + "$";
|
|
4921
|
+
return RegExp(rule);
|
|
4922
|
+
};
|
|
4909
4923
|
var generateRulesMatcher = (rules, replacerFn = (match) => match) => {
|
|
4910
4924
|
if (!rules) {
|
|
4911
4925
|
return () => [];
|
|
4912
4926
|
}
|
|
4913
4927
|
const compiledRules = Object.entries(rules).map(([rule, match]) => {
|
|
4914
4928
|
const crossHost = rule.startsWith("https://");
|
|
4915
|
-
rule = rule.split("*").map(escapeRegex).join("(?<splat>.*)");
|
|
4916
|
-
const host_matches = rule.matchAll(HOST_PLACEHOLDER_REGEX);
|
|
4917
|
-
for (const host_match of host_matches) {
|
|
4918
|
-
rule = rule.split(host_match[0]).join(`(?<${host_match[1]}>[^/.]+)`);
|
|
4919
|
-
}
|
|
4920
|
-
const path_matches = rule.matchAll(PLACEHOLDER_REGEX);
|
|
4921
|
-
for (const path_match of path_matches) {
|
|
4922
|
-
rule = rule.split(path_match[0]).join(`(?<${path_match[1]}>[^/]+)`);
|
|
4923
|
-
}
|
|
4924
|
-
rule = "^" + rule + "$";
|
|
4925
4929
|
try {
|
|
4926
|
-
const regExp =
|
|
4930
|
+
const regExp = generateRuleRegExp(rule);
|
|
4927
4931
|
return [{ crossHost, regExp }, match];
|
|
4928
4932
|
} catch {
|
|
4929
4933
|
}
|
|
@@ -5140,10 +5144,11 @@ var resolveAssetIntentToResponse = async (assetIntent, request, env, configurati
|
|
|
5140
5144
|
});
|
|
5141
5145
|
};
|
|
5142
5146
|
var canFetch = async (request, env, configuration, exists) => {
|
|
5143
|
-
|
|
5147
|
+
const shouldKeepNotFoundHandling = configuration.has_static_routing || flagIsEnabled(
|
|
5144
5148
|
configuration,
|
|
5145
5149
|
SEC_FETCH_MODE_NAVIGATE_HEADER_PREFERS_ASSET_SERVING
|
|
5146
|
-
) && request.headers.get("Sec-Fetch-Mode") === "navigate"
|
|
5150
|
+
) && request.headers.get("Sec-Fetch-Mode") === "navigate";
|
|
5151
|
+
if (!shouldKeepNotFoundHandling) {
|
|
5147
5152
|
configuration = {
|
|
5148
5153
|
...configuration,
|
|
5149
5154
|
not_found_handling: "none"
|
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
// ../workers-shared/utils/tracing.ts
|
|
2
|
+
function mockJaegerBindingSpan() {
|
|
3
|
+
return {
|
|
4
|
+
addLogs: () => {
|
|
5
|
+
},
|
|
6
|
+
setTags: () => {
|
|
7
|
+
},
|
|
8
|
+
end: () => {
|
|
9
|
+
},
|
|
10
|
+
isRecording: true
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function mockJaegerBinding() {
|
|
14
|
+
return {
|
|
15
|
+
enterSpan: (_, span, ...args) => {
|
|
16
|
+
return span(mockJaegerBindingSpan(), ...args);
|
|
17
|
+
},
|
|
18
|
+
getSpanContext: () => ({
|
|
19
|
+
traceId: "test-trace",
|
|
20
|
+
spanId: "test-span",
|
|
21
|
+
parentSpanId: "test-parent-span",
|
|
22
|
+
traceFlags: 0
|
|
23
|
+
}),
|
|
24
|
+
runWithSpanContext: (_, callback, ...args) => {
|
|
25
|
+
return callback(...args);
|
|
26
|
+
},
|
|
27
|
+
traceId: "test-trace",
|
|
28
|
+
spanId: "test-span",
|
|
29
|
+
parentSpanId: "test-parent-span",
|
|
30
|
+
cfTraceIdHeader: "test-trace:test-span:0"
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ../workers-shared/asset-worker/src/utils/rules-engine.ts
|
|
35
|
+
var ESCAPE_REGEX_CHARACTERS = /[-/\\^$*+?.()|[\]{}]/g;
|
|
36
|
+
var escapeRegex = (str) => {
|
|
37
|
+
return str.replace(ESCAPE_REGEX_CHARACTERS, "\\$&");
|
|
38
|
+
};
|
|
39
|
+
var generateGlobOnlyRuleRegExp = (rule) => {
|
|
40
|
+
rule = rule.split("*").map(escapeRegex).join(".*");
|
|
41
|
+
rule = "^" + rule + "$";
|
|
42
|
+
return RegExp(rule);
|
|
43
|
+
};
|
|
44
|
+
var generateStaticRoutingRuleMatcher = (rules) => ({ request }) => {
|
|
45
|
+
const { pathname } = new URL(request.url);
|
|
46
|
+
for (const rule of rules) {
|
|
47
|
+
try {
|
|
48
|
+
const regExp = generateGlobOnlyRuleRegExp(rule);
|
|
49
|
+
if (regExp.test(pathname)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
|
|
1
58
|
// ../workers-shared/utils/performance.ts
|
|
2
59
|
var PerformanceTimer = class {
|
|
3
60
|
performanceTimer;
|
|
@@ -4483,39 +4540,6 @@ function setupSentry(request, context, dsn, clientId, clientSecret, coloMetadata
|
|
|
4483
4540
|
return sentry;
|
|
4484
4541
|
}
|
|
4485
4542
|
|
|
4486
|
-
// ../workers-shared/utils/tracing.ts
|
|
4487
|
-
function mockJaegerBindingSpan() {
|
|
4488
|
-
return {
|
|
4489
|
-
addLogs: () => {
|
|
4490
|
-
},
|
|
4491
|
-
setTags: () => {
|
|
4492
|
-
},
|
|
4493
|
-
end: () => {
|
|
4494
|
-
},
|
|
4495
|
-
isRecording: true
|
|
4496
|
-
};
|
|
4497
|
-
}
|
|
4498
|
-
function mockJaegerBinding() {
|
|
4499
|
-
return {
|
|
4500
|
-
enterSpan: (_, span, ...args) => {
|
|
4501
|
-
return span(mockJaegerBindingSpan(), ...args);
|
|
4502
|
-
},
|
|
4503
|
-
getSpanContext: () => ({
|
|
4504
|
-
traceId: "test-trace",
|
|
4505
|
-
spanId: "test-span",
|
|
4506
|
-
parentSpanId: "test-parent-span",
|
|
4507
|
-
traceFlags: 0
|
|
4508
|
-
}),
|
|
4509
|
-
runWithSpanContext: (_, callback, ...args) => {
|
|
4510
|
-
return callback(...args);
|
|
4511
|
-
},
|
|
4512
|
-
traceId: "test-trace",
|
|
4513
|
-
spanId: "test-span",
|
|
4514
|
-
parentSpanId: "test-parent-span",
|
|
4515
|
-
cfTraceIdHeader: "test-trace:test-span:0"
|
|
4516
|
-
};
|
|
4517
|
-
}
|
|
4518
|
-
|
|
4519
4543
|
// ../workers-shared/router-worker/src/analytics.ts
|
|
4520
4544
|
var VERSION = 1;
|
|
4521
4545
|
var Analytics = class {
|
|
@@ -4551,7 +4575,9 @@ var Analytics = class {
|
|
|
4551
4575
|
// double3
|
|
4552
4576
|
this.data.coloTier ?? -1,
|
|
4553
4577
|
// double4
|
|
4554
|
-
this.data.userWorkerAhead === void 0 ? -1 : Number(this.data.userWorkerAhead)
|
|
4578
|
+
this.data.userWorkerAhead === void 0 ? -1 : Number(this.data.userWorkerAhead),
|
|
4579
|
+
this.data.staticRoutingDecision ?? 0 /* NOT_PROVIDED */
|
|
4580
|
+
// double6
|
|
4555
4581
|
],
|
|
4556
4582
|
blobs: [
|
|
4557
4583
|
this.data.hostname?.substring(0, 256),
|
|
@@ -4576,7 +4602,10 @@ var applyConfigurationDefaults = (configuration) => {
|
|
|
4576
4602
|
has_user_worker: configuration?.has_user_worker ?? false,
|
|
4577
4603
|
account_id: configuration?.account_id ?? -1,
|
|
4578
4604
|
script_id: configuration?.script_id ?? -1,
|
|
4579
|
-
debug: configuration?.debug ?? false
|
|
4605
|
+
debug: configuration?.debug ?? false,
|
|
4606
|
+
static_routing: configuration?.static_routing ?? {
|
|
4607
|
+
user_worker: []
|
|
4608
|
+
}
|
|
4580
4609
|
};
|
|
4581
4610
|
};
|
|
4582
4611
|
|
|
@@ -4603,6 +4632,7 @@ var worker_default = {
|
|
|
4603
4632
|
env.CONFIG?.account_id,
|
|
4604
4633
|
env.CONFIG?.script_id
|
|
4605
4634
|
);
|
|
4635
|
+
const hasStaticRouting = env.CONFIG.static_routing !== void 0;
|
|
4606
4636
|
const config = applyConfigurationDefaults(env.CONFIG);
|
|
4607
4637
|
const url = new URL(request.url);
|
|
4608
4638
|
if (env.COLO_METADATA && env.VERSION_METADATA && env.CONFIG) {
|
|
@@ -4619,6 +4649,55 @@ var worker_default = {
|
|
|
4619
4649
|
});
|
|
4620
4650
|
}
|
|
4621
4651
|
const maybeSecondRequest = request.clone();
|
|
4652
|
+
if (config.static_routing) {
|
|
4653
|
+
const excludeRulesMatcher = generateStaticRoutingRuleMatcher(
|
|
4654
|
+
config.static_routing.asset_worker ?? []
|
|
4655
|
+
);
|
|
4656
|
+
if (excludeRulesMatcher({
|
|
4657
|
+
request
|
|
4658
|
+
})) {
|
|
4659
|
+
analytics.setData({
|
|
4660
|
+
dispatchtype: "asset" /* ASSETS */,
|
|
4661
|
+
staticRoutingDecision: 2 /* ROUTED */
|
|
4662
|
+
});
|
|
4663
|
+
return await env.JAEGER.enterSpan("dispatch_assets", async (span) => {
|
|
4664
|
+
span.setTags({
|
|
4665
|
+
hasUserWorker: config.has_user_worker,
|
|
4666
|
+
asset: "static_routing",
|
|
4667
|
+
dispatchType: "asset" /* ASSETS */
|
|
4668
|
+
});
|
|
4669
|
+
return env.ASSET_WORKER.fetch(maybeSecondRequest);
|
|
4670
|
+
});
|
|
4671
|
+
}
|
|
4672
|
+
const includeRulesMatcher = generateStaticRoutingRuleMatcher(
|
|
4673
|
+
config.static_routing.user_worker
|
|
4674
|
+
);
|
|
4675
|
+
if (includeRulesMatcher({
|
|
4676
|
+
request
|
|
4677
|
+
})) {
|
|
4678
|
+
if (!config.has_user_worker) {
|
|
4679
|
+
throw new Error(
|
|
4680
|
+
"Fetch for user worker without having a user worker binding"
|
|
4681
|
+
);
|
|
4682
|
+
}
|
|
4683
|
+
analytics.setData({
|
|
4684
|
+
dispatchtype: "worker" /* WORKER */,
|
|
4685
|
+
staticRoutingDecision: 2 /* ROUTED */
|
|
4686
|
+
});
|
|
4687
|
+
return await env.JAEGER.enterSpan("dispatch_worker", async (span) => {
|
|
4688
|
+
span.setTags({
|
|
4689
|
+
hasUserWorker: true,
|
|
4690
|
+
asset: "static_routing",
|
|
4691
|
+
dispatchType: "worker" /* WORKER */
|
|
4692
|
+
});
|
|
4693
|
+
userWorkerInvocation = true;
|
|
4694
|
+
return env.USER_WORKER.fetch(maybeSecondRequest);
|
|
4695
|
+
});
|
|
4696
|
+
}
|
|
4697
|
+
analytics.setData({
|
|
4698
|
+
staticRoutingDecision: hasStaticRouting ? 1 /* NOT_ROUTED */ : 0 /* NOT_PROVIDED */
|
|
4699
|
+
});
|
|
4700
|
+
}
|
|
4622
4701
|
if (config.invoke_user_worker_ahead_of_assets) {
|
|
4623
4702
|
if (!config.has_user_worker) {
|
|
4624
4703
|
throw new Error(
|