check-installed 2.0.0 → 2.0.2

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.
@@ -8,7 +8,7 @@ const semver = require('semver')
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'], { shell: true })
12
12
 
13
13
  return new Promise((resolve) => {
14
14
  let result = ''
@@ -17,11 +17,13 @@ async function getEngineVersion (name) {
17
17
  result += data.toString()
18
18
  })
19
19
 
20
- spawned.stderr.on('data', () => {
20
+ spawned.stderr.on('data', (data) => {
21
+ console.error(data.toString())
21
22
  resolve('none')
22
23
  })
23
24
 
24
- spawned.on('error', () => {
25
+ spawned.on('error', (error) => {
26
+ console.error(error)
25
27
  resolve('none')
26
28
  })
27
29
 
@@ -11,20 +11,22 @@ const NPM_ALIAS_REGEX = /npm:(.+)@(.+)/
11
11
  * Checks that the given node module is installed and satisfies version (throws if not)
12
12
  * @param {string} name - The name of the node module to check
13
13
  * @param {string} version - The version to check against
14
- * @returns {[string, string, string]} - The [name, version, installed] installed and checked successfully
14
+ * @returns {[string, string, string, string]} - The [name, version, aliased, installed] installed and checked successfully
15
15
  */
16
16
  function checkModuleVersion (name, version, optional) {
17
17
  // Update with npm alias if needed ("my-react": "npm:react@^18.2.0")
18
+ let aliased = ''
18
19
  if (NPM_ALIAS_REGEX.test(version)) {
19
20
  const [, realName, realVersion] = version.match(NPM_ALIAS_REGEX)
20
21
 
21
- name = realName
22
+ aliased = `${realName} `
23
+ console.log('realnamel', realName)
22
24
  version = realVersion
23
25
  }
24
26
 
25
27
  // Ignore git URLs version
26
28
  if (/^(git.*:\/\/|github:|gitlab:|bitbucket:|gist:)/.test(version)) {
27
- return [name, version, 'skipped']
29
+ return [name, version, aliased, 'skipped']
28
30
  }
29
31
 
30
32
  const directoryPath = `node_modules/${name}`
@@ -33,9 +35,9 @@ function checkModuleVersion (name, version, optional) {
33
35
  // Check if module is installed and contains a `package.json` (throw if not optional)
34
36
  if (!fs.existsSync(directoryPath) || !fs.existsSync(jsonPath)) {
35
37
  if (optional) {
36
- return [name, version, 'none']
38
+ return [name, version, aliased, 'none']
37
39
  } else {
38
- throw new Error(`check-installed module failed for ${name}: installed none, expected ${version}`)
40
+ throw new Error(`check-installed module failed for ${name}: installed none, expected ${aliased}${version}`)
39
41
  }
40
42
  }
41
43
 
@@ -43,10 +45,10 @@ function checkModuleVersion (name, version, optional) {
43
45
  const installed = json.version
44
46
 
45
47
  if (version !== 'latest' && !semver.satisfies(json.version, version)) {
46
- throw new Error(`check-installed module failed for ${name}: installed ${installed}, expected ${version}`)
48
+ throw new Error(`check-installed module failed for ${name}: installed ${installed}, expected ${aliased}${version}`)
47
49
  }
48
50
 
49
- return [name, version, installed]
51
+ return [name, version, aliased, installed]
50
52
  }
51
53
 
52
54
  /**
@@ -72,8 +74,8 @@ async function checkModules (options) {
72
74
  }
73
75
 
74
76
  if (showModules) {
75
- for (const [name, version, installed] of modules) {
76
- console.log(`${name}: ${installed} (${version})`)
77
+ for (const [name, version, aliased, installed] of modules) {
78
+ console.log(`${name}: ${installed} (${aliased}${version})`)
77
79
  }
78
80
  }
79
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "check-installed",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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",