@snap/valdi 1.2.0 → 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.
@@ -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;
@@ -1,13 +1,20 @@
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
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
4
6
  const constants_1 = require("../core/constants");
5
7
  const BazelClient_1 = require("../utils/BazelClient");
6
8
  const applicationUtils_1 = require("../utils/applicationUtils");
7
9
  const buildInfo_1 = require("../utils/buildInfo");
8
10
  const deviceUtils_1 = require("../utils/deviceUtils");
9
11
  const errorUtils_1 = require("../utils/errorUtils");
12
+ const tempDir_1 = require("../utils/tempDir");
10
13
  const logUtils_1 = require("../utils/logUtils");
14
+ const processUtils_1 = require("../utils/processUtils");
15
+ const webApplicationSession_1 = require("../utils/webApplicationSession");
16
+ const webHotReloadSession_1 = require("../utils/webHotReloadSession");
17
+ const webServerUtils_1 = require("../utils/webServerUtils");
11
18
  async function valdiInstall(argv) {
12
19
  const bazel = new BazelClient_1.BazelClient();
13
20
  const buildInfo = await (0, buildInfo_1.getBuildInfo)(argv, bazel, true);
@@ -48,10 +55,63 @@ async function valdiInstall(argv) {
48
55
  await bazel.runTarget(buildInfo.application, buildInfo.bazelArgs);
49
56
  break;
50
57
  }
58
+ case constants_1.PLATFORM.WEB: {
59
+ const outputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
60
+ console.log('Resolving output paths...');
61
+ return (0, applicationUtils_1.getOutputFilePath)(bazel, (0, applicationUtils_1.applicationExtensionForPlatform)(buildInfo.platform), buildInfo.application, buildInfo.bazelArgs);
62
+ });
63
+ await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
64
+ const tempDir = (0, tempDir_1.makeTempDir)();
65
+ fs_1.default.mkdirSync(tempDir);
66
+ try {
67
+ const workspaceRoot = await bazel.getWorkspaceRoot();
68
+ const applicationTarget = (await bazel.resolveLabel(buildInfo.application)).toString();
69
+ const hotreloadTarget = (0, webHotReloadSession_1.inferWebHotReloadTarget)(applicationTarget);
70
+ const session = await (0, webApplicationSession_1.startWebApplicationSession)({
71
+ archivePath: outputFilePath,
72
+ host: argv.getArgument('host') ?? '127.0.0.1',
73
+ liveReload: hotreloadTarget !== undefined,
74
+ port: argv.getArgument('port') ?? 0,
75
+ workingDir: tempDir,
76
+ });
77
+ const hotReloadRegistration = hotreloadTarget === undefined
78
+ ? undefined
79
+ : await (0, webHotReloadSession_1.registerWebHotReloadSession)({
80
+ applicationTarget,
81
+ bazelArgs: buildInfo.bazelArgs,
82
+ hotreloadTarget,
83
+ onPublish: async () => {
84
+ await session.publish();
85
+ console.log(`Reloaded web application at ${(0, logUtils_1.wrapInColor)(session.url, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
86
+ },
87
+ workspaceRoot,
88
+ });
89
+ try {
90
+ console.log(`Serving web application at ${(0, logUtils_1.wrapInColor)(session.url, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
91
+ if (hotreloadTarget) {
92
+ console.log(`For hot reload, run ${(0, logUtils_1.wrapInColor)(`valdi hotreload --target ${hotreloadTarget}`, constants_1.ANSI_COLORS.GREEN_COLOR)} in another terminal.`);
93
+ }
94
+ if (argv.getArgument('open') ?? true) {
95
+ (0, webServerUtils_1.openUrlInDefaultBrowser)(session.url);
96
+ }
97
+ (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
98
+ console.log('Press Ctrl+C to stop the web server.');
99
+ await (0, processUtils_1.waitForShutdownSignal)();
100
+ }
101
+ finally {
102
+ await hotReloadRegistration?.close();
103
+ await session.close();
104
+ }
105
+ }
106
+ finally {
107
+ fs_1.default.rmSync(tempDir, { force: true, recursive: true });
108
+ }
109
+ break;
110
+ }
51
111
  }
52
112
  }
53
113
  exports.command = 'install <platform>';
54
- exports.describe = 'Build and install the application to the connected device';
114
+ exports.describe = 'Build and install the application to the connected device or local web server';
55
115
  exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
56
116
  yargs
57
117
  .option('application', {
@@ -70,8 +130,25 @@ exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
70
130
  requiresArg: true,
71
131
  })
72
132
  .option('simulator', {
73
- describe: 'Whether to build for simulator or for device',
133
+ describe: 'Build for the iOS simulator (default). Pass --no-simulator to build for a device',
74
134
  type: 'boolean',
135
+ })
136
+ .option('open', {
137
+ describe: 'Open the web application in the default browser after starting the server',
138
+ type: 'boolean',
139
+ default: true,
140
+ })
141
+ .option('host', {
142
+ describe: 'Host to bind when serving a web application',
143
+ type: 'string',
144
+ default: '127.0.0.1',
145
+ requiresArg: true,
146
+ })
147
+ .option('port', {
148
+ describe: 'Port to bind when serving a web application. Use 0 to select an available port automatically',
149
+ type: 'number',
150
+ default: 0,
151
+ requiresArg: true,
75
152
  });
76
153
  });
77
154
  exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiInstall);
@@ -9,7 +9,7 @@ async function valdiWebHotreload(argv) {
9
9
  const client = new BazelClient_1.BazelClient();
10
10
  const target = argv.getArgument('target');
11
11
  if (!target) {
12
- throw new Error('--target is required (e.g. //apps/helloworld:dev)');
12
+ throw new Error('--target is required (e.g. //experiments/helloworld_playground:dev)');
13
13
  }
14
14
  (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
15
15
  console.log((0, logUtils_1.wrapInColor)(`Starting webpack-dev-server via ${target} ...`, constants_1.ANSI_COLORS.GREEN_COLOR));
@@ -21,7 +21,7 @@ exports.describe = 'Start a Valdi web playground with hot module reload (webpack
21
21
  + 'valdi_web_playground(hmr_config = ...).';
22
22
  const builder = (yargs) => {
23
23
  yargs.option('target', {
24
- describe: 'Bazel label of the playground :dev js_binary (e.g. //apps/helloworld:dev)',
24
+ describe: 'Bazel label of the playground :dev js_binary (e.g. //experiments/helloworld_playground:dev)',
25
25
  type: 'string',
26
26
  requiresArg: true,
27
27
  demandOption: true,
@@ -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) {
@@ -48,14 +49,23 @@ var TEMPLATE_BASE_PATHS;
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";
50
51
  })(TEMPLATE_BASE_PATHS || (exports.TEMPLATE_BASE_PATHS = TEMPLATE_BASE_PATHS = {}));
51
- exports.VALID_PLATFORMS = [PLATFORM.ANDROID, PLATFORM.IOS, PLATFORM.MACOS, PLATFORM.LINUX, PLATFORM.CLI];
52
+ exports.VALID_PLATFORMS = [
53
+ PLATFORM.ANDROID,
54
+ PLATFORM.IOS,
55
+ PLATFORM.MACOS,
56
+ PLATFORM.LINUX,
57
+ PLATFORM.CLI,
58
+ PLATFORM.WEB,
59
+ ];
52
60
  exports.IOS_BAZEL_APPLICATION_TAG = 'valdi_ios_application';
53
61
  exports.ANDROID_BAZEL_APPLICATION_TAG = 'valdi_android_application';
54
62
  exports.MACOS_BAZEL_APPLICATION_TAG = 'valdi_macos_application';
55
63
  exports.LINUX_BAZEL_APPLICATION_TAG = 'valdi_linux_application';
56
64
  exports.CLI_BAZEL_APPLICATION_TAG = 'valdi_cli_application';
65
+ exports.WEB_BAZEL_APPLICATION_TAG = 'valdi_web_application';
57
66
  exports.IOS_EXPORTED_LIBRARY_TAG = 'valdi_ios_exported_library';
58
67
  exports.ANDROID_EXPORTED_LIBRARY_TAG = 'valdi_android_exported_library';
68
+ exports.WEB_EXPORTED_LIBRARY_TAG = 'valdi_web_exported_library';
59
69
  exports.CLI_ROOT = path_1.default.join(__dirname, '../..');
60
70
  exports.CONFIG_DIR_PATH = path_1.default.join(exports.CLI_ROOT, '.config');
61
71
  exports.META_DIR_PATH = path_1.default.join(exports.CLI_ROOT, '.metadata');
@@ -94,4 +104,5 @@ const INLINE_ASSETS_BUILD_FLAGS = ['--@valdi//bzl/valdi:assets_mode=inline'];
94
104
  exports.MACOS_BUILD_FLAGS = [...INLINE_ASSETS_BUILD_FLAGS, '--repo_env=VALDI_PLATFORM_DEPENDENCIES=macos'];
95
105
  exports.LINUX_BUILD_FLAGS = [...INLINE_ASSETS_BUILD_FLAGS, '--repo_env=VALDI_PLATFORM_DEPENDENCIES=linux'];
96
106
  exports.CLI_BUILD_FLAGS = [...INLINE_ASSETS_BUILD_FLAGS, '--repo_env=VALDI_PLATFORM_DEPENDENCIES=cli'];
107
+ exports.WEB_BUILD_FLAGS = ['--define', 'enable_web=true', ...INLINE_ASSETS_BUILD_FLAGS];
97
108
  exports.TEST_BUILD_FLAGS = INLINE_ASSETS_BUILD_FLAGS;
@@ -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 => {