Skip to content

Commit e1c749d

Browse files
authored
fix: update projects in a deterministic order (#7)
1 parent 3f101b4 commit e1c749d

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/index.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ export async function performUpdates<
7070
const { files } = update
7171
const formats = 'formats' in update ? { ...builtInFormatPlugins, ...update.formats } : builtInFormatPlugins
7272

73-
const promises = pkgs.flatMap(({ dir, manifest, writeProjectManifest }) =>
74-
Object.keys(files).map(async (fileKey) => {
73+
const diffs = []
74+
for (const { dir, manifest, writeProjectManifest } of pkgs) {
75+
for (const [fileKey, updateFile] of Object.entries(files)) {
7576
const updateTargetFile = !opts?.test
7677
const { file, formatPlugin } = parseFileKey(fileKey, formats)
7778
const resolvedPath = resolve(dir, file)
@@ -83,12 +84,12 @@ export async function performUpdates<
8384
_writeProjectManifest: writeProjectManifest,
8485
}
8586
const actual = (await fileExists(resolvedPath)) ? await formatPlugin.read(formatHandlerOptions) : null
86-
const expected = await formatPlugin.update(clone(actual), files[fileKey], formatHandlerOptions)
87+
const expected = await formatPlugin.update(clone(actual), updateFile as any, formatHandlerOptions)
8788
const equal =
8889
(actual == null && expected == null) ||
8990
(actual != null && expected != null && (await formatPlugin.equal(expected, actual, formatHandlerOptions)))
9091
if (equal) {
91-
return
92+
continue
9293
}
9394

9495
if (updateTargetFile) {
@@ -97,23 +98,14 @@ export async function performUpdates<
9798
} else {
9899
await formatPlugin.write(expected, formatHandlerOptions)
99100
}
100-
return
101+
continue
101102
}
102103

103-
return { actual, expected, path: resolvedPath }
104-
})
105-
)
106-
107-
const diffs = await Promise.allSettled(promises)
108-
const errors = diffs.flatMap((diff) => {
109-
switch (diff.status) {
110-
case 'fulfilled':
111-
return diff.value ?? []
112-
case 'rejected':
113-
return diff.reason
104+
diffs.push({ actual, expected, path: resolvedPath })
114105
}
115-
})
116-
return errors.length > 0 ? errors : null
106+
}
107+
108+
return diffs.length > 0 ? diffs : null
117109
}
118110

119111
function printJsonDiff(actual: unknown, expected: unknown, out: NodeJS.WriteStream) {

0 commit comments

Comments
 (0)