11import chalk from 'chalk'
22import { execSync } from 'node:child_process'
33import fs from 'node:fs/promises'
4+ import path from 'node:path' ;
45
56console . log ( chalk . magenta ( 'Removing everything in ./.build except tmp' ) )
67await fs . readdir ( './.build' )
@@ -28,7 +29,8 @@ console.log(chalk.magenta('Install production dependencies'))
2829execSync ( 'npm install --production' , { cwd : './.build' , shell : 'zsh' } )
2930
3031console . log ( chalk . magenta ( 'Running oclif pkg macos' ) )
31- execSync ( 'oclif pack macos -r .' , { cwd : './.build' , shell : 'zsh' } )
32+ execSync ( 'oclif pack macos -r .' , { cwd : './.build' , shell : 'zsh' } ) ;
33+ await patchMacOsInstallers ( )
3234
3335console . log ( chalk . magenta ( 'Running oclif pkg tarballs' ) )
3436execSync ( 'oclif pack tarballs -r . -t darwin-arm64,darwin-x64' , { cwd : './.build' , shell : 'zsh' } )
@@ -44,3 +46,24 @@ async function ignoreError(fn: () => Promise<any> | any): Promise<void> {
4446 } catch ( e ) {
4547 }
4648}
49+
50+ // Oclif has a bug where the installer doesn't clear out the auto-updater location. This causes older versions
51+ // to be re-used even with a clean install
52+ async function patchMacOsInstallers ( ) {
53+ console . log ( chalk . magenta ( 'Patching MacOS installers with bug fix' ) )
54+
55+ const pkgFolder = './.build/dist/macos' ;
56+ const files = await fs . readdir ( pkgFolder )
57+ const pkgFiles = files . filter ( ( name ) => name . endsWith ( '.pkg' ) )
58+
59+ for ( const pkgFile of pkgFiles ) {
60+ const pkgPath = path . join ( pkgFolder , pkgFile ) ;
61+ const tmpPath = path . join ( pkgFolder , 'tmp' ) ;
62+
63+ execSync ( `pkgutil --expand ${ pkgPath } ${ tmpPath } ` )
64+ await fs . appendFile ( path . join ( tmpPath , 'Scripts' , 'preinstall' ) , '\nsudo rm -rf ~/.local/share/codify' , 'utf8' ) ;
65+ execSync ( `pkgutil --flatten ${ tmpPath } ${ pkgPath } ` )
66+ execSync ( `rm -rf ${ tmpPath } ` ) ;
67+ console . log ( chalk . magenta ( `Done patching installer ${ pkgFile } ` ) )
68+ }
69+ }
0 commit comments