Skip to content

Commit

Permalink
Use neostandard + add more static code analysis (#142)
Browse files Browse the repository at this point in the history
* Use neostandard

* ci: add knip + rimraf + clean up with help of knip

* only run workflows on on `master` branch and PR:s

* tweak new npm scripts

* add installed-check
  • Loading branch information
voxpelli authored Jul 2, 2024
1 parent 6be8fff commit 25738ae
Show file tree
Hide file tree
Showing 29 changed files with 85 additions and 287 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
name: tests

on: [pull_request, push]
on:
push:
branches:
- master
tags:
- '*'
pull_request:
branches:
- master

env:
FORCE_COLOR: 2

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js lts/*
uses: actions/setup-node@v4
with:
node-version: lts/*
- run: npm i
- run: npm run check

test:
runs-on: ${{ matrix.os }}

Expand All @@ -22,14 +41,14 @@ jobs:
with:
node-version: ${{ matrix.node }}
- run: npm i
- run: npm test
- run: npm run test-mocha
- uses: codecov/codecov-action@v4
if: ${{ github.event_name == 'pull_request' }}
with:
flags: ${{ matrix.os }}-${{ matrix.node }}

automerge:
needs: test
needs: [lint, test]
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand Down
5 changes: 5 additions & 0 deletions .knip.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"entry": ["lib/index.js", "bin/*/*.js", "test-workspace/tasks/*.js"],
"ignoreDependencies": ["rimraf", "yarn"]
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![Downloads/month](https://img.shields.io/npm/dm/npm-run-all2.svg)](http://www.npmtrends.com/npm-run-all2)
[![tests](https://github.com/bcomnes/npm-run-all2/workflows/tests/badge.svg)](https://github.com/bcomnes/npm-run-all2/actions)
[![Coverage Status](https://codecov.io/gh/bcomnes/npm-run-all2/branch/master/graph/badge.svg)](https://codecov.io/gh/bcomnes/npm-run-all2)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

A CLI tool to run multiple npm-scripts in parallel or sequential.

Expand Down
3 changes: 0 additions & 3 deletions bin/common/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// ------------------------------------------------------------------------------
// Public Interface
// ------------------------------------------------------------------------------
/* eslint-disable no-process-exit */

module.exports = function bootstrap (name) {
const argv = process.argv.slice(2)
Expand Down Expand Up @@ -47,5 +46,3 @@ module.exports = function bootstrap (name) {
)
}
}

/* eslint-enable */
4 changes: 0 additions & 4 deletions bin/common/parse-cli-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
'use strict'

/* eslint-disable no-process-env */

// ------------------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -243,5 +241,3 @@ function parseCLIArgsCore (set, args) {
module.exports = function parseCLIArgs (args, initialValues, options) {
return parseCLIArgsCore(new ArgumentSet(initialValues, options), args)
}

/* eslint-enable */
4 changes: 1 addition & 3 deletions bin/npm-run-all/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function npmRunAll (args, stdout, stderr) {
arguments: argv.rest,
race: group.parallel && argv.race,
npmPath: argv.npmPath,
aggregateOutput: group.parallel && argv.aggregateOutput
aggregateOutput: group.parallel && argv.aggregateOutput,
}
))
},
Expand All @@ -61,14 +61,12 @@ module.exports = function npmRunAll (args, stdout, stderr) {

if (!argv.silent) {
promise.catch(err => {
// eslint-disable-next-line no-console
console.error('ERROR:', err.message)
})
}

return promise
} catch (err) {
// eslint-disable-next-line no-console
console.error('ERROR:', err.message)

return Promise.reject(err)
Expand Down
4 changes: 1 addition & 3 deletions bin/run-p/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,18 @@ module.exports = function npmRunAll (args, stdout, stderr) {
arguments: argv.rest,
race: argv.race,
npmPath: argv.npmPath,
aggregateOutput: argv.aggregateOutput
aggregateOutput: argv.aggregateOutput,
}
)

if (!argv.silent) {
promise.catch(err => {
// eslint-disable-next-line no-console
console.error('ERROR:', err.message)
})
}

return promise
} catch (err) {
// eslint-disable-next-line no-console
console.error('ERROR:', err.message)

return Promise.reject(err)
Expand Down
4 changes: 1 addition & 3 deletions bin/run-s/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ module.exports = function npmRunAll (args, stdout, stderr) {
packageConfig: argv.packageConfig,
silent: argv.silent,
arguments: argv.rest,
npmPath: argv.npmPath
npmPath: argv.npmPath,
}
)

if (!argv.silent) {
promise.catch(err => {
// eslint-disable-next-line no-console
console.error('ERROR:', err.message)
})
}

return promise
} catch (err) {
// eslint-disable-next-line no-console
console.error('ERROR:', err.message)

return Promise.reject(err)
Expand Down
9 changes: 9 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

module.exports = [
...require('neostandard')({
env: ['mocha'],
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true,
}),
]
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function maxLength (length, name) {
* @returns {Promise}
* A promise object which becomes fullfilled when all npm-scripts are completed.
*/
module.exports = function npmRunAll (patternOrPatterns, options) { // eslint-disable-line complexity
module.exports = function npmRunAll (patternOrPatterns, options) {
const stdin = (options && options.stdin) || null
const stdout = (options && options.stdout) || null
const stderr = (options && options.stderr) || null
Expand Down Expand Up @@ -290,14 +290,14 @@ module.exports = function npmRunAll (patternOrPatterns, options) { // eslint-dis
enabled: printLabel,
width: labelWidth,
lastPrefix: null,
lastIsLinebreak: true
lastIsLinebreak: true,
},
printName,
packageInfo: x.packageInfo,
race,
maxParallel,
npmPath,
aggregateOutput
aggregateOutput,
})
})
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/read-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ module.exports = function readPackageJson () {
const path = joinPath(process.cwd(), 'package.json')
return readPackage(path).then(body => ({
taskList: Object.keys(body.scripts || {}),
packageInfo: { path, body }
packageInfo: { path, body },
}))
}
8 changes: 4 additions & 4 deletions lib/run-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ module.exports = function runTask (task, options) {
const basename = path.basename(process.env.npm_execpath)
let newBasename = basename
if (basename.startsWith('npx')) {
newBasename = basename.replace('npx', 'npm') // eslint-disable-line no-process-env
newBasename = basename.replace('npx', 'npm')
} else if (basename.startsWith('pnpx')) {
newBasename = basename.replace('pnpx', 'pnpm') // eslint-disable-line no-process-env
newBasename = basename.replace('pnpx', 'pnpm')
}

npmPath = newBasename !== basename
? path.join(path.dirname(process.env.npm_execpath), newBasename)
: process.env.npm_execpath // eslint-disable-line no-process-env
: process.env.npm_execpath
}

const npmPathIsJs = typeof npmPath === 'string' && /\.(c|m)?js/.test(path.extname(npmPath))
Expand All @@ -191,7 +191,7 @@ module.exports = function runTask (task, options) {
}
}

const isYarn = process.env.npm_config_user_agent && process.env.npm_config_user_agent.startsWith('yarn') // eslint-disable-line no-process-env
const isYarn = process.env.npm_config_user_agent && process.env.npm_config_user_agent.startsWith('yarn')

const spawnArgs = ['run']

Expand Down
4 changes: 2 additions & 2 deletions lib/run-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const signals = {
SIGTTIN: 21,
SIGTTOU: 22,
SIGUSR1: 30,
SIGUSR2: 31
SIGUSR2: 31,
}

/**
Expand Down Expand Up @@ -142,7 +142,7 @@ module.exports = function runTasks (tasks, options) {
const originalOutputStream = options.stdout
const optionsClone = Object.assign({}, options)
const writer = new MemoryStream(null, {
readable: false
readable: false,
})

if (options.aggregateOutput) {
Expand Down
4 changes: 1 addition & 3 deletions lib/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@
* This is {@link ./spawn-posix.js:spawn} or {@link ./spawn-win32.js:spawn}
* @private
*/
module.exports = require(
process.platform === 'win32' ? './spawn-win32' : './spawn-posix'
)
module.exports = process.platform === 'win32' ? require('./spawn-win32') : require('./spawn-posix')
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
},
"main": "lib/index.js",
"engines": {
"node": "^14.18.0 || >=16.0.0",
"node": "^14.18.0 || ^16.13.0 || >=18.0.0",
"npm": ">= 8"
},
"scripts": {
"_mocha": "mocha --timeout 120000",
"clean": "rm -rf coverage jsdoc \"test-workspace/{build,test.txt}\"",
"docs": "jsdoc -c jsdoc.json",
"lint": "standard",
"pretest": "node scripts/make-slink.js && npm run lint",
"test": "c8 npm run _mocha",
"watch": "npm run _mocha -- --watch --growl",
"check:installed-check": "installed-check --ignore-dev",
"check:eslint": "eslint",
"check:knip": "knip",
"precheck": "node scripts/make-slink.js",
"check": "node ./bin/run-p/index.js check:*",
"pretest-mocha": "node scripts/make-slink.js",
"test-mocha": "c8 mocha --timeout 120000",
"test": "node ./bin/run-s/index.js check test-mocha",
"watch": "mocha --timeout 120000 --watch --growl",
"version": "auto-changelog -p --template keepachangelog auto-changelog --breaking-pattern 'BREAKING CHANGE:' && git add CHANGELOG.md",
"preversion": "npm test",
"postversion": "git push --follow-tags && gh-release -y"
Expand All @@ -37,12 +41,14 @@
"devDependencies": {
"auto-changelog": "^2.2.0",
"c8": "^10.0.0",
"fs-extra": "^11.1.0",
"eslint": "^9.6.0",
"gh-release": "^7.0.0",
"installed-check": "^9.3.0",
"jsdoc": "^4.0.0",
"knip": "^5.23.3",
"mocha": "^10.0.0",
"p-queue": "^8.0.1",
"standard": "^17.1.0",
"neostandard": "^0.11.0",
"rimraf": "^5.0.7",
"yarn": "^1.12.3"
},
"repository": {
Expand Down
5 changes: 2 additions & 3 deletions test/aggregate-output.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-env mocha */
/**
* @author Toru Nagashima
* @copyright 2016 Toru Nagashima. All rights reserved.
Expand Down Expand Up @@ -40,7 +39,7 @@ describe('[aggregated-output] npm-run-all', () => {
createExpectedOutput('second'),
createExpectedOutput('third'),
createExpectedOutput('first'),
''
'',
].join('\n')

let stdout = null
Expand Down Expand Up @@ -107,7 +106,7 @@ describe('[aggregated-output] npm-run-all', () => {
'test-task:delayed first 5000',
'test-task:delayed second 1000',
'test-task:delayed third 3000',
'--silent', '--aggregate-output'
'--silent', '--aggregate-output',
],
stdout
)
Expand Down
8 changes: 1 addition & 7 deletions test/argument-placeholders.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-env mocha */
/**
* @author Toru Nagashima
* @copyright 2016 Toru Nagashima. All rights reserved.
Expand All @@ -14,12 +13,7 @@ const assert = require('assert').strict
const { strictEqual } = assert

const nodeApi = require('../lib')
const util = require('./lib/util')
const result = util.result
const removeResult = util.removeResult
const runAll = util.runAll
const runPar = util.runPar
const runSeq = util.runSeq
const { result, removeResult, runAll, runPar, runSeq } = require('./lib/util')

// ------------------------------------------------------------------------------
// Test
Expand Down
Loading

0 comments on commit 25738ae

Please sign in to comment.