From 52b1766ddcfa8648c9fa49d11f1833367533c4ff Mon Sep 17 00:00:00 2001 From: iclectic Date: Sun, 16 Nov 2025 19:39:54 +0000 Subject: [PATCH 1/5] fix(cloudflare): clean up duplicated helper functions in utils/assets.ts Removes the repeated definitions of matchHostname, matchPathname, matchProtocol, matchPort and matchPattern that are already provided by the @astrojs/internal-helpers/remote package. This resolves the build warning about unused external imports and avoids maintaining the same logic in multiple places by relying on the shared helpers. Closes #14752 --- .../cloudflare/src/utils/assets.ts | 64 ++----------------- 1 file changed, 5 insertions(+), 59 deletions(-) diff --git a/packages/integrations/cloudflare/src/utils/assets.ts b/packages/integrations/cloudflare/src/utils/assets.ts index 4b784f865a98..39e0b6e36d5f 100644 --- a/packages/integrations/cloudflare/src/utils/assets.ts +++ b/packages/integrations/cloudflare/src/utils/assets.ts @@ -1,64 +1,10 @@ import { isRemotePath } from '@astrojs/internal-helpers/path'; -import type { AstroConfig, RemotePattern } from 'astro'; +import { + matchHostname, + matchPattern, +} from '@astrojs/internal-helpers/remote'; +import type { AstroConfig } from 'astro'; -function matchHostname(url: URL, hostname?: string, allowWildcard?: boolean) { - if (!hostname) { - return true; - } - if (!allowWildcard || !hostname.startsWith('*')) { - return hostname === url.hostname; - } - if (hostname.startsWith('**.')) { - const slicedHostname = hostname.slice(2); // ** length - return slicedHostname !== url.hostname && url.hostname.endsWith(slicedHostname); - } - if (hostname.startsWith('*.')) { - const slicedHostname = hostname.slice(1); // * length - const additionalSubdomains = url.hostname - .replace(slicedHostname, '') - .split('.') - .filter(Boolean); - return additionalSubdomains.length === 1; - } - - return false; -} -function matchPort(url: URL, port?: string) { - return !port || port === url.port; -} -function matchProtocol(url: URL, protocol?: string) { - return !protocol || protocol === url.protocol.slice(0, -1); -} -function matchPathname(url: URL, pathname?: string, allowWildcard?: boolean) { - if (!pathname) { - return true; - } - if (!allowWildcard || !pathname.endsWith('*')) { - return pathname === url.pathname; - } - if (pathname.endsWith('/**')) { - const slicedPathname = pathname.slice(0, -2); // ** length - return slicedPathname !== url.pathname && url.pathname.startsWith(slicedPathname); - } - if (pathname.endsWith('/*')) { - const slicedPathname = pathname.slice(0, -1); // * length - const additionalPathChunks = url.pathname - .replace(slicedPathname, '') - .split('/') - .filter(Boolean); - return additionalPathChunks.length === 1; - } - - return false; -} -function matchPattern(url: URL, remotePattern: RemotePattern) { - return ( - matchProtocol(url, remotePattern.protocol) && - matchHostname(url, remotePattern.hostname, true) && - matchPort(url, remotePattern.port) && - matchPathname(url, remotePattern.pathname, true) - ); -} export function isRemoteAllowed( src: string, { From 2c6419f79f60360bbc736c2507b56d4e079ecfe4 Mon Sep 17 00:00:00 2001 From: iclectic Date: Sun, 16 Nov 2025 19:55:04 +0000 Subject: [PATCH 2/5] chore: add changeset --- .changeset/tough-spiders-wish.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-spiders-wish.md diff --git a/.changeset/tough-spiders-wish.md b/.changeset/tough-spiders-wish.md new file mode 100644 index 000000000000..fb701ecf2ed8 --- /dev/null +++ b/.changeset/tough-spiders-wish.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +Removal of duplicate helper function definitions in utils/assets.ts From 2ec05928b0aca41ee2910fa4534f941093de4bf6 Mon Sep 17 00:00:00 2001 From: iclectic Date: Sun, 16 Nov 2025 20:30:52 +0000 Subject: [PATCH 3/5] chore: update changeset to focus on user-facing impact --- .changeset/tough-spiders-wish.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changeset/tough-spiders-wish.md b/.changeset/tough-spiders-wish.md index fb701ecf2ed8..858d21d04d13 100644 --- a/.changeset/tough-spiders-wish.md +++ b/.changeset/tough-spiders-wish.md @@ -2,4 +2,5 @@ '@astrojs/cloudflare': patch --- -Removal of duplicate helper function definitions in utils/assets.ts +Fixes duplicate import warnings during build + From 0a098551fe5978d33d467014a9bfcf4ffcfc6fd1 Mon Sep 17 00:00:00 2001 From: iclectic Date: Sun, 16 Nov 2025 20:35:04 +0000 Subject: [PATCH 4/5] chore: improve changeset description with user context --- .changeset/tough-spiders-wish.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tough-spiders-wish.md b/.changeset/tough-spiders-wish.md index 858d21d04d13..38de879212fd 100644 --- a/.changeset/tough-spiders-wish.md +++ b/.changeset/tough-spiders-wish.md @@ -2,5 +2,5 @@ '@astrojs/cloudflare': patch --- -Fixes duplicate import warnings during build +Fixes build warnings about external module imports that appeared when building projects using the Cloudflare adapter. These warnings no longer appear during the build process. From 88d3e0ccfdc0472aec28f1f8264bd44f38902fa3 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Mon, 24 Nov 2025 11:27:33 +0100 Subject: [PATCH 5/5] Apply suggestion from @florian-lefebvre --- .changeset/tough-spiders-wish.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tough-spiders-wish.md b/.changeset/tough-spiders-wish.md index 38de879212fd..d83fd11f2991 100644 --- a/.changeset/tough-spiders-wish.md +++ b/.changeset/tough-spiders-wish.md @@ -2,5 +2,5 @@ '@astrojs/cloudflare': patch --- -Fixes build warnings about external module imports that appeared when building projects using the Cloudflare adapter. These warnings no longer appear during the build process. +Updates assets handling to use `@astrojs/internal-helpers`