Skip to content

Commit 6af4520

Browse files
author
test2
committed
fix: move accept license after
1 parent fbf6eee commit 6af4520

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "default",
3-
"version": "1.15.2",
3+
"version": "1.15.3-beta.1",
44
"description": "Default plugin for Codify - provides 50+ declarative resources for managing development tools and system configuration across macOS and Linux",
55
"main": "dist/index.js",
66
"scripts": {

src/resources/xcodes/xcode-versions-parameter.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ArrayStatefulParameter, Plan, getPty } from '@codifycli/plugin-core';
1+
import { ArrayStatefulParameter, Plan, SpawnStatus, getPty } from '@codifycli/plugin-core';
22

33
import { XcodesConfig } from './xcodes-resource.js';
44

@@ -11,7 +11,7 @@ export class XcodeVersionsParameter extends ArrayStatefulParameter<XcodesConfig,
1111

1212
override async addItem(version: string, plan: Plan<XcodesConfig>): Promise<void> {
1313
const $ = getPty();
14-
const { appleId, appleIdPassword } = plan.desiredConfig ?? {};
14+
const { appleId, appleIdPassword, acceptLicense } = plan.desiredConfig ?? {};
1515

1616
const env: Record<string, string> = {};
1717
if (appleId) env['XCODES_USERNAME'] = appleId;
@@ -22,6 +22,25 @@ export class XcodeVersionsParameter extends ArrayStatefulParameter<XcodesConfig,
2222
stdin: true,
2323
...(Object.keys(env).length > 0 ? { env } : {}),
2424
});
25+
26+
if (acceptLicense !== false) {
27+
await this.acceptLicenseIfNeeded(version);
28+
}
29+
}
30+
31+
private async acceptLicenseIfNeeded(version: string): Promise<void> {
32+
const $ = getPty();
33+
34+
// xcodebuild resolves against whatever xcode-select currently points at. If it's
35+
// still pointing at a CommandLineTools-only instance (e.g. installed before xcodes
36+
// ran), `xcodebuild -license accept` fails with "requires Xcode" even though a full
37+
// Xcode was just installed above. Explicitly select the version we just installed
38+
// first so xcode-select points at the full Xcode.
39+
await $.spawn(`xcodes select "${version}"`, { interactive: true, stdin: true });
40+
41+
const { status } = await $.spawnSafe('xcodebuild -license status');
42+
if (status === SpawnStatus.SUCCESS) return;
43+
await $.spawn('xcodebuild -license accept', { requiresRoot: true });
2544
}
2645

2746
override async removeItem(version: string): Promise<void> {

src/resources/xcodes/xcodes-resource.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
CreatePlan,
32
ExampleConfig,
43
Resource,
54
ResourceSettings,
@@ -105,21 +104,11 @@ export class XcodesResource extends Resource<XcodesConfig> {
105104
return status === SpawnStatus.SUCCESS ? {} : null;
106105
}
107106

108-
override async create(plan: CreatePlan<XcodesConfig>): Promise<void> {
107+
override async create(): Promise<void> {
109108
await Utils.installViaPkgMgr('xcodes', undefined, PackageManager.BREW);
110-
if (plan.desiredConfig.acceptLicense !== false) {
111-
await this.acceptLicenseIfNeeded();
112-
}
113109
}
114110

115111
override async destroy(): Promise<void> {
116112
await Utils.uninstallViaPkgMgr('xcodes', undefined, PackageManager.BREW);
117113
}
118-
119-
private async acceptLicenseIfNeeded(): Promise<void> {
120-
const $ = getPty();
121-
const { status } = await $.spawnSafe('xcodebuild -license status');
122-
if (status === SpawnStatus.SUCCESS) return;
123-
await $.spawn('xcodebuild -license accept', { requiresRoot: true });
124-
}
125114
}

0 commit comments

Comments
 (0)