Skip to content

Commit

Permalink
feat: allow using cjs as default config (#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Aug 28, 2020
1 parent fa1449c commit aaaa07b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/webpack-cli/lib/groups/ConfigGroup.js
Expand Up @@ -31,7 +31,8 @@ const modeAlias = {

const getDefaultConfigFiles = () => {
return DEFAULT_CONFIG_LOC.map((filename) => {
return Object.keys(extensions).map((ext) => {
// Since .cjs is not available on interpret side add it manually to default config extension list
return [...Object.keys(extensions), '.cjs'].map((ext) => {
return {
path: resolve(filename + ext),
ext: ext,
Expand Down
@@ -1,10 +1,10 @@
const fs = require('fs');
const path = require('path');
const { run } = require('../../utils/test-utils');
const { run } = require('../../../utils/test-utils');

describe('Zero Config', () => {
it('runs when config is present but not supplied via flag', () => {
const { stdout, stderr } = run(__dirname, [], false);
const { stdout, stderr, exitCode } = run(__dirname, [], false);
// default entry should be used
expect(stdout).toContain('./index.js');
// should pick up the output path from config
Expand All @@ -13,6 +13,8 @@ describe('Zero Config', () => {
expect(stdout).toContain('Version');
expect(stdout).toContain('Built at');
expect(stdout).toContain('Time');
// Should return the correct exit code
expect(exitCode).toEqual(0);
// check that the output file exists
expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy();
expect(stderr).toBeFalsy();
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions test/config/defaults/cjs-config/default-cjs-config.test.js
@@ -0,0 +1,22 @@
const fs = require('fs');
const path = require('path');
const { run } = require('../../../utils/test-utils');

describe('Default Config:', () => {
it('Should be able to pick cjs config by default', () => {
const { stdout, stderr, exitCode } = run(__dirname, [], false);
// default entry should be used
expect(stdout).toContain('./index.js');
// should pick up the output path from config
expect(stdout).toContain('Entrypoint main = test-output');
expect(stdout).toContain('Hash');
expect(stdout).toContain('Version');
expect(stdout).toContain('Built at');
expect(stdout).toContain('Time');
// Should return the correct exit code
expect(exitCode).toEqual(0);
// check that the output file exists
expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy();
expect(stderr).toBeFalsy();
});
});
1 change: 1 addition & 0 deletions test/config/defaults/cjs-config/index.js
@@ -0,0 +1 @@
console.log("Jotaro Kujo")
6 changes: 6 additions & 0 deletions test/config/defaults/cjs-config/webpack.config.cjs
@@ -0,0 +1,6 @@
module.exports = {
mode: 'development',
output: {
filename: 'test-output.js',
},
};

0 comments on commit aaaa07b

Please sign in to comment.