diff --git a/src/index.ts b/src/index.ts index 58f0fbf57..a0ec3bfdf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,11 @@ import debug from 'debug'; import * as path from 'path'; import { getArtifactFileName, getArtifactRemoteURL, FileNameUse } from './artifact-utils'; -import { ElectronArtifactDetails, ElectronDownloadRequestOptions } from './types'; +import { + ElectronArtifactDetails, + ElectronDownloadRequestOptions, + ElectronPlatformArtifactDetailsWithDefaults, +} from './types'; import { Cache } from './Cache'; import { getDownloaderForSystem } from './downloader-resolver'; import { @@ -44,10 +48,18 @@ export function download( * * @param artifactDetails - The information required to download the artifact */ -export async function downloadArtifact(_artifactDetails: ElectronArtifactDetails): Promise { - const artifactDetails: ElectronArtifactDetails = { - ..._artifactDetails, - }; +export async function downloadArtifact( + _artifactDetails: ElectronPlatformArtifactDetailsWithDefaults, +): Promise { + const artifactDetails: ElectronArtifactDetails = _artifactDetails.isGeneric + ? { + ..._artifactDetails, + } + : { + platform: process.platform, + arch: getHostArch(), + ..._artifactDetails, + }; ensureIsTruthyString(artifactDetails, 'version'); artifactDetails.version = normalizeVersion(artifactDetails.version); diff --git a/src/types.ts b/src/types.ts index 81d4fd569..1b6a9998b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -91,4 +91,13 @@ export type ElectronArtifactDetails = | ElectronPlatformArtifactDetails | ElectronGenericArtifactDetails; +export type Omit = Pick>; + +export type ElectronPlatformArtifactDetailsWithDefaults = + | (Omit & { + platform?: string; + arch?: string; + }) + | ElectronGenericArtifactDetails; + export type DownloadOptions = any; diff --git a/test/index.spec.ts b/test/index.spec.ts index 6802aa329..b141ce8da 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -120,6 +120,13 @@ describe('Public API', () => { expect(await fs.readFile(dtsPath, 'utf8')).toContain('declare namespace Electron'); }); + it('should work default platform/arch', async () => { + await downloadArtifact({ + version: '2.0.3', + artifactName: 'electron', + }); + }); + it('should work for chromedriver', async () => { const driverPath = await downloadArtifact({ cacheRoot,