mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-25 02:14:11 -05:00
fix: optionally keep source if setting file contents (#58747)
Co-authored-by: Naomi <accounts+github@nhcarrigan.com>
This commit is contained in:
committed by
GitHub
parent
e34e63176a
commit
71e39308a4
@@ -21,7 +21,7 @@ export interface ChallengeFile extends IncompleteChallengeFile {
|
||||
head: string;
|
||||
tail: string;
|
||||
seed?: string;
|
||||
source?: string | null;
|
||||
source?: string;
|
||||
path: string;
|
||||
history: string[];
|
||||
}
|
||||
@@ -105,16 +105,17 @@ function checkPoly(poly: ChallengeFile) {
|
||||
);
|
||||
}
|
||||
|
||||
// setContent will lose source if set
|
||||
// setContent will lose source if not supplied
|
||||
export function setContent(
|
||||
contents: string,
|
||||
poly: ChallengeFile
|
||||
poly: ChallengeFile,
|
||||
source?: string
|
||||
): ChallengeFile {
|
||||
checkPoly(poly);
|
||||
return {
|
||||
...poly,
|
||||
contents,
|
||||
source: null
|
||||
source
|
||||
};
|
||||
}
|
||||
|
||||
@@ -161,9 +162,7 @@ export async function transformContents(
|
||||
polyP: ChallengeFile | Promise<ChallengeFile>
|
||||
) {
|
||||
const poly = await polyP;
|
||||
const newPoly = setContent(await wrap(poly.contents), poly);
|
||||
// if no source exist, set the original contents as source
|
||||
newPoly.source = poly.source || poly.contents;
|
||||
const newPoly = setContent(await wrap(poly.contents), poly, poly.source);
|
||||
return newPoly;
|
||||
}
|
||||
|
||||
@@ -183,9 +182,11 @@ export async function transformHeadTailAndContents(
|
||||
}
|
||||
|
||||
// createSource(poly: PolyVinyl) => PolyVinyl
|
||||
export function createSource(poly: Pick<ChallengeFile, 'contents' | 'source'>) {
|
||||
export function createSource<Rest>(
|
||||
poly: Pick<ChallengeFile, 'contents' | 'source'> & Rest
|
||||
): Rest & { contents: string; source: string } {
|
||||
return {
|
||||
...poly,
|
||||
source: poly.source || poly.contents
|
||||
source: poly.source ?? poly.contents
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user