Skip to content

Commit

Permalink
feat: look for config in cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
shellscape committed Nov 14, 2018
1 parent b2b7b33 commit 68c0119
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ node_modules
.nyc_output
coverage.lcov

test/fixtures/dist
test/fixtures/**/dist

.eslintcache
6 changes: 6 additions & 0 deletions bin/wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of this Source Code Form.
*/
const { existsSync } = require('fs');
const path = require('path');

const chalk = require('chalk');
Expand All @@ -25,6 +26,7 @@ const configTypes = {
function: (c, argv) => Promise.resolve(c(argv.env || {}, argv)),
object: (c) => Promise.resolve(c)
};
const defaultConfigPath = path.resolve(process.cwd(), 'webpack.config.js');

const help = chalk`
${pkg.description}
Expand Down Expand Up @@ -81,6 +83,10 @@ webpack v${webpack.version}
let config = {};
let watchConfig;

if (!argv.config && existsSync(defaultConfigPath)) {
argv.config = defaultConfigPath;
}

// let's not process any config if the user hasn't specified any
if (argv.config) {
const configName = typeof argv.config !== 'string' ? Object.keys(argv.config)[0] : null;
Expand Down
File renamed without changes.
9 changes: 7 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { resolve } = require('path');
const { join, resolve } = require('path');

const test = require('ava');
const execa = require('execa');
Expand All @@ -9,6 +9,11 @@ const cwd = resolve(__dirname, './fixtures');

const run = (...args) => execa('node', [bin].concat(args), { cwd });

test('no config', async (t) => {
const { stderr } = await run();
t.truthy(stderr.includes('⬡ webpack: Build Finished'));
});

test('--config', async (t) => {
const { stderr } = await run('--config', 'webpack.config.js');
t.truthy(stderr.includes('⬡ webpack: Build Finished'));
Expand Down Expand Up @@ -81,7 +86,7 @@ test('watch', (t) => {
});

test('zero config', async (t) => {
const { stderr } = await run();
const { stderr } = await execa('node', [bin], { cwd: join(cwd, '/zero') });
t.truthy(stderr.includes('⬡ webpack: Build Finished'));
});

Expand Down

0 comments on commit 68c0119

Please sign in to comment.