Skip to content

Commit

Permalink
chore: remove undici, set node to >=18.17
Browse files Browse the repository at this point in the history
The node engines "^18.17.0 || ^20.3.0 || >=21.0.0" are taken from
the `sharp` dependency, which probably has good reason for them.

All of these include global fetch, so undici is not needed.

Bun and deno also include fetch.
  • Loading branch information
wmertens committed Feb 4, 2024
1 parent c55c1eb commit 344a776
Show file tree
Hide file tree
Showing 32 changed files with 23 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ body:
id: system-info
attributes:
label: System Info
description: Output of `npx envinfo --system --npmPackages '{vite,undici,@builder.io/*}' --binaries --browsers`
description: Output of `npx envinfo --system --npmPackages '{vite,@builder.io/*}' --binaries --browsers`
render: shell
placeholder: System, Binaries, Browsers
validations:
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"terser": "^5.27.0",
"tsm": "^2.3.0",
"typescript": "5.3.3",
"undici": "*",
"vfile": "^6.0.1",
"vite": "^5.0.12",
"vite-imagetools": "^6.2.9",
Expand All @@ -102,7 +101,7 @@
"zod": "^3.22.4"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11",
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
"npm": "please-use-pnpm",
"yarn": "please-use-pnpm",
"pnpm": ">=8.6.12"
Expand Down
3 changes: 1 addition & 2 deletions packages/create-qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"yargs": "17.7.2"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11",
"npm": ">=6.0.0"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"files": [
"create-qwik.cjs",
Expand Down
1 change: 0 additions & 1 deletion packages/docs/contributors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-console */
import { fetch } from 'undici';
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';
Expand Down
3 changes: 1 addition & 2 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@
"tailwindcss": "^3.4.1",
"tsm": "^2.3.0",
"typescript": "5.3.3",
"undici": "*",
"valibot": "^0.25.0",
"vite": "^5.0.12",
"vite-plugin-inspect": "^0.8.1",
"wrangler": "^3.22.4"
},
"engines": {
"node": ">=18.11",
"node": "^18.17.0 || ^20.3.0 || >=21.0.0",
"npm": "please-use-pnpm",
"yarn": "please-use-pnpm",
"pnpm": ">=8.6.12"
Expand Down
1 change: 0 additions & 1 deletion packages/docs/scripts/showcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ async function captureMultipleScreenshots() {
}

async function getPagespeedData(url) {
const { fetch } = await import('undici');
const requestURL = `https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=${encodeURIComponent(
url
)}&key=AIzaSyApBC9gblaCzWrtEBgHnZkd_B37OF49BfM&category=PERFORMANCE&strategy=MOBILE`;
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"redent": "^4.0.0"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"homepage": "https://github.com/BuilderIO/qwik#readme",
"keywords": [
Expand Down
3 changes: 1 addition & 2 deletions packages/insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
"prettier-plugin-tailwindcss": "^0.5.11",
"tailwindcss": "^3.4.1",
"typescript": "5.3.3",
"undici": "*",
"vite": "^5.0.12",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.2.1"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"set-cookie-parser": "^2.6.0"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"exports": {
".": {
Expand Down
4 changes: 0 additions & 4 deletions packages/qwik-city/buildtime/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { build } from '../build';
import { ssrDevMiddleware, staticDistMiddleware } from './dev-server';
import { transformMenu } from '../markdown/menu';
import { generateQwikCityEntries } from '../runtime-generation/generate-entries';
import { patchGlobalThis } from '../../middleware/node/node-fetch';
import type { QwikVitePlugin } from '@builder.io/qwik/optimizer';
import fs from 'node:fs';
import {
Expand Down Expand Up @@ -42,9 +41,6 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {
let ssrFormat: 'esm' | 'cjs' = 'esm';
let outDir: string | null = null;

// Patch Stream APIs
patchGlobalThis();

(globalThis as any).__qwikCityNew = true;

const api: QwikCityPluginApi = {
Expand Down
4 changes: 0 additions & 4 deletions packages/qwik-city/middleware/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ import { extname, join, basename } from 'node:path';
import { fileURLToPath } from 'node:url';
import { computeOrigin, fromNodeHttp, getUrl } from './http';
import { MIME_TYPES } from '../request-handler/mime-types';
import { patchGlobalThis } from './node-fetch';
import { _deserializeData, _serializeData, _verifySerializable } from '@builder.io/qwik';
import type { Http2ServerRequest } from 'node:http2';

// @builder.io/qwik-city/middleware/node

/** @public */
export function createQwikCity(opts: QwikCityNodeRequestOptions) {
// Patch Stream APIs
patchGlobalThis();

const qwikSerializer = {
_deserializeData,
_serializeData,
Expand Down
35 changes: 0 additions & 35 deletions packages/qwik-city/middleware/node/node-fetch.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/qwik-city/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"@types/mdx": "^2.0.8",
"source-map": "0.7.4",
"svgo": "^3.2.0",
"undici": "*",
"vfile": "^6.0.1",
"vite": "^5.0.12",
"vite-imagetools": "^6.2.9",
Expand Down Expand Up @@ -44,7 +43,7 @@
"yaml": "^2.3.2"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"exports": {
".": {
Expand Down
5 changes: 2 additions & 3 deletions packages/qwik-city/runtime/src/service-worker/utils.unit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Request as NodeRequest, Response as NodeResponse } from 'undici';
import type { AppBundle } from './types';
import { getCacheToDelete, isAppBundleRequest, useCache } from './utils';
import { assert, test } from 'vitest';
Expand Down Expand Up @@ -78,9 +77,9 @@ test('useCache', () => {

export function mockRequest(url?: string): Request {
url = url || 'https://qwik.builder.io/';
return new NodeRequest(url) as any;
return new Request(url);
}

export function mockResponse(body?: any): Response {
return new NodeResponse(body) as any;
return new Response(body);
}
3 changes: 0 additions & 3 deletions packages/qwik-city/static/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createSystem } from './node-system';
import { isMainThread, workerData } from 'node:worker_threads';
import { mainThread } from '../main-thread';
import { workerThread } from '../worker-thread';
import { patchGlobalThis } from 'packages/qwik-city/middleware/node/node-fetch';

export async function generate(opts: StaticGenerateOptions) {
if (isMainThread) {
Expand All @@ -17,8 +16,6 @@ export async function generate(opts: StaticGenerateOptions) {

if (!isMainThread && workerData) {
(async () => {
patchGlobalThis();

// self initializing worker thread with workerData
const sys = await createSystem(workerData);
await workerThread(sys);
Expand Down
3 changes: 0 additions & 3 deletions packages/qwik-city/static/node/node-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import type { StaticGenerateOptions, System } from '../types';
import fs from 'node:fs';
import { dirname, join } from 'node:path';
import { patchGlobalThis } from '../../middleware/node/node-fetch';
import { createNodeMainProcess } from './node-main';
import { createNodeWorkerProcess } from './node-worker';
import { normalizePath } from '../../utils/fs';

/** @public */
export async function createSystem(opts: StaticGenerateOptions) {
patchGlobalThis();

const createWriteStream = (filePath: string) => {
return fs.createWriteStream(filePath, {
flags: 'w',
Expand Down
3 changes: 1 addition & 2 deletions packages/qwik-labs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
"np": "^8.0.4",
"prettier": "^3.2.4",
"typescript": "5.3.3",
"undici": "*",
"vite": "^5.0.12"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"vite": "^5.0.12"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"vite-plugin-static-copy": "^1.0.0"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"kleur": "4.1.5"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/cli/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function cleanPackageJson(srcPkg: IntegrationPackageJson) {
types: srcPkg.types,
exports: srcPkg.exports,
files: srcPkg.files,
engines: { node: '>=15.0.0' },
engines: { node: srcPkg.engines?.node || '^18.17.0 || ^20.3.0 || >=21.0.0' },
};

Object.keys(cleanedPkg).forEach((prop) => {
Expand Down
19 changes: 3 additions & 16 deletions packages/qwik/src/optimizer/src/plugins/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,9 @@ export async function configureDevServer(
isClientDevOnly: boolean,
clientDevInput: string | undefined
) {
if (typeof fetch !== 'function' && sys.env === 'node') {
// polyfill fetch() when not available in Node.js

try {
if (!globalThis.fetch) {
const undici = await sys.strictDynamicImport('undici');
globalThis.fetch = undici.fetch;
globalThis.Headers = undici.Headers;
globalThis.Request = undici.Request;
globalThis.Response = undici.Response;
globalThis.FormData = undici.FormData;
}
} catch {
console.warn('Global fetch() was not installed');
// Nothing
}
if (typeof fetch !== 'function') {
console.error('Global fetch() is missing');
process.exit(1);
}

// qwik middleware injected BEFORE vite internal middlewares
Expand Down
22 changes: 1 addition & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion scripts/binding-platform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type BuildConfig, ensureDir } from './util';
import spawn from 'cross-spawn';
import { join } from 'node:path';
import { fetch } from 'undici';
import semver from 'semver';
import { existsSync } from 'node:fs';
import { copyFile, readdir, writeFile } from 'fs/promises';
Expand Down
1 change: 0 additions & 1 deletion scripts/create-qwik-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ async function updatePackageJson(config: BuildConfig, destDir: string) {
setVersionFromRoot('prettier');
setVersionFromRoot('typescript');
setVersionFromRoot('node-fetch');
setVersionFromRoot('undici');
setVersionFromRoot('vite');

await writePackageJson(destDir, pkgJson);
Expand Down
Loading

0 comments on commit 344a776

Please sign in to comment.