diff --git a/packages/webpack-cli/bin/cli.js b/packages/webpack-cli/bin/cli.js index db74156aa8b..9a9f5f02a59 100755 --- a/packages/webpack-cli/bin/cli.js +++ b/packages/webpack-cli/bin/cli.js @@ -12,9 +12,11 @@ const importLocal = require('import-local'); const runCLI = require('../lib/bootstrap'); const utils = require('../lib/utils'); -// Prefer the local installation of `webpack-cli` -if (importLocal(__filename)) { - return; +if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) { + // Prefer the local installation of `webpack-cli` + if (importLocal(__filename)) { + return; + } } process.title = 'webpack'; diff --git a/test/build/import-local/import-local.test.js b/test/build/import-local/import-local.test.js new file mode 100644 index 00000000000..afbb3d90a9e --- /dev/null +++ b/test/build/import-local/import-local.test.js @@ -0,0 +1,21 @@ +'use strict'; + +const { run } = require('../../utils/test-utils'); + +const importLocalMock = jest.fn(); +jest.setMock('import-local', importLocalMock); + +describe('import local', () => { + beforeEach(() => { + importLocalMock.mockClear(); + }); + it('should skip import local when supplied', () => { + const { exitCode, stderr, stdout } = run(__dirname, [], { + env: { WEBPACK_CLI_SKIP_IMPORT_LOCAL: true }, + }); + expect(importLocalMock).toHaveBeenCalledTimes(0); + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(stdout).toBeTruthy(); + }); +}); diff --git a/test/build/import-local/src/index.js b/test/build/import-local/src/index.js new file mode 100644 index 00000000000..e69de29bb2d