-
Notifications
You must be signed in to change notification settings - Fork 86
fix: vendor deno dependencies #2302
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1addb01
fix: vendor deno dependencies
Skn0tt 4988b83
chore: install deno along node
Skn0tt 88ac9a9
fix: install deno in cypress tests
Skn0tt 30416b5
fix: try scoping down the import map
Skn0tt 187aae1
fix: import straight from vendor directory
Skn0tt b5ae8db
fix: run vendoring before testing deno
Skn0tt 4ffa6b1
fix: npm install needs deno
Skn0tt 7201a27
fix: run build:vendor in right dir
Skn0tt 1848684
refactor: move deno tests into normal test file
Skn0tt 1ec8485
fix: include vendor files in package
Skn0tt e8428c8
fix: patch html rewriter to fetch wasm from web, not from disk
Skn0tt 226f5c7
Merge branch 'main' into vendor-deno-deps
Skn0tt 9a2b90d
chore: use precise path
Skn0tt 35886e1
Update packages/runtime/src/templates/vendor.ts
Skn0tt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/templates/vendor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
56c56 | ||
< fetch(new URL("./vendor/html_rewriter_bg.wasm", import.meta.url).href) | ||
--- | ||
> fetch("https://deno.land/x/[email protected]/vendor/html_rewriter_bg.wasm") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"lib/**/*", | ||
"src/templates/edge/*", | ||
"src/templates/edge-shared/*", | ||
"src/templates/vendor/*", | ||
"index.js", | ||
"manifest.yml" | ||
], | ||
|
@@ -52,7 +53,9 @@ | |
"publish:install": "npm ci", | ||
"publish:test": "cd .. && npm ci && npm test", | ||
"clean": "rimraf lib dist-types", | ||
"build": "tsc", | ||
"build": "run-s build:*", | ||
"build:vendor": "rimraf src/templates/vendor && deno vendor src/templates/vendor.ts --output=src/templates/vendor && patch src/templates/vendor/deno.land/x/[email protected]/index.ts html_rewriter.patch", | ||
"build:tsc": "tsc", | ||
"watch": "tsc --watch", | ||
"prepare": "npm run build" | ||
}, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,10 @@ | |
*/ | ||
|
||
// Deno imports | ||
import type { Key } from 'https://deno.land/x/[email protected]/index.ts' | ||
import type { Key } from '../vendor/deno.land/x/[email protected]/index.ts' | ||
|
||
import { compile, pathToRegexp } from 'https://deno.land/x/[email protected]/index.ts' | ||
import { getCookies } from 'https://deno.land/std@0.148.0/http/cookie.ts' | ||
import { compile, pathToRegexp } from '../vendor/deno.land/x/[email protected]/index.ts' | ||
import { getCookies } from '../vendor/deno.land/std@0.175.0/http/cookie.ts' | ||
|
||
// Inlined/re-implemented types | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { Context } from 'https://edge.netlify.com' | ||
import { ElementHandlers, HTMLRewriter } from 'https://deno.land/x/[email protected]/index.ts' | ||
import { ElementHandlers, HTMLRewriter } from '../vendor/deno.land/x/[email protected]/index.ts' | ||
|
||
export interface FetchEventResult { | ||
response: Response | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { NextRequest } from 'https://esm.sh/v91/[email protected]/deno/dist/server/web/spec-extension/request.js' | ||
import { NextResponse } from 'https://esm.sh/v91/[email protected]/deno/dist/server/web/spec-extension/response.js' | ||
import { fromFileUrl } from 'https://deno.land/std@0.151.0/path/mod.ts' | ||
import { NextRequest } from '../vendor/esm.sh/v91/[email protected]/deno/dist/server/web/spec-extension/request.js' | ||
import { NextResponse } from '../vendor/esm.sh/v91/[email protected]/deno/dist/server/web/spec-extension/response.js' | ||
import { fromFileUrl } from '../vendor/deno.land/std@0.175.0/path/mod.ts' | ||
import { buildResponse, isFunction } from '../edge-shared/utils.ts' | ||
|
||
globalThis.NFRequestContextMap ||= new Map() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// @ts-check | ||
// deno-lint-ignore-file prefer-const no-unused-vars | ||
import { decode as _base64Decode } from 'https://deno.land/[email protected]/encoding/base64.ts' | ||
import BufferCompat from 'https://deno.land/[email protected]/node/buffer.ts' | ||
import EventsCompat from 'https://deno.land/[email protected]/node/events.ts' | ||
import AsyncHooksCompat from 'https://deno.land/[email protected]/node/async_hooks.ts' | ||
import AssertCompat from 'https://deno.land/[email protected]/node/assert.ts' | ||
import UtilCompat from 'https://deno.land/[email protected]/node/util.ts' | ||
import { decode as _base64Decode } from '../vendor/deno.land/[email protected]/encoding/base64.ts' | ||
import BufferCompat from '../vendor/deno.land/[email protected]/node/buffer.ts' | ||
import EventsCompat from '../vendor/deno.land/[email protected]/node/events.ts' | ||
import AsyncHooksCompat from '../vendor/deno.land/[email protected]/node/async_hooks.ts' | ||
import AssertCompat from '../vendor/deno.land/[email protected]/node/assert.ts' | ||
import UtilCompat from '../vendor/deno.land/[email protected]/node/util.ts' | ||
|
||
/** | ||
* These are the shims, polyfills and other kludges to make Next.js work in standards-compliant runtime. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// this file isn't meant to be imported. | ||
// it's a list of all external modules that we use, | ||
// and we vendor those into the `vendor/` directory | ||
// for consumption in other files. | ||
Skn0tt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Vendoring happens automatically as part of runtime `build` script. | ||
// You can trigger just vendoring without full package build by running `build:vendor` script. | ||
|
||
import 'https://deno.land/[email protected]/encoding/base64.ts' | ||
import 'https://deno.land/[email protected]/http/cookie.ts' | ||
import 'https://deno.land/[email protected]/node/buffer.ts' | ||
import 'https://deno.land/[email protected]/node/events.ts' | ||
import 'https://deno.land/[email protected]/node/async_hooks.ts' | ||
import 'https://deno.land/[email protected]/node/assert.ts' | ||
import 'https://deno.land/[email protected]/node/util.ts' | ||
import 'https://deno.land/[email protected]/path/mod.ts' | ||
|
||
import 'https://deno.land/x/[email protected]/index.ts' | ||
import 'https://deno.land/x/[email protected]/index.ts' | ||
|
||
import 'https://esm.sh/v91/[email protected]/deno/dist/server/web/spec-extension/request.js' | ||
import 'https://esm.sh/v91/[email protected]/deno/dist/server/web/spec-extension/response.js' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 viahttps://
, meaning thatimport.meta.url
was something likehttps://deno.land/x/...
- now that we're accessing this file from disk, it's more likefile://.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 :/