check-installed 3.2.0 → 4.0.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.
@@ -1,4 +1,4 @@
1
- const { spawn } = require('child_process')
1
+ const spawn = require('cross-spawn')
2
2
  const semver = require('semver')
3
3
  const { OPTIONS } = require('./constants')
4
4
 
@@ -8,14 +8,16 @@ const { OPTIONS } = require('./constants')
8
8
  * @returns {Promise<string>} - The version of the engine
9
9
  */
10
10
  async function getEngineVersion (name) {
11
- const spawned = spawn(name, ['--version'], { shell: true })
11
+ const spawned = spawn(name, ['--version'])
12
12
 
13
13
  return new Promise((resolve) => {
14
14
  let result = ''
15
15
 
16
- spawned.stdout.on('data', (data) => {
17
- result += data.toString()
18
- })
16
+ if (spawned.stdout != null) {
17
+ spawned.stdout.on('data', (data) => {
18
+ result += data.toString()
19
+ })
20
+ }
19
21
 
20
22
  spawned.on('close', (code) => {
21
23
  if (code !== 0) {
@@ -45,7 +47,7 @@ async function checkEngineVersion (name, version) {
45
47
 
46
48
  /**
47
49
  * Checks engines in `package.json` are installed
48
- * @param {object} json - The `package.json` JSON object
50
+ * @param {Record<string, any>} json - The `package.json` JSON object
49
51
  * @param {Partial<typeof import('./constants').OPTIONS>} options - Options for the CLI
50
52
  * @returns {Promise<void>} - Resolves when all engines are checked (throws on check fail)
51
53
  */
@@ -12,16 +12,19 @@ const NPM_ALIAS_REGEX = /npm:(.+)@(.+)/
12
12
  * Checks that the given node module is installed and satisfies version (throws if not)
13
13
  * @param {string} name - The name of the node module to check
14
14
  * @param {string} version - The version to check against
15
+ * @param {boolean} optional - Whether the module is optional
15
16
  * @returns {[string, string, string, string]} - The [name, version, aliased, installed] installed and checked successfully
16
17
  */
17
18
  function checkModuleVersion (name, version, optional) {
18
19
  // Update with npm alias if needed ("my-react": "npm:react@^18.2.0")
19
20
  let aliased = ''
20
21
  if (NPM_ALIAS_REGEX.test(version)) {
21
- const [, realName, realVersion] = version.match(NPM_ALIAS_REGEX)
22
-
23
- aliased = `${realName} `
24
- version = realVersion
22
+ const match = version.match(NPM_ALIAS_REGEX)
23
+ if (match != null) {
24
+ const [, realName, realVersion] = match
25
+ aliased = `${realName} `
26
+ version = realVersion
27
+ }
25
28
  }
26
29
 
27
30
  // Ignore git URLs version
@@ -52,7 +55,7 @@ function checkModuleVersion (name, version, optional) {
52
55
 
53
56
  /**
54
57
  * Checks node modules in `package.json` are installed
55
- * @param {object} json - The `package.json` JSON object
58
+ * @param {Record<string, any>} json - The `package.json` JSON object
56
59
  * @param {Partial<typeof import('./constants').OPTIONS>} options - Options for the CLI
57
60
  * @returns {Promise<void>} - Resolves when all modules are checked (throws on check fail)
58
61
  */
package/lib/getOptions.js CHANGED
@@ -6,12 +6,14 @@ const { OPTIONS } = require('./constants')
6
6
  * @returns {Partial<typeof OPTIONS>} - Options for the CLI with defaults
7
7
  */
8
8
  function getOptions (args = []) {
9
+ /** @type {Record<string, boolean | string>} */
9
10
  const options = {}
10
11
 
11
12
  for (const arg of args) {
12
13
  if (arg.startsWith('--')) {
13
14
  const [key, value] = arg.slice(2).split('=')
14
15
  const keyCamelCase = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase())
16
+ // @ts-ignore
15
17
  const option = OPTIONS[keyCamelCase]
16
18
 
17
19
  // Only set if the option is defined in `OPTIONS`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "check-installed",
3
- "version": "3.2.0",
3
+ "version": "4.0.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",
@@ -32,7 +32,7 @@
32
32
  "npm": ">=6"
33
33
  },
34
34
  "scripts": {
35
- "check": "./bin/check-installed --show-engines",
35
+ "check": "./bin/check-installed --show-engines --show-modules",
36
36
  "lint": "standard",
37
37
  "lint:fix": "npm run lint -- --fix",
38
38
  "compile": "tsc",
@@ -43,15 +43,18 @@
43
43
  "prepare": "husky"
44
44
  },
45
45
  "dependencies": {
46
- "semver": "^7.7.2"
46
+ "cross-spawn": "^7.0.6",
47
+ "semver": "^7.7.4"
47
48
  },
48
49
  "devDependencies": {
50
+ "@types/cross-spawn": "^6.0.6",
49
51
  "@types/jest": "^30.0.0",
52
+ "@types/semver": "^7.7.1",
50
53
  "husky": "^9.1.7",
51
- "jest": "^30.0.5",
54
+ "jest": "^30.3.0",
52
55
  "jest-junit": "^16.0.0",
53
56
  "standard": "^17.1.2",
54
- "typescript": "^5.9.2"
57
+ "typescript": "^6.0.2"
55
58
  },
56
59
  "standard": {
57
60
  "env": [