From 344529a78f967dcd2fd06fb8010a569045078bf5 Mon Sep 17 00:00:00 2001 From: lvqq Date: Fri, 21 Oct 2022 10:02:13 +0800 Subject: [PATCH] feat: migrate from warning to failedToLoadBuiltInConfig flag --- index.js | 7 +++++-- test.js | 7 ++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 5442eab..6b6dbb4 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ module.exports = (opts, types, defaults) => { conf.add(Object.assign({}, opts), 'cli'); const warnings = []; + let failedToLoadBuiltInConfig = false; if (require.resolve.paths) { const paths = require.resolve.paths('npm'); @@ -17,8 +18,9 @@ module.exports = (opts, types, defaults) => { try { npmPath = require.resolve('npm', {paths: paths.slice(-1)}); } catch (error) { - // If npm module cannot be found, add warning about adding global config to overwrite builtin config - warnings.push('Load npm builtin configs failed, you can use "pnpm config ls" to show builtin configs. And then use "pnpm config --global set " to migrate configs from builtin to global.'); + // Error will be thrown if module cannot be found. + // Update the flag while loading builtin config failed. + failedToLoadBuiltInConfig = true; } if (npmPath) { @@ -69,6 +71,7 @@ module.exports = (opts, types, defaults) => { return { config: conf, warnings: warnings.filter(Boolean), + failedToLoadBuiltInConfig, }; }; diff --git a/test.js b/test.js index 1b215dc..cc0a413 100644 --- a/test.js +++ b/test.js @@ -25,12 +25,9 @@ test('mirror npm defaults', () => { test('npm builtin configs require failed', async () => { - const expected = [ - expect.stringMatching(/Load npm builtin configs failed/), - ]; // In the scope of jest, require.resolve.paths('npm') cannot reach global npm path by default - const { warnings } = m(); + const { failedToLoadBuiltInConfig } = m(); - expect(warnings).toEqual(expect.arrayContaining(expected)); + expect(failedToLoadBuiltInConfig).toBeTruthy(); })