@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.
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +1 -1
- package/.metadata/.bazelrc.template +5 -5
- package/.metadata/.bazelversion.template +1 -1
- package/.metadata/AGENTS.md.template +7 -0
- package/.metadata/MODULE.bazel.template +75 -6
- package/.metadata/README.md.template +2 -2
- package/.metadata/android_ide_common_30_1_3_install.json.template +1818 -0
- package/.metadata/android_mvn_install.json.template +2877 -0
- package/.metadata/maven_install.json.template +444 -0
- package/.metadata/rules_android_maven_install.json.template +4879 -0
- package/.metadata/skill-tests-README.md.template +1 -1
- package/README.md +12 -13
- package/bundled-skills/skills/valdi-async/tests/README.md +1 -1
- package/bundled-skills/skills/valdi-compiler/skill.md +3 -8
- package/bundled-skills/skills/valdi-component-tests/skill.md +1 -1
- package/bundled-skills/skills/valdi-component-tests/tests/README.md +1 -1
- package/bundled-skills/skills/valdi-custom-view/skill.md +1 -1
- package/bundled-skills/skills/valdi-gestures/skill.md +1 -1
- package/bundled-skills/skills/valdi-migrate/tests/README.md +2 -2
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +1 -1
- package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +8 -8
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +2 -2
- package/bundled-skills/skills/valdi-perf/skill.md +2 -2
- package/bundled-skills/skills/valdi-perf/tests/README.md +1 -1
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +5 -1
- package/bundled-skills/skills/valdi-tsx/skill.md +6 -6
- package/bundled-skills/skills/valdi-tsx/tests/README.md +1 -1
- package/dist/commands/agentCheck.js +9 -7
- package/dist/commands/bootstrap.js +16 -5
- package/dist/commands/build.js +7 -1
- package/dist/commands/doctor.js +4 -7
- package/dist/commands/export.js +47 -16
- package/dist/commands/hotreload.js +247 -27
- package/dist/commands/install.js +92 -3
- package/dist/commands/newModule.js +8 -1
- package/dist/commands/webHotreload.js +3 -3
- package/dist/core/constants.js +17 -2
- package/dist/setup/DevSetupHelper.js +11 -2
- package/dist/setup/libtinfo5.js +19 -0
- package/dist/setup/linuxSetup.js +2 -22
- package/dist/utils/BazelClient.js +11 -4
- package/dist/utils/applicationUtils.js +17 -2
- package/dist/utils/buildInfo.js +5 -1
- package/dist/utils/cliUtils.js +2 -2
- package/dist/utils/directorySync.js +153 -0
- package/dist/utils/errorUtils.js +1 -1
- package/dist/utils/githubUtils.js +1 -1
- package/dist/utils/iosSimulator.js +136 -0
- package/dist/utils/nonInteractive.js +13 -0
- package/dist/utils/prettierCheck.js +19 -0
- package/dist/utils/processUtils.js +14 -0
- package/dist/utils/webApplicationSession.js +58 -0
- package/dist/utils/webHotReloadSession.js +212 -0
- package/dist/utils/webServerUtils.js +195 -0
- package/dist/utils/zipUtils.js +20 -2
- package/package.json +4 -2
package/dist/commands/export.js
CHANGED
|
@@ -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
|
|
33
|
-
|
|
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
|
-
(
|
|
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
|
|
42
|
-
|
|
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,
|
|
62
|
+
return (0, applicationUtils_1.getOutputFilePath)(bazel, bazelOutputExtension, targetToExport, bazelArgs);
|
|
50
63
|
});
|
|
51
|
-
console.log(`Building: ${(0, logUtils_1.wrapInColor)(
|
|
52
|
-
await bazel.buildTarget(
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
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
|
-
|
|
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
|
|
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;
|
package/dist/commands/install.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
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");
|
|
11
|
+
const iosSimulator_1 = require("../utils/iosSimulator");
|
|
9
12
|
const errorUtils_1 = require("../utils/errorUtils");
|
|
13
|
+
const tempDir_1 = require("../utils/tempDir");
|
|
10
14
|
const logUtils_1 = require("../utils/logUtils");
|
|
15
|
+
const processUtils_1 = require("../utils/processUtils");
|
|
16
|
+
const webApplicationSession_1 = require("../utils/webApplicationSession");
|
|
17
|
+
const webHotReloadSession_1 = require("../utils/webHotReloadSession");
|
|
18
|
+
const webServerUtils_1 = require("../utils/webServerUtils");
|
|
11
19
|
async function valdiInstall(argv) {
|
|
12
20
|
const bazel = new BazelClient_1.BazelClient();
|
|
13
21
|
const buildInfo = await (0, buildInfo_1.getBuildInfo)(argv, bazel, true);
|
|
@@ -26,7 +34,18 @@ async function valdiInstall(argv) {
|
|
|
26
34
|
}
|
|
27
35
|
case constants_1.PLATFORM.IOS: {
|
|
28
36
|
console.log('Installing iOS application...');
|
|
29
|
-
await
|
|
37
|
+
const developerDir = await (0, iosSimulator_1.getDeveloperDir)();
|
|
38
|
+
if ((0, buildInfo_1.isDeviceBuild)(argv.getArgument('simulator')) || !(0, iosSimulator_1.needsSimctlInstall)(developerDir)) {
|
|
39
|
+
await bazel.runTarget(buildInfo.application, buildInfo.bazelArgs);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const outputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
|
|
43
|
+
console.log('Resolving output paths...');
|
|
44
|
+
return (0, applicationUtils_1.getOutputFilePath)(bazel, (0, applicationUtils_1.applicationExtensionForPlatform)(buildInfo.platform), buildInfo.application, buildInfo.bazelArgs);
|
|
45
|
+
});
|
|
46
|
+
await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
|
|
47
|
+
await (0, iosSimulator_1.installAndLaunchOnSimulator)(outputFilePath, { deviceId: argv.getArgument('device_id'), developerDir });
|
|
48
|
+
}
|
|
30
49
|
(0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
|
|
31
50
|
break;
|
|
32
51
|
}
|
|
@@ -48,10 +67,63 @@ async function valdiInstall(argv) {
|
|
|
48
67
|
await bazel.runTarget(buildInfo.application, buildInfo.bazelArgs);
|
|
49
68
|
break;
|
|
50
69
|
}
|
|
70
|
+
case constants_1.PLATFORM.WEB: {
|
|
71
|
+
const outputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
|
|
72
|
+
console.log('Resolving output paths...');
|
|
73
|
+
return (0, applicationUtils_1.getOutputFilePath)(bazel, (0, applicationUtils_1.applicationExtensionForPlatform)(buildInfo.platform), buildInfo.application, buildInfo.bazelArgs);
|
|
74
|
+
});
|
|
75
|
+
await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
|
|
76
|
+
const tempDir = (0, tempDir_1.makeTempDir)();
|
|
77
|
+
fs_1.default.mkdirSync(tempDir);
|
|
78
|
+
try {
|
|
79
|
+
const workspaceRoot = await bazel.getWorkspaceRoot();
|
|
80
|
+
const applicationTarget = (await bazel.resolveLabel(buildInfo.application)).toString();
|
|
81
|
+
const hotreloadTarget = (0, webHotReloadSession_1.inferWebHotReloadTarget)(applicationTarget);
|
|
82
|
+
const session = await (0, webApplicationSession_1.startWebApplicationSession)({
|
|
83
|
+
archivePath: outputFilePath,
|
|
84
|
+
host: argv.getArgument('host') ?? '127.0.0.1',
|
|
85
|
+
liveReload: hotreloadTarget !== undefined,
|
|
86
|
+
port: argv.getArgument('port') ?? 0,
|
|
87
|
+
workingDir: tempDir,
|
|
88
|
+
});
|
|
89
|
+
const hotReloadRegistration = hotreloadTarget === undefined
|
|
90
|
+
? undefined
|
|
91
|
+
: await (0, webHotReloadSession_1.registerWebHotReloadSession)({
|
|
92
|
+
applicationTarget,
|
|
93
|
+
bazelArgs: buildInfo.bazelArgs,
|
|
94
|
+
hotreloadTarget,
|
|
95
|
+
onPublish: async () => {
|
|
96
|
+
await session.publish();
|
|
97
|
+
console.log(`Reloaded web application at ${(0, logUtils_1.wrapInColor)(session.url, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
|
|
98
|
+
},
|
|
99
|
+
workspaceRoot,
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
console.log(`Serving web application at ${(0, logUtils_1.wrapInColor)(session.url, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
|
|
103
|
+
if (hotreloadTarget) {
|
|
104
|
+
console.log(`For hot reload, run ${(0, logUtils_1.wrapInColor)(`valdi hotreload --target ${hotreloadTarget}`, constants_1.ANSI_COLORS.GREEN_COLOR)} in another terminal.`);
|
|
105
|
+
}
|
|
106
|
+
if (argv.getArgument('open') ?? true) {
|
|
107
|
+
(0, webServerUtils_1.openUrlInDefaultBrowser)(session.url);
|
|
108
|
+
}
|
|
109
|
+
(0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
|
|
110
|
+
console.log('Press Ctrl+C to stop the web server.');
|
|
111
|
+
await (0, processUtils_1.waitForShutdownSignal)();
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
await hotReloadRegistration?.close();
|
|
115
|
+
await session.close();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
fs_1.default.rmSync(tempDir, { force: true, recursive: true });
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
51
123
|
}
|
|
52
124
|
}
|
|
53
125
|
exports.command = 'install <platform>';
|
|
54
|
-
exports.describe = 'Build and install the application to the connected device';
|
|
126
|
+
exports.describe = 'Build and install the application to the connected device or local web server';
|
|
55
127
|
exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
|
|
56
128
|
yargs
|
|
57
129
|
.option('application', {
|
|
@@ -70,8 +142,25 @@ exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
|
|
|
70
142
|
requiresArg: true,
|
|
71
143
|
})
|
|
72
144
|
.option('simulator', {
|
|
73
|
-
describe: '
|
|
145
|
+
describe: 'Build for the iOS simulator (default). Pass --no-simulator to build for a device',
|
|
74
146
|
type: 'boolean',
|
|
147
|
+
})
|
|
148
|
+
.option('open', {
|
|
149
|
+
describe: 'Open the web application in the default browser after starting the server',
|
|
150
|
+
type: 'boolean',
|
|
151
|
+
default: true,
|
|
152
|
+
})
|
|
153
|
+
.option('host', {
|
|
154
|
+
describe: 'Host to bind when serving a web application',
|
|
155
|
+
type: 'string',
|
|
156
|
+
default: '127.0.0.1',
|
|
157
|
+
requiresArg: true,
|
|
158
|
+
})
|
|
159
|
+
.option('port', {
|
|
160
|
+
describe: 'Port to bind when serving a web application. Use 0 to select an available port automatically',
|
|
161
|
+
type: 'number',
|
|
162
|
+
default: 0,
|
|
163
|
+
requiresArg: true,
|
|
75
164
|
});
|
|
76
165
|
});
|
|
77
166
|
exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiInstall);
|
|
@@ -9,6 +9,7 @@ const constants_1 = require("../core/constants");
|
|
|
9
9
|
const errors_1 = require("../core/errors");
|
|
10
10
|
const BazelClient_1 = require("../utils/BazelClient");
|
|
11
11
|
const cliUtils_1 = require("../utils/cliUtils");
|
|
12
|
+
const nonInteractive_1 = require("../utils/nonInteractive");
|
|
12
13
|
const copyBootstrapFiles_1 = require("../utils/copyBootstrapFiles");
|
|
13
14
|
const errorUtils_1 = require("../utils/errorUtils");
|
|
14
15
|
const fileUtils_1 = require("../utils/fileUtils");
|
|
@@ -154,6 +155,11 @@ function getBazelWorkspaceRoot() {
|
|
|
154
155
|
async function valdiNewModule(argv) {
|
|
155
156
|
console.log(referenceString);
|
|
156
157
|
const skipChecks = argv.getArgument('skipChecks');
|
|
158
|
+
(0, nonInteractive_1.requireFlagsWhenNonInteractive)('valdi new_module', [
|
|
159
|
+
{ flag: '--skip-checks', provided: Boolean(skipChecks) },
|
|
160
|
+
{ flag: '--template <type>', provided: Boolean(argv.getArgument('template')) },
|
|
161
|
+
{ flag: '<module-name>', provided: Boolean(argv.getArgument('moduleName')) },
|
|
162
|
+
]);
|
|
157
163
|
const checks = skipChecks ? {} : await promptChecks();
|
|
158
164
|
const valdiModulePath = checks.valdiModulePath ?? path_1.default.join(await getBazelWorkspaceRoot(), 'modules');
|
|
159
165
|
let moduleName = await getModuleName(argv);
|
|
@@ -199,8 +205,9 @@ const builder = (yargs) => {
|
|
|
199
205
|
choices: ALL_MODULE_TEMPLATES.map(template => template.path),
|
|
200
206
|
})
|
|
201
207
|
.option('skip-checks', {
|
|
202
|
-
describe: 'Skips confirmation prompts.',
|
|
208
|
+
describe: 'Skips confirmation prompts. With --template and a module name, runs without any prompt.',
|
|
203
209
|
type: 'boolean',
|
|
210
|
+
alias: 'y',
|
|
204
211
|
});
|
|
205
212
|
};
|
|
206
213
|
exports.builder = builder;
|
|
@@ -9,19 +9,19 @@ 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. //
|
|
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));
|
|
16
16
|
await client.runTarget(target, '--define enable_web=true');
|
|
17
17
|
}
|
|
18
18
|
exports.command = 'web-hotreload --target <bazel-target>';
|
|
19
|
-
exports.describe = 'Start a Valdi web playground with hot module reload (webpack-dev-server). '
|
|
19
|
+
exports.describe = '(experimental) Start a Valdi web playground with hot module reload (webpack-dev-server). '
|
|
20
20
|
+ 'Pass the Bazel label of the playground :dev target created by '
|
|
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. //
|
|
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,
|