-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support switching
arch
when downloading nodejs
Signed-off-by: The1111mp <[email protected]>
- Loading branch information
Showing
5 changed files
with
120 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,41 @@ | ||
import { once } from 'node:events'; | ||
import { createWriteStream } from 'node:fs'; | ||
import { once } from "node:events"; | ||
import { createWriteStream } from "node:fs"; | ||
|
||
import fetchNodeWebsite from '../fetch-node-website'; | ||
import { checkChecksum } from './checksum'; | ||
import fetchNodeWebsite from "../fetch-node-website"; | ||
import { checkChecksum } from "./checksum"; | ||
|
||
import type { Request } from 'got'; | ||
import type { Options as FetchNodeOptions } from '../fetch-node-website'; | ||
import type { Request } from "got"; | ||
import type { Options as FetchNodeOptions } from "../fetch-node-website"; | ||
|
||
// Make HTTP request to retrieve a Node.js binary. | ||
// Also make another HTTP request to calculate the checksum. | ||
export const fetchNodeUrl = async ( | ||
version: string, | ||
filepath: string, | ||
fetchOpts: FetchNodeOptions, | ||
fetchOpts: FetchNodeOptions | ||
) => { | ||
const response = await fetchNodeWebsite(`v${version}/${filepath}`, fetchOpts); | ||
const checksumError = checkChecksum({ | ||
version, | ||
filepath, | ||
response, | ||
fetchOpts, | ||
fetchOpts | ||
}); | ||
return { response, checksumError }; | ||
}; | ||
|
||
// `response` `error` events do not necessarily make piped streams error, so we | ||
// need to await either. | ||
export const promiseOrFetchError = async ( | ||
promise: Promise<void>, | ||
response: Request, | ||
) => { | ||
export const promiseOrFetchError = async (promise: Promise<void>, response: Request) => { | ||
await Promise.race([promise, throwOnFetchError(response)]); | ||
}; | ||
|
||
const throwOnFetchError = async (response: Request) => { | ||
const [error] = await once(response, 'error'); | ||
const [error] = await once(response, "error"); | ||
throw error; | ||
}; | ||
|
||
// Persist stream to a `node[.exe]` file | ||
export const writeNodeBinary = (tmpFile: string) => | ||
createWriteStream(tmpFile, { mode: NODE_MODE }); | ||
export const writeNodeBinary = (tmpFile: string) => createWriteStream(tmpFile, { mode: NODE_MODE }); | ||
|
||
const NODE_MODE = 0o755; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters