@snap/valdi 1.0.7 → 1.0.11
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/{ios_android_bridge_module → polyglot_bridge_module}/BUILD.bazel.template +16 -1
- package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
- package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
- package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
- package/.metadata/AGENTS.md.template +8 -274
- package/.metadata/skill-reference.tsx.template +8 -0
- package/.metadata/skill-tests-BUILD.bazel.template +21 -0
- package/.metadata/skill-tests-README.md.template +17 -0
- package/.metadata/skill.md.template +27 -0
- package/README.md +12 -3
- package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
- package/bundled-skills/registry.json +21 -0
- package/bundled-skills/skills/valdi-android/skill.md +89 -0
- package/bundled-skills/skills/valdi-async/skill.md +246 -0
- package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
- package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-bazel/skill.md +141 -0
- package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
- package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
- package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
- package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
- package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
- package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
- package/bundled-skills/skills/valdi-custom-view/skill.md +64 -0
- package/bundled-skills/skills/valdi-inspect/skill.md +199 -0
- package/bundled-skills/skills/valdi-ios/skill.md +93 -0
- package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
- package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
- package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
- package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
- package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
- package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
- package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
- package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
- package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
- package/bundled-skills/skills/valdi-overview/skill.md +63 -0
- package/bundled-skills/skills/valdi-perf/skill.md +197 -0
- package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
- package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
- package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +124 -0
- package/bundled-skills/skills/valdi-profile/skill.md +126 -0
- package/bundled-skills/skills/valdi-setup/skill.md +129 -0
- package/bundled-skills/skills/valdi-testing/skill.md +65 -0
- package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
- package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
- package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
- package/dist/commands/bootstrap.js +0 -7
- package/dist/commands/inspect.js +16 -0
- package/dist/commands/inspect_commands/contexts.js +55 -0
- package/dist/commands/inspect_commands/devices.js +53 -0
- package/dist/commands/inspect_commands/heap.js +59 -0
- package/dist/commands/inspect_commands/select.js +43 -0
- package/dist/commands/inspect_commands/snapshot.js +64 -0
- package/dist/commands/inspect_commands/status.js +68 -0
- package/dist/commands/inspect_commands/tree.js +86 -0
- package/dist/commands/newModule.js +10 -14
- package/dist/commands/profile.js +16 -0
- package/dist/commands/profile_commands/capture.js +106 -0
- package/dist/commands/skills.js +16 -0
- package/dist/commands/skills_commands/create.js +125 -0
- package/dist/commands/skills_commands/install.js +96 -0
- package/dist/commands/skills_commands/list.js +83 -0
- package/dist/commands/skills_commands/remove.js +41 -0
- package/dist/commands/skills_commands/update.js +59 -0
- package/dist/core/constants.js +0 -1
- package/dist/core/packageFiles.spec.js +29 -0
- package/dist/setup/versions.js +1 -1
- package/dist/utils/daemonClient.js +342 -0
- package/dist/utils/hermesClient.js +252 -0
- package/dist/utils/skillsAdapters.js +140 -0
- package/dist/utils/skillsRegistry.js +40 -0
- package/dist/utils/stringUtils.spec.js +1 -1
- package/package.json +20 -5
- package/.bazelignore +0 -2
- package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
- package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
- package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
- package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
- package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
- package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
- package/.config/copyconfig.json +0 -10
- package/.editorconfig +0 -21
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -72
- package/.github/README.md +0 -164
- package/.metadata/.cursorrules.template +0 -60
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -7
- package/LINUX_COMPATIBILITY.md +0 -248
- package/prettier.config.js +0 -4
- package/scripts/sync-agents-md.sh +0 -44
- package/scripts/update-agents-templates.ts +0 -170
- package/spec/support/jasmine.json +0 -6
- package/src/commands/bootstrap.ts +0 -410
- package/src/commands/build.ts +0 -89
- package/src/commands/devSetup.ts +0 -17
- package/src/commands/doctor.ts +0 -1832
- package/src/commands/export.ts +0 -131
- package/src/commands/hotreload.ts +0 -108
- package/src/commands/install.ts +0 -93
- package/src/commands/lint.ts +0 -15
- package/src/commands/lint_commands/lintCheck.ts +0 -53
- package/src/commands/lint_commands/lintFormat.ts +0 -49
- package/src/commands/log.ts +0 -108
- package/src/commands/newModule.ts +0 -286
- package/src/commands/package.ts +0 -102
- package/src/commands/projectsync.ts +0 -488
- package/src/commands/test.ts +0 -68
- package/src/core/constants.ts +0 -98
- package/src/core/errors.ts +0 -10
- package/src/index.ts +0 -27
- package/src/setup/DevSetupHelper.ts +0 -290
- package/src/setup/linuxSetup.ts +0 -261
- package/src/setup/macOSSetup.ts +0 -156
- package/src/setup/setupEntryPoint.ts +0 -64
- package/src/setup/versions.ts +0 -8
- package/src/utils/ArgumentsResolver.ts +0 -23
- package/src/utils/BazelClient.ts +0 -285
- package/src/utils/Digraph.ts +0 -81
- package/src/utils/LoadingIndicator.ts +0 -43
- package/src/utils/applicationUtils.ts +0 -276
- package/src/utils/buildInfo.ts +0 -99
- package/src/utils/byString.ts +0 -3
- package/src/utils/cliUtils.ts +0 -112
- package/src/utils/copyBootstrapFiles.ts +0 -30
- package/src/utils/deviceUtils.ts +0 -76
- package/src/utils/errorUtils.ts +0 -63
- package/src/utils/fileUtils.ts +0 -257
- package/src/utils/githubUtils.ts +0 -102
- package/src/utils/jsonUtils.ts +0 -30
- package/src/utils/lintUtils.ts +0 -190
- package/src/utils/linuxDistro.spec.ts +0 -219
- package/src/utils/linuxDistro.ts +0 -326
- package/src/utils/logUtils.ts +0 -9
- package/src/utils/pathUtils.ts +0 -12
- package/src/utils/stringUtils.spec.ts +0 -95
- package/src/utils/stringUtils.ts +0 -103
- package/src/utils/tempDir.ts +0 -24
- package/src/utils/zipUtils.ts +0 -14
- package/test/ValdiSmokeTest.ts +0 -279
- package/test/helpers/AsyncHelpers.ts +0 -113
- package/test/helpers/CommandHelpers.ts +0 -37
- package/test/helpers/ProjectHelpers.ts +0 -153
- package/test/helpers/StreamHelpers.ts +0 -37
- package/test/helpers/TypeScriptClient.ts +0 -217
- package/tsconfig.dist.json +0 -8
- package/tsconfig.json +0 -42
- /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/android/CalculatorModuleFactory.kt.template +0 -0
- /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/ios/SCCCalculatorModuleFactory.m.template +0 -0
- /package/.bootstrap/modules/{cpp_bridge_module → polyglot_bridge_module}/src/Calculator.d.ts +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// valdi-async skill reference — compile check for async lifecycle safety patterns.
|
|
2
|
+
// This file must compile cleanly against the Valdi TypeScript compiler.
|
|
3
|
+
// Run: bzl build //ai-skills/skills/valdi-async/tests:tests
|
|
4
|
+
|
|
5
|
+
import { StatefulComponent } from 'valdi_core/src/Component';
|
|
6
|
+
import { CancelablePromise, promiseToCancelablePromise } from 'valdi_core/src/CancelablePromise';
|
|
7
|
+
import { setTimeoutInterruptible } from 'valdi_core/src/SetTimeout';
|
|
8
|
+
import { HTTPClient } from 'valdi_http/src/HTTPClient';
|
|
9
|
+
import { HTTPResponse } from 'valdi_http/src/HTTPTypes';
|
|
10
|
+
|
|
11
|
+
// ─── HTTPClient: store, cancel in onDestroy, cancel before restart ────────────
|
|
12
|
+
|
|
13
|
+
interface UserProfileViewModel {
|
|
14
|
+
userId: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface UserProfileState {
|
|
18
|
+
user: { name: string } | null;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class UserProfile extends StatefulComponent<UserProfileViewModel, UserProfileState> {
|
|
23
|
+
state: UserProfileState = { user: null, loading: true };
|
|
24
|
+
|
|
25
|
+
private client = new HTTPClient('https://api.example.com');
|
|
26
|
+
private request?: CancelablePromise<HTTPResponse>;
|
|
27
|
+
|
|
28
|
+
onCreate(): void {
|
|
29
|
+
this.fetchUser(this.viewModel.userId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
onViewModelUpdate(previous?: UserProfileViewModel): void {
|
|
33
|
+
if (this.viewModel.userId !== previous?.userId) {
|
|
34
|
+
this.request?.cancel?.(); // Cancel in-flight before starting new one
|
|
35
|
+
this.fetchUser(this.viewModel.userId);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onDestroy(): void {
|
|
40
|
+
this.request?.cancel?.(); // Always clean up
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private fetchUser(id: string): void {
|
|
44
|
+
this.request = this.client.get(`/users/${id}`);
|
|
45
|
+
this.request.then(response => {
|
|
46
|
+
const user = JSON.parse(new TextDecoder().decode(response.body)) as { name: string };
|
|
47
|
+
this.setState({ user, loading: false });
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onRender(): void {
|
|
52
|
+
if (this.state.loading) {
|
|
53
|
+
<spinner />;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
<label value={this.state.user?.name ?? ''} />;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ─── registerDisposable: timers and subscriptions ────────────────────────────
|
|
61
|
+
|
|
62
|
+
interface ClockViewModel {
|
|
63
|
+
format: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface ClockState {
|
|
67
|
+
ticks: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class LiveClock extends StatefulComponent<ClockViewModel, ClockState> {
|
|
71
|
+
state: ClockState = { ticks: 0 };
|
|
72
|
+
|
|
73
|
+
onCreate(): void {
|
|
74
|
+
// ✅ Automatically cancelled on destroy — no onDestroy() needed
|
|
75
|
+
const id = setInterval(() => this.tick(), 1000);
|
|
76
|
+
this.registerDisposable({ cancel: () => clearInterval(id) });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private tick = (): void => {
|
|
80
|
+
this.setState({ ticks: this.state.ticks + 1 });
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
onRender(): void {
|
|
84
|
+
<label value={String(this.state.ticks)} />;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ─── isDestroyed() guard for plain Promises ──────────────────────────────────
|
|
89
|
+
|
|
90
|
+
declare function expensiveOperation(): Promise<string>;
|
|
91
|
+
|
|
92
|
+
interface DataState {
|
|
93
|
+
data: string | null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface DataViewModel {
|
|
97
|
+
query: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class DataLoader extends StatefulComponent<DataViewModel, DataState> {
|
|
101
|
+
state: DataState = { data: null };
|
|
102
|
+
|
|
103
|
+
onCreate(): void {
|
|
104
|
+
this.loadData().catch(() => {});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private async loadData(): Promise<void> {
|
|
108
|
+
const result = await expensiveOperation();
|
|
109
|
+
|
|
110
|
+
if (this.isDestroyed()) return; // Guard before setState
|
|
111
|
+
|
|
112
|
+
this.setState({ data: result });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
onRender(): void {
|
|
116
|
+
<label value={this.state.data ?? 'Loading…'} />;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ─── setTimeoutInterruptible for debounce ────────────────────────────────────
|
|
121
|
+
// setTimeoutInterruptible returns number (timer ID) — cancel with clearTimeout
|
|
122
|
+
|
|
123
|
+
interface SearchViewModel {
|
|
124
|
+
query: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface SearchState {
|
|
128
|
+
results: string[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class SearchBar extends StatefulComponent<SearchViewModel, SearchState> {
|
|
132
|
+
state: SearchState = { results: [] };
|
|
133
|
+
|
|
134
|
+
private debounceId?: number;
|
|
135
|
+
private searchRequest?: CancelablePromise<HTTPResponse>;
|
|
136
|
+
private client = new HTTPClient('https://api.example.com');
|
|
137
|
+
|
|
138
|
+
onViewModelUpdate(previous?: SearchViewModel): void {
|
|
139
|
+
if (this.viewModel.query !== previous?.query) {
|
|
140
|
+
clearTimeout(this.debounceId); // Cancel pending debounce
|
|
141
|
+
this.debounceId = setTimeoutInterruptible(() => {
|
|
142
|
+
this.fetchResults(this.viewModel.query);
|
|
143
|
+
}, 300);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
onDestroy(): void {
|
|
148
|
+
this.searchRequest?.cancel?.();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private fetchResults(query: string): void {
|
|
152
|
+
this.searchRequest?.cancel?.();
|
|
153
|
+
this.searchRequest = this.client.get(`/search?q=${encodeURIComponent(query)}`);
|
|
154
|
+
this.searchRequest.then(response => {
|
|
155
|
+
const data = JSON.parse(new TextDecoder().decode(response.body)) as { results: string[] };
|
|
156
|
+
this.setState({ results: data.results });
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
onRender(): void {
|
|
161
|
+
<scroll>
|
|
162
|
+
{this.state.results.forEach(result => {
|
|
163
|
+
<label key={result} value={result} />;
|
|
164
|
+
})}
|
|
165
|
+
</scroll>;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ─── promiseToCancelablePromise ──────────────────────────────────────────────
|
|
170
|
+
|
|
171
|
+
declare function thirdPartyFetch(url: string): Promise<string>;
|
|
172
|
+
|
|
173
|
+
interface FetchState {
|
|
174
|
+
content: string | null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
interface FetchViewModel {
|
|
178
|
+
url: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
class ThirdPartyFetcher extends StatefulComponent<FetchViewModel, FetchState> {
|
|
182
|
+
state: FetchState = { content: null };
|
|
183
|
+
|
|
184
|
+
private request?: CancelablePromise<string>;
|
|
185
|
+
|
|
186
|
+
onCreate(): void {
|
|
187
|
+
const rawPromise = thirdPartyFetch(this.viewModel.url);
|
|
188
|
+
this.request = promiseToCancelablePromise(rawPromise, () => {
|
|
189
|
+
// optional cleanup on cancel
|
|
190
|
+
});
|
|
191
|
+
this.request.then(content => {
|
|
192
|
+
if (this.isDestroyed()) return;
|
|
193
|
+
this.setState({ content });
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
onDestroy(): void {
|
|
198
|
+
this.request?.cancel?.();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
onRender(): void {
|
|
202
|
+
<label value={this.state.content ?? ''} />;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
void UserProfile;
|
|
207
|
+
void LiveClock;
|
|
208
|
+
void DataLoader;
|
|
209
|
+
void SearchBar;
|
|
210
|
+
void ThirdPartyFetcher;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"extends": "../../../../src/valdi_modules/src/valdi/_configs/base.tsconfig.json"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Bazel Build System Rules
|
|
2
|
+
|
|
3
|
+
**Applies to**: `BUILD.bazel`, `*.bzl` files in `/bzl/`, `WORKSPACE`, `MODULE.bazel`
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Valdi uses Bazel as its build system. Bazel provides reproducible, incremental builds across all platforms.
|
|
8
|
+
|
|
9
|
+
## Key Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Build everything
|
|
13
|
+
bazel build //...
|
|
14
|
+
|
|
15
|
+
# Build specific target
|
|
16
|
+
bazel build //apps/helloworld:helloworld
|
|
17
|
+
|
|
18
|
+
# Run tests
|
|
19
|
+
bazel test //...
|
|
20
|
+
|
|
21
|
+
# Clean (use sparingly - cache is valuable!)
|
|
22
|
+
bazel clean
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Important Notes
|
|
26
|
+
|
|
27
|
+
1. **Use `bazel`** for all build commands
|
|
28
|
+
2. **The CLI wraps Bazel** - `valdi` commands use bazel under the hood
|
|
29
|
+
3. **Cache is important** - Don't suggest `bazel clean` unless necessary
|
|
30
|
+
|
|
31
|
+
## Build Rules
|
|
32
|
+
|
|
33
|
+
### Valdi-Specific Rules
|
|
34
|
+
|
|
35
|
+
- `/bzl/valdi/` - Valdi build rules and macros
|
|
36
|
+
- Custom rules for compiling .tsx to .valdimodule
|
|
37
|
+
- Platform-specific build transitions
|
|
38
|
+
|
|
39
|
+
### Common Targets
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
|
|
43
|
+
|
|
44
|
+
# Valdi application
|
|
45
|
+
valdi_application(
|
|
46
|
+
name = "my_app",
|
|
47
|
+
root_component_path = "App@my_app/src/MyApp",
|
|
48
|
+
title = "My App",
|
|
49
|
+
version = "1.0.0",
|
|
50
|
+
deps = ["//apps/my_app/src/valdi/my_app"],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Web polyglot views — MUST be ts_project, never filegroup
|
|
54
|
+
ts_project(
|
|
55
|
+
name = "my_module_web",
|
|
56
|
+
srcs = glob(
|
|
57
|
+
["web/**/*.ts", "src/**/*.d.ts"],
|
|
58
|
+
exclude = ["web/**/*.d.ts"],
|
|
59
|
+
),
|
|
60
|
+
allow_js = True,
|
|
61
|
+
composite = True,
|
|
62
|
+
transpiler = "tsc",
|
|
63
|
+
tsconfig = "web/tsconfig.json",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# Valdi module with platform deps
|
|
67
|
+
valdi_module(
|
|
68
|
+
name = "my_module",
|
|
69
|
+
srcs = glob(["src/**/*.ts", "src/**/*.tsx"]) + ["tsconfig.json"],
|
|
70
|
+
ios_deps = [":my_ios_views"], # objc_library
|
|
71
|
+
macos_deps = [":my_macos_views"], # objc_library (or omit to share ios_deps)
|
|
72
|
+
android_deps = [":my_android_views"], # valdi_android_library
|
|
73
|
+
web_deps = [":my_module_web"], # ts_project (never filegroup)
|
|
74
|
+
deps = [
|
|
75
|
+
"//src/valdi_modules/src/valdi/valdi_core",
|
|
76
|
+
],
|
|
77
|
+
)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Conventions
|
|
81
|
+
|
|
82
|
+
### File Naming
|
|
83
|
+
|
|
84
|
+
- `BUILD.bazel` not `BUILD` (explicit extension)
|
|
85
|
+
- `.bzl` for Starlark macros and rules
|
|
86
|
+
|
|
87
|
+
### Targets
|
|
88
|
+
|
|
89
|
+
- Use descriptive target names
|
|
90
|
+
- One main target per BUILD file usually matches directory name
|
|
91
|
+
|
|
92
|
+
### Dependencies
|
|
93
|
+
|
|
94
|
+
- Be explicit about dependencies
|
|
95
|
+
- Don't rely on transitive deps implicitly
|
|
96
|
+
- Use visibility to control access
|
|
97
|
+
|
|
98
|
+
## Platform Builds
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Build and install iOS app
|
|
102
|
+
valdi install ios
|
|
103
|
+
|
|
104
|
+
# Build and install Android app
|
|
105
|
+
valdi install android
|
|
106
|
+
|
|
107
|
+
# Or use bazel directly with configs
|
|
108
|
+
bazel build //apps/helloworld:hello_world --config=ios
|
|
109
|
+
bazel build //apps/helloworld:hello_world --config=android
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Configuration
|
|
113
|
+
|
|
114
|
+
- `.bazelrc` - Build flags and configurations
|
|
115
|
+
- `MODULE.bazel` - Bazel module dependencies
|
|
116
|
+
- `WORKSPACE` - Legacy workspace configuration (being migrated to MODULE.bazel)
|
|
117
|
+
|
|
118
|
+
## Common Issues
|
|
119
|
+
|
|
120
|
+
1. **Missing dependencies** - Add to `deps` in BUILD.bazel
|
|
121
|
+
2. **Cache issues** - Try `bazel clean --expunge` (last resort)
|
|
122
|
+
3. **Platform transitions** - Use correct config flags
|
|
123
|
+
|
|
124
|
+
## Testing
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Run all tests
|
|
128
|
+
bazel test //...
|
|
129
|
+
|
|
130
|
+
# Run specific test
|
|
131
|
+
bazel test //valdi/test:renderer_test
|
|
132
|
+
|
|
133
|
+
# Run with coverage
|
|
134
|
+
bazel coverage //...
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## More Information
|
|
138
|
+
|
|
139
|
+
- Bazel docs: https://bazel.build
|
|
140
|
+
- Valdi build rules: `/bzl/valdi/README.md`
|
|
141
|
+
- Framework docs: `/AGENTS.md`
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Valdi Compiler Rules
|
|
2
|
+
|
|
3
|
+
**Applies to**: Swift files in `/compiler/compiler/`
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Valdi compiler consists of two parts:
|
|
8
|
+
|
|
9
|
+
1. **Compiler (Swift)**: Transforms TypeScript/TSX into `.valdimodule` files
|
|
10
|
+
2. **Companion (TypeScript/Node.js)**: Handles TypeScript compilation, type checking, and provides debugging support
|
|
11
|
+
|
|
12
|
+
## Key Conventions
|
|
13
|
+
|
|
14
|
+
### Code Style
|
|
15
|
+
|
|
16
|
+
- **4-space indentation** for Swift
|
|
17
|
+
- Follow Swift naming conventions (camelCase for methods, PascalCase for types)
|
|
18
|
+
- Use Swift type inference where appropriate
|
|
19
|
+
- Prefer `let` over `var` when possible
|
|
20
|
+
|
|
21
|
+
### Architecture
|
|
22
|
+
|
|
23
|
+
- Compiler is a multi-pass system
|
|
24
|
+
- AST transformation pipeline
|
|
25
|
+
- Type checking and validation
|
|
26
|
+
- Code generation for each platform
|
|
27
|
+
|
|
28
|
+
### Important Files
|
|
29
|
+
|
|
30
|
+
- `/compiler/compiler/` - Main Swift compiler implementation
|
|
31
|
+
- Output: `.valdimodule` files (binary format read by runtime)
|
|
32
|
+
|
|
33
|
+
## Common Patterns
|
|
34
|
+
|
|
35
|
+
### AST Traversal
|
|
36
|
+
|
|
37
|
+
```swift
|
|
38
|
+
// Follow existing visitor patterns
|
|
39
|
+
class MyASTVisitor: ASTVisitor {
|
|
40
|
+
func visit(_ node: Node) -> Result {
|
|
41
|
+
// Visit logic
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Error Handling
|
|
47
|
+
|
|
48
|
+
```swift
|
|
49
|
+
// Use proper error types
|
|
50
|
+
enum CompilerError: Error {
|
|
51
|
+
case invalidSyntax(String)
|
|
52
|
+
case typeError(String)
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Testing
|
|
57
|
+
|
|
58
|
+
Tests are critical - add tests for new features and error cases. The `update_compiler.sh` script runs tests automatically.
|
|
59
|
+
|
|
60
|
+
## Build
|
|
61
|
+
|
|
62
|
+
### Using the update script (recommended):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
cd compiler/compiler
|
|
66
|
+
./scripts/update_compiler.sh ../../bin/compiler
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
This script:
|
|
70
|
+
- Runs `swift test` automatically
|
|
71
|
+
- Builds the compiler for the correct architecture
|
|
72
|
+
- Copies the binary to `bin/compiler/macos/valdi_compiler` (or `linux/valdi_compiler`)
|
|
73
|
+
- Handles platform differences (macOS vs Linux)
|
|
74
|
+
|
|
75
|
+
### Alternative: Using Xcode
|
|
76
|
+
|
|
77
|
+
Open `compiler/compiler/Compiler/Package.swift` in Xcode, let it resolve dependencies, then build.
|
|
78
|
+
|
|
79
|
+
## Companion (TypeScript)
|
|
80
|
+
|
|
81
|
+
The companion is a TypeScript service that works alongside the Swift compiler. It handles TypeScript compilation, type checking, and provides debugging support.
|
|
82
|
+
|
|
83
|
+
### Build the companion:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
cd compiler/companion
|
|
87
|
+
./scripts/update_companion.sh ../../bin/compiler_companion
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This script:
|
|
91
|
+
- Runs `npm install`
|
|
92
|
+
- Runs `npm run test`
|
|
93
|
+
- Builds with `bazel build //compiler/companion:bundle`
|
|
94
|
+
- Copies output to `bin/compiler_companion`
|
|
95
|
+
|
|
96
|
+
**Note**: Once built, the companion is automatically invoked by the compiler during compilation. You don't need to run it manually - it's part of the compiler process.
|
|
97
|
+
|
|
98
|
+
## Important Notes
|
|
99
|
+
|
|
100
|
+
1. **Performance matters** - Compiler speed affects developer experience
|
|
101
|
+
2. **Error messages** - Make them helpful and actionable
|
|
102
|
+
3. **Backward compatibility** - Don't break existing .valdimodule files
|
|
103
|
+
4. **Cross-platform** - Consider iOS, Android, macOS targets
|
|
104
|
+
|
|
105
|
+
## More Information
|
|
106
|
+
|
|
107
|
+
- Compiler architecture: `/compiler/compiler/README.md`
|
|
108
|
+
- Framework docs: `/AGENTS.md`
|