Skip to content

Commit

Permalink
fix: silent exit on unsupported node.js versions (#1829)
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli authored Jul 19, 2022
2 parents 8d83230 + f635e4e commit 6dd2162
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 36 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/old-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

strategy:
matrix:
node-version: [0.10.48]
node-version: [0.10.48, 4]

steps:
- name: Checkout project
Expand All @@ -30,17 +30,9 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Cache Node dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install
run: npm install --production

- name: Test that the command line program exits cleanly.
run: ./bin/cmd.js
run: ./bin/cmd.cjs
shell: bash
3 changes: 3 additions & 0 deletions bin/cmd.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('version-guard')('../lib/cli.js', 12, 22)
16 changes: 0 additions & 16 deletions bin/cmd.js

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! standard. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
import { StandardEngine } from 'standard-engine'
import options from './options.js'
import options from './lib/options.js'

export default new StandardEngine(options)
4 changes: 4 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { cli } from 'standard-engine'
import options from './options.js'

cli(options)
4 changes: 2 additions & 2 deletions options.js → lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { fileURLToPath } from 'node:url'
import eslint from 'eslint'

// eslintConfig.overrideConfigFile have problem reading URLs and file:///
const overrideConfigFile = fileURLToPath(new URL('./eslintrc.json', import.meta.url))
const pkgURL = new URL('./package.json', import.meta.url)
const overrideConfigFile = fileURLToPath(new URL('../eslintrc.json', import.meta.url))
const pkgURL = new URL('../package.json', import.meta.url)
const pkgJSON = readFileSync(pkgURL, { encoding: 'utf-8' })
const pkg = JSON.parse(pkgJSON)

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://feross.org"
},
"bin": {
"standard": "bin/cmd.js"
"standard": "bin/cmd.cjs"
},
"type": "module",
"bugs": {
Expand All @@ -22,7 +22,8 @@
"eslint-plugin-n": "^15.1.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.28.0",
"standard-engine": "^15.0.0"
"standard-engine": "^15.0.0",
"version-guard": "^1.1.0"
},
"devDependencies": {
"cross-spawn": "^7.0.3",
Expand Down Expand Up @@ -70,7 +71,7 @@
},
"scripts": {
"test": "npm run test-internal && npm run test-external",
"test-internal": "./bin/cmd.js --verbose && tape test/*.js",
"test-internal": "./bin/cmd.cjs --verbose && tape test/*.js",
"test-external": "tape test/external/*.js",
"update-authors": "./tools/update-authors.sh && hallmark --fix AUTHORS.md"
},
Expand Down
2 changes: 1 addition & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import standard from '../index.js'

test('api: lintFiles', async (t) => {
t.plan(2)
const [result] = await standard.lintFiles(['bin/cmd.js'])
const [result] = await standard.lintFiles(['bin/cmd.cjs'])
t.equal(typeof result, 'object', 'result is an object')
t.equal(result.errorCount, 0)
})
Expand Down
2 changes: 1 addition & 1 deletion test/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url'
import test from 'tape'
import crossSpawn from 'cross-spawn'

const CMD_PATH = fileURLToPath(new URL('../bin/cmd.js', import.meta.url))
const CMD_PATH = fileURLToPath(new URL('../bin/cmd.cjs', import.meta.url))

test('command line usage: --help', t => {
t.plan(1)
Expand Down
2 changes: 1 addition & 1 deletion test/external/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const testPkgs = JSON.parse(json)

const GIT = 'git'
const NPM = 'npm'
const STANDARD = fileURLToPath(new URL('../../bin/cmd.js', import.meta.url))
const STANDARD = fileURLToPath(new URL('../../bin/cmd.cjs', import.meta.url))
const TMP = new URL('../../tmp/', import.meta.url)
const PARALLEL_LIMIT = Math.ceil(cpus().length / 2)

Expand Down

0 comments on commit 6dd2162

Please sign in to comment.