UNPKG

3.4 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/utils/gatsby-webpack-eslint-graphql-schema-reload-plugin.js"],"names":["store","require","eslintConfig","hasLocalEslint","isEslintRule","rule","options","use","useEslintrc","GatsbyWebpackEslintGraphqlSchemaReload","constructor","compiler","module","rules","find","plugin","name","apply","hooks","compile","tap","schema","program","getState","directory","findEslintOptions","Object","assign","exports"],"mappings":";;;;;;AAAA;;;;;;AAMA,MAAM;AAAEA,EAAAA;AAAF,IAAYC,OAAO,CAAE,UAAF,CAAzB;;AACA,MAAMC,YAAY,GAAGD,OAAO,CAAE,iBAAF,CAA5B;;AACA,MAAME,cAAc,GAAGF,OAAO,CAAE,8BAAF,CAA9B;;AAEA,MAAMG,YAAY,GAAGC,IAAI,IAAI;AAC3B,QAAMC,OAAO,GAAGD,IAAI,IAAIA,IAAI,CAACE,GAAb,IAAoBF,IAAI,CAACE,GAAL,CAAS,CAAT,CAApB,IAAmCF,IAAI,CAACE,GAAL,CAAS,CAAT,EAAYD,OAA/D;AACA,SAAOA,OAAO,IAAI,OAAOA,OAAO,CAACE,WAAf,KAAgC,WAAlD;AACD,CAHD;;AAKA,MAAMC,sCAAN,CAA6C;AAG3CC,EAAAA,WAAW,CAACJ,OAAD,EAAU;AAAA,kDAFZ,IAEY;AAAA,6DAKDK,QAAQ,IAC1BA,QAAQ,CAACL,OAAT,CAAiBM,MAAjB,CAAwBC,KAAxB,CAA8BC,IAA9B,CAAmCV,YAAnC,EAAiDG,GAAjD,CAAqD,CAArD,EAAwDD,OANrC;AACnB,SAAKS,MAAL,GAAc;AAAEC,MAAAA,IAAI,EAAG;AAAT,KAAd;AACA,SAAKV,OAAL,GAAeA,OAAO,IAAI,EAA1B;AACD;;AAKDW,EAAAA,KAAK,CAACN,QAAD,EAAW;AACdA,IAAAA,QAAQ,CAACO,KAAT,CAAeC,OAAf,CAAuBC,GAAvB,CAA2B,KAAKL,MAAL,CAAYC,IAAvC,EAA6C,MAAM;AACjD,YAAM;AAAEK,QAAAA,MAAF;AAAUC,QAAAA;AAAV,UAAsBtB,KAAK,CAACuB,QAAN,EAA5B;;AAEA,UAAI,CAAC,KAAKF,MAAV,EAAkB;AAChB;AACA,aAAKA,MAAL,GAAcA,MAAd;AACA;AACD;;AAED,UAAI,KAAKA,MAAL,KAAgBA,MAAhB,IAA0BlB,cAAc,CAACmB,OAAO,CAACE,SAAT,CAA5C,EAAiE;AAC/D;AACD;;AACD,WAAKH,MAAL,GAAcA,MAAd,CAZiD,CAcjD;;AACA,YAAMf,OAAO,GAAG,KAAKmB,iBAAL,CAAuBd,QAAvB,CAAhB,CAfiD,CAiBjD;AACA;;AACAe,MAAAA,MAAM,CAACC,MAAP,CAAcrB,OAAd,EAAuBJ,YAAY,CAACmB,MAAD,CAAnC;AACD,KApBD;AAqBD;;AAjC0C;;AAoC7CT,MAAM,CAACgB,OAAP,GAAiBnB,sCAAjB","sourcesContent":["/**\n * The problem: after GraphQL schema rebuilds, eslint loader keeps validating against\n * the old schema.\n *\n * This plugin replaces options of eslint-plugin-graphql during develop\n */\nconst { store } = require(`../redux`)\nconst eslintConfig = require(`./eslint-config`)\nconst hasLocalEslint = require(`./local-eslint-config-finder`)\n\nconst isEslintRule = rule => {\n const options = rule && rule.use && rule.use[0] && rule.use[0].options\n return options && typeof options.useEslintrc !== `undefined`\n}\n\nclass GatsbyWebpackEslintGraphqlSchemaReload {\n schema = null\n\n constructor(options) {\n this.plugin = { name: `GatsbyWebpackEslintGraphqlSchemaReload` }\n this.options = options || {}\n }\n\n findEslintOptions = compiler =>\n compiler.options.module.rules.find(isEslintRule).use[0].options\n\n apply(compiler) {\n compiler.hooks.compile.tap(this.plugin.name, () => {\n const { schema, program } = store.getState()\n\n if (!this.schema) {\n // initial build\n this.schema = schema\n return\n }\n\n if (this.schema === schema || hasLocalEslint(program.directory)) {\n return\n }\n this.schema = schema\n\n // Original eslint config object from webpack rules\n const options = this.findEslintOptions(compiler)\n\n // Hackish but works:\n // replacing original eslint options object with updated config\n Object.assign(options, eslintConfig(schema))\n })\n }\n}\n\nmodule.exports = GatsbyWebpackEslintGraphqlSchemaReload\n"],"file":"gatsby-webpack-eslint-graphql-schema-reload-plugin.js"}
\No newline at end of file