Skip to content

Commit 148e61d

Browse files
Princesseuhematipico
authored andcommitted
feat: remove webapi in favor of a smaller polyfill (#7840)
* feat: remove webapi in favor of a smaller polyfill * test: remove old test * test: 🤦‍♀️ * chore: changeset
1 parent 7d2f311 commit 148e61d

84 files changed

Lines changed: 37 additions & 3775 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/spicy-eels-rush.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'astro': major
3+
'@astrojs/netlify': major
4+
'@astrojs/vercel': major
5+
'@astrojs/node': major
6+
---
7+
8+
Reduced the amount of polyfills provided by Astro. Astro will no longer provide (no-op) polyfills for several web apis such as HTMLElement, Image or Document. If you need access to those APIs on the server, we recommend using more proper polyfills available on npm.

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
packages/**/*.min.js
33
packages/**/dist/**/*
44
packages/**/fixtures/**/*
5-
packages/webapi/**/*
65
packages/astro/vendor/vite/**/*
76
examples/**/*
87
scripts/**/*

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ benchmark/results/
2222
.changeset
2323

2424
# Files
25-
packages/webapi/mod.d.ts
2625
pnpm-lock.yaml

benchmark/packages/timer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"dev": "astro-scripts dev \"src/**/*.ts\""
2424
},
2525
"dependencies": {
26-
"@astrojs/webapi": "workspace:*",
2726
"server-destroy": "^1.0.1"
2827
},
2928
"peerDependencies": {

benchmark/packages/timer/src/server.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { polyfill } from '@astrojs/webapi';
21
import type { SSRManifest } from 'astro';
3-
import { NodeApp } from 'astro/app/node';
2+
import { NodeApp, applyPolyfills } from 'astro/app/node';
43
import type { IncomingMessage, ServerResponse } from 'node:http';
54

6-
polyfill(globalThis, {
7-
exclude: 'window document',
8-
});
5+
applyPolyfills();
96

107
export function createExports(manifest: SSRManifest) {
118
const app = new NodeApp(manifest);

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
}
7474
},
7575
"dependencies": {
76-
"@astrojs/webapi": "workspace:*",
7776
"astro-benchmark": "workspace:*"
7877
},
7978
"devDependencies": {

packages/astro/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"@astrojs/language-server": "^1.0.0",
121121
"@astrojs/markdown-remark": "^2.2.1",
122122
"@astrojs/telemetry": "^2.1.1",
123-
"@astrojs/webapi": "^2.2.0",
124123
"@babel/core": "^7.22.5",
125124
"@babel/generator": "^7.22.5",
126125
"@babel/parser": "^7.22.5",

packages/astro/src/core/app/node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IncomingMessage } from 'node:http';
66
import { TLSSocket } from 'node:tls';
77
import { deserializeManifest } from './common.js';
88
import { App, type MatchOptions } from './index.js';
9+
export { apply as applyPolyfills } from '../polyfill.js';
910

1011
const clientAddressSymbol = Symbol.for('astro.clientAddress');
1112

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import { polyfill } from '@astrojs/webapi';
1+
import { File } from 'node:buffer';
2+
import crypto from 'node:crypto';
3+
4+
// NOTE: This file does not intend to polyfill everything that exists, its main goal is to make life easier
5+
// for users deploying to runtime that do support these features. In the future, we hope for this file to disappear.
26

37
export function apply() {
4-
// polyfill WebAPIs for Node.js runtime
5-
polyfill(globalThis, {
6-
exclude: 'window document',
7-
});
8+
// Remove when Node 18 is dropped for Node 20
9+
if (!globalThis.crypto) {
10+
Object.defineProperty(globalThis, 'crypto', {
11+
value: crypto.webcrypto,
12+
});
13+
}
14+
15+
// Remove when Node 18 is dropped for Node 20
16+
if (!globalThis.File) {
17+
Object.defineProperty(globalThis, 'File', {
18+
value: File,
19+
});
20+
}
821
}

packages/astro/test/custom-elements.test.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)