@@ -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
@@ -310,19 +310,27 @@ export function parseHomebrewLatestVersion(
310310 return version === "latest" ? null : version ;
311311}
312312
313- const runHomebrew = Effect . fn ( "runHomebrew " ) ( function * (
314- brewPath : string ,
313+ const runProbe = Effect . fn ( "runProbe " ) ( function * (
314+ command : string ,
315315 args : ReadonlyArray < string > ,
316316 env : NodeJS . ProcessEnv ,
317317) {
318318 const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
319319 const collect = Effect . gen ( function * ( ) {
320- const child = yield * spawner . spawn ( ChildProcess . make ( brewPath , args , { env, extendEnv : true } ) ) ;
320+ // Windows package managers are `.cmd` shims that need the shell.
321+ const resolved = yield * resolveSpawnCommand ( command , args , { env, extendEnv : true } ) ;
322+ const child = yield * spawner . spawn (
323+ ChildProcess . make ( resolved . command , resolved . args , {
324+ env,
325+ extendEnv : true ,
326+ shell : resolved . shell ,
327+ } ) ,
328+ ) ;
321329 yield * Effect . addFinalizer ( ( ) => child . kill ( ) . pipe ( Effect . ignore ) ) ;
322- // stderr is drained so a chatty brew cannot block on a full pipe.
330+ // stderr is drained so a chatty tool cannot block on a full pipe.
323331 const [ stdout , exitCode ] = yield * Effect . all (
324332 [
325- collectUint8StreamText ( { stream : child . stdout , maxBytes : HOMEBREW_INFO_MAX_BYTES } ) ,
333+ collectUint8StreamText ( { stream : child . stdout , maxBytes : PROBE_MAX_BYTES } ) ,
326334 child . exitCode ,
327335 Stream . runDrain ( child . stderr ) ,
328336 ] ,
@@ -332,10 +340,11 @@ const runHomebrew = Effect.fn("runHomebrew")(function* (
332340 } ) ;
333341 return yield * collect . pipe (
334342 Effect . scoped ,
335- Effect . timeoutOption ( Duration . millis ( HOMEBREW_INFO_TIMEOUT_MS ) ) ,
343+ Effect . timeoutOption ( Duration . millis ( PROBE_TIMEOUT_MS ) ) ,
336344 Effect . map ( Option . getOrNull ) ,
337345 Effect . catchCause ( ( cause ) =>
338- Effect . logWarning ( "Homebrew probe failed" , {
346+ Effect . logWarning ( "Maintenance probe failed" , {
347+ command,
339348 subcommand : args [ 0 ] ,
340349 errorTag : causeErrorTag ( cause ) ,
341350 } ) . pipe ( Effect . as ( null ) ) ,
@@ -413,11 +422,20 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
413422 } ) ;
414423 }
415424 if ( commandPaths . some ( isPnpmGlobalCommandPath ) ) {
425+ // pnpm 10 skips unapproved install scripts and still exits 0, leaving a
426+ // package whose postinstall finishes the install broken. Global installs
427+ // can only approve on the command line, and pnpm before 10.4 rejects the
428+ // flag as an unknown option.
429+ const pnpmVersion = yield * runProbe ( "pnpm" , [ "--version" ] , context . env ) ;
430+ const allowBuild =
431+ pnpmVersion !== null && satisfiesSemverRange ( pnpmVersion , ">=10.4.0" )
432+ ? [ `--allow-build=${ packageName } ` ]
433+ : [ ] ;
416434 return makeProviderMaintenanceCapabilities ( {
417435 provider : definition . provider ,
418436 packageName,
419437 updateExecutable : "pnpm" ,
420- updateArgs : [ "add" , "-g" , `${ packageName } @latest` ] ,
438+ updateArgs : [ "add" , "-g" , ... allowBuild , `${ packageName } @latest` ] ,
421439 updateLockKey : "pnpm-global" ,
422440 } ) ;
423441 }
@@ -488,7 +506,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
488506 if ( ! brewPath ) {
489507 return fallback ;
490508 }
491- const brewPrefix = nonEmptyString ( yield * runHomebrew ( brewPath , [ "--prefix" ] , context . env ) ) ;
509+ const brewPrefix = nonEmptyString ( yield * runProbe ( brewPath , [ "--prefix" ] , context . env ) ) ;
492510 const realBrewPrefix = brewPrefix
493511 ? yield * fileSystem . realPath ( brewPrefix ) . pipe ( Effect . orElseSucceed ( ( ) => brewPrefix ) )
494512 : null ;
@@ -502,7 +520,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
502520 homebrew . kind === "cask" ? [ "upgrade" , "--cask" , homebrew . name ] : [ "upgrade" , homebrew . name ] ;
503521 // Homebrew lags npm by hours on every release, so compare against what
504522 // `brew upgrade` can actually deliver.
505- const info = yield * runHomebrew ( brewPath , [ "info" , "--json=v2" , homebrew . name ] , context . env ) ;
523+ const info = yield * runProbe ( brewPath , [ "info" , "--json=v2" , homebrew . name ] , context . env ) ;
506524 return makeProviderMaintenanceCapabilities ( {
507525 provider : definition . provider ,
508526 packageName,
0 commit comments