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

fix: support webpack@5 #477

Merged
merged 8 commits into from
Dec 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
node-10-canary:
node_version: ^10.13.0
webpack_version: next
continue_on_error: true
steps:
- task: NodeTool@0
inputs:
Expand All @@ -78,7 +77,7 @@ jobs:
displayName: 'Install dependencies'
- script: npm i webpack@$(webpack_version)
displayName: 'Install "webpack@$(webpack_version)"'
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit"
displayName: 'Run tests with coverage'
- task: PublishTestResults@2
inputs:
Expand Down Expand Up @@ -114,7 +113,6 @@ jobs:
node-10-canary:
node_version: ^10.13.0
webpack_version: next
continue_on_error: true
steps:
- task: NodeTool@0
inputs:
Expand All @@ -136,7 +134,7 @@ jobs:
displayName: 'Install dependencies'
- script: npm i webpack@$(webpack_version)
displayName: 'Install "webpack@$(webpack_version)"'
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit"
displayName: 'Run tests with coverage'
- task: PublishTestResults@2
inputs:
Expand Down Expand Up @@ -172,7 +170,6 @@ jobs:
node-10-canary:
node_version: ^10.13.0
webpack_version: next
continue_on_error: true
steps:
- script: 'git config --global core.autocrlf input'
displayName: 'Config git core.autocrlf'
Expand All @@ -197,7 +194,7 @@ jobs:
displayName: 'Install dependencies'
- script: npm i webpack@$(webpack_version)
displayName: 'Install "webpack@$(webpack_version)"'
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
- script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit"
displayName: 'Run tests with coverage'
- task: PublishTestResults@2
inputs:
Expand Down
326 changes: 208 additions & 118 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dist"
],
"peerDependencies": {
"webpack": "^4.4.0"
"webpack": "^4.4.0 || ^5.0.0"
},
"dependencies": {
"loader-utils": "^1.1.0",
Expand Down Expand Up @@ -72,7 +72,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"standard-version": "^7.0.1",
"webpack": "^4.41.3",
"webpack": "^4.41.4",
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.7.2"
},
Expand Down
23 changes: 19 additions & 4 deletions test/TestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ function compareDirectory(actual, expected) {
}

function compareWarning(actual, expectedFile) {
if (!fs.existsSync(expectedFile)) return;
if (!fs.existsSync(expectedFile)) {
return;
}

// eslint-disable-next-line global-require, import/no-dynamic-require
const expected = require(expectedFile);

const expected = require(expectedFile); // eslint-disable-line global-require,import/no-dynamic-require
expect(actual).toBe(expected);
expect(actual.trim()).toBe(expected.trim());
}

describe('TestCases', () => {
Expand Down Expand Up @@ -97,8 +101,19 @@ describe('TestCases', () => {
}

const expectedDirectory = path.resolve(directoryForCase, 'expected');
const expectedDirectoryByVersion = path.join(
expectedDirectory,
`webpack-${webpack.version[0]}`
);

compareDirectory(outputDirectoryForCase, expectedDirectory);
if (fs.existsSync(expectedDirectoryByVersion)) {
compareDirectory(
outputDirectoryForCase,
expectedDirectoryByVersion
);
} else {
compareDirectory(outputDirectoryForCase, expectedDirectory);
}

const expectedWarning = path.resolve(directoryForCase, 'warnings.js');
const actualWarning = stats.toString({
Expand Down
2 changes: 2 additions & 0 deletions test/cases/composes-async/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: "async-1" */ './async-1.css');
/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: "async-2" */ './async-2.css');
24 changes: 24 additions & 0 deletions test/cases/hmr/expected/webpack-5/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import url(https://some/other/external/css);
@import url(https://some/external/css);
body {
background: red;
}

.c {
background: red;
}

.c {
color: yellow;
}

.b {
background: red;
}

.b {
color: yellow;
}



7 changes: 7 additions & 0 deletions test/cases/hmr/expected/webpack-5/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/******/ (() => { // webpackBootstrap
/******/ /************************************************************************/
// extracted by mini-css-extract-plugin
if(false) { var cssReload; }

/******/ })()
;
1 change: 1 addition & 0 deletions test/cases/js-hash/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: "style" */ './style.css');
4 changes: 2 additions & 2 deletions test/cases/js-hash/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ module.exports = [1, 2].map((n) => {
],
},
output: {
filename: `[name].[contenthash].js`,
filename: `[name].[contenthash].${n}.js`,
},
plugins: [
new Self({
filename: `[name].[chunkhash].css`,
filename: `[name].[contenthash].${n}.css`,
}),
],
};
Expand Down
1 change: 1 addition & 0 deletions test/cases/multiple-entry/index-one.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './a.css';
import './b.css';

/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: 'async-one' */ './async-one');
1 change: 1 addition & 0 deletions test/cases/multiple-entry/index-two.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './b.css';
import './a.css';

/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: 'async-two' */ './async-two');
1 change: 1 addition & 0 deletions test/cases/shared-import/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './a.css';
import './b.css';

/* eslint-disable-next-line no-unused-expressions */
import('./c.css');
2 changes: 2 additions & 0 deletions test/cases/simple-async-load-css-fallback/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './a.css';
import './b.css';

/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: 'async-one' */ './async-one');
/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: 'async-two' */ './async-two');
2 changes: 2 additions & 0 deletions test/cases/simple-async-load-css/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './a.css';
import './b.css';

/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: 'async-one' */ './async-one');
/* eslint-disable-next-line no-unused-expressions */
import(/* webpackChunkName: 'async-two' */ './async-two');
2 changes: 2 additions & 0 deletions test/cases/simple-async-source-map/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './main.css';

/* eslint-disable-next-line no-unused-expressions */
import('./async');

/* eslint-disable-next-line no-unused-expressions */
import('./async.css');
2 changes: 2 additions & 0 deletions test/cases/simple-async/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './main.css';

/* eslint-disable-next-line no-unused-expressions */
import('./async');

/* eslint-disable-next-line no-unused-expressions */
import('./async.css');
2 changes: 2 additions & 0 deletions test/cases/split-chunks-single/entry1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import './e1.css';
import './e2.css';
import './f.css';

/* eslint-disable-next-line no-unused-expressions */
import('./chunk1');
/* eslint-disable-next-line no-unused-expressions */
import('./chunk2');
1 change: 1 addition & 0 deletions test/cases/split-chunks/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
chunks: 'all',
cacheGroups: {
vendors: {
name: 'vendors',
test: /node_modules/,
enforce: true,
},
Expand Down