dylang / npm-check

Check for outdated, incorrect, and unused dependencies.
https://www.npmjs.com/package/npm-check
MIT License
6.58k stars 236 forks source link

CWD has home path twice #309

Open lantrix opened 6 years ago

lantrix commented 6 years ago

Running npm-check globally is giving me errors that all the packages are missing. They are not, and npm can install/update them fine, it is just npm-check that is borking the cwd.

Also, I have a custom NODE_PATH set in my bash profile like:

export NPM_PACKAGES="${HOME}/.npm-packages"
export NODE_PATH="${NPM_PACKAGES}/lib/node_modules:${NODE_PATH}"
export PATH="${NPM_PACKAGES}/bin:$PATH"

running a normal npm-check update with global options I get the modules as all missing, and I see the global path is correct /Users/lantrix/.npm-packages/lib/node_modules:

$ npm-check -ug
warning: Using the first of multiple paths specified in NODE_PATH
The global path you are searching is: /Users/lantrix/.npm-packages/lib/node_modules
? Choose which packages to update. (Press <space> to select)

 Missing. You probably want these.
❯◯ npm-check missing                5.9.0  https://github.com/dylang/npm-check
 ◯ npm-install-missing missing      0.1.4  https://github.com/AlexCline/npm-install-missing
 ◯ npm missing                      6.4.1  https://docs.npmjs.com/

 Minor Update New backwards-compatible features.
 ◯ eslint missing      5.2.0   ❯  5.6.1   https://eslint.org
 ◯ serverless missing  1.28.0  ❯  1.32.0  https://github.com/serverless/serverless#readme

 Space to select. Enter to start upgrading. Control-C to cancel.

But when I look at the debug output, the cwd is wrong. It has ${HOME} in the path as well as the existing home path, yielding a working directory of:

/Users/lantrix/${HOME}/.npm-packages/lib/node_modules

$ npm-check -ug --debug
[npm-check] debug
cli.flags { update: true,
  u: true,
  updateAll: false,
  y: false,
  global: true,
  g: true,
  skipUnused: false,
  s: false,
  production: false,
  p: false,
  devOnly: false,
  d: false,
  saveExact: false,
  E: false,
  color: false,
  emoji: true,
  spinner: true,
  debug: true,
  dir: '/Users/lantrix' }
===============================
[npm-check] debug
cli.input []
===============================
[npm-check] debug
set key spinner to value true
===============================
[npm-check] debug
set key ignore to value undefined
===============================
warning: Using the first of multiple paths specified in NODE_PATH
The global path you are searching is: /Users/lantrix/.npm-packages/lib/node_modules
[npm-check] debug
set key cwd to value /Users/lantrix/${HOME}/.npm-packages/lib/node_modules
===============================
[npm-check] debug
set key globalPackages to value { eslint: '5.2.0',
  'npm-check': '5.9.0',
  'npm-install-missing': '0.1.4',
  npm: '6.4.1',
  serverless: '1.28.0' }
===============================
[npm-check] debug
set key unusedDependencies to value [ undefined, undefined ]
===============================
[npm-check] debug
set key missingFromPackageJson to value {}

This ultimately means that the package.json can't be found for the modules. (I removed all but one of the failed modules to trim the debug output)

===============================
[npm-check] debug
current state { update: true,
  updateAll: false,
  global: true,
  cwd: '/Users/lantrix/${HOME}/.npm-packages/lib/node_modules',
  skipUnused: false,
  ignoreDev: false,
  devOnly: false,
  forceColor: false,
  saveExact: false,
  specials: undefined,
  debug: true,
  emoji: true,
  spinner: true,
  installer: 'npm',
  ignore: undefined,
  globalPackages:
   { eslint: '5.2.0',
     'npm-check': '5.9.0',
     'npm-install-missing': '0.1.4',
     npm: '6.4.1',
     serverless: '1.28.0' },
  cwdPackageJson: { devDependencies: {}, dependencies: {} },
  packages:
   [ { moduleName: 'eslint',
       homepage: 'https://eslint.org',
       regError: undefined,
       pkgError: Error: A package.json was not found at /Users/lantrix/${HOME}/.npm-packages/lib/node_modules/eslint/package.json
    at readPackageJson (/Users/lantrix/.npm-packages/lib/node_modules/npm-check/lib/in/read-package-json.js:12:21)
    at createPackageSummary (/Users/lantrix/.npm-packages/lib/node_modules/npm-check/lib/in/create-package-summary.js:18:31)
    at allDependenciesIncludingMissing.map.moduleName (/Users/lantrix/.npm-packages/lib/node_modules/npm-check/lib/in/index.js:38:32)
    at Array.map (<anonymous>)
    at /Users/lantrix/.npm-packages/lib/node_modules/npm-check/lib/in/index.js:38:14
    at Generator.next (<anonymous>)
    at onFulfilled (/Users/lantrix/.npm-packages/lib/node_modules/npm-check/node_modules/co/index.js:65:19)
    at <anonymous>,
       latest: '5.6.1',
       installed: '5.2.0',
       isInstalled: false,
       notInstalled: true,
       packageWanted: '5.2.0',
       packageJson: '5.2.0',
       notInPackageJson: undefined,
       devDependency: false,
       usedInScripts: undefined,
       mismatch: false,
       semverValid: '5.2.0',
       easyUpgrade: false,
       bump: 'minor',
       unused: false } ],
  unusedDependencies: [ undefined, undefined ],
  missingFromPackageJson: {} }
  ===============================

I can't find why this is putting ${HOME} in the working direction in addition to the existing home /Users/lantrix/

$ echo $HOME
/Users/lantrix
kradalby commented 5 years ago

Have the same issue.