Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion __tests__/registries/npm-registry.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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