File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,17 +10,22 @@ import {
1010 getBinaryPathInArchive ,
1111 getDownloadUrl ,
1212 resolveNodeVersion ,
13+ type ExeExtensionOptions ,
1314 type ExeTarget ,
1415} from './platform.ts'
1516
1617const debug = createDebug ( 'tsdown:exe:download' )
1718
1819export async function resolveNodeBinary (
1920 target : ExeTarget ,
21+ options : ExeExtensionOptions ,
2022 logger ?: Logger ,
2123) : Promise < string > {
2224 debug ( 'Resolving Node.js binary for target: %O' , target )
23- target . nodeVersion = await resolveNodeVersion ( target . nodeVersion )
25+ target . nodeVersion = await resolveNodeVersion (
26+ target . nodeVersion ,
27+ options . nodeDistIndexUrl ,
28+ )
2429
2530 const cachedPath = getCachedBinaryPath ( target )
2631 debug ( 'Cache path: %s' , cachedPath )
@@ -33,7 +38,7 @@ export async function resolveNodeBinary(
3338 return cachedPath
3439 }
3540
36- const url = getDownloadUrl ( target )
41+ const url = await ( options . getDownloadUrl ?? getDownloadUrl ) ( target )
3742 debug ( 'Cache miss, downloading from: %s' , url )
3843 logger ?. info (
3944 `Downloading Node.js ${ target . nodeVersion } for ${ target . platform } -${ target . arch } ...` ,
Original file line number Diff line number Diff line change @@ -39,6 +39,13 @@ export interface ExeExtensionOptions {
3939 * ```
4040 */
4141 targets ?: ExeTarget [ ]
42+
43+ getDownloadUrl ?: ( target : ExeTarget ) => string | Promise < string >
44+
45+ /**
46+ * @default 'https://nodejs.org/dist/index.json'
47+ */
48+ nodeDistIndexUrl ?: string
4249}
4350
4451export function getArchiveExtension ( platform : ExePlatform ) : string {
@@ -67,14 +74,15 @@ interface NodeRelease {
6774 lts : string | false
6875}
6976
70- const NODE_DIST_INDEX_URL = 'https://nodejs.org/dist/index.json'
71-
72- export async function resolveNodeVersion ( nodeVersion : string ) : Promise < string > {
77+ export async function resolveNodeVersion (
78+ nodeVersion : string ,
79+ nodeDistIndexUrl = 'https://nodejs.org/dist/index.json' ,
80+ ) : Promise < string > {
7381 if ( nodeVersion === 'latest' || nodeVersion === 'latest-lts' ) {
74- const response = await fetch ( NODE_DIST_INDEX_URL )
82+ const response = await fetch ( nodeDistIndexUrl )
7583 if ( ! response . ok ) {
7684 throw new Error (
77- `Failed to fetch Node.js releases: HTTP ${ response . status } from ${ NODE_DIST_INDEX_URL } ` ,
85+ `Failed to fetch Node.js releases: HTTP ${ response . status } from ${ nodeDistIndexUrl } ` ,
7886 )
7987 }
8088
Original file line number Diff line number Diff line change @@ -137,7 +137,11 @@ export async function buildExe(
137137 await importWithError < typeof import ( '@tsdown/exe' ) > ( '@tsdown/exe' )
138138
139139 for ( const target of targets ) {
140- const nodeBinaryPath = await resolveNodeBinary ( target , config . logger )
140+ const nodeBinaryPath = await resolveNodeBinary (
141+ target ,
142+ config . exe ,
143+ config . logger ,
144+ )
141145 const suffix = getTargetSuffix ( target )
142146 const outputFile = resolveOutputFileName (
143147 config . exe ,
You can’t perform that action at this time.
0 commit comments