Skip to content

Commit

Permalink
Use node built-in fetch (#3246)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
timotheeguerin authored Apr 26, 2024
1 parent 40b1ff2 commit 0a83800
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 63 deletions.
8 changes: 8 additions & 0 deletions .chronus/changes/use-node-fetch-builtin-2024-3-26-17-50-57.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---

Internals: Use node built-in `fetch` API that is now stable since node `18.13.0`
2 changes: 0 additions & 2 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"@babel/code-frame": "~7.24.2",
"ajv": "~8.12.0",
"change-case": "~5.4.4",
"follow-redirects": "^1.15.6",
"globby": "~14.0.1",
"mustache": "~4.2.0",
"picocolors": "~1.0.0",
Expand All @@ -99,7 +98,6 @@
},
"devDependencies": {
"@types/babel__code-frame": "~7.0.6",
"@types/follow-redirects": "^1.14.4",
"@types/mustache": "~4.2.5",
"@types/node": "~18.11.19",
"@types/prompts": "~2.4.9",
Expand Down
47 changes: 0 additions & 47 deletions packages/compiler/src/core/fetch.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/compiler/src/core/node-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { realpath } from "fs";
import { mkdir, readdir, readFile, rm, stat, writeFile } from "fs/promises";
import { fileURLToPath, pathToFileURL } from "url";
import { findProjectRoot } from "../utils/misc.js";
import { fetch } from "./fetch.js";
import { createConsoleSink } from "./logger/index.js";
import { joinPaths } from "./path-utils.js";
import { createSourceFile, getSourceFileKindFromExt } from "./source-file.js";
Expand All @@ -16,7 +15,7 @@ export const CompilerPackageRoot = (await findProjectRoot(stat, fileURLToPath(im
*/
export const NodeHost: CompilerHost = {
readUrl: async (url: string) => {
const response = await fetch(url);
const response = await fetch(url, { redirect: "follow" });
const text = await response.text();
return createSourceFile(text, response.url);
},
Expand Down
12 changes: 0 additions & 12 deletions pnpm-lock.yaml

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

0 comments on commit 0a83800

Please sign in to comment.