Skip to content
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

BREAKING CHANGE: Drop Node.js 12 #191

Merged
merged 15 commits into from
Oct 27, 2022
Merged
10 changes: 10 additions & 0 deletions .changeset/olive-rivers-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@edge-runtime/cookies": major
"@edge-runtime/jest-environment": major
"@edge-runtime/ponyfill": major
"@edge-runtime/primitives": major
"@edge-runtime/vm": major
"@edge-runtime/docs": major
---

BREAKING CHANGE: Drop Node.js 12
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
# https://nodejs.org/en/about/releases/
# https://pnpm.io/installation#compatibility
version:
- node: 12.x
- node: 14.x
- node: 16.x
- node: 18.x
Expand All @@ -40,7 +39,6 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: ${{ matrix.version.node == '12.x' && '6' || '7' }}
run_install: |
- recursive: true
args: [--loglevel=error]
Expand Down
22 changes: 10 additions & 12 deletions docs/pages/features/polyfills.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ If you are using an old Node.js version, then it is likely one of these Web APIs

Under the hood, the following Web APIs are used by the **Edge Runtime**:

| polyfill | node12 | node14 | node16 | node18 |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ | ------ | ------ |
| [http](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/patches/http.js) | x | | | |
| [util.types](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/patches/util-types.js) | x | | | |
| [buffer](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/patches/buffer.js) | x | | | |
| [WebCrypto](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/crypto.js) | x | x | | |
| [AbortController, AbortSignal, DOMException](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/abort-controller.js) | x | x | | |
| [base64](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/encoding.js) | x | x | | |
| [fetch, Request, Response](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/fetch.js) | x | x | x | |
| [URLPattern](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/url.js) | x | x | x | x |
| [Cache](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/cache.js) | x | x | x | x |
| [WebStreams](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/streams.js) | x | x | x | x |
| polyfill | node14 | node16 | node18 |
| ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ | ------ |
| [util.types](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/patches/util-types.js) | x | | |
| [WebCrypto](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/crypto.js) | x | | |
| [AbortController, AbortSignal, DOMException](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/abort-controller.js) | x | | |
| [base64](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/encoding.js) | x | | |
| [fetch, Request, Response](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/fetch.js) | x | x | |
| [URLPattern](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/url.js) | x | x | x |
| [Cache](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/cache.js) | x | x | x |
| [WebStreams](https://github.com/vercel/edge-runtime/blob/main/packages/primitives/src/primitives/streams.js) | x | x | x |

The Edge Runtime polyfills missing APIs for backward compatibility with older Node.js versions.

Expand Down
15 changes: 8 additions & 7 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { Config } from '@jest/types'
import path from 'path'

export default (rootDir: string): Config.InitialOptions => {
return {
rootDir,
setupFilesAfterEnv: [path.join(__dirname, 'jest.setup.js')],
globals: {
'ts-jest': {
'diagnostics': true,
'isolatedModules': true,
},
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
'diagnostics': true,
'isolatedModules': true,
},
],
},
preset: 'ts-jest/presets/default',
testEnvironment: 'node',
Expand Down
1 change: 0 additions & 1 deletion jest.setup.js

This file was deleted.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,25 @@
},
"devDependencies": {
"@changesets/cli": "latest",
"@jest/types": "28.1.3",
styfle marked this conversation as resolved.
Show resolved Hide resolved
"@jest/types": "29.1.2",
"@svitejs/changesets-changelog-github-compact": "latest",
"@types/jest": "28.1.8",
"@types/node": "12",
"@types/jest": "29.0.3",
"@types/node": "14",
"c8": "latest",
"finepack": "latest",
"git-authors-cli": "latest",
"jest": "28.1.3",
"jest-watch-typeahead": "latest",
"jest": "29.0.3",
"jest-watch-typeahead": "2.2.0",
"nano-staged": "latest",
"prettier": "latest",
"simple-git-hooks": "latest",
"ts-jest": "28.0.8",
"ts-node": "latest",
"ts-jest": "29.0.3",
"ts-node": "10.9.1",
"turbo": "latest",
"typescript": "latest"
},
"engines": {
"node": ">=12",
"pnpm": ">=6"
"node": ">=14"
},
"scripts": {
"build": "turbo run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/cookies/test/request-cookies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test('formatting with @edge-runtime/format', () => {
const format = createFormat()
const result = format(cookies)
expect(result).toMatchInlineSnapshot(
`"RequestCookies {\\"a\\":{\\"name\\":\\"a\\",\\"value\\":\\"1\\"},\\"b\\":{\\"name\\":\\"b\\",\\"value\\":\\"2\\"}}"`
`"RequestCookies {"a":{"name":"a","value":"1"},"b":{"name":"b","value":"2"}}"`
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/cookies/test/response-cookies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ test('formatting with @edge-runtime/format', () => {
const format = createFormat()
const result = format(cookies)
expect(result).toMatchInlineSnapshot(
`"ResponseCookies {\\"a\\":{\\"name\\":\\"a\\",\\"value\\":\\"1\\",\\"httpOnly\\":true,\\"path\\":\\"/\\"},\\"b\\":{\\"name\\":\\"b\\",\\"value\\":\\"2\\",\\"sameSite\\":\\"lax\\",\\"path\\":\\"/\\"}}"`
`"ResponseCookies {"a":{"name":"a","value":"1","httpOnly":true,"path":"/"},"b":{"name":"b","value":"2","sameSite":"lax","path":"/"}}"`
)
})
2 changes: 1 addition & 1 deletion packages/jest-environment/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test('TextEncoder references the same global Uint8Array constructor', () => {
})

test('allows to run fetch', async () => {
const response = await fetch('https://vercel.com')
const response = await fetch('https://example.vercel.sh')
expect(response.status).toEqual(200)
})

Expand Down
4 changes: 2 additions & 2 deletions packages/ponyfill/test/crypto.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { crypto, TextEncoder } from '..'

test('randomUUID', async () => {
test('crypto.randomUUID', async () => {
expect(crypto.randomUUID()).toEqual(expect.stringMatching(/^[a-f0-9-]+$/))
})

test('crypto.subtle digest', async () => {
test('crypto.subtle.digest', async () => {
const digest = await crypto.subtle.digest(
'SHA-256',
new TextEncoder().encode('Hello, world')
Expand Down
4 changes: 2 additions & 2 deletions packages/ponyfill/test/url-pattern.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { URLPattern } from '..'

test('URLPattern', () => {
const urlPattern = new URLPattern('/:foo/:bar', 'https://example.com')
const urlPattern = new URLPattern('/:foo/:bar', 'https://example.vercel.sh')
const urlPatternAsType: URLPattern = urlPattern
const result = urlPatternAsType.exec('https://example.com/1/2')
const result = urlPatternAsType.exec('https://example.vercel.sh/1/2')
expect(result?.pathname.groups).toEqual({
foo: '1',
bar: '2',
Expand Down
2 changes: 0 additions & 2 deletions packages/primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"devDependencies": {
"@edge-runtime/format": "workspace:1.1.0",
"@peculiar/webcrypto": "1.4.0",
"@types/uuid": "8.3.4",
"@ungap/structured-clone": "1.0.1",
"aggregate-error-ponyfill": "1.1.0",
"blob-polyfill": "7.0.20220408",
Expand All @@ -35,7 +34,6 @@
"tsup": "6",
"undici": "5.11.0",
"urlpattern-polyfill": "6.0.1",
"uuid": "9.0.0",
"web-streams-polyfill": "4.0.0-beta.3",
"whatwg-url": "11.0.0"
},
Expand Down
11 changes: 5 additions & 6 deletions packages/primitives/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { basename, join, parse, resolve } from 'path'
import { Options, build } from 'tsup'
import alias from 'esbuild-plugin-alias'
import { Options, build } from 'tsup'
import fs from 'fs'

const TARGET = ['node14.6']

const BUNDLE_OPTIONS: Options = {
bundle: true,
keepNames: true,
Expand All @@ -23,7 +25,7 @@ async function bundlePackage() {
resolve: true,
},
format: [],
target: ['node12.22'],
target: TARGET,
entry: filesExt
.map((f) => f.replace(/\.(js|ts)$/, '.d.ts'))
.map((f) => join(__dirname, '../type-definitions', f)),
Expand All @@ -40,7 +42,7 @@ async function bundlePackage() {
entryPoints,
outDir: outdir,
minify: false,
target: ['node12.22'],
target: TARGET,
esbuildOptions(opts, _context) {
opts.legalComments = 'external'
},
Expand All @@ -49,11 +51,8 @@ async function bundlePackage() {
},
esbuildPlugins: [
alias({
buffer: resolve('src/patches/buffer.js'),
http: resolve('src/patches/http.js'),
'util/types': resolve('src/patches/util-types.js'),
}),

{
name: 'alias-undici-core-request',
setup: (build) => {
Expand Down
7 changes: 0 additions & 7 deletions packages/primitives/src/patches/buffer.js

This file was deleted.

24 changes: 0 additions & 24 deletions packages/primitives/src/patches/http.js

This file was deleted.

13 changes: 1 addition & 12 deletions packages/primitives/src/primitives/crypto.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
/**
* Implement polyfills for the Crypto Module. Since we support down to Node 12
* we use a UUID package to support generating random values. We also must
* transform web/stream into the ponyfill require when bundling in case any
* dependency uses Node recent web streams.
*/
import { Crypto as WebCrypto, CryptoKey } from '@peculiar/webcrypto'
import { v4 as uuid } from 'uuid'

class Crypto extends WebCrypto {
#randomUUID = uuid
}
import { Crypto, CryptoKey } from '@peculiar/webcrypto'

function SubtleCrypto() {
if (!(this instanceof SubtleCrypto)) return new SubtleCrypto()
Expand Down
5 changes: 5 additions & 0 deletions packages/primitives/tests/crypto.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { crypto } from '../crypto'

test('crypto.randomUUID', () => {
expect(crypto.randomUUID()).toEqual(expect.stringMatching(/^[a-f0-9-]+$/))
})
3 changes: 1 addition & 2 deletions packages/primitives/tests/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ test('sets header calling Headers constructor', async () => {
})

test('sets headers unsupported in undici', async () => {
const url = new URL('/', 'https://example.com')
const url = new URL('/', 'https://example.vercel.sh')
const response = await fetch(url, {
headers: {
Connection: 'keep-alive',
'Keep-Alive': 'timeout=5, max=1000',
'Transfer-Encoding': 'gzip',
},
})
expect(response.status).toBe(200)
Expand Down
8 changes: 4 additions & 4 deletions packages/vm/tests/integration/body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ test('allows to read a FormData body as text', async () => {
expect(text.replace(/formdata-undici-0\.\d+/g, 'formdata-unidici-0.1234'))
.toMatchInlineSnapshot(`
"------formdata-unidici-0.1234
Content-Disposition: form-data; name=\\"name\\"
Content-Disposition: form-data; name="name"

John
------formdata-unidici-0.1234
Content-Disposition: form-data; name=\\"lastname\\"
Content-Disposition: form-data; name="lastname"

Doe
------formdata-unidici-0.1234
Content-Disposition: form-data; name=\\"metadata\\"; filename=\\"blob\\"
Content-Disposition: form-data; name="metadata"; filename="blob"
Content-Type: application/json

{
\\"hello\\": \\"world\\"
"hello": "world"
}
------formdata-unidici-0.1234--"
`)
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/tests/integration/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ test('throws when the URL is malformed', async () => {
})

test('Request.referrer is `about:client` by default', async () => {
const request = new Request('https://vercel.com')
const request = new Request('https://example.vercel.sh')
expect(request.referrer).toEqual('about:client')
})

test('Request.referrer can be customized', async () => {
const request = new Request('https://vercel.com', {
const request = new Request('https://example.vercel.sh', {
referrer: 'https://vercel.com/home',
})
expect(request.referrer).toEqual('https://vercel.com/home')
Expand Down
4 changes: 3 additions & 1 deletion packages/vm/tests/unit/edge-vm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ it('uses the same builtins in polyfills as in VM', () => {
new EdgeVM().evaluate(`(new AbortController()) instanceof Object`)
).toBe(true)
expect(
new EdgeVM().evaluate(`(new URL('https://vercel.com')) instanceof Object`)
new EdgeVM().evaluate(
`(new URL('https://example.vercel.sh')) instanceof Object`
)
).toBe(true)
expect(
new EdgeVM().evaluate(`(new URLSearchParams()) instanceof Object`)
Expand Down
Loading