@snap/valdi 1.1.5 → 1.2.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/.metadata/.bazelrc.template +9 -3
- package/.metadata/MODULE.bazel.template +112 -3
- 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/README.md +35 -1
- 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-bazel/skill.md +2 -6
- package/bundled-skills/skills/valdi-compiler/skill.md +4 -4
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +18 -0
- 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-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-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/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 +6 -5
- package/dist/commands/build.js +6 -0
- package/dist/commands/debugger.js +163 -0
- package/dist/commands/doctor.js +5 -125
- 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 +6 -0
- package/dist/commands/projectsync.js +15 -0
- package/dist/commands/webHotreload.js +31 -0
- package/dist/core/constants.js +26 -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/setup/DevSetupHelper.js +0 -3
- package/dist/setup/linuxSetup.js +0 -14
- package/dist/setup/macOSSetup.js +1 -2
- package/dist/utils/BazelClient.js +34 -5
- package/dist/utils/applicationUtils.js +18 -0
- package/dist/utils/chromiumDevToolsClient.js +350 -0
- package/dist/utils/daemonClient.js +364 -44
- package/dist/utils/hermesClient.js +82 -176
- package/dist/utils/linuxDistro.js +0 -21
- package/dist/utils/loopbackHost.js +14 -0
- package/dist/utils/owlCdpClient.js +282 -0
- package/dist/utils/owlDevToolsExtension.js +142 -0
- package/dist/utils/skillsAdapters.js +40 -14
- package/dist/utils/stringUtils.js +13 -1
- 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 -170
- package/dist/utils/skillsAdapters.spec.js +0 -60
- package/dist/utils/stringUtils.spec.js +0 -81
|
@@ -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
|
+
}
|
|
@@ -121,26 +121,52 @@ const CursorAdapter = {
|
|
|
121
121
|
const cursorDir = path.join(os.homedir(), '.cursor');
|
|
122
122
|
return fs.existsSync(cursorDir);
|
|
123
123
|
},
|
|
124
|
-
install(skillName, content, meta) {
|
|
125
|
-
const
|
|
126
|
-
fs.mkdirSync(
|
|
127
|
-
const frontmatter = `---\
|
|
128
|
-
fs.writeFileSync(path.join(
|
|
124
|
+
install(skillName, content, meta, resourceDir) {
|
|
125
|
+
const skillDir = path.join(os.homedir(), '.cursor', 'skills', skillName);
|
|
126
|
+
fs.mkdirSync(skillDir, { recursive: true });
|
|
127
|
+
const frontmatter = `---\nname: ${meta.name}\ndescription: ${meta.description}\n---\n\n`;
|
|
128
|
+
fs.writeFileSync(path.join(skillDir, 'SKILL.md'), frontmatter + content, 'utf8');
|
|
129
|
+
if (resourceDir) {
|
|
130
|
+
for (const entry of fs.readdirSync(resourceDir, { withFileTypes: true })) {
|
|
131
|
+
if (entry.isDirectory()) {
|
|
132
|
+
copyDirSync(path.join(resourceDir, entry.name), path.join(skillDir, entry.name));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const legacyFile = path.join(os.homedir(), '.cursor', 'rules', `valdi-${skillName}.mdc`);
|
|
137
|
+
if (fs.existsSync(legacyFile)) {
|
|
138
|
+
fs.unlinkSync(legacyFile);
|
|
139
|
+
}
|
|
129
140
|
},
|
|
130
141
|
remove(skillName) {
|
|
131
|
-
const
|
|
132
|
-
if (fs.existsSync(
|
|
133
|
-
fs.
|
|
142
|
+
const skillDir = path.join(os.homedir(), '.cursor', 'skills', skillName);
|
|
143
|
+
if (fs.existsSync(skillDir)) {
|
|
144
|
+
fs.rmSync(skillDir, { recursive: true, force: true });
|
|
145
|
+
}
|
|
146
|
+
const legacyFile = path.join(os.homedir(), '.cursor', 'rules', `valdi-${skillName}.mdc`);
|
|
147
|
+
if (fs.existsSync(legacyFile)) {
|
|
148
|
+
fs.unlinkSync(legacyFile);
|
|
134
149
|
}
|
|
135
150
|
},
|
|
136
151
|
listInstalled() {
|
|
152
|
+
const installed = new Set();
|
|
153
|
+
const skillsDir = path.join(os.homedir(), '.cursor', 'skills');
|
|
154
|
+
if (fs.existsSync(skillsDir)) {
|
|
155
|
+
for (const entry of fs.readdirSync(skillsDir)) {
|
|
156
|
+
if (fs.existsSync(path.join(skillsDir, entry, 'SKILL.md'))) {
|
|
157
|
+
installed.add(entry);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
137
161
|
const rulesDir = path.join(os.homedir(), '.cursor', 'rules');
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
162
|
+
if (fs.existsSync(rulesDir)) {
|
|
163
|
+
for (const f of fs.readdirSync(rulesDir)) {
|
|
164
|
+
if (f.startsWith('valdi-') && f.endsWith('.mdc')) {
|
|
165
|
+
installed.add(f.replace(/^valdi-/u, '').replace(/\.mdc$/u, ''));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return Array.from(installed);
|
|
144
170
|
},
|
|
145
171
|
};
|
|
146
172
|
const CopilotAdapter = {
|
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snap/valdi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Valdi CLI tools for developers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,14 +16,16 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
19
|
+
"debugger",
|
|
19
20
|
"bundled-skills",
|
|
20
21
|
".metadata",
|
|
21
22
|
".bootstrap"
|
|
22
23
|
],
|
|
23
24
|
"scripts": {
|
|
24
25
|
"prepare": "npm run build",
|
|
25
|
-
"prebuild": "node scripts/bundle-skills.js",
|
|
26
|
+
"prebuild": "node scripts/clean-dist.js && node scripts/bundle-skills.js",
|
|
26
27
|
"build": "npm exec --package=typescript@5.9.2 tsc -- --project ./tsconfig.dist.json",
|
|
28
|
+
"postbuild": "chmod +x dist/index.js",
|
|
27
29
|
"test": "tsx node_modules/jasmine/bin/jasmine",
|
|
28
30
|
"watch": "tsc --watch",
|
|
29
31
|
"main": "ts-node ./src/index.ts",
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
require("jasmine");
|
|
4
|
-
const snapshot_1 = require("./snapshot");
|
|
5
|
-
describe('snapshot tree helpers', () => {
|
|
6
|
-
describe('firstElementId', () => {
|
|
7
|
-
it('returns null for null/non-object input', () => {
|
|
8
|
-
expect((0, snapshot_1.firstElementId)(null)).toBeNull();
|
|
9
|
-
expect((0, snapshot_1.firstElementId)(undefined)).toBeNull();
|
|
10
|
-
expect((0, snapshot_1.firstElementId)(42)).toBeNull();
|
|
11
|
-
expect((0, snapshot_1.firstElementId)('string')).toBeNull();
|
|
12
|
-
});
|
|
13
|
-
it('returns the element id from a direct element node', () => {
|
|
14
|
-
const node = { element: { id: 5 } };
|
|
15
|
-
expect((0, snapshot_1.firstElementId)(node)).toBe('5');
|
|
16
|
-
});
|
|
17
|
-
it('returns the first element id from nested children', () => {
|
|
18
|
-
const node = {
|
|
19
|
-
children: [
|
|
20
|
-
{ tag: 'view' },
|
|
21
|
-
{ children: [{ element: { id: 42 } }] },
|
|
22
|
-
],
|
|
23
|
-
};
|
|
24
|
-
expect((0, snapshot_1.firstElementId)(node)).toBe('42');
|
|
25
|
-
});
|
|
26
|
-
it('returns null when no element is found', () => {
|
|
27
|
-
const node = { children: [{ tag: 'view' }, { tag: 'label' }] };
|
|
28
|
-
expect((0, snapshot_1.firstElementId)(node)).toBeNull();
|
|
29
|
-
});
|
|
30
|
-
it('handles element id of 0', () => {
|
|
31
|
-
const node = { element: { id: 0 } };
|
|
32
|
-
expect((0, snapshot_1.firstElementId)(node)).toBe('0');
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe('findElementByKey', () => {
|
|
36
|
-
it('finds element by explicit key', () => {
|
|
37
|
-
const tree = {
|
|
38
|
-
children: [
|
|
39
|
-
{ key: 'header', element: { id: 10 } },
|
|
40
|
-
{ key: 'body', element: { id: 20 } },
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
expect((0, snapshot_1.findElementByKey)(tree, 'header')).toBe('10');
|
|
44
|
-
expect((0, snapshot_1.findElementByKey)(tree, 'body')).toBe('20');
|
|
45
|
-
});
|
|
46
|
-
it('finds element by tag name', () => {
|
|
47
|
-
const tree = {
|
|
48
|
-
children: [
|
|
49
|
-
{ tag: 'ChatFriendsList', element: { id: 15 } },
|
|
50
|
-
],
|
|
51
|
-
};
|
|
52
|
-
expect((0, snapshot_1.findElementByKey)(tree, 'ChatFriendsList')).toBe('15');
|
|
53
|
-
});
|
|
54
|
-
it('finds component node by tag and returns first child element id', () => {
|
|
55
|
-
const tree = {
|
|
56
|
-
children: [
|
|
57
|
-
{
|
|
58
|
-
tag: 'MyComponent',
|
|
59
|
-
component: 'MyComponent',
|
|
60
|
-
children: [
|
|
61
|
-
{ element: { id: 99 } },
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
};
|
|
66
|
-
expect((0, snapshot_1.findElementByKey)(tree, 'MyComponent')).toBe('99');
|
|
67
|
-
});
|
|
68
|
-
it('searches deeply nested trees', () => {
|
|
69
|
-
const tree = {
|
|
70
|
-
children: [
|
|
71
|
-
{
|
|
72
|
-
children: [
|
|
73
|
-
{
|
|
74
|
-
children: [
|
|
75
|
-
{ key: 'deep-key', element: { id: 77 } },
|
|
76
|
-
],
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
};
|
|
82
|
-
expect((0, snapshot_1.findElementByKey)(tree, 'deep-key')).toBe('77');
|
|
83
|
-
});
|
|
84
|
-
it('returns null when key is not found', () => {
|
|
85
|
-
const tree = {
|
|
86
|
-
children: [
|
|
87
|
-
{ key: 'exists', element: { id: 1 } },
|
|
88
|
-
],
|
|
89
|
-
};
|
|
90
|
-
expect((0, snapshot_1.findElementByKey)(tree, 'nonexistent')).toBeNull();
|
|
91
|
-
});
|
|
92
|
-
it('returns null for null input', () => {
|
|
93
|
-
expect((0, snapshot_1.findElementByKey)(null, 'anything')).toBeNull();
|
|
94
|
-
});
|
|
95
|
-
it('prefers key match over tag match', () => {
|
|
96
|
-
const tree = {
|
|
97
|
-
children: [
|
|
98
|
-
{ key: 'my-key', tag: 'SomeTag', element: { id: 1 } },
|
|
99
|
-
{ key: 'other', tag: 'my-key', element: { id: 2 } },
|
|
100
|
-
],
|
|
101
|
-
};
|
|
102
|
-
expect((0, snapshot_1.findElementByKey)(tree, 'my-key')).toBe('1');
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
require("jasmine");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
-
describe('npm package contents', () => {
|
|
8
|
-
let packedFiles;
|
|
9
|
-
beforeAll(() => {
|
|
10
|
-
const cliRoot = path_1.default.join(__dirname, '../..');
|
|
11
|
-
packedFiles = (0, child_process_1.execSync)('npm pack --dry-run 2>&1', {
|
|
12
|
-
cwd: cliRoot,
|
|
13
|
-
encoding: 'utf-8',
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
it('includes .metadata templates for bootstrap config', () => {
|
|
17
|
-
expect(packedFiles).toContain('.metadata/config.yaml.template');
|
|
18
|
-
expect(packedFiles).toContain('.metadata/MODULE.bazel.template');
|
|
19
|
-
});
|
|
20
|
-
it('includes .bootstrap templates for project scaffolding', () => {
|
|
21
|
-
expect(packedFiles).toContain('.bootstrap/');
|
|
22
|
-
});
|
|
23
|
-
it('includes dist output', () => {
|
|
24
|
-
expect(packedFiles).toContain('dist/');
|
|
25
|
-
});
|
|
26
|
-
it('includes bundled-skills', () => {
|
|
27
|
-
expect(packedFiles).toContain('bundled-skills/');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
require("jasmine");
|
|
5
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
-
const os = tslib_1.__importStar(require("os"));
|
|
7
|
-
const path = tslib_1.__importStar(require("path"));
|
|
8
|
-
const previewGenerator_1 = require("./previewGenerator");
|
|
9
|
-
describe('previewGenerator', () => {
|
|
10
|
-
let tmpDir;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pg-test-'));
|
|
13
|
-
});
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
16
|
-
});
|
|
17
|
-
describe('getPreviewDir', () => {
|
|
18
|
-
it('returns apps/preview under workspace root', () => {
|
|
19
|
-
expect((0, previewGenerator_1.getPreviewDir)('/workspace')).toBe('/workspace/apps/preview');
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe('getModuleNameFromImport', () => {
|
|
23
|
-
it('extracts the first path segment', () => {
|
|
24
|
-
expect((0, previewGenerator_1.getModuleNameFromImport)('widgets/src/components/Button')).toBe('widgets');
|
|
25
|
-
expect((0, previewGenerator_1.getModuleNameFromImport)('coreui/src/Cell')).toBe('coreui');
|
|
26
|
-
expect((0, previewGenerator_1.getModuleNameFromImport)('mymod')).toBe('mymod');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
describe('findModuleDir', () => {
|
|
30
|
-
it('walks up to find BUILD.bazel with valdi_module()', () => {
|
|
31
|
-
const modDir = path.join(tmpDir, 'mod');
|
|
32
|
-
const srcDir = path.join(modDir, 'src', 'components');
|
|
33
|
-
fs.mkdirSync(srcDir, { recursive: true });
|
|
34
|
-
fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), `
|
|
35
|
-
valdi_module(
|
|
36
|
-
name = "mymod",
|
|
37
|
-
srcs = glob(["**/*.tsx"]),
|
|
38
|
-
)
|
|
39
|
-
`, 'utf8');
|
|
40
|
-
const componentFile = path.join(srcDir, 'Button.tsx');
|
|
41
|
-
fs.writeFileSync(componentFile, 'export class Button {}', 'utf8');
|
|
42
|
-
expect((0, previewGenerator_1.findModuleDir)(componentFile)).toBe(modDir);
|
|
43
|
-
});
|
|
44
|
-
it('skips BUILD.bazel files without valdi_module()', () => {
|
|
45
|
-
const parentDir = path.join(tmpDir, 'parent');
|
|
46
|
-
const childDir = path.join(parentDir, 'child');
|
|
47
|
-
fs.mkdirSync(childDir, { recursive: true });
|
|
48
|
-
fs.writeFileSync(path.join(childDir, 'BUILD.bazel'), 'cc_library(name = "lib")', 'utf8');
|
|
49
|
-
fs.writeFileSync(path.join(parentDir, 'BUILD.bazel'), 'valdi_module(name = "mod")', 'utf8');
|
|
50
|
-
const componentFile = path.join(childDir, 'Comp.tsx');
|
|
51
|
-
fs.writeFileSync(componentFile, '', 'utf8');
|
|
52
|
-
expect((0, previewGenerator_1.findModuleDir)(componentFile)).toBe(parentDir);
|
|
53
|
-
});
|
|
54
|
-
it('throws when no valdi_module BUILD is found', () => {
|
|
55
|
-
const isolatedDir = path.join(tmpDir, 'isolated');
|
|
56
|
-
fs.mkdirSync(isolatedDir, { recursive: true });
|
|
57
|
-
const componentFile = path.join(isolatedDir, 'Comp.tsx');
|
|
58
|
-
fs.writeFileSync(componentFile, '', 'utf8');
|
|
59
|
-
expect(() => (0, previewGenerator_1.findModuleDir)(componentFile)).toThrowError(/Could not find a BUILD.bazel/);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe('readModuleName', () => {
|
|
63
|
-
it('extracts module name from BUILD.bazel', () => {
|
|
64
|
-
const modDir = path.join(tmpDir, 'mymod');
|
|
65
|
-
fs.mkdirSync(modDir, { recursive: true });
|
|
66
|
-
fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), `
|
|
67
|
-
load("@valdi//bzl:valdi.bzl", "valdi_module")
|
|
68
|
-
valdi_module(
|
|
69
|
-
name = "widgets",
|
|
70
|
-
srcs = glob(["**/*.tsx"]),
|
|
71
|
-
)
|
|
72
|
-
`, 'utf8');
|
|
73
|
-
expect((0, previewGenerator_1.readModuleName)(modDir)).toBe('widgets');
|
|
74
|
-
});
|
|
75
|
-
it('throws when no valdi_module name found', () => {
|
|
76
|
-
const modDir = path.join(tmpDir, 'bad');
|
|
77
|
-
fs.mkdirSync(modDir, { recursive: true });
|
|
78
|
-
fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'cc_library(name = "lib")', 'utf8');
|
|
79
|
-
expect(() => (0, previewGenerator_1.readModuleName)(modDir)).toThrowError(/Could not find valdi_module name/);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe('isValdiWorkspace', () => {
|
|
83
|
-
it('returns true for workspace named "valdi"', () => {
|
|
84
|
-
fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "valdi")\n', 'utf8');
|
|
85
|
-
expect((0, previewGenerator_1.isValdiWorkspace)(tmpDir)).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
it('returns false for other workspace names', () => {
|
|
88
|
-
fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "my_app")\n', 'utf8');
|
|
89
|
-
expect((0, previewGenerator_1.isValdiWorkspace)(tmpDir)).toBe(false);
|
|
90
|
-
});
|
|
91
|
-
it('returns false when no WORKSPACE file exists', () => {
|
|
92
|
-
expect((0, previewGenerator_1.isValdiWorkspace)(tmpDir)).toBe(false);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe('computeModuleLabel', () => {
|
|
96
|
-
it('computes a Bazel label from module dir', () => {
|
|
97
|
-
const modDir = path.join(tmpDir, 'src', 'widgets');
|
|
98
|
-
fs.mkdirSync(modDir, { recursive: true });
|
|
99
|
-
fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'valdi_module(name = "widgets")', 'utf8');
|
|
100
|
-
expect((0, previewGenerator_1.computeModuleLabel)(modDir, tmpDir)).toBe('//src/widgets:widgets');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('generatePreviewFiles', () => {
|
|
104
|
-
it('generates PreviewRoot.tsx, BUILD.bazel, and tsconfig.json', () => {
|
|
105
|
-
const modDir = path.join(tmpDir, 'src', 'widgets');
|
|
106
|
-
fs.mkdirSync(modDir, { recursive: true });
|
|
107
|
-
fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'valdi_module(name = "widgets")', 'utf8');
|
|
108
|
-
fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "my_app")', 'utf8');
|
|
109
|
-
const configDir = path.join(tmpDir, 'valdi_modules', '_configs');
|
|
110
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
111
|
-
fs.writeFileSync(path.join(configDir, 'base.tsconfig.json'), '{}', 'utf8');
|
|
112
|
-
const config = {
|
|
113
|
-
componentFilePath: path.join(modDir, 'src', 'Button.tsx'),
|
|
114
|
-
importPath: 'widgets/src/Button',
|
|
115
|
-
moduleLabel: '//src/widgets:widgets',
|
|
116
|
-
workspaceRoot: tmpDir,
|
|
117
|
-
isValdiRepo: false,
|
|
118
|
-
viewModel: {
|
|
119
|
-
componentName: 'Button',
|
|
120
|
-
viewModelName: 'ButtonViewModel',
|
|
121
|
-
props: [
|
|
122
|
-
{ name: 'label', typeString: 'string', optional: false, isBoolean: false, isCallback: false, callbackParamType: undefined },
|
|
123
|
-
{ name: 'onTap', typeString: '() => void', optional: false, isBoolean: false, isCallback: true, callbackParamType: undefined },
|
|
124
|
-
],
|
|
125
|
-
extraImports: [],
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
(0, previewGenerator_1.generatePreviewFiles)(config);
|
|
129
|
-
const previewDir = (0, previewGenerator_1.getPreviewDir)(tmpDir);
|
|
130
|
-
expect(fs.existsSync(path.join(previewDir, 'PreviewRoot.tsx'))).toBe(true);
|
|
131
|
-
expect(fs.existsSync(path.join(previewDir, 'BUILD.bazel'))).toBe(true);
|
|
132
|
-
expect(fs.existsSync(path.join(previewDir, 'tsconfig.json'))).toBe(true);
|
|
133
|
-
const previewTsx = fs.readFileSync(path.join(previewDir, 'PreviewRoot.tsx'), 'utf8');
|
|
134
|
-
expect(previewTsx).toContain("import { Button } from 'widgets/src/Button'");
|
|
135
|
-
expect(previewTsx).toContain('<Button');
|
|
136
|
-
expect(previewTsx).toContain("label={'Sample'}");
|
|
137
|
-
expect(previewTsx).toContain('onTap={() => {}}');
|
|
138
|
-
const buildBazel = fs.readFileSync(path.join(previewDir, 'BUILD.bazel'), 'utf8');
|
|
139
|
-
expect(buildBazel).toContain('@valdi//bzl/valdi:valdi_application.bzl');
|
|
140
|
-
expect(buildBazel).toContain('//src/widgets:widgets');
|
|
141
|
-
expect(buildBazel).toContain('root_component_path = "PreviewRoot@preview/PreviewRoot"');
|
|
142
|
-
const tsconfig = JSON.parse(fs.readFileSync(path.join(previewDir, 'tsconfig.json'), 'utf8'));
|
|
143
|
-
expect(tsconfig.compilerOptions.paths['preview/*']).toEqual(['./*']);
|
|
144
|
-
});
|
|
145
|
-
it('generates StatefulComponent when interactive state is detected', () => {
|
|
146
|
-
const modDir = path.join(tmpDir, 'src', 'widgets');
|
|
147
|
-
fs.mkdirSync(modDir, { recursive: true });
|
|
148
|
-
fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'valdi_module(name = "widgets")', 'utf8');
|
|
149
|
-
fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "other")', 'utf8');
|
|
150
|
-
const configDir = path.join(tmpDir, 'valdi_modules', '_configs');
|
|
151
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
152
|
-
fs.writeFileSync(path.join(configDir, 'base.tsconfig.json'), '{}', 'utf8');
|
|
153
|
-
const config = {
|
|
154
|
-
componentFilePath: path.join(modDir, 'src', 'Toggle.tsx'),
|
|
155
|
-
importPath: 'widgets/src/Toggle',
|
|
156
|
-
moduleLabel: '//src/widgets:widgets',
|
|
157
|
-
workspaceRoot: tmpDir,
|
|
158
|
-
isValdiRepo: false,
|
|
159
|
-
viewModel: {
|
|
160
|
-
componentName: 'Toggle',
|
|
161
|
-
viewModelName: 'ToggleVM',
|
|
162
|
-
props: [
|
|
163
|
-
{ name: 'checked', typeString: 'boolean', optional: false, isBoolean: true, isCallback: false, callbackParamType: undefined },
|
|
164
|
-
{ name: 'onToggle', typeString: '(val: boolean) => void', optional: false, isBoolean: false, isCallback: true, callbackParamType: 'boolean' },
|
|
165
|
-
],
|
|
166
|
-
extraImports: [],
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
(0, previewGenerator_1.generatePreviewFiles)(config);
|
|
170
|
-
const previewTsx = fs.readFileSync(path.join((0, previewGenerator_1.getPreviewDir)(tmpDir), 'PreviewRoot.tsx'), 'utf8');
|
|
171
|
-
expect(previewTsx).toContain('StatefulComponent');
|
|
172
|
-
expect(previewTsx).toContain('state: PreviewState');
|
|
173
|
-
expect(previewTsx).toContain('this.state.checked');
|
|
174
|
-
expect(previewTsx).toContain('this.setState');
|
|
175
|
-
});
|
|
176
|
-
it('uses // prefix for Valdi repo BUILD.bazel', () => {
|
|
177
|
-
const modDir = path.join(tmpDir, 'src', 'widgets');
|
|
178
|
-
fs.mkdirSync(modDir, { recursive: true });
|
|
179
|
-
fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'valdi_module(name = "widgets")', 'utf8');
|
|
180
|
-
fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "valdi")', 'utf8');
|
|
181
|
-
const configDir = path.join(tmpDir, 'modules', '_configs');
|
|
182
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
183
|
-
fs.writeFileSync(path.join(configDir, 'base.tsconfig.json'), '{}', 'utf8');
|
|
184
|
-
const config = {
|
|
185
|
-
componentFilePath: path.join(modDir, 'src', 'Button.tsx'),
|
|
186
|
-
importPath: 'widgets/src/Button',
|
|
187
|
-
moduleLabel: '//src/widgets:widgets',
|
|
188
|
-
workspaceRoot: tmpDir,
|
|
189
|
-
isValdiRepo: true,
|
|
190
|
-
viewModel: {
|
|
191
|
-
componentName: 'Button',
|
|
192
|
-
viewModelName: 'ButtonVM',
|
|
193
|
-
props: [],
|
|
194
|
-
extraImports: [],
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
(0, previewGenerator_1.generatePreviewFiles)(config);
|
|
198
|
-
const buildBazel = fs.readFileSync(path.join((0, previewGenerator_1.getPreviewDir)(tmpDir), 'BUILD.bazel'), 'utf8');
|
|
199
|
-
expect(buildBazel).toContain('load("//bzl/valdi:valdi_application.bzl"');
|
|
200
|
-
expect(buildBazel).not.toContain('@valdi');
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|