fix: Flaky behavior of Yalc (#11084)
This commit is contained in:
1 parent
2d0e50624f
commit
e53b8b0a97
3 files changed
+56
-8
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
"@medusajs/framework": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: Flaky behavior of Yalc
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { getConfigFile } from "@medusajs/utils"
|
import { getConfigFile } from "@medusajs/utils"
|
||||||
import type { AdminOptions, ConfigModule, Logger } from "@medusajs/types"
|
import type { AdminOptions, ConfigModule, Logger } from "@medusajs/types"
|
||||||
import { rm, access, constants, copyFile, writeFile } from "fs/promises"
|
import { rm, access, constants, copyFile, writeFile, mkdir } from "fs/promises"
|
||||||
import type tsStatic from "typescript"
|
import type tsStatic from "typescript"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,6 +140,16 @@ export class Compiler {
|
|||||||
await rm(path, { recursive: true }).catch(() => {})
|
await rm(path, { recursive: true }).catch(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures a directory exists
|
||||||
|
*/
|
||||||
|
async #ensureDir(path: string, clean?: boolean) {
|
||||||
|
if (clean) {
|
||||||
|
await this.#clean(path)
|
||||||
|
}
|
||||||
|
await mkdir(path, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the medusa config file and prints the error to
|
* Loads the medusa config file and prints the error to
|
||||||
* the console (in case of any errors). Otherwise, the
|
* the console (in case of any errors). Otherwise, the
|
||||||
@@ -463,6 +473,7 @@ export class Compiler {
|
|||||||
* a file has changed.
|
* a file has changed.
|
||||||
*/
|
*/
|
||||||
async developPluginBackend(onFileChange?: () => void) {
|
async developPluginBackend(onFileChange?: () => void) {
|
||||||
|
await this.#ensureDir(this.#pluginsDistFolder, true)
|
||||||
await this.#createPluginOptionsFile()
|
await this.#createPluginOptionsFile()
|
||||||
const ts = await this.#loadTSCompiler()
|
const ts = await this.#loadTSCompiler()
|
||||||
|
|
||||||
|
|||||||
@@ -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 { logger } from "@medusajs/framework/logger"
|
||||||
import { Compiler } from "@medusajs/framework/build-tools"
|
import { Compiler } from "@medusajs/framework/build-tools"
|
||||||
|
|
||||||
@@ -7,13 +8,43 @@ export default async function developPlugin({
|
|||||||
}: {
|
}: {
|
||||||
directory: string
|
directory: string
|
||||||
}) {
|
}) {
|
||||||
|
let isBusy = false
|
||||||
const compiler = new Compiler(directory, logger)
|
const compiler = new Compiler(directory, logger)
|
||||||
|
const yalcBin = path.join(path.dirname(require.resolve("yalc")), "yalc.js")
|
||||||
|
|
||||||
await compiler.developPluginBackend(async () => {
|
await compiler.developPluginBackend(async () => {
|
||||||
await yalc.publishPackage({
|
/**
|
||||||
push: true,
|
* Here we avoid multiple publish calls when the filesystem is
|
||||||
workingDir: directory,
|
* changed too quickly. This might result in stale content in
|
||||||
changed: true,
|
* some edge cases. However, not preventing multiple publishes
|
||||||
replace: true,
|
* 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)
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user