Skip to content

Commit

Permalink
fix: enforce Node version constraint for the CLI (#193)
Browse files Browse the repository at this point in the history
This is a variation on the version checking code in the Electron Packager CLI.

Also mention the Node version requirement in the README.
  • Loading branch information
malept committed Mar 12, 2020
1 parent 19889b6 commit 49bba74
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ all files together without compression, while having random access support.

### Install

This module requires Node 10 or later.

```bash
$ npm install asar
$ npm install --engine-strict asar
```

### Usage
Expand Down
15 changes: 14 additions & 1 deletion bin/asar.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#!/usr/bin/env node

var packageJSON = require('../package.json')
var splitVersion = function (version) { return version.split('.').map(function (part) { return Number(part) }) }
var requiredNodeVersion = splitVersion(packageJSON.engines.node.slice(2))
var actualNodeVersion = splitVersion(process.versions.node)

if (actualNodeVersion[0] < requiredNodeVersion[0] || (actualNodeVersion[0] === requiredNodeVersion[0] && actualNodeVersion[1] < requiredNodeVersion[1])) {
console.error('CANNOT RUN WITH NODE ' + process.versions.node)
console.error('asar requires Node ' + packageJSON.engines.node + '.')
process.exit(1)
}

// Not consts so that this file can load in Node < 4.0
var asar = require('../lib/asar')
var program = require('commander')

program.version('v' + require('../package.json').version)
program.version('v' + packageJSON.version)
.description('Manipulate asar archive files')

program.command('pack <dir> <output>')
Expand Down

0 comments on commit 49bba74

Please sign in to comment.