Summary
In packages/create-cedar-rsc-app/src/upgradeToLatestCanary.ts, the updatePackageJsons function updates multiple package.json files sequentially using synchronous file I/O:
// TODO: await Promise.all(packageJsons.map(async (path) => {
for (const path of packageJsons) {
const contents = fs.readFileSync(path, 'utf8')
// ... mutate package.json ...
fs.writeFileSync(path, JSON.stringify(packageJson, null, 2))
}
The TODO comment already suggests the intended fix: convert to Promise.all for parallel I/O.
Fix
- Make
updatePackageJsons async
- Switch from
fs.readFileSync/fs.writeFileSync to fs.promises.readFile/fs.promises.writeFile
- Wrap in
Promise.all
async function updatePackageJsons(
config: Config,
packageJsons: string[],
latestRwCanary: string,
) {
await Promise.all(
packageJsons.map(async (path) => {
const contents = await fs.promises.readFile(path, 'utf8')
const packageJson = JSON.parse(contents)
const { dependencies, devDependencies } = packageJson
if (dependencies) {
for (const name of Object.keys(dependencies)) {
if (name.startsWith('@cedarjs/')) {
dependencies[name] = latestRwCanary
}
}
}
if (devDependencies) {
for (const name of Object.keys(devDependencies)) {
if (name.startsWith('@cedarjs/')) {
devDependencies[name] = latestRwCanary
}
}
}
await fs.promises.writeFile(path, JSON.stringify(packageJson, null, 2))
}),
)
}
The writes are to different files so there are no ordering dependencies — parallel execution is safe.
The call site in the same file will also need to await the now-async function.
Files
packages/create-cedar-rsc-app/src/upgradeToLatestCanary.ts — updatePackageJsons function and its call site
Summary
In
packages/create-cedar-rsc-app/src/upgradeToLatestCanary.ts, theupdatePackageJsonsfunction updates multiplepackage.jsonfiles sequentially using synchronous file I/O:The TODO comment already suggests the intended fix: convert to
Promise.allfor parallel I/O.Fix
updatePackageJsonsasyncfs.readFileSync/fs.writeFileSynctofs.promises.readFile/fs.promises.writeFilePromise.allThe writes are to different files so there are no ordering dependencies — parallel execution is safe.
The call site in the same file will also need to
awaitthe now-async function.Files
packages/create-cedar-rsc-app/src/upgradeToLatestCanary.ts—updatePackageJsonsfunction and its call site