@electron/get

  • Version 5.0.0
  • Published
  • 68.7 kB
  • 6 dependencies
  • MIT license

Install

npm i @electron/get
yarn add @electron/get
pnpm add @electron/get

Overview

Utility for downloading artifacts from different versions of Electron

Index

Functions

function download

download: (
version: string,
options?: ElectronDownloadRequestOptions
) => Promise<string>;
  • Downloads the Electron binary for a specific version and returns an absolute path to a ZIP file.

    Parameter version

    The version of Electron you want to download (e.g. 31.0.0)

    Parameter options

    Options to customize the download behavior

    Returns

    An absolute path to the downloaded ZIP file Download Electron

function downloadArtifact

downloadArtifact: (
artifactDetails:
| ElectronPlatformArtifactDetailsWithDefaults
| ElectronGenericArtifactDetails
) => Promise<string>;
  • Downloads an artifact from an Electron release and returns an absolute path to the downloaded file.

    Each release of Electron comes with artifacts, many of which are platform/arch-specific (e.g. ffmpeg-v31.0.0-darwin-arm64.zip) and others that are generic (e.g. SHASUMS256.txt).

    Parameter artifactDetails

    The information required to download the artifact Download Artifact

function getHostArch

getHostArch: () => string;
  • Generates an architecture name that would be used in an Electron or Node.js download file name from the process module information.

    Utility

function initializeProxy

initializeProxy: () => void;
  • Initializes a third-party proxy module for HTTP(S) requests. Call this function before using the download and downloadArtifact APIs if you need proxy support.

    If the ELECTRON_GET_USE_PROXY environment variable is set to true, this function will be called automatically for @electron/get requests.

    Supported environment variables are HTTP_PROXY, HTTPS_PROXY, and NO_PROXY.

    Utility

    See Also

Classes

class FetchDownloader

class FetchDownloader implements Downloader<FetchDownloaderOptions> {}

method download

download: (
url: string,
targetFilePath: string,
options?: FetchDownloaderOptions
) => Promise<void>;

    class HTTPError

    class HTTPError extends Error {}
    • Downloader

    constructor

    constructor(response: Response);

      property response

      readonly response: Response;

        Interfaces

        interface Downloader

        interface Downloader<T> {}

        method download

        download: (url: string, targetFilePath: string, options: T) => Promise<void>;
        • Download an artifact from an arbitrary URL to a file path on system

          Parameter url

          URL of the file to download

          Parameter targetFilePath

          Filesystem path to download the artifact to (including the file name)

          Parameter options

          Options to pass to the downloader

        interface ElectronDownloadRequestOptions

        interface ElectronDownloadRequestOptions {}
        • Download Electron

        property cacheMode

        cacheMode?: ElectronDownloadCacheMode;
        • Controls the cache read and write behavior.

          When set to either ReadOnly or Bypass, the caller is responsible for cleaning up the returned file path once they are done using it (e.g. via fs.remove(path.dirname(pathFromElectronGet))).

          When set to either WriteOnly or ReadWrite (the default), the caller should not move or delete the file path that is returned as the path points directly to the disk cache.

        property cacheRoot

        cacheRoot?: string;
        • The directory that caches Electron artifact downloads.

        property checksums

        checksums?: Record<string, string>;
        • Provides checksums for the artifact as strings. Can be used if you already know the checksums of the Electron artifact you are downloading and want to skip the checksum file download without skipping the checksum validation.

          This should be an object whose keys are the file names of the artifacts and the values are their respective SHA256 checksums.

          Example 1

          {
          "electron-v4.0.4-linux-x64.zip": "877617029f4c0f2b24f3805a1c3554ba166fda65c4e88df9480ae7b6ffa26a22"
          }

        property downloader

        downloader?: Downloader<DownloadOptions>;

        property downloadOptions

        downloadOptions?: DownloadOptions;

        property mirrorOptions

        mirrorOptions?: MirrorOptions;
        • Options related to specifying an artifact mirror.

        property tempDirectory

        tempDirectory?: string;
        • A temporary directory for downloads. It is used before artifacts are put into cache.

        property unsafelyDisableChecksums

        unsafelyDisableChecksums?: boolean;
        • When set to true, disables checking that the artifact download completed successfully with the correct payload.

        interface MirrorOptions

        interface MirrorOptions {}
        • Options for specifying an alternative download mirror for Electron.

          Utility

          Example 1

          To download the Electron v4.0.4 release for x64 Linux from https://github.com/electron/electron/releases/download/v4.0.4/electron-v4.0.4-linux-x64.zip

          const opts = {
          mirror: 'https://github.com/electron/electron/releases/download',
          customDir: 'v4.0.4',
          customFilename: 'electron-v4.0.4-linux-x64.zip',
          }

        property customDir

        customDir?: string;
        • The name of the directory to download from, often scoped by version number e.g 'v4.0.4'

        property customFilename

        customFilename?: string;
        • The name of the asset to download, e.g 'electron-v4.0.4-linux-x64.zip'

        property customVersion

        customVersion?: string;
        • The version of the asset to download, e.g '4.0.4'

        property mirror

        mirror?: string;
        • The base URL of the mirror to download from. e.g https://github.com/electron/electron/releases/download

        property nightlyMirror

        nightlyMirror?: string;
        • The mirror URL for [electron-nightly](https://npmjs.com/package/electron-nightly), which lives in a separate npm package.

        property resolveAssetURL

        resolveAssetURL?: (opts: DownloadOptions) => Promise<string>;
        • A function allowing customization of the url returned from getArtifactRemoteURL().

        interface Progress

        interface Progress {}
        • Downloader

        property percent

        percent: number;
        • Ratio of transferred to total between 0 and 1. If total is unknown, this is 0 until the download completes, then 1.

        property total

        total: number | null;
        • Total bytes to download, or null if the response had no Content-Length header.

        property transferred

        transferred: number;
        • Bytes downloaded so far.

        Enums

        enum ElectronDownloadCacheMode

        enum ElectronDownloadCacheMode {
        ReadWrite = 0,
        ReadOnly = 1,
        WriteOnly = 2,
        Bypass = 3,
        }

          member Bypass

          Bypass = 3
          • Bypasses the cache completely, neither reads from nor writes to the cache

          member ReadOnly

          ReadOnly = 1
          • Reads from the cache if present Will **not** write back to the cache after fetching missing artifact

          member ReadWrite

          ReadWrite = 0
          • Reads from the cache if present Writes to the cache after fetch if not present

          member WriteOnly

          WriteOnly = 2
          • Skips reading from the cache Will write back into the cache, overwriting anything currently in the cache after fetch

          Type Aliases

          type DownloadOptions

          type DownloadOptions = any;
          • Custom downloaders can implement any set of options. Downloader

          type ElectronGenericArtifactDetails

          type ElectronGenericArtifactDetails = {
          isGeneric: true;
          } & ElectronDownloadRequest &
          ElectronDownloadRequestOptions;
          • Options to download a generic (i.e. platform and architecture-agnostic) Electron artifact. Contains all options from ElectronDownloadRequestOptions, but specifies a version and artifactName for the artifact to download.

            Download Artifact

          type ElectronPlatformArtifactDetailsWithDefaults

          type ElectronPlatformArtifactDetailsWithDefaults = Omit<
          ElectronPlatformArtifactDetails,
          'platform' | 'arch'
          > & {
          /**
          * The target artifact platform. These are Node-style platform names, for example:
          * * `win32`
          * * `darwin`
          * * `linux`
          *
          * @see Node.js {@link https://nodejs.org/api/process.html#processplatform | process.platform} docs
          */
          platform?: string;
          /**
          * The target artifact architecture. These are Node-style architecture names, for example:
          * * `ia32`
          * * `x64`
          * * `armv7l`
          *
          * @see Node.js {@link https://nodejs.org/api/process.html#processarch | process.arch} docs
          */
          arch?: string;
          };
          • Options to download a platform and architecture-specific Electron artifact. Contains all options from ElectronDownloadRequestOptions, but specifies a version and artifactName for the artifact to download.

            If platform and arch are omitted, they will be inferred using the host system platform and architecture.

            Download Artifact

          type FetchDownloaderOptions

          type FetchDownloaderOptions = RequestInit & {
          /** Called on each chunk with the current download {@link Progress}. */
          getProgressCallback?: (progress: Progress) => Promise<void>;
          /**
          * Disables the console progress bar. Setting the `ELECTRON_GET_NO_PROGRESS`
          * environment variable to a non-empty value also does this.
          */
          quiet?: boolean;
          };

          Package Files (6)

          Dependencies (6)

          Dev Dependencies (16)

          Peer Dependencies (0)

          No peer dependencies.

          Badge

          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@electron/get.

          • Markdown
            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@electron/get)
          • HTML
            <a href="https://www.jsdocs.io/package/@electron/get"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>