Socket
Socket
Sign inDemoInstall

electron-installer-common

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-installer-common - npm Package Compare versions

Comparing version 0.6.3 to 0.7.0

18

NEWS.md

@@ -5,4 +5,20 @@ # `electron-installer-common` - Changes by Version

[Unreleased]: https://github.com/electron-userland/electron-installer-common/compare/v0.6.3...master
[Unreleased]: https://github.com/electron-userland/electron-installer-common/compare/v0.7.0...master
## [0.7.0] - 2019-05-24
[0.7.0]: https://github.com/electron-userland/electron-installer-common/compare/v0.6.3...v0.7.0
### Fixed
* Let implementing modules specify revision fallbacks (#29)
### Changed
* `wrapError` is more `async`/`await`-friendly (#27)
### Removed
* Support for Node < 8 (#27)
## [0.6.3] - 2019-05-02

@@ -9,0 +25,0 @@

20

package.json
{
"name": "electron-installer-common",
"version": "0.6.3",
"version": "0.7.0",
"description": "Common functionality for creating distributable Electron apps",

@@ -26,3 +26,3 @@ "author": "Mark Lee",

"ava": "^1.0.1",
"codecov": "^3.1.0",
"codecov": "^3.5.0",
"eslint": "^5.10.0",

@@ -32,22 +32,21 @@ "eslint-config-standard": "^12.0.0",

"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-node": "^9.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"nyc": "^14.0.0",
"nyc": "^14.1.1",
"sinon": "^7.2.2"
},
"dependencies": {
"asar": "^1.0.0",
"asar": "^2.0.1",
"cross-spawn-promise": "^0.10.1",
"debug": "^4.1.1",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"glob-promise": "^3.4.0",
"fs-extra": "^8.0.1",
"glob": "^7.1.4",
"lodash": "^4.17.11",
"parse-author": "^2.0.0",
"semver": "^6.0.0",
"tmp-promise": "^1.0.5"
"tmp-promise": "^2.0.1"
},
"engines": {
"node": ">= 6.0"
"node": ">= 8.0"
},

@@ -72,3 +71,2 @@ "ava": {

"rules": {
"ava/prefer-async-await": 0,
"node/no-unpublished-require": [

@@ -75,0 +73,0 @@ "error",

@@ -10,3 +10,3 @@ # `electron-installer-common`

Requires Node 6 or greater.
Requires Node 8 or greater.

@@ -13,0 +13,0 @@ ## Legal

@@ -5,3 +5,10 @@ 'use strict'

module.exports = function getDefaultsFromPackageJSON (pkg) {
/**
* Generate default configuration values from the given parsed `package.json`.
*
* @param {object} pkg - the parsed `package.json` file
* @param {?object} fallbacks - fallback default value for certain options, currently:
* * `revision`
*/
module.exports = function getDefaultsFromPackageJSON (pkg, fallbacks = {}) {
return {

@@ -23,4 +30,4 @@ arch: undefined,

productName: pkg.productName || pkg.name,
revision: pkg.revision || '1'
revision: pkg.revision || fallbacks.revision
}
}

@@ -9,9 +9,8 @@ 'use strict'

module.exports = {
createDesktopFile: function createDesktopFile (templatePath, dir, baseName, options) {
createDesktopFile: async function createDesktopFile (templatePath, dir, baseName, options) {
const dest = path.join(dir, `${baseName}.desktop`)
debug(`Creating desktop file at ${dest}`)
return createTemplatedFile(templatePath, dest, options, 0o644)
.catch(wrapError('creating desktop file'))
return wrapError('creating desktop file', () => createTemplatedFile(templatePath, dest, options, 0o644))
}
}

@@ -17,9 +17,26 @@ 'use strict'

* ```
*
* The `wrappedFunction` parameter is used for async/await use cases. For example:
*
* ```javascript
* wrapError('with the code', async () => {
* await foo();
* await bar();
* })
* ```
*/
wrapError: function wrapError (message) {
return err => {
err.message = errorMessage(message, err)
throw err
wrapError: function wrapError (message, wrappedFunction) {
if (wrappedFunction) {
try {
return wrappedFunction()
} catch (error) {
module.exports.wrapError(message)(error)
}
} else {
return err => {
err.message = errorMessage(message, err)
throw err
}
}
}
}
'use strict'
const { promisify } = require('util')
const _ = require('lodash')

@@ -8,3 +10,3 @@ const debug = require('debug')('electron-installer-common:installer')

const fs = require('fs-extra')
const glob = require('glob-promise')
const glob = promisify(require('glob'))
const path = require('path')

@@ -15,2 +17,4 @@ const template = require('./template')

tmp.setGracefulCleanup()
class ElectronInstaller {

@@ -66,8 +70,9 @@ constructor (userSupplied) {

*/
copyApplication (ignoreFunc) {
async copyApplication (ignoreFunc) {
debug(`Copying application to ${this.stagingAppDir}`)
return fs.ensureDir(this.stagingAppDir, '0755')
.then(() => fs.copy(this.sourceDir, this.stagingAppDir, { filter: ignoreFunc }))
.catch(error.wrapError('copying application directory'))
return error.wrapError('copying application directory', async () => {
await fs.ensureDir(this.stagingAppDir, '0755')
return fs.copy(this.sourceDir, this.stagingAppDir, { filter: ignoreFunc })
})
}

@@ -78,3 +83,3 @@

*/
copyHicolorIcons () {
async copyHicolorIcons () {
return Promise.all(_.map(this.options.icon, (iconSrc, resolution) => {

@@ -84,4 +89,3 @@ const iconExt = resolution === 'scalable' ? 'svg' : 'png'

return this.copyIcon(iconSrc, iconFile)
.catch(error.wrapError('creating hicolor icon file'))
return error.wrapError('creating hicolor icon file', async () => this.copyIcon(iconSrc, iconFile))
}))

@@ -93,14 +97,11 @@ }

*/
copyIcon (src, dest) {
async copyIcon (src, dest) {
debug(`Copying icon file at from "${src}" to "${dest}"`)
return fs.pathExists(src)
.then(exists => {
if (!exists) {
throw new Error(`The icon "${src}" does not exist`)
}
return true
}).then(() => fs.ensureDir(path.dirname(dest), '0755'))
.then(() => fs.copy(src, dest))
.then(() => fs.chmod(dest, '0644'))
if (!await fs.pathExists(src)) {
throw new Error(`The icon "${src}" does not exist`)
}
await fs.ensureDir(path.dirname(dest), '0755')
await fs.copy(src, dest)
return fs.chmod(dest, '0644')
}

@@ -111,3 +112,3 @@

*/
copyLicense (copyrightFile) {
async copyLicense (copyrightFile) {
const licenseSrc = path.join(this.sourceDir, 'LICENSE')

@@ -122,3 +123,3 @@ debug(`Copying license file from ${licenseSrc}`)

*/
copyLinuxIcons () {
async copyLinuxIcons () {
if (_.isObject(this.options.icon)) {

@@ -134,7 +135,6 @@ return this.copyHicolorIcons()

*/
copyPixmapIcon () {
async copyPixmapIcon () {
const iconFile = path.join(this.stagingDir, this.baseAppDir, this.pixmapIconPath)
return this.copyIcon(this.options.icon, iconFile)
.catch(error.wrapError('creating pixmap icon file'))
return error.wrapError('creating pixmap icon file', async () => this.copyIcon(this.options.icon, iconFile))
}

@@ -145,3 +145,3 @@

*/
createBinarySymlink () {
async createBinarySymlink () {
const binSrc = path.join('../lib', this.appIdentifier, this.options.bin)

@@ -153,10 +153,9 @@ const binDest = path.join(this.stagingDir, this.baseAppDir, 'bin', this.appIdentifier)

return fs.pathExists(bundledBin)
.then(exists => {
if (!exists) {
throw new Error(`could not find the Electron app binary at "${bundledBin}". You may need to re-bundle the app using Electron Packager's "executableName" option.`)
}
return fs.ensureDir(path.dirname(binDest), '0755')
}).then(() => fs.symlink(binSrc, binDest, 'file'))
.catch(error.wrapError('creating binary symlink'))
return error.wrapError('creating binary symlink', async () => {
if (!await fs.pathExists(bundledBin)) {
throw new Error(`could not find the Electron app binary at "${bundledBin}". You may need to re-bundle the app using Electron Packager's "executableName" option.`)
}
await fs.ensureDir(path.dirname(binDest), '0755')
return fs.symlink(binSrc, binDest, 'file')
})
}

@@ -168,7 +167,6 @@

*/
createContents () {
async createContents () {
debug('Creating contents of package')
return Promise.all(this.contentFunctions.map(func => this[func]()))
.catch(error.wrapError('creating contents of package'))
return error.wrapError('creating contents of package', async () => Promise.all(this.contentFunctions.map(func => this[func]())))
}

@@ -179,10 +177,11 @@

*/
createCopyright () {
async createCopyright () {
const copyrightFile = path.join(this.stagingDir, this.baseAppDir, 'share', 'doc', this.appIdentifier, 'copyright')
debug(`Creating copyright file at ${copyrightFile}`)
return fs.ensureDir(path.dirname(copyrightFile), '0755')
.then(() => this.copyLicense(copyrightFile))
.then(() => fs.chmod(copyrightFile, '0644'))
.catch(error.wrapError('creating copyright file'))
return error.wrapError('creating copyright file', async () => {
await fs.ensureDir(path.dirname(copyrightFile), '0755')
await this.copyLicense(copyrightFile)
await fs.chmod(copyrightFile, '0644')
})
}

@@ -195,3 +194,3 @@

*/
createDesktopFile () {
async createDesktopFile () {
const templatePath = this.options.desktopTemplate || this.defaultDesktopTemplatePath

@@ -205,13 +204,13 @@ const baseDir = path.join(this.stagingDir, this.baseAppDir, 'share', 'applications')

*/
createStagingDir () {
async createStagingDir () {
debug('Creating staging directory')
return tmp.dir({ prefix: 'electron-', unsafeCleanup: true })
.then(dir => {
this.stagingDir = path.join(dir.path, `${this.appIdentifier}_${this.options.version}_${this.options.arch}`)
return fs.ensureDir(this.stagingDir, '0755')
}).catch(error.wrapError('creating staging directory'))
return error.wrapError('creating staging directory', async () => {
const dir = await tmp.dir({ prefix: 'electron-installer-', unsafeCleanup: true })
this.stagingDir = path.join(dir.path, `${this.appIdentifier}_${this.options.version}_${this.options.arch}`)
return fs.ensureDir(this.stagingDir, '0755')
})
}
createTemplatedFile (templatePath, dest, filePermissions) {
async createTemplatedFile (templatePath, dest, filePermissions) {
return template.createTemplatedFile(templatePath, dest, this.options, filePermissions)

@@ -230,7 +229,8 @@ }

*/
movePackage () {
async movePackage () {
debug('Moving package to destination')
return glob(this.packagePattern)
.then(files => Promise.all(files.map(file => {
return error.wrapError('moving package files', async () => {
const files = await glob(this.packagePattern)
return Promise.all(files.map(async file => {
const renameTemplate = this.options.rename(this.options.dest, path.basename(file))

@@ -240,3 +240,4 @@ const dest = _.template(renameTemplate)(this.options)

return fs.move(file, dest, { clobber: true })
}))).catch(error.wrapError('moving package files'))
}))
})
}

@@ -248,3 +249,3 @@

*/
updateSandboxHelperPermissions () {
async updateSandboxHelperPermissions () {
return updateSandboxHelperPermissions(this.stagingAppDir)

@@ -251,0 +252,0 @@ }

@@ -13,5 +13,5 @@ 'use strict'

*/
module.exports = function readElectronVersion (appDir) {
return fs.readFile(path.resolve(appDir, 'version'))
.then(tag => tag.toString().trim())
module.exports = async function readElectronVersion (appDir) {
const tag = await fs.readFile(path.resolve(appDir, 'version'))
return tag.toString().trim()
}

@@ -8,3 +8,3 @@ 'use strict'

function readPackageJSONFromUnpackedApp (options) {
async function readPackageJSONFromUnpackedApp (options) {
const appPackageJSONPath = path.join(options.src, 'resources', 'app', 'package.json')

@@ -29,14 +29,13 @@ options.logger(`Reading package metadata from ${appPackageJSONPath}`)

*/
module.exports = function readMetadata (options) {
module.exports = async function readMetadata (options) {
const appAsarPath = path.join(options.src, 'resources/app.asar')
return fs.pathExists(appAsarPath)
.then(asarExists => {
if (asarExists) {
options.logger(`Reading package metadata from ${appAsarPath}`)
return JSON.parse(asar.extractFile(appAsarPath, 'package.json'))
} else {
return readPackageJSONFromUnpackedApp(options)
}
}).catch(wrapError('reading package metadata'))
return wrapError('reading package metadata', async () => {
if (await fs.pathExists(appAsarPath)) {
options.logger(`Reading package metadata from ${appAsarPath}`)
return JSON.parse(asar.extractFile(appAsarPath, 'package.json'))
} else {
return readPackageJSONFromUnpackedApp(options)
}
})
}

@@ -16,12 +16,7 @@ 'use strict'

*/
module.exports = function updateSandboxHelperPermissions (appDir) {
module.exports = async function updateSandboxHelperPermissions (appDir) {
const sandboxHelperPath = path.join(appDir, 'chrome-sandbox')
return fs.pathExists(sandboxHelperPath)
.then(exists => {
if (exists) {
return fs.chmod(sandboxHelperPath, 0o4755)
} else {
return Promise.resolve()
}
})
if (await fs.pathExists(sandboxHelperPath)) {
return fs.chmod(sandboxHelperPath, 0o4755)
}
}

@@ -10,15 +10,16 @@ 'use strict'

*/
module.exports = function (cmd, args, logger, updateErrorCallback) {
module.exports = async function (cmd, args, logger, updateErrorCallback) {
if (logger) logger(`Executing command ${cmd} ${args.join(' ')}`)
return spawn(cmd, args)
.then(stdout => stdout.toString())
.catch(err => {
const stderr = err.stderr ? err.stderr.toString() : ''
if (updateErrorCallback) {
updateErrorCallback(err, !!logger)
}
try {
const stdout = await spawn(cmd, args)
return stdout.toString()
} catch (err) {
const stderr = err.stderr ? err.stderr.toString() : ''
if (updateErrorCallback) {
updateErrorCallback(err, !!logger)
}
throw new Error(`Error executing command (${err.message || err}):\n${cmd} ${args.join(' ')}\n${stderr}`)
})
throw new Error(`Error executing command (${err.message || err}):\n${cmd} ${args.join(' ')}\n${stderr}`)
}
}

@@ -11,11 +11,8 @@ 'use strict'

*/
function generateTemplate (file, data) {
async function generateTemplate (file, data) {
debug(`Generating template from ${file}`)
return fs.readFile(file)
.then(template => {
const result = _.template(template)(data)
debug(`Generated template from ${file}\n${result}`)
return result
})
const result = _.template(await fs.readFile(file))(data)
debug(`Generated template from ${file}\n${result}`)
return result
}

@@ -27,3 +24,3 @@

*/
createTemplatedFile: function createTemplatedFile (templatePath, dest, options, filePermissions) {
createTemplatedFile: async function createTemplatedFile (templatePath, dest, options, filePermissions) {
const fileOptions = {}

@@ -33,7 +30,7 @@ if (filePermissions) {

}
return fs.ensureDir(path.dirname(dest), '0755')
.then(() => generateTemplate(templatePath, options))
.then(data => fs.outputFile(dest, data, fileOptions))
await fs.ensureDir(path.dirname(dest), '0755')
const data = await generateTemplate(templatePath, options)
return fs.outputFile(dest, data, fileOptions)
},
generateTemplate
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc