Skip to content

Commit

Permalink
feat: require Node 10.12.0 (#191)
Browse files Browse the repository at this point in the history
* refactor: replace mkdirp with built-in Node functionality
* build(deps-dev): upgrade standard to ^14.3.1
* refactor: use promisified stream.pipeline instead of multiple pipes
* build(deps): upgrade glob to ^7.1.6
* refactor: remove tmp-promise dependency
* build(deps-dev): upgrade rimraf to ^3.0.2
* build(deps-dev): upgrade lodash to ^4.17.15
* build(deps-dev): upgrade electron-mocha to ^8.2.1
* build(deps-dev): upgrade mocha to ^7.0.1
* build(deps-dev): upgrade semantic-release to ^17.0.4
* refactor: replace cuint with Node's builtin BigInt
* build(deps): upgrade commander to ^4.1.1
* build: update linux workers in CI to the correct Node versions

BREAKING CHANGE: Drops support for Node < 10.12.0
  • Loading branch information
malept committed Mar 10, 2020
1 parent 0ee4133 commit f1a29ba
Show file tree
Hide file tree
Showing 7 changed files with 3,517 additions and 4,368 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ version: 2.1
orbs:
win: circleci/windows@2.4.0
jobs:
test-linux-8:
docker:
- image: circleci/node:8
<<: *steps-test
test-linux-10:
docker:
- image: circleci/node:10
<<: *steps-test
test-linux-12:
docker:
- image: circleci/node:12
<<: *steps-test
test-mac:
macos:
xcode: "10.2.0"
Expand All @@ -57,14 +57,14 @@ workflows:
test_and_release:
# Run the test jobs first, then the release only when all the test jobs are successful
jobs:
- test-linux-8
- test-linux-10
- test-linux-12
- test-mac
- test-windows
- release:
requires:
- test-linux-8
- test-linux-10
- test-linux-12
- test-mac
- test-windows
filters:
Expand Down
2 changes: 1 addition & 1 deletion lib/asar.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ module.exports.extractAll = function (archive, dest) {
// try to delete output file, because we can't overwrite a link
try {
fs.unlinkSync(destFilename)
} catch (error) {}
} catch {}
const linkTo = path.join(relativePath, path.basename(file.link))
fs.symlinkSync(linkTo, destFilename)
} else {
Expand Down
71 changes: 31 additions & 40 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use strict'

const fs = require('./wrapped-fs')
const os = require('os')
const path = require('path')
const tmp = require('tmp-promise')
const UINT64 = require('cuint').UINT64
const { promisify } = require('util')
const stream = require('stream')

const UINT32_MAX = 4294967295
const UINT32_MAX = 2 ** 32 - 1

const pipeline = promisify(stream.pipeline)

class Filesystem {
constructor (src) {
this.src = path.resolve(src)
this.header = { files: {} }
this.offset = UINT64(0)
this.offset = BigInt(0)
}

searchNodeFromDirectory (p) {
Expand Down Expand Up @@ -57,48 +60,36 @@ class Filesystem {
return Promise.resolve()
}

const handler = (resolve, reject) => {
const size = file.transformed ? file.transformed.stat.size : file.stat.size

// JavaScript can not precisely present integers >= UINT32_MAX.
if (size > UINT32_MAX) {
const error = new Error(`${p}: file size can not be larger than 4.2GB`)
if (reject) {
return reject(error)
} else {
throw error
}
}
let size

node.size = size
node.offset = this.offset.toString()
if (process.platform !== 'win32' && (file.stat.mode & 0o100)) {
node.executable = true
const transformed = options.transform && options.transform(p)
if (transformed) {
const tmpdir = await fs.mkdtemp(path.join(os.tmpdir(), 'asar-'))
const tmpfile = path.join(tmpdir, path.basename(p))
const out = fs.createWriteStream(tmpfile)
const readStream = fs.createReadStream(p)

await pipeline(readStream, transformed, out)
file.transformed = {
path: tmpfile,
stat: await fs.lstat(tmpfile)
}
this.offset.add(UINT64(size))
size = file.transformed.stat.size
} else {
size = file.stat.size
}

return resolve ? resolve() : Promise.resolve()
// JavaScript cannot precisely present integers >= UINT32_MAX.
if (size > UINT32_MAX) {
throw new Error(`${p}: file size can not be larger than 4.2GB`)
}

const transformed = options.transform && options.transform(p)
if (transformed) {
const tmpfile = await tmp.file()
return new Promise((resolve, reject) => {
const out = fs.createWriteStream(tmpfile.path)
const stream = fs.createReadStream(p)

stream.pipe(transformed).pipe(out)
return out.on('close', async () => {
file.transformed = {
path: tmpfile.path,
stat: await fs.lstat(tmpfile.path)
}
return handler(resolve, reject)
})
})
} else {
return handler()
node.size = size
node.offset = this.offset.toString()
if (process.platform !== 'win32' && (file.stat.mode & 0o100)) {
node.executable = true
}
this.offset += BigInt(size)
}

insertLink (p) {
Expand Down
10 changes: 4 additions & 6 deletions lib/wrapped-fs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict'

const { promisify } = require('util')

const fs = process.versions.electron ? require('original-fs') : require('fs')
const mkdirp = require('mkdirp')

const promisifiedMethods = [
'lstat',
'mkdtemp',
'readFile',
'stat',
'writeFile'
Expand All @@ -16,13 +14,13 @@ const promisified = {}

for (const method of Object.keys(fs)) {
if (promisifiedMethods.includes(method)) {
promisified[method] = promisify(fs[method])
promisified[method] = fs.promises[method]
} else {
promisified[method] = fs[method]
}
}
// To make it more like fs-extra
promisified.mkdirp = promisify(mkdirp)
promisified.mkdirpSync = mkdirp.sync
promisified.mkdirp = (dir) => fs.promises.mkdir(dir, { recursive: true })
promisified.mkdirpSync = (dir) => fs.mkdirSync(dir, { recursive: true })

module.exports = promisified
Loading

0 comments on commit f1a29ba

Please sign in to comment.