Skip to content

Commit

Permalink
feat: add env var to skip local import (#2546)
Browse files Browse the repository at this point in the history
* feat: add env var to skip local import

* feat: tests
  • Loading branch information
anshumanv committed Mar 24, 2021
1 parent 0f0e403 commit e130822
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/webpack-cli/bin/cli.js
Expand Up @@ -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';
Expand Down
21 changes: 21 additions & 0 deletions 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();
});
});
Empty file.

0 comments on commit e130822

Please sign in to comment.