gatsby 4.7.1 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -45,26 +45,17 @@ async function findPageOwnedByNodeId({
|
|
|
45
45
|
} = state;
|
|
46
46
|
const {
|
|
47
47
|
byNode
|
|
48
|
-
} = state.queries; //
|
|
49
|
-
// So in development we can just use the Map of all pages (pagePath -> pageNode)
|
|
50
|
-
// but for builds (preview inc builds or regular builds) we will have a full map
|
|
51
|
-
// of all nodeId's to pages they're queried on and we can use that instead since it
|
|
52
|
-
// will be a much smaller list of pages, resulting in better performance for large sites
|
|
53
|
-
|
|
54
|
-
const usingPagesMap = `development` === process.env.NODE_ENV;
|
|
55
|
-
const pagePathSetOrMap = usingPagesMap ? // this is a Map of page path to page node
|
|
56
|
-
pages : // this is a Set of page paths
|
|
57
|
-
byNode === null || byNode === void 0 ? void 0 : byNode.get(nodeId); // the default page path is the first page found in
|
|
48
|
+
} = state.queries; // the default page path is the first page found in
|
|
58
49
|
// node id to page query tracking
|
|
59
50
|
|
|
60
51
|
let pagePath = byNode === null || byNode === void 0 ? void 0 : (_byNode$get = byNode.get(nodeId)) === null || _byNode$get === void 0 ? void 0 : (_byNode$get$values = _byNode$get.values()) === null || _byNode$get$values === void 0 ? void 0 : (_byNode$get$values$ne = _byNode$get$values.next()) === null || _byNode$get$values$ne === void 0 ? void 0 : _byNode$get$values$ne.value;
|
|
61
52
|
let foundPageBy = pagePath ? `queryTracking` : `none`;
|
|
62
53
|
|
|
63
|
-
if (
|
|
54
|
+
if (pages) {
|
|
64
55
|
let ownerPagePath;
|
|
65
56
|
let foundOwnerNodeId = false; // for each page this nodeId is queried in
|
|
66
57
|
|
|
67
|
-
for (const
|
|
58
|
+
for (const pageObject of pages.values()) {
|
|
68
59
|
// if we haven't found a page with this nodeId
|
|
69
60
|
// set as page.ownerNodeId then run this logic.
|
|
70
61
|
// this condition is on foundOwnerNodeId instead of ownerPagePath
|
|
@@ -76,9 +67,7 @@ async function findPageOwnedByNodeId({
|
|
|
76
67
|
break;
|
|
77
68
|
}
|
|
78
69
|
|
|
79
|
-
const path =
|
|
80
|
-
pathOrPageObject.path : // in builds we're using a Set so the page path is the value
|
|
81
|
-
pathOrPageObject;
|
|
70
|
+
const path = pageObject.path;
|
|
82
71
|
const fullPage = pages.get(path);
|
|
83
72
|
foundOwnerNodeId = (fullPage === null || fullPage === void 0 ? void 0 : fullPage.ownerNodeId) === nodeId;
|
|
84
73
|
const foundPageIdInContext = (fullPage === null || fullPage === void 0 ? void 0 : fullPage.context.id) === nodeId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/node-manifest.ts"],"names":["findPageOwnedByNodeId","nodeId","state","store","getState","pages","nodes","byNode","queries","usingPagesMap","process","env","NODE_ENV","pagePathSetOrMap","get","pagePath","values","next","value","foundPageBy","ownerPagePath","foundOwnerNodeId","pathOrPageObject","path","fullPage","ownerNodeId","foundPageIdInContext","context","id","pageCreatedByPluginName","pluginCreatorId","name","pageCreatedByFilesystemPlugin","page","foundPageByToLogIds","none","queryTracking","warnAboutNodeManifestMappingProblems","inputManifest","verbose","logId","reporter","error","Error","processNodeManifest","listOfUniqueErrorIds","nodeManifestPagePathMap","verboseLogs","node","fullNode","noNodeWarningId","pluginName","add","nodeManifestPage","nodeManifestMappingProblemsContext","finalManifest","gatsbySiteDirectory","program","directory","fileNameBase","manifestId","platform","replace","manifestFilePath","join","manifestFileDir","dirname","fs","ensureDir","writeJSON","info","set","processNodeManifests","gatsby_log_level","VERBOSE_NODE_MANIFEST","startTime","Date","now","nodeManifests","totalManifests","length","totalProcessedManifests","totalFailedManifests","Map","Set","processNodeManifestTask","manifest","cb","processedManifest","setImmediate","processNodeManifestQueue","push","idle","Promise","resolve","drain","pluralize","endTime","size","dispatch","internalActions","deleteNodeManifests"],"mappings":";;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAyBA;AACA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,IAAAA,YAAY,CAAC,MAAMF,EAAE,CAAC,IAAD,EAAO,IAAP,CAAT,CAAZ;AACA;AACD;;AAED,QAAMG,wBAAwB,GAAG,oBAAML,uBAAN,EAA+B,EAA/B,CAAjC;;AAEA,OAAK,MAAMC,QAAX,IAAuBR,aAAvB,EAAsC;AACpCY,IAAAA,wBAAwB,CAACC,IAAzB,CAA8BL,QAA9B,EAAwC,MAAM,CAAE,CAAhD;AACD;;AAED,MAAI,CAACI,wBAAwB,CAACE,IAAzB,EAAL,EAAsC;AACpC,UAAM,IAAIC,OAAJ,CAAYC,OAAO,IAAI;AAC3BJ,MAAAA,wBAAwB,CAACK,KAAzB,GAAiCD,OAAjC;AACD,KAFK,CAAN;AAGD;;AAED,QAAME,SAAS,GAAIhB,MAAD,IAChBA,MAAM,GAAG,CAAT,IAAcA,MAAM,KAAK,CAAzB,GAA8B,GAA9B,GAAoC,EADtC;;AAGA,QAAMiB,OAAO,GAAGrB,IAAI,CAACC,GAAL,EAAhB;;AAEApC,oBAAS6B,IAAT,CACG,aAAYW,uBAAwB,2BAA0Be,SAAS,CACtEf,uBADsE,CAEtE,OAAMgB,OAAO,GAAGtB,SAAU,QAC1BO,oBAAoB,GAAG,CAAvB,GACK,KAAIA,oBAAqB,YAAWc,SAAS,CAC5Cd,oBAD4C,CAE5C,yBAHN,GAIK,EACN,EATH;;AAYAzC,oBAAS6B,IAAT,CACE,CAAC,CAACvB,WAAD,IAAgBF,oBAAoB,CAACqD,IAArB,GAA4B,CAA5C,GACI,kDAAiD,CAChD,GAAGrD,oBAD6C,EAEhDmB,IAFgD,CAE1C,IAF0C,CAErC,KAHhB,GAII,EAJL,IAKG,uJANL,EAvEQ,CAgFR;;;AACA7D,eAAMgG,QAAN,CAAeC,yBAAgBC,mBAAhB,EAAf;;AACA,SAAOvD,uBAAP;AACD","sourcesContent":["import type { ErrorId } from \"gatsby-cli/lib/structured-errors/error-map\"\nimport { getNode } from \"./../datastore\"\nimport { IGatsbyPage, INodeManifest } from \"./../redux/types\"\nimport reporter from \"gatsby-cli/lib/reporter\"\nimport { store } from \"../redux/\"\nimport { internalActions } from \"../redux/actions\"\nimport path from \"path\"\nimport fs from \"fs-extra\"\nimport fastq from \"fastq\"\n\ninterface INodeManifestPage {\n path?: string\n}\n\n/**\n * This it the output after processing calls to the public unstable_createNodeManifest action\n */\ninterface INodeManifestOut {\n page: INodeManifestPage\n node: {\n id: string\n }\n foundPageBy: FoundPageBy\n}\n\ntype FoundPageBy =\n | `ownerNodeId`\n | `filesystem-route-api`\n // for these three we warn to use ownerNodeId instead\n | `context.id`\n | `queryTracking`\n | `none`\n\n/**\n * Finds a final built page by nodeId\n *\n * Note that this function wont work properly in `gatsby develop`\n * since develop no longer runs all page queries when creating pages.\n * We use the node id to query mapping to find the right page but\n * this mapping only exists once you've visited a page in your browser.\n * When this fn is being used for routing to previews the user wont necessarily have\n * visited the page in the browser yet.\n */\nasync function findPageOwnedByNodeId({ nodeId }: { nodeId: string }): Promise<{\n page: INodeManifestPage\n foundPageBy: FoundPageBy\n}> {\n const state = store.getState()\n const { pages, nodes } = state\n const { byNode } = state.queries\n\n // in development queries are run on demand so we wont have an accurate nodeId->pages map until those pages are visited in the browser. We want this mapping before the page is visited in the browser so we can route to the right page in the browser.\n // So in development we can just use the Map of all pages (pagePath -> pageNode)\n // but for builds (preview inc builds or regular builds) we will have a full map\n // of all nodeId's to pages they're queried on and we can use that instead since it\n // will be a much smaller list of pages, resulting in better performance for large sites\n const usingPagesMap: boolean = `development` === process.env.NODE_ENV\n\n const pagePathSetOrMap = usingPagesMap\n ? // this is a Map of page path to page node\n pages\n : // this is a Set of page paths\n byNode?.get(nodeId)\n\n // the default page path is the first page found in\n // node id to page query tracking\n\n let pagePath = byNode?.get(nodeId)?.values()?.next()?.value\n\n let foundPageBy: FoundPageBy = pagePath ? `queryTracking` : `none`\n\n if (pagePathSetOrMap) {\n let ownerPagePath: string | undefined\n let foundOwnerNodeId = false\n\n // for each page this nodeId is queried in\n for (const pathOrPageObject of pagePathSetOrMap.values()) {\n // if we haven't found a page with this nodeId\n // set as page.ownerNodeId then run this logic.\n // this condition is on foundOwnerNodeId instead of ownerPagePath\n // in case we find a page with the nodeId in page.context.id\n // and then later in the loop there's a page with this nodeId\n // set on page.ownerNodeId.\n // We always want to prefer ownerPagePath over context.id\n if (foundOwnerNodeId) {\n break\n }\n\n const path = (\n usingPagesMap\n ? // in development we're using a Map, so the value here is a page object\n (pathOrPageObject as IGatsbyPage).path\n : // in builds we're using a Set so the page path is the value\n pathOrPageObject\n ) as string\n\n const fullPage: IGatsbyPage | undefined = pages.get(path)\n\n foundOwnerNodeId = fullPage?.ownerNodeId === nodeId\n\n const foundPageIdInContext = fullPage?.context.id === nodeId\n\n if (foundOwnerNodeId) {\n foundPageBy = `ownerNodeId`\n } else if (foundPageIdInContext && fullPage) {\n const pageCreatedByPluginName = nodes.get(\n fullPage.pluginCreatorId\n )?.name\n\n const pageCreatedByFilesystemPlugin =\n pageCreatedByPluginName === `gatsby-plugin-page-creator`\n\n foundPageBy = pageCreatedByFilesystemPlugin\n ? `filesystem-route-api`\n : `context.id`\n }\n\n if (\n fullPage &&\n // first check for the ownerNodeId on the page. this is\n // the defacto owner. Can't get more specific than this\n (foundOwnerNodeId ||\n // if there's no specified owner look to see if\n // pageContext has an `id` variable which matches our\n // nodeId. Using an \"id\" as a variable in queries is common\n // and if we don't have an owner this is a better guess\n // of an owner than grabbing the first page query we find\n // that's mapped to this node id.\n // this also makes this work with the filesystem Route API without\n // changing that API.\n foundPageIdInContext)\n ) {\n // save this path to use in our manifest!\n ownerPagePath = fullPage.path\n }\n }\n\n if (ownerPagePath) {\n pagePath = ownerPagePath\n }\n }\n\n return {\n page: {\n path: pagePath || null,\n },\n foundPageBy,\n }\n}\n\n// these id's correspond to error id's in\n// packages/gatsby-cli/src/structured-errors/error-map.ts\nexport const foundPageByToLogIds = {\n none: `11801`,\n [`context.id`]: `11802`,\n queryTracking: `11803`,\n [`filesystem-route-api`]: `success`,\n ownerNodeId: `success`,\n}\n\n/**\n * Takes in some info about a node manifest and the page we did or didn't find for it, then warns and returns the warning string\n */\nexport function warnAboutNodeManifestMappingProblems({\n inputManifest,\n pagePath,\n foundPageBy,\n verbose,\n}: {\n inputManifest: INodeManifest\n pagePath?: string\n foundPageBy: FoundPageBy\n verbose: boolean\n}): { logId: string } {\n let logId: ErrorId | `success`\n\n switch (foundPageBy) {\n case `none`:\n case `context.id`:\n case `queryTracking`: {\n logId = foundPageByToLogIds[foundPageBy]\n if (verbose) {\n reporter.error({\n id: logId,\n context: {\n inputManifest,\n pagePath,\n },\n })\n }\n break\n }\n\n case `filesystem-route-api`:\n case `ownerNodeId`:\n logId = `success`\n break\n\n default: {\n throw Error(`Node Manifest mapping is in an impossible state`)\n }\n }\n\n return {\n logId,\n }\n}\n\n/**\n * Prepares and then writes out an individual node manifest file to be used for routing to previews. Manifest files are added via the public unstable_createNodeManifest action\n */\nexport async function processNodeManifest(\n inputManifest: INodeManifest,\n listOfUniqueErrorIds: Set<string>,\n nodeManifestPagePathMap: Map<string, string>,\n verboseLogs: boolean\n): Promise<null | INodeManifestOut> {\n const nodeId = inputManifest.node.id\n const fullNode = getNode(nodeId)\n const noNodeWarningId = `11804`\n\n if (!fullNode) {\n if (verboseLogs) {\n reporter.error({\n id: noNodeWarningId,\n context: {\n pluginName: inputManifest.pluginName,\n nodeId,\n },\n })\n } else {\n listOfUniqueErrorIds.add(noNodeWarningId)\n }\n\n return null\n }\n\n // map the node to a page that was created\n const { page: nodeManifestPage, foundPageBy } = await findPageOwnedByNodeId({\n nodeId,\n })\n\n const nodeManifestMappingProblemsContext = {\n inputManifest,\n pagePath: nodeManifestPage.path,\n foundPageBy,\n verbose: verboseLogs,\n }\n\n if (verboseLogs) {\n warnAboutNodeManifestMappingProblems(nodeManifestMappingProblemsContext)\n } else {\n const { logId } = warnAboutNodeManifestMappingProblems(\n nodeManifestMappingProblemsContext\n )\n\n if (logId !== `success`) {\n listOfUniqueErrorIds.add(logId)\n }\n }\n\n const finalManifest: INodeManifestOut = {\n node: inputManifest.node,\n page: nodeManifestPage,\n foundPageBy,\n }\n\n const gatsbySiteDirectory = store.getState().program.directory\n\n let fileNameBase = inputManifest.manifestId\n\n /**\n * Windows has a handful of special/reserved characters that are not valid in a file path\n * @reference https://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os\n *\n * The two exceptions to the list linked above are\n * - the colon that is part of the hard disk partition name at the beginning of a file path (i.e. C:)\n * - backslashes. We don't want to replace backslashes because those are used to delineate what the actual file path is\n *\n * During local development, node manifests can be written to disk but are generally unused as they are only used\n * for Content Sync which runs in Gatsby Cloud. Gatsby cloud is a Linux environment in which these special chars are valid in\n * filepaths. To avoid errors on Windows, we replace all instances of the special chars in the filepath (with the exception of the\n * hard disk partition name) with \"-\" to ensure that local Windows development setups do not break when attempting\n * to write one of these manifests to disk.\n */\n if (process.platform === `win32`) {\n fileNameBase = fileNameBase.replace(/:|\\/|\\*|\\?|\"|<|>|\\||\\\\/g, `-`)\n }\n\n // write out the manifest file\n const manifestFilePath = path.join(\n gatsbySiteDirectory,\n `public`,\n `__node-manifests`,\n inputManifest.pluginName,\n `${fileNameBase}.json`\n )\n\n const manifestFileDir = path.dirname(manifestFilePath)\n\n await fs.ensureDir(manifestFileDir)\n await fs.writeJSON(manifestFilePath, finalManifest)\n\n if (verboseLogs) {\n reporter.info(\n `Plugin ${inputManifest.pluginName} created a manifest with the id ${fileNameBase}`\n )\n }\n\n if (nodeManifestPage.path) {\n nodeManifestPagePathMap.set(nodeManifestPage.path, fileNameBase)\n }\n\n return finalManifest\n}\n\n/**\n * Grabs all pending node manifests, processes them, writes them to disk,\n * and then removes them from the store.\n * Manifest files are added via the public unstable_createNodeManifest action in sourceNodes\n */\nexport async function processNodeManifests(): Promise<Map<\n string,\n string\n> | null> {\n const verboseLogs =\n process.env.gatsby_log_level === `verbose` ||\n process.env.VERBOSE_NODE_MANIFEST === `true`\n\n const startTime = Date.now()\n const { nodeManifests } = store.getState()\n\n const totalManifests = nodeManifests.length\n\n if (totalManifests === 0) {\n return null\n }\n\n let totalProcessedManifests = 0\n let totalFailedManifests = 0\n const nodeManifestPagePathMap: Map<string, string> = new Map()\n const listOfUniqueErrorIds: Set<string> = new Set()\n\n async function processNodeManifestTask(\n manifest: INodeManifest,\n cb: fastq.done<any>\n ): Promise<void> {\n const processedManifest = await processNodeManifest(\n manifest,\n listOfUniqueErrorIds,\n nodeManifestPagePathMap,\n verboseLogs\n )\n\n if (processedManifest) {\n totalProcessedManifests++\n } else {\n totalFailedManifests++\n }\n\n // `setImmediate` below is a workaround against stack overflow\n // occurring when there are many manifests\n setImmediate(() => cb(null, true))\n return\n }\n\n const processNodeManifestQueue = fastq(processNodeManifestTask, 25)\n\n for (const manifest of nodeManifests) {\n processNodeManifestQueue.push(manifest, () => {})\n }\n\n if (!processNodeManifestQueue.idle()) {\n await new Promise(resolve => {\n processNodeManifestQueue.drain = resolve as () => unknown\n })\n }\n\n const pluralize = (length: number): string =>\n length > 1 || length === 0 ? `s` : ``\n\n const endTime = Date.now()\n\n reporter.info(\n `Wrote out ${totalProcessedManifests} node page manifest file${pluralize(\n totalProcessedManifests\n )} in ${endTime - startTime} ms. ${\n totalFailedManifests > 0\n ? `. ${totalFailedManifests} manifest${pluralize(\n totalFailedManifests\n )} couldn't be processed.`\n : ``\n }`\n )\n\n reporter.info(\n (!verboseLogs && listOfUniqueErrorIds.size > 0\n ? `unstable_createNodeManifest produced warnings [${[\n ...listOfUniqueErrorIds,\n ].join(`, `)}]. `\n : ``) +\n `To see full warning messages set process.env.VERBOSE_NODE_MANIFEST to \"true\".\\nVisit https://gatsby.dev/nodemanifest for more info on Node Manifests.`\n )\n\n // clean up all pending manifests from the store\n store.dispatch(internalActions.deleteNodeManifests())\n return nodeManifestPagePathMap\n}\n"],"file":"node-manifest.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/node-manifest.ts"],"names":["findPageOwnedByNodeId","nodeId","state","store","getState","pages","nodes","byNode","queries","pagePath","get","values","next","value","foundPageBy","ownerPagePath","foundOwnerNodeId","pageObject","path","fullPage","ownerNodeId","foundPageIdInContext","context","id","pageCreatedByPluginName","pluginCreatorId","name","pageCreatedByFilesystemPlugin","page","foundPageByToLogIds","none","queryTracking","warnAboutNodeManifestMappingProblems","inputManifest","verbose","logId","reporter","error","Error","processNodeManifest","listOfUniqueErrorIds","nodeManifestPagePathMap","verboseLogs","node","fullNode","noNodeWarningId","pluginName","add","nodeManifestPage","nodeManifestMappingProblemsContext","finalManifest","gatsbySiteDirectory","program","directory","fileNameBase","manifestId","process","platform","replace","manifestFilePath","join","manifestFileDir","dirname","fs","ensureDir","writeJSON","info","set","processNodeManifests","env","gatsby_log_level","VERBOSE_NODE_MANIFEST","startTime","Date","now","nodeManifests","totalManifests","length","totalProcessedManifests","totalFailedManifests","Map","Set","processNodeManifestTask","manifest","cb","processedManifest","setImmediate","processNodeManifestQueue","push","idle","Promise","resolve","drain","pluralize","endTime","size","dispatch","internalActions","deleteNodeManifests"],"mappings":";;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAyBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeA,qBAAf,CAAqC;AAAEC,EAAAA;AAAF,CAArC,EAGG;AAAA;;AACD,QAAMC,KAAK,GAAGC,aAAMC,QAAN,EAAd;;AACA,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAmBJ,KAAzB;AACA,QAAM;AAAEK,IAAAA;AAAF,MAAaL,KAAK,CAACM,OAAzB,CAHC,CAKD;AACA;;AACA,MAAIC,QAAQ,GAAGF,MAAH,aAAGA,MAAH,sCAAGA,MAAM,CAAEG,GAAR,CAAYT,MAAZ,CAAH,sEAAG,YAAqBU,MAArB,EAAH,gFAAG,mBAA+BC,IAA/B,EAAH,0DAAG,sBAAuCC,KAAtD;AAEA,MAAIC,WAAwB,GAAGL,QAA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N,EATH;;AAYA3C,oBAAS8B,IAAT,CACE,CAAC,CAACxB,WAAD,IAAgBF,oBAAoB,CAACuD,IAArB,GAA4B,CAA5C,GACI,kDAAiD,CAChD,GAAGvD,oBAD6C,EAEhDoB,IAFgD,CAE1C,IAF0C,CAErC,KAHhB,GAII,EAJL,IAKG,uJANL,EAvEQ,CAgFR;;;AACAzD,eAAM6F,QAAN,CAAeC,yBAAgBC,mBAAhB,EAAf;;AACA,SAAOzD,uBAAP;AACD","sourcesContent":["import type { ErrorId } from \"gatsby-cli/lib/structured-errors/error-map\"\nimport { getNode } from \"./../datastore\"\nimport { IGatsbyPage, INodeManifest } from \"./../redux/types\"\nimport reporter from \"gatsby-cli/lib/reporter\"\nimport { store } from \"../redux/\"\nimport { internalActions } from \"../redux/actions\"\nimport path from \"path\"\nimport fs from \"fs-extra\"\nimport fastq from \"fastq\"\n\ninterface INodeManifestPage {\n path?: string\n}\n\n/**\n * This it the output after processing calls to the public unstable_createNodeManifest action\n */\ninterface INodeManifestOut {\n page: INodeManifestPage\n node: {\n id: string\n }\n foundPageBy: FoundPageBy\n}\n\ntype FoundPageBy =\n | `ownerNodeId`\n | `filesystem-route-api`\n // for these three we warn to use ownerNodeId instead\n | `context.id`\n | `queryTracking`\n | `none`\n\n/**\n * Finds a final built page by nodeId\n *\n * Note that this function wont work properly in `gatsby develop`\n * since develop no longer runs all page queries when creating pages.\n * We use the node id to query mapping to find the right page but\n * this mapping only exists once you've visited a page in your browser.\n * When this fn is being used for routing to previews the user wont necessarily have\n * visited the page in the browser yet.\n */\nasync function findPageOwnedByNodeId({ nodeId }: { nodeId: string }): Promise<{\n page: INodeManifestPage\n foundPageBy: FoundPageBy\n}> {\n const state = store.getState()\n const { pages, nodes } = state\n const { byNode } = state.queries\n\n // the default page path is the first page found in\n // node id to page query tracking\n let pagePath = byNode?.get(nodeId)?.values()?.next()?.value\n\n let foundPageBy: FoundPageBy = pagePath ? `queryTracking` : `none`\n\n if (pages) {\n let ownerPagePath: string | undefined\n let foundOwnerNodeId = false\n\n // for each page this nodeId is queried in\n for (const pageObject of pages.values()) {\n // if we haven't found a page with this nodeId\n // set as page.ownerNodeId then run this logic.\n // this condition is on foundOwnerNodeId instead of ownerPagePath\n // in case we find a page with the nodeId in page.context.id\n // and then later in the loop there's a page with this nodeId\n // set on page.ownerNodeId.\n // We always want to prefer ownerPagePath over context.id\n if (foundOwnerNodeId) {\n break\n }\n\n const path = pageObject.path\n\n const fullPage: IGatsbyPage | undefined = pages.get(path)\n\n foundOwnerNodeId = fullPage?.ownerNodeId === nodeId\n\n const foundPageIdInContext = fullPage?.context.id === nodeId\n\n if (foundOwnerNodeId) {\n foundPageBy = `ownerNodeId`\n } else if (foundPageIdInContext && fullPage) {\n const pageCreatedByPluginName = nodes.get(\n fullPage.pluginCreatorId\n )?.name\n\n const pageCreatedByFilesystemPlugin =\n pageCreatedByPluginName === `gatsby-plugin-page-creator`\n\n foundPageBy = pageCreatedByFilesystemPlugin\n ? `filesystem-route-api`\n : `context.id`\n }\n\n if (\n fullPage &&\n // first check for the ownerNodeId on the page. this is\n // the defacto owner. Can't get more specific than this\n (foundOwnerNodeId ||\n // if there's no specified owner look to see if\n // pageContext has an `id` variable which matches our\n // nodeId. Using an \"id\" as a variable in queries is common\n // and if we don't have an owner this is a better guess\n // of an owner than grabbing the first page query we find\n // that's mapped to this node id.\n // this also makes this work with the filesystem Route API without\n // changing that API.\n foundPageIdInContext)\n ) {\n // save this path to use in our manifest!\n ownerPagePath = fullPage.path\n }\n }\n\n if (ownerPagePath) {\n pagePath = ownerPagePath\n }\n }\n\n return {\n page: {\n path: pagePath || null,\n },\n foundPageBy,\n }\n}\n\n// these id's correspond to error id's in\n// packages/gatsby-cli/src/structured-errors/error-map.ts\nexport const foundPageByToLogIds = {\n none: `11801`,\n [`context.id`]: `11802`,\n queryTracking: `11803`,\n [`filesystem-route-api`]: `success`,\n ownerNodeId: `success`,\n}\n\n/**\n * Takes in some info about a node manifest and the page we did or didn't find for it, then warns and returns the warning string\n */\nexport function warnAboutNodeManifestMappingProblems({\n inputManifest,\n pagePath,\n foundPageBy,\n verbose,\n}: {\n inputManifest: INodeManifest\n pagePath?: string\n foundPageBy: FoundPageBy\n verbose: boolean\n}): { logId: string } {\n let logId: ErrorId | `success`\n\n switch (foundPageBy) {\n case `none`:\n case `context.id`:\n case `queryTracking`: {\n logId = foundPageByToLogIds[foundPageBy]\n if (verbose) {\n reporter.error({\n id: logId,\n context: {\n inputManifest,\n pagePath,\n },\n })\n }\n break\n }\n\n case `filesystem-route-api`:\n case `ownerNodeId`:\n logId = `success`\n break\n\n default: {\n throw Error(`Node Manifest mapping is in an impossible state`)\n }\n }\n\n return {\n logId,\n }\n}\n\n/**\n * Prepares and then writes out an individual node manifest file to be used for routing to previews. Manifest files are added via the public unstable_createNodeManifest action\n */\nexport async function processNodeManifest(\n inputManifest: INodeManifest,\n listOfUniqueErrorIds: Set<string>,\n nodeManifestPagePathMap: Map<string, string>,\n verboseLogs: boolean\n): Promise<null | INodeManifestOut> {\n const nodeId = inputManifest.node.id\n const fullNode = getNode(nodeId)\n const noNodeWarningId = `11804`\n\n if (!fullNode) {\n if (verboseLogs) {\n reporter.error({\n id: noNodeWarningId,\n context: {\n pluginName: inputManifest.pluginName,\n nodeId,\n },\n })\n } else {\n listOfUniqueErrorIds.add(noNodeWarningId)\n }\n\n return null\n }\n\n // map the node to a page that was created\n const { page: nodeManifestPage, foundPageBy } = await findPageOwnedByNodeId({\n nodeId,\n })\n\n const nodeManifestMappingProblemsContext = {\n inputManifest,\n pagePath: nodeManifestPage.path,\n foundPageBy,\n verbose: verboseLogs,\n }\n\n if (verboseLogs) {\n warnAboutNodeManifestMappingProblems(nodeManifestMappingProblemsContext)\n } else {\n const { logId } = warnAboutNodeManifestMappingProblems(\n nodeManifestMappingProblemsContext\n )\n\n if (logId !== `success`) {\n listOfUniqueErrorIds.add(logId)\n }\n }\n\n const finalManifest: INodeManifestOut = {\n node: inputManifest.node,\n page: nodeManifestPage,\n foundPageBy,\n }\n\n const gatsbySiteDirectory = store.getState().program.directory\n\n let fileNameBase = inputManifest.manifestId\n\n /**\n * Windows has a handful of special/reserved characters that are not valid in a file path\n * @reference https://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os\n *\n * The two exceptions to the list linked above are\n * - the colon that is part of the hard disk partition name at the beginning of a file path (i.e. C:)\n * - backslashes. We don't want to replace backslashes because those are used to delineate what the actual file path is\n *\n * During local development, node manifests can be written to disk but are generally unused as they are only used\n * for Content Sync which runs in Gatsby Cloud. Gatsby cloud is a Linux environment in which these special chars are valid in\n * filepaths. To avoid errors on Windows, we replace all instances of the special chars in the filepath (with the exception of the\n * hard disk partition name) with \"-\" to ensure that local Windows development setups do not break when attempting\n * to write one of these manifests to disk.\n */\n if (process.platform === `win32`) {\n fileNameBase = fileNameBase.replace(/:|\\/|\\*|\\?|\"|<|>|\\||\\\\/g, `-`)\n }\n\n // write out the manifest file\n const manifestFilePath = path.join(\n gatsbySiteDirectory,\n `public`,\n `__node-manifests`,\n inputManifest.pluginName,\n `${fileNameBase}.json`\n )\n\n const manifestFileDir = path.dirname(manifestFilePath)\n\n await fs.ensureDir(manifestFileDir)\n await fs.writeJSON(manifestFilePath, finalManifest)\n\n if (verboseLogs) {\n reporter.info(\n `Plugin ${inputManifest.pluginName} created a manifest with the id ${fileNameBase}`\n )\n }\n\n if (nodeManifestPage.path) {\n nodeManifestPagePathMap.set(nodeManifestPage.path, fileNameBase)\n }\n\n return finalManifest\n}\n\n/**\n * Grabs all pending node manifests, processes them, writes them to disk,\n * and then removes them from the store.\n * Manifest files are added via the public unstable_createNodeManifest action in sourceNodes\n */\nexport async function processNodeManifests(): Promise<Map<\n string,\n string\n> | null> {\n const verboseLogs =\n process.env.gatsby_log_level === `verbose` ||\n process.env.VERBOSE_NODE_MANIFEST === `true`\n\n const startTime = Date.now()\n const { nodeManifests } = store.getState()\n\n const totalManifests = nodeManifests.length\n\n if (totalManifests === 0) {\n return null\n }\n\n let totalProcessedManifests = 0\n let totalFailedManifests = 0\n const nodeManifestPagePathMap: Map<string, string> = new Map()\n const listOfUniqueErrorIds: Set<string> = new Set()\n\n async function processNodeManifestTask(\n manifest: INodeManifest,\n cb: fastq.done<any>\n ): Promise<void> {\n const processedManifest = await processNodeManifest(\n manifest,\n listOfUniqueErrorIds,\n nodeManifestPagePathMap,\n verboseLogs\n )\n\n if (processedManifest) {\n totalProcessedManifests++\n } else {\n totalFailedManifests++\n }\n\n // `setImmediate` below is a workaround against stack overflow\n // occurring when there are many manifests\n setImmediate(() => cb(null, true))\n return\n }\n\n const processNodeManifestQueue = fastq(processNodeManifestTask, 25)\n\n for (const manifest of nodeManifests) {\n processNodeManifestQueue.push(manifest, () => {})\n }\n\n if (!processNodeManifestQueue.idle()) {\n await new Promise(resolve => {\n processNodeManifestQueue.drain = resolve as () => unknown\n })\n }\n\n const pluralize = (length: number): string =>\n length > 1 || length === 0 ? `s` : ``\n\n const endTime = Date.now()\n\n reporter.info(\n `Wrote out ${totalProcessedManifests} node page manifest file${pluralize(\n totalProcessedManifests\n )} in ${endTime - startTime} ms. ${\n totalFailedManifests > 0\n ? `. ${totalFailedManifests} manifest${pluralize(\n totalFailedManifests\n )} couldn't be processed.`\n : ``\n }`\n )\n\n reporter.info(\n (!verboseLogs && listOfUniqueErrorIds.size > 0\n ? `unstable_createNodeManifest produced warnings [${[\n ...listOfUniqueErrorIds,\n ].join(`, `)}]. `\n : ``) +\n `To see full warning messages set process.env.VERBOSE_NODE_MANIFEST to \"true\".\\nVisit https://gatsby.dev/nodemanifest for more info on Node Manifests.`\n )\n\n // clean up all pending manifests from the store\n store.dispatch(internalActions.deleteNodeManifests())\n return nodeManifestPagePathMap\n}\n"],"file":"node-manifest.js"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby",
|
|
3
3
|
"description": "Blazing fast modern site generator for React",
|
|
4
|
-
"version": "4.7.
|
|
4
|
+
"version": "4.7.2",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gatsby": "./cli.js"
|
|
@@ -263,5 +263,5 @@
|
|
|
263
263
|
"yargs": {
|
|
264
264
|
"boolean-negation": false
|
|
265
265
|
},
|
|
266
|
-
"gitHead": "
|
|
266
|
+
"gitHead": "db835237140023a9a09207180ea2cf0a5a3afe22"
|
|
267
267
|
}
|