Skip to content

Commit 49bba74

Browse files
authored
fix: enforce Node version constraint for the CLI (#193)
This is a variation on the version checking code in the Electron Packager CLI. Also mention the Node version requirement in the README.
1 parent 19889b6 commit 49bba74

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ all files together without compression, while having random access support.
1717

1818
### Install
1919

20+
This module requires Node 10 or later.
21+
2022
```bash
21-
$ npm install asar
23+
$ npm install --engine-strict asar
2224
```
2325

2426
### Usage

bin/asar.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
#!/usr/bin/env node
2+
3+
var packageJSON = require('../package.json')
4+
var splitVersion = function (version) { return version.split('.').map(function (part) { return Number(part) }) }
5+
var requiredNodeVersion = splitVersion(packageJSON.engines.node.slice(2))
6+
var actualNodeVersion = splitVersion(process.versions.node)
7+
8+
if (actualNodeVersion[0] < requiredNodeVersion[0] || (actualNodeVersion[0] === requiredNodeVersion[0] && actualNodeVersion[1] < requiredNodeVersion[1])) {
9+
console.error('CANNOT RUN WITH NODE ' + process.versions.node)
10+
console.error('asar requires Node ' + packageJSON.engines.node + '.')
11+
process.exit(1)
12+
}
13+
14+
// Not consts so that this file can load in Node < 4.0
215
var asar = require('../lib/asar')
316
var program = require('commander')
417

5-
program.version('v' + require('../package.json').version)
18+
program.version('v' + packageJSON.version)
619
.description('Manipulate asar archive files')
720

821
program.command('pack <dir> <output>')

0 commit comments

Comments
 (0)