Skip to content

Commit f3cfe12

Browse files
authoredMay 22, 2023
fix: remove unused lib/npm relics (#6482)
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.
1 parent fc52ca8 commit f3cfe12

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed
 

‎lib/npm.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const EventEmitter = require('events')
21
const { resolve, dirname, join } = require('path')
32
const Config = require('@npmcli/config')
43
const chalk = require('chalk')
@@ -20,7 +19,7 @@ const updateNotifier = require('./utils/update-notifier.js')
2019
const pkg = require('../package.json')
2120
const { commands, aliases } = require('./utils/cmd-list.js')
2221

23-
class Npm extends EventEmitter {
22+
class Npm {
2423
static get version () {
2524
return pkg.version
2625
}
@@ -32,7 +31,6 @@ class Npm extends EventEmitter {
3231
#command = null
3332
#runId = new Date().toISOString().replace(/[.:]/g, '_')
3433
#loadPromise = null
35-
#tmpFolder = null
3634
#title = 'npm'
3735
#argvClean = []
3836
#chalk = null
@@ -66,7 +64,6 @@ class Npm extends EventEmitter {
6664
// prefix to `npmRoot` since that is the first dir it would encounter when
6765
// doing implicit detection
6866
constructor ({ npmRoot = dirname(__dirname), argv = [], excludeNpmCwd = false } = {}) {
69-
super()
7067
this.#npmRoot = npmRoot
7168
this.config = new Config({
7269
npmPath: this.#npmRoot,
@@ -462,15 +459,6 @@ class Npm extends EventEmitter {
462459
return usage(this)
463460
}
464461

465-
// XXX add logging to see if we actually use this
466-
get tmp () {
467-
if (!this.#tmpFolder) {
468-
const rand = require('crypto').randomBytes(4).toString('hex')
469-
this.#tmpFolder = `npm-${process.pid}-${rand}`
470-
}
471-
return resolve(this.config.get('tmp'), this.#tmpFolder)
472-
}
473-
474462
// output to stdout in a progress bar compatible way
475463
output (...msg) {
476464
log.clearProgress()

‎test/lib/npm.js

-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ t.test('npm.load', async t => {
105105
mockGlobals(t, { process: { platform: 'win32' } })
106106
t.equal(npm.bin, npm.globalBin, 'bin is global bin in windows mode')
107107
t.equal(npm.dir, npm.globalDir, 'dir is global dir in windows mode')
108-
109-
const tmp = npm.tmp
110-
t.match(tmp, String, 'npm.tmp is a string')
111-
t.equal(tmp, npm.tmp, 'getter only generates it once')
112108
})
113109

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

0 commit comments

Comments
 (0)
Please sign in to comment.