@snap/valdi 1.1.7 → 1.2.1

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 (96) hide show
  1. package/.metadata/.bazelrc.template +9 -7
  2. package/.metadata/AGENTS.md.template +7 -0
  3. package/.metadata/MODULE.bazel.template +47 -3
  4. package/.metadata/README.md.template +2 -2
  5. package/.metadata/bzl/patches/rules_python/1.9.0/BUILD.bazel.template +1 -0
  6. package/.metadata/bzl/patches/rules_python/1.9.0/remove_setuptools_spaces.patch.template +96 -0
  7. package/.metadata/skill-tests-README.md.template +1 -1
  8. package/README.md +47 -14
  9. package/bundled-skills/registry.json +2 -1
  10. package/bundled-skills/skills/valdi-animations/skill.md +49 -0
  11. package/bundled-skills/skills/valdi-async/skill.md +3 -2
  12. package/bundled-skills/skills/valdi-async/tests/README.md +1 -1
  13. package/bundled-skills/skills/valdi-bazel/skill.md +2 -6
  14. package/bundled-skills/skills/valdi-component-tests/tests/README.md +1 -1
  15. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +18 -0
  16. package/bundled-skills/skills/valdi-custom-view/skill.md +1 -1
  17. package/bundled-skills/skills/valdi-error-handling/skill.md +1 -1
  18. package/bundled-skills/skills/valdi-gestures/skill.md +3 -3
  19. package/bundled-skills/skills/valdi-migrate/skill.md +2 -1
  20. package/bundled-skills/skills/valdi-migrate/tests/README.md +2 -2
  21. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +4 -4
  22. package/bundled-skills/skills/valdi-mock-to-module/skill.md +9 -6
  23. package/bundled-skills/skills/valdi-overview/skill.md +2 -1
  24. package/bundled-skills/skills/valdi-perf/skill.md +121 -5
  25. package/bundled-skills/skills/valdi-perf/tests/README.md +1 -1
  26. package/bundled-skills/skills/valdi-pr-review/skill.md +189 -0
  27. package/bundled-skills/skills/valdi-profile/skill.md +5 -3
  28. package/bundled-skills/skills/valdi-setup/skill.md +3 -6
  29. package/bundled-skills/skills/valdi-testing/skill.md +1 -1
  30. package/bundled-skills/skills/valdi-tsx/skill.md +47 -11
  31. package/bundled-skills/skills/valdi-tsx/tests/README.md +1 -1
  32. package/debugger/README.md +356 -0
  33. package/debugger/debugger-actions.js +373 -0
  34. package/debugger/debugger-api.js +225 -0
  35. package/debugger/debugger-bootstrap.js +295 -0
  36. package/debugger/debugger-model.js +790 -0
  37. package/debugger/debugger-performance.js +573 -0
  38. package/debugger/debugger-preview-html.js +676 -0
  39. package/debugger/debugger-providers.js +389 -0
  40. package/debugger/debugger-render.js +529 -0
  41. package/debugger/debugger-runtime.js +387 -0
  42. package/debugger/debugger-session.js +188 -0
  43. package/debugger/debugger-settings.js +209 -0
  44. package/debugger/debugger-state.js +221 -0
  45. package/debugger/debugger-tree-model.js +539 -0
  46. package/debugger/debugger.css +1865 -0
  47. package/debugger/devtools-panel.css +1318 -0
  48. package/debugger/devtools-panel.html +273 -0
  49. package/debugger/devtools-panel.js +3329 -0
  50. package/debugger/index.html +279 -0
  51. package/dist/commands/bootstrap.js +7 -6
  52. package/dist/commands/build.js +7 -1
  53. package/dist/commands/debugger.js +163 -0
  54. package/dist/commands/doctor.js +3 -62
  55. package/dist/commands/export.js +47 -16
  56. package/dist/commands/hotreload.js +247 -27
  57. package/dist/commands/inspect.js +5 -2
  58. package/dist/commands/inspect_commands/input.js +176 -0
  59. package/dist/commands/inspect_commands/snapshot.js +1 -1
  60. package/dist/commands/inspect_commands/tree.js +1 -1
  61. package/dist/commands/install.js +79 -2
  62. package/dist/commands/projectsync.js +15 -0
  63. package/dist/commands/webHotreload.js +31 -0
  64. package/dist/core/constants.js +34 -7
  65. package/dist/debugger/chromiumConsole.js +279 -0
  66. package/dist/debugger/inputClient.js +473 -0
  67. package/dist/debugger/server.js +3801 -0
  68. package/dist/debugger/targetRegistry.js +436 -0
  69. package/dist/debugger/webPreviewPerformance.js +864 -0
  70. package/dist/index.js +0 -0
  71. package/dist/utils/BazelClient.js +34 -5
  72. package/dist/utils/applicationUtils.js +20 -2
  73. package/dist/utils/buildInfo.js +5 -1
  74. package/dist/utils/chromiumDevToolsClient.js +350 -0
  75. package/dist/utils/cliUtils.js +2 -2
  76. package/dist/utils/daemonClient.js +364 -44
  77. package/dist/utils/directorySync.js +153 -0
  78. package/dist/utils/githubUtils.js +1 -1
  79. package/dist/utils/hermesClient.js +82 -176
  80. package/dist/utils/loopbackHost.js +14 -0
  81. package/dist/utils/owlCdpClient.js +282 -0
  82. package/dist/utils/owlDevToolsExtension.js +142 -0
  83. package/dist/utils/processUtils.js +14 -0
  84. package/dist/utils/stringUtils.js +13 -1
  85. package/dist/utils/webApplicationSession.js +58 -0
  86. package/dist/utils/webHotReloadSession.js +212 -0
  87. package/dist/utils/webServerUtils.js +195 -0
  88. package/dist/utils/zipUtils.js +20 -2
  89. package/package.json +4 -2
  90. package/dist/commands/inspect_commands/snapshot.spec.js +0 -105
  91. package/dist/core/packageFiles.spec.js +0 -29
  92. package/dist/preview/previewGenerator.spec.js +0 -203
  93. package/dist/preview/viewModelParser.spec.js +0 -171
  94. package/dist/utils/linuxDistro.spec.js +0 -122
  95. package/dist/utils/skillsAdapters.spec.js +0 -141
  96. package/dist/utils/stringUtils.spec.js +0 -81
@@ -8,11 +8,13 @@ const constants_1 = require("../core/constants");
8
8
  const errors_1 = require("../core/errors");
9
9
  const BazelClient_1 = require("../utils/BazelClient");
10
10
  const applicationUtils_1 = require("../utils/applicationUtils");
11
+ const directorySync_1 = require("../utils/directorySync");
11
12
  const errorUtils_1 = require("../utils/errorUtils");
12
13
  const fileUtils_1 = require("../utils/fileUtils");
13
14
  const logUtils_1 = require("../utils/logUtils");
14
15
  const tempDir_1 = require("../utils/tempDir");
15
16
  const zipUtils_1 = require("../utils/zipUtils");
17
+ const OUTPUT_FORMATS = ['archive', 'directory'];
16
18
  async function decompressAndMoveXCFrameworkIntoDestination(bazelOutputFilePath, resolvedOutputPath) {
17
19
  await (0, tempDir_1.withTempDir)(async (tempDir) => {
18
20
  await (0, zipUtils_1.decompressTo)(bazelOutputFilePath, tempDir);
@@ -24,37 +26,61 @@ async function decompressAndMoveXCFrameworkIntoDestination(bazelOutputFilePath,
24
26
  await fs.promises.rename(inputDir, resolvedOutputPath);
25
27
  });
26
28
  }
29
+ function getExportOutputExtension(platform) {
30
+ return (0, applicationUtils_1.exportedLibraryExtensionForPlatform)(platform);
31
+ }
32
+ async function getTargetToExport(argv, bazel, platform) {
33
+ return await argv.getArgumentOrResolve('library', () => {
34
+ console.log('No library specified querying available targets...');
35
+ return (0, applicationUtils_1.selectBazelTarget)(bazel, (0, applicationUtils_1.getExportedLibraryTargetTagForPlatform)(platform), 'valdi_exported_library', 'Please select a library to export:');
36
+ });
37
+ }
27
38
  async function valdiExport(argv) {
28
39
  const bazel = new BazelClient_1.BazelClient();
29
40
  const platform = argv.getArgument('platform');
30
41
  const bazelArgs = (0, applicationUtils_1.resolveBazelBuildArgs)(platform, argv.getArgument('build_config'), constants_1.ALL_ARCHITECTURES, false, argv.getArgument('enable_runtime_logs'), argv.getArgument('enable_runtime_traces'), argv.getArgument('bazel_args'));
31
42
  const resolvedOutputPath = path_1.default.resolve(argv.getArgument('output_path'));
32
- const expectedExtension = (0, applicationUtils_1.exportedLibraryExtensionForPlatform)(platform);
33
- if (!resolvedOutputPath.endsWith(expectedExtension)) {
43
+ const outputFormat = argv.getArgument('output_format');
44
+ const expectedExtension = getExportOutputExtension(platform);
45
+ if (outputFormat === 'directory' && platform !== constants_1.PLATFORM.WEB) {
46
+ throw new errors_1.CliError("The 'directory' output format is only supported for web exports");
47
+ }
48
+ if (outputFormat === 'archive' && !resolvedOutputPath.endsWith(expectedExtension)) {
34
49
  throw new errors_1.CliError(`Output path for platform '${platform}' must have ${expectedExtension} file extension`);
35
50
  }
36
- (0, fileUtils_1.removeFileOrDirAtPath)(resolvedOutputPath);
51
+ if (outputFormat === 'archive') {
52
+ (0, fileUtils_1.removeFileOrDirAtPath)(resolvedOutputPath);
53
+ }
37
54
  const directoryPath = path_1.default.dirname(resolvedOutputPath);
38
55
  if (!fs.existsSync(directoryPath)) {
39
56
  fs.mkdirSync(directoryPath, { recursive: true });
40
57
  }
41
- const library = await argv.getArgumentOrResolve('library', () => {
42
- console.log('No library specified querying available targets...');
43
- return (0, applicationUtils_1.selectBazelTarget)(bazel, (0, applicationUtils_1.getExportedLibraryTargetTagForPlatform)(platform), 'valdi_exported_library', 'Please select a library to export:');
44
- });
45
- console.log('Resolving output paths...');
46
- const bazelOutputExtension = platform === constants_1.PLATFORM.IOS ? '.zip' : expectedExtension;
58
+ const targetToExport = await getTargetToExport(argv, bazel, platform);
59
+ const bazelOutputExtension = platform === constants_1.PLATFORM.IOS ? '.zip' : platform === constants_1.PLATFORM.WEB ? '' : expectedExtension;
47
60
  const bazelOutputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
48
61
  console.log('Resolving output paths...');
49
- return (0, applicationUtils_1.getOutputFilePath)(bazel, bazelOutputExtension, library, bazelArgs);
62
+ return (0, applicationUtils_1.getOutputFilePath)(bazel, bazelOutputExtension, targetToExport, bazelArgs);
50
63
  });
51
- console.log(`Building: ${(0, logUtils_1.wrapInColor)(library, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
52
- await bazel.buildTarget(library, bazelArgs);
53
- console.log(`Copying built target to ${resolvedOutputPath}...`);
54
- if (platform === constants_1.PLATFORM.IOS) {
64
+ console.log(`Building: ${(0, logUtils_1.wrapInColor)(targetToExport, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
65
+ await bazel.buildTarget(targetToExport, bazelArgs);
66
+ if (platform === constants_1.PLATFORM.WEB) {
67
+ if (outputFormat === 'directory') {
68
+ console.log(`Synchronizing built target to ${resolvedOutputPath}...`);
69
+ const syncResult = await (0, directorySync_1.syncDirectoryContents)(bazelOutputFilePath, resolvedOutputPath);
70
+ console.log(`Directory export: ${syncResult.added} added, ${syncResult.updated} updated, ` +
71
+ `${syncResult.removed} removed, ${syncResult.unchanged} unchanged`);
72
+ }
73
+ else {
74
+ console.log(`Copying built target to ${resolvedOutputPath}...`);
75
+ await (0, zipUtils_1.compressDirectoryContentsTo)(bazelOutputFilePath, resolvedOutputPath);
76
+ }
77
+ }
78
+ else if (platform === constants_1.PLATFORM.IOS) {
79
+ console.log(`Copying built target to ${resolvedOutputPath}...`);
55
80
  await decompressAndMoveXCFrameworkIntoDestination(bazelOutputFilePath, resolvedOutputPath);
56
81
  }
57
82
  else {
83
+ console.log(`Copying built target to ${resolvedOutputPath}...`);
58
84
  await fs.promises.copyFile(bazelOutputFilePath, resolvedOutputPath);
59
85
  }
60
86
  (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
@@ -65,7 +91,7 @@ exports.describe = 'Build and export a Valdi library';
65
91
  exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
66
92
  yargs
67
93
  .option('library', {
68
- describe: 'Name of the library to build',
94
+ describe: 'Name of the library to export',
69
95
  type: 'string',
70
96
  requiresArg: true,
71
97
  })
@@ -75,9 +101,14 @@ exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
75
101
  requiresArg: true,
76
102
  })
77
103
  .option('output_path', {
78
- describe: 'The path where to store the built application package',
104
+ describe: 'The path where to store the exported library artifact or directory',
79
105
  type: 'string',
80
106
  requiresArg: true,
107
+ })
108
+ .option('output_format', {
109
+ choices: OUTPUT_FORMATS,
110
+ default: 'archive',
111
+ describe: 'Export web output as an archive or a content-synchronized directory',
81
112
  })
82
113
  .demandOption('output_path');
83
114
  });
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ exports.validateHotreloadPort = validateHotreloadPort;
5
+ exports.hotreloadCleanupCommands = hotreloadCleanupCommands;
6
+ exports.killExistingHotreloaders = killExistingHotreloaders;
7
+ exports.buildHotreloadCommand = buildHotreloadCommand;
8
+ exports.formatHotreloadLifecycleEvent = formatHotreloadLifecycleEvent;
9
+ exports.isCompilerRecompilationSucceededEvent = isCompilerRecompilationSucceededEvent;
4
10
  const child_process_1 = require("child_process");
5
11
  const constants_1 = require("../core/constants");
6
12
  const errors_1 = require("../core/errors");
@@ -8,11 +14,26 @@ const BazelClient_1 = require("../utils/BazelClient");
8
14
  const cliUtils_1 = require("../utils/cliUtils");
9
15
  const errorUtils_1 = require("../utils/errorUtils");
10
16
  const logUtils_1 = require("../utils/logUtils");
11
- function killExistingHotreloaders() {
12
- const commands = [
13
- 'pkill -f valdi_companion',
14
- 'pkill -f run_hotreloader',
15
- ];
17
+ const webHotReloadSession_1 = require("../utils/webHotReloadSession");
18
+ const MIN_PORT = 1;
19
+ const MAX_PORT = 65_535;
20
+ function validateHotreloadPort(port) {
21
+ if (port === undefined) {
22
+ return undefined;
23
+ }
24
+ if (!Number.isInteger(port) || port < MIN_PORT || port > MAX_PORT) {
25
+ throw new errors_1.CliError(`Invalid hotreload port: ${port}. Expected an integer between ${MIN_PORT} and ${MAX_PORT}.`);
26
+ }
27
+ return port;
28
+ }
29
+ function hotreloadCleanupCommands(port) {
30
+ if (port === undefined) {
31
+ return ['pkill -f valdi_companion', 'pkill -f run_hotreloader', `pkill -f 'valdi.*--monitor'`];
32
+ }
33
+ return [`pkill -f 'run_hotreloader.*--port ${port}($| )'`, `pkill -f 'valdi.*--monitor.*--port ${port}($| )'`];
34
+ }
35
+ function killExistingHotreloaders(port) {
36
+ const commands = hotreloadCleanupCommands(port);
16
37
  for (const cmd of commands) {
17
38
  try {
18
39
  (0, child_process_1.execSync)(cmd, { stdio: 'ignore' });
@@ -21,34 +42,189 @@ function killExistingHotreloaders() {
21
42
  }
22
43
  }
23
44
  }
24
- async function hotreloadResolvedTarget(client, resolvedTarget) {
25
- killExistingHotreloaders();
26
- await client.buildTarget(resolvedTarget);
45
+ function shellQuote(value) {
46
+ return `'${value.replaceAll("'", `'\\''`)}'`;
47
+ }
48
+ function buildHotreloadCommand(hotreloadCommand, options) {
49
+ const args = [];
50
+ if (options.port !== undefined) {
51
+ args.push(`--port ${options.port}`);
52
+ }
53
+ if (options.jsonEvents) {
54
+ args.push('--hotreload-json-events', `--hotreload-target ${shellQuote(options.target)}`);
55
+ }
56
+ if (args.length === 0) {
57
+ return hotreloadCommand;
58
+ }
59
+ return `${shellQuote(hotreloadCommand)} ${args.join(' ')}`;
60
+ }
61
+ function formatHotreloadLifecycleEvent(event) {
62
+ return JSON.stringify({ source: 'valdi_hotreload', ...event });
63
+ }
64
+ function lifecycleReporter(enabled, target, port) {
65
+ return (event, returnCode) => {
66
+ if (!enabled) {
67
+ return;
68
+ }
69
+ const payload = {
70
+ event,
71
+ target,
72
+ port: port ?? null,
73
+ time: new Date().toISOString(),
74
+ };
75
+ if (returnCode !== undefined) {
76
+ payload.returnCode = returnCode;
77
+ }
78
+ console.log(formatHotreloadLifecycleEvent(payload));
79
+ };
80
+ }
81
+ function isCompilerRecompilationSucceededEvent(line) {
82
+ const event = parseCompilerHotreloadEvent(line);
83
+ return event?.event === 'recompilation_succeeded';
84
+ }
85
+ function parseCompilerHotreloadEvent(line) {
86
+ try {
87
+ const parsed = JSON.parse(line);
88
+ if (typeof parsed !== 'object' || parsed === null) {
89
+ return undefined;
90
+ }
91
+ const event = parsed;
92
+ return event.source === 'valdi_hotreload' ? event : undefined;
93
+ }
94
+ catch {
95
+ return undefined;
96
+ }
97
+ }
98
+ function runHotreloadWithCompilerEvents(command, cwd, onRecompilationSucceeded, relayCompilerEvents) {
99
+ return new Promise((resolve, reject) => {
100
+ const child = (0, child_process_1.spawn)(command, {
101
+ cwd,
102
+ env: { ...process.env, FORCE_COLOR: '1' },
103
+ shell: process.env['SHELL'] ?? '/bin/bash',
104
+ stdio: ['inherit', 'pipe', 'inherit'],
105
+ });
106
+ let pendingLine = '';
107
+ child.stdout?.on('data', (data) => {
108
+ pendingLine += data.toString();
109
+ const lines = pendingLine.split('\n');
110
+ pendingLine = lines.pop() ?? '';
111
+ for (const line of lines) {
112
+ const compilerEvent = parseCompilerHotreloadEvent(line.trim());
113
+ if (compilerEvent?.event === 'recompilation_succeeded') {
114
+ onRecompilationSucceeded();
115
+ }
116
+ if (compilerEvent === undefined || relayCompilerEvents) {
117
+ process.stdout.write(`${line}\n`);
118
+ }
119
+ }
120
+ });
121
+ child.once('close', code => {
122
+ const compilerEvent = parseCompilerHotreloadEvent(pendingLine.trim());
123
+ if (compilerEvent?.event === 'recompilation_succeeded') {
124
+ onRecompilationSucceeded();
125
+ }
126
+ if (pendingLine !== '' && (compilerEvent === undefined || relayCompilerEvents)) {
127
+ process.stdout.write(pendingLine);
128
+ }
129
+ resolve({ returnCode: code ?? 0, stderr: '', stdout: '' });
130
+ });
131
+ child.once('error', reject);
132
+ });
133
+ }
134
+ function createWebPublicationScheduler(client, sessions) {
135
+ let publicationRequested = false;
136
+ let activePublication;
137
+ const publish = async () => {
138
+ const groups = new Map();
139
+ for (const session of sessions) {
140
+ const key = JSON.stringify([session.applicationTarget, session.bazelArgs]);
141
+ const group = groups.get(key) ?? [];
142
+ group.push(session);
143
+ groups.set(key, group);
144
+ }
145
+ for (const group of groups.values()) {
146
+ const representative = group[0];
147
+ if (!representative) {
148
+ continue;
149
+ }
150
+ console.log(`Rebuilding web application: ${(0, logUtils_1.wrapInColor)(representative.applicationTarget, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
151
+ await client.buildTarget(representative.applicationTarget, representative.bazelArgs);
152
+ await Promise.all(group.map(session => (0, webHotReloadSession_1.publishWebHotReloadSession)(session)));
153
+ console.log(`Published web application to ${group.length} running host${group.length === 1 ? '' : 's'}.`);
154
+ }
155
+ };
156
+ const run = async () => {
157
+ while (publicationRequested) {
158
+ publicationRequested = false;
159
+ try {
160
+ await publish();
161
+ }
162
+ catch (error) {
163
+ console.error((0, logUtils_1.wrapInColor)(`Web rebuild failed; running hosts kept their last successful build. ${String(error)}`, constants_1.ANSI_COLORS.RED_COLOR));
164
+ }
165
+ }
166
+ };
167
+ const start = () => {
168
+ if (activePublication !== undefined) {
169
+ return;
170
+ }
171
+ activePublication = run().finally(() => {
172
+ activePublication = undefined;
173
+ if (publicationRequested) {
174
+ start();
175
+ }
176
+ });
177
+ };
178
+ return {
179
+ drain: async () => {
180
+ while (activePublication !== undefined) {
181
+ await activePublication;
182
+ }
183
+ },
184
+ schedule: () => {
185
+ publicationRequested = true;
186
+ start();
187
+ },
188
+ };
189
+ }
190
+ async function hotreloadResolvedTarget(client, resolvedTarget, port, jsonEvents, report, webSessions) {
191
+ killExistingHotreloaders(port);
192
+ const extraBuildFlags = process.env['VALDI_HOTRELOAD_BUILD_FLAGS'] ?? '';
193
+ report('build_started');
194
+ try {
195
+ await client.buildTarget(resolvedTarget, extraBuildFlags);
196
+ }
197
+ catch (error) {
198
+ report('build_failed');
199
+ throw error;
200
+ }
201
+ report('build_succeeded');
27
202
  const workspaceRoot = await client.getWorkspaceRoot();
28
- const buildOutputs = await client.queryBuildOutputs([resolvedTarget]);
203
+ const buildOutputs = await client.queryBuildOutputs([resolvedTarget], extraBuildFlags);
29
204
  if (buildOutputs.length === 0) {
30
205
  throw new errors_1.CliError(`No build outputs found for target: ${resolvedTarget}`);
31
206
  }
32
207
  const hotreloadCommand = buildOutputs[0] ?? '';
33
- await (0, cliUtils_1.spawnCliCommand)(hotreloadCommand, workspaceRoot, 'inherit', true, false);
34
- }
35
- async function hotreloadTarget(client, target) {
36
- const resolvedLabel = await client.resolveLabel(target);
37
- let resolvedTarget;
38
- if (resolvedLabel.name) {
39
- resolvedTarget = resolvedLabel.toString();
208
+ report('hotreload_starting');
209
+ let result;
210
+ if (webSessions.length === 0) {
211
+ result = await (0, cliUtils_1.spawnCliCommand)(buildHotreloadCommand(hotreloadCommand, {
212
+ jsonEvents,
213
+ port,
214
+ target: resolvedTarget,
215
+ }), workspaceRoot, 'inherit', true, false);
40
216
  }
41
217
  else {
42
- const targets = await client.query(`kind('valdi_hotreload', ${resolvedLabel.toString()}/...)`);
43
- if (targets.length === 0) {
44
- throw new Error(`Could not resolve hot reload target for label ${resolvedLabel.toString()}`);
45
- }
46
- if (targets.length !== 1) {
47
- throw new Error(`Resolved more than 1 hot reload target for ${resolvedLabel.toString()}: ${targets.join(',')}`);
48
- }
49
- resolvedTarget = targets[0];
218
+ console.log(`Connected hot reload to ${webSessions.length} running web host${webSessions.length === 1 ? '' : 's'}.`);
219
+ const scheduler = createWebPublicationScheduler(client, webSessions);
220
+ result = await runHotreloadWithCompilerEvents(buildHotreloadCommand(hotreloadCommand, {
221
+ jsonEvents: true,
222
+ port,
223
+ target: resolvedTarget,
224
+ }), workspaceRoot, () => scheduler.schedule(), jsonEvents);
225
+ await scheduler.drain();
50
226
  }
51
- await hotreloadResolvedTarget(client, resolvedTarget);
227
+ report('hotreload_stopped', result.returnCode);
52
228
  }
53
229
  async function getHotreloadTargetByModuleName(client, moduleName) {
54
230
  const targets = await client.query(`filter(${moduleName}_hotreload, kind('valdi_hotreload rule', //...))`);
@@ -57,8 +233,26 @@ async function getHotreloadTargetByModuleName(client, moduleName) {
57
233
  }
58
234
  return targets[0]?.trim() ?? '';
59
235
  }
236
+ async function resolveHotreloadTarget(client, target) {
237
+ const resolvedLabel = await client.resolveLabel(target);
238
+ if (resolvedLabel.name) {
239
+ return resolvedLabel.toString();
240
+ }
241
+ const targets = await client.query(`kind('valdi_hotreload', ${resolvedLabel.toString()}/...)`);
242
+ if (targets.length === 0) {
243
+ throw new Error(`Could not resolve hot reload target for label ${resolvedLabel.toString()}`);
244
+ }
245
+ if (targets.length !== 1) {
246
+ throw new Error(`Resolved more than 1 hot reload target for ${resolvedLabel.toString()}: ${targets.join(',')}`);
247
+ }
248
+ return targets[0];
249
+ }
60
250
  async function valdiHotreload(argv) {
61
251
  const client = new BazelClient_1.BazelClient();
252
+ const port = validateHotreloadPort(argv.getArgument('port'));
253
+ const jsonEvents = argv.getArgument('jsonEvents');
254
+ const workspaceRoot = await client.getWorkspaceRoot();
255
+ const activeWebSessions = (0, webHotReloadSession_1.findWebHotReloadSessions)(workspaceRoot);
62
256
  const target = await argv.getArgumentOrResolve('target', async () => {
63
257
  const module = argv.getArgument('module');
64
258
  if (module) {
@@ -67,6 +261,18 @@ async function valdiHotreload(argv) {
67
261
  console.log('Found target:', (0, logUtils_1.wrapInColor)(target, constants_1.ANSI_COLORS.GREEN_COLOR));
68
262
  return target;
69
263
  }
264
+ const activeTargets = [...new Set(activeWebSessions.map(session => session.hotreloadTarget))];
265
+ if (activeTargets.length === 1) {
266
+ const activeTarget = activeTargets[0] ?? '';
267
+ console.log('Using hot reload target from the running web host:', (0, logUtils_1.wrapInColor)(activeTarget, constants_1.ANSI_COLORS.GREEN_COLOR));
268
+ return activeTarget;
269
+ }
270
+ if (activeTargets.length > 1) {
271
+ return await (0, cliUtils_1.getUserChoice)(activeTargets.map((activeTarget, index) => ({
272
+ name: `${index + 1}. ${activeTarget}`,
273
+ value: activeTarget,
274
+ })), 'Please choose a running web application to hot reload:');
275
+ }
70
276
  const targets = await client.query('attr("tags", "valdi_application", //...)');
71
277
  if (targets.length === 0) {
72
278
  throw new errors_1.CliError(`Could not resolve Valdi application Bazel target`);
@@ -83,9 +289,13 @@ async function valdiHotreload(argv) {
83
289
  }
84
290
  });
85
291
  (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
86
- await hotreloadResolvedTarget(client, target);
292
+ const resolvedTarget = await resolveHotreloadTarget(client, target);
293
+ const webSessions = activeWebSessions.filter(session => session.hotreloadTarget === resolvedTarget);
294
+ const report = lifecycleReporter(jsonEvents, resolvedTarget, port);
295
+ report('target_resolved');
296
+ await hotreloadResolvedTarget(client, resolvedTarget, port, jsonEvents, report, webSessions);
87
297
  }
88
- exports.command = 'hotreload [--module module_name] [--target target_name]';
298
+ exports.command = 'hotreload [--module module_name] [--target target_name] [--port port] [--json-events]';
89
299
  exports.describe = 'Starts the hotreloader for the application';
90
300
  const builder = (yargs) => {
91
301
  yargs
@@ -98,6 +308,16 @@ const builder = (yargs) => {
98
308
  describe: 'Bazel target path to hotreload',
99
309
  type: 'string',
100
310
  requiresArg: true,
311
+ })
312
+ .option('port', {
313
+ describe: 'Port of the running app Valdi debugger/hotreload service',
314
+ type: 'number',
315
+ requiresArg: true,
316
+ })
317
+ .option('json-events', {
318
+ describe: 'Emit machine-readable lifecycle events while retaining normal build and runtime output',
319
+ type: 'boolean',
320
+ default: false,
101
321
  });
102
322
  };
103
323
  exports.builder = builder;
@@ -5,8 +5,11 @@ exports.command = 'inspect <command>';
5
5
  exports.describe = 'Inspect a running Valdi app — component trees, contexts, screenshots, heap';
6
6
  const builder = (yargs) => {
7
7
  return yargs
8
- .commandDir('inspect_commands', { extensions: ['js', 'ts'] })
9
- .demandCommand(1, 'Use devices, select, status, contexts, tree, snapshot, or heap')
8
+ .commandDir('inspect_commands', {
9
+ extensions: ['js', 'ts'],
10
+ exclude: /\.spec\.(js|ts)$/,
11
+ })
12
+ .demandCommand(1, 'Use devices, select, status, contexts, tree, snapshot, input, or heap')
10
13
  .recommendCommands()
11
14
  .wrap(yargs.terminalWidth())
12
15
  .help();
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ exports.buildInputRequest = buildInputRequest;
5
+ const inputClient_1 = require("../../debugger/inputClient");
6
+ const daemonClient_1 = require("../../utils/daemonClient");
7
+ const errorUtils_1 = require("../../utils/errorUtils");
8
+ const INPUT_SELECTOR_FIELDS = new Set(['elementId', 'accessibilityId', 'tag']);
9
+ function parseSelector(selector) {
10
+ const trimmed = selector.trim();
11
+ if (!trimmed.startsWith('{')) {
12
+ return selector;
13
+ }
14
+ let parsed;
15
+ try {
16
+ parsed = JSON.parse(trimmed);
17
+ }
18
+ catch {
19
+ throw new Error('--selector must be a selector string or a JSON object.');
20
+ }
21
+ if (parsed === null || Array.isArray(parsed) || typeof parsed !== 'object') {
22
+ throw new Error('--selector JSON must be an object.');
23
+ }
24
+ const record = parsed;
25
+ const unknownKey = Object.keys(record)
26
+ .sort()
27
+ .find(key => !INPUT_SELECTOR_FIELDS.has(key));
28
+ if (unknownKey) {
29
+ throw new Error(`Unsupported selector field "${unknownKey}".`);
30
+ }
31
+ return record;
32
+ }
33
+ function addDefined(request, key, value) {
34
+ if (value !== undefined) {
35
+ request[key] = value;
36
+ }
37
+ }
38
+ function buildInputRequest(args) {
39
+ const selectorCount = [args.elementId, args.accessibilityId, args.selector].filter(value => value !== undefined).length;
40
+ if (selectorCount > 1) {
41
+ throw new Error('Use only one of --element-id, --accessibility-id, or --selector.');
42
+ }
43
+ if (args.action === inputClient_1.DebuggerInputType.Text && args.text === undefined) {
44
+ throw new Error('The text action requires --text.');
45
+ }
46
+ if (args.action === inputClient_1.DebuggerInputType.Key && args.key === undefined) {
47
+ throw new Error('The key action requires --key.');
48
+ }
49
+ const request = { type: args.action };
50
+ addDefined(request, 'elementId', args.elementId);
51
+ addDefined(request, 'accessibilityId', args.accessibilityId);
52
+ addDefined(request, 'selector', args.selector === undefined ? undefined : parseSelector(args.selector));
53
+ if (args.action === inputClient_1.DebuggerInputType.Focus) {
54
+ request['focused'] = args.focused;
55
+ }
56
+ addDefined(request, 'text', args.text);
57
+ addDefined(request, 'key', args.key);
58
+ addDefined(request, 'selectionStart', args.selectionStart);
59
+ addDefined(request, 'selectionEnd', args.selectionEnd);
60
+ addDefined(request, 'x', args.x);
61
+ addDefined(request, 'y', args.y);
62
+ addDefined(request, 'deltaX', args.deltaX);
63
+ addDefined(request, 'deltaY', args.deltaY);
64
+ const validationError = (0, inputClient_1.validateDebuggerInputRequest)(request);
65
+ if (validationError) {
66
+ throw new Error(validationError);
67
+ }
68
+ return request;
69
+ }
70
+ async function inspectInput(argv) {
71
+ const action = argv.getArgument('action');
72
+ const contextIdArg = argv.getArgument('contextId');
73
+ const port = argv.getArgument('port');
74
+ const clientOverride = argv.getArgument('client');
75
+ const request = buildInputRequest({
76
+ action,
77
+ elementId: argv.getArgument('elementId'),
78
+ accessibilityId: argv.getArgument('accessibilityId'),
79
+ selector: argv.getArgument('selector'),
80
+ focused: argv.getArgument('focused'),
81
+ text: argv.getArgument('text'),
82
+ key: argv.getArgument('key'),
83
+ selectionStart: argv.getArgument('selectionStart'),
84
+ selectionEnd: argv.getArgument('selectionEnd'),
85
+ x: argv.getArgument('x'),
86
+ y: argv.getArgument('y'),
87
+ deltaX: argv.getArgument('deltaX'),
88
+ deltaY: argv.getArgument('deltaY'),
89
+ });
90
+ const conn = await (0, daemonClient_1.connectToDaemon)(port);
91
+ try {
92
+ await conn.configure();
93
+ const clientId = await (0, daemonClient_1.resolveClientId)(conn, clientOverride);
94
+ const contextId = action === inputClient_1.DebuggerInputType.Capabilities ? undefined : await (0, daemonClient_1.resolveContextId)(conn, clientId, contextIdArg);
95
+ const requestWithContext = contextId === undefined ? request : { ...request, contextId };
96
+ const input = await (0, inputClient_1.sendDebuggerInput)(conn, clientId, requestWithContext);
97
+ console.log(JSON.stringify({ port, clientId, contextId, input }));
98
+ }
99
+ finally {
100
+ conn.close();
101
+ }
102
+ }
103
+ exports.command = 'input <action> [contextId]';
104
+ exports.describe = 'Query and control a live Valdi app through the default debugger input contract';
105
+ const builder = (yargs) => {
106
+ yargs
107
+ .positional('action', {
108
+ describe: 'Input operation',
109
+ choices: Object.values(inputClient_1.DebuggerInputType),
110
+ type: 'string',
111
+ })
112
+ .positional('contextId', {
113
+ describe: 'Context ID (omit to auto-select or be prompted)',
114
+ type: 'string',
115
+ })
116
+ .option('port', {
117
+ describe: 'Daemon TCP port (use 13591 for standalone macOS apps)',
118
+ type: 'number',
119
+ default: daemonClient_1.DEFAULT_PORT,
120
+ })
121
+ .option('client', {
122
+ describe: 'Client ID to target (from "valdi inspect devices")',
123
+ type: 'string',
124
+ })
125
+ .option('element-id', {
126
+ describe: 'Target a rendered element ID',
127
+ type: 'number',
128
+ })
129
+ .option('accessibility-id', {
130
+ describe: 'Target a stable accessibility ID',
131
+ type: 'string',
132
+ })
133
+ .option('selector', {
134
+ describe: 'Target #accessibilityId, [accessibilityId="..."], or a JSON selector object',
135
+ type: 'string',
136
+ })
137
+ .option('focused', {
138
+ describe: 'Focus state for the focus action; use --no-focused to blur',
139
+ type: 'boolean',
140
+ default: true,
141
+ })
142
+ .option('text', {
143
+ describe: 'Replacement text for the text action',
144
+ type: 'string',
145
+ })
146
+ .option('key', {
147
+ describe: 'Key for the key action (Enter, Return, Escape, Backspace, Delete, or one printable grapheme)',
148
+ type: 'string',
149
+ })
150
+ .option('selection-start', {
151
+ describe: 'Selection start for text and key actions',
152
+ type: 'number',
153
+ })
154
+ .option('selection-end', {
155
+ describe: 'Selection end for text and key actions',
156
+ type: 'number',
157
+ })
158
+ .option('x', {
159
+ describe: 'Absolute X coordinate for tap',
160
+ type: 'number',
161
+ })
162
+ .option('y', {
163
+ describe: 'Absolute Y coordinate for tap',
164
+ type: 'number',
165
+ })
166
+ .option('delta-x', {
167
+ describe: 'Horizontal content-offset delta for scroll',
168
+ type: 'number',
169
+ })
170
+ .option('delta-y', {
171
+ describe: 'Vertical content-offset delta for scroll',
172
+ type: 'number',
173
+ });
174
+ };
175
+ exports.builder = builder;
176
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(inspectInput);
@@ -71,7 +71,7 @@ async function inspectSnapshot(argv) {
71
71
  const contextId = await (0, daemonClient_1.resolveContextId)(conn, clientId, contextIdArg);
72
72
  let elementId = elementIdArg;
73
73
  if (keyOverride) {
74
- const tree = await conn.getContextTree(clientId, contextId);
74
+ const tree = await conn.getContextTree(clientId, contextId, false);
75
75
  const found = findElementByKey(tree, keyOverride);
76
76
  if (!found) {
77
77
  throw new Error(`No element found with key "${keyOverride}". Use "valdi inspect tree" to see available keys.`);
@@ -40,7 +40,7 @@ async function inspectTree(argv) {
40
40
  await conn.configure();
41
41
  const clientId = await (0, daemonClient_1.resolveClientId)(conn, clientOverride);
42
42
  const contextId = await (0, daemonClient_1.resolveContextId)(conn, clientId, contextIdArg);
43
- let tree = await conn.getContextTree(clientId, contextId);
43
+ let tree = await conn.getContextTree(clientId, contextId, false);
44
44
  if (maxDepth !== undefined) {
45
45
  tree = trimDepth(tree, maxDepth);
46
46
  }