UNPKG

5.49 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/utils/source-nodes.js"],"names":["report","require","apiRunner","store","getNode","getNodes","boundActionCreators","deleteNode","discoverPluginsWithoutNodes","storeState","nodes","nodeOwnerSet","Set","forEach","node","add","internal","owner","flattenedPlugins","filter","plugin","nodeAPIs","includes","has","name","map","warnForPluginsWithoutNodes","state","pluginsWithNoNodes","warn","getStaleNodes","rootNode","whileCount","parent","undefined","console","log","nodesTouched","id","deleteStaleNodes","staleNodes","length","module","exports","webhookBody","parentSpan","traceId","waitForCascadingActions","getState"],"mappings":";;AAAA,MAAMA,MAAM,GAAGC,OAAO,CAAE,yBAAF,CAAtB;;AAEA,MAAMC,SAAS,GAAGD,OAAO,CAAE,mBAAF,CAAzB;;AACA,MAAM;AAAEE,EAAAA;AAAF,IAAYF,OAAO,CAAE,UAAF,CAAzB;;AACA,MAAM;AAAEG,EAAAA,OAAF;AAAWC,EAAAA;AAAX,IAAwBJ,OAAO,CAAE,aAAF,CAArC;;AACA,MAAM;AAAEK,EAAAA;AAAF,IAA0BL,OAAO,CAAE,kBAAF,CAAvC;;AACA,MAAM;AAAEM,EAAAA;AAAF,IAAiBD,mBAAvB;AAEA;;;;;AAIA,SAASE,2BAAT,CAAqCC,UAArC,EAAiDC,KAAjD,EAAwD;AACtD;AACA,QAAMC,YAAY,GAAG,IAAIC,GAAJ,CAAQ,CAAE,qBAAF,CAAR,CAArB;AACAF,EAAAA,KAAK,CAACG,OAAN,CAAcC,IAAI,IAAIH,YAAY,CAACI,GAAb,CAAiBD,IAAI,CAACE,QAAL,CAAcC,KAA/B,CAAtB;AAEA,SAAOR,UAAU,CAACS,gBAAX,CACJC,MADI,CAEHC,MAAM,IACJ;AACAA,EAAAA,MAAM,CAACC,QAAP,CAAgBC,QAAhB,CAA0B,aAA1B,KACA;AACA,GAACX,YAAY,CAACY,GAAb,CAAiBH,MAAM,CAACI,IAAxB,CANA,EAQJC,GARI,CAQAL,MAAM,IAAIA,MAA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CAACC,OAAP,GAAiB,OAAO;AAAEC,EAAAA,WAAW,GAAG,EAAhB;AAAoBC,EAAAA;AAApB,IAAmC,EAA1C,KAAiD;AAChE,QAAM3C,SAAS,CAAE,aAAF,EAAgB;AAC7B4C,IAAAA,OAAO,EAAG,qBADmB;AAE7BC,IAAAA,uBAAuB,EAAE,IAFI;AAG7BF,IAAAA,UAH6B;AAI7BD,IAAAA;AAJ6B,GAAhB,CAAf;AAOA,QAAMjB,KAAK,GAAGxB,KAAK,CAAC6C,QAAN,EAAd;AACA,QAAMtC,KAAK,GAAGL,QAAQ,EAAtB;AAEAqB,EAAAA,0BAA0B,CAACC,KAAD,EAAQjB,KAAR,CAA1B;AAEA6B,EAAAA,gBAAgB,CAACZ,KAAD,EAAQjB,KAAR,CAAhB;AACD,CAdD","sourcesContent":["const report = require(`gatsby-cli/lib/reporter`)\n\nconst apiRunner = require(`./api-runner-node`)\nconst { store } = require(`../redux`)\nconst { getNode, getNodes } = require(`../db/nodes`)\nconst { boundActionCreators } = require(`../redux/actions`)\nconst { deleteNode } = boundActionCreators\n\n/**\n * Finds the name of all plugins which implement Gatsby APIs that\n * may create nodes, but which have not actually created any nodes.\n */\nfunction discoverPluginsWithoutNodes(storeState, nodes) {\n // Find out which plugins own already created nodes\n const nodeOwnerSet = new Set([`default-site-plugin`])\n nodes.forEach(node => nodeOwnerSet.add(node.internal.owner))\n\n return storeState.flattenedPlugins\n .filter(\n plugin =>\n // \"Can generate nodes\"\n plugin.nodeAPIs.includes(`sourceNodes`) &&\n // \"Has not generated nodes\"\n !nodeOwnerSet.has(plugin.name)\n )\n .map(plugin => plugin.name)\n}\n\n/**\n * Warn about plugins that should have created nodes but didn't.\n */\nfunction warnForPluginsWithoutNodes(state, nodes) {\n const pluginsWithNoNodes = discoverPluginsWithoutNodes(state, nodes)\n\n pluginsWithNoNodes.map(name =>\n report.warn(\n `The ${name} plugin has generated no Gatsby nodes. Do you need it?`\n )\n )\n}\n\n/**\n * Return the set of nodes for which its root node has not been touched\n */\nfunction getStaleNodes(state, nodes) {\n return nodes.filter(node => {\n let rootNode = node\n let whileCount = 0\n while (\n rootNode.parent &&\n getNode(rootNode.parent) !== undefined &&\n whileCount < 101\n ) {\n rootNode = getNode(rootNode.parent)\n whileCount += 1\n if (whileCount > 100) {\n console.log(\n `It looks like you have a node that's set its parent as itself`,\n rootNode\n )\n }\n }\n\n return !state.nodesTouched.has(rootNode.id)\n })\n}\n\n/**\n * Find all stale nodes and delete them\n */\nfunction deleteStaleNodes(state, nodes) {\n const staleNodes = getStaleNodes(state, nodes)\n\n if (staleNodes.length > 0) {\n staleNodes.forEach(node => deleteNode({ node }))\n }\n}\n\nmodule.exports = async ({ webhookBody = {}, parentSpan } = {}) => {\n await apiRunner(`sourceNodes`, {\n traceId: `initial-sourceNodes`,\n waitForCascadingActions: true,\n parentSpan,\n webhookBody,\n })\n\n const state = store.getState()\n const nodes = getNodes()\n\n warnForPluginsWithoutNodes(state, nodes)\n\n deleteStaleNodes(state, nodes)\n}\n"],"file":"source-nodes.js"}
\No newline at end of file