fix(dx): make gatsby id static for hot reloading (#44542)
* fix: make gatsby id static for hot reloading * fix: catch duplication of challenge.id * fix: handle CertificateNodes Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@ -1,7 +1,13 @@
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { blockNameify } = require('../../../utils/block-nameify');
|
const { blockNameify } = require('../../../utils/block-nameify');
|
||||||
|
|
||||||
function createChallengeNode(challenge, reporter) {
|
const createdIds = new Set();
|
||||||
|
|
||||||
|
function createChallengeNode(
|
||||||
|
challenge,
|
||||||
|
reporter,
|
||||||
|
{ isReloading } = { isReloading: false }
|
||||||
|
) {
|
||||||
// challengeType 11 is for video challenges (they only have instructions)
|
// challengeType 11 is for video challenges (they only have instructions)
|
||||||
// challengeType 7 is for certificates (they only have tests)
|
// challengeType 7 is for certificates (they only have tests)
|
||||||
// challengeType 12 is for CodeAlly/CodeRoad challenge
|
// challengeType 12 is for CodeAlly/CodeRoad challenge
|
||||||
@ -43,6 +49,18 @@ function createChallengeNode(challenge, reporter) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Challenge id should be unique for CertificateNodes, but not for
|
||||||
|
// ChallengeNodes
|
||||||
|
const id =
|
||||||
|
internal.type === 'ChallengeNode' ? challenge.fields.slug : challenge.id;
|
||||||
|
|
||||||
|
if (createdIds.has(id) && !isReloading) {
|
||||||
|
throw Error(`
|
||||||
|
Challenge slugs must be unique, but ${id} already exists.
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
createdIds.add(id);
|
||||||
|
|
||||||
return JSON.parse(
|
return JSON.parse(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
@ -54,7 +72,9 @@ function createChallengeNode(challenge, reporter) {
|
|||||||
sourceInstanceName: 'challenge'
|
sourceInstanceName: 'challenge'
|
||||||
},
|
},
|
||||||
{ challenge },
|
{ challenge },
|
||||||
{ id: crypto.randomUUID() }
|
{
|
||||||
|
id
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -45,7 +45,7 @@ exports.sourceNodes = function sourceChallengesSourceNodes(
|
|||||||
File changed at ${filePath}, replacing challengeNode id ${challenge.id}
|
File changed at ${filePath}, replacing challengeNode id ${challenge.id}
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
createVisibleChallenge(challenge);
|
createVisibleChallenge(challenge, { isReloading: true });
|
||||||
})
|
})
|
||||||
.catch(e =>
|
.catch(e =>
|
||||||
reporter.error(`fcc-replace-challenge
|
reporter.error(`fcc-replace-challenge
|
||||||
@ -111,8 +111,8 @@ ${e.message}
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createVisibleChallenge(challenge) {
|
function createVisibleChallenge(challenge, options) {
|
||||||
createNode(createChallengeNode(challenge, reporter));
|
createNode(createChallengeNode(challenge, reporter, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
Reference in New Issue
Block a user