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

Chore: Support Webpack 5 #15

Merged
merged 5 commits into from
Mar 10, 2023
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '8'
- '16'
notifications:
email: false
deploy:
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dot-index-webpack-plugin",
"version": "5.2.0",
"version": "5.3.0",
"description": "",
"main": "src/index.js",
"bin": {
Expand All @@ -25,14 +25,15 @@
"devDependencies": {
"@launchpadlab/babel-preset": "^1.0.0",
"@launchpadlab/eslint-config": "^2.1.0",
"babel-core": "^6.26.0",
"@babel/core": "^7.12.0",
"babel-eslint": "^8.0.1",
"babel-loader": "^7.1.4",
"babel-loader": "^9.1.0",
"eslint": "^4.10.0",
"jest": "^21.2.1",
"webpack": "^4.0.0"
"jest": "^29.5.0",
"webpack": "^5.0.0",
"webpack-cli": "^5.0.1"
},
"peerDependencies": {
"webpack": "^4.0.0"
"webpack": "^4.0.0 || ^5.0.0"
}
}
11 changes: 6 additions & 5 deletions test/dot-index-plugin/dot-index-plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const fs = require('fs-extra')
const to = relPath => path.resolve(__dirname, relPath)

test('Generates dot index files', end => {

const config = {
mode: 'production',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Webpack recommends always adding mode

https://webpack.js.org/migrate/5/#make-sure-to-use-mode

entry: to('./test-input'),
output: {
path: to('./test-output'),
Expand All @@ -28,9 +28,9 @@ test('Generates dot index files', end => {

webpack(config, (err, stats) => {
expect(err).toEqual(null)
const modules = stats.toJson().modules
const modules = stats.toJson({ source: true }).modules
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(modules.length).toEqual(4)
const indexFileContent = modules.pop().source
const indexFileContent = modules.find((module) => module.name.includes('.index.js')).source
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Webpack 5 returns the .index file as the first file. Instead of switching this to .shift, I thought it would be more future proof to actually find the file.

expect(indexFileContent).toMatchSnapshot()
end()
})
Expand All @@ -40,6 +40,7 @@ test('Generates dot index files', end => {
test('Accepts formatExports argument', end => {
const toUpperCase = filename => filename.replace(/-/g, '').toUpperCase()
const config = {
mode: 'production',
entry: to('./test-input'),
output: {
path: to('./test-output'),
Expand All @@ -60,9 +61,9 @@ test('Accepts formatExports argument', end => {

webpack(config, (err, stats) => {
expect(err).toEqual(null)
const modules = stats.toJson().modules
const modules = stats.toJson({ source: true }).modules
expect(modules.length).toEqual(4)
const indexFileContent = modules.pop().source
const indexFileContent = modules.find((module) => module.name.includes('.index.js')).source
expect(indexFileContent).toMatchSnapshot()
end()
})
Expand Down
Loading