|
19 | 19 | // Note: console.log('Running Codify apply/destroy...') was removed from src/commands/apply.ts |
20 | 20 | // and src/commands/destroy.ts to prevent double-printing (shell prints first, Node would repeat it). |
21 | 21 | // |
22 | | -// If oclif upgrades and changes bin.js structure, this script exits with code 1 so the breakage |
23 | | -// is immediately visible. |
| 22 | +// Also patches node_modules/oclif/lib/commands/pack/macos.js to add |
| 23 | +// `sudo rm -rf ~/.local/share/codify` to the macOS installer's preinstall script. |
| 24 | +// This fixes an oclif bug where the auto-updater cache (~/.local/share/codify) isn't cleared |
| 25 | +// on fresh installs, causing the old cached version to be used. The patch must happen before |
| 26 | +// `oclif pack macos` runs — modifying the .pkg after the fact breaks notarization. |
| 27 | +// |
| 28 | +// If oclif upgrades and changes either file's structure, this script exits with code 1 so the |
| 29 | +// breakage is immediately visible. |
24 | 30 | import { existsSync } from 'node:fs'; |
25 | 31 | import fs from 'node:fs/promises'; |
26 | 32 | import path from 'node:path'; |
27 | 33 | import { fileURLToPath } from 'node:url'; |
28 | 34 |
|
29 | 35 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
30 | 36 | const BIN_JS = path.join(__dirname, '../node_modules/oclif/lib/tarballs/bin.js'); |
| 37 | +const MACOS_JS = path.join(__dirname, '../node_modules/oclif/lib/commands/pack/macos.js'); |
31 | 38 |
|
32 | 39 | if (!existsSync(BIN_JS)) { |
33 | 40 | console.log('oclif bin.js not found (likely production install). Skipping.'); |
@@ -100,3 +107,26 @@ if (patched.includes(NODE_LAUNCH) && !patched.includes(NODE_LAUNCH_EXEC)) { |
100 | 107 |
|
101 | 108 | await fs.writeFile(BIN_JS, withExec, 'utf8'); |
102 | 109 | console.log('Successfully patched oclif bin.js'); |
| 110 | + |
| 111 | +// Patch macos.js preinstall script to also clear the auto-updater cache directory. |
| 112 | +// Oclif's auto-updater stores binaries in ~/.local/share/codify and the macOS installer |
| 113 | +// doesn't clean this up, so fresh installs still run the old cached version. |
| 114 | +// We must patch the template before `oclif pack macos` runs — modifying the .pkg after |
| 115 | +// the fact breaks notarization since the binary has been tampered with. |
| 116 | +const SEARCH_PREINSTALL = 'sudo rm -rf /usr/local/bin/${config.bin}\n${additionalCLI'; |
| 117 | +const PATCH_PREINSTALL = 'sudo rm -rf /usr/local/bin/${config.bin}\nsudo rm -rf ~/.local/share/${config.dirname}\n${additionalCLI'; |
| 118 | + |
| 119 | +if (!existsSync(MACOS_JS)) { |
| 120 | + console.log('oclif macos.js not found. Skipping preinstall patch.'); |
| 121 | +} else { |
| 122 | + const macosContent = await fs.readFile(MACOS_JS, 'utf8'); |
| 123 | + if (macosContent.includes(PATCH_PREINSTALL)) { |
| 124 | + console.log('oclif macos.js preinstall already patched. Skipping.'); |
| 125 | + } else if (!macosContent.includes(SEARCH_PREINSTALL)) { |
| 126 | + console.error('ERROR: Could not find preinstall insertion point in oclif macos.js. The oclif version may have changed.'); |
| 127 | + process.exit(1); |
| 128 | + } else { |
| 129 | + await fs.writeFile(MACOS_JS, macosContent.replace(SEARCH_PREINSTALL, PATCH_PREINSTALL), 'utf8'); |
| 130 | + console.log('Successfully patched oclif macos.js preinstall script'); |
| 131 | + } |
| 132 | +} |
0 commit comments