refactor(@angular/build): remove direct usage of undici dependency for SSR

The Node.js types (`@types/node`) now contains the information for the `Response`
class and the global `fetch` function. The `Response` object is also globally
accessible in all versions of Node.js supported by the Angular CLI. This removes
the need to depend directly on the `undici` package.
The `undici` package is still used for unit-testing and remains as a development
dependency.
This commit is contained in:
Charles Lyding 2024-07-08 10:48:49 -04:00 committed by Alan Agius
parent 4da922e4f4
commit 4286bb03b5
6 changed files with 5 additions and 9 deletions

View File

@ -95,7 +95,6 @@ ts_library(
"@npm//semver",
"@npm//tslib",
"@npm//typescript",
"@npm//undici",
"@npm//vite",
"@npm//watchpack",
],

View File

@ -42,7 +42,6 @@
"rollup": "4.18.0",
"sass": "1.77.6",
"semver": "7.6.2",
"undici": "6.19.2",
"vite": "5.3.3",
"watchpack": "2.4.1"
},

View File

@ -10,7 +10,6 @@ import { lookup as lookupMimeType } from 'mrmime';
import { readFile } from 'node:fs/promises';
import { extname } from 'node:path';
import { workerData } from 'node:worker_threads';
import { Response, fetch } from 'undici';
/**
* This is passed as workerData when setting up the worker via the `piscina` package.
@ -25,8 +24,7 @@ const assetsCache: Map<string, { headers: undefined | Record<string, string>; co
const RESOLVE_PROTOCOL = 'resolve:';
export function patchFetchToLoadInMemoryAssets(): void {
const global = globalThis as unknown as { fetch: typeof fetch };
const originalFetch = global.fetch;
const originalFetch = globalThis.fetch;
const patchedFetch: typeof fetch = async (input, init) => {
let url: URL;
if (input instanceof URL) {
@ -72,5 +70,5 @@ export function patchFetchToLoadInMemoryAssets(): void {
});
};
global.fetch = patchedFetch;
globalThis.fetch = patchedFetch;
}

View File

@ -198,7 +198,6 @@ ts_library(
"@npm//tree-kill",
"@npm//tslib",
"@npm//typescript",
"@npm//undici",
"@npm//vite",
"@npm//watchpack",
"@npm//webpack",

View File

@ -61,7 +61,6 @@
"terser": "5.29.2",
"tree-kill": "1.2.2",
"tslib": "2.6.3",
"undici": "6.19.2",
"vite": "5.3.3",
"watchpack": "2.4.1",
"webpack": "5.92.1",
@ -73,6 +72,9 @@
"optionalDependencies": {
"esbuild": "0.23.0"
},
"devDependencies": {
"undici": "6.19.2"
},
"peerDependencies": {
"@angular/compiler-cli": "^18.0.0 || ^18.1.0-next.0",
"@angular/localize": "^18.0.0 || ^18.1.0-next.0",

View File

@ -418,7 +418,6 @@ __metadata:
rollup: "npm:4.18.0"
sass: "npm:1.77.6"
semver: "npm:7.6.2"
undici: "npm:6.19.2"
vite: "npm:5.3.3"
watchpack: "npm:2.4.1"
peerDependencies: