check-installed 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
  Minimal Node package to check that dependencies are installed ✅
3
3
 
4
4
  [![npm](https://img.shields.io/npm/v/check-installed)](https://www.npmjs.com/package/check-installed)
5
+ [![pipeline status](https://gitlab.com/flippidippi/check-installed/badges/main/pipeline.svg)](https://gitlab.com/flippidippi/check-installed/-/pipelines?ref=main)
6
+ [![coverage report](https://gitlab.com/flippidippi/check-installed/badges/main/coverage.svg)](https://check-installed-flippidippi-09a6e441a6dd0a7a65f32f5fe3ec449245f.gitlab.io/coverage)
5
7
 
6
8
  ## Install
7
9
  ```bash
@@ -34,7 +36,8 @@ In `package.json`:
34
36
  },
35
37
  "scripts": {
36
38
  "check": "check-installed",
37
- "start": "npm run check && node index.js"
39
+ "start": "npm run check && node index.js",
40
+ "test": "npm run check && jest"
38
41
  }
39
42
  ```
40
43
 
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../index").cli();
2
+ require('../index').cli()
package/index.js CHANGED
@@ -1,49 +1,9 @@
1
- const { HELP, OPTIONS } = require('./lib/constants')
1
+ const { cli } = require('./lib/cli')
2
2
  const { checkEngines } = require('./lib/checkEngines')
3
3
  const { checkModules } = require('./lib/checkModules')
4
4
 
5
- /**
6
- * Get options from CLI arguments
7
- * @param {string[]} args - CLI arguments
8
- * @returns {typeof OPTIONS} - Options for the CLI with defaults
9
- */
10
- function getOptions (args) {
11
- const options = { ...OPTIONS }
12
-
13
- for (const arg of args) {
14
- if (arg.startsWith('--')) {
15
- const [key, value] = arg.slice(2).split('=')
16
- const keyCamelCase = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase())
17
-
18
- if (options[keyCamelCase] != null) {
19
- options[keyCamelCase] = value ?? true
20
- }
21
- }
22
- }
23
-
24
- return options
5
+ module.exports = {
6
+ cli,
7
+ checkEngines,
8
+ checkModules
25
9
  }
26
-
27
- /**
28
- * check-installed CLI entry point
29
- * @param {string[]} argv - CLI arguments
30
- */
31
- async function cli (argv = process.argv) {
32
- const args = argv.slice(2)
33
- const options = getOptions(args)
34
-
35
- if (options.help) {
36
- console.log(HELP)
37
- return
38
- }
39
-
40
- if (!options.skipEngines) {
41
- await checkEngines(options)
42
- }
43
-
44
- if (!options.skipModules) {
45
- await checkModules(options)
46
- }
47
- }
48
-
49
- exports.cli = cli
@@ -1,6 +1,6 @@
1
1
  const { spawn } = require('child_process')
2
- const { resolve } = require('path')
3
2
  const semver = require('semver')
3
+ const { OPTIONS } = require('./constants')
4
4
 
5
5
  /**
6
6
  * Get the version of an engine
@@ -51,11 +51,11 @@ async function checkEngineVersion (name, version) {
51
51
 
52
52
  /**
53
53
  * Checks engines in `package.json` are installed
54
- * @param {typeof import('./constants').OPTIONS} options - Options for the CLI
54
+ * @param {object} json - The `package.json` JSON object
55
+ * @param {Partial<typeof import('./constants').OPTIONS>} options - Options for the CLI
55
56
  */
56
- async function checkEngines (options) {
57
- const { showSuccess, showEngines } = options
58
- const json = require(resolve(process.cwd(), 'package.json'))
57
+ async function checkEngines (json = {}, options) {
58
+ const { showSuccess, showEngines } = { ...OPTIONS, ...options }
59
59
 
60
60
  // Check engines
61
61
  const engines = await Promise.all(
@@ -1,6 +1,7 @@
1
1
  const { resolve } = require('path')
2
2
  const fs = require('fs')
3
3
  const semver = require('semver')
4
+ const { OPTIONS } = require('./constants')
4
5
 
5
6
  /**
6
7
  * Regex used to extract the real name and version from an npm alias
@@ -53,11 +54,11 @@ function checkModuleVersion (name, version, optional) {
53
54
 
54
55
  /**
55
56
  * Checks node modules in `package.json` are installed
56
- * @param {typeof import('./constants').OPTIONS} options - Options for the CLI
57
+ * @param {object} json - The `package.json` JSON object
58
+ * @param {Partial<typeof import('./constants').OPTIONS>} options - Options for the CLI
57
59
  */
58
- async function checkModules (options) {
59
- const { showSuccess, showModules } = options
60
- const json = require(resolve(process.cwd(), 'package.json'))
60
+ async function checkModules (json = {}, options) {
61
+ const { showSuccess, showModules } = { ...OPTIONS, ...options }
61
62
 
62
63
  // Check modules
63
64
  const modules = [
package/lib/cli.js ADDED
@@ -0,0 +1,52 @@
1
+ const { resolve } = require('path')
2
+ const { HELP, OPTIONS } = require('./constants')
3
+ const { checkEngines } = require('./checkEngines')
4
+ const { checkModules } = require('./checkModules')
5
+
6
+ /**
7
+ * Get options from CLI arguments
8
+ * @param {string[]} args - CLI arguments
9
+ * @returns {typeof OPTIONS} - Options for the CLI with defaults
10
+ */
11
+ function getOptions (args) {
12
+ const options = {}
13
+
14
+ for (const arg of args) {
15
+ if (arg.startsWith('--')) {
16
+ const [key, value] = arg.slice(2).split('=')
17
+ const keyCamelCase = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase())
18
+
19
+ if (OPTIONS[keyCamelCase] != null) {
20
+ options[keyCamelCase] = value ?? true
21
+ }
22
+ }
23
+ }
24
+
25
+ return options
26
+ }
27
+
28
+ /**
29
+ * check-installed CLI entry point
30
+ * @param {string[]} argv - CLI arguments
31
+ */
32
+ async function cli (argv = process.argv) {
33
+ const json = require(resolve(process.cwd(), 'package.json'))
34
+ const options = getOptions(argv.slice(2))
35
+
36
+ if (options.help) {
37
+ console.log(HELP)
38
+ return
39
+ }
40
+
41
+ if (!options.skipEngines) {
42
+ await checkEngines(json, options)
43
+ }
44
+
45
+ if (!options.skipModules) {
46
+ await checkModules(json, options)
47
+ }
48
+ }
49
+
50
+ module.exports = {
51
+ cli
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "check-installed",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Minimal Node package to check that dependencies are installed ✅",
5
5
  "author": "Phillip Lanclos <check-installed@flippidippi.com>",
6
6
  "license": "Unlicense",
@@ -35,7 +35,10 @@
35
35
  "check": "./bin/check-installed",
36
36
  "lint": "standard",
37
37
  "lint:fix": "npm run lint -- --fix",
38
- "test": "npm run check",
38
+ "test": "npm run check && jest",
39
+ "test:coverage": "npm run test -- --coverage",
40
+ "test:watch": "npm run test -- --watch",
41
+ "test:ci": "npm run test:coverage -- --ci --reporters=default --reporters=jest-junit",
39
42
  "prepare": "husky install"
40
43
  },
41
44
  "dependencies": {
@@ -43,6 +46,25 @@
43
46
  },
44
47
  "devDependencies": {
45
48
  "husky": "^8.0.3",
49
+ "jest": "^29.7.0",
50
+ "jest-junit": "^16.0.0",
46
51
  "standard": "^17.1.0"
52
+ },
53
+ "standard": {
54
+ "env": [
55
+ "jest"
56
+ ]
57
+ },
58
+ "jest": {
59
+ "collectCoverageFrom": [
60
+ "index.js",
61
+ "lib/**/*.js"
62
+ ],
63
+ "coverageReporters": [
64
+ "html",
65
+ "text",
66
+ "text-summary",
67
+ "cobertura"
68
+ ]
47
69
  }
48
70
  }