Socket
Socket
Sign inDemoInstall

npm-cli-dir

Package Overview
Dependencies
10
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.0.2

LICENSE

26

index.js
'use strict';
const dirname = require('path').dirname;
const pathLib = require('path');
const dirname = pathLib.dirname;
const join = pathLib.join;
const parse = pathLib.parse;
const npmCliPath = require('npm-cli-path');
const resolveFromSilent = require('resolve-from').silent;
const getNpmCliDir = npmCliPath().then(result => {
do {
result = dirname(result);
} while (resolveFromSilent(result, './package.json') === null);
const path = parse(result);
const root = path.root;
result = path.dir;
return result;
do {
try {
require.resolve(join(result, 'package.json'));
break;
} catch (_) {
result = dirname(result);
}
} while (result !== root);
return result;
});
module.exports = function npmCliDir() {
return getNpmCliDir;
return getNpmCliDir;
};
{
"name": "npm-cli-dir",
"version": "2.0.1",
"description": "Resolve the directory path where npm CLI is installed",
"repository": "shinnn/npm-cli-dir",
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
"scripts": {
"pretest": "eslint --fix --config @shinnn/node index.js test.js",
"test": "node --throw-deprecation --track-heap-objects test.js",
"coverage": "node --throw-deprecation --track-heap-objects node_modules/.bin/istanbul cover test.js"
},
"license": "CC0-1.0",
"files": [
"index.js"
],
"keywords": [
"dir",
"directory",
"folder",
"path",
"npm",
"npm-cli",
"base",
"resolve",
"find",
"pinpoint",
"promise",
"promises",
"then",
"async",
"asynchronous",
"asynchronously"
],
"dependencies": {
"npm-cli-path": "^2.0.0",
"resolve-from": "^3.0.0"
},
"devDependencies": {
"@shinnn/eslint-config-node": "^3.0.0",
"eslint": "^3.19.0",
"execa": "^0.6.3",
"istanbul": "^0.4.5",
"tape": "^4.6.3"
}
"name": "npm-cli-dir",
"version": "2.0.2",
"description": "Resolve the directory path where npm CLI is installed",
"repository": "shinnn/npm-cli-dir",
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
"scripts": {
"pretest": "eslint --fix --format=codeframe index.js test.js",
"test": "nyc --reporter=html --reporter=text node test.js"
},
"license": "ISC",
"files": [
"index.js"
],
"keywords": [
"dir",
"directory",
"folder",
"path",
"npm",
"npm-cli",
"base",
"resolve",
"find",
"pinpoint",
"promise",
"promises",
"then",
"async",
"asynchronous",
"asynchronously"
],
"dependencies": {
"npm-cli-path": "^2.0.1"
},
"devDependencies": {
"@shinnn/eslint-config-node": "^5.0.0",
"eslint": "^4.16.0",
"execa": "^0.9.0",
"nyc": "^11.4.1",
"tape": "^4.8.0"
},
"eslintConfig": {
"extends": "@shinnn/node"
}
}
# npm-cli-dir
[![NPM version](https://img.shields.io/npm/v/npm-cli-dir.svg)](https://www.npmjs.com/package/npm-cli-dir)
[![npm version](https://img.shields.io/npm/v/npm-cli-dir.svg)](https://www.npmjs.com/package/npm-cli-dir)
[![Build Status](https://travis-ci.org/shinnn/npm-cli-dir.svg?branch=master)](https://travis-ci.org/shinnn/npm-cli-dir)

@@ -13,5 +13,5 @@ [![Build status](https://ci.appveyor.com/api/projects/status/e83hdqrnieckmm5c/branch/master?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/npm-cli-dir/branch/master)

npmCliDir().then(dir => {
dir; //=> '/usr/local/lib/node_modules/npm'
});
(async () => {
const dir = await npmCliDir(); //=> '/usr/local/lib/node_modules/npm'
})();
```

@@ -35,3 +35,3 @@

Return: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) instance
Return: `Promise<string>`

@@ -41,9 +41,9 @@ It resolves the base path of globally installed [npm](https://github.com/npm/npm) CLI.

```javascript
const fs = require('fs');
const {readFileSync} = require('fs');
const npmCliDir = require('npm-cli-dir');
npmCliDir().then(dir => {
fs.readdirSync(dir);
(async () => {
readFileSync(await npmCliDir());
//=> ['.mailmap', '.npmignore', '.travis.yml', 'AUTHORS', 'CHANGELOG.md', ...]
});
})();
```

@@ -53,2 +53,2 @@

[Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/deed)
[ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc