1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const {
|
14 | store
|
15 | } = require(`../redux`);
|
16 |
|
17 | const eslintConfig = require(`./eslint-config`);
|
18 |
|
19 | const hasLocalEslint = require(`./local-eslint-config-finder`);
|
20 |
|
21 | const isEslintRule = rule => {
|
22 | const options = rule && rule.use && rule.use[0] && rule.use[0].options;
|
23 | return options && typeof options.useEslintrc !== `undefined`;
|
24 | };
|
25 |
|
26 | class GatsbyWebpackEslintGraphqlSchemaReload {
|
27 | constructor(options) {
|
28 | (0, _defineProperty2.default)(this, "schema", null);
|
29 | (0, _defineProperty2.default)(this, "findEslintOptions", compiler => compiler.options.module.rules.find(isEslintRule).use[0].options);
|
30 | this.plugin = {
|
31 | name: `GatsbyWebpackEslintGraphqlSchemaReload`
|
32 | };
|
33 | this.options = options || {};
|
34 | }
|
35 |
|
36 | apply(compiler) {
|
37 | compiler.hooks.compile.tap(this.plugin.name, () => {
|
38 | const {
|
39 | schema,
|
40 | program
|
41 | } = store.getState();
|
42 |
|
43 | if (!this.schema) {
|
44 |
|
45 | this.schema = schema;
|
46 | return;
|
47 | }
|
48 |
|
49 | if (this.schema === schema || hasLocalEslint(program.directory)) {
|
50 | return;
|
51 | }
|
52 |
|
53 | this.schema = schema;
|
54 |
|
55 | const options = this.findEslintOptions(compiler);
|
56 |
|
57 |
|
58 | Object.assign(options, eslintConfig(schema));
|
59 | });
|
60 | }
|
61 |
|
62 | }
|
63 |
|
64 | module.exports = GatsbyWebpackEslintGraphqlSchemaReload;
|
65 |
|
\ | No newline at end of file |