Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .chronus/changes/fix-init-never-ending-2024-3-17-20-24-14.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"
---

Fix tsp init hanging when done due to unclosed connection
2 changes: 2 additions & 0 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@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 @@ -98,6 +99,7 @@
},
"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
12 changes: 6 additions & 6 deletions packages/compiler/src/core/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import http from "http";
import https from "https";
import followRedirects from "follow-redirects";
import { compilerAssert } from "./diagnostics.js";

export interface FetchResponse {
Expand All @@ -19,14 +18,15 @@ export function fetch(uri: string): Promise<FetchResponse> {
function request(uri: string, resolve: (arg: FetchResponse) => void, reject: (arg: any) => void) {
const url = new URL(uri);
const protocol =
url.protocol === "https:" ? https : url.protocol === "http:" ? http : undefined;
url.protocol === "https:"
? followRedirects.https
: url.protocol === "http:"
? followRedirects.http
: undefined;
compilerAssert(protocol, `Protocol '${url.protocol}' is not supported`);

protocol
.get(url, (res) => {
if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location) {
return request(res.headers.location, resolve, reject);
}
let data = "";

res.on("data", (chunk) => {
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

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