Skip to content

Commit 16c419b

Browse files
committed
minor refactor
1 parent 49684bd commit 16c419b

10 files changed

+132
-168
lines changed

.editorconfig

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
# http://editorconfig.org/
12
root = true
23

34
[*]
4-
indent_style = space
5-
end_of_line = lf
65
charset = utf-8
6+
end_of_line = lf
77
indent_size = 2
8-
trim_trailing_whitespace = true
8+
indent_style = space
99
insert_final_newline = true
10+
trim_trailing_whitespace = true
1011

11-
[{**/{actual,fixtures,expected,templates}/**,*.md}]
12+
[*.md]
1213
trim_trailing_whitespace = false
13-
insert_final_newline = false

.eslintrc.json

+13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
{
2+
"extends": [
3+
"eslint:recommended"
4+
],
5+
26
"env": {
37
"browser": false,
48
"es6": true,
59
"node": true,
610
"mocha": true
711
},
812

13+
"parserOptions":{
14+
"ecmaVersion": 9,
15+
"sourceType": "module",
16+
"ecmaFeatures": {
17+
"modules": true,
18+
"experimentalObjectRestSpread": true
19+
}
20+
},
21+
922
"globals": {
1023
"document": false,
1124
"navigator": false,

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ sudo: false
22
os:
33
- linux
44
- osx
5+
- windows
56
language: node_js
67
node_js:
78
- node
9+
- '11'
10+
- '10'
11+
- '9'
812
- '8'
913
- '7'
1014
- '6'
11-
- '5'
12-
- '4'
13-
- '0.12'
14-
- '0.10'

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2017, Jon Schlinkert.
3+
Copyright (c) 2015-present, Jon Schlinkert.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
21+
THE SOFTWARE.

README.md

+40-26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
> Get the npm global path prefix.
44
5+
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6+
57
## Install
68

79
Install with [npm](https://www.npmjs.com/):
@@ -21,29 +23,26 @@ var prefix = require('global-prefix');
2123

2224
## About
2325

24-
### Related projects
26+
<details>
27+
<summary><strong>Contributing</strong></summary>
2528

26-
* [global-modules](https://www.npmjs.com/package/global-modules): The directory used by npm for globally installed npm modules. | [homepage](https://github.com/jonschlinkert/global-modules "The directory used by npm for globally installed npm modules.")
27-
* [global-paths](https://www.npmjs.com/package/global-paths): Returns an array of unique "global" directories based on the user's platform and environment. The… [more](https://github.com/jonschlinkert/global-paths) | [homepage](https://github.com/jonschlinkert/global-paths "Returns an array of unique "global" directories based on the user's platform and environment. The resulting paths can be used for doing lookups for generators or other globally installed npm packages. Node.js / JavaScript.")
29+
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
2830

29-
### Contributing
31+
</details>
3032

31-
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
33+
<details>
34+
<summary><strong>Running Tests</strong></summary>
3235

33-
### Contributors
36+
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
3437

35-
| **Commits** | **Contributor** |
36-
| --- | --- |
37-
| 16 | [jonschlinkert](https://github.com/jonschlinkert) |
38-
| 15 | [doowb](https://github.com/doowb) |
39-
| 1 | [rmbaad](https://github.com/rmbaad) |
40-
| 1 | [avengerpenguin](https://github.com/avengerpenguin) |
41-
| 1 | [jason-chang](https://github.com/jason-chang) |
42-
| 1 | [jorrit](https://github.com/jorrit) |
43-
| 1 | [mathiasvr](https://github.com/mathiasvr) |
44-
| 1 | [tunnckoCore](https://github.com/tunnckoCore) |
38+
```sh
39+
$ npm install && npm test
40+
```
41+
42+
</details>
4543

46-
### Building docs
44+
<details>
45+
<summary><strong>Building docs</strong></summary>
4746

4847
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
4948

@@ -53,26 +52,41 @@ To generate the readme, run the following command:
5352
$ npm install -g verbose/verb#dev verb-generate-readme && verb
5453
```
5554

56-
### Running tests
55+
</details>
5756

58-
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
57+
### Related projects
5958

60-
```sh
61-
$ npm install && npm test
62-
```
59+
You might also be interested in these projects:
60+
61+
* [global-modules](https://www.npmjs.com/package/global-modules): The directory used by npm for globally installed npm modules. | [homepage](https://github.com/jonschlinkert/global-modules "The directory used by npm for globally installed npm modules.")
62+
* [global-paths](https://www.npmjs.com/package/global-paths): Returns an array of unique "global" directories based on the user's platform and environment. The… [more](https://github.com/jonschlinkert/global-paths) | [homepage](https://github.com/jonschlinkert/global-paths "Returns an array of unique "global" directories based on the user's platform and environment. The resulting paths can be used for doing lookups for generators or other globally installed npm packages. Node.js / JavaScript.")
63+
64+
### Contributors
65+
66+
| **Commits** | **Contributor** |
67+
| --- | --- |
68+
| 23 | [jonschlinkert](https://github.com/jonschlinkert) |
69+
| 15 | [doowb](https://github.com/doowb) |
70+
| 2 | [phated](https://github.com/phated) |
71+
| 1 | [rmbaad](https://github.com/rmbaad) |
72+
| 1 | [avengerpenguin](https://github.com/avengerpenguin) |
73+
| 1 | [jorrit](https://github.com/jorrit) |
74+
| 1 | [mathiasvr](https://github.com/mathiasvr) |
75+
| 1 | [tunnckoCore](https://github.com/tunnckoCore) |
6376

6477
### Author
6578

6679
**Jon Schlinkert**
6780

68-
* [github/jonschlinkert](https://github.com/jonschlinkert)
69-
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
81+
* [GitHub Profile](https://github.com/jonschlinkert)
82+
* [Twitter Profile](https://twitter.com/jonschlinkert)
83+
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
7084

7185
### License
7286

73-
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
87+
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
7488
Released under the [MIT License](LICENSE).
7589

7690
***
7791

78-
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 28, 2017._
92+
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 11, 2018._

appveyor.yml

-27
This file was deleted.

index.js

+47-58
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,85 @@
11
/*!
22
* global-prefix <https://github.com/jonschlinkert/global-prefix>
33
*
4-
* Copyright (c) 2015-2017 Jon Schlinkert.
4+
* Copyright (c) 2015-present Jon Schlinkert.
55
* Licensed under the MIT license.
66
*/
77

88
'use strict';
99

10-
var fs = require('fs');
11-
var path = require('path');
12-
var expand = require('expand-tilde');
13-
var homedir = require('homedir-polyfill');
14-
var ini = require('ini');
15-
var prefix;
16-
17-
function getPrefix() {
18-
if (process.env.PREFIX) {
19-
prefix = process.env.PREFIX;
20-
} else {
21-
// Start by checking if the global prefix is set by the user
22-
var home = homedir();
23-
if (home) {
24-
// homedir() returns undefined if $HOME not set; path.resolve requires strings
25-
var userConfig = path.resolve(home, '.npmrc');
26-
prefix = tryConfigPath(userConfig);
27-
}
10+
const fs = require('fs');
11+
const os = require('os');
12+
const path = require('path');
13+
const ini = require('ini');
14+
let prefix;
2815

29-
if (!prefix) {
30-
// Otherwise find the path of npm
31-
var npm = tryNpmPath();
32-
if (npm) {
33-
// Check the built-in npm config file
34-
var builtinConfig = path.resolve(npm, '..', '..', 'npmrc');
35-
prefix = tryConfigPath(builtinConfig);
36-
37-
if (prefix) {
38-
// Now the global npm config can also be checked.
39-
var globalConfig = path.resolve(prefix, 'etc', 'npmrc');
40-
prefix = tryConfigPath(globalConfig) || prefix;
41-
}
42-
}
43-
44-
if (!prefix) fallback();
45-
}
16+
const getPrefix = () => {
17+
if (process.env.PREFIX) return process.env.PREFIX;
18+
if (prefix) return prefix;
19+
20+
// Start by checking if the global prefix is set by the user
21+
let home = os.homedir();
22+
23+
// os.homedir() returns undefined if $HOME is not set; path.resolve requires strings
24+
if (home) {
25+
prefix = tryConfigPath(path.resolve(home, '.npmrc'));
4626
}
4727

4828
if (prefix) {
49-
return expand(prefix);
29+
return prefix;
5030
}
51-
}
5231

53-
function fallback() {
54-
var isWindows = require('is-windows');
55-
if (isWindows()) {
32+
// Otherwise find the path of npm
33+
let npm = tryNpmPath();
34+
if (npm) {
35+
// Check the built-in npm config file
36+
prefix = tryConfigPath(path.resolve(npm, '..', '..', 'npmrc'));
37+
38+
if (prefix) {
39+
// Now the global npm config can also be checked.
40+
prefix = tryConfigPath(path.resolve(prefix, 'etc', 'npmrc')) || prefix;
41+
}
42+
}
43+
44+
if (!prefix) {
45+
let { APPDATA, DESTDIR, OSTYPE } = process.env;
46+
5647
// c:\node\node.exe --> prefix=c:\node\
57-
prefix = process.env.APPDATA
58-
? path.join(process.env.APPDATA, 'npm')
59-
: path.dirname(process.execPath);
60-
} else {
48+
if (process.platform === 'win32' || OSTYPE === 'msys' || OSTYPE === 'cygwin') {
49+
prefix = APPDATA ? path.join(APPDATA, 'npm') : path.dirname(process.execPath);
50+
return prefix;
51+
}
52+
6153
// /usr/local/bin/node --> prefix=/usr/local
6254
prefix = path.dirname(path.dirname(process.execPath));
6355

6456
// destdir only is respected on Unix
65-
if (process.env.DESTDIR) {
66-
prefix = path.join(process.env.DESTDIR, prefix);
57+
if (DESTDIR) {
58+
prefix = path.join(DESTDIR, prefix);
6759
}
6860
}
61+
62+
return prefix;
6963
}
7064

7165
function tryNpmPath() {
7266
try {
7367
return fs.realpathSync(require('which').sync('npm'));
74-
} catch (err) {}
75-
return null;
68+
} catch (err) { /* do nothing */ }
7669
}
7770

7871
function tryConfigPath(configPath) {
7972
try {
80-
var data = fs.readFileSync(configPath, 'utf-8');
81-
var config = ini.parse(data);
82-
if (config.prefix) return config.prefix;
83-
} catch (err) {}
84-
return null;
73+
return ini.parse(fs.readFileSync(configPath, 'utf-8')).prefix;
74+
} catch (err) { /* do nothing */ }
8575
}
8676

8777
/**
8878
* Expose `prefix`
8979
*/
9080

91-
Object.defineProperty(module, 'exports', {
92-
enumerable: true,
93-
get: function() {
94-
return prefix || (prefix = getPrefix());
81+
Reflect.defineProperty(module, 'exports', {
82+
get() {
83+
return getPrefix();
9584
}
9685
});

0 commit comments

Comments
 (0)