diff --git a/shared/utils/polyvinyl.ts b/shared/utils/polyvinyl.ts index c29bca04a78..135ef92191c 100644 --- a/shared/utils/polyvinyl.ts +++ b/shared/utils/polyvinyl.ts @@ -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 ) { 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) { +export function createSource( + poly: Pick & Rest +): Rest & { contents: string; source: string } { return { ...poly, - source: poly.source || poly.contents + source: poly.source ?? poly.contents }; }