tstyche 8.0.0-beta.1 → 8.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/runner/Runner.js
CHANGED
|
@@ -12,7 +12,7 @@ import { FileRunner } from "./FileRunner.js";
|
|
|
12
12
|
export class Runner {
|
|
13
13
|
#eventEmitter = new EventEmitter();
|
|
14
14
|
#resolvedConfig;
|
|
15
|
-
static version = "8.0.0-beta.
|
|
15
|
+
static version = "8.0.0-beta.2";
|
|
16
16
|
constructor(resolvedConfig) {
|
|
17
17
|
this.#resolvedConfig = resolvedConfig;
|
|
18
18
|
}
|
package/dist/store/Fetcher.d.ts
CHANGED
|
@@ -12,12 +12,13 @@ export interface PackageMetadata {
|
|
|
12
12
|
name: string;
|
|
13
13
|
versions: Record<string, VersionMetadata>;
|
|
14
14
|
}
|
|
15
|
+
export type ResponseHandler<T> = (response: Response) => Promise<T>;
|
|
15
16
|
export declare class Fetcher {
|
|
16
17
|
#private;
|
|
17
18
|
constructor(onDiagnostics: DiagnosticsHandler, registry: string, retries: number, timeout: number);
|
|
18
|
-
get(request: Request, diagnostic: () => Diagnostic, options?: {
|
|
19
|
+
get<T>(request: Request, onResponse: ResponseHandler<T>, diagnostic: () => Diagnostic, options?: {
|
|
19
20
|
suppressErrors?: boolean | undefined;
|
|
20
|
-
}): Promise<
|
|
21
|
+
}): Promise<T | undefined>;
|
|
21
22
|
getMetadata<T>(packageSpecifier: string, options?: {
|
|
22
23
|
suppressErrors?: boolean | undefined;
|
|
23
24
|
}): Promise<T | undefined>;
|
package/dist/store/Fetcher.js
CHANGED
|
@@ -13,17 +13,18 @@ export class Fetcher {
|
|
|
13
13
|
this.#retries = retries;
|
|
14
14
|
this.#timeout = timeout;
|
|
15
15
|
}
|
|
16
|
-
async get(request, diagnostic, options) {
|
|
16
|
+
async get(request, onResponse, diagnostic, options) {
|
|
17
17
|
let delay = 3000;
|
|
18
|
-
request.headers.set("User-Agent", `tstyche/8.0.0-beta.
|
|
18
|
+
request.headers.set("User-Agent", `tstyche/8.0.0-beta.2 ${process.platform} ${process.arch}`);
|
|
19
19
|
for (let attempt = 0; attempt <= this.#retries; attempt++) {
|
|
20
20
|
const isLastAttempt = attempt === this.#retries;
|
|
21
21
|
const suppressErrors = options?.suppressErrors || !isLastAttempt;
|
|
22
22
|
try {
|
|
23
23
|
const response = await fetch(request, { signal: AbortSignal.timeout(this.#timeout) });
|
|
24
24
|
if (response.ok) {
|
|
25
|
-
return response;
|
|
25
|
+
return await onResponse(response);
|
|
26
26
|
}
|
|
27
|
+
await response.body?.cancel();
|
|
27
28
|
if (response.status >= 400 && response.status < 500 && response.status !== 429) {
|
|
28
29
|
if (options?.suppressErrors) {
|
|
29
30
|
return;
|
|
@@ -53,16 +54,13 @@ export class Fetcher {
|
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
async getMetadata(packageSpecifier, options) {
|
|
56
|
-
const diagnostic = () => Diagnostic.error(StoreDiagnosticText.failedToFetchMetadata(this.#registry));
|
|
57
57
|
const request = new Request(new URL(packageSpecifier, this.#registry), {
|
|
58
58
|
headers: {
|
|
59
59
|
["Accept"]: "application/vnd.npm.install-v1+json;q=1.0, application/json;q=0.8, */*",
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
return (await response.json());
|
|
62
|
+
const onResponse = (response) => response.json();
|
|
63
|
+
const diagnostic = () => Diagnostic.error(StoreDiagnosticText.failedToFetchMetadata(this.#registry));
|
|
64
|
+
return await this.get(request, onResponse, diagnostic, { suppressErrors: options?.suppressErrors });
|
|
67
65
|
}
|
|
68
66
|
}
|
|
@@ -46,14 +46,15 @@ export class PackageService {
|
|
|
46
46
|
return `${pathToFileURL(packagePath)}/`;
|
|
47
47
|
}
|
|
48
48
|
async #fetch(packagePath, packageSpecifier, packageResource) {
|
|
49
|
-
const diagnostic = () => Diagnostic.error(StoreDiagnosticText.failedToFetchPackage(packageSpecifier));
|
|
50
49
|
const request = new Request(packageResource.tarball, { integrity: packageResource.integrity });
|
|
51
|
-
const
|
|
52
|
-
|
|
50
|
+
const diagnostic = () => Diagnostic.error(StoreDiagnosticText.failedToFetchPackage(packageSpecifier));
|
|
51
|
+
const onResponse = (response) => response.arrayBuffer();
|
|
52
|
+
const buffer = await this.#fetcher.get(request, onResponse, diagnostic);
|
|
53
|
+
if (!buffer) {
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
let packageJson;
|
|
56
|
-
const stream =
|
|
57
|
+
const stream = new Blob([buffer]).stream().pipeThrough(new DecompressionStream("gzip"));
|
|
57
58
|
const tarReader = new TarReader(stream);
|
|
58
59
|
for await (const file of tarReader.extract()) {
|
|
59
60
|
const fileName = file.name.replace(/^package\//, "");
|