From 11a49f900c2c6b4226b9de3636634239b8a57160 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 15 May 2024 11:52:32 -0700 Subject: [PATCH] fixup: set json config in pkg get explicitly --- lib/npm.js | 4 +++- lib/utils/display.js | 12 +++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/npm.js b/lib/npm.js index 3f6e290339058..9d00b630857b1 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -301,7 +301,9 @@ class Npm { output.flush({ [META]: true, - json: this.config.get('json'), + // json can be set during a command so we send the + // final value of it to the display layer here + json: this.loaded && this.config.get('json'), jsonError: jsonError(err, this), }) diff --git a/lib/utils/display.js b/lib/utils/display.js index 3665aad953fe4..ede2588cacfc1 100644 --- a/lib/utils/display.js +++ b/lib/utils/display.js @@ -172,8 +172,7 @@ class Display { #command #levelIndex #timing - #jsonConfig - #jsonOutput + #json #heading #silent @@ -209,11 +208,6 @@ class Display { } } - // We are in json mode if set from the config or if jsonOutput is set via a handler - get #json () { - return this.#jsonConfig || this.#jsonOutput - } - async load ({ command, heading, @@ -245,7 +239,7 @@ class Display { this.#command = command this.#levelIndex = LEVEL_OPTIONS[loglevel].index this.#timing = timing - this.#jsonConfig = json + this.#json = json this.#heading = heading this.#silent = this.#levelIndex <= 0 @@ -296,7 +290,7 @@ class Display { // Arrow function assigned to a private class field so it can be passed // directly as a listener and still reference "this" #outputHandler = withMeta((level, meta, ...args) => { - this.#jsonOutput = meta.json + this.#json = typeof meta.json === 'boolean' ? meta.json : this.#json switch (level) { case output.KEYS.flush: { this.#outputState.buffering = false