diff --git a/lib/fund.js b/lib/fund.js index 3a3b223b47cc4..a4986f3c473f7 100644 --- a/lib/fund.js +++ b/lib/fund.js @@ -88,7 +88,7 @@ class Fund extends BaseCommand { } printHuman (fundingInfo) { - const color = this.npm.config.get('color') + const color = !!this.npm.color const unicode = this.npm.config.get('unicode') const seenUrls = new Map() diff --git a/lib/ls.js b/lib/ls.js index d89165caaf8e9..3b73f4d1e4cc5 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -44,7 +44,7 @@ class LS extends BaseCommand { async ls (args) { const all = this.npm.config.get('all') - const color = !!this.npm.config.get('color') + const color = !!this.npm.color const depth = this.npm.config.get('depth') const dev = this.npm.config.get('dev') const development = this.npm.config.get('development') diff --git a/lib/outdated.js b/lib/outdated.js index 835aa407d159f..6a7b4e7b3e9e3 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -88,7 +88,7 @@ class Outdated extends BaseCommand { outHead.push('Package Type', 'Homepage') const outTable = [outHead].concat(outList) - if (this.npm.config.get('color')) + if (this.npm.color) outTable[0] = outTable[0].map(heading => styles.underline(heading)) const tableOpts = { @@ -216,7 +216,7 @@ class Outdated extends BaseCommand { columns[7] = homepage } - if (this.npm.config.get('color')) { + if (this.npm.color) { columns[0] = color[current === wanted ? 'yellow' : 'red'](columns[0]) // current columns[2] = color.green(columns[2]) // wanted columns[3] = color.magenta(columns[3]) // latest diff --git a/test/lib/fund.js b/test/lib/fund.js index c1623ecbf57c5..bd600dbf75c01 100644 --- a/test/lib/fund.js +++ b/test/lib/fund.js @@ -780,14 +780,14 @@ test('fund colors', t => { }, }, }) - config.color = true + npm.color = true fund.exec([], (err) => { t.ifError(err, 'should not error out') t.matchSnapshot(result, 'should print output with color info') result = '' - config.color = false + npm.color = false t.end() }) }) diff --git a/test/lib/ls.js b/test/lib/ls.js index 97d227c1d5304..5367dec688658 100644 --- a/test/lib/ls.js +++ b/test/lib/ls.js @@ -182,7 +182,7 @@ t.test('ls', (t) => { }) t.test('with filter arg', (t) => { - config.color = true + npm.color = true npm.prefix = t.testdir({ 'package.json': JSON.stringify({ name: 'test-npm-ls', @@ -197,7 +197,7 @@ t.test('ls', (t) => { ls.exec(['lorem'], (err) => { t.ifError(err, 'npm ls') t.matchSnapshot(redactCwd(result), 'should output tree contaning only occurrences of filtered by package and colored output') - config.color = false + npm.color = false t.end() }) }) @@ -431,7 +431,7 @@ t.test('ls', (t) => { }) t.test('colored output', (t) => { - config.color = true + npm.color = true npm.prefix = t.testdir({ 'package.json': JSON.stringify({ name: 'test-npm-ls', @@ -446,7 +446,7 @@ t.test('ls', (t) => { ls.exec([], (err) => { t.equal(err.code, 'ELSPROBLEMS', 'should have error code') t.matchSnapshot(redactCwd(result), 'should output tree containing color info') - config.color = false + npm.color = false t.end() }) }) @@ -752,7 +752,7 @@ t.test('ls', (t) => { }) t.test('invalid deduped dep', (t) => { - config.color = true + npm.color = true npm.prefix = t.testdir({ 'package.json': JSON.stringify({ name: 'invalid-deduped-dep', @@ -782,7 +782,7 @@ t.test('ls', (t) => { }) ls.exec([], () => { t.matchSnapshot(redactCwd(result), 'should output tree signaling mismatching peer dep in problems') - config.color = false + npm.color = false t.end() }) }) @@ -836,7 +836,7 @@ t.test('ls', (t) => { }) t.test('unmet optional dep', (t) => { - config.color = true + npm.color = true npm.prefix = t.testdir({ 'package.json': JSON.stringify({ name: 'test-npm-ls', @@ -862,7 +862,7 @@ t.test('ls', (t) => { t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code') t.match(err.message, /invalid: optional-dep@1.0.0/, 'should have invalid dep error msg') t.matchSnapshot(redactCwd(result), 'should output tree with empty entry for missing optional deps') - config.color = false + npm.color = false t.end() }) }) @@ -905,7 +905,7 @@ t.test('ls', (t) => { }) t.test('cycle deps with filter args', (t) => { - config.color = true + npm.color = true npm.prefix = t.testdir({ 'package.json': JSON.stringify({ name: 'test-npm-ls', @@ -938,7 +938,7 @@ t.test('ls', (t) => { ls.exec(['a'], (err) => { t.ifError(err, 'npm ls') t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref') - config.color = false + npm.color = false t.end() }) }) @@ -1042,7 +1042,7 @@ t.test('ls', (t) => { }) t.test('with args and dedupe entries', (t) => { - config.color = true + npm.color = true npm.prefix = t.testdir({ 'package.json': JSON.stringify({ name: 'dedupe-entries', @@ -1085,7 +1085,7 @@ t.test('ls', (t) => { ls.exec(['@npmcli/b'], (err) => { t.ifError(err, 'npm ls') t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref') - config.color = false + npm.color = false t.end() }) }) diff --git a/test/lib/outdated.js b/test/lib/outdated.js index ea108bdb80c1b..39379265f56fd 100644 --- a/test/lib/outdated.js +++ b/test/lib/outdated.js @@ -91,9 +91,9 @@ const outdated = (dir, opts) => { }, }) const npm = mockNpm({ + ...opts, prefix: dir, globalDir: `${globalDir}/node_modules`, - config: opts, output, }) return new Outdated(npm) @@ -175,8 +175,9 @@ t.test('should display outdated deps', t => { t.test('outdated global', t => { outdated(null, { - global: true, + config: { global: true }, }).exec([], () => { + console.log(logs) t.matchSnapshot(logs) t.end() }) @@ -184,7 +185,9 @@ t.test('should display outdated deps', t => { t.test('outdated', t => { outdated(testDir, { - global: false, + config: { + global: false, + }, color: true, }).exec([], () => { t.matchSnapshot(logs) @@ -194,9 +197,11 @@ t.test('should display outdated deps', t => { t.test('outdated --omit=dev', t => { outdated(testDir, { - global: false, + config: { + global: false, + omit: ['dev'], + }, color: true, - omit: ['dev'], }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -205,9 +210,11 @@ t.test('should display outdated deps', t => { t.test('outdated --omit=dev --omit=peer', t => { outdated(testDir, { - global: false, + config: { + global: false, + omit: ['dev', 'peer'], + }, color: true, - omit: ['dev', 'peer'], }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -216,9 +223,11 @@ t.test('should display outdated deps', t => { t.test('outdated --omit=prod', t => { outdated(testDir, { - global: false, + config: { + global: false, + omit: ['prod'], + }, color: true, - omit: ['prod'], }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -227,8 +236,10 @@ t.test('should display outdated deps', t => { t.test('outdated --long', t => { outdated(testDir, { - global: false, - long: true, + config: { + global: false, + long: true, + }, }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -237,8 +248,10 @@ t.test('should display outdated deps', t => { t.test('outdated --json', t => { outdated(testDir, { - global: false, - json: true, + config: { + global: false, + json: true, + }, }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -247,9 +260,11 @@ t.test('should display outdated deps', t => { t.test('outdated --json --long', t => { outdated(testDir, { - global: false, - json: true, - long: true, + config: { + global: false, + json: true, + long: true, + }, }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -258,8 +273,10 @@ t.test('should display outdated deps', t => { t.test('outdated --parseable', t => { outdated(testDir, { - global: false, - parseable: true, + config: { + global: false, + parseable: true, + }, }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -268,9 +285,11 @@ t.test('should display outdated deps', t => { t.test('outdated --parseable --long', t => { outdated(testDir, { - global: false, - parseable: true, - long: true, + config: { + global: false, + parseable: true, + long: true, + }, }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -279,7 +298,9 @@ t.test('should display outdated deps', t => { t.test('outdated --all', t => { outdated(testDir, { - all: true, + config: { + all: true, + }, }).exec([], () => { t.matchSnapshot(logs) t.end() @@ -288,7 +309,9 @@ t.test('should display outdated deps', t => { t.test('outdated specific dep', t => { outdated(testDir, { - global: false, + config: { + global: false, + }, }).exec(['alpha'], () => { t.matchSnapshot(logs) t.end()