Skip to content

Commit 837a42d

Browse files
committed
Fix Command Line Tools follow-ups
- action no longer requires xcode-tools: scripts that need it declare it - nvm installs with METHOD=script (curl) instead of the /usr/bin/git stub, so it no longer requires xcode-tools - git: refresh checks xcode-select for the macOS system git (the stub passes which git), create skips brew when the Command Line Tools already provide git, destroy skips the system git - ios-simulators needs Xcode, not the Command Line Tools: soft dependency on xcodes, clear error when the selected developer dir isn't Xcode.app - codex-app installs with installViaPkgMgr instead of calling brew Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016QnBk1brshJrHGEkhMFR29
1 parent 6be0a39 commit 837a42d

6 files changed

Lines changed: 70 additions & 26 deletions

File tree

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ getSettings() {
633633

634634
- `requiresOnMacOS('homebrew')`: the resource installs/uninstalls with brew on macOS (`Utils.installViaPkgMgr`, `PackageManager.BREW`).
635635
- `requiresOnMacOS('xcode-tools')`: the resource runs `git`, `make`, a compiler or `/usr/bin/python3`, builds native
636-
code, or runs user commands (`action`, `project-install`). On a fresh Mac these are stubs that open an install dialog.
636+
code, or installs project dependencies (`project-install`). `action` requires nothing: a script that needs the Command Line Tools must add an `xcode-tools` resource itself (and `dependsOn` it). On a fresh Mac these are stubs that open an install dialog.
637637
- Resources that only write files, run `defaults` or download binaries/dmg/pkg require nothing.
638638
- Always use the helper (or an `Utils.isMacOS()` conditional): `xcode-tools` doesn't exist on Linux.
639639
- `src/utils/requires.test.ts` scans the resource sources and fails if a resource uses brew or git without declaring it.

‎src/resources/codex/codex-app.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
22
ExampleConfig,
3+
PackageManager,
34
Resource,
45
ResourceSettings,
6+
Utils,
57
getPty,
68
z,
79
} from '@codifycli/plugin-core';
@@ -53,18 +55,16 @@ export class CodexAppResource extends Resource<CodexAppConfig> {
5355
}
5456

5557
async create(): Promise<void> {
56-
const $ = getPty();
57-
await $.spawn('brew install --cask codex-app', {
58-
interactive: true,
59-
env: { HOMEBREW_NO_AUTO_UPDATE: '1' },
60-
});
58+
await Utils.installViaPkgMgr('codex-app', { [PackageManager.BREW]: { cask: true } }, PackageManager.BREW);
6159
}
6260

6361
async destroy(): Promise<void> {
64-
const $ = getPty();
65-
await $.spawnSafe('brew uninstall --cask codex-app', {
66-
env: { HOMEBREW_NO_AUTO_UPDATE: '1' },
67-
});
68-
await $.spawnSafe(`rm -rf "${CODEX_APP_PATH}"`);
62+
try {
63+
await Utils.uninstallViaPkgMgr('codex-app', { [PackageManager.BREW]: { cask: true } }, PackageManager.BREW);
64+
} catch {
65+
// Homebrew is gone: remove the app directly below
66+
}
67+
68+
await getPty().spawnSafe(`rm -rf "${CODEX_APP_PATH}"`);
6969
}
7070
}

‎src/resources/git/git/git-resource.ts‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,49 @@ export class GitResource extends Resource<GitConfig> {
4242
}
4343

4444
async refresh(): Promise<Partial<GitConfig> | null> {
45-
const $ = getPty();
46-
47-
const { status } = await $.spawnSafe('which git')
48-
return status === SpawnStatus.ERROR ? null : {}
45+
return await isGitInstalled() ? {} : null;
4946
}
5047

5148
async create(): Promise<void> {
49+
// On macOS git comes with the Xcode Command Line Tools (required, so applied first)
50+
if (await isGitInstalled({ interactive: true })) {
51+
return;
52+
}
53+
5254
await Utils.installViaPkgMgr('git');
5355
}
5456

5557
async destroy(): Promise<void> {
58+
if (Utils.isMacOS() && await gitPath({ interactive: true }) === MACOS_SYSTEM_GIT) {
59+
console.warn('git is part of the Xcode Command Line Tools on macOS and cannot be uninstalled separately. Skipping...');
60+
return;
61+
}
62+
5663
await Utils.uninstallViaPkgMgr('git');
5764
}
5865
}
66+
67+
const MACOS_SYSTEM_GIT = '/usr/bin/git';
68+
69+
async function gitPath(options?: { interactive?: boolean }): Promise<null | string> {
70+
const { data, status } = await getPty().spawnSafe('which git', options);
71+
return status === SpawnStatus.ERROR || !data.trim() ? null : data.trim();
72+
}
73+
74+
/**
75+
* On a fresh Mac /usr/bin/git is a stub that opens an "install developer tools" dialog, so `which git` alone is not
76+
* enough: the system git only works once the Xcode Command Line Tools (or Xcode) are installed.
77+
*/
78+
async function isGitInstalled(options?: { interactive?: boolean }): Promise<boolean> {
79+
const path = await gitPath(options);
80+
if (!path) {
81+
return false;
82+
}
83+
84+
if (Utils.isMacOS() && path === MACOS_SYSTEM_GIT) {
85+
const { status } = await getPty().spawnSafe('xcode-select -p', options);
86+
return status === SpawnStatus.SUCCESS;
87+
}
88+
89+
return true;
90+
}

‎src/resources/ios/ios-simulator/ios-simulator.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
z,
1212
} from '@codifycli/plugin-core';
1313
import { OS } from '@codifycli/schemas';
14-
import { requiresOnMacOS } from '../../../utils/requires.js';
1514

1615
const simulatorSchema = z.object({
1716
name: z.string().describe('Name for the simulator instance (e.g. "iPhone 15 Dev")'),
@@ -97,9 +96,9 @@ const exampleBasic: ExampleConfig = {
9796

9897
const exampleMultiDevice: ExampleConfig = {
9998
title: 'iPhone and iPad simulator setup',
100-
description: 'Install Xcode Command Line Tools and create an iPhone and iPad simulator for cross-device testing.',
99+
description: 'Install the latest Xcode with xcodes and create an iPhone and iPad simulator for cross-device testing.',
101100
configs: [
102-
{ type: 'xcode-tools', os: ['macOS'] },
101+
{ type: 'xcodes', xcodeVersions: ['latest'], os: ['macOS'] },
103102
{
104103
type: 'ios-simulators',
105104
simulators: [
@@ -143,7 +142,8 @@ export class IosSimulatorResource extends Resource<IosSimulatorConfig> {
143142
getSettings(): ResourceSettings<IosSimulatorConfig> {
144143
return {
145144
id: 'ios-simulators',
146-
requires: requiresOnMacOS('xcode-tools'),
145+
// Needs the full Xcode app (the Command Line Tools don't include simctl). Applied after xcodes when it's declared.
146+
dependencies: ['xcodes'],
147147
defaultConfig,
148148
exampleConfigs: {
149149
example1: exampleBasic,
@@ -292,8 +292,22 @@ export class IosSimulatorResource extends Resource<IosSimulatorConfig> {
292292

293293
private async assertSimctlAvailable(): Promise<void> {
294294
const $ = getPty();
295+
296+
// xcrun is a stub on a fresh Mac (it opens an install dialog), and the Command Line Tools don't include simctl.
297+
// Check that the selected developer directory is an Xcode app before running it.
298+
const { data: developerDir, status: selectStatus } = await $.spawnSafe('xcode-select -p', { interactive: true });
299+
if (selectStatus !== SpawnStatus.SUCCESS || !developerDir.includes('.app/Contents/Developer')) {
300+
throw new Error(
301+
'Xcode is required to manage iOS simulators (the Xcode Command Line Tools are not enough). ' +
302+
'Add an xcodes resource (ex: { "type": "xcodes", "xcodeVersions": ["latest"] }) or install Xcode from the Mac App Store. ' +
303+
(developerDir?.includes('CommandLineTools')
304+
? 'If Xcode is already installed, select it with: sudo xcode-select -s /Applications/Xcode.app'
305+
: ''),
306+
);
307+
}
308+
295309
// Use `xcrun -f simctl` to locate the binary without invoking it — avoids triggering the license prompt
296-
const { status } = await $.spawnSafe('xcrun -f simctl');
310+
const { status } = await $.spawnSafe('xcrun -f simctl', { interactive: true });
297311
if (status !== SpawnStatus.SUCCESS) {
298312
throw new Error(
299313
'xcrun simctl is not available. Xcode must be installed to manage iOS simulators. ' +

‎src/resources/javascript/nvm/nvm.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { FileUtils } from '../../../utils/file-utils.js';
66
import { globalVersionSchema, versionsArraySchema } from '../../../utils/version-aliases.js';
77
import { NvmGlobalParameter } from './global-parameter.js';
88
import { NvmNodeVersionsParameter } from './node-versions-parameter.js';
9-
import { requiresOnMacOS } from '../../../utils/requires.js';
109

1110
export const schema = z.object({
1211
nodeVersions: versionsArraySchema(['latest', 'lts'], 'An array of node versions to install using nvm. Partial matching is supported (20 instead of 20.15.1).').optional(),
@@ -45,7 +44,6 @@ export class NvmResource extends Resource<NvmConfig> {
4544
getSettings(): ResourceSettings<NvmConfig> {
4645
return {
4746
id: 'nvm',
48-
requires: requiresOnMacOS('xcode-tools'),
4947
defaultConfig,
5048
exampleConfigs: {
5149
example1: exampleLts,
@@ -79,7 +77,9 @@ export class NvmResource extends Resource<NvmConfig> {
7977
await FileUtils.addToStartupFile('unset npm_config_prefix');
8078
}
8179

82-
const { data: installResult } = await $.spawn('curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash', { interactive: true })
80+
// METHOD=script downloads nvm with curl. Otherwise the installer clones it with git whenever `command -v git`
81+
// succeeds, which on a fresh Mac is the /usr/bin/git stub that needs the Xcode Command Line Tools.
82+
const { data: installResult } = await $.spawn('curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | METHOD=script bash', { interactive: true })
8383

8484
// Nvm doesn't handle if the init string is commented out
8585
// This check first checks that nvm detects the init string is there but nvm itself is still not present

‎src/resources/scripting/action.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { CreatePlan, DestroyPlan, ExampleConfig, getPty, Resource, ResourceSettings, SpawnStatus, z } from '@codifycli/plugin-core';
22
import { RefreshContext } from '@codifycli/plugin-core/src/resource/resource.js';
33
import { OS, StringIndexedObject } from '@codifycli/schemas';
4-
import { requiresOnMacOS } from '../../utils/requires.js';
54

65
export const schema = z.object({
76
condition: z.string().optional().describe('A bash condition that decides whether the action needs to run. Exit code 0 means the action is already done — skip it. Any non-zero exit code means the action should run. Think of it as a check for the desired end-state: if the check passes (exit 0), the work is done; if it fails (non-zero), run the action. Example: \'command -v mytool\' exits 0 when mytool is already installed (skip), and non-zero when it is absent (run the install action).'),
@@ -10,7 +9,7 @@ export const schema = z.object({
109
requiresRoot: z.boolean().optional().describe('When true, the action is executed with root privileges (sudo). Codify handles privilege escalation — do not add sudo to the action command directly.'),
1110
requiresStdin: z.boolean().optional().describe('When true, the action is run in interactive mode so it can read from stdin (e.g. for prompts or password input).'),
1211
})
13-
.describe('Run custom scripts using the action resource. A condition can be specified to conditionally trigger a script.');
12+
.describe('Run custom scripts using the action resource. A condition can be specified to conditionally trigger a script. On macOS, a script that needs git, make or a compiler should depend on an xcode-tools resource.');
1413

1514

1615
export type ActionConfig = z.infer<typeof schema>;
@@ -44,7 +43,6 @@ export class ActionResource extends Resource<ActionConfig> {
4443
getSettings(): ResourceSettings<ActionConfig> {
4544
return {
4645
id: 'action',
47-
requires: requiresOnMacOS('xcode-tools'),
4846
defaultConfig,
4947
exampleConfigs: {
5048
example1: exampleConditional,

0 commit comments

Comments
 (0)