chore: update to standard 12

This commit is contained in:
Samuel Attard 2018-09-14 02:10:51 +10:00
parent 9e85bdb02c
commit 558fff69e7
No known key found for this signature in database
GPG key ID: E89DDE5742D58C4E
198 changed files with 4455 additions and 2940 deletions

View file

@ -1,7 +1,7 @@
(function () {
const asar = process.binding('atom_common_asar')
const assert = require('assert')
const {Buffer} = require('buffer')
const { Buffer } = require('buffer')
const childProcess = require('child_process')
const path = require('path')
const util = require('util')
@ -48,22 +48,22 @@
// Separate asar package's path from full path.
const splitPath = archivePathOrBuffer => {
// Shortcut for disabled asar.
if (isAsarDisabled()) return {isAsar: false}
if (isAsarDisabled()) return { isAsar: false }
// Check for a bad argument type.
let archivePath = archivePathOrBuffer
if (Buffer.isBuffer(archivePathOrBuffer)) {
archivePath = archivePathOrBuffer.toString()
}
if (typeof archivePath !== 'string') return {isAsar: false}
if (typeof archivePath !== 'string') return { isAsar: false }
if (archivePath.endsWith(ASAR_EXTENSION)) {
return {isAsar: true, asarPath: archivePath, filePath: ''}
return { isAsar: true, asarPath: archivePath, filePath: '' }
}
archivePath = path.normalize(archivePath)
const index = archivePath.lastIndexOf(`${ASAR_EXTENSION}${path.sep}`)
if (index === -1) return {isAsar: false}
if (index === -1) return { isAsar: false }
// E.g. for "//some/path/to/archive.asar/then/internal.file"...
return {
@ -85,7 +85,7 @@
const msec = (date) => (date || fakeTime).getTime()
const asarStatsToFsStats = function (stats) {
const {Stats, constants} = require('fs')
const { Stats, constants } = require('fs')
let mode = constants.S_IROTH ^ constants.S_IRGRP ^ constants.S_IRUSR ^ constants.S_IWUSR
@ -98,20 +98,20 @@
}
return new Stats(
1, // dev
mode, // mode
1, // nlink
uid,
gid,
0, // rdev
undefined, // blksize
++nextInode, // ino
stats.size,
undefined, // blocks,
msec(stats.atime), // atim_msec
msec(stats.mtime), // mtim_msec
msec(stats.ctime), // ctim_msec
msec(stats.birthtime) // birthtim_msec
1, // dev
mode, // mode
1, // nlink
uid,
gid,
0, // rdev
undefined, // blksize
++nextInode, // ino
stats.size,
undefined, // blocks,
msec(stats.atime), // atim_msec
msec(stats.mtime), // mtim_msec
msec(stats.ctime), // ctim_msec
msec(stats.birthtime) // birthtim_msec
)
}
@ -122,7 +122,7 @@
INVALID_ARCHIVE: 'INVALID_ARCHIVE'
}
const createError = (errorType, {asarPath, filePath} = {}) => {
const createError = (errorType, { asarPath, filePath } = {}) => {
let error
switch (errorType) {
case AsarError.NOT_FOUND:
@ -154,14 +154,14 @@
const old = module[name]
module[name] = function () {
const pathArgument = arguments[pathArgumentIndex]
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return old.apply(this, arguments)
const archive = getOrCreateArchive(asarPath)
if (!archive) throw createError(AsarError.INVALID_ARCHIVE, {asarPath})
if (!archive) throw createError(AsarError.INVALID_ARCHIVE, { asarPath })
const newPath = archive.copyFileOut(filePath)
if (!newPath) throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
if (!newPath) throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
arguments[pathArgumentIndex] = newPath
return old.apply(this, arguments)
@ -173,7 +173,7 @@
const old = module[name]
module[name] = function () {
const pathArgument = arguments[pathArgumentIndex]
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return old.apply(this, arguments)
const callback = arguments[arguments.length - 1]
@ -183,14 +183,14 @@
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
nextTick(callback, [error])
return
}
const newPath = archive.copyFileOut(filePath)
if (!newPath) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -202,17 +202,17 @@
if (old[util.promisify.custom]) {
module[name][util.promisify.custom] = function () {
const pathArgument = arguments[pathArgumentIndex]
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return old[util.promisify.custom].apply(this, arguments)
const archive = getOrCreateArchive(asarPath)
if (!archive) {
return Promise.reject(createError(AsarError.INVALID_ARCHIVE, {asarPath}))
return Promise.reject(createError(AsarError.INVALID_ARCHIVE, { asarPath }))
}
const newPath = archive.copyFileOut(filePath)
if (!newPath) {
return Promise.reject(createError(AsarError.NOT_FOUND, {asarPath, filePath}))
return Promise.reject(createError(AsarError.NOT_FOUND, { asarPath, filePath }))
}
arguments[pathArgumentIndex] = newPath
@ -235,35 +235,35 @@
fs.writeSync(logFDs[asarPath], `${offset}: ${filePath}\n`)
}
const {lstatSync} = fs
const { lstatSync } = fs
fs.lstatSync = pathArgument => {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return lstatSync(pathArgument)
const archive = getOrCreateArchive(asarPath)
if (!archive) throw createError(AsarError.INVALID_ARCHIVE, {asarPath})
if (!archive) throw createError(AsarError.INVALID_ARCHIVE, { asarPath })
const stats = archive.stat(filePath)
if (!stats) throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
if (!stats) throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
return asarStatsToFsStats(stats)
}
const {lstat} = fs
const { lstat } = fs
fs.lstat = (pathArgument, callback) => {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return lstat(pathArgument, callback)
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
nextTick(callback, [error])
return
}
const stats = archive.stat(filePath)
if (!stats) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -272,27 +272,27 @@
nextTick(callback, [null, fsStats])
}
const {statSync} = fs
const { statSync } = fs
fs.statSync = pathArgument => {
const {isAsar} = splitPath(pathArgument)
const { isAsar } = splitPath(pathArgument)
if (!isAsar) return statSync(pathArgument)
// Do not distinguish links for now.
return fs.lstatSync(pathArgument)
}
const {stat} = fs
const { stat } = fs
fs.stat = (pathArgument, callback) => {
const {isAsar} = splitPath(pathArgument)
const { isAsar } = splitPath(pathArgument)
if (!isAsar) return stat(pathArgument, callback)
// Do not distinguish links for now.
process.nextTick(() => fs.lstat(pathArgument, callback))
}
const {statSyncNoException} = fs
const { statSyncNoException } = fs
fs.statSyncNoException = pathArgument => {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return statSyncNoException(pathArgument)
const archive = getOrCreateArchive(asarPath)
@ -304,44 +304,44 @@
return asarStatsToFsStats(stats)
}
const {realpathSync} = fs
const { realpathSync } = fs
fs.realpathSync = function (pathArgument) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return realpathSync.apply(this, arguments)
const archive = getOrCreateArchive(asarPath)
if (!archive) {
throw createError(AsarError.INVALID_ARCHIVE, {asarPath})
throw createError(AsarError.INVALID_ARCHIVE, { asarPath })
}
const fileRealPath = archive.realpath(filePath)
if (fileRealPath === false) {
throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
}
return path.join(realpathSync(asarPath), fileRealPath)
}
fs.realpathSync.native = function (pathArgument) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return realpathSync.native.apply(this, arguments)
const archive = getOrCreateArchive(asarPath)
if (!archive) {
throw createError(AsarError.INVALID_ARCHIVE, {asarPath})
throw createError(AsarError.INVALID_ARCHIVE, { asarPath })
}
const fileRealPath = archive.realpath(filePath)
if (fileRealPath === false) {
throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
}
return path.join(realpathSync.native(asarPath), fileRealPath)
}
const {realpath} = fs
const { realpath } = fs
fs.realpath = function (pathArgument, cache, callback) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return realpath.apply(this, arguments)
if (typeof cache === 'function') {
@ -351,14 +351,14 @@
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
nextTick(callback, [error])
return
}
const fileRealPath = archive.realpath(filePath)
if (fileRealPath === false) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -374,7 +374,7 @@
}
fs.realpath.native = function (pathArgument, cache, callback) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return realpath.native.apply(this, arguments)
if (typeof cache === 'function') {
@ -384,14 +384,14 @@
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
nextTick(callback, [error])
return
}
const fileRealPath = archive.realpath(filePath)
if (fileRealPath === false) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -406,14 +406,14 @@
})
}
const {exists} = fs
const { exists } = fs
fs.exists = (pathArgument, callback) => {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return exists(pathArgument, callback)
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
nextTick(callback, [error])
return
}
@ -423,21 +423,21 @@
}
fs.exists[util.promisify.custom] = pathArgument => {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return exists[util.promisify.custom](pathArgument)
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
return Promise.reject(error)
}
return Promise.resolve(archive.stat(filePath) !== false)
}
const {existsSync} = fs
const { existsSync } = fs
fs.existsSync = pathArgument => {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return existsSync(pathArgument)
const archive = getOrCreateArchive(asarPath)
@ -446,9 +446,9 @@
return archive.stat(filePath) !== false
}
const {access} = fs
const { access } = fs
fs.access = function (pathArgument, mode, callback) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return access.apply(this, arguments)
if (typeof mode === 'function') {
@ -458,14 +458,14 @@
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
nextTick(callback, [error])
return
}
const info = archive.getFileInfo(filePath)
if (!info) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -477,13 +477,13 @@
const stats = archive.stat(filePath)
if (!stats) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
if (mode & fs.constants.W_OK) {
const error = createError(AsarError.NO_ACCESS, {asarPath, filePath})
const error = createError(AsarError.NO_ACCESS, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -491,21 +491,21 @@
nextTick(callback)
}
const {accessSync} = fs
const { accessSync } = fs
fs.accessSync = function (pathArgument, mode) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return accessSync.apply(this, arguments)
if (mode == null) mode = fs.constants.F_OK
const archive = getOrCreateArchive(asarPath)
if (!archive) {
throw createError(AsarError.INVALID_ARCHIVE, {asarPath})
throw createError(AsarError.INVALID_ARCHIVE, { asarPath })
}
const info = archive.getFileInfo(filePath)
if (!info) {
throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
}
if (info.unpacked) {
@ -515,17 +515,17 @@
const stats = archive.stat(filePath)
if (!stats) {
throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
}
if (mode & fs.constants.W_OK) {
throw createError(AsarError.NO_ACCESS, {asarPath, filePath})
throw createError(AsarError.NO_ACCESS, { asarPath, filePath })
}
}
const {readFile} = fs
const { readFile } = fs
fs.readFile = function (pathArgument, options, callback) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return readFile.apply(this, arguments)
if (typeof options === 'function') {
@ -539,17 +539,17 @@
throw new TypeError('Bad arguments')
}
const {encoding} = options
const { encoding } = options
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
nextTick(callback, [error])
return
}
const info = archive.getFileInfo(filePath)
if (!info) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -567,7 +567,7 @@
const buffer = Buffer.alloc(info.size)
const fd = archive.getFd()
if (!(fd >= 0)) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -578,16 +578,16 @@
})
}
const {readFileSync} = fs
const { readFileSync } = fs
fs.readFileSync = function (pathArgument, options) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return readFileSync.apply(this, arguments)
const archive = getOrCreateArchive(asarPath)
if (!archive) throw createError(AsarError.INVALID_ARCHIVE, {asarPath})
if (!archive) throw createError(AsarError.INVALID_ARCHIVE, { asarPath })
const info = archive.getFileInfo(filePath)
if (!info) throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
if (!info) throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
if (info.size === 0) return (options) ? '' : Buffer.alloc(0)
if (info.unpacked) {
@ -603,31 +603,31 @@
throw new TypeError('Bad arguments')
}
const {encoding} = options
const { encoding } = options
const buffer = Buffer.alloc(info.size)
const fd = archive.getFd()
if (!(fd >= 0)) throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
if (!(fd >= 0)) throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
logASARAccess(asarPath, filePath, info.offset)
fs.readSync(fd, buffer, 0, info.size, info.offset)
return (encoding) ? buffer.toString(encoding) : buffer
}
const {readdir} = fs
const { readdir } = fs
fs.readdir = function (pathArgument, callback) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return readdir.apply(this, arguments)
const archive = getOrCreateArchive(asarPath)
if (!archive) {
const error = createError(AsarError.INVALID_ARCHIVE, {asarPath})
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath })
nextTick(callback, [error])
return
}
const files = archive.readdir(filePath)
if (!files) {
const error = createError(AsarError.NOT_FOUND, {asarPath, filePath})
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath })
nextTick(callback, [error])
return
}
@ -635,27 +635,27 @@
nextTick(callback, [null, files])
}
const {readdirSync} = fs
const { readdirSync } = fs
fs.readdirSync = function (pathArgument) {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return readdirSync.apply(this, arguments)
const archive = getOrCreateArchive(asarPath)
if (!archive) {
throw createError(AsarError.INVALID_ARCHIVE, {asarPath})
throw createError(AsarError.INVALID_ARCHIVE, { asarPath })
}
const files = archive.readdir(filePath)
if (!files) {
throw createError(AsarError.NOT_FOUND, {asarPath, filePath})
throw createError(AsarError.NOT_FOUND, { asarPath, filePath })
}
return files
}
const {internalModuleReadJSON} = process.binding('fs')
const { internalModuleReadJSON } = process.binding('fs')
process.binding('fs').internalModuleReadJSON = pathArgument => {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return internalModuleReadJSON(pathArgument)
const archive = getOrCreateArchive(asarPath)
@ -666,7 +666,7 @@
if (info.size === 0) return ''
if (info.unpacked) {
const realPath = archive.copyFileOut(filePath)
return fs.readFileSync(realPath, {encoding: 'utf8'})
return fs.readFileSync(realPath, { encoding: 'utf8' })
}
const buffer = Buffer.alloc(info.size)
@ -678,9 +678,9 @@
return buffer.toString('utf8')
}
const {internalModuleStat} = process.binding('fs')
const { internalModuleStat } = process.binding('fs')
process.binding('fs').internalModuleStat = pathArgument => {
const {isAsar, asarPath, filePath} = splitPath(pathArgument)
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return internalModuleStat(pathArgument)
// -ENOENT
@ -699,14 +699,14 @@
// This is to work around the recursive looping bug of mkdirp since it is
// widely used.
if (process.platform === 'win32') {
const {mkdir} = fs
const { mkdir } = fs
fs.mkdir = (pathArgument, mode, callback) => {
if (typeof mode === 'function') {
callback = mode
mode = undefined
}
const {isAsar, filePath} = splitPath(pathArgument)
const { isAsar, filePath } = splitPath(pathArgument)
if (isAsar && filePath.length > 0) {
const error = createError(AsarError.NOT_DIR)
nextTick(callback, [error])
@ -716,9 +716,9 @@
mkdir(pathArgument, mode, callback)
}
const {mkdirSync} = fs
const { mkdirSync } = fs
fs.mkdirSync = function (pathArgument, mode) {
const {isAsar, filePath} = splitPath(pathArgument)
const { isAsar, filePath } = splitPath(pathArgument)
if (isAsar && filePath.length) throw createError(AsarError.NOT_DIR)
return mkdirSync(pathArgument, mode)
}
@ -729,7 +729,7 @@
// called by `childProcess.{exec,execSync}`, causing
// Electron to consider the full command as a single path
// to an archive.
const {exec, execSync} = childProcess
const { exec, execSync } = childProcess
childProcess.exec = invokeWithNoAsar(exec)
childProcess.exec[util.promisify.custom] = invokeWithNoAsar(exec[util.promisify.custom])
childProcess.execSync = invokeWithNoAsar(execSync)