Skip to content

Commit f1a29ba

Browse files
authored
feat: require Node 10.12.0 (#191)
* 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
1 parent 0ee4133 commit f1a29ba

File tree

7 files changed

+3517
-4368
lines changed

7 files changed

+3517
-4368
lines changed

.circleci/config.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ version: 2.1
2626
orbs:
2727
win: circleci/[email protected]
2828
jobs:
29-
test-linux-8:
30-
docker:
31-
- image: circleci/node:8
32-
<<: *steps-test
3329
test-linux-10:
3430
docker:
3531
- image: circleci/node:10
3632
<<: *steps-test
33+
test-linux-12:
34+
docker:
35+
- image: circleci/node:12
36+
<<: *steps-test
3737
test-mac:
3838
macos:
3939
xcode: "10.2.0"
@@ -57,14 +57,14 @@ workflows:
5757
test_and_release:
5858
# Run the test jobs first, then the release only when all the test jobs are successful
5959
jobs:
60-
- test-linux-8
6160
- test-linux-10
61+
- test-linux-12
6262
- test-mac
6363
- test-windows
6464
- release:
6565
requires:
66-
- test-linux-8
6766
- test-linux-10
67+
- test-linux-12
6868
- test-mac
6969
- test-windows
7070
filters:

lib/asar.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ module.exports.extractAll = function (archive, dest) {
192192
// try to delete output file, because we can't overwrite a link
193193
try {
194194
fs.unlinkSync(destFilename)
195-
} catch (error) {}
195+
} catch {}
196196
const linkTo = path.join(relativePath, path.basename(file.link))
197197
fs.symlinkSync(linkTo, destFilename)
198198
} else {

lib/filesystem.js

+31-40
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
'use strict'
22

33
const fs = require('./wrapped-fs')
4+
const os = require('os')
45
const path = require('path')
5-
const tmp = require('tmp-promise')
6-
const UINT64 = require('cuint').UINT64
6+
const { promisify } = require('util')
7+
const stream = require('stream')
78

8-
const UINT32_MAX = 4294967295
9+
const UINT32_MAX = 2 ** 32 - 1
10+
11+
const pipeline = promisify(stream.pipeline)
912

1013
class Filesystem {
1114
constructor (src) {
1215
this.src = path.resolve(src)
1316
this.header = { files: {} }
14-
this.offset = UINT64(0)
17+
this.offset = BigInt(0)
1518
}
1619

1720
searchNodeFromDirectory (p) {
@@ -57,48 +60,36 @@ class Filesystem {
5760
return Promise.resolve()
5861
}
5962

60-
const handler = (resolve, reject) => {
61-
const size = file.transformed ? file.transformed.stat.size : file.stat.size
62-
63-
// JavaScript can not precisely present integers >= UINT32_MAX.
64-
if (size > UINT32_MAX) {
65-
const error = new Error(`${p}: file size can not be larger than 4.2GB`)
66-
if (reject) {
67-
return reject(error)
68-
} else {
69-
throw error
70-
}
71-
}
63+
let size
7264

73-
node.size = size
74-
node.offset = this.offset.toString()
75-
if (process.platform !== 'win32' && (file.stat.mode & 0o100)) {
76-
node.executable = true
65+
const transformed = options.transform && options.transform(p)
66+
if (transformed) {
67+
const tmpdir = await fs.mkdtemp(path.join(os.tmpdir(), 'asar-'))
68+
const tmpfile = path.join(tmpdir, path.basename(p))
69+
const out = fs.createWriteStream(tmpfile)
70+
const readStream = fs.createReadStream(p)
71+
72+
await pipeline(readStream, transformed, out)
73+
file.transformed = {
74+
path: tmpfile,
75+
stat: await fs.lstat(tmpfile)
7776
}
78-
this.offset.add(UINT64(size))
77+
size = file.transformed.stat.size
78+
} else {
79+
size = file.stat.size
80+
}
7981

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

83-
const transformed = options.transform && options.transform(p)
84-
if (transformed) {
85-
const tmpfile = await tmp.file()
86-
return new Promise((resolve, reject) => {
87-
const out = fs.createWriteStream(tmpfile.path)
88-
const stream = fs.createReadStream(p)
89-
90-
stream.pipe(transformed).pipe(out)
91-
return out.on('close', async () => {
92-
file.transformed = {
93-
path: tmpfile.path,
94-
stat: await fs.lstat(tmpfile.path)
95-
}
96-
return handler(resolve, reject)
97-
})
98-
})
99-
} else {
100-
return handler()
87+
node.size = size
88+
node.offset = this.offset.toString()
89+
if (process.platform !== 'win32' && (file.stat.mode & 0o100)) {
90+
node.executable = true
10191
}
92+
this.offset += BigInt(size)
10293
}
10394

10495
insertLink (p) {

lib/wrapped-fs.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
'use strict'
22

3-
const { promisify } = require('util')
4-
53
const fs = process.versions.electron ? require('original-fs') : require('fs')
6-
const mkdirp = require('mkdirp')
74

85
const promisifiedMethods = [
96
'lstat',
7+
'mkdtemp',
108
'readFile',
119
'stat',
1210
'writeFile'
@@ -16,13 +14,13 @@ const promisified = {}
1614

1715
for (const method of Object.keys(fs)) {
1816
if (promisifiedMethods.includes(method)) {
19-
promisified[method] = promisify(fs[method])
17+
promisified[method] = fs.promises[method]
2018
} else {
2119
promisified[method] = fs[method]
2220
}
2321
}
2422
// To make it more like fs-extra
25-
promisified.mkdirp = promisify(mkdirp)
26-
promisified.mkdirpSync = mkdirp.sync
23+
promisified.mkdirp = (dir) => fs.promises.mkdir(dir, { recursive: true })
24+
promisified.mkdirpSync = (dir) => fs.mkdirSync(dir, { recursive: true })
2725

2826
module.exports = promisified

0 commit comments

Comments
 (0)