Utility for downloading artifacts from different versions of Electron
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Helper functions for architecture detection and proxy initialization to support cross-platform downloads and enterprise environments.
Get the current system architecture in the format used by Electron and Node.js downloads.
/**
* Generates an architecture name that would be used in an Electron or Node.js
* download file name from the `process` module information.
*/
function getHostArch(): string;Usage Examples:
import { getHostArch } from "@electron/get";
const arch = getHostArch();
console.log(`Current architecture: ${arch}`);
// Possible outputs: 'x64', 'ia32', 'arm64', 'armv7l'
// Use in download calls
import { downloadArtifact } from "@electron/get";
await downloadArtifact({
version: '31.0.0',
artifactName: 'electron',
platform: 'linux',
arch: getHostArch() // Use detected architecture
});Architecture Mapping:
The function handles architecture normalization:
'arm' becomes 'armv7l' (default) or output of uname -m (for ARM v6)'x64', 'ia32', 'arm64') pass through unchangedInitialize HTTP(S) proxy support for downloads using the global-agent module.
/**
* 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.
*/
function initializeProxy(): void;Usage Examples:
import { initializeProxy, download } from "@electron/get";
// Manual proxy initialization
initializeProxy();
// Then proceed with downloads
const electronPath = await download('31.0.0');Environment Variables:
The proxy initialization looks for these environment variables:
GLOBAL_AGENT_HTTP_PROXY - HTTP proxy URLGLOBAL_AGENT_HTTPS_PROXY - HTTPS proxy URLGLOBAL_AGENT_NO_PROXY - Comma-separated list of hosts to bypass proxyConfiguration Examples:
# Set proxy environment variables
export GLOBAL_AGENT_HTTPS_PROXY="http://proxy.company.com:8080"
export GLOBAL_AGENT_NO_PROXY="localhost,127.0.0.1,.company.com"
# Enable automatic proxy initialization
export ELECTRON_GET_USE_PROXY=true// Proxy will be automatically initialized due to ELECTRON_GET_USE_PROXY
import { download } from "@electron/get";
const electronPath = await download('31.0.0');Functions for creating and managing temporary directories during downloads.
/**
* Creates a temporary directory with a unique name.
*/
function mkdtemp(parentDirectory?: string): Promise<string>;
/**
* Executes a function with a temporary directory and optionally cleans it up.
*/
function withTempDirectory<T>(
fn: (directory: string) => Promise<T>,
cleanUp: TempDirCleanUpMode
): Promise<T>;
/**
* Executes a function with a temporary directory in a specific parent directory.
*/
function withTempDirectoryIn<T>(
parentDirectory: string,
fn: (directory: string) => Promise<T>,
cleanUp: TempDirCleanUpMode
): Promise<T>;
/**
* Controls temporary directory cleanup behavior.
*/
enum TempDirCleanUpMode {
CLEAN, // Clean up the directory after use
ORPHAN, // Leave the directory (caller owns it)
}Usage Examples:
import { mkdtemp, withTempDirectory, TempDirCleanUpMode } from "@electron/get";
// Create a temporary directory
const tempDir = await mkdtemp('/custom/temp/path');
console.log(`Temporary directory: ${tempDir}`);
// Use temporary directory with automatic cleanup
const result = await withTempDirectory(async (tempDir) => {
// Do work in tempDir
return someProcessing(tempDir);
}, TempDirCleanUpMode.CLEAN);
// Use temporary directory without cleanup (caller owns it)
const tempPath = await withTempDirectory(async (tempDir) => {
const outputFile = path.join(tempDir, 'output.zip');
// Create file in tempDir
return outputFile;
}, TempDirCleanUpMode.ORPHAN);Additional utility functions for version normalization and architecture handling.
/**
* Normalize version strings by adding 'v' prefix if needed.
*/
function normalizeVersion(version: string): string;
/**
* Generate architecture name for Electron/Node.js downloads.
*/
function getNodeArch(arch: string): string;
/**
* Run the uname command and return trimmed output.
*/
function uname(): string;
/**
* Validate that a property is a truthy string.
*/
function ensureIsTruthyString<T, K extends keyof T>(obj: T, key: K): void;Usage Examples:
import { normalizeVersion, getNodeArch, uname } from "@electron/get";
// Normalize version strings
const version1 = normalizeVersion('4.0.4'); // Returns 'v4.0.4'
const version2 = normalizeVersion('v4.0.4'); // Returns 'v4.0.4'
// Get Node-style architecture
const nodeArch = getNodeArch('x64'); // Returns 'x64'
const armArch = getNodeArch('arm'); // Returns 'armv7l'
// Get system information
const systemInfo = uname(); // Returns output of uname -m
console.log(`System: ${systemInfo}`);Utilities for working with environment variables with optional prefixes.
/**
* Get environment variables with optional prefix.
*/
function getEnv(prefix?: string): (name: string) => string | undefined;
/**
* Set environment variables.
*/
function setEnv(key: string, value: string | undefined): void;Usage Examples:
import { getEnv, setEnv } from "@electron/get";
// Create environment variable getter with prefix
const getElectronEnv = getEnv('ELECTRON_');
const customDir = getElectronEnv('CUSTOM_DIR'); // Gets ELECTRON_CUSTOM_DIR
// Set environment variable
setEnv('ELECTRON_MIRROR', 'https://custom-mirror.com/');Utility functions for determining cache behavior.
/**
* Determine effective cache mode from artifact details.
*/
function effectiveCacheMode(
artifactDetails: ElectronPlatformArtifactDetailsWithDefaults | ElectronGenericArtifactDetails
): ElectronDownloadCacheMode;
/**
* Check if cache should be read based on cache mode.
*/
function shouldTryReadCache(cacheMode: ElectronDownloadCacheMode): boolean;
/**
* Check if cache should be written based on cache mode.
*/
function shouldWriteCache(cacheMode: ElectronDownloadCacheMode): boolean;
/**
* Check if caller owns temporary output based on cache mode.
*/
function doesCallerOwnTemporaryOutput(cacheMode: ElectronDownloadCacheMode): boolean;Install with Tessl CLI
npx tessl i tessl/npm-electron--get