Skip to content

ci: build with deno v2 #2888

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deno-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x.x
deno-version: v2.x.x
- name: Vendor Deno modules
run: deno vendor edge-runtime/vendor.ts --output=edge-runtime/vendor --force
run: deno --allow-import edge-runtime/vendor.ts
- name: Test
run: deno test -A edge-runtime/
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/build/blob/main/packages/edge-bundler/node/bridge.ts#L20
deno-version: v1.46.3
deno-version: v2.3.1
- name: Extract tag and version
id: extract
run: |-
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/build/blob/main/packages/edge-bundler/node/bridge.ts#L20
deno-version: v1.46.3
deno-version: v2.3.1
- name: Build
run: npm run build
if: ${{ steps.release.outputs.release_created }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/build/blob/main/packages/edge-bundler/node/bridge.ts#L20
deno-version: v1.46.3
deno-version: v2.3.1
- name: 'Install dependencies'
run: npm ci
- name: 'Prepare Netlify CLI'
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/edge-bundler/blob/e55f825bd985d3c92e21d1b765d71e70d5628fba/node/bridge.ts#L17
deno-version: v1.46.3
deno-version: v2.3.1
- name: 'Install dependencies'
run: npm ci
- name: 'Build'
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/build/blob/main/packages/edge-bundler/node/bridge.ts#L20
deno-version: v1.46.3
deno-version: v2.3.1
- name: 'Install dependencies'
run: npm ci
- name: 'Build'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/size-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/build/blob/main/packages/edge-bundler/node/bridge.ts#L20
deno-version: v1.46.3
deno-version: v2.3.1
- run: npm ci

- name: Package size report
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:
uses: denoland/setup-deno@v1
with:
# Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/build/blob/main/packages/edge-bundler/node/bridge.ts#L20
deno-version: v1.46.3
deno-version: v2.3.1

- name: install runtime
run: npm install --ignore-scripts
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"imports": {
"@netlify/edge-functions": "https://edge.netlify.com/v1/index.ts"
},
"importMap": "./edge-runtime/vendor/import_map.json"
"vendor": true
}
4 changes: 2 additions & 2 deletions edge-runtime/lib/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Context } from '@netlify/edge-functions'

import type { ElementHandlers } from '../vendor/deno.land/x/htmlrewriter@v1.0.0/src/index.ts'
import { getCookies } from '../vendor/deno.land/std@0.175.0/http/cookie.ts'
import type { ElementHandlers } from 'https://deno.land/x/htmlrewriter@v1.0.0/src/index.ts'
import { getCookies } from 'https://deno.land/x/std@0.175.0/http/cookie.ts'

type NextDataTransform = <T>(data: T) => T

Expand Down
5 changes: 1 addition & 4 deletions edge-runtime/lib/response.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { Context } from '@netlify/edge-functions'
import {
HTMLRewriter,
type TextChunk,
} from '../vendor/deno.land/x/htmlrewriter@v1.0.0/src/index.ts'
import { HTMLRewriter, type TextChunk } from 'https://deno.land/x/htmlrewriter@v1.0.0/src/index.ts'

import { updateModifiedHeaders } from './headers.ts'
import type { StructuredLogger } from './logging.ts'
Expand Down
6 changes: 3 additions & 3 deletions edge-runtime/lib/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* Some types have been re-implemented to be more compatible with Deno or avoid chains of dependent files
*/

import type { Key } from '../vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts'
import type { Key } from 'https://deno.land/x/path_to_regexp@v6.2.1/index.ts'

import { compile, pathToRegexp } from '../vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts'
import { getCookies } from '../vendor/deno.land/std@0.175.0/http/cookie.ts'
import { compile, pathToRegexp } from 'https://deno.land/x/path_to_regexp@v6.2.1/index.ts'
import { getCookies } from 'https://deno.land/x/std@0.175.0/http/cookie.ts'

/*
┌─────────────────────────────────────────────────────────────────────────┐
Expand Down
16 changes: 6 additions & 10 deletions src/build/functions/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ const writeHandlerFile = async (ctx: PluginContext, { matchers, name }: NextDefi
JSON.stringify(minimalNextConfig),
)

const htmlRewriterWasm = await readFile(
join(
ctx.pluginDir,
'edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter_bg.wasm',
),
)
// const htmlRewriterWasm = await readFile(
// join(
// ctx.pluginDir,
// 'edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter_bg.wasm',
// ),
// )

// Writing the function entry file. It wraps the middleware code with the
// compatibility layer mentioned above.
Expand All @@ -108,10 +108,6 @@ const writeHandlerFile = async (ctx: PluginContext, { matchers, name }: NextDefi
import { handleMiddleware } from './edge-runtime/middleware.ts';
import handler from './server/${name}.js';

await htmlRewriterInit({ module_or_path: Uint8Array.from(${JSON.stringify([
...htmlRewriterWasm,
])}) });

export default (req, context) => handleMiddleware(req, context, handler);
`,
)
Expand Down
41 changes: 20 additions & 21 deletions tools/build-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,32 @@ export async function vendorDeno({
}

console.log(`📦 Vendoring Deno modules for '${vendorSource}' into '${vendorDest}'...`)
// --output=${vendorDest}
await execaCommand(`deno vendor ${vendorSource} --force`, {
await execaCommand(`deno --allow-import ${vendorSource}`, {
cwd,
})

if (wasmFilesToDownload.length !== 0) {
console.log(`⬇️ Downloading wasm files...`)
// if (wasmFilesToDownload.length !== 0) {
// console.log(`⬇️ Downloading wasm files...`)

// deno vendor doesn't work well with wasm files
// see https://github.com/denoland/deno/issues/14123
// to workaround this we copy the wasm files manually
// (note Deno 2 allows to vendor wasm files, but it also require modules to import them and not fetch and instantiate them
// se being able to drop downloading is dependent on implementation of wasm handling in external modules as well)
await Promise.all(
wasmFilesToDownload.map(async (urlString) => {
const url = new URL(urlString)
// // deno vendor doesn't work well with wasm files
// // see https://github.com/denoland/deno/issues/14123
// // to workaround this we copy the wasm files manually
// // (note Deno 2 allows to vendor wasm files, but it also require modules to import them and not fetch and instantiate them
// // so being able to drop downloading is dependent on implementation of wasm handling in external modules as well)
// await Promise.all(
// wasmFilesToDownload.map(async (urlString) => {
// const url = new URL(urlString)

const destination = join(vendorDest, url.hostname, url.pathname)
// const destination = join(vendorDest, url.hostname, url.pathname)

const res = await fetch(url)
if (!res.ok)
throw new Error(`Failed to fetch .wasm file to vendor. Response status: ${res.status}`)
const fileStream = createWriteStream(destination, { flags: 'wx' })
await finished(Readable.fromWeb(res.body).pipe(fileStream))
}),
)
}
// const res = await fetch(url)
// if (!res.ok)
// throw new Error(`Failed to fetch .wasm file to vendor. Response status: ${res.status}`)
// const fileStream = createWriteStream(destination, { flags: 'wx' })
// await finished(Readable.fromWeb(res.body).pipe(fileStream))
// }),
// )
// }

console.log(`✅ Vendored Deno modules for '${vendorSource}' into '${vendorDest}'`)
}
Loading