From b4d8c9f8204e90aaf958dde6fbfe9cf4925af559 Mon Sep 17 00:00:00 2001 From: ertopogo Date: Sat, 24 Jan 2026 19:36:11 +0100 Subject: ajout d'un patch pour les modules manquants --- backend/scripts/patch-medusa.js | 76 ++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 16 deletions(-) (limited to 'backend') diff --git a/backend/scripts/patch-medusa.js b/backend/scripts/patch-medusa.js index f44f23c..b20a9fd 100644 --- a/backend/scripts/patch-medusa.js +++ b/backend/scripts/patch-medusa.js @@ -11,24 +11,68 @@ const targetPath = path.join( "services", "payment-provider.js" ); +const notificationPath = path.join( + __dirname, + "..", + "node_modules", + "@medusajs", + "medusa", + "dist", + "services", + "notification.js" +); -if (!fs.existsSync(targetPath)) { - console.error("patch-medusa: cible introuvable:", targetPath); - process.exit(1); -} +const targets = [ + { + label: "payment-provider", + filePath: targetPath, + }, + { + label: "notification", + filePath: notificationPath, + }, +]; + +const replacements = [ + { + before: "model.update({}, { is_installed: false })", + after: + "model.createQueryBuilder().update().set({ is_installed: false }).where('1=1').execute()", + }, +]; + +let totalApplied = 0; + +for (const target of targets) { + if (!fs.existsSync(target.filePath)) { + console.error("patch-medusa: cible introuvable:", target.filePath); + process.exit(1); + } -const original = fs.readFileSync(targetPath, "utf8"); -const before = "model.update({}, { is_installed: false })"; -const after = - "model.createQueryBuilder().update().set({ is_installed: false }).where('1=1').execute()"; + const original = fs.readFileSync(target.filePath, "utf8"); + let patched = original; + let appliedCount = 0; -if (!original.includes(before)) { - console.error( - "patch-medusa: motif introuvable, le patch n'a pas ete applique." - ); - process.exit(1); + for (const { before, after } of replacements) { + if (patched.includes(before)) { + patched = patched.replace(before, after); + appliedCount += 1; + } + } + + if (appliedCount === 0) { + console.error( + "patch-medusa: motif introuvable pour " + target.label + "." + ); + process.exit(1); + } + + fs.writeFileSync(target.filePath, patched, "utf8"); + totalApplied += appliedCount; } -const patched = original.replace(before, after); -fs.writeFileSync(targetPath, patched, "utf8"); -console.log("patch-medusa: update vide remplace avec succes."); +console.log( + "patch-medusa: update vide remplace avec succes (count=" + + totalApplied + + ")." +); -- cgit v1.2.3