Skip to content

Commit

Permalink
Fix polyfills not being available to imports on Netlify (#6117)
Browse files Browse the repository at this point in the history
* 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 <natemoo-re@users.noreply.github.com>
  • Loading branch information
Princesseuh and natemoo-re authored Feb 6, 2023
1 parent 1b591a1 commit 32abe49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/silent-dragons-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/netlify': patch
'astro': patch
---

Fix polyfills not being available in certain cases
6 changes: 6 additions & 0 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
3 changes: 3 additions & 0 deletions packages/integrations/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@
"cheerio": "^1.0.0-rc.11",
"mocha": "^9.2.2",
"vite": "^4.0.3"
},
"astro": {
"external": true
}
}

0 comments on commit 32abe49

Please sign in to comment.