diff --git a/README.md b/README.md index 665eb35cd..cf3b2af6a 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,18 @@ const zipFilePath = await download('4.0.4', { // Will download from https://mirror.example.com/electron/version-4.0.4/electron-v4.0.4-linux-x64.zip ``` +#### Using environment variables for mirror options +Mirror options can also be specified via the following environment variables: +* `ELECTRON_CUSTOM_DIR` - Specifies the custom directory to download from. +* `ELECTRON_CUSTOM_FILENAME` - Specifies the custom file name to download. +* `ELECTRON_MIRROR` - Specifies the URL of the server to download from if the version is not a nightly version. +* `ELECTRON_NIGHTLY_MIRROR` - Specifies the URL of the server to download from if the version is a nightly version. + +### Overriding the version downloaded + +The version downloaded can be overriden by setting the `ELECTRON_CUSTOM_VERSION` environment variable. +Setting this environment variable will override the version passed in to `download` or `downloadArtifact`. + ## How It Works This module downloads Electron to a known place on your system and caches it diff --git a/src/index.ts b/src/index.ts index b12808540..1eeb9743a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -76,8 +76,10 @@ export async function downloadArtifact( } } ensureIsTruthyString(artifactDetails, 'version'); - artifactDetails.version = normalizeVersion(artifactDetails.version); + artifactDetails.version = normalizeVersion( + process.env.ELECTRON_CUSTOM_VERSION || artifactDetails.version, + ); const fileName = getArtifactFileName(artifactDetails); const url = getArtifactRemoteURL(artifactDetails); const cache = new Cache(artifactDetails.cacheRoot); @@ -134,7 +136,6 @@ export async function downloadArtifact( downloader: artifactDetails.downloader, mirrorOptions: artifactDetails.mirrorOptions, }); - await sumchecker('sha256', shasumPath, path.dirname(tempDownloadPath), [ path.basename(tempDownloadPath), ]); diff --git a/test/index.spec.ts b/test/index.spec.ts index fc8562c7b..9413cc18b 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -112,6 +112,19 @@ describe('Public API', () => { downloadOptions: downloadOpts, }); }); + + it('should download a custom version of a zip file', async () => { + process.env.ELECTRON_CUSTOM_VERSION = '2.0.10'; + const zipPath = await download('2.0.3', { + cacheRoot, + downloader, + }); + expect(typeof zipPath).toEqual('string'); + expect(await fs.pathExists(zipPath)).toEqual(true); + expect(path.basename(zipPath)).toMatch(/v2.0.10/); + expect(path.extname(zipPath)).toEqual('.zip'); + process.env.ELECTRON_CUSTOM_VERSION = ''; + }); }); describe('downloadArtifact()', () => { @@ -179,5 +192,22 @@ describe('Public API', () => { ); expect(path.extname(driverPath)).toEqual('.zip'); }); + + it('should download a custom version of a zip file', async () => { + process.env.ELECTRON_CUSTOM_VERSION = '2.0.10'; + const zipPath = await downloadArtifact({ + artifactName: 'electron', + cacheRoot, + downloader, + platform: 'darwin', + arch: 'x64', + version: '2.0.3', + }); + expect(typeof zipPath).toEqual('string'); + expect(await fs.pathExists(zipPath)).toEqual(true); + expect(path.basename(zipPath)).toMatchInlineSnapshot(`"electron-v2.0.10-darwin-x64.zip"`); + expect(path.extname(zipPath)).toEqual('.zip'); + process.env.ELECTRON_CUSTOM_VERSION = ''; + }); }); });