@@ -359,6 +359,36 @@ export class RushPnpmCommandLineParser {
359359 }
360360 break ;
361361 }
362+ case 'approve-builds' : {
363+ const semver : typeof import ( 'semver' ) = await import ( 'semver' ) ;
364+ /**
365+ * The "approve-builds" command was introduced in pnpm version 10.1.0
366+ * to approve packages for running build scripts when onlyBuiltDependencies is used
367+ */
368+ if ( semver . lt ( this . _rushConfiguration . packageManagerToolVersion , '10.1.0' ) ) {
369+ this . _terminal . writeErrorLine (
370+ PrintUtilities . wrapWords (
371+ `Error: The "pnpm approve-builds" command is added after pnpm@10.1.0.` +
372+ ` Please update "pnpmVersion" >= 10.1.0 in ${ RushConstants . rushJsonFilename } file and run "rush update" to use this command.`
373+ ) + '\n'
374+ ) ;
375+ throw new AlreadyReportedError ( ) ;
376+ }
377+ const pnpmOptionsJsonFilename : string = path . join (
378+ this . _rushConfiguration . commonRushConfigFolder ,
379+ RushConstants . pnpmConfigFilename
380+ ) ;
381+ if ( this . _rushConfiguration . rushConfigurationJson . pnpmOptions ) {
382+ this . _terminal . writeErrorLine (
383+ PrintUtilities . wrapWords (
384+ `Error: The "pnpm approve-builds" command is incompatible with specifying "pnpmOptions" in ${ RushConstants . rushJsonFilename } file.` +
385+ ` Please move the content of "pnpmOptions" in ${ RushConstants . rushJsonFilename } file to ${ pnpmOptionsJsonFilename } `
386+ ) + '\n'
387+ ) ;
388+ throw new AlreadyReportedError ( ) ;
389+ }
390+ break ;
391+ }
362392
363393 // Known safe
364394 case 'audit' :
@@ -532,6 +562,39 @@ export class RushPnpmCommandLineParser {
532562 }
533563 break ;
534564 }
565+ case 'approve-builds' : {
566+ if ( this . _subspace . getPnpmOptions ( ) === undefined ) {
567+ const subspaceConfigFolder : string = this . _subspace . getSubspaceConfigFolderPath ( ) ;
568+ this . _terminal . writeErrorLine (
569+ `The "rush-pnpm approve-builds" command cannot proceed without a pnpm-config.json file.` +
570+ ` Create one in this folder: ${ subspaceConfigFolder } `
571+ ) ;
572+ break ;
573+ }
574+
575+ // Example: "C:\MyRepo\common\temp\package.json"
576+ const commonPackageJsonFilename : string = `${ subspaceTempFolder } /${ FileConstants . PackageJson } ` ;
577+ const commonPackageJson : JsonObject = JsonFile . load ( commonPackageJsonFilename ) ;
578+ const newGlobalOnlyBuiltDependencies : string [ ] | undefined =
579+ commonPackageJson ?. pnpm ?. onlyBuiltDependencies ;
580+ const pnpmOptions : PnpmOptionsConfiguration | undefined = this . _subspace . getPnpmOptions ( ) ;
581+ const currentGlobalOnlyBuiltDependencies : string [ ] | undefined =
582+ pnpmOptions ?. globalOnlyBuiltDependencies ;
583+
584+ if ( ! Objects . areDeepEqual ( currentGlobalOnlyBuiltDependencies , newGlobalOnlyBuiltDependencies ) ) {
585+ // Update onlyBuiltDependencies to pnpm configuration file
586+ pnpmOptions ?. updateGlobalOnlyBuiltDependencies ( newGlobalOnlyBuiltDependencies ) ;
587+
588+ // Rerun installation to update
589+ await this . _doRushUpdateAsync ( ) ;
590+
591+ this . _terminal . writeWarningLine (
592+ `Rush refreshed the ${ RushConstants . pnpmConfigFilename } and shrinkwrap file.\n` +
593+ ' Please commit this change to Git.'
594+ ) ;
595+ }
596+ break ;
597+ }
535598 }
536599 }
537600
0 commit comments