Skip to content

Commit

Permalink
refactor: replace osenv with native node.js os module
Browse files Browse the repository at this point in the history
PR-URL: npm/pacote#31
Credit: @fraxken
Close: zkat#31
Reviewed-by: @isaacs
  • Loading branch information
fraxken authored and isaacs committed Mar 12, 2020
1 parent dad33cf commit e364c88
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
1 change: 0 additions & 1 deletion lib/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const procLog = require('./util/proc-log.js')
const retry = require('promise-retry')
const fsm = require('fs-minipass')
const cacache = require('cacache')
const osenv = require('osenv')
const isPackageBin = require('./util/is-package-bin.js')
const getContents = require('@npmcli/installed-package-contents')

Expand Down
6 changes: 3 additions & 3 deletions lib/util/cache-dir.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const osenv = require('osenv')
const os = require('os')
const {resolve} = require('path')

module.exports = (fakePlatform = false) => {
const temp = osenv.tmpdir()
const temp = os.tmpdir()
const uidOrPid = process.getuid ? process.getuid() : process.pid
const home = osenv.home() || resolve(temp, 'npm-' + uidOrPid)
const home = os.homedir() || resolve(temp, 'npm-' + uidOrPid)
const platform = fakePlatform || process.platform
const cacheExtra = platform === 'win32' ? 'npm-cache' : '.npm'
const cacheRoot = (platform === 'win32' && process.env.APPDATA) || home
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"npm-packlist": "^2.1.0",
"npm-pick-manifest": "^6.0.0",
"npm-registry-fetch": "^8.0.0",
"osenv": "^0.1.5",
"promise-inflight": "^1.0.1",
"promise-retry": "^1.1.1",
"read-package-json-fast": "^1.1.3",
Expand Down
8 changes: 4 additions & 4 deletions test/util/cache-dir.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const t = require('tap')
const osenv = require('osenv')
const os = require('os')

osenv.tmpdir = () => '/tmp'
osenv.home = () => '/home/isaacs'
os.tmpdir = () => '/tmp'
os.homedir = () => '/home/isaacs'
const path = require('path')
path.resolve = path.posix.resolve
process.getuid = () => 69420
Expand All @@ -21,7 +21,7 @@ t.ok(cacheDir(), 'a cache dir is ok')
t.equal(cacheDir(posix), '/home/isaacs/.npm')
t.equal(cacheDir(windows), '/home/isaacs/npm-cache')

osenv.home = () => null
os.homedir = () => null
t.equal(cacheDir(posix), '/tmp/npm-69420/.npm')
t.equal(cacheDir(windows), '/tmp/npm-69420/npm-cache')

Expand Down

0 comments on commit e364c88

Please sign in to comment.