Skip to content

Commit

Permalink
fix: remove unused lib/npm relics (npm#6482)
Browse files Browse the repository at this point in the history
npm being an instance of EventEmitter and have a tmp public getter
were both unused. Since we do not have a public API we can make these
changes without it being a breaking change.
  • Loading branch information
lukekarrys authored May 22, 2023
1 parent fc52ca8 commit f3cfe12
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
14 changes: 1 addition & 13 deletions lib/npm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const EventEmitter = require('events')
const { resolve, dirname, join } = require('path')
const Config = require('@npmcli/config')
const chalk = require('chalk')
Expand All @@ -20,7 +19,7 @@ const updateNotifier = require('./utils/update-notifier.js')
const pkg = require('../package.json')
const { commands, aliases } = require('./utils/cmd-list.js')

class Npm extends EventEmitter {
class Npm {
static get version () {
return pkg.version
}
Expand All @@ -32,7 +31,6 @@ class Npm extends EventEmitter {
#command = null
#runId = new Date().toISOString().replace(/[.:]/g, '_')
#loadPromise = null
#tmpFolder = null
#title = 'npm'
#argvClean = []
#chalk = null
Expand Down Expand Up @@ -66,7 +64,6 @@ class Npm extends EventEmitter {
// prefix to `npmRoot` since that is the first dir it would encounter when
// doing implicit detection
constructor ({ npmRoot = dirname(__dirname), argv = [], excludeNpmCwd = false } = {}) {
super()
this.#npmRoot = npmRoot
this.config = new Config({
npmPath: this.#npmRoot,
Expand Down Expand Up @@ -462,15 +459,6 @@ class Npm extends EventEmitter {
return usage(this)
}

// XXX add logging to see if we actually use this
get tmp () {
if (!this.#tmpFolder) {
const rand = require('crypto').randomBytes(4).toString('hex')
this.#tmpFolder = `npm-${process.pid}-${rand}`
}
return resolve(this.config.get('tmp'), this.#tmpFolder)
}

// output to stdout in a progress bar compatible way
output (...msg) {
log.clearProgress()
Expand Down
4 changes: 0 additions & 4 deletions test/lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ t.test('npm.load', async t => {
mockGlobals(t, { process: { platform: 'win32' } })
t.equal(npm.bin, npm.globalBin, 'bin is global bin in windows mode')
t.equal(npm.dir, npm.globalDir, 'dir is global dir in windows mode')

const tmp = npm.tmp
t.match(tmp, String, 'npm.tmp is a string')
t.equal(tmp, npm.tmp, 'getter only generates it once')
})

await t.test('forceful loading', async t => {
Expand Down

0 comments on commit f3cfe12

Please sign in to comment.