Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,46 @@ jobs:

- name: Test (each package runs its own complete suite)
run: pnpm -r run test

ecs:
# ecs/ is also a workspace of its own, with its own lockfile, which is how it's developed and published. The job
# above builds its packages with this workspace's lockfile; this one builds them with ecs/'s, so a tool resolved
# differently there can't break its build unseen. The convention check above keeps the two lockfiles' tools alike.
name: ecs workspace · typecheck · lint · build · test
runs-on: ubuntu-latest
defaults:
run:
working-directory: ecs
steps:
- uses: actions/checkout@v6

- uses: pnpm/action-setup@v6
with:
package_json_file: ecs/package.json

- uses: actions/setup-node@v6
with:
node-version-file: ecs/.nvmrc
cache: pnpm
cache-dependency-path: ecs/pnpm-lock.yaml

- run: pnpm install --frozen-lockfile

- name: Check workspace conventions
run: pnpm run check:workspace

- name: Type-check (every package, topological)
run: pnpm -r run typecheck

# A plain recursive run fails where no package defines the script, as none here lints yet; any that does is checked.
- name: Lint (every package that defines it)
run: pnpm -r --if-present run lint

- name: API docs (every package that defines them; warnings fail)
run: pnpm -r --if-present run docs

- name: Build (every package, topological)
run: pnpm -r run build

- name: Test (each package runs its own complete suite)
run: pnpm -r run test
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ explicitly — an absent `private` means "publishable" to npm, which we forbid s
nothing ships by accident. `scripts/check-workspace-conventions.mjs` (run in CI
via `pnpm run check:workspace`) enforces both rules.

`ecs/` is also a workspace of its own, with its own lockfile. Every package it
lists is listed in this `pnpm-workspace.yaml` too, the tools both build with are
pinned alike in both files' `overrides`, and both lockfiles must resolve them to
the same versions; the convention check enforces all three, and CI's `ecs` job
builds and tests `ecs/` with its own lockfile.

To make a package publishable, set `private: false`; to hold it back, set
`private: true`. That one field is the single source of truth — there is no list
to update anywhere else.
1 change: 1 addition & 0 deletions ecs/.claude/rules/ecs/component._.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ paths:
<!-- Written by `ecs-architecture agents` from the rules of @adobe/ecs-architecture and @adobe/ecs: run it again, never edit. -->

- The file exports the key alone: a top-level `Symbol()` constant, its traits declared beside it in `declare module "@adobe/ecs" { interface Components { ... } }`.
- Treat its value as immutable, changed by row assignment or `commands`: an object or array value is `readonly` throughout and replaced, since a change in place goes unseen. A handle to what's outside the world, such as an element, is mutable by nature; keep the state that matters in the world.
- A key is a top-level `Symbol()` with no description, its traits declared beside it: `declare module "@adobe/ecs" { interface Components { [title]: { type: string } } }`.
- An entity reference is a component of its own, `type: Entity` with `reference: "owner"` or `"weak"`, never a field of a struct. A DOM object is `thread: "main"`.
- A derived component, `derived: true`, is defined in its own file by `Component.derive(key, { from, not })`: it's on exactly the entities some derivation of it matches, and nothing else adds or removes it.
3 changes: 3 additions & 0 deletions ecs/.claude/rules/ecs/resource._.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ paths:
<!-- Written by `ecs-architecture agents` from the rules of @adobe/ecs-architecture and @adobe/ecs: run it again, never edit. -->

- The file exports the key alone: a top-level `Symbol()` constant, its traits declared beside it in `declare module "@adobe/ecs" { interface Resources { ... } }`.
- Treat its value as immutable, `readonly` throughout, and change it by assigning a new one, `resources[key] = next`, when it differs: that's what `changed: [key]` sees, and a change in place goes unseen.
- A handle to what's outside the world, such as an element, canvas or GPU device, is mutable by nature; keep the state that matters in the world, and write it to the handle.
- Mutate for performance only where a benchmark shows the need, keeping it private to the system, or the few closely related systems or the feature, that use it.
- A key is a top-level `Symbol()` with no description, its traits declared beside it: `declare module "@adobe/ecs" { interface Resources { [filter]: { type: Filter; default: "all" } } }`.
- A resource a system waits for is typed `T | null` and read with `resources: { is: [key] }`. A DOM object is `thread: "main"`.
1 change: 1 addition & 0 deletions ecs/.claude/rules/ecs/system._.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ paths:
- The world reaches it only if something in the source lists it: its layer's plugin's `systems`, a composite, or `world.run`/`world.add`; a test doesn't count. A layer's root holds only systems others add, run or order against; the rest are parts of their plugin, in `plugin.<feature>-<layer>/`, or of a composite, in `system.<name>/`.
- A model system never names a view system: put the `before`/`after` on the view system, or order both against a phase.
- A changes or removed system is typed `System<never>`, which `run` never takes; compose it with the system making what it reacts to.
- Prefer pure functions and immutable values: change a component or resource by assigning a new value rather than changing an object or array read from one in place, which change filters can't see; handles, such as elements, are the usual exception. Small values are cheap to replace, and the compiler avoids allocating where it can, so mutate for speed only where a benchmark shows the need.
- Read entities with a query (`components: { with, not }`). Define an `Index` only to look up by key, or to read a set from inside another system's body: every structural change updates it.
- A system that only reads is `readonly: true`; `changed: [x]` skips rows whose `x` didn't change, `resources: { is: [r] }` waits for a resource.
- Spawn, despawn, add and remove through `commands`; they apply at the next sync point. Order systems with `before`, `after` and `during`, never by list position.
Expand Down
1 change: 1 addition & 0 deletions ecs/.claude/rules/ecs/view/_.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ paths:
- The view renders the model, binding the DOM or drawing, and connects this feature's widgets: it imports `model`, `elements` and `view`, never `ports`.
- Order its systems against the model's with their own `before`/`after`; the model never names them.
- It finds the fixed elements it drives with a system of its own, from the app's root element, a resource, and exports its plugin, `plugin.<feature>-view.ts`.
- Prefer WebGPU, through `@adobe/ecs-gpu` and render systems (`System.render`), to WebGL and other older APIs: a render system draws from the GPU copy of the components it names, which the world uploads straight from storage as rows change.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ applyTo: "**/component.*.ts"
<!-- Written by `ecs-architecture agents` from the rules of @adobe/ecs-architecture and @adobe/ecs: run it again, never edit. -->

- The file exports the key alone: a top-level `Symbol()` constant, its traits declared beside it in `declare module "@adobe/ecs" { interface Components { ... } }`.
- Treat its value as immutable, changed by row assignment or `commands`: an object or array value is `readonly` throughout and replaced, since a change in place goes unseen. A handle to what's outside the world, such as an element, is mutable by nature; keep the state that matters in the world.
- A key is a top-level `Symbol()` with no description, its traits declared beside it: `declare module "@adobe/ecs" { interface Components { [title]: { type: string } } }`.
- An entity reference is a component of its own, `type: Entity` with `reference: "owner"` or `"weak"`, never a field of a struct. A DOM object is `thread: "main"`.
- A derived component, `derived: true`, is defined in its own file by `Component.derive(key, { from, not })`: it's on exactly the entities some derivation of it matches, and nothing else adds or removes it.
3 changes: 3 additions & 0 deletions ecs/.github/instructions/ecs/resource._.ts.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ applyTo: "**/resource.*.ts"
<!-- Written by `ecs-architecture agents` from the rules of @adobe/ecs-architecture and @adobe/ecs: run it again, never edit. -->

- The file exports the key alone: a top-level `Symbol()` constant, its traits declared beside it in `declare module "@adobe/ecs" { interface Resources { ... } }`.
- Treat its value as immutable, `readonly` throughout, and change it by assigning a new one, `resources[key] = next`, when it differs: that's what `changed: [key]` sees, and a change in place goes unseen.
- A handle to what's outside the world, such as an element, canvas or GPU device, is mutable by nature; keep the state that matters in the world, and write it to the handle.
- Mutate for performance only where a benchmark shows the need, keeping it private to the system, or the few closely related systems or the feature, that use it.
- A key is a top-level `Symbol()` with no description, its traits declared beside it: `declare module "@adobe/ecs" { interface Resources { [filter]: { type: Filter; default: "all" } } }`.
- A resource a system waits for is typed `T | null` and read with `resources: { is: [key] }`. A DOM object is `thread: "main"`.
1 change: 1 addition & 0 deletions ecs/.github/instructions/ecs/system._.ts.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ applyTo: "**/system.*.ts"
- The world reaches it only if something in the source lists it: its layer's plugin's `systems`, a composite, or `world.run`/`world.add`; a test doesn't count. A layer's root holds only systems others add, run or order against; the rest are parts of their plugin, in `plugin.<feature>-<layer>/`, or of a composite, in `system.<name>/`.
- A model system never names a view system: put the `before`/`after` on the view system, or order both against a phase.
- A changes or removed system is typed `System<never>`, which `run` never takes; compose it with the system making what it reacts to.
- Prefer pure functions and immutable values: change a component or resource by assigning a new value rather than changing an object or array read from one in place, which change filters can't see; handles, such as elements, are the usual exception. Small values are cheap to replace, and the compiler avoids allocating where it can, so mutate for speed only where a benchmark shows the need.
- Read entities with a query (`components: { with, not }`). Define an `Index` only to look up by key, or to read a set from inside another system's body: every structural change updates it.
- A system that only reads is `readonly: true`; `changed: [x]` skips rows whose `x` didn't change, `resources: { is: [r] }` waits for a resource.
- Spawn, despawn, add and remove through `commands`; they apply at the next sync point. Order systems with `before`, `after` and `during`, never by list position.
Expand Down
1 change: 1 addition & 0 deletions ecs/.github/instructions/ecs/view/_.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ applyTo: "**/view/**"
- The view renders the model, binding the DOM or drawing, and connects this feature's widgets: it imports `model`, `elements` and `view`, never `ports`.
- Order its systems against the model's with their own `before`/`after`; the model never names them.
- It finds the fixed elements it drives with a system of its own, from the app's root element, a resource, and exports its plugin, `plugin.<feature>-view.ts`.
- Prefer WebGPU, through `@adobe/ecs-gpu` and render systems (`System.render`), to WebGL and other older APIs: a render system draws from the GPU copy of the components it names, which the world uploads straight from storage as rows change.
5 changes: 3 additions & 2 deletions ecs/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ jobs:
- name: Type-check (every package, topological)
run: pnpm -r run typecheck

# A plain recursive run fails where no package defines the script, as none here lints yet; any that does is checked.
- name: Lint (every package that defines it)
run: pnpm -r run lint
run: pnpm -r --if-present run lint

- name: Build (every package, topological)
run: pnpm -r run build

- name: API docs (every package that defines them; warnings fail)
run: pnpm -r run docs
run: pnpm -r --if-present run docs

- name: Test (each package runs its own complete suite)
run: pnpm -r run test
10 changes: 8 additions & 2 deletions ecs/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ circular-await chain and the bundled graph deadlocks silently, while native ESM

The root and CI never name individual packages. They invoke uniform recursive scripts (`pnpm -r run <script>`), which
pnpm runs in dependency order and skips for packages that don't define the script. Each package owns *how* it does each
step, so a new package needs no edit to any central list but `pnpm-workspace.yaml`, which lists packages explicitly.
step, so a new package needs no edit to any central list but `pnpm-workspace.yaml`, which lists packages explicitly:
both this workspace's and the repository root's, whose CI builds and tests it with the root's lockfile as well as this
one's. The tools both workspaces build with are pinned alike in both files' `overrides`; the root's
`scripts/check-workspace-conventions.mjs` checks the lists, the pins and both lockfiles agree.

Standard script names a package may define:

Expand All @@ -69,7 +72,10 @@ Standard script names a package may define:
- **`test`**: run the package's *complete* suite, self-contained and runnable in CI. A package that needs a browser
installs and drives it itself. Keep long or optional lanes under suffixed names (`test:perf`) that CI doesn't call.
- **`lint`**: lint the package.
- **`dev`**: local dev or watch.
- **`dev`**: local dev or watch. A page served from the workspace's packages builds them first, as they're served
from their `dist`, which a failed build leaves stale: `test -n "$ECS_DEPENDENCIES_BUILT" || pnpm --filter
"$npm_package_name^..." run build && vite`, so a build error stops it. The workspace's `dev` builds them once and
sets `ECS_DEPENDENCIES_BUILT`; `scripts/check-workspace-conventions.mjs` checks every such `dev`.
- **`docs`**: generate the package's documentation (typedoc). What a package publishes to the GitHub Pages site is
its `pages` field: a list of `{ "from", "to" }`, a folder of the package and its path on the site (`"."` for the
root). The docs workflow runs `pnpm -r run build` and `pnpm -r run docs`, then `scripts/collect-pages.mjs` copies
Expand Down
2 changes: 1 addition & 1 deletion ecs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint": "pnpm -r run lint",
"typecheck": "pnpm -r run typecheck",
"docs": "pnpm -r run docs",
"dev": "pnpm -r --parallel run dev",
"dev": "pnpm --filter \"@adobe/*\" run build && ECS_DEPENDENCIES_BUILT=1 pnpm -r --parallel run dev",
"check:workspace": "node scripts/check-workspace-conventions.mjs && node --test 'scripts/*.test.mjs'",
"publish": "sh -c 'for x in \"$@\"; do OTP=\"$x\"; done; export NPM_CONFIG_OTP=\"$OTP\"; pnpm -r run build && pnpm -r publish --no-git-checks --access public' sh"
},
Expand Down
1 change: 1 addition & 0 deletions ecs/packages/ecs-architecture/rules/component.x.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
glob: "**/component.*.ts"
---
- The file exports the key alone: a top-level `Symbol()` constant, its traits declared beside it in `declare module "@adobe/ecs" { interface Components { ... } }`.
- Treat its value as immutable, changed by row assignment or `commands`: an object or array value is `readonly` throughout and replaced, since a change in place goes unseen. A handle to what's outside the world, such as an element, is mutable by nature; keep the state that matters in the world.
3 changes: 3 additions & 0 deletions ecs/packages/ecs-architecture/rules/resource.x.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
glob: "**/resource.*.ts"
---
- The file exports the key alone: a top-level `Symbol()` constant, its traits declared beside it in `declare module "@adobe/ecs" { interface Resources { ... } }`.
- Treat its value as immutable, `readonly` throughout, and change it by assigning a new one, `resources[key] = next`, when it differs: that's what `changed: [key]` sees, and a change in place goes unseen.
- A handle to what's outside the world, such as an element, canvas or GPU device, is mutable by nature; keep the state that matters in the world, and write it to the handle.
- Mutate for performance only where a benchmark shows the need, keeping it private to the system, or the few closely related systems or the feature, that use it.
1 change: 1 addition & 0 deletions ecs/packages/ecs-architecture/rules/system.x.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ glob: "**/system.*.ts"
- The world reaches it only if something in the source lists it: its layer's plugin's `systems`, a composite, or `world.run`/`world.add`; a test doesn't count. A layer's root holds only systems others add, run or order against; the rest are parts of their plugin, in `plugin.<feature>-<layer>/`, or of a composite, in `system.<name>/`.
- A model system never names a view system: put the `before`/`after` on the view system, or order both against a phase.
- A changes or removed system is typed `System<never>`, which `run` never takes; compose it with the system making what it reacts to.
- Prefer pure functions and immutable values: change a component or resource by assigning a new value rather than changing an object or array read from one in place, which change filters can't see; handles, such as elements, are the usual exception. Small values are cheap to replace, and the compiler avoids allocating where it can, so mutate for speed only where a benchmark shows the need.
1 change: 1 addition & 0 deletions ecs/packages/ecs-architecture/rules/view.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ glob: "**/view/**"
- The view renders the model, binding the DOM or drawing, and connects this feature's widgets: it imports `model`, `elements` and `view`, never `ports`.
- Order its systems against the model's with their own `before`/`after`; the model never names them.
- It finds the fixed elements it drives with a system of its own, from the app's root element, a resource, and exports its plugin, `plugin.<feature>-view.ts`.
- Prefer WebGPU, through `@adobe/ecs-gpu` and render systems (`System.render`), to WebGL and other older APIs: a render system draws from the GPU copy of the components it names, which the world uploads straight from storage as rows change.
11 changes: 11 additions & 0 deletions ecs/packages/ecs-architecture/standard.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,18 @@ feature, and of its sub-features, import them, and they add no systems to an app
- **Persist only independent data;** derived data is derived again on load.
- **Read with a query,** not an `Index`, unless the system looks up by key or reads a set from inside another system.
- **Commands,** not row assignment, for anything a changes system must see.
- **Prefer pure functions and immutable values.** Keep a component's or resource's value `readonly` throughout and
change it by assignment or `commands`, which is what change filters, changes systems, persistence and other threads
see; a change in place goes unseen. Mutate only where you must: a *handle* to what's outside the world, such as an
element, canvas or GPU device, mutable by nature, where the state that matters is best kept in the world and written
to it; or for performance a benchmark shows is needed, kept private to the system, or the few closely related systems
or the feature, using it. A mutable pattern that's faster in general is a finding about the ECS, to design for: the
aim is to stay semantically immutable and gain its speed underneath, as compiled systems do, assigning new tuples in
source and allocating none.
- **Hot paths allocate nothing per frame,** and have a benchmark.
- **Prefer WebGPU for drawing,** through `@adobe/ecs-gpu` and render systems, to WebGL and other older APIs: a render
system draws from the GPU copy of the components it names, which the world uploads straight from storage as rows
change, with no copy of its own.

## Configuration

Expand Down
2 changes: 1 addition & 1 deletion ecs/packages/ecs-gpu-views/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"private": true,
"scripts": {
"build": "tsc && vite build",
"dev": "vite",
"dev": "test -n \"$ECS_DEPENDENCIES_BUILT\" || pnpm --filter \"$npm_package_name^...\" run build && vite",
"typecheck": "tsc",
"test": "vitest --run"
},
Expand Down
2 changes: 1 addition & 1 deletion ecs/packages/ecs-guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"private": true,
"scripts": {
"build": "tsc && vite build",
"dev": "vite",
"dev": "test -n \"$ECS_DEPENDENCIES_BUILT\" || pnpm --filter \"$npm_package_name^...\" run build && vite",
"typecheck": "tsc",
"test": "pnpm exec playwright install chromium && vitest --run"
},
Expand Down
Loading