Skip to content

Commit 9720b70

Browse files
fix(cloudflare): eliminate duplicate import warnings during build (#14777)
Co-authored-by: Florian Lefebvre <[email protected]>
1 parent b43ee71 commit 9720b70

File tree

2 files changed

+11
-59
lines changed

2 files changed

+11
-59
lines changed

.changeset/tough-spiders-wish.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@astrojs/cloudflare': patch
3+
---
4+
5+
Updates assets handling to use `@astrojs/internal-helpers`
6+

packages/integrations/cloudflare/src/utils/assets.ts

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,10 @@
11
import { isRemotePath } from '@astrojs/internal-helpers/path';
2-
import type { AstroConfig, RemotePattern } from 'astro';
2+
import {
3+
matchHostname,
4+
matchPattern,
5+
} from '@astrojs/internal-helpers/remote';
6+
import type { AstroConfig } from 'astro';
37

4-
function matchHostname(url: URL, hostname?: string, allowWildcard?: boolean) {
5-
if (!hostname) {
6-
return true;
7-
}
8-
if (!allowWildcard || !hostname.startsWith('*')) {
9-
return hostname === url.hostname;
10-
}
11-
if (hostname.startsWith('**.')) {
12-
const slicedHostname = hostname.slice(2); // ** length
13-
return slicedHostname !== url.hostname && url.hostname.endsWith(slicedHostname);
14-
}
15-
if (hostname.startsWith('*.')) {
16-
const slicedHostname = hostname.slice(1); // * length
17-
const additionalSubdomains = url.hostname
18-
.replace(slicedHostname, '')
19-
.split('.')
20-
.filter(Boolean);
21-
return additionalSubdomains.length === 1;
22-
}
23-
24-
return false;
25-
}
26-
function matchPort(url: URL, port?: string) {
27-
return !port || port === url.port;
28-
}
29-
function matchProtocol(url: URL, protocol?: string) {
30-
return !protocol || protocol === url.protocol.slice(0, -1);
31-
}
32-
function matchPathname(url: URL, pathname?: string, allowWildcard?: boolean) {
33-
if (!pathname) {
34-
return true;
35-
}
36-
if (!allowWildcard || !pathname.endsWith('*')) {
37-
return pathname === url.pathname;
38-
}
39-
if (pathname.endsWith('/**')) {
40-
const slicedPathname = pathname.slice(0, -2); // ** length
41-
return slicedPathname !== url.pathname && url.pathname.startsWith(slicedPathname);
42-
}
43-
if (pathname.endsWith('/*')) {
44-
const slicedPathname = pathname.slice(0, -1); // * length
45-
const additionalPathChunks = url.pathname
46-
.replace(slicedPathname, '')
47-
.split('/')
48-
.filter(Boolean);
49-
return additionalPathChunks.length === 1;
50-
}
51-
52-
return false;
53-
}
54-
function matchPattern(url: URL, remotePattern: RemotePattern) {
55-
return (
56-
matchProtocol(url, remotePattern.protocol) &&
57-
matchHostname(url, remotePattern.hostname, true) &&
58-
matchPort(url, remotePattern.port) &&
59-
matchPathname(url, remotePattern.pathname, true)
60-
);
61-
}
628
export function isRemoteAllowed(
639
src: string,
6410
{

0 commit comments

Comments
 (0)