Skip to content

Commit 321bbe5

Browse files
authored
fix(webpack-cli): fixed support for SCSS entry points (#1271)
* fix(webpack-cli): fixed support for SCSS entry points * fix(webpack-cli): use children only when configuration is an array * fix(webpack-cli): added tests correctly * fix(webpack-cli): increased time out for installing deps * tests(webpack-cli): enforced time out * tests(webpack-cli): fix correct cwd when installing deps * tests(webpack-cli): fix correct cwd when installing deps * tests(webpack-cli): install all packages before launching the tests
1 parent afe97f6 commit 321bbe5

File tree

14 files changed

+190
-48
lines changed

14 files changed

+190
-48
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ module.exports = {
99
},
1010
testRegex: ['/__tests__/.*\\.(test.js|test.ts)$', '/test/.*\\.(test.js|test.ts)$'],
1111
moduleFileExtensions: ['ts', 'js', 'json'],
12+
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
1213
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
"scripts": {
2626
"bootstrap": "lerna bootstrap",
2727
"build": "node scripts/buildPackages.js",
28+
"prepsuite": "node scripts/prepareSuite.js",
2829
"clean:all": "rimraf node_modules packages/*/{node_modules}",
2930
"commit": "git-cz",
3031
"docs": "typedoc",
3132
"format": "eslint --fix . --ext .js,.ts",
3233
"lint": "eslint . --ext .js,.ts",
3334
"lint:fix": "eslint . --ext .js,.ts --fix",
34-
"pretest": "yarn build && yarn lint",
35+
"pretest": "yarn build && yarn lint && yarn prepsuite",
3536
"reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov",
3637
"smoketest": "smoketests/smoketests.sh",
3738
"test": "nyc jest --maxWorkers=4 --reporters=default --reporters=jest-junit",
@@ -150,6 +151,7 @@
150151
"jest": "^25.1.0",
151152
"jest-junit": "^10.0.0",
152153
"jest-serializer-ansi": "^1.0.3",
154+
"jest-watch-typeahead": "^0.4.2",
153155
"lerna": "^3.20.2",
154156
"lint-staged": "^9.4.2",
155157
"nyc": "^14.1.1",

packages/webpack-cli/lib/utils/Compiler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { CompilerOutput } = require('./CompilerOutput');
66
class Compiler {
77
constructor() {
88
this.output = new CompilerOutput();
9+
this.compilerOptions = {};
910
}
1011
setUpHookForCompilation(compilation, outputOptions, options) {
1112
const { ProgressPlugin } = webpack;
@@ -81,7 +82,7 @@ class Compiler {
8182
this.output.generateRawOutput(stats);
8283
} else {
8384
const statsObj = stats.toJson(outputOptions);
84-
if (statsObj.children && statsObj.children.length) {
85+
if (statsObj.children && Array.isArray(statsObj.children) && this.compilerOptions && Array.isArray(this.compilerOptions)) {
8586
statsObj.children.forEach(child => {
8687
this.output.generateFancyOutput(child, statsErrors, processingMessageBuffer);
8788
});
@@ -146,6 +147,7 @@ class Compiler {
146147
async createCompiler(options) {
147148
try {
148149
this.compiler = await webpack(options);
150+
this.compilerOptions = options;
149151
} catch (err) {
150152
process.stdout.write('\n');
151153
logger.error(`${err.name}: ${err.message}`);

packages/webpack-cli/lib/utils/CompilerOutput.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,40 @@ class CompilerOutput {
3232
const asset = assets.find(asset => {
3333
return asset.name === assetName;
3434
});
35-
const entrypointChunks = entrypoint.chunks.map(id => {
36-
return chunks.find(chunk => chunk.id === id);
37-
});
38-
39-
const chunksOutput = this._createChunksOutput(entrypointChunks);
40-
const kbSize = `${(asset.size / 1000).toFixed(2)} kb`;
41-
const hasBeenCompiled = asset.comparedForEmit;
42-
const bundleTbl = new Table({
43-
chars: {
44-
top: '',
45-
'top-mid': '',
46-
'top-left': '',
47-
'top-right': '',
48-
bottom: '',
49-
'bottom-mid': '',
50-
'bottom-left': '',
51-
'bottom-right': '',
52-
left: '',
53-
'left-mid': '',
54-
mid: '',
55-
'mid-mid': '',
56-
right: '',
57-
'right-mid': '',
58-
},
59-
style: { compact: true },
60-
});
61-
bundleTbl.push({ 'Bundle Name': asset.name });
62-
bundleTbl.push({ 'Compared For Emit': hasBeenCompiled });
63-
bundleTbl.push({ 'Bundle size': kbSize });
64-
const bundleOutput = bundleTbl.toString() + `\n\nModules:\n${chunksOutput}`;
65-
assetsTble.push([entrypoint.name, bundleOutput]);
66-
compilationTableEmpty = false;
35+
if (asset) {
36+
const entrypointChunks = entrypoint.chunks.map(id => {
37+
return chunks.find(chunk => chunk.id === id);
38+
});
39+
40+
const chunksOutput = this._createChunksOutput(entrypointChunks);
41+
const kbSize = `${(asset.size / 1000).toFixed(2)} kb`;
42+
const hasBeenCompiled = asset.comparedForEmit;
43+
const bundleTbl = new Table({
44+
chars: {
45+
top: '',
46+
'top-mid': '',
47+
'top-left': '',
48+
'top-right': '',
49+
bottom: '',
50+
'bottom-mid': '',
51+
'bottom-left': '',
52+
'bottom-right': '',
53+
left: '',
54+
'left-mid': '',
55+
mid: '',
56+
'mid-mid': '',
57+
right: '',
58+
'right-mid': '',
59+
},
60+
style: { compact: true },
61+
});
62+
bundleTbl.push({ 'Bundle Name': asset.name });
63+
bundleTbl.push({ 'Compared For Emit': hasBeenCompiled });
64+
bundleTbl.push({ 'Bundle size': kbSize });
65+
const bundleOutput = bundleTbl.toString() + `\n\nModules:\n${chunksOutput}`;
66+
assetsTble.push([entrypoint.name, bundleOutput]);
67+
compilationTableEmpty = false;
68+
}
6769
});
6870
});
6971

scripts/prepareSuite.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
// eslint-disable-next-line node/no-unpublished-require
6+
const execa = require('execa');
7+
// eslint-disable-next-line node/no-unpublished-require
8+
const chalk = require('chalk');
9+
10+
const BASE_DIR = 'test/';
11+
const PACKAGE = 'package.json';
12+
13+
function collectTestingFoldersWithPackage() {
14+
const testFolder = path.resolve(path.join(process.cwd(), BASE_DIR));
15+
16+
return extractFolder(testFolder);
17+
}
18+
19+
function extractFolder(folderToRead, folders = []) {
20+
const files = fs.readdirSync(folderToRead);
21+
22+
files.forEach(file => {
23+
const filePath = path.resolve(path.join(folderToRead, file));
24+
const stats = fs.statSync(filePath);
25+
if (stats.isFile() && file === PACKAGE) {
26+
folders.push(folderToRead);
27+
}
28+
if (stats.isDirectory() && file !== 'node_modules') {
29+
extractFolder(filePath, folders);
30+
}
31+
});
32+
33+
return folders;
34+
}
35+
36+
{
37+
Promise.all(
38+
collectTestingFoldersWithPackage().map(async folder => {
39+
return execa('yarn', {
40+
cwd: folder,
41+
stdio: 'inherit',
42+
});
43+
}),
44+
)
45+
.then(() => {
46+
console.log(chalk.inverse.green(' Successfully prepared the test suite '));
47+
})
48+
.catch(e => {
49+
console.error(chalk.inverse.red(' Unable to prepare the test suite '));
50+
console.error(e.stack);
51+
process.exitCode = 1;
52+
});
53+
}

test/entry/scss/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
yarn.lock
2+
package-lock.json
3+
node_modules/

test/entry/scss/home.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('home');

test/entry/scss/home.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
body {
2+
font-size: 100%;
3+
body {
4+
background-color: red;
5+
}
6+
}

test/entry/scss/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"dependencies": {
3+
"css-loader": "^3.4.2",
4+
"style-loader": "^1.1.3",
5+
"sass-loader": "^8.0.2",
6+
"mini-css-extract-plugin": "^0.9.0",
7+
"node-sass": "^4.13.1"
8+
}
9+
}

test/entry/scss/scss.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable node/no-missing-require */
2+
/* eslint-disable node/no-unpublished-require */
3+
const { run, runInstall } = require('../../utils/test-utils');
4+
5+
jest.setTimeout(1000 * 60 * 5);
6+
7+
describe('entry point', () => {
8+
it('should support SCSS files', async () => {
9+
await runInstall(__dirname);
10+
const { stdout } = run(__dirname);
11+
expect(stdout).toBeTruthy();
12+
expect(stdout).toContain('home.scss');
13+
expect(stdout).toContain('home.js');
14+
});
15+
});

0 commit comments

Comments
 (0)