Skip to content

Commit 0a83800

Browse files
Use node built-in fetch (#3246)
Node `fetch` built-in function is now out of experimental since node `18.13.0` this allows us to not have some partial implementation and get rid of an external dependency
1 parent 40b1ff2 commit 0a83800

File tree

5 files changed

+9
-63
lines changed

5 files changed

+9
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: fix
4+
packages:
5+
- "@typespec/compiler"
6+
---
7+
8+
Internals: Use node built-in `fetch` API that is now stable since node `18.13.0`

packages/compiler/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
"@babel/code-frame": "~7.24.2",
8686
"ajv": "~8.12.0",
8787
"change-case": "~5.4.4",
88-
"follow-redirects": "^1.15.6",
8988
"globby": "~14.0.1",
9089
"mustache": "~4.2.0",
9190
"picocolors": "~1.0.0",
@@ -99,7 +98,6 @@
9998
},
10099
"devDependencies": {
101100
"@types/babel__code-frame": "~7.0.6",
102-
"@types/follow-redirects": "^1.14.4",
103101
"@types/mustache": "~4.2.5",
104102
"@types/node": "~18.11.19",
105103
"@types/prompts": "~2.4.9",

packages/compiler/src/core/fetch.ts

-47
This file was deleted.

packages/compiler/src/core/node-host.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { realpath } from "fs";
22
import { mkdir, readdir, readFile, rm, stat, writeFile } from "fs/promises";
33
import { fileURLToPath, pathToFileURL } from "url";
44
import { findProjectRoot } from "../utils/misc.js";
5-
import { fetch } from "./fetch.js";
65
import { createConsoleSink } from "./logger/index.js";
76
import { joinPaths } from "./path-utils.js";
87
import { createSourceFile, getSourceFileKindFromExt } from "./source-file.js";
@@ -16,7 +15,7 @@ export const CompilerPackageRoot = (await findProjectRoot(stat, fileURLToPath(im
1615
*/
1716
export const NodeHost: CompilerHost = {
1817
readUrl: async (url: string) => {
19-
const response = await fetch(url);
18+
const response = await fetch(url, { redirect: "follow" });
2019
const text = await response.text();
2120
return createSourceFile(text, response.url);
2221
},

pnpm-lock.yaml

-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)