Skip to content

Commit e130822

Browse files
authored
feat: add env var to skip local import (#2546)
* feat: add env var to skip local import * feat: tests
1 parent 0f0e403 commit e130822

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

packages/webpack-cli/bin/cli.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ const importLocal = require('import-local');
1212
const runCLI = require('../lib/bootstrap');
1313
const utils = require('../lib/utils');
1414

15-
// Prefer the local installation of `webpack-cli`
16-
if (importLocal(__filename)) {
17-
return;
15+
if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) {
16+
// Prefer the local installation of `webpack-cli`
17+
if (importLocal(__filename)) {
18+
return;
19+
}
1820
}
1921

2022
process.title = 'webpack';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const { run } = require('../../utils/test-utils');
4+
5+
const importLocalMock = jest.fn();
6+
jest.setMock('import-local', importLocalMock);
7+
8+
describe('import local', () => {
9+
beforeEach(() => {
10+
importLocalMock.mockClear();
11+
});
12+
it('should skip import local when supplied', () => {
13+
const { exitCode, stderr, stdout } = run(__dirname, [], {
14+
env: { WEBPACK_CLI_SKIP_IMPORT_LOCAL: true },
15+
});
16+
expect(importLocalMock).toHaveBeenCalledTimes(0);
17+
expect(exitCode).toBe(0);
18+
expect(stderr).toBeFalsy();
19+
expect(stdout).toBeTruthy();
20+
});
21+
});

test/build/import-local/src/index.js

Whitespace-only changes.

0 commit comments

Comments
 (0)