@snap/valdi 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/.bootstrap/modules/ui_component/BUILD.bazel.template +1 -1
  2. package/.metadata/.bazelrc.template +4 -0
  3. package/.metadata/.bazelversion.template +1 -1
  4. package/.metadata/MODULE.bazel.template +48 -6
  5. package/.metadata/android_ide_common_30_1_3_install.json.template +1818 -0
  6. package/.metadata/android_mvn_install.json.template +2877 -0
  7. package/.metadata/maven_install.json.template +444 -0
  8. package/.metadata/rules_android_maven_install.json.template +4879 -0
  9. package/README.md +1 -1
  10. package/bundled-skills/skills/valdi-compiler/skill.md +3 -8
  11. package/bundled-skills/skills/valdi-component-tests/skill.md +1 -1
  12. package/bundled-skills/skills/valdi-gestures/skill.md +1 -1
  13. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +1 -1
  14. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +8 -8
  15. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +2 -2
  16. package/bundled-skills/skills/valdi-perf/skill.md +2 -2
  17. package/bundled-skills/skills/valdi-polyglot-module/skill.md +5 -1
  18. package/bundled-skills/skills/valdi-tsx/skill.md +6 -6
  19. package/dist/commands/agentCheck.js +9 -7
  20. package/dist/commands/bootstrap.js +15 -4
  21. package/dist/commands/doctor.js +4 -7
  22. package/dist/commands/install.js +13 -1
  23. package/dist/commands/newModule.js +8 -1
  24. package/dist/commands/webHotreload.js +1 -1
  25. package/dist/core/constants.js +4 -0
  26. package/dist/setup/DevSetupHelper.js +11 -2
  27. package/dist/setup/libtinfo5.js +19 -0
  28. package/dist/setup/linuxSetup.js +2 -22
  29. package/dist/utils/BazelClient.js +11 -4
  30. package/dist/utils/errorUtils.js +1 -1
  31. package/dist/utils/githubUtils.js +1 -1
  32. package/dist/utils/iosSimulator.js +136 -0
  33. package/dist/utils/nonInteractive.js +13 -0
  34. package/dist/utils/prettierCheck.js +19 -0
  35. package/package.json +4 -2
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDeveloperDir = getDeveloperDir;
4
+ exports.legacySimulatorAppPath = legacySimulatorAppPath;
5
+ exports.findSimulatorUiApp = findSimulatorUiApp;
6
+ exports.needsSimctlInstall = needsSimctlInstall;
7
+ exports.parseSimulatorDevices = parseSimulatorDevices;
8
+ exports.pickSimulator = pickSimulator;
9
+ exports.installAndLaunchOnSimulator = installAndLaunchOnSimulator;
10
+ const tslib_1 = require("tslib");
11
+ const node_child_process_1 = require("node:child_process");
12
+ const fs = tslib_1.__importStar(require("node:fs"));
13
+ const node_os_1 = tslib_1.__importDefault(require("node:os"));
14
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
15
+ const node_util_1 = require("node:util");
16
+ const errors_1 = require("../core/errors");
17
+ const zipUtils_1 = require("./zipUtils");
18
+ const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
19
+ const defaultExec = async (file, args) => (await execFileAsync(file, args)).stdout;
20
+ async function getDeveloperDir(exec = defaultExec) {
21
+ const fromEnv = process.env['DEVELOPER_DIR'];
22
+ if (fromEnv) {
23
+ return fromEnv;
24
+ }
25
+ return (await exec('xcode-select', ['-p'])).trim();
26
+ }
27
+ function legacySimulatorAppPath(developerDir) {
28
+ return node_path_1.default.join(developerDir, 'Applications', 'Simulator.app');
29
+ }
30
+ function findSimulatorUiApp(developerDir, exists = fs.existsSync) {
31
+ const candidates = [legacySimulatorAppPath(developerDir), node_path_1.default.join(developerDir, '..', 'Applications', 'DeviceHub.app')];
32
+ return candidates.find(exists);
33
+ }
34
+ function needsSimctlInstall(developerDir, exists = fs.existsSync) {
35
+ return !exists(legacySimulatorAppPath(developerDir));
36
+ }
37
+ function parseRuntimeVersion(runtimeId) {
38
+ const match = /\.iOS-(\d+(?:-\d+)*)(?=-|$)/.exec(runtimeId);
39
+ return match?.[1]?.split('-').map(Number);
40
+ }
41
+ function compareVersions(a, b) {
42
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
43
+ const diff = (a[i] ?? 0) - (b[i] ?? 0);
44
+ if (diff !== 0) {
45
+ return diff;
46
+ }
47
+ }
48
+ return 0;
49
+ }
50
+ function parseSimulatorDevices(listJson) {
51
+ const parsed = JSON.parse(listJson);
52
+ const result = [];
53
+ for (const [runtimeId, devices] of Object.entries(parsed.devices)) {
54
+ const runtimeVersion = parseRuntimeVersion(runtimeId);
55
+ if (!runtimeVersion) {
56
+ continue;
57
+ }
58
+ for (const device of devices) {
59
+ if (device.isAvailable !== false) {
60
+ result.push({ udid: device.udid, name: device.name, state: device.state, runtimeVersion });
61
+ }
62
+ }
63
+ }
64
+ return result;
65
+ }
66
+ function pickSimulator(devices, requestedUdid) {
67
+ if (requestedUdid === 'booted') {
68
+ const booted = devices.filter(device => device.state === 'Booted');
69
+ const found = booted.find(device => device.name.startsWith('iPhone')) ?? booted[0];
70
+ if (!found) {
71
+ throw new errors_1.CliError("No booted iOS simulator found. Boot one or omit '--device_id booted'.");
72
+ }
73
+ return found;
74
+ }
75
+ if (requestedUdid) {
76
+ const requested = devices.find(device => device.udid === requestedUdid);
77
+ if (!requested) {
78
+ throw new errors_1.CliError(`No available iOS simulator with UDID ${requestedUdid}. Run 'xcrun simctl list devices' to see them.`);
79
+ }
80
+ return requested;
81
+ }
82
+ const iphones = devices.filter(device => device.name.startsWith('iPhone'));
83
+ const booted = iphones.find(device => device.state === 'Booted');
84
+ if (booted) {
85
+ return booted;
86
+ }
87
+ const newestFirst = [...iphones].sort((a, b) => compareVersions(b.runtimeVersion, a.runtimeVersion));
88
+ const fallback = newestFirst[0];
89
+ if (!fallback) {
90
+ throw new errors_1.CliError('No iPhone simulator is available. Install an iOS simulator runtime in Xcode and try again.');
91
+ }
92
+ return fallback;
93
+ }
94
+ async function installAndLaunchOnSimulator(ipaPath, options = {}) {
95
+ const exec = options.exec ?? defaultExec;
96
+ const developerDir = options.developerDir ?? (await getDeveloperDir(exec));
97
+ const listJson = await exec('xcrun', ['simctl', 'list', 'devices', 'available', '--json']);
98
+ const simulator = pickSimulator(parseSimulatorDevices(listJson), options.deviceId);
99
+ console.log(`Using simulator ${simulator.name} (${simulator.udid})`);
100
+ await exec('xcrun', ['simctl', 'bootstatus', simulator.udid, '-b']).catch((error) => {
101
+ throw new errors_1.CliError(`Failed to boot simulator ${simulator.udid}: ${error.message}`);
102
+ });
103
+ const extractDir = fs.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'valdi-ios-install-'));
104
+ try {
105
+ await (0, zipUtils_1.decompressTo)(ipaPath, extractDir);
106
+ const payloadDir = node_path_1.default.join(extractDir, 'Payload');
107
+ const appName = fs.existsSync(payloadDir) ? fs.readdirSync(payloadDir).find(name => name.endsWith('.app')) : undefined;
108
+ if (!appName) {
109
+ throw new errors_1.CliError(`No .app bundle found in ${ipaPath}`);
110
+ }
111
+ const appPath = node_path_1.default.join(payloadDir, appName);
112
+ const bundleId = (await exec('plutil', ['-extract', 'CFBundleIdentifier', 'raw', '-o', '-', node_path_1.default.join(appPath, 'Info.plist')])).trim();
113
+ await exec('xcrun', ['simctl', 'install', simulator.udid, appPath]).catch((error) => {
114
+ throw new errors_1.CliError(`Failed to install ${appName} on simulator ${simulator.udid}: ${error.message}`);
115
+ });
116
+ await exec('xcrun', ['simctl', 'get_app_container', simulator.udid, bundleId]).catch(() => {
117
+ throw new errors_1.CliError(`Installed ${bundleId} is not present on simulator ${simulator.udid}`);
118
+ });
119
+ await exec('xcrun', ['simctl', 'launch', '--terminate-running-process', simulator.udid, bundleId]).catch((error) => {
120
+ throw new errors_1.CliError(`Failed to launch ${bundleId} on simulator ${simulator.udid}: ${error.message}`);
121
+ });
122
+ console.log(`Launched ${bundleId} on ${simulator.name}`);
123
+ }
124
+ finally {
125
+ fs.rmSync(extractDir, { force: true, recursive: true });
126
+ }
127
+ const uiApp = findSimulatorUiApp(developerDir);
128
+ if (uiApp) {
129
+ await exec('open', ['-a', uiApp]).catch(() => {
130
+ console.log(`Could not open ${uiApp}; the app is running on the simulator.`);
131
+ });
132
+ }
133
+ else {
134
+ console.log('No simulator UI app found in the active Xcode; the app is running on the booted simulator.');
135
+ }
136
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireFlagsWhenNonInteractive = requireFlagsWhenNonInteractive;
4
+ const errors_1 = require("../core/errors");
5
+ function requireFlagsWhenNonInteractive(command, flags, isInteractive = Boolean(process.stdin.isTTY)) {
6
+ if (isInteractive) {
7
+ return;
8
+ }
9
+ const missing = flags.filter(f => !f.provided).map(f => f.flag);
10
+ if (missing.length > 0) {
11
+ throw new errors_1.CliError(`'${command}' would prompt for input, but stdin is not a terminal. Pass these flags to run it non-interactively: ${missing.join(' ')}`);
12
+ }
13
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runPrettierCheck = runPrettierCheck;
4
+ const child_process_1 = require("child_process");
5
+ function runPrettierCheck(pattern, cwd = process.cwd(), prettierBin = require.resolve('prettier/bin/prettier.cjs')) {
6
+ return new Promise(resolve => {
7
+ (0, child_process_1.execFile)(process.execPath, [prettierBin, '--list-different', pattern], { cwd, maxBuffer: 16 * 1024 * 1024 }, (error, stdout, stderr) => {
8
+ if (!error) {
9
+ resolve({ status: 'ok' });
10
+ }
11
+ else if (error.code === 1 && stdout.trim().length > 0) {
12
+ resolve({ status: 'unformatted', output: stdout.trim() });
13
+ }
14
+ else {
15
+ resolve({ status: 'error', output: `${stdout}${stderr}`.trim() || error.message });
16
+ }
17
+ });
18
+ });
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snap/valdi",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Valdi CLI tools for developers",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,6 +14,9 @@
14
14
  "bin": {
15
15
  "valdi": "dist/index.js"
16
16
  },
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
17
20
  "files": [
18
21
  "dist",
19
22
  "debugger",
@@ -42,7 +45,6 @@
42
45
  "@bazel/bazelisk": "^1.19.0",
43
46
  "@types/inquirer": "^9.0.7",
44
47
  "@types/yargs": "^17.0.32",
45
- "extract-zip": "^2.0.1",
46
48
  "glob": "^11.0.1",
47
49
  "inquirer": "^8.0.0",
48
50
  "jsonc-parser": "^3.3.1",