fix: Flaky behavior of Yalc (#11084)

This commit is contained in:
Harminder Virk
2025-01-22 14:26:07 +05:30
committed by GitHub
parent 2d0e50624f
commit e53b8b0a97
3 changed files with 56 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
import * as yalc from "yalc"
import path from "path"
import { execFile } from "child_process"
import { logger } from "@medusajs/framework/logger"
import { Compiler } from "@medusajs/framework/build-tools"
@@ -7,13 +8,43 @@ export default async function developPlugin({
}: {
directory: string
}) {
let isBusy = false
const compiler = new Compiler(directory, logger)
const yalcBin = path.join(path.dirname(require.resolve("yalc")), "yalc.js")
await compiler.developPluginBackend(async () => {
await yalc.publishPackage({
push: true,
workingDir: directory,
changed: true,
replace: true,
})
/**
* Here we avoid multiple publish calls when the filesystem is
* changed too quickly. This might result in stale content in
* some edge cases. However, not preventing multiple publishes
* at the same time will result in race conditions and the old
* output might appear in the published package.
*/
if (isBusy) {
return
}
isBusy = true
/**
* Yalc is meant to be used a binary and not as a long-lived
* module import. Therefore we will have to execute it like
* a command to get desired outcome. Otherwise, yalc behaves
* flaky.
*/
execFile(
yalcBin,
["publish", "--push", "--no-scripts"],
{
cwd: directory,
},
(error, stdout, stderr) => {
isBusy = false
if (error) {
console.log(error)
}
console.log(stdout)
console.error(stderr)
}
)
})
}