Skip to content

Commit ee22312

Browse files
refactor: webpack v5 (#131)
BREAKING CHANGE: minimum supported webpack version is `5`, minimum supported Node.ks version is `14.15.0`
1 parent fb4ab6e commit ee22312

File tree

13 files changed

+26513
-8792
lines changed

13 files changed

+26513
-8792
lines changed

.eslintrc.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ module.exports = {
44
extends: [
55
"plugin:itgalaxy/script",
66
"plugin:itgalaxy/esnext",
7-
"plugin:itgalaxy/node"
7+
"plugin:itgalaxy/node",
88
],
99
overrides: [
1010
// Source
1111
{
1212
extends: ["plugin:itgalaxy/dirty"],
1313
// Exclude nested tests
1414
excludedFiles: ["**/__tests__/**/*", "**/__mocks__/**/*", "**/*.md"],
15-
files: ["src/**/*"]
15+
files: ["src/**/*"],
1616
},
1717

1818
// Jest
@@ -22,26 +22,26 @@ module.exports = {
2222
files: ["**/__tests__/**/*", "**/__mocks__/**/*"],
2323
rules: {
2424
// Allow to use `console` (example - `mocking`)
25-
"no-console": "off"
26-
}
25+
"no-console": "off",
26+
},
2727
},
2828

2929
// Markdown
3030
{
3131
extends: [
3232
// Documentation files can contain ECMA and CommonJS modules
3333
"plugin:itgalaxy/dirty",
34-
"plugin:itgalaxy/markdown"
34+
"plugin:itgalaxy/markdown",
3535
],
3636
files: ["**/*.md"],
3737
rules: {
3838
"no-unused-vars": "off",
3939
"no-console": "off",
4040
"import/no-unresolved": "off",
4141
"node/no-unpublished-require": "off",
42-
"node/no-unpublished-import": "off"
43-
}
44-
}
42+
"node/no-unpublished-import": "off",
43+
},
44+
},
4545
],
46-
root: true
46+
root: true,
4747
};

.remarkrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
22

33
module.exports = {
4-
plugins: ["remark-preset-lint-itgalaxy"]
4+
plugins: ["remark-preset-lint-itgalaxy"],
55
};

__tests__/RobotstxtPlugin.test.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,66 @@
1+
import path from "path";
12
import { webpack } from "./helpers";
23
import RobotstxtPlugin from "../src/RobotstxtPlugin";
34

45
describe("plugin", () => {
56
it("should execute successfully", async () => {
6-
const stats = await webpack("entry.js");
7-
8-
const { warnings, errors, assets } = stats.compilation;
7+
const { stats, compiler } = await webpack("entry.js");
8+
const { warnings, errors } = stats.compilation;
99

1010
expect(warnings).toMatchSnapshot("warnings");
1111
expect(errors).toMatchSnapshot("errors");
12-
expect(assets["robots.txt"].source()).toMatchSnapshot();
12+
expect(
13+
// eslint-disable-next-line no-sync
14+
compiler.outputFileSystem.readFileSync(
15+
path.resolve(compiler.outputPath, "robots.txt"),
16+
"utf-8"
17+
)
18+
).toMatchSnapshot();
1319
});
1420

1521
it("should execute successfully #2", async () => {
16-
const stats = await webpack("entry.js", {
17-
plugins: [new RobotstxtPlugin()]
22+
const { stats, compiler } = await webpack("entry.js", {
23+
plugins: [new RobotstxtPlugin()],
1824
});
1925

20-
const { warnings, errors, assets } = stats.compilation;
26+
const { warnings, errors } = stats.compilation;
2127

2228
expect(warnings).toMatchSnapshot("warnings");
2329
expect(errors).toMatchSnapshot("errors");
24-
expect(assets["robots.txt"].source()).toMatchSnapshot();
30+
expect(
31+
// eslint-disable-next-line no-sync
32+
compiler.outputFileSystem.readFileSync(
33+
path.resolve(compiler.outputPath, "robots.txt"),
34+
"utf-8"
35+
)
36+
).toMatchSnapshot();
2537
});
2638

2739
it("should execute successfully with `filePath` option", async () => {
28-
const stats = await webpack("entry.js", {
40+
const { stats, compiler } = await webpack("entry.js", {
2941
pluginOptions: {
30-
filePath: "robots.dev.txt"
31-
}
42+
filePath: "robots.dev.txt",
43+
},
3244
});
3345

34-
const { warnings, errors, assets } = stats.compilation;
46+
const { warnings, errors } = stats.compilation;
3547

3648
expect(warnings).toMatchSnapshot("warnings");
3749
expect(errors).toMatchSnapshot("errors");
38-
expect(assets["robots.dev.txt"].source()).toMatchSnapshot();
50+
expect(
51+
// eslint-disable-next-line no-sync
52+
compiler.outputFileSystem.readFileSync(
53+
path.resolve(compiler.outputPath, "robots.dev.txt"),
54+
"utf-8"
55+
)
56+
).toMatchSnapshot();
3957
});
4058

4159
it("should throw error on invalid `generate-robotstxt` options", async () => {
42-
const stats = await webpack("entry.js", {
60+
const { stats } = await webpack("entry.js", {
4361
pluginOptions: {
44-
policy: {}
45-
}
62+
policy: {},
63+
},
4664
});
4765

4866
const { warnings, errors } = stats.compilation;

__tests__/__snapshots__/RobotstxtPlugin.test.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Allow: /
66
"
77
`;
88

9-
exports[`plugin should execute successfully #2: errors 1`] = `Array []`;
9+
exports[`plugin should execute successfully #2: errors 1`] = `[]`;
1010

11-
exports[`plugin should execute successfully #2: warnings 1`] = `Array []`;
11+
exports[`plugin should execute successfully #2: warnings 1`] = `[]`;
1212

1313
exports[`plugin should execute successfully 1`] = `
1414
"User-agent: *
@@ -22,18 +22,18 @@ Allow: /
2222
"
2323
`;
2424

25-
exports[`plugin should execute successfully with \`filePath\` option: errors 1`] = `Array []`;
25+
exports[`plugin should execute successfully with \`filePath\` option: errors 1`] = `[]`;
2626

27-
exports[`plugin should execute successfully with \`filePath\` option: warnings 1`] = `Array []`;
27+
exports[`plugin should execute successfully with \`filePath\` option: warnings 1`] = `[]`;
2828

29-
exports[`plugin should execute successfully: errors 1`] = `Array []`;
29+
exports[`plugin should execute successfully: errors 1`] = `[]`;
3030

31-
exports[`plugin should execute successfully: warnings 1`] = `Array []`;
31+
exports[`plugin should execute successfully: warnings 1`] = `[]`;
3232

3333
exports[`plugin should throw error on invalid \`generate-robotstxt\` options: errors 1`] = `
34-
Array [
34+
[
3535
[Error: Options \`policy\` must be array],
3636
]
3737
`;
3838

39-
exports[`plugin should throw error on invalid \`generate-robotstxt\` options: warnings 1`] = `Array []`;
39+
exports[`plugin should throw error on invalid \`generate-robotstxt\` options: warnings 1`] = `[]`;

__tests__/helpers.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import del from "del";
44
import webpack from "webpack";
55
import RobotstxtPlugin from "../src/RobotstxtPlugin";
66

7-
const outputConfig = config => ({
7+
const outputConfig = (config) => ({
88
path: path.resolve(
99
__dirname,
1010
`../outputs/${config.output ? config.output : ""}`
1111
),
12-
filename: "[name].bundle.js"
12+
filename: "[name].bundle.js",
1313
});
1414

15-
const moduleConfig = config => ({
16-
rules: config.rules ? config.rules : []
15+
const moduleConfig = (config) => ({
16+
rules: config.rules ? config.rules : [],
1717
});
1818

19-
const pluginsConfig = config =>
19+
const pluginsConfig = (config) =>
2020
[].concat(
2121
config.plugins || [new RobotstxtPlugin(config.pluginOptions || {})]
2222
);
@@ -26,12 +26,12 @@ function compile(fixture, config = {}, options = {}) {
2626
// eslint-disable-next-line no-param-reassign
2727
config = {
2828
mode: "development",
29-
devtool: config.devtool || "sourcemap",
29+
devtool: false,
3030
context: path.resolve(__dirname, "fixtures"),
3131
entry: path.resolve(__dirname, "fixtures", fixture),
3232
output: outputConfig(config),
3333
module: moduleConfig(config),
34-
plugins: pluginsConfig(config)
34+
plugins: pluginsConfig(config),
3535
};
3636

3737
// Compiler Options
@@ -54,7 +54,7 @@ function compile(fixture, config = {}, options = {}) {
5454
return reject(error);
5555
}
5656

57-
return resolve(stats);
57+
return resolve({ stats, compiler });
5858
})
5959
);
6060
}

babel.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const MIN_BABEL_VERSION = 7;
44

5-
module.exports = api => {
5+
module.exports = (api) => {
66
api.assertVersion(MIN_BABEL_VERSION);
77
api.cache(true);
88

@@ -12,10 +12,10 @@ module.exports = api => {
1212
"@babel/preset-env",
1313
{
1414
targets: {
15-
node: "10.13.0"
16-
}
17-
}
18-
]
19-
]
15+
node: "10.13.0",
16+
},
17+
},
18+
],
19+
],
2020
};
2121
};

husky.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module.exports = {
44
hooks: {
5-
"pre-commit": "lint-staged"
6-
}
5+
"pre-commit": "lint-staged",
6+
},
77
};

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
module.exports = {
44
collectCoverageFrom: ["src/**/*.{js,mjs,jsx}"],
5-
testPathIgnorePatterns: ["/node_modules/", "/fixtures/", "helpers.js"]
5+
testPathIgnorePatterns: ["/node_modules/", "/fixtures/", "helpers.js"],
66
};

lint-staged.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ module.exports = {
44
"*.{js,jsx}": [
55
"prettier --list-different",
66
"eslint --report-unused-disable-directives",
7-
"git add"
7+
"git add",
88
],
99
"!(CHANGELOG).{md,markdown,mdown,mkdn,mkd,mdwn,mkdown,ron}": [
1010
"prettier --list-different",
1111
"remark -f -q",
12-
"git add"
12+
"git add",
1313
],
14-
"*.{yml,yaml}": ["prettier --list-different", "git add"]
14+
"*.{yml,yaml}": ["prettier --list-different", "git add"],
1515
};

0 commit comments

Comments
 (0)