From 32abe49bd073417b480b1b990f432a837c12eb6f Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:17:34 +0100 Subject: [PATCH] Fix polyfills not being available to imports on Netlify (#6117) * fix(netlify): Try to make polyfill external * feat(webapi): Add polyfill applier for SSR * fix(netlify): Externalize polyfills so they're always applied before user code * chore: changeset * test(netlify): Add test for polyfill being in the proper place * config(netlify): Remove unnecessary change to package.json * revert(netlify): Revert changes * feat(astro): Add a way for packages to explicitely mark themselves as needing to be external * Update .changeset/silent-dragons-sell.md --------- Co-authored-by: Nate Moore --- .changeset/silent-dragons-sell.md | 6 ++++++ packages/astro/src/core/create-vite.ts | 6 ++++++ packages/integrations/netlify/package.json | 3 +++ 3 files changed, 15 insertions(+) create mode 100644 .changeset/silent-dragons-sell.md diff --git a/.changeset/silent-dragons-sell.md b/.changeset/silent-dragons-sell.md new file mode 100644 index 000000000000..233d99a9696a --- /dev/null +++ b/.changeset/silent-dragons-sell.md @@ -0,0 +1,6 @@ +--- +'@astrojs/netlify': patch +'astro': patch +--- + +Fix polyfills not being available in certain cases diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 5ebd05f55874..c25668af4a83 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -55,6 +55,12 @@ export async function createVite( isBuild: mode === 'build', viteUserConfig: settings.config.vite, isFrameworkPkgByJson(pkgJson) { + // Certain packages will trigger the checks below, but need to be external. A common example are SSR adapters + // for node-based platforms, as we need to control the order of the import paths to make sure polyfills are applied in time. + if (pkgJson?.astro?.external === true) { + return false; + } + return ( // Attempt: package relies on `astro`. ✅ Definitely an Astro package pkgJson.peerDependencies?.astro || diff --git a/packages/integrations/netlify/package.json b/packages/integrations/netlify/package.json index 25695ea79181..33caf0f62004 100644 --- a/packages/integrations/netlify/package.json +++ b/packages/integrations/netlify/package.json @@ -50,5 +50,8 @@ "cheerio": "^1.0.0-rc.11", "mocha": "^9.2.2", "vite": "^4.0.3" + }, + "astro": { + "external": true } }