const fs = require("fs"); const path = require("path"); const targetPath = path.join( __dirname, "..", "node_modules", "@medusajs", "medusa", "dist", "services", "payment-provider.js" ); const notificationPath = path.join( __dirname, "..", "node_modules", "@medusajs", "medusa", "dist", "services", "notification.js" ); const fulfillmentPath = path.join( __dirname, "..", "node_modules", "@medusajs", "medusa", "dist", "services", "fulfillment-provider.js" ); const targets = [ { label: "payment-provider", filePath: targetPath, }, { label: "notification", filePath: notificationPath, }, { label: "fulfillment-provider", filePath: fulfillmentPath, }, ]; const replacements = [ { before: "model.update({}, { is_installed: false })", after: "model.createQueryBuilder().update().set({ is_installed: false }).where('1=1').execute()", }, { before: "fulfillmentProviderRepo.update({}, { is_installed: false })", after: "fulfillmentProviderRepo.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(target.filePath, "utf8"); let patched = original; let appliedCount = 0; 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; } console.log( "patch-medusa: update vide remplace avec succes (count=" + totalApplied + ")." );