Skip to content

Commit 4286bb0

Browse files
clydinalan-agius4
authored andcommitted
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.
1 parent 4da922e commit 4286bb0

File tree

6 files changed

+5
-9
lines changed

6 files changed

+5
-9
lines changed

packages/angular/build/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ ts_library(
9595
"@npm//semver",
9696
"@npm//tslib",
9797
"@npm//typescript",
98-
"@npm//undici",
9998
"@npm//vite",
10099
"@npm//watchpack",
101100
],

packages/angular/build/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"rollup": "4.18.0",
4343
"sass": "1.77.6",
4444
"semver": "7.6.2",
45-
"undici": "6.19.2",
4645
"vite": "5.3.3",
4746
"watchpack": "2.4.1"
4847
},

packages/angular/build/src/utils/server-rendering/fetch-patch.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { lookup as lookupMimeType } from 'mrmime';
1010
import { readFile } from 'node:fs/promises';
1111
import { extname } from 'node:path';
1212
import { workerData } from 'node:worker_threads';
13-
import { Response, fetch } from 'undici';
1413

1514
/**
1615
* 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
2524
const RESOLVE_PROTOCOL = 'resolve:';
2625

2726
export function patchFetchToLoadInMemoryAssets(): void {
28-
const global = globalThis as unknown as { fetch: typeof fetch };
29-
const originalFetch = global.fetch;
27+
const originalFetch = globalThis.fetch;
3028
const patchedFetch: typeof fetch = async (input, init) => {
3129
let url: URL;
3230
if (input instanceof URL) {
@@ -72,5 +70,5 @@ export function patchFetchToLoadInMemoryAssets(): void {
7270
});
7371
};
7472

75-
global.fetch = patchedFetch;
73+
globalThis.fetch = patchedFetch;
7674
}

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ ts_library(
198198
"@npm//tree-kill",
199199
"@npm//tslib",
200200
"@npm//typescript",
201-
"@npm//undici",
202201
"@npm//vite",
203202
"@npm//watchpack",
204203
"@npm//webpack",

packages/angular_devkit/build_angular/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"terser": "5.29.2",
6262
"tree-kill": "1.2.2",
6363
"tslib": "2.6.3",
64-
"undici": "6.19.2",
6564
"vite": "5.3.3",
6665
"watchpack": "2.4.1",
6766
"webpack": "5.92.1",
@@ -73,6 +72,9 @@
7372
"optionalDependencies": {
7473
"esbuild": "0.23.0"
7574
},
75+
"devDependencies": {
76+
"undici": "6.19.2"
77+
},
7678
"peerDependencies": {
7779
"@angular/compiler-cli": "^18.0.0 || ^18.1.0-next.0",
7880
"@angular/localize": "^18.0.0 || ^18.1.0-next.0",

yarn.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ __metadata:
418418
rollup: "npm:4.18.0"
419419
sass: "npm:1.77.6"
420420
semver: "npm:7.6.2"
421-
undici: "npm:6.19.2"
422421
vite: "npm:5.3.3"
423422
watchpack: "npm:2.4.1"
424423
peerDependencies:

0 commit comments

Comments
 (0)