Skip to content

Commit 8f4f5ba

Browse files
committed
fix(npm): repair .cmd wrappers for already-installed tools on Windows
EnsureInstalledFromSpecs skips installation when a tool is already present (e.g. restored from a CI cache). If the cached installation was created before PostInstall was implemented, the npm .cmd wrappers still contain the broken relative node.exe path. Add an idempotent PostInstall repair pass inside the 'already installed' branch for npm tools on Windows. PostInstall reads and rewrites .cmd files to use the absolute node.exe path — safe to call repeatedly. On Linux/macOS PostInstall is a no-op, so there is no performance impact on those platforms.
1 parent 32ce045 commit 8f4f5ba

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

internal/service/installation.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,21 @@ func (im *InstallationManager) EnsureInstalledFromSpecs(ctx context.Context, too
974974
// Check if already installed using robust variant detection
975975
installed, _ := im.IsInstalled(ctx, toolName, version, backendName)
976976
if installed {
977+
// On Windows, npm-generated .cmd wrappers may have been restored from
978+
// a cache that was built before PostInstall was implemented. Re-run
979+
// PostInstall unconditionally for npm tools on Windows — it is idempotent
980+
// (reads & rewrites .cmd files) and a no-op on non-Windows platforms.
981+
if runtime.GOOS == "windows" && backendName == "npm" {
982+
p := im.providerRegistry.GetWithBackend(toolName, backendName)
983+
fsName := env.GetFSToolName(toolName, backendName)
984+
installPath := filepath.Join(env.GetInstallsDir(), fsName, version)
985+
if postErr := p.PostInstall(ctx, toolName, installPath, version); postErr != nil {
986+
logger.Debug("npm PostInstall repair skipped", map[string]interface{}{
987+
"tool": toolName,
988+
"error": postErr.Error(),
989+
})
990+
}
991+
}
977992
continue
978993
}
979994

0 commit comments

Comments
 (0)