-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: vendor deno dependencies #2302
Conversation
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-demo-all-flags ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-plugin-edge-middleware ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for nextjs-plugin-custom-routes-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
This is an eszip file that I created using the changes in this PR. Opening it on https://eszip-viewer.deno.dev/, you can see that it indeed picks up the vendored files from the local directory: ![]() |
For some reason, this import map breaks the config detection. I'll need to figure out what's going on there before we can merge this. Turning the PR into draft for now.
|
packages/runtime/src/helpers/edge.ts
Outdated
@@ -378,6 +378,11 @@ export const writeEdgeFunctions = async ({ | |||
const nextConfig = nextConfigFile.config | |||
const usesAppDir = nextConfig.experimental?.appDir | |||
|
|||
await copy(getEdgeTemplatePath('../vendor'), join(edgeFunctionRoot, 'vendor')) | |||
netlifyConfig.functions['*'] = { | |||
deno_import_map: join(INTERNAL_EDGE_FUNCTIONS_SRC, 'vendor', 'import_map.json'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives a TypeScript error as deno_import_map
doesn't exist in FunctionsObject
. Do we need to update the type to support import maps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, good catch! doing that in netlify/build#5305
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know when it's released and when this PR is updated. We'll get this merged. 👍🏻
This seems like |
No, because it's a moving target and when we update the version here: we might also update the stdlib modules under the hood, and then it'll break again since Next-runtime has other modules bundled.
We could implement this using a scoped import map. I've tried that out with 30416b5, but wasn't able to get it working. I'm now going down a straight-forward path, and am updating all imports to straight-up import from the |
@@ -0,0 +1,4 @@ | |||
56c56 | |||
< fetch(new URL("./vendor/html_rewriter_bg.wasm", import.meta.url).href) | |||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like we're replacing the from-disk fetch with a HTTP request at runtime here. This is required because deno vendor
doesn't download the WASM onto disk (for whatever reason), so fetching this from disk would fail. This was already the case before this PR, but before this file was imported via https://
, meaning that import.meta.url
was something like https://deno.land/x/...
- now that we're accessing this file from disk, it's more like file://.netlify/edge-functions/vendor...
. Before, with the HTTPS address, fetch
would fall back to an HTTP request anyways.
So TL;DR: This looks like we're replacing a solid disk-read with a brittle network fetch. In reality, it's always been a brittle network fetch, so this is fine-ish!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we download that wasm file ourselves and manually vendor it? i.e. manually pull from https://github.com/worker-tools/html-rewriter/blob/v0.1.0-pre.17/vendor/html_rewriter_bg.wasm and avoid doing a patch (it's bit icky to me, but manual download is icky as well, so I guess - pick your poison). This way at least we would avoid this brittle network fetch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried that, but the problem is not only that deno vendor
doesn't download WASM files - Deno's eszip tool (that we use for bundling) also isn't able to detect the import, so it doesn't bundle the file. This will probably change once https://github.com/tc39/proposal-source-phase-imports lands, but until then the HTTP fetch is the only thing we can do :/
Co-authored-by: Michal Piechowiak <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
This PR vendors all dependencies of the edge function templates into the
src/templates/vendor
directory, and sets thefunctions[*].deno_import_map
directive to use it at build-time. This should shield next-runtime builds against deno.land outages.Documentation
Tests
I didn't add any tests - hoping our existing E2E suite will capture any regressions.
Relevant links (GitHub issues, etc.) or a picture of cute animal
Closes https://github.com/netlify/pod-ecosystem-frameworks/issues/404.