From 1639741cdd2842a0058d12894b324f9e2f37561a Mon Sep 17 00:00:00 2001 From: Karstein Phobic Nyvold Kvistad Date: Mon, 27 Apr 2026 20:37:28 +0200 Subject: [PATCH] fix(postinstall): banner now actually prints on real installs (npm 11+ compat) npm 11 stopped setting npm_config_global=true, so the previous guard `process.env.npm_config_global !== 'true'` always evaluated true and the banner was silently skipped on every install -- including the `npm install -g` case it was supposed to handle. Replace the global-detection (which is unreliable across npm versions) with a positive dev-clone detector: only skip if INIT_CWD points at a checkout of this very package (matched by package.json name). Also keep the CI skip (CI=true / npm_config_ci=true). Verified all three paths: - Real install (no INIT_CWD or INIT_CWD outside repo): banner prints - Dev clone (INIT_CWD = this repo): silent - CI: silent --- src/postinstall.ts | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/postinstall.ts b/src/postinstall.ts index 47f1da5..ce0b111 100644 --- a/src/postinstall.ts +++ b/src/postinstall.ts @@ -12,17 +12,38 @@ * and downgraded to a friendly note. We never block the install. */ -function isDevOrCi(): boolean { - // Skip during local installs / dev clones. - if (process.env.npm_config_global !== 'true') return true; - // Skip in CI. +function shouldSkip(): boolean { + // Skip in CI -- banners pollute build logs. if (process.env.CI === 'true') return true; if (process.env.npm_config_ci === 'true') return true; + + // Skip when running inside the package's own dev clone (developer ran + // `npm install` on a checkout of this repo). Detect by checking whether + // INIT_CWD (npm sets this to the user's invocation cwd) appears to be + // a checkout of THIS package, vs a global install or a downstream consumer. + // Heuristic: if INIT_CWD contains a package.json whose name matches ours, + // it's the dev clone. + if (process.env.INIT_CWD) { + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const fs = require('fs'); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const path = require('path'); + const pkgPath = path.join(process.env.INIT_CWD, 'package.json'); + if (fs.existsSync(pkgPath)) { + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); + if (pkg.name === 'codesys-mcp-sp21-plus') return true; + } + } catch { + // Not a dev clone or unreadable -- fall through and print the banner. + } + } + return false; } async function main(): Promise { - if (isDevOrCi()) { + if (shouldSkip()) { return; }