Download Electron release artifacts
Перейти к файлу
Mark Lee bc0b3ee1a2 Use a URL that exists for the write error test 2020-03-05 15:26:43 -08:00
.circleci build(deps-dev): upgrade semantic-release to ^17.0.4 2020-03-05 15:13:30 -08:00
.vscode feat: @electron/download 2019-03-15 12:45:00 -07:00
src chore: require Node 10.13 2020-03-05 15:13:29 -08:00
test Use a URL that exists for the write error test 2020-03-05 15:26:43 -08:00
.gitignore chore: add typedoc support 2019-06-13 08:56:02 -07:00
.prettierrc.json feat: @electron/download 2019-03-15 12:45:00 -07:00
.releaserc.json build: add circleci 2019-05-22 16:55:59 -07:00
README.md chore: require Node 10.13 2020-03-05 15:13:29 -08:00
jest.config.js feat: @electron/download 2019-03-15 12:45:00 -07:00
package.json build(deps-dev): upgrade jest and related to ^25 2020-03-05 15:13:30 -08:00
tsconfig.esm.json feat: @electron/download 2019-03-15 12:45:00 -07:00
tsconfig.json chore: require Node 10.13 2020-03-05 15:13:29 -08:00
yarn.lock build(deps-dev): upgrade jest and related to ^25 2020-03-05 15:13:30 -08:00

README.md

@electron/get

Download Electron release artifacts

CircleCI

Usage

Simple: Downloading an Electron Binary ZIP

import { download } from '@electron/get';

// NB: Use this syntax within an async function, Node does not have support for
//     top-level await as of Node 12.
const zipFilePath = await download('4.0.4');

Advanced: Downloading a macOS Electron Symbol File

import { downloadArtifact } from '@electron/get';

// NB: Use this syntax within an async function, Node does not have support for
//     top-level await as of Node 12.
const zipFilePath = await downloadArtifact({
  version: '4.0.4',
  platform: 'darwin',
  artifactName: 'electron',
  artifactSuffix: 'symbols',
  arch: 'x64',
});

Specifying a mirror

Anatomy of a download URL, in terms of mirrorOptions:

https://github.com/electron/electron/releases/download/v4.0.4/electron-v4.0.4-linux-x64.zip
|                                                     |       |                           |
-------------------------------------------------------       -----------------------------
                        |                                                   |
              mirror / nightly_mirror                  |    |         customFilename
                                                       ------
                                                         ||
                                                      customDir

Example:

import { download } from '@electron/get';

const zipFilePath = await download('4.0.4', {
  mirrorOptions: {
    mirror: 'https://mirror.example.com/electron/',
    customDir: 'custom',
    customFilename: 'unofficial-electron-linux.zip'
  }
});
// Will download from https://mirror.example.com/electron/custom/unofficial-electron-linux.zip

const nightlyZipFilePath = await download('8.0.0-nightly.20190901', {
  mirrorOptions: {
    nightly_mirror: 'https://nightly.example.com/',
    customDir: 'nightlies',
    customFilename: 'nightly-linux.zip'
  }
});
// Will download from https://nightly.example.com/nightlies/nightly-linux.zip

customDir can have the placeholder {{ version }}, which will be replaced by the version specified (without the leading v). For example:

const zipFilePath = await download('4.0.4', {
  mirrorOptions: {
    mirror: 'https://mirror.example.com/electron/',
    customDir: 'version-{{ version }}',
    platform: 'linux',
    arch: 'x64'
  }
});
// Will download from https://mirror.example.com/electron/version-4.0.4/electron-v4.0.4-linux-x64.zip

How It Works

This module downloads Electron to a known place on your system and caches it so that future requests for that asset can be returned instantly. The cache locations are:

  • Linux: $XDG_CACHE_HOME or ~/.cache/electron/
  • MacOS: ~/Library/Caches/electron/
  • Windows: %LOCALAPPDATA%/electron/Cache or ~/AppData/Local/electron/Cache/

By default, the module uses got as the downloader. As a result, you can use the same options via downloadOptions.

Progress Bar

By default, a progress bar is shown when downloading an artifact for more than 30 seconds. To disable, set the ELECTRON_GET_NO_PROGRESS environment variable to any non-empty value, or set quiet to true in downloadOptions. If you need to monitor progress yourself via the API, set getProgressCallback in downloadOptions, which has the same function signature as got's downloadProgress event callback.

Proxies

Downstream packages should utilize the initializeProxy function to add HTTP(S) proxy support. If the environment variable ELECTRON_GET_USE_PROXY is set, it is called automatically. Refer to the documentation for the global-agent module to determine how to configure proxy support. To troubleshoot proxy support, try setting the DEBUG environment variable to @electron/get:proxy and analyze the debug output.