From a6637fbce979db09593ecd61670e2eb17ecced54 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 24 May 2019 13:40:53 -0700 Subject: [PATCH] chore: update the npm package to use @electron/get (#18413) * chore: update the npm package to use @electron/get * chore: update node requirement for got --- npm/install.js | 38 ++++++++++++++++++-------------------- npm/package.json | 25 +++++++------------------ 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/npm/install.js b/npm/install.js index 05bdab0bdab0..61792cdab2dd 100755 --- a/npm/install.js +++ b/npm/install.js @@ -1,14 +1,14 @@ #!/usr/bin/env node -var version = require('./package').version +const version = require('./package').version -var fs = require('fs') -var os = require('os') -var path = require('path') -var extract = require('extract-zip') -var download = require('electron-download') +const fs = require('fs') +const os = require('os') +const path = require('path') +const extract = require('extract-zip') +const { downloadArtifact } = require('@electron/get') -var installedVersion = null +let installedVersion = null try { installedVersion = fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '') } catch (ignored) { @@ -19,28 +19,26 @@ if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) { process.exit(0) } -var platformPath = getPlatformPath() +const platformPath = getPlatformPath() -var electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath) +const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath) if (installedVersion === version && fs.existsSync(electronPath)) { process.exit(0) } // downloads if not cached -download({ - cache: process.env.electron_config_cache, - version: version, - platform: process.env.npm_config_platform, - arch: process.env.npm_config_arch, - strictSSL: process.env.npm_config_strict_ssl === 'true', +downloadArtifact({ + version, + artifactName: 'electron', force: process.env.force_no_cache === 'true', - quiet: process.env.npm_config_loglevel === 'silent' || process.env.CI -}, extractFile) + cacheRoot: process.env.electron_config_cache, + platform: process.env.npm_config_platform || process.platform, + arch: process.env.npm_config_arch || process.arch +}).then((zipPath) => extractFile(zipPath)).catch((err) => onerror(err)) // unzips and makes path.txt point at the correct executable -function extractFile (err, zipPath) { - if (err) return onerror(err) +function extractFile (zipPath) { extract(zipPath, { dir: path.join(__dirname, 'dist') }, function (err) { if (err) return onerror(err) fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, function (err) { @@ -54,7 +52,7 @@ function onerror (err) { } function getPlatformPath () { - var platform = process.env.npm_config_platform || os.platform() + const platform = process.env.npm_config_platform || os.platform() switch (platform) { case 'darwin': diff --git a/npm/package.json b/npm/package.json index 3f08f475041b..43bb4a698256 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,29 +1,18 @@ { - "scripts": { - "cache-clean": "rm -rf ~/.electron && rm -rf dist", - "postinstall": "node install.js", - "pretest": "npm run cache-clean", - "test": "standard" - }, + "main": "index.js", + "types": "electron.d.ts", "bin": { "electron": "cli.js" }, - "main": "index.js", - "types": "electron.d.ts", + "scripts": { + "postinstall": "node install.js" + }, "dependencies": { + "@electron/get": "^1.0.1", "@types/node": "^10.12.18", - "electron-download": "^4.1.0", "extract-zip": "^1.0.3" }, - "devDependencies": { - "home-path": "^0.1.1", - "path-exists": "^2.0.0", - "standard": "^5.4.1" - }, - "directories": { - "test": "test" - }, "engines": { - "node": ">= 4.0" + "node": ">= 8.6" } }