Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow using cjs as default config #1775

Merged
merged 3 commits into from Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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("Naruto")
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',
},
};