@@ -11,10 +11,10 @@ import {
1111 type ServerProvider ,
1212 type ServerProviderVersionAdvisory ,
1313} from "@t3tools/contracts" ;
14- import { compareSemverVersions } from "@t3tools/shared/semver" ;
14+ import { compareSemverVersions , satisfiesSemverRange } from "@t3tools/shared/semver" ;
1515import * as HostProcess from "@t3tools/shared/HostProcess" ;
1616import { causeErrorTag } from "@t3tools/shared/observability" ;
17- import { resolveCommandPath } from "@t3tools/shared/shell" ;
17+ import { resolveCommandPath , resolveSpawnCommand } from "@t3tools/shared/shell" ;
1818import * as Cache from "effect/Cache" ;
1919import * as Config from "effect/Config" ;
2020import * as DateTime from "effect/DateTime" ;
@@ -34,8 +34,8 @@ import { collectUint8StreamText } from "./collectStreamText.ts";
3434import * as ProviderLatestVersions from "./ProviderLatestVersions.ts" ;
3535
3636const LATEST_VERSION_TIMEOUT_MS = 4_000 ;
37- const HOMEBREW_INFO_TIMEOUT_MS = 10_000 ;
38- const HOMEBREW_INFO_MAX_BYTES = 256 * 1_024 ;
37+ const PROBE_TIMEOUT_MS = 10_000 ;
38+ const PROBE_MAX_BYTES = 256 * 1_024 ;
3939const MISE_WRAPPER_MAX_BYTES = 16 * 1_024 ;
4040const PROVIDER_UPDATE_ACTION_TOAST_MESSAGE = "Install the update now or review provider settings." ;
4141
@@ -293,19 +293,27 @@ export function parseHomebrewLatestVersion(
293293 return nonEmptyString ( raw ) ;
294294}
295295
296- const runHomebrew = Effect . fn ( "runHomebrew " ) ( function * (
297- brewPath : string ,
296+ const runProbe = Effect . fn ( "runProbe " ) ( function * (
297+ command : string ,
298298 args : ReadonlyArray < string > ,
299299 env : NodeJS . ProcessEnv ,
300300) {
301301 const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
302302 const collect = Effect . gen ( function * ( ) {
303- const child = yield * spawner . spawn ( ChildProcess . make ( brewPath , args , { env, extendEnv : true } ) ) ;
303+ // Windows package managers are `.cmd` shims that need the shell.
304+ const resolved = yield * resolveSpawnCommand ( command , args , { env, extendEnv : true } ) ;
305+ const child = yield * spawner . spawn (
306+ ChildProcess . make ( resolved . command , resolved . args , {
307+ env,
308+ extendEnv : true ,
309+ shell : resolved . shell ,
310+ } ) ,
311+ ) ;
304312 yield * Effect . addFinalizer ( ( ) => child . kill ( ) . pipe ( Effect . ignore ) ) ;
305- // stderr is drained so a chatty brew cannot block on a full pipe.
313+ // stderr is drained so a chatty tool cannot block on a full pipe.
306314 const [ stdout , exitCode ] = yield * Effect . all (
307315 [
308- collectUint8StreamText ( { stream : child . stdout , maxBytes : HOMEBREW_INFO_MAX_BYTES } ) ,
316+ collectUint8StreamText ( { stream : child . stdout , maxBytes : PROBE_MAX_BYTES } ) ,
309317 child . exitCode ,
310318 Stream . runDrain ( child . stderr ) ,
311319 ] ,
@@ -315,10 +323,11 @@ const runHomebrew = Effect.fn("runHomebrew")(function* (
315323 } ) ;
316324 return yield * collect . pipe (
317325 Effect . scoped ,
318- Effect . timeoutOption ( Duration . millis ( HOMEBREW_INFO_TIMEOUT_MS ) ) ,
326+ Effect . timeoutOption ( Duration . millis ( PROBE_TIMEOUT_MS ) ) ,
319327 Effect . map ( Option . getOrNull ) ,
320328 Effect . catchCause ( ( cause ) =>
321- Effect . logWarning ( "Homebrew probe failed" , {
329+ Effect . logWarning ( "Maintenance probe failed" , {
330+ command,
322331 subcommand : args [ 0 ] ,
323332 errorTag : causeErrorTag ( cause ) ,
324333 } ) . pipe ( Effect . as ( null ) ) ,
@@ -383,11 +392,20 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
383392 } ) ;
384393 }
385394 if ( commandPaths . some ( isPnpmGlobalCommandPath ) ) {
395+ // pnpm 10 skips unapproved install scripts and still exits 0, leaving a
396+ // package whose postinstall finishes the install broken. Global installs
397+ // can only approve on the command line, and pnpm before 10.4 rejects the
398+ // flag as an unknown option.
399+ const pnpmVersion = yield * runProbe ( "pnpm" , [ "--version" ] , context . env ) ;
400+ const allowBuild =
401+ pnpmVersion !== null && satisfiesSemverRange ( pnpmVersion , ">=10.4.0" )
402+ ? [ `--allow-build=${ packageName } ` ]
403+ : [ ] ;
386404 return makeProviderMaintenanceCapabilities ( {
387405 provider : definition . provider ,
388406 packageName,
389407 updateExecutable : "pnpm" ,
390- updateArgs : [ "add" , "-g" , `${ packageName } @latest` ] ,
408+ updateArgs : [ "add" , "-g" , ... allowBuild , `${ packageName } @latest` ] ,
391409 updateLockKey : "pnpm-global" ,
392410 } ) ;
393411 }
@@ -458,7 +476,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
458476 if ( ! brewPath ) {
459477 return fallback ;
460478 }
461- const brewPrefix = nonEmptyString ( yield * runHomebrew ( brewPath , [ "--prefix" ] , context . env ) ) ;
479+ const brewPrefix = nonEmptyString ( yield * runProbe ( brewPath , [ "--prefix" ] , context . env ) ) ;
462480 const realBrewPrefix = brewPrefix
463481 ? yield * fileSystem . realPath ( brewPrefix ) . pipe ( Effect . orElseSucceed ( ( ) => brewPrefix ) )
464482 : null ;
@@ -472,7 +490,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
472490 homebrew . kind === "cask" ? [ "upgrade" , "--cask" , homebrew . name ] : [ "upgrade" , homebrew . name ] ;
473491 // Homebrew lags npm by hours on every release, so compare against what
474492 // `brew upgrade` can actually deliver.
475- const info = yield * runHomebrew ( brewPath , [ "info" , "--json=v2" , homebrew . name ] , context . env ) ;
493+ const info = yield * runProbe ( brewPath , [ "info" , "--json=v2" , homebrew . name ] , context . env ) ;
476494 return makeProviderMaintenanceCapabilities ( {
477495 provider : definition . provider ,
478496 packageName,
0 commit comments