From e1c749de70bd8edd50a9c3f8bab6606a5e02a413 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 18 Nov 2022 13:54:06 +0200 Subject: [PATCH] fix: update projects in a deterministic order (#7) --- src/index.ts | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/index.ts b/src/index.ts index f4523b9..edba6a7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,8 +70,9 @@ export async function performUpdates< const { files } = update const formats = 'formats' in update ? { ...builtInFormatPlugins, ...update.formats } : builtInFormatPlugins - const promises = pkgs.flatMap(({ dir, manifest, writeProjectManifest }) => - Object.keys(files).map(async (fileKey) => { + const diffs = [] + for (const { dir, manifest, writeProjectManifest } of pkgs) { + for (const [fileKey, updateFile] of Object.entries(files)) { const updateTargetFile = !opts?.test const { file, formatPlugin } = parseFileKey(fileKey, formats) const resolvedPath = resolve(dir, file) @@ -83,12 +84,12 @@ export async function performUpdates< _writeProjectManifest: writeProjectManifest, } const actual = (await fileExists(resolvedPath)) ? await formatPlugin.read(formatHandlerOptions) : null - const expected = await formatPlugin.update(clone(actual), files[fileKey], formatHandlerOptions) + const expected = await formatPlugin.update(clone(actual), updateFile as any, formatHandlerOptions) const equal = (actual == null && expected == null) || (actual != null && expected != null && (await formatPlugin.equal(expected, actual, formatHandlerOptions))) if (equal) { - return + continue } if (updateTargetFile) { @@ -97,23 +98,14 @@ export async function performUpdates< } else { await formatPlugin.write(expected, formatHandlerOptions) } - return + continue } - return { actual, expected, path: resolvedPath } - }) - ) - - const diffs = await Promise.allSettled(promises) - const errors = diffs.flatMap((diff) => { - switch (diff.status) { - case 'fulfilled': - return diff.value ?? [] - case 'rejected': - return diff.reason + diffs.push({ actual, expected, path: resolvedPath }) } - }) - return errors.length > 0 ? errors : null + } + + return diffs.length > 0 ? diffs : null } function printJsonDiff(actual: unknown, expected: unknown, out: NodeJS.WriteStream) {