From 260afc5ab743e060439d706a9a68a49ae5da26f0 Mon Sep 17 00:00:00 2001 From: Darcy Clarke Date: Tue, 11 Oct 2022 22:36:19 -0400 Subject: [PATCH] feat(arborist): do not audit outside of project locations BREAKING CHANGE: We no longer audit for non-project locations Co-authored-by: Nathan Fritz Co-authored-by: Jordan Harband --- workspaces/arborist/lib/arborist/index.js | 5 +++++ workspaces/arborist/test/arborist/index.js | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/workspaces/arborist/lib/arborist/index.js b/workspaces/arborist/lib/arborist/index.js index 091e0b46574cc..5316c9b7e3b1a 100644 --- a/workspaces/arborist/lib/arborist/index.js +++ b/workspaces/arborist/lib/arborist/index.js @@ -77,7 +77,12 @@ class Arborist extends Base { replaceRegistryHost: options.replaceRegistryHost, lockfileVersion: lockfileVersion(options.lockfileVersion), installStrategy: options.global ? 'shallow' : (options.installStrategy ? options.installStrategy : 'hoisted'), + location: options.global ? 'global' : options.location, } + // don't audit when run in a non-project location + this.options.audit = (!this.options.location || this.options.location === 'project') + && options.audit !== false + this.replaceRegistryHost = this.options.replaceRegistryHost = (!this.options.replaceRegistryHost || this.options.replaceRegistryHost === 'npmjs') ? 'registry.npmjs.org' : this.options.replaceRegistryHost diff --git a/workspaces/arborist/test/arborist/index.js b/workspaces/arborist/test/arborist/index.js index 88da04b94ffed..3b52a7ef7b237 100644 --- a/workspaces/arborist/test/arborist/index.js +++ b/workspaces/arborist/test/arborist/index.js @@ -253,3 +253,13 @@ t.test('valid global/installStrategy values', t => { t.equal(new Arborist({ installStrategy: 'hoisted' }).options.installStrategy, 'hoisted') t.end() }) + +t.test('disable audit when location is not project', t => { + t.equal(new Arborist({ location: 'global' }).options.audit, false) + t.equal(new Arborist({ location: undefined }).options.audit, true) + t.equal(new Arborist({ audit: undefined }).options.audit, true) + t.equal(new Arborist({ audit: false, location: 'project' }).options.audit, false) + t.equal(new Arborist({ global: true }).options.audit, false) + t.equal(new Arborist({ global: false }).options.audit, true) + t.end() +})