check-installed 3.1.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.
- package/lib/checkEngines.js +8 -6
- package/lib/checkModules.js +8 -5
- package/lib/getOptions.js +2 -0
- package/package.json +12 -9
package/lib/checkEngines.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
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']
|
|
11
|
+
const spawned = spawn(name, ['--version'])
|
|
12
12
|
|
|
13
13
|
return new Promise((resolve) => {
|
|
14
14
|
let result = ''
|
|
15
15
|
|
|
16
|
-
spawned.stdout
|
|
17
|
-
|
|
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 {
|
|
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
|
*/
|
package/lib/checkModules.js
CHANGED
|
@@ -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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 {
|
|
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
|
+
"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",
|
|
@@ -40,18 +40,21 @@
|
|
|
40
40
|
"test:coverage": "npm run test -- --coverage",
|
|
41
41
|
"test:watch": "npm run test -- --watch",
|
|
42
42
|
"test:ci": "npm run test:coverage -- --ci --reporters=default --reporters=jest-junit",
|
|
43
|
-
"prepare": "husky
|
|
43
|
+
"prepare": "husky"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"
|
|
46
|
+
"cross-spawn": "^7.0.6",
|
|
47
|
+
"semver": "^7.7.4"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"@types/
|
|
50
|
-
"
|
|
51
|
-
"
|
|
50
|
+
"@types/cross-spawn": "^6.0.6",
|
|
51
|
+
"@types/jest": "^30.0.0",
|
|
52
|
+
"@types/semver": "^7.7.1",
|
|
53
|
+
"husky": "^9.1.7",
|
|
54
|
+
"jest": "^30.3.0",
|
|
52
55
|
"jest-junit": "^16.0.0",
|
|
53
|
-
"standard": "^17.1.
|
|
54
|
-
"typescript": "^
|
|
56
|
+
"standard": "^17.1.2",
|
|
57
|
+
"typescript": "^6.0.2"
|
|
55
58
|
},
|
|
56
59
|
"standard": {
|
|
57
60
|
"env": [
|