From 383f9f99cf8ab37306b2395c131318e193addacf Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Mon, 30 Sep 2024 09:09:28 +0200 Subject: [PATCH 1/5] chore: externalize `cloudflare:sockets` imports --- .changeset/good-rivers-add.md | 5 +++++ packages/cloudflare/src/index.ts | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 .changeset/good-rivers-add.md diff --git a/.changeset/good-rivers-add.md b/.changeset/good-rivers-add.md new file mode 100644 index 000000000..c027a25af --- /dev/null +++ b/.changeset/good-rivers-add.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': minor +--- + +Improves default config to support `cloudflare:sockets` imports diff --git a/packages/cloudflare/src/index.ts b/packages/cloudflare/src/index.ts index 718fac020..ada729ed5 100644 --- a/packages/cloudflare/src/index.ts +++ b/packages/cloudflare/src/index.ts @@ -130,6 +130,14 @@ export default function createIntegration(args?: Options): AstroIntegration { // Allows imports of '.wasm', '.bin', and '.txt' file types cloudflareModulePlugin, ], + ssr: { + external: ['cloudflare:sockets'], + }, + build: { + rollupOptions: { + external: ['cloudflare:sockets'], + }, + } }, integrations: [astroWhen()], image: setImageConfig(args?.imageService ?? 'compile', config.image, command, logger), From dd994abcebe200426e74ec4ef260c9981b4b57ca Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Mon, 21 Oct 2024 10:02:44 +0200 Subject: [PATCH 2/5] format --- packages/cloudflare/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cloudflare/src/index.ts b/packages/cloudflare/src/index.ts index ada729ed5..4ab5f05a2 100644 --- a/packages/cloudflare/src/index.ts +++ b/packages/cloudflare/src/index.ts @@ -137,7 +137,7 @@ export default function createIntegration(args?: Options): AstroIntegration { rollupOptions: { external: ['cloudflare:sockets'], }, - } + }, }, integrations: [astroWhen()], image: setImageConfig(args?.imageService ?? 'compile', config.image, command, logger), From d04600d8dfc2bcd3987960ab5bc6194883aa02f5 Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Mon, 21 Oct 2024 10:13:33 +0200 Subject: [PATCH 3/5] use plugin instead of config --- packages/cloudflare/src/index.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/cloudflare/src/index.ts b/packages/cloudflare/src/index.ts index 4ab5f05a2..ee8e64421 100644 --- a/packages/cloudflare/src/index.ts +++ b/packages/cloudflare/src/index.ts @@ -129,15 +129,17 @@ export default function createIntegration(args?: Options): AstroIntegration { // https://developers.cloudflare.com/pages/functions/module-support/ // Allows imports of '.wasm', '.bin', and '.txt' file types cloudflareModulePlugin, + { + name: 'vite:cf-imports', + enforce: 'pre', + resolveId(source) { + if (source.startsWith("cloudflare:")) { + return { id: source, external: true }; + } + return null; + }, + } ], - ssr: { - external: ['cloudflare:sockets'], - }, - build: { - rollupOptions: { - external: ['cloudflare:sockets'], - }, - }, }, integrations: [astroWhen()], image: setImageConfig(args?.imageService ?? 'compile', config.image, command, logger), From 99d91500ff8cd2e9cda2224e4fe76694e2dbef64 Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Mon, 21 Oct 2024 10:53:30 +0200 Subject: [PATCH 4/5] format --- packages/cloudflare/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cloudflare/src/index.ts b/packages/cloudflare/src/index.ts index ee8e64421..4facef327 100644 --- a/packages/cloudflare/src/index.ts +++ b/packages/cloudflare/src/index.ts @@ -133,12 +133,12 @@ export default function createIntegration(args?: Options): AstroIntegration { name: 'vite:cf-imports', enforce: 'pre', resolveId(source) { - if (source.startsWith("cloudflare:")) { + if (source.startsWith('cloudflare:')) { return { id: source, external: true }; } return null; }, - } + }, ], }, integrations: [astroWhen()], From 5b58b54038c11591405c2d044004b67aab2fd972 Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Sat, 26 Oct 2024 08:03:13 +0200 Subject: [PATCH 5/5] Update good-rivers-add.md --- .changeset/good-rivers-add.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/good-rivers-add.md b/.changeset/good-rivers-add.md index c027a25af..24fb72046 100644 --- a/.changeset/good-rivers-add.md +++ b/.changeset/good-rivers-add.md @@ -1,5 +1,5 @@ --- -'@astrojs/cloudflare': minor +'@astrojs/cloudflare': patch --- -Improves default config to support `cloudflare:sockets` imports +Fixes an issue where `cloudflare:` scoped imports made the build fail. We externalize all imports with the `cloudflare:` scope by default now.