@snap/valdi 1.2.0 → 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 (56) hide show
  1. package/.bootstrap/modules/ui_component/BUILD.bazel.template +1 -1
  2. package/.metadata/.bazelrc.template +5 -5
  3. package/.metadata/.bazelversion.template +1 -1
  4. package/.metadata/AGENTS.md.template +7 -0
  5. package/.metadata/MODULE.bazel.template +75 -6
  6. package/.metadata/README.md.template +2 -2
  7. package/.metadata/android_ide_common_30_1_3_install.json.template +1818 -0
  8. package/.metadata/android_mvn_install.json.template +2877 -0
  9. package/.metadata/maven_install.json.template +444 -0
  10. package/.metadata/rules_android_maven_install.json.template +4879 -0
  11. package/.metadata/skill-tests-README.md.template +1 -1
  12. package/README.md +12 -13
  13. package/bundled-skills/skills/valdi-async/tests/README.md +1 -1
  14. package/bundled-skills/skills/valdi-compiler/skill.md +3 -8
  15. package/bundled-skills/skills/valdi-component-tests/skill.md +1 -1
  16. package/bundled-skills/skills/valdi-component-tests/tests/README.md +1 -1
  17. package/bundled-skills/skills/valdi-custom-view/skill.md +1 -1
  18. package/bundled-skills/skills/valdi-gestures/skill.md +1 -1
  19. package/bundled-skills/skills/valdi-migrate/tests/README.md +2 -2
  20. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +1 -1
  21. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +8 -8
  22. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +2 -2
  23. package/bundled-skills/skills/valdi-perf/skill.md +2 -2
  24. package/bundled-skills/skills/valdi-perf/tests/README.md +1 -1
  25. package/bundled-skills/skills/valdi-polyglot-module/skill.md +5 -1
  26. package/bundled-skills/skills/valdi-tsx/skill.md +6 -6
  27. package/bundled-skills/skills/valdi-tsx/tests/README.md +1 -1
  28. package/dist/commands/agentCheck.js +9 -7
  29. package/dist/commands/bootstrap.js +16 -5
  30. package/dist/commands/build.js +7 -1
  31. package/dist/commands/doctor.js +4 -7
  32. package/dist/commands/export.js +47 -16
  33. package/dist/commands/hotreload.js +247 -27
  34. package/dist/commands/install.js +92 -3
  35. package/dist/commands/newModule.js +8 -1
  36. package/dist/commands/webHotreload.js +3 -3
  37. package/dist/core/constants.js +17 -2
  38. package/dist/setup/DevSetupHelper.js +11 -2
  39. package/dist/setup/libtinfo5.js +19 -0
  40. package/dist/setup/linuxSetup.js +2 -22
  41. package/dist/utils/BazelClient.js +11 -4
  42. package/dist/utils/applicationUtils.js +17 -2
  43. package/dist/utils/buildInfo.js +5 -1
  44. package/dist/utils/cliUtils.js +2 -2
  45. package/dist/utils/directorySync.js +153 -0
  46. package/dist/utils/errorUtils.js +1 -1
  47. package/dist/utils/githubUtils.js +1 -1
  48. package/dist/utils/iosSimulator.js +136 -0
  49. package/dist/utils/nonInteractive.js +13 -0
  50. package/dist/utils/prettierCheck.js +19 -0
  51. package/dist/utils/processUtils.js +14 -0
  52. package/dist/utils/webApplicationSession.js +58 -0
  53. package/dist/utils/webHotReloadSession.js +212 -0
  54. package/dist/utils/webServerUtils.js +195 -0
  55. package/dist/utils/zipUtils.js +20 -2
  56. package/package.json +4 -2
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TEST_BUILD_FLAGS = exports.CLI_BUILD_FLAGS = exports.LINUX_BUILD_FLAGS = exports.MACOS_BUILD_FLAGS = exports.IOS_BUILD_FLAGS = exports.IOS_DEVICE_BUILD_FLAGS = exports.RELEASE_BUILD_FLAGS = exports.DEBUG_BUILD_FLAGS = exports.ENABLE_RUNTIME_TRACES_BUILD_FLAGS = exports.ENABLE_RUNTIME_LOGS_BUILD_FLAGS = exports.STABLE_EXEC_BAZELRC_BLOCK = exports.STABLE_EXEC_BUILD_FLAGS = exports.ANDROID_X86_64_BUILD_FLAGS = exports.ANDROID_ARMV7_BUILD_FLAGS = exports.ANDROID_ARM64_BUILD_FLAGS = exports.ANDROID_BUILD_FLAGS = exports.COPY_CONFIG_PATH = exports.LINUX_SETUP_SCRIPT_DIR_PATH = exports.MACOS_SETUP_SCRIPT_DIR_PATH = exports.SETUP_SCRIPT_DIR_PATH = exports.BOOTSTRAP_DIR_PATH = exports.META_DIR_PATH = exports.CONFIG_DIR_PATH = exports.CLI_ROOT = exports.ANDROID_EXPORTED_LIBRARY_TAG = exports.IOS_EXPORTED_LIBRARY_TAG = exports.CLI_BAZEL_APPLICATION_TAG = exports.LINUX_BAZEL_APPLICATION_TAG = exports.MACOS_BAZEL_APPLICATION_TAG = exports.ANDROID_BAZEL_APPLICATION_TAG = exports.IOS_BAZEL_APPLICATION_TAG = exports.VALID_PLATFORMS = exports.TEMPLATE_BASE_PATHS = exports.ALL_ARCHITECTURES = exports.Architecture = exports.PLATFORM = exports.ANSI_COLORS = exports.BAZEL_EXECUTABLES = exports.BAZEL_BIN_ENV = exports.VALDI_CONFIG_PATHS = void 0;
3
+ exports.TEST_BUILD_FLAGS = exports.WEB_BUILD_FLAGS = exports.CLI_BUILD_FLAGS = exports.LINUX_BUILD_FLAGS = exports.MACOS_BUILD_FLAGS = exports.IOS_BUILD_FLAGS = exports.IOS_DEVICE_BUILD_FLAGS = exports.RELEASE_BUILD_FLAGS = exports.DEBUG_BUILD_FLAGS = exports.ENABLE_RUNTIME_TRACES_BUILD_FLAGS = exports.ENABLE_RUNTIME_LOGS_BUILD_FLAGS = exports.STABLE_EXEC_BAZELRC_BLOCK = exports.STABLE_EXEC_BUILD_FLAGS = exports.ANDROID_X86_64_BUILD_FLAGS = exports.ANDROID_ARMV7_BUILD_FLAGS = exports.ANDROID_ARM64_BUILD_FLAGS = exports.ANDROID_BUILD_FLAGS = exports.COPY_CONFIG_PATH = exports.LINUX_SETUP_SCRIPT_DIR_PATH = exports.MACOS_SETUP_SCRIPT_DIR_PATH = exports.SETUP_SCRIPT_DIR_PATH = exports.BOOTSTRAP_DIR_PATH = exports.META_DIR_PATH = exports.CONFIG_DIR_PATH = exports.CLI_ROOT = exports.WEB_EXPORTED_LIBRARY_TAG = exports.ANDROID_EXPORTED_LIBRARY_TAG = exports.IOS_EXPORTED_LIBRARY_TAG = exports.WEB_BAZEL_APPLICATION_TAG = exports.CLI_BAZEL_APPLICATION_TAG = exports.LINUX_BAZEL_APPLICATION_TAG = exports.MACOS_BAZEL_APPLICATION_TAG = exports.ANDROID_BAZEL_APPLICATION_TAG = exports.IOS_BAZEL_APPLICATION_TAG = exports.VALID_PLATFORMS = exports.TEMPLATE_BASE_PATHS = exports.ALL_ARCHITECTURES = exports.Architecture = exports.PLATFORM = exports.ANSI_COLORS = exports.BAZEL_EXECUTABLES = exports.BAZEL_BIN_ENV = exports.VALDI_CONFIG_PATHS = void 0;
4
4
  exports.androidPlatformsFlag = androidPlatformsFlag;
5
5
  const tslib_1 = require("tslib");
6
6
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -23,6 +23,7 @@ var PLATFORM;
23
23
  PLATFORM["MACOS"] = "macos";
24
24
  PLATFORM["LINUX"] = "linux";
25
25
  PLATFORM["CLI"] = "cli";
26
+ PLATFORM["WEB"] = "web";
26
27
  })(PLATFORM || (exports.PLATFORM = PLATFORM = {}));
27
28
  var Architecture;
28
29
  (function (Architecture) {
@@ -47,15 +48,28 @@ var TEMPLATE_BASE_PATHS;
47
48
  TEMPLATE_BASE_PATHS["AGENTS"] = "AGENTS.md.template";
48
49
  TEMPLATE_BASE_PATHS["RULES_PYTHON_PATCH"] = "bzl/patches/rules_python/1.9.0/remove_setuptools_spaces.patch.template";
49
50
  TEMPLATE_BASE_PATHS["RULES_PYTHON_PATCH_BUILD"] = "bzl/patches/rules_python/1.9.0/BUILD.bazel.template";
51
+ TEMPLATE_BASE_PATHS["ANDROID_MVN_LOCK"] = "android_mvn_install.json.template";
52
+ TEMPLATE_BASE_PATHS["ANDROID_IDE_COMMON_LOCK"] = "android_ide_common_30_1_3_install.json.template";
53
+ TEMPLATE_BASE_PATHS["MAVEN_LOCK"] = "maven_install.json.template";
54
+ TEMPLATE_BASE_PATHS["RULES_ANDROID_MAVEN_LOCK"] = "rules_android_maven_install.json.template";
50
55
  })(TEMPLATE_BASE_PATHS || (exports.TEMPLATE_BASE_PATHS = TEMPLATE_BASE_PATHS = {}));
51
- exports.VALID_PLATFORMS = [PLATFORM.ANDROID, PLATFORM.IOS, PLATFORM.MACOS, PLATFORM.LINUX, PLATFORM.CLI];
56
+ exports.VALID_PLATFORMS = [
57
+ PLATFORM.ANDROID,
58
+ PLATFORM.IOS,
59
+ PLATFORM.MACOS,
60
+ PLATFORM.LINUX,
61
+ PLATFORM.CLI,
62
+ PLATFORM.WEB,
63
+ ];
52
64
  exports.IOS_BAZEL_APPLICATION_TAG = 'valdi_ios_application';
53
65
  exports.ANDROID_BAZEL_APPLICATION_TAG = 'valdi_android_application';
54
66
  exports.MACOS_BAZEL_APPLICATION_TAG = 'valdi_macos_application';
55
67
  exports.LINUX_BAZEL_APPLICATION_TAG = 'valdi_linux_application';
56
68
  exports.CLI_BAZEL_APPLICATION_TAG = 'valdi_cli_application';
69
+ exports.WEB_BAZEL_APPLICATION_TAG = 'valdi_web_application';
57
70
  exports.IOS_EXPORTED_LIBRARY_TAG = 'valdi_ios_exported_library';
58
71
  exports.ANDROID_EXPORTED_LIBRARY_TAG = 'valdi_android_exported_library';
72
+ exports.WEB_EXPORTED_LIBRARY_TAG = 'valdi_web_exported_library';
59
73
  exports.CLI_ROOT = path_1.default.join(__dirname, '../..');
60
74
  exports.CONFIG_DIR_PATH = path_1.default.join(exports.CLI_ROOT, '.config');
61
75
  exports.META_DIR_PATH = path_1.default.join(exports.CLI_ROOT, '.metadata');
@@ -94,4 +108,5 @@ const INLINE_ASSETS_BUILD_FLAGS = ['--@valdi//bzl/valdi:assets_mode=inline'];
94
108
  exports.MACOS_BUILD_FLAGS = [...INLINE_ASSETS_BUILD_FLAGS, '--repo_env=VALDI_PLATFORM_DEPENDENCIES=macos'];
95
109
  exports.LINUX_BUILD_FLAGS = [...INLINE_ASSETS_BUILD_FLAGS, '--repo_env=VALDI_PLATFORM_DEPENDENCIES=linux'];
96
110
  exports.CLI_BUILD_FLAGS = [...INLINE_ASSETS_BUILD_FLAGS, '--repo_env=VALDI_PLATFORM_DEPENDENCIES=cli'];
111
+ exports.WEB_BUILD_FLAGS = ['--define', 'enable_web=true', ...INLINE_ASSETS_BUILD_FLAGS];
97
112
  exports.TEST_BUILD_FLAGS = INLINE_ASSETS_BUILD_FLAGS;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DevSetupHelper = exports.HOME_DIR = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const errors_1 = require("../core/errors");
5
6
  const fs_1 = tslib_1.__importDefault(require("fs"));
6
7
  const path_1 = tslib_1.__importDefault(require("path"));
7
8
  const constants_1 = require("../core/constants");
@@ -36,8 +37,16 @@ class DevSetupHelper {
36
37
  for (const command of commands) {
37
38
  console.log(`- ${command}`);
38
39
  }
39
- const result = await (0, cliUtils_1.spawnCliCommand)(command, undefined, 'inherit', false, true);
40
- return result.stdout;
40
+ try {
41
+ const result = await (0, cliUtils_1.spawnCliCommand)(command, undefined, 'inherit', false, true);
42
+ return result.stdout;
43
+ }
44
+ catch (error) {
45
+ const detail = error instanceof Error && error.message ? `\n${error.message}` : '';
46
+ throw new errors_1.CliError(`${guide} failed while running:\n ${commands.join('\n ')}${detail}\n` +
47
+ 'If a step asked for a sudo password, re-run this command from an interactive terminal ' +
48
+ '(sudo needs a TTY), or run the failed step manually and then re-run `valdi dev_setup`.');
49
+ }
41
50
  }
42
51
  async writeEnvVariablesToRcFile(envVariables) {
43
52
  const expectedEnvVariable = envVariables.map(e => `export ${e.name}=${e.value}`);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIBTINFO5_INSTALL_COMMAND = void 0;
4
+ exports.installLibtinfo5 = installLibtinfo5;
5
+ const constants_1 = require("../core/constants");
6
+ const logUtils_1 = require("../utils/logUtils");
7
+ exports.LIBTINFO5_INSTALL_COMMAND = 'sudo apt-get install -y libtinfo5';
8
+ async function installLibtinfo5(shell) {
9
+ try {
10
+ await shell.runShell('Installing libtinfo5 (required for Android tools)', [exports.LIBTINFO5_INSTALL_COMMAND]);
11
+ return true;
12
+ }
13
+ catch (error) {
14
+ console.log((0, logUtils_1.wrapInColor)('Warning: libtinfo5 is not available from your package repositories. Some Android command-line tools may not work.', constants_1.ANSI_COLORS.YELLOW_COLOR));
15
+ console.log((0, logUtils_1.wrapInColor)(`Details: ${error instanceof Error ? error.message : 'Unknown error'}`, constants_1.ANSI_COLORS.YELLOW_COLOR));
16
+ console.log((0, logUtils_1.wrapInColor)('On releases that dropped it, enable a repository that still ships libtinfo5 and rerun setup.', constants_1.ANSI_COLORS.YELLOW_COLOR));
17
+ return false;
18
+ }
19
+ }
@@ -11,6 +11,7 @@ const cliUtils_1 = require("../utils/cliUtils");
11
11
  const linuxDistro_1 = require("../utils/linuxDistro");
12
12
  const logUtils_1 = require("../utils/logUtils");
13
13
  const DevSetupHelper_1 = require("./DevSetupHelper");
14
+ const libtinfo5_1 = require("./libtinfo5");
14
15
  const BAZELISK_URL = 'https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-linux-amd64';
15
16
  function getDebianArchitecture() {
16
17
  const nodeArch = os_1.default.arch();
@@ -104,28 +105,7 @@ async function linuxSetup() {
104
105
  }
105
106
  })();
106
107
  if (!libtinfoInstalled) {
107
- try {
108
- const arch = getDebianArchitecture();
109
- const version = '6.3-2ubuntu0.1';
110
- const packageName = `libtinfo5_${version}_${arch}.deb`;
111
- const packageUrl = `https://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/${packageName}`;
112
- const tempPath = path_1.default.join(DevSetupHelper_1.HOME_DIR, `.valdi/tmp/${packageName}`);
113
- const tempDir = path_1.default.dirname(tempPath);
114
- if (!fs_1.default.existsSync(tempDir)) {
115
- fs_1.default.mkdirSync(tempDir, { recursive: true });
116
- }
117
- console.log((0, logUtils_1.wrapInColor)(`Downloading libtinfo5 for ${arch} architecture...`, constants_1.ANSI_COLORS.BLUE_COLOR));
118
- await devSetup.downloadToPath(packageUrl, tempPath);
119
- await devSetup.runShell('Installing libtinfo5 (required for Android tools)', [
120
- `sudo apt install -y ${tempPath}`,
121
- ]);
122
- fs_1.default.unlinkSync(tempPath);
123
- }
124
- catch (error) {
125
- console.log((0, logUtils_1.wrapInColor)('Warning: libtinfo5 installation failed. Some Android command-line tools may not work.', constants_1.ANSI_COLORS.YELLOW_COLOR));
126
- console.log((0, logUtils_1.wrapInColor)(`Details: ${error instanceof Error ? error.message : 'Unknown error'}`, constants_1.ANSI_COLORS.YELLOW_COLOR));
127
- console.log((0, logUtils_1.wrapInColor)('You may need to install it manually if you encounter issues.', constants_1.ANSI_COLORS.YELLOW_COLOR));
128
- }
108
+ await (0, libtinfo5_1.installLibtinfo5)(devSetup);
129
109
  }
130
110
  }
131
111
  else if (distro.type === linuxDistro_1.LinuxDistroType.REDHAT) {
@@ -92,8 +92,9 @@ class BazelLabel {
92
92
  get apparentRepo() {
93
93
  if (!this.repo)
94
94
  return undefined;
95
- const tildeIndex = this.repo.indexOf('~');
96
- return tildeIndex >= 0 ? this.repo.slice(0, tildeIndex) : this.repo;
95
+ const repo = this.repo.replace(/^@+/, '');
96
+ const separatorIndex = repo.search(/[~+]/);
97
+ return separatorIndex > 0 ? repo.slice(0, separatorIndex) : repo;
97
98
  }
98
99
  toString() {
99
100
  const repoPrefix = this.repo ? `@${this.repo}` : '';
@@ -132,10 +133,12 @@ class BazelCommandCache {
132
133
  }
133
134
  }
134
135
  class BazelClient {
136
+ machineOutput;
135
137
  workspaceRootCache;
136
138
  executionRootCache;
137
139
  stableExecArgsCache;
138
- constructor() {
140
+ constructor(machineOutput = false) {
141
+ this.machineOutput = machineOutput;
139
142
  this.workspaceRootCache = new BazelCommandCache(async () => {
140
143
  return this.runCommandAndGetTrimmedStdOut('info workspace');
141
144
  });
@@ -248,7 +251,11 @@ class BazelClient {
248
251
  }
249
252
  async spawnCommand(command, stdioMode = DEFAULT_STDIO_MODE, extraArgs = '') {
250
253
  const commandWithOptions = getBazelCommandString(command, extraArgs, false);
251
- console.log(`${(0, logUtils_1.wrapInColor)('Running Bazel command:', constants_1.ANSI_COLORS.YELLOW_COLOR)} ${getBazelCli()} ${command} ${extraArgs}`);
254
+ const log = this.machineOutput ? console.error : console.log;
255
+ log(`${(0, logUtils_1.wrapInColor)('Running Bazel command:', constants_1.ANSI_COLORS.YELLOW_COLOR)} ${getBazelCli()} ${command} ${extraArgs}`);
256
+ if (this.machineOutput && stdioMode === 'inherit') {
257
+ stdioMode = ['ignore', 2, 2];
258
+ }
252
259
  return await (0, cliUtils_1.spawnCliCommand)(commandWithOptions, undefined, stdioMode, true, true);
253
260
  }
254
261
  async resolveTarget(pathStr) {
@@ -18,7 +18,7 @@ function makeArgsBuilder(nestedBuilder) {
18
18
  return yargs => {
19
19
  yargs
20
20
  .positional('platform', {
21
- describe: 'Platform to build the library or application for: <ios|android>',
21
+ describe: 'Platform to build for: <ios|android|macos|cli|web>',
22
22
  type: 'string',
23
23
  choices: constants_1.VALID_PLATFORMS,
24
24
  coerce: arg => {
@@ -26,7 +26,7 @@ function makeArgsBuilder(nestedBuilder) {
26
26
  },
27
27
  })
28
28
  .option('build_config', {
29
- describe: 'Specifiy whether the application or library should be built in release or debug mode',
29
+ describe: 'Specifiy whether the target should be built in release or debug mode',
30
30
  type: 'string',
31
31
  choices: ['debug', 'release'],
32
32
  default: 'debug',
@@ -83,6 +83,9 @@ function getApplicationTargetTagForPlatform(platform) {
83
83
  case constants_1.PLATFORM.CLI: {
84
84
  return constants_1.CLI_BAZEL_APPLICATION_TAG;
85
85
  }
86
+ case constants_1.PLATFORM.WEB: {
87
+ return constants_1.WEB_BAZEL_APPLICATION_TAG;
88
+ }
86
89
  }
87
90
  }
88
91
  function getExportedLibraryTargetTagForPlatform(platform) {
@@ -102,6 +105,9 @@ function getExportedLibraryTargetTagForPlatform(platform) {
102
105
  case constants_1.PLATFORM.CLI: {
103
106
  throw new errors_1.CliError('Exported library is not supported for CLI platform');
104
107
  }
108
+ case constants_1.PLATFORM.WEB: {
109
+ return constants_1.WEB_EXPORTED_LIBRARY_TAG;
110
+ }
105
111
  }
106
112
  }
107
113
  function applicationExtensionForPlatform(platform) {
@@ -121,6 +127,9 @@ function applicationExtensionForPlatform(platform) {
121
127
  case constants_1.PLATFORM.CLI: {
122
128
  return '';
123
129
  }
130
+ case constants_1.PLATFORM.WEB: {
131
+ return '.zip';
132
+ }
124
133
  }
125
134
  }
126
135
  function exportedLibraryExtensionForPlatform(platform) {
@@ -140,6 +149,9 @@ function exportedLibraryExtensionForPlatform(platform) {
140
149
  case constants_1.PLATFORM.CLI: {
141
150
  return '.zip';
142
151
  }
152
+ case constants_1.PLATFORM.WEB: {
153
+ return '.zip';
154
+ }
143
155
  }
144
156
  }
145
157
  async function getOutputFilePath(bazel, expectedExtension, target, bazelArgs = '') {
@@ -203,6 +215,9 @@ function resolveBazelBuildArgs(platform, buildConfig, architectures, forDevice,
203
215
  else if (platform === constants_1.PLATFORM.LINUX) {
204
216
  allArgs.push(...constants_1.LINUX_BUILD_FLAGS);
205
217
  }
218
+ else if (platform === constants_1.PLATFORM.WEB) {
219
+ allArgs.push(...constants_1.WEB_BUILD_FLAGS);
220
+ }
206
221
  if (platform === constants_1.PLATFORM.ANDROID) {
207
222
  allArgs.push(...constants_1.ANDROID_BUILD_FLAGS);
208
223
  for (const architecture of architectures) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDeviceBuild = isDeviceBuild;
3
4
  exports.getBuildInfo = getBuildInfo;
4
5
  const tslib_1 = require("tslib");
5
6
  const separator_1 = tslib_1.__importDefault(require("inquirer/lib/objects/separator"));
@@ -29,9 +30,12 @@ async function getDeviceChoice(platform) {
29
30
  choices.push(...availableDevices.map(device => ({ name: device, value: device })));
30
31
  return await (0, cliUtils_1.getUserChoice)(choices, 'Please select a device to perform the install:');
31
32
  }
33
+ function isDeviceBuild(simulator) {
34
+ return simulator === false;
35
+ }
32
36
  async function getBuildInfo(argv, bazel, checkDevice) {
33
37
  const platform = argv.getArgument('platform');
34
- const forDevice = !!argv.getArgument('simulator');
38
+ const forDevice = isDeviceBuild(argv.getArgument('simulator'));
35
39
  let selectedDevice;
36
40
  let architectures = constants_1.ALL_ARCHITECTURES;
37
41
  if (platform === constants_1.PLATFORM.ANDROID) {
@@ -35,13 +35,13 @@ function spawnCliCommand(command, cwd, stdioMode, quiet, rejectOnFailure) {
35
35
  child.stdout?.on('data', (data) => {
36
36
  stdout += data.toString();
37
37
  if (!quiet) {
38
- process.stdout.write(stdout);
38
+ process.stdout.write(data);
39
39
  }
40
40
  });
41
41
  child.stderr?.on('data', (data) => {
42
42
  stderr += data.toString();
43
43
  if (!quiet) {
44
- process.stderr.write(stderr);
44
+ process.stderr.write(data);
45
45
  }
46
46
  });
47
47
  child.on('close', code => {
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncDirectoryContents = syncDirectoryContents;
4
+ const tslib_1 = require("tslib");
5
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
7
+ let temporaryFileCounter = 0;
8
+ function isPathInside(parentPath, childPath) {
9
+ const relativePath = node_path_1.default.relative(parentPath, childPath);
10
+ return (relativePath === '' ||
11
+ (!relativePath.startsWith(`..${node_path_1.default.sep}`) && relativePath !== '..' && !node_path_1.default.isAbsolute(relativePath)));
12
+ }
13
+ async function countFiles(directoryPath) {
14
+ const entries = await node_fs_1.default.promises.readdir(directoryPath, { withFileTypes: true });
15
+ let count = 0;
16
+ for (const entry of entries) {
17
+ const entryPath = node_path_1.default.join(directoryPath, entry.name);
18
+ count += entry.isDirectory() ? await countFiles(entryPath) : 1;
19
+ }
20
+ return count;
21
+ }
22
+ async function makeTreeWritable(entryPath) {
23
+ const stats = await node_fs_1.default.promises.lstat(entryPath);
24
+ if (stats.isDirectory()) {
25
+ await node_fs_1.default.promises.chmod(entryPath, (stats.mode & 0o777) | 0o700);
26
+ const entries = await node_fs_1.default.promises.readdir(entryPath);
27
+ for (const entry of entries) {
28
+ await makeTreeWritable(node_path_1.default.join(entryPath, entry));
29
+ }
30
+ }
31
+ else if (stats.isFile()) {
32
+ await node_fs_1.default.promises.chmod(entryPath, (stats.mode & 0o777) | 0o600);
33
+ }
34
+ }
35
+ async function removeTree(entryPath) {
36
+ await makeTreeWritable(entryPath);
37
+ await node_fs_1.default.promises.rm(entryPath, { force: true, recursive: true });
38
+ }
39
+ async function filesHaveEqualContents(sourcePath, destinationPath) {
40
+ const [sourceStats, destinationStats] = await Promise.all([
41
+ node_fs_1.default.promises.stat(sourcePath),
42
+ node_fs_1.default.promises.stat(destinationPath),
43
+ ]);
44
+ if (sourceStats.size !== destinationStats.size) {
45
+ return false;
46
+ }
47
+ const [sourceContents, destinationContents] = await Promise.all([
48
+ node_fs_1.default.promises.readFile(sourcePath),
49
+ node_fs_1.default.promises.readFile(destinationPath),
50
+ ]);
51
+ return sourceContents.equals(destinationContents);
52
+ }
53
+ async function replaceFile(sourcePath, destinationPath, sourceMode) {
54
+ const temporaryPath = `${destinationPath}.valdi-export-${process.pid}-${temporaryFileCounter++}`;
55
+ try {
56
+ await node_fs_1.default.promises.copyFile(sourcePath, temporaryPath);
57
+ await node_fs_1.default.promises.chmod(temporaryPath, sourceMode);
58
+ await node_fs_1.default.promises.rename(temporaryPath, destinationPath);
59
+ }
60
+ finally {
61
+ await node_fs_1.default.promises.rm(temporaryPath, { force: true });
62
+ }
63
+ }
64
+ async function syncFile(sourcePath, destinationPath, destinationEntry, result) {
65
+ const sourceStats = await node_fs_1.default.promises.stat(sourcePath);
66
+ const sourceMode = sourceStats.mode & 0o777;
67
+ if (destinationEntry?.isFile() && (await filesHaveEqualContents(sourcePath, destinationPath))) {
68
+ result.unchanged += 1;
69
+ return;
70
+ }
71
+ if (destinationEntry?.isDirectory()) {
72
+ const removedFileCount = await countFiles(destinationPath);
73
+ result.removed += removedFileCount;
74
+ await removeTree(destinationPath);
75
+ }
76
+ else if (destinationEntry?.isSymbolicLink()) {
77
+ result.removed += 1;
78
+ await node_fs_1.default.promises.rm(destinationPath);
79
+ }
80
+ await replaceFile(sourcePath, destinationPath, sourceMode);
81
+ if (destinationEntry) {
82
+ result.updated += 1;
83
+ }
84
+ else {
85
+ result.added += 1;
86
+ }
87
+ }
88
+ async function syncDirectory(sourceDirectory, destinationDirectory, result) {
89
+ if (node_fs_1.default.existsSync(destinationDirectory)) {
90
+ const destinationStats = await node_fs_1.default.promises.lstat(destinationDirectory);
91
+ if (destinationStats.isDirectory()) {
92
+ const destinationMode = destinationStats.mode & 0o777;
93
+ const writableDestinationMode = destinationMode | 0o700;
94
+ if (destinationMode !== writableDestinationMode) {
95
+ await node_fs_1.default.promises.chmod(destinationDirectory, writableDestinationMode);
96
+ }
97
+ }
98
+ else {
99
+ result.removed += 1;
100
+ await removeTree(destinationDirectory);
101
+ await node_fs_1.default.promises.mkdir(destinationDirectory, { recursive: true });
102
+ }
103
+ }
104
+ else {
105
+ await node_fs_1.default.promises.mkdir(destinationDirectory, { recursive: true });
106
+ }
107
+ const [sourceEntries, destinationEntries] = await Promise.all([
108
+ node_fs_1.default.promises.readdir(sourceDirectory, { withFileTypes: true }),
109
+ node_fs_1.default.promises.readdir(destinationDirectory, { withFileTypes: true }),
110
+ ]);
111
+ const remainingDestinationEntries = new Map(destinationEntries.map(entry => [entry.name, entry]));
112
+ await Promise.all(sourceEntries.map(async (sourceEntry) => {
113
+ const sourcePath = node_path_1.default.join(sourceDirectory, sourceEntry.name);
114
+ const destinationPath = node_path_1.default.join(destinationDirectory, sourceEntry.name);
115
+ const destinationEntry = remainingDestinationEntries.get(sourceEntry.name);
116
+ remainingDestinationEntries.delete(sourceEntry.name);
117
+ if (sourceEntry.isDirectory()) {
118
+ await syncDirectory(sourcePath, destinationPath, result);
119
+ }
120
+ else if (sourceEntry.isFile() || sourceEntry.isSymbolicLink()) {
121
+ await syncFile(sourcePath, destinationPath, destinationEntry, result);
122
+ }
123
+ else {
124
+ throw new Error(`Unsupported entry in exported web package: ${sourcePath}`);
125
+ }
126
+ }));
127
+ await Promise.all(Array.from(remainingDestinationEntries.values(), async (destinationEntry) => {
128
+ const destinationPath = node_path_1.default.join(destinationDirectory, destinationEntry.name);
129
+ const removedFileCount = destinationEntry.isDirectory() ? await countFiles(destinationPath) : 1;
130
+ result.removed += removedFileCount;
131
+ await removeTree(destinationPath);
132
+ }));
133
+ }
134
+ async function syncDirectoryContents(sourceDirectory, destinationDirectory) {
135
+ const resolvedSourceDirectory = node_path_1.default.resolve(sourceDirectory);
136
+ const resolvedDestinationDirectory = node_path_1.default.resolve(destinationDirectory);
137
+ if (isPathInside(resolvedSourceDirectory, resolvedDestinationDirectory) ||
138
+ isPathInside(resolvedDestinationDirectory, resolvedSourceDirectory)) {
139
+ throw new Error('Source and destination directories must not overlap');
140
+ }
141
+ const sourceStats = await node_fs_1.default.promises.stat(resolvedSourceDirectory);
142
+ if (!sourceStats.isDirectory()) {
143
+ throw new Error(`Directory export source is not a directory: ${resolvedSourceDirectory}`);
144
+ }
145
+ const result = {
146
+ added: 0,
147
+ updated: 0,
148
+ removed: 0,
149
+ unchanged: 0,
150
+ };
151
+ await syncDirectory(resolvedSourceDirectory, resolvedDestinationDirectory, result);
152
+ return result;
153
+ }
@@ -33,7 +33,7 @@ function makeCommandHandler(cb) {
33
33
  const argumentsResolver = new ArgumentsResolver_1.ArgumentsResolver(argv);
34
34
  try {
35
35
  await cb(argumentsResolver);
36
- process.exitCode = 0;
36
+ process.exitCode ??= 0;
37
37
  }
38
38
  catch (error) {
39
39
  process.exitCode = 1;
@@ -11,7 +11,7 @@ function parseGitHubRepoSlug(repoUrl) {
11
11
  }
12
12
  return `${match[1]}/${match[2]}`;
13
13
  }
14
- const LATEST_RELEASE_HINT = 'Use --valdiVersion=latest to retry, or --valdiVersion=<tag> (e.g. main or v1.0.0) to pin a version.';
14
+ const LATEST_RELEASE_HINT = 'Use --valdiVersion=latest to retry, or --valdiVersion=<tag> (e.g. main or 1.0.0) to pin a version.';
15
15
  async function getLatestReleaseTag(repoUrl) {
16
16
  const slug = parseGitHubRepoSlug(repoUrl);
17
17
  let response;
@@ -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
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitForShutdownSignal = waitForShutdownSignal;
4
+ function waitForShutdownSignal() {
5
+ return new Promise(resolve => {
6
+ const resolveOnce = () => {
7
+ process.off('SIGINT', resolveOnce);
8
+ process.off('SIGTERM', resolveOnce);
9
+ resolve();
10
+ };
11
+ process.once('SIGINT', resolveOnce);
12
+ process.once('SIGTERM', resolveOnce);
13
+ });
14
+ }