Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddee7ea
commit 0aae4d6
Showing
5 changed files
with
88 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
declare namespace globalDirectories { | ||
interface GlobalDirectories { | ||
/** | ||
Directory with globally installed packages. | ||
Equivalent to `npm root --global`. | ||
*/ | ||
readonly packages: string; | ||
|
||
/** | ||
Directory with globally installed binaries. | ||
Equivalent to `npm bin --global`. | ||
*/ | ||
readonly binaries: string; | ||
|
||
/** | ||
Directory with directories for packages and binaries. You probably want either of the above. | ||
Equivalent to `npm prefix --global`. | ||
*/ | ||
readonly prefix: string; | ||
} | ||
} | ||
|
||
declare const globalDirectories: { | ||
/** | ||
Get the directory of globally installed packages and binaries. | ||
@example | ||
``` | ||
import * as globalDirectories from 'global-dirs'; | ||
console.log(globalDirectories.npm.prefix); | ||
//=> '/usr/local' | ||
console.log(globalDirectories.npm.packages); | ||
//=> '/usr/local/lib/node_modules' | ||
``` | ||
*/ | ||
readonly npm: globalDirectories.GlobalDirectories; | ||
|
||
/** | ||
Get the directory of globally installed packages and binaries. | ||
@example | ||
``` | ||
import * as globalDirectories from 'global-dirs'; | ||
console.log(globalDirectories.npm.binaries); | ||
//=> '/usr/local/bin' | ||
console.log(globalDirectories.yarn.packages); | ||
//=> '/Users/sindresorhus/.config/yarn/global/node_modules' | ||
``` | ||
*/ | ||
readonly yarn: globalDirectories.GlobalDirectories; | ||
} | ||
|
||
export = globalDirectories; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {expectType} from 'tsd'; | ||
import globalDirectories = require('.'); | ||
|
||
expectType<string>(globalDirectories.npm.prefix); | ||
expectType<string>(globalDirectories.npm.packages); | ||
expectType<string>(globalDirectories.npm.binaries); | ||
expectType<string>(globalDirectories.yarn.prefix); | ||
expectType<string>(globalDirectories.yarn.packages); | ||
expectType<string>(globalDirectories.yarn.binaries); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import test from 'ava'; | ||
import execa from 'execa'; | ||
import globalDirs from '.'; | ||
import globalDirectories from '.'; | ||
|
||
console.log(globalDirs); | ||
console.log(globalDirectories); | ||
|
||
const npm = arguments_ => execa.stdout('npm', arguments_); | ||
|
||
test('npm.prefix', async t => { | ||
t.is(globalDirs.npm.prefix, await npm(['prefix', '--global'])); | ||
t.is(globalDirectories.npm.prefix, await npm(['prefix', '--global'])); | ||
}); | ||
|
||
test('npm.packages', async t => { | ||
t.is(globalDirs.npm.packages, await npm(['root', '--global'])); | ||
t.is(globalDirectories.npm.packages, await npm(['root', '--global'])); | ||
}); | ||
|
||
test('npm.binaries', async t => { | ||
t.is(globalDirs.npm.binaries, await npm(['bin', '--global'])); | ||
t.is(globalDirectories.npm.binaries, await npm(['bin', '--global'])); | ||
}); | ||
|
||
test('yarn', async t => { | ||
await npm(['install', '--global', 'yarn']); | ||
t.truthy(globalDirs.yarn); | ||
t.truthy(globalDirs.yarn.prefix); | ||
t.truthy(globalDirs.yarn.packages); | ||
t.truthy(globalDirs.yarn.binaries); | ||
t.truthy(globalDirectories.yarn); | ||
t.truthy(globalDirectories.yarn.prefix); | ||
t.truthy(globalDirectories.yarn.packages); | ||
t.truthy(globalDirectories.yarn.binaries); | ||
}); |