Skip to content

Commit 55ab38c

Browse files
wraithgarruyadorno
authored andcommitted
fix(doctor): allow for missing local bin and node_modules
1 parent 1c182e1 commit 55ab38c

File tree

3 files changed

+169
-62
lines changed

3 files changed

+169
-62
lines changed

lib/commands/doctor.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const semver = require('semver')
1010
const { promisify } = require('util')
1111
const log = require('../utils/log-shim.js')
1212
const ansiTrim = require('../utils/ansi-trim.js')
13-
const isWindows = require('../utils/is-windows.js')
1413
const ping = require('../utils/ping.js')
1514
const {
1615
registry: { default: defaultRegistry },
@@ -55,32 +54,36 @@ class Doctor extends BaseCommand {
5554
['node -v', 'getLatestNodejsVersion', []],
5655
['npm config get registry', 'checkNpmRegistry', []],
5756
['which git', 'getGitPath', []],
58-
...(isWindows
57+
...(process.platform === 'win32'
5958
? []
6059
: [
61-
['Perms check on cached files', 'checkFilesPermission', [this.npm.cache, true, R_OK]],
6260
[
61+
'Perms check on cached files',
62+
'checkFilesPermission',
63+
[this.npm.cache, true, R_OK],
64+
], [
6365
'Perms check on local node_modules',
6466
'checkFilesPermission',
65-
[this.npm.localDir, true],
66-
],
67-
[
67+
[this.npm.localDir, true, R_OK | W_OK, true],
68+
], [
6869
'Perms check on global node_modules',
6970
'checkFilesPermission',
70-
[this.npm.globalDir, false],
71-
],
72-
[
71+
[this.npm.globalDir, false, R_OK],
72+
], [
7373
'Perms check on local bin folder',
7474
'checkFilesPermission',
75-
[this.npm.localBin, false, R_OK | W_OK | X_OK],
76-
],
77-
[
75+
[this.npm.localBin, false, R_OK | W_OK | X_OK, true],
76+
], [
7877
'Perms check on global bin folder',
7978
'checkFilesPermission',
8079
[this.npm.globalBin, false, X_OK],
8180
],
8281
]),
83-
['Verify cache contents', 'verifyCachedFiles', [this.npm.flatOptions.cache]],
82+
[
83+
'Verify cache contents',
84+
'verifyCachedFiles',
85+
[this.npm.flatOptions.cache],
86+
],
8487
// TODO:
8588
// - ensure arborist.loadActual() runs without errors and no invalid edges
8689
// - ensure package-lock.json matches loadActual()
@@ -202,11 +205,7 @@ class Doctor extends BaseCommand {
202205
}
203206
}
204207

205-
async checkFilesPermission (root, shouldOwn, mask = null) {
206-
if (mask === null) {
207-
mask = shouldOwn ? R_OK | W_OK : R_OK
208-
}
209-
208+
async checkFilesPermission (root, shouldOwn, mask, missingOk) {
210209
let ok = true
211210

212211
const tracker = log.newItem(root, 1)
@@ -218,8 +217,11 @@ class Doctor extends BaseCommand {
218217
for (const f of files) {
219218
tracker.silly('checkFilesPermission', f.substr(root.length + 1))
220219
const st = await lstat(f).catch(er => {
221-
ok = false
222-
tracker.warn('checkFilesPermission', 'error getting info for ' + f)
220+
// if it can't be missing, or if it can and the error wasn't that it was missing
221+
if (!missingOk || er.code !== 'ENOENT') {
222+
ok = false
223+
tracker.warn('checkFilesPermission', 'error getting info for ' + f)
224+
}
223225
})
224226

225227
tracker.completeWork(1)

tap-snapshots/test/lib/commands/doctor.js.test.cjs

+58
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,64 @@ Perms check on global bin folder not ok Check the permissions of files in {C
826826
Verify cache contents ok verified 0 tarballs
827827
`
828828

829+
exports[`test/lib/commands/doctor.js TAP missing local node_modules > logs 1`] = `
830+
Object {
831+
"error": Array [],
832+
"info": Array [
833+
Array [
834+
"Running checkup",
835+
],
836+
Array [
837+
"checkPing",
838+
"Pinging registry",
839+
],
840+
Array [
841+
"getLatestNpmVersion",
842+
"Getting npm package information",
843+
],
844+
Array [
845+
"getLatestNodejsVersion",
846+
"Getting Node.js release information",
847+
],
848+
Array [
849+
"getGitPath",
850+
"Finding git in your PATH",
851+
],
852+
Array [
853+
"verifyCachedFiles",
854+
"Verifying the npm cache",
855+
],
856+
Array [
857+
"verifyCachedFiles",
858+
String(
859+
Verification complete. Stats: {
860+
"badContentCount": 0,
861+
"reclaimedCount": 0,
862+
"missingContent": 0,
863+
"verifiedContent": 0
864+
}
865+
),
866+
],
867+
],
868+
"warn": Array [],
869+
}
870+
`
871+
872+
exports[`test/lib/commands/doctor.js TAP missing local node_modules > missing local node_modules 1`] = `
873+
Check Value Recommendation/Notes
874+
npm ping ok
875+
npm -v ok current: v1.0.0, latest: v1.0.0
876+
node -v ok current: v1.0.0, recommended: v1.0.0
877+
npm config get registry ok using default registry (https://registry.npmjs.org/)
878+
which git ok /path/to/git
879+
Perms check on cached files ok
880+
Perms check on local node_modules ok
881+
Perms check on global node_modules ok
882+
Perms check on local bin folder ok
883+
Perms check on global bin folder ok
884+
Verify cache contents ok verified 0 tarballs
885+
`
886+
829887
exports[`test/lib/commands/doctor.js TAP node out of date - current > logs 1`] = `
830888
Object {
831889
"error": Array [],

0 commit comments

Comments
 (0)