Skip to content

Commit

Permalink
add gatsby version check
Browse files Browse the repository at this point in the history
  • Loading branch information
kathmbeck authored and matjack1 committed Dec 15, 2021
1 parent 30e1a76 commit a0447e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"promise-queue": "2.2.5",
"query-string": "6.14.1",
"regenerator-runtime": "^0.13.3",
"semver": "^7.3.5",
"unist-util-visit": "^2.0.3"
},
"keywords": [
Expand Down
23 changes: 19 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { SiteClient, Loader } = require('datocms-client');
const { getGatsbyVersion } = require("gatsby-core-utils");
const { lt, prerelease } = require("semver");

const CLIENT_HEADERS = {
'X-Reason': 'dump',
Expand Down Expand Up @@ -57,7 +59,15 @@ async function getLoader({ cache, loadStateFromCache, ...options }) {
return loader;
}

let nodeManifestWarningWasLogged;
let warnOnceForNoSupport = false;
let warnOnceToUpgradeGatsby = false;

const GATSBY_VERSION_MANIFEST_V2 = `4.3.0`
const gatsbyVersion = getGatsbyVersion()
const gatsbyVersionIsPrerelease = prerelease(gatsbyVersion)
const shouldUpgradeGatsbyVersion =
lt(gatsbyVersion, GATSBY_VERSION_MANIFEST_V2) && !gatsbyVersionIsPrerelease


const datocmsCreateNodeManifest = ({ node, context }) => {
try {
Expand All @@ -69,7 +79,12 @@ const datocmsCreateNodeManifest = ({ node, context }) => {
const shouldCreateNodeManifest = createNodeManifestIsSupported && nodeNeedsManifestCreated;

if (shouldCreateNodeManifest) {

if (shouldUpgradeGatsbyVersion && !warnOnceToUpgradeGatsby) {
console.warn(
`Your site is doing more work than it needs to for Preview, upgrade to Gatsby ^${GATSBY_VERSION_MANIFEST_V2} for better performance`
)
warnOnceToUpgradeGatsby = true
}
// Example manifestId: "34324203-2021-07-08T21:52:28.791+01:00"
const manifestId = `${node.entityPayload.id}-${updatedAt}`;

Expand All @@ -78,11 +93,11 @@ const datocmsCreateNodeManifest = ({ node, context }) => {
node,
updatedAt
});
} else if (!createNodeManifestIsSupported && !nodeManifestWarningWasLogged) {
} else if (!createNodeManifestIsSupported && !warnOnceForNoSupport) {
console.warn(
`DatoCMS: Your version of Gatsby core doesn't support Content Sync (via the unstable_createNodeManifest action). Please upgrade to the latest version to use Content Sync in your site.`,
);
nodeManifestWarningWasLogged = true;
warnOnceForNoSupport = true;
}
} catch (e) {
console.info(`Cannot create node manifest`, e.message);
Expand Down

0 comments on commit a0447e5

Please sign in to comment.