Skip to content

Commit

Permalink
feat: remove webapi in favor of a smaller polyfill (#7840)
Browse files Browse the repository at this point in the history
* feat: remove webapi in favor of a smaller polyfill

* test: remove old test

* test: 🤦‍♀️

* chore: changeset
  • Loading branch information
Princesseuh authored and ematipico committed Aug 8, 2023
1 parent 7d2f311 commit 148e61d
Show file tree
Hide file tree
Showing 84 changed files with 37 additions and 3,775 deletions.
8 changes: 8 additions & 0 deletions .changeset/spicy-eels-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'astro': major
'@astrojs/netlify': major
'@astrojs/vercel': major
'@astrojs/node': major
---

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.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
packages/**/*.min.js
packages/**/dist/**/*
packages/**/fixtures/**/*
packages/webapi/**/*
packages/astro/vendor/vite/**/*
examples/**/*
scripts/**/*
Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ benchmark/results/
.changeset

# Files
packages/webapi/mod.d.ts
pnpm-lock.yaml
1 change: 0 additions & 1 deletion benchmark/packages/timer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"dev": "astro-scripts dev \"src/**/*.ts\""
},
"dependencies": {
"@astrojs/webapi": "workspace:*",
"server-destroy": "^1.0.1"
},
"peerDependencies": {
Expand Down
7 changes: 2 additions & 5 deletions benchmark/packages/timer/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { polyfill } from '@astrojs/webapi';
import type { SSRManifest } from 'astro';
import { NodeApp } from 'astro/app/node';
import { NodeApp, applyPolyfills } from 'astro/app/node';
import type { IncomingMessage, ServerResponse } from 'node:http';

polyfill(globalThis, {
exclude: 'window document',
});
applyPolyfills();

export function createExports(manifest: SSRManifest) {
const app = new NodeApp(manifest);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
}
},
"dependencies": {
"@astrojs/webapi": "workspace:*",
"astro-benchmark": "workspace:*"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
"@astrojs/language-server": "^1.0.0",
"@astrojs/markdown-remark": "^2.2.1",
"@astrojs/telemetry": "^2.1.1",
"@astrojs/webapi": "^2.2.0",
"@babel/core": "^7.22.5",
"@babel/generator": "^7.22.5",
"@babel/parser": "^7.22.5",
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/app/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IncomingMessage } from 'node:http';
import { TLSSocket } from 'node:tls';
import { deserializeManifest } from './common.js';
import { App, type MatchOptions } from './index.js';
export { apply as applyPolyfills } from '../polyfill.js';

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

Expand Down
23 changes: 18 additions & 5 deletions packages/astro/src/core/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { polyfill } from '@astrojs/webapi';
import { File } from 'node:buffer';
import crypto from 'node:crypto';

// NOTE: This file does not intend to polyfill everything that exists, its main goal is to make life easier
// for users deploying to runtime that do support these features. In the future, we hope for this file to disappear.

export function apply() {
// polyfill WebAPIs for Node.js runtime
polyfill(globalThis, {
exclude: 'window document',
});
// Remove when Node 18 is dropped for Node 20
if (!globalThis.crypto) {
Object.defineProperty(globalThis, 'crypto', {
value: crypto.webcrypto,
});
}

// Remove when Node 18 is dropped for Node 20
if (!globalThis.File) {
Object.defineProperty(globalThis, 'File', {
value: File,
});
}
}
70 changes: 0 additions & 70 deletions packages/astro/test/custom-elements.test.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/astro/test/fixtures/custom-elements/astro.config.mjs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions packages/astro/test/fixtures/custom-elements/package.json

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions packages/astro/test/fixtures/custom-elements/src/pages/ctr.astro

This file was deleted.

15 changes: 0 additions & 15 deletions packages/astro/test/fixtures/custom-elements/src/pages/index.astro

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions packages/astro/test/fixtures/custom-elements/src/pages/nossr.astro

This file was deleted.

6 changes: 0 additions & 6 deletions packages/astro/test/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { polyfill } from '@astrojs/webapi';
import { execa } from 'execa';
import fastGlob from 'fast-glob';
import fs from 'node:fs';
Expand All @@ -17,11 +16,6 @@ import { nodeLogDestination } from '../dist/core/logger/node.js';
import preview from '../dist/core/preview/index.js';
import { sync } from '../dist/core/sync/index.js';

// polyfill WebAPIs to globalThis for Node v12, Node v14, and Node v16
polyfill(globalThis, {
exclude: 'window document',
});

// Disable telemetry when running tests
process.env.ASTRO_TELEMETRY_DISABLED = true;

Expand Down
1 change: 0 additions & 1 deletion packages/integrations/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
},
"dependencies": {
"@astrojs/underscore-redirects": "^0.2.0",
"@astrojs/webapi": "^2.2.0",
"@netlify/functions": "^1.6.0",
"esbuild": "^0.18.16"
},
Expand Down
Loading

0 comments on commit 148e61d

Please sign in to comment.