@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.
- package/.metadata/.bazelrc.template +9 -7
- package/.metadata/AGENTS.md.template +7 -0
- package/.metadata/MODULE.bazel.template +47 -3
- package/.metadata/README.md.template +2 -2
- package/.metadata/bzl/patches/rules_python/1.9.0/BUILD.bazel.template +1 -0
- package/.metadata/bzl/patches/rules_python/1.9.0/remove_setuptools_spaces.patch.template +96 -0
- package/.metadata/skill-tests-README.md.template +1 -1
- package/README.md +47 -14
- package/bundled-skills/registry.json +2 -1
- package/bundled-skills/skills/valdi-animations/skill.md +49 -0
- package/bundled-skills/skills/valdi-async/skill.md +3 -2
- package/bundled-skills/skills/valdi-async/tests/README.md +1 -1
- package/bundled-skills/skills/valdi-bazel/skill.md +2 -6
- package/bundled-skills/skills/valdi-component-tests/tests/README.md +1 -1
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +18 -0
- package/bundled-skills/skills/valdi-custom-view/skill.md +1 -1
- package/bundled-skills/skills/valdi-error-handling/skill.md +1 -1
- package/bundled-skills/skills/valdi-gestures/skill.md +3 -3
- package/bundled-skills/skills/valdi-migrate/skill.md +2 -1
- package/bundled-skills/skills/valdi-migrate/tests/README.md +2 -2
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +4 -4
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +9 -6
- package/bundled-skills/skills/valdi-overview/skill.md +2 -1
- package/bundled-skills/skills/valdi-perf/skill.md +121 -5
- package/bundled-skills/skills/valdi-perf/tests/README.md +1 -1
- package/bundled-skills/skills/valdi-pr-review/skill.md +189 -0
- package/bundled-skills/skills/valdi-profile/skill.md +5 -3
- package/bundled-skills/skills/valdi-setup/skill.md +3 -6
- package/bundled-skills/skills/valdi-testing/skill.md +1 -1
- package/bundled-skills/skills/valdi-tsx/skill.md +47 -11
- package/bundled-skills/skills/valdi-tsx/tests/README.md +1 -1
- package/debugger/README.md +356 -0
- package/debugger/debugger-actions.js +373 -0
- package/debugger/debugger-api.js +225 -0
- package/debugger/debugger-bootstrap.js +295 -0
- package/debugger/debugger-model.js +790 -0
- package/debugger/debugger-performance.js +573 -0
- package/debugger/debugger-preview-html.js +676 -0
- package/debugger/debugger-providers.js +389 -0
- package/debugger/debugger-render.js +529 -0
- package/debugger/debugger-runtime.js +387 -0
- package/debugger/debugger-session.js +188 -0
- package/debugger/debugger-settings.js +209 -0
- package/debugger/debugger-state.js +221 -0
- package/debugger/debugger-tree-model.js +539 -0
- package/debugger/debugger.css +1865 -0
- package/debugger/devtools-panel.css +1318 -0
- package/debugger/devtools-panel.html +273 -0
- package/debugger/devtools-panel.js +3329 -0
- package/debugger/index.html +279 -0
- package/dist/commands/bootstrap.js +7 -6
- package/dist/commands/build.js +7 -1
- package/dist/commands/debugger.js +163 -0
- package/dist/commands/doctor.js +3 -62
- package/dist/commands/export.js +47 -16
- package/dist/commands/hotreload.js +247 -27
- package/dist/commands/inspect.js +5 -2
- package/dist/commands/inspect_commands/input.js +176 -0
- package/dist/commands/inspect_commands/snapshot.js +1 -1
- package/dist/commands/inspect_commands/tree.js +1 -1
- package/dist/commands/install.js +79 -2
- package/dist/commands/projectsync.js +15 -0
- package/dist/commands/webHotreload.js +31 -0
- package/dist/core/constants.js +34 -7
- package/dist/debugger/chromiumConsole.js +279 -0
- package/dist/debugger/inputClient.js +473 -0
- package/dist/debugger/server.js +3801 -0
- package/dist/debugger/targetRegistry.js +436 -0
- package/dist/debugger/webPreviewPerformance.js +864 -0
- package/dist/index.js +0 -0
- package/dist/utils/BazelClient.js +34 -5
- package/dist/utils/applicationUtils.js +20 -2
- package/dist/utils/buildInfo.js +5 -1
- package/dist/utils/chromiumDevToolsClient.js +350 -0
- package/dist/utils/cliUtils.js +2 -2
- package/dist/utils/daemonClient.js +364 -44
- package/dist/utils/directorySync.js +153 -0
- package/dist/utils/githubUtils.js +1 -1
- package/dist/utils/hermesClient.js +82 -176
- package/dist/utils/loopbackHost.js +14 -0
- package/dist/utils/owlCdpClient.js +282 -0
- package/dist/utils/owlDevToolsExtension.js +142 -0
- package/dist/utils/processUtils.js +14 -0
- package/dist/utils/stringUtils.js +13 -1
- 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/inspect_commands/snapshot.spec.js +0 -105
- package/dist/core/packageFiles.spec.js +0 -29
- package/dist/preview/previewGenerator.spec.js +0 -203
- package/dist/preview/viewModelParser.spec.js +0 -171
- package/dist/utils/linuxDistro.spec.js +0 -122
- package/dist/utils/skillsAdapters.spec.js +0 -141
- package/dist/utils/stringUtils.spec.js +0 -81
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OwlChromiumConnection = exports.OWL_DEVTOOLS_TARGET_NONCE_PROPERTY = void 0;
|
|
4
|
+
exports.matchesOwlApplicationUrl = matchesOwlApplicationUrl;
|
|
5
|
+
exports.listOwlChromiumTargets = listOwlChromiumTargets;
|
|
6
|
+
exports.connectToOwlApplication = connectToOwlApplication;
|
|
7
|
+
exports.readOwlDebuggerSnapshot = readOwlDebuggerSnapshot;
|
|
8
|
+
exports.evaluateOwlApplicationExpression = evaluateOwlApplicationExpression;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const node_http_1 = tslib_1.__importDefault(require("node:http"));
|
|
11
|
+
const node_util_1 = require("node:util");
|
|
12
|
+
const chromiumDevToolsClient_1 = require("./chromiumDevToolsClient");
|
|
13
|
+
const loopbackHost_1 = require("./loopbackHost");
|
|
14
|
+
const CHROMIUM_DISCOVERY_TIMEOUT_MS = 3000;
|
|
15
|
+
const CHROMIUM_COMMAND_TIMEOUT_MS = 8000;
|
|
16
|
+
const MAX_CHROMIUM_DISCOVERY_BYTES = 1024 * 1024;
|
|
17
|
+
const MAX_CHROMIUM_DISCOVERY_TARGETS = 256;
|
|
18
|
+
const VALDI_INJECTED_QUERY_PARAMETERS = ['valdiDebugger', 'valdiDevTools', 'valdiTrace'];
|
|
19
|
+
const FATAL_UTF8_DECODER = new node_util_1.TextDecoder('utf8', { fatal: true });
|
|
20
|
+
const GUARDED_TARGET_MATCH_PROPERTY = '__valdiDevToolsTargetMatched';
|
|
21
|
+
exports.OWL_DEVTOOLS_TARGET_NONCE_PROPERTY = '__VALDI_DEVTOOLS_TARGET_NONCE__';
|
|
22
|
+
function chromiumError(error, fallback) {
|
|
23
|
+
if (error instanceof Error)
|
|
24
|
+
return error;
|
|
25
|
+
if (typeof error === 'string' && error)
|
|
26
|
+
return new Error(error);
|
|
27
|
+
return new Error(fallback);
|
|
28
|
+
}
|
|
29
|
+
function isWebSocketForDiscoveryPort(value, port) {
|
|
30
|
+
try {
|
|
31
|
+
const url = new URL(value);
|
|
32
|
+
return (url.protocol === 'ws:' &&
|
|
33
|
+
(0, loopbackHost_1.isLoopbackHost)(url.hostname) &&
|
|
34
|
+
!url.username &&
|
|
35
|
+
!url.password &&
|
|
36
|
+
Number.parseInt(url.port || '80', 10) === port);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function canonicalApplicationUrl(value, removeInjectedParameters) {
|
|
43
|
+
const url = new URL(value);
|
|
44
|
+
if (removeInjectedParameters) {
|
|
45
|
+
for (const parameter of VALDI_INJECTED_QUERY_PARAMETERS)
|
|
46
|
+
url.searchParams.delete(parameter);
|
|
47
|
+
}
|
|
48
|
+
const entries = Array.from(url.searchParams.entries()).sort(([firstName], [secondName]) => {
|
|
49
|
+
if (firstName !== secondName)
|
|
50
|
+
return firstName < secondName ? -1 : 1;
|
|
51
|
+
return 0;
|
|
52
|
+
});
|
|
53
|
+
url.search = '';
|
|
54
|
+
for (const [name, value] of entries)
|
|
55
|
+
url.searchParams.append(name, value);
|
|
56
|
+
return `${url.origin}${url.pathname}${url.search}`;
|
|
57
|
+
}
|
|
58
|
+
function matchesOwlApplicationUrl(inspectedUrl, applicationUrl) {
|
|
59
|
+
try {
|
|
60
|
+
return canonicalApplicationUrl(inspectedUrl, true) === canonicalApplicationUrl(applicationUrl, false);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.warn('[Valdi Owl] Ignoring invalid Chromium target URL.', error);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function listOwlChromiumTargets(port) {
|
|
68
|
+
return await new Promise((resolve, reject) => {
|
|
69
|
+
let settled = false;
|
|
70
|
+
let activeResponse;
|
|
71
|
+
function fail(error) {
|
|
72
|
+
if (settled)
|
|
73
|
+
return;
|
|
74
|
+
settled = true;
|
|
75
|
+
clearTimeout(deadline);
|
|
76
|
+
activeResponse?.destroy();
|
|
77
|
+
request.destroy();
|
|
78
|
+
reject(error);
|
|
79
|
+
}
|
|
80
|
+
function succeed(targets) {
|
|
81
|
+
if (settled)
|
|
82
|
+
return;
|
|
83
|
+
settled = true;
|
|
84
|
+
clearTimeout(deadline);
|
|
85
|
+
resolve(targets);
|
|
86
|
+
}
|
|
87
|
+
const request = node_http_1.default.get(`http://127.0.0.1:${port}/json/list`, response => {
|
|
88
|
+
activeResponse = response;
|
|
89
|
+
if (response.statusCode !== 200) {
|
|
90
|
+
fail(new Error(`Owl Chromium discovery returned HTTP ${String(response.statusCode)}.`));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const chunks = [];
|
|
94
|
+
let bodyBytes = 0;
|
|
95
|
+
response.on('data', (chunk) => {
|
|
96
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
97
|
+
const chunkBytes = buffer.length;
|
|
98
|
+
if (chunkBytes > MAX_CHROMIUM_DISCOVERY_BYTES - bodyBytes) {
|
|
99
|
+
fail(new Error(`Owl Chromium discovery exceeded the ${MAX_CHROMIUM_DISCOVERY_BYTES} byte response limit.`));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
bodyBytes += chunkBytes;
|
|
103
|
+
chunks.push(buffer);
|
|
104
|
+
});
|
|
105
|
+
response.once('error', error => fail(error));
|
|
106
|
+
response.once('end', () => {
|
|
107
|
+
if (settled)
|
|
108
|
+
return;
|
|
109
|
+
let body;
|
|
110
|
+
try {
|
|
111
|
+
body = FATAL_UTF8_DECODER.decode(Buffer.concat(chunks, bodyBytes));
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
fail(new Error('Owl Chromium discovery returned malformed UTF-8.'));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
const parsed = JSON.parse(body);
|
|
119
|
+
if (!Array.isArray(parsed)) {
|
|
120
|
+
fail(new Error('Owl Chromium discovery did not return a target list.'));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (parsed.length > MAX_CHROMIUM_DISCOVERY_TARGETS) {
|
|
124
|
+
fail(new Error(`Owl Chromium discovery returned more than ${MAX_CHROMIUM_DISCOVERY_TARGETS} targets.`));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const targets = parsed.filter((item) => {
|
|
128
|
+
if (typeof item !== 'object' || item === null)
|
|
129
|
+
return false;
|
|
130
|
+
const target = item;
|
|
131
|
+
return (typeof target.id === 'string' &&
|
|
132
|
+
typeof target.title === 'string' &&
|
|
133
|
+
typeof target.type === 'string' &&
|
|
134
|
+
typeof target.url === 'string' &&
|
|
135
|
+
typeof target.webSocketDebuggerUrl === 'string' &&
|
|
136
|
+
isWebSocketForDiscoveryPort(target.webSocketDebuggerUrl, port));
|
|
137
|
+
});
|
|
138
|
+
succeed(targets);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
fail(chromiumError(error, 'Owl Chromium discovery returned invalid JSON.'));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
const deadline = setTimeout(() => {
|
|
146
|
+
fail(new Error(`Timed out discovering Owl Chromium targets on port ${port}.`));
|
|
147
|
+
}, CHROMIUM_DISCOVERY_TIMEOUT_MS);
|
|
148
|
+
request.once('error', error => fail(error));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function guardedOwlExpression(applicationUrl, targetNonce, expression) {
|
|
152
|
+
const expectedUrl = canonicalApplicationUrl(applicationUrl, false);
|
|
153
|
+
return `(async () => {
|
|
154
|
+
const currentUrl = new URL(globalThis.location.href);
|
|
155
|
+
for (const parameter of ${JSON.stringify(VALDI_INJECTED_QUERY_PARAMETERS)}) currentUrl.searchParams.delete(parameter);
|
|
156
|
+
const entries = Array.from(currentUrl.searchParams.entries()).sort(([firstName], [secondName]) =>
|
|
157
|
+
firstName === secondName ? 0 : firstName < secondName ? -1 : 1
|
|
158
|
+
);
|
|
159
|
+
currentUrl.search = '';
|
|
160
|
+
for (const [name, value] of entries) currentUrl.searchParams.append(name, value);
|
|
161
|
+
const canonicalUrl = currentUrl.origin + currentUrl.pathname + currentUrl.search;
|
|
162
|
+
if (
|
|
163
|
+
globalThis[${JSON.stringify(exports.OWL_DEVTOOLS_TARGET_NONCE_PROPERTY)}] !== ${JSON.stringify(targetNonce)} ||
|
|
164
|
+
canonicalUrl !== ${JSON.stringify(expectedUrl)}
|
|
165
|
+
) {
|
|
166
|
+
return { ${JSON.stringify(GUARDED_TARGET_MATCH_PROPERTY)}: false };
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
${JSON.stringify(GUARDED_TARGET_MATCH_PROPERTY)}: true,
|
|
170
|
+
value: await (${expression}),
|
|
171
|
+
};
|
|
172
|
+
})()`;
|
|
173
|
+
}
|
|
174
|
+
async function evaluateGuardedOwlExpression(connection, applicationUrl, targetNonce, expression) {
|
|
175
|
+
const result = await connection.evaluate(guardedOwlExpression(applicationUrl, targetNonce, expression));
|
|
176
|
+
if (typeof result !== 'object' || result === null || Array.isArray(result)) {
|
|
177
|
+
throw new Error('The running Owl page returned an invalid guarded evaluation result.');
|
|
178
|
+
}
|
|
179
|
+
const record = result;
|
|
180
|
+
if (record[GUARDED_TARGET_MATCH_PROPERTY] === false)
|
|
181
|
+
return { matched: false };
|
|
182
|
+
if (record[GUARDED_TARGET_MATCH_PROPERTY] !== true) {
|
|
183
|
+
throw new Error('The running Owl page omitted its guarded target identity.');
|
|
184
|
+
}
|
|
185
|
+
return { matched: true, value: record['value'] };
|
|
186
|
+
}
|
|
187
|
+
class OwlChromiumConnection {
|
|
188
|
+
connection;
|
|
189
|
+
constructor(connection) {
|
|
190
|
+
this.connection = connection;
|
|
191
|
+
}
|
|
192
|
+
static async connect(webSocketUrl) {
|
|
193
|
+
const parsed = new URL(webSocketUrl);
|
|
194
|
+
if (parsed.protocol !== 'ws:' || !(0, loopbackHost_1.isLoopbackHost)(parsed.hostname) || parsed.username || parsed.password) {
|
|
195
|
+
throw new Error('Owl Chromium inspection only allows unauthenticated loopback WebSocket targets.');
|
|
196
|
+
}
|
|
197
|
+
return new OwlChromiumConnection(await chromiumDevToolsClient_1.ChromiumDevToolsConnection.connect(webSocketUrl, CHROMIUM_DISCOVERY_TIMEOUT_MS));
|
|
198
|
+
}
|
|
199
|
+
async evaluate(expression) {
|
|
200
|
+
const result = (await this.connection.call('Runtime.evaluate', {
|
|
201
|
+
awaitPromise: true,
|
|
202
|
+
expression,
|
|
203
|
+
returnByValue: true,
|
|
204
|
+
}, CHROMIUM_COMMAND_TIMEOUT_MS));
|
|
205
|
+
if (result.exceptionDetails) {
|
|
206
|
+
throw new Error(result.exceptionDetails.text ?? 'Owl Chromium could not evaluate the Valdi inspection request.');
|
|
207
|
+
}
|
|
208
|
+
if (result.result?.type === 'undefined') {
|
|
209
|
+
throw new Error('The running Owl page has not registered the Valdi inspection bridge.');
|
|
210
|
+
}
|
|
211
|
+
return result.result?.value;
|
|
212
|
+
}
|
|
213
|
+
async call(method, params, timeoutMs) {
|
|
214
|
+
return await this.connection.call(method, params, timeoutMs);
|
|
215
|
+
}
|
|
216
|
+
async matchesTarget(applicationUrl, targetNonce) {
|
|
217
|
+
const evaluation = await evaluateGuardedOwlExpression(this, applicationUrl, targetNonce, 'true');
|
|
218
|
+
return evaluation.matched;
|
|
219
|
+
}
|
|
220
|
+
onClose(listener) {
|
|
221
|
+
return this.connection.onClose(listener);
|
|
222
|
+
}
|
|
223
|
+
onEvent(listener) {
|
|
224
|
+
return this.connection.onEvent(listener);
|
|
225
|
+
}
|
|
226
|
+
close() {
|
|
227
|
+
this.connection.close();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.OwlChromiumConnection = OwlChromiumConnection;
|
|
231
|
+
async function connectToOwlApplication(port, applicationUrl, targetNonce) {
|
|
232
|
+
const targets = await listOwlChromiumTargets(port);
|
|
233
|
+
const candidates = targets.filter(candidate => candidate.type === 'page' && matchesOwlApplicationUrl(candidate.url, applicationUrl));
|
|
234
|
+
if (candidates.length === 0) {
|
|
235
|
+
throw new Error('No running Owl Chromium page matches this Valdi application.');
|
|
236
|
+
}
|
|
237
|
+
let lastProbeError = null;
|
|
238
|
+
for (const candidate of candidates) {
|
|
239
|
+
let connection = null;
|
|
240
|
+
let matched = false;
|
|
241
|
+
try {
|
|
242
|
+
connection = await OwlChromiumConnection.connect(candidate.webSocketDebuggerUrl);
|
|
243
|
+
const probe = await evaluateGuardedOwlExpression(connection, applicationUrl, targetNonce, 'true');
|
|
244
|
+
if (!probe.matched)
|
|
245
|
+
continue;
|
|
246
|
+
matched = true;
|
|
247
|
+
return connection;
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
lastProbeError = chromiumError(error, 'Could not inspect the candidate Owl Chromium page.');
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
if (connection && !matched)
|
|
254
|
+
connection.close();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (candidates.length === 1 && lastProbeError)
|
|
258
|
+
throw lastProbeError;
|
|
259
|
+
throw new Error('No running Owl Chromium page matches the exact inspected DevTools tab.');
|
|
260
|
+
}
|
|
261
|
+
async function evaluateOnOwlApplication(port, applicationUrl, targetNonce, expression) {
|
|
262
|
+
const connection = await connectToOwlApplication(port, applicationUrl, targetNonce);
|
|
263
|
+
try {
|
|
264
|
+
const evaluation = await evaluateGuardedOwlExpression(connection, applicationUrl, targetNonce, expression);
|
|
265
|
+
if (evaluation.matched)
|
|
266
|
+
return evaluation.value;
|
|
267
|
+
throw new Error('The inspected Owl page changed while the debugger request was running.');
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
connection.close();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async function readOwlDebuggerSnapshot(port, applicationUrl, targetNonce) {
|
|
274
|
+
const snapshot = await evaluateOwlApplicationExpression(port, applicationUrl, targetNonce, 'globalThis.__VALDI_WEB_DEBUGGER__?.getSnapshot()');
|
|
275
|
+
if (typeof snapshot !== 'object' || snapshot === null || Array.isArray(snapshot)) {
|
|
276
|
+
throw new Error('The running Owl page returned an invalid Valdi debug snapshot.');
|
|
277
|
+
}
|
|
278
|
+
return snapshot;
|
|
279
|
+
}
|
|
280
|
+
async function evaluateOwlApplicationExpression(port, applicationUrl, targetNonce, expression) {
|
|
281
|
+
return await evaluateOnOwlApplication(port, applicationUrl, targetNonce, expression);
|
|
282
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeOwlDevToolsExtension = writeOwlDevToolsExtension;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const errors_1 = require("../core/errors");
|
|
8
|
+
const loopbackHost_1 = require("./loopbackHost");
|
|
9
|
+
const owlCdpClient_1 = require("./owlCdpClient");
|
|
10
|
+
const DEVTOOLS_PAGE = `<!doctype html>
|
|
11
|
+
<html lang="en">
|
|
12
|
+
<head>
|
|
13
|
+
<meta charset="utf-8" />
|
|
14
|
+
<script src="./devtools.js"></script>
|
|
15
|
+
</head>
|
|
16
|
+
</html>
|
|
17
|
+
`;
|
|
18
|
+
const DEVTOOLS_SCRIPT = `chrome.devtools.panels.create('Valdi', '', 'panel.html');
|
|
19
|
+
`;
|
|
20
|
+
const PANEL_PAGE = `<!doctype html>
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<head>
|
|
23
|
+
<meta charset="utf-8" />
|
|
24
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
25
|
+
<title>Valdi Debugger</title>
|
|
26
|
+
<link rel="stylesheet" href="./panel.css" />
|
|
27
|
+
</head>
|
|
28
|
+
<body>
|
|
29
|
+
<iframe id="valdi-debugger" title="Valdi Debugger" referrerpolicy="no-referrer"></iframe>
|
|
30
|
+
<script src="./panel.js"></script>
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
|
33
|
+
`;
|
|
34
|
+
const PANEL_STYLES = `html,
|
|
35
|
+
body,
|
|
36
|
+
#valdi-debugger {
|
|
37
|
+
width: 100%;
|
|
38
|
+
height: 100%;
|
|
39
|
+
margin: 0;
|
|
40
|
+
border: 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
body {
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
function resolveDebuggerUrl(value) {
|
|
48
|
+
let url;
|
|
49
|
+
try {
|
|
50
|
+
url = new URL(value);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw new errors_1.CliError(`Invalid Valdi debugger URL: ${value}`);
|
|
54
|
+
}
|
|
55
|
+
if (url.protocol !== 'http:' || !(0, loopbackHost_1.isLoopbackHost)(url.hostname) || url.username !== '' || url.password !== '') {
|
|
56
|
+
throw new errors_1.CliError(`The Valdi DevTools panel requires a loopback HTTP debugger URL: ${value}`);
|
|
57
|
+
}
|
|
58
|
+
return url;
|
|
59
|
+
}
|
|
60
|
+
function writeOwlDevToolsExtension(extensionDirectory, debuggerUrl) {
|
|
61
|
+
const url = resolveDebuggerUrl(debuggerUrl);
|
|
62
|
+
node_fs_1.default.mkdirSync(extensionDirectory, { recursive: true });
|
|
63
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(extensionDirectory, 'manifest.json'), `${JSON.stringify({
|
|
64
|
+
manifest_version: 3,
|
|
65
|
+
name: 'Valdi DevTools',
|
|
66
|
+
version: '1.0.0',
|
|
67
|
+
description: 'Inspect the running Valdi application inside Chromium DevTools.',
|
|
68
|
+
devtools_page: 'devtools.html',
|
|
69
|
+
host_permissions: [`${url.origin}/*`],
|
|
70
|
+
content_security_policy: {
|
|
71
|
+
extension_pages: `script-src 'self'; object-src 'self'; frame-src ${url.origin}`,
|
|
72
|
+
},
|
|
73
|
+
}, undefined, 2)}\n`);
|
|
74
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(extensionDirectory, 'devtools.html'), DEVTOOLS_PAGE);
|
|
75
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(extensionDirectory, 'devtools.js'), DEVTOOLS_SCRIPT);
|
|
76
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(extensionDirectory, 'panel.html'), PANEL_PAGE);
|
|
77
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(extensionDirectory, 'panel.js'), `const debuggerUrl = new URL(${JSON.stringify(url.toString())});
|
|
78
|
+
debuggerUrl.pathname = '/devtools-panel.html';
|
|
79
|
+
debuggerUrl.searchParams.set('theme', chrome.devtools.panels.themeName || 'default');
|
|
80
|
+
const inspectedTargetMarker = ${JSON.stringify(owlCdpClient_1.OWL_DEVTOOLS_TARGET_NONCE_PROPERTY)};
|
|
81
|
+
const inspectedTargetNonce = crypto.randomUUID();
|
|
82
|
+
let inspectedTargetGeneration = 0;
|
|
83
|
+
|
|
84
|
+
function inspectedTargetExpression(remove) {
|
|
85
|
+
const marker = JSON.stringify(inspectedTargetMarker);
|
|
86
|
+
const nonce = JSON.stringify(inspectedTargetNonce);
|
|
87
|
+
if (remove) {
|
|
88
|
+
return '(() => { const marker = ' + marker + '; const nonce = ' + nonce + '; if (globalThis[marker] === nonce) { try { globalThis.__VALDI_WEB_DEBUGGER__?.clearHighlight?.(); } finally { delete globalThis[marker]; } } return true; })()';
|
|
89
|
+
}
|
|
90
|
+
return '(() => { const marker = ' + marker + '; const nonce = ' + nonce + '; Object.defineProperty(globalThis, marker, { configurable: true, value: nonce }); return { nonce, url: String(globalThis.location.href) }; })()';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function updateInspectedTarget() {
|
|
94
|
+
const generation = ++inspectedTargetGeneration;
|
|
95
|
+
chrome.devtools.inspectedWindow.eval(inspectedTargetExpression(false), (identity, error) => {
|
|
96
|
+
if (generation !== inspectedTargetGeneration) return;
|
|
97
|
+
if (
|
|
98
|
+
error ||
|
|
99
|
+
!identity ||
|
|
100
|
+
identity.nonce !== inspectedTargetNonce ||
|
|
101
|
+
typeof identity.url !== 'string'
|
|
102
|
+
) {
|
|
103
|
+
console.error('Unable to resolve the inspected Valdi Owl application.', error);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
debuggerUrl.searchParams.set('inspectedUrl', identity.url);
|
|
107
|
+
debuggerUrl.searchParams.set('targetNonce', inspectedTargetNonce);
|
|
108
|
+
document.getElementById('valdi-debugger').src = debuggerUrl.toString();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function clearInspectedTarget() {
|
|
113
|
+
chrome.devtools.inspectedWindow.eval(inspectedTargetExpression(true), (_result, error) => {
|
|
114
|
+
if (error) console.warn('Unable to clear the inspected Valdi Owl marker.', error);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function teardownInspectedTarget() {
|
|
119
|
+
inspectedTargetGeneration++;
|
|
120
|
+
if (chrome.devtools.network && chrome.devtools.network.onNavigated) {
|
|
121
|
+
chrome.devtools.network.onNavigated.removeListener(updateInspectedTarget);
|
|
122
|
+
}
|
|
123
|
+
clearInspectedTarget();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (chrome.devtools.network && chrome.devtools.network.onNavigated) {
|
|
127
|
+
chrome.devtools.network.onNavigated.addListener(updateInspectedTarget);
|
|
128
|
+
}
|
|
129
|
+
window.addEventListener('unload', teardownInspectedTarget);
|
|
130
|
+
updateInspectedTarget();
|
|
131
|
+
|
|
132
|
+
if (chrome.devtools.panels.onThemeChanged) {
|
|
133
|
+
chrome.devtools.panels.onThemeChanged.addListener(theme => {
|
|
134
|
+
const frame = document.getElementById('valdi-debugger');
|
|
135
|
+
if (frame.contentWindow) {
|
|
136
|
+
frame.contentWindow.postMessage({ channel: 'valdi-devtools-theme', theme }, debuggerUrl.origin);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
`);
|
|
141
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(extensionDirectory, 'panel.css'), PANEL_STYLES);
|
|
142
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForShutdownSignal = waitForShutdownSignal;
|
|
4
|
+
function waitForShutdownSignal() {
|
|
5
|
+
return new Promise(resolve => {
|
|
6
|
+
const resolveOnce = () => {
|
|
7
|
+
process.off('SIGINT', resolveOnce);
|
|
8
|
+
process.off('SIGTERM', resolveOnce);
|
|
9
|
+
resolve();
|
|
10
|
+
};
|
|
11
|
+
process.once('SIGINT', resolveOnce);
|
|
12
|
+
process.once('SIGTERM', resolveOnce);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sanitizeProjectName = sanitizeProjectName;
|
|
4
|
+
exports.isValidBazelModuleName = isValidBazelModuleName;
|
|
4
5
|
exports.validateProjectName = validateProjectName;
|
|
5
6
|
exports.toPascalCase = toPascalCase;
|
|
6
7
|
exports.toSnakeCase = toSnakeCase;
|
|
@@ -47,7 +48,11 @@ function sanitizeProjectName(name) {
|
|
|
47
48
|
}
|
|
48
49
|
return sanitized;
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
+
const BAZEL_MODULE_NAME_REGEX = /^[a-z]([\d._a-z-]*[\da-z])?$/;
|
|
52
|
+
function isValidBazelModuleName(name) {
|
|
53
|
+
return BAZEL_MODULE_NAME_REGEX.test(name);
|
|
54
|
+
}
|
|
55
|
+
function validateProjectName(name, options = {}) {
|
|
51
56
|
if (!name || name.trim().length === 0) {
|
|
52
57
|
return 'Project name cannot be empty.';
|
|
53
58
|
}
|
|
@@ -58,6 +63,13 @@ function validateProjectName(name) {
|
|
|
58
63
|
if (RESERVED_PROJECT_NAMES.has(sanitized.toLowerCase())) {
|
|
59
64
|
return `Project name "${name}" (sanitized to "${sanitized}") is a reserved word and cannot be used. Please choose a different name.`;
|
|
60
65
|
}
|
|
66
|
+
if (options.requireBazelModuleName && !isValidBazelModuleName(sanitized)) {
|
|
67
|
+
const suggestion = sanitized.toLowerCase().replace(/^[^a-z]+/, '').replace(/[^\da-z]+$/, '');
|
|
68
|
+
return (`Project name "${name}" is not a valid Bazel module name. ` +
|
|
69
|
+
`It must only contain lowercase letters (a-z), digits (0-9), dots (.), hyphens (-) and underscores (_), ` +
|
|
70
|
+
`begin with a lowercase letter and end with a lowercase letter or digit.` +
|
|
71
|
+
(suggestion ? ` Did you mean "${suggestion}"?` : ''));
|
|
72
|
+
}
|
|
61
73
|
if (sanitized !== name.replace(/-/g, '_')) {
|
|
62
74
|
return `Project name "${name}" contains invalid characters. It will be sanitized to "${sanitized}". Please use only letters, numbers, underscores, and dashes.`;
|
|
63
75
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startWebApplicationSession = startWebApplicationSession;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const webServerUtils_1 = require("./webServerUtils");
|
|
8
|
+
const zipUtils_1 = require("./zipUtils");
|
|
9
|
+
async function extractWebSite(archivePath, sitesDir, generation) {
|
|
10
|
+
const siteDir = node_path_1.default.join(sitesDir, String(generation));
|
|
11
|
+
node_fs_1.default.mkdirSync(siteDir);
|
|
12
|
+
try {
|
|
13
|
+
await (0, zipUtils_1.decompressTo)(archivePath, siteDir);
|
|
14
|
+
return siteDir;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
node_fs_1.default.rmSync(siteDir, { force: true, recursive: true });
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function startWebApplicationSession(options) {
|
|
22
|
+
const sitesDir = node_path_1.default.join(options.workingDir, 'sites');
|
|
23
|
+
node_fs_1.default.mkdirSync(sitesDir);
|
|
24
|
+
let generation = 1;
|
|
25
|
+
let activeSiteDir = await extractWebSite(options.archivePath, sitesDir, generation);
|
|
26
|
+
const staleSiteDirs = [];
|
|
27
|
+
const server = await (0, webServerUtils_1.startStaticWebServer)(activeSiteDir, {
|
|
28
|
+
host: options.host,
|
|
29
|
+
liveReload: options.liveReload ?? false,
|
|
30
|
+
port: options.port,
|
|
31
|
+
});
|
|
32
|
+
let publicationQueue = Promise.resolve();
|
|
33
|
+
const publish = async () => {
|
|
34
|
+
const nextSiteDir = await extractWebSite(options.archivePath, sitesDir, ++generation);
|
|
35
|
+
const previousSiteDir = activeSiteDir;
|
|
36
|
+
activeSiteDir = nextSiteDir;
|
|
37
|
+
server.setRootDir(nextSiteDir);
|
|
38
|
+
server.reload();
|
|
39
|
+
staleSiteDirs.push(previousSiteDir);
|
|
40
|
+
while (staleSiteDirs.length > 1) {
|
|
41
|
+
const staleSiteDir = staleSiteDirs.shift();
|
|
42
|
+
if (staleSiteDir) {
|
|
43
|
+
node_fs_1.default.rmSync(staleSiteDir, { force: true, recursive: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
url: server.url,
|
|
49
|
+
close: async () => {
|
|
50
|
+
await publicationQueue.catch(() => { });
|
|
51
|
+
await server.close();
|
|
52
|
+
},
|
|
53
|
+
publish: () => {
|
|
54
|
+
publicationQueue = publicationQueue.then(publish, publish);
|
|
55
|
+
return publicationQueue;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|