Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle NPM_CONFIG_GLOBALCONFIG when present #7604

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion __tests__/registries/npm-registry.js
@@ -1,6 +1,6 @@
/* @flow */

import {resolve, join as pathJoin} from 'path';
import {resolve, join as pathJoin, sep as pathSep} from 'path';

import NpmRegistry from '../../src/registries/npm-registry.js';
import {BufferReporter} from '../../src/reporters/index.js';
Expand Down Expand Up @@ -836,6 +836,30 @@ describe('getPossibleConfigLocations', () => {
]),
);
});

test('aware of NPM_CONFIG_GLOBALCONFIG directory when present', async () => {
const customrc = pathSep + pathJoin('tmp', 'customrc');
try {
process.env.NPM_CONFIG_GLOBALCONFIG = customrc;
const testCwd = './project/subdirectory';
const {mockRequestManager, mockRegistries} = createMocks();
const reporter = new BufferReporter({verbose: true});
const npmRegistry = new NpmRegistry(testCwd, mockRegistries, mockRequestManager, reporter, true, []);
await npmRegistry.getPossibleConfigLocations('npmrc', reporter);

const logs = reporter.getBuffer().map(logItem => logItem.data);
expect(logs).toEqual(
expect.arrayContaining([
expect.stringContaining(JSON.stringify(customrc)),
expect.stringContaining(JSON.stringify(pathJoin('project', 'subdirectory', '.npmrc'))),
expect.stringContaining(JSON.stringify(pathJoin('project', '.npmrc'))),
expect.stringContaining(JSON.stringify(pathJoin(homeDir, '.npmrc'))),
]),
);
} finally {
delete process.env.NPM_GLOBAL_GLOBALCONFIG;
}
});
});

describe('checkOutdated functional test', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/registries/npm-registry.js
Expand Up @@ -253,6 +253,10 @@ export default class NpmRegistry extends Registry {
async getPossibleConfigLocations(filename: string, reporter: Reporter): Promise<Array<[boolean, string, string]>> {
let possibles = [];

if (process.env.NPM_CONFIG_GLOBALCONFIG) {
possibles.push([false, process.env.NPM_CONFIG_GLOBALCONFIG]);
}

for (const rcFile of this.extraneousRcFiles.slice().reverse()) {
possibles.push([false, path.resolve(process.cwd(), rcFile)]);
}
Expand Down