From 96690e1354d355a690d60b4d2cdc8b0ed5092110 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 22 Dec 2024 21:25:51 +0100 Subject: [PATCH] Generate the postinstall script as the first entry of the package.json --- .../addPostinstallScriptIfNotPresent.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/bin/shared/addPostinstallScriptIfNotPresent.ts b/src/bin/shared/addPostinstallScriptIfNotPresent.ts index 36dc3c5f..d7094c96 100644 --- a/src/bin/shared/addPostinstallScriptIfNotPresent.ts +++ b/src/bin/shared/addPostinstallScriptIfNotPresent.ts @@ -15,8 +15,6 @@ export function addPostinstallScriptIfNotPresent(params: { }) { const { parsedPackageJson, buildContext } = params; - const scripts = (parsedPackageJson.scripts ??= {}); - const cmd_base = "keycloakify postinstall"; const projectCliOptionValue = (() => { @@ -48,18 +46,25 @@ export function addPostinstallScriptIfNotPresent(params: { return cmd; }; - for (const scriptName of ["postinstall", "prepare"]) { - const cmd_preexisting = scripts[scriptName]; + { + const scripts = (parsedPackageJson.scripts ??= {}); - if (cmd_preexisting === undefined) { - continue; - } + for (const scriptName of ["postinstall", "prepare"]) { + const cmd_preexisting = scripts[scriptName]; - if (cmd_preexisting.includes(cmd_base)) { - scripts[scriptName] = generateCmd({ cmd_preexisting }); - return; + if (cmd_preexisting === undefined) { + continue; + } + + if (cmd_preexisting.includes(cmd_base)) { + scripts[scriptName] = generateCmd({ cmd_preexisting }); + return; + } } } - scripts["postinstall"] = generateCmd({ cmd_preexisting: scripts["postinstall"] }); + parsedPackageJson.scripts = { + postinstall: generateCmd({ cmd_preexisting: undefined }), + ...parsedPackageJson.scripts + }; }