diff --git a/.bazelrc b/.bazelrc index 22d39f0..329926a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -81,5 +81,11 @@ build --experimental_reuse_sandbox_directories # Valdi Open Source Flags build --define=open_source_build=true +build --flag_alias=valdi_js_engine=@valdi//bzl/valdi:js_engine -build --android_crosstool_top="@snap_client_toolchains//:android_crosstool" \ No newline at end of file +# Enable web compilation (generates JS outputs from Valdi compiler for web targets) +common --define=enable_web=true + +build --android_crosstool_top="@snap_client_toolchains//:android_crosstool" +# Web build configuration (used by scripts/bazel_web_serve.sh) +build:web --build_tag_filters=web diff --git a/.cursor/rules/README.md b/.cursor/rules/README.md deleted file mode 100644 index c802020..0000000 --- a/.cursor/rules/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Cursor Rules for Valdi Widgets - -Context-specific rules for AI assistants in this repo. Valdi Widgets is TypeScript/TSX + Bazel; it depends on [Valdi](https://github.com/Snapchat/Valdi) via `WORKSPACE`. - -## How Cursor Rules Work - -Rules load based on what you're editing: - -- `valdi_modules/**/*.ts`, `valdi_modules/**/*.tsx` → **typescript-tsx.md** -- `**/BUILD.bazel`, `**/*.bzl`, `WORKSPACE` → **bazel.md** -- `**/test/**/*.ts`, `**/*.spec.ts` → **testing.md** - -## Rules - -| File | Applies To | Description | -|------|-----------|-------------| -| `typescript-tsx.md` | `valdi_modules/**/*.ts`, `valdi_modules/**/*.tsx` | Valdi component patterns, anti-React warnings | -| `bazel.md` | `**/BUILD.bazel`, `**/*.bzl`, `WORKSPACE` | Bazel conventions | -| `testing.md` | `**/test/**/*.ts`, `**/*.spec.ts` | Testing (Jasmine) | - -## More - -- Valdi: https://github.com/Snapchat/Valdi -- Repo README: `/README.md` diff --git a/.cursor/rules/bazel.md b/.cursor/rules/bazel.md deleted file mode 100644 index dafd9b8..0000000 --- a/.cursor/rules/bazel.md +++ /dev/null @@ -1,54 +0,0 @@ -# Bazel Build System Rules - -**Applies to**: `BUILD.bazel`, `*.bzl` files, `WORKSPACE` - -## Overview - -Valdi Widgets uses Bazel as its build system, with Valdi as an external dependency (`@valdi//...`). - -## Key Commands - -```bash -# Build macOS app -bazel build //valdi_modules/playground:app_macos - -# Run tests -bazel test //valdi_modules/widgets:test //valdi_modules/navigation:test //valdi_modules/valdi_standalone_ui:test - -# Build specific module -bazel build //valdi_modules/widgets:widgets -``` - -## Valdi Dependency - -- Valdi is loaded via `http_archive` in WORKSPACE (release tag, e.g. `beta-0.0.2`). -- Valdi build rules live in `@valdi//bzl/valdi/`. -- Custom rules: `valdi_module`, `valdi_application` (from Valdi). - -## Conventions - -### File Naming - -- `BUILD.bazel` not `BUILD` (explicit extension) -- `.bzl` for Starlark macros and rules - -### Targets - -- Use descriptive target names -- One main target per BUILD file usually matches directory name - -### Dependencies - -- Be explicit about dependencies -- Use `@valdi//...` for Valdi module deps (e.g. `@valdi//src/valdi_modules/src/valdi/valdi_core`) -- Use visibility to control access - -## Configuration - -- `.bazelrc` – Build flags and configurations -- `WORKSPACE` – Workspace and repository configuration - -## More Information - -- Bazel docs: https://bazel.build -- Valdi: https://github.com/Snapchat/Valdi diff --git a/.cursor/rules/testing.md b/.cursor/rules/testing.md deleted file mode 100644 index 95af340..0000000 --- a/.cursor/rules/testing.md +++ /dev/null @@ -1,58 +0,0 @@ -# Testing Rules - -**Applies to**: Test files in `**/test/`, `**/*.spec.ts`, `**/*.test.ts` - -## Overview - -Valdi Widgets uses the same testing approach as Valdi: Jasmine for TypeScript/component tests. - -## Test Framework - -### Jasmine for TypeScript Tests - -```typescript -import 'jasmine/src/jasmine'; -import { Component } from 'valdi_core/src/Component'; - -describe('MyComponent', () => { - it('should render correctly', () => { - const component = new MyComponent(); - expect(component).toBeDefined(); - }); - - it('should handle state updates', () => { - const component = new MyStatefulComponent(); - component.setState({ count: 1 }); - expect(component.state.count).toBe(1); - }); -}); -``` - -Test files use `.spec.ts` and live under `test/` in each module. - -## Running Tests - -```bash -# Run Valdi Widgets tests -bazel test //valdi_modules/widgets:test //valdi_modules/navigation:test //valdi_modules/valdi_standalone_ui:test //valdi_modules/navigation_internal:test - -# With output -bazel test //valdi_modules/...:test --test_output=errors -``` - -## Test Conventions - -- `*.spec.ts` or `*.test.ts` for unit tests -- `test/` directory per module -- Test file should mirror source file name - -## Important - -1. **Test behavior, not implementation** -2. **Isolate tests** – Each test independent -3. **Mock dependencies** when appropriate -4. **Use this.setTimeoutDisposable()** in component code; avoid raw setTimeout/setInterval in tests when testing components - -## More Information - -- Valdi testing: https://github.com/Snapchat/Valdi diff --git a/.cursor/rules/typescript-tsx.md b/.cursor/rules/typescript-tsx.md deleted file mode 100644 index 4b84496..0000000 --- a/.cursor/rules/typescript-tsx.md +++ /dev/null @@ -1,106 +0,0 @@ -# Valdi TypeScript/TSX Component Rules - -**Applies to**: TypeScript and TSX files in `valdi_modules/**/*.ts`, `valdi_modules/**/*.tsx` - -## 🚨 CRITICAL: Valdi is NOT React! - -**AI assistants frequently suggest React patterns that DON'T EXIST in Valdi.** Despite using TSX/JSX syntax, Valdi compiles to native code. - -### Most Common Mistakes - -```typescript -// ❌ NEVER use React hooks (don't exist!) -const [count, setCount] = useState(0); // ❌ -useEffect(() => { ... }, []); // ❌ - -// ❌ NEVER use functional components (don't exist!) -const MyComponent = () => ; // ❌ - -// ❌ Common hallucinations -this.props.title; // Should be: this.viewModel.title -this.markNeedsRender(); // Doesn't exist! Use setState() -onMount() { } // Should be: onCreate() -return ; // onRender() returns void! -``` - -### ✅ Correct Valdi Patterns - -```typescript -import { StatefulComponent } from 'valdi_core/src/Component'; - -class MyComponent extends StatefulComponent { - state = { count: 0 }; - - onCreate() { } // Component created - onViewModelUpdate(prev: ViewModel) { } // Props changed - onDestroy() { } // Before removal - - handleClick = () => { - this.setState({ count: this.state.count + 1 }); // Auto re-renders - }; - - onRender() { // Returns void, not JSX! -