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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ import { EntityFetcherProvider, EntityGrid } from "@metaobjectsdev/tanstack";
- **TS runtime**: Bun-first for development (zero-config TS, native test runner). Node-compatible for distribution; users install via npm/pnpm/bun without lock-in to Bun's runtime.
- **Module system**: ESM only. No CommonJS, no transpile step required.
- **Storage format**: JSON files in `metaobjects/meta.<concept>.json` at project root. `.metaobjects/.gen-state/` holds the codegen merge base: the snapshot **bodies are gitignored** (a second full copy of all generated output), but **`.hashes.json` is COMMITTED** — one hash per generated path, and the only thing that lets `meta gen` tell "this file is exactly what I wrote" from "somebody edited this" on a machine that did not generate it. Ignore it and a fresh clone or CI runner silently overwrites hand edits; commit it and an edited file is refused by name instead.
- **Codegen substrate**: ts-poet for greenfield emit, ts-morph for in-place edits, Biome for format pass, `git merge-file --diff3` for hand-edit-preserving regen.
- **Codegen substrate**: the vendored ts-poet printer (`codegen-ts/src/poet.ts`) for greenfield emit, ts-morph for in-place edits, Biome for format pass, `git merge-file --diff3` for hand-edit-preserving regen.
- **Runtime substrate**: Kysely for TS (user-provided connection, async-only).
- **Migration substrate**: Postgres + SQLite for TS v0.3.
- **Metadata location**: resolved via `resolveCollection()` (`@metaobjectsdev/sdk`) — the single authority. `metaobjects/` is the **default value of `sources`** and nothing else: no other module, command or user-facing message may assert that a directory of that name exists or is where metadata lives. Exactly five sites may name it — `sdk/src/metadata-files.ts` (`DEFAULT_METADATA_DIR`, its single definition), `sdk/src/sources.ts` (`DEFAULT_SOURCES`, **the** default), `sdk/src/collection.ts` (inside `resolveCollection`, *applying* that default), `sdk/src/index.ts` (the barrel re-export of the constant, no use), and `cli/src/commands/init.ts` (the scaffolder **writing** the layout). Enforced by `sdk/test/no-hardcoded-metadata-dir.test.ts`, whose allowlist demands a written reason per entry. See [docs/features/metadata-sources.md](docs/features/metadata-sources.md).
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ loaded before stops loading. This vocabulary ships in 1.3.0 with `metamodelVersi
lint gate), and a fresh npm install of the CLI drops from 245 MB to 151 MB of `node_modules`.
`scripts/check-peer-ranges.ts` now fails a publishable package that requires `@biomejs/biome`
through `dependencies` or a non-optional peer.
- **`@metaobjectsdev/cli` no longer installs `dprint-node`.** The TypeScript generators printed
code with `ts-poet`, which loads `dprint-node` on import, and dprint-node ships all seven of
its platform binaries in one package (24 MB, of which a machine runs one). `codegen-ts` now
vendors the part of ts-poet the generators use (`src/poet.ts`, Apache-2.0, licence in
`LICENSE.ts-poet`) and runs the same dprint TypeScript plugin as WebAssembly
(`@dprint/typescript`, pinned to 0.87.1, the version dprint-node 1.0.8 compiles in, 5 MB) with
ts-poet's configuration, so generated code is byte-identical: every codegen golden and
conformance fixture is unchanged. `codegen-ts-react`, `codegen-ts-tanstack` and
`codegen-ts-angular` drop their `ts-poet` dependency and import the printer from
`@metaobjectsdev/codegen-ts/engine`, which an ejected template also uses. A bare `ts-poet`
import in an older owned generator is still pointed at that entry by `meta gen`, which
carries `code`, `imp`, `joinCode`, `Import` and the `Code` type; ts-poet's `saveFiles`,
`conditionalOutput` and its `toString` import options are not carried over. A fresh npm
install of the CLI drops from 151 MB (134,641,989 bytes) to 133 MB (115,302,944 bytes) of
`node_modules`. `scripts/check-peer-ranges.ts` now also fails a publishable package that
requires `dprint-node`, `ts-poet` or any `@types/*` package through `dependencies`,
`optionalDependencies` or a non-optional peer; a type package a published `.d.ts` imports goes
in its `ALLOWED_TYPES_DEPS`
with the reason. No `@metaobjectsdev/*` package declares `@types/node`: the 3 MB copy in the
install comes through the libSQL driver (`@libsql/isomorphic-ws` → `@types/ws`), which is
unchanged here. This also repairs the standalone binary (`bun run build:binary`): `--compile`
cannot embed dprint-node's native `.node` file, so a binary built from 1.2.0 crashed with
`Cannot find module './dprint-node.linux-x64-gnu.node'` on every command that loads the
codegen engine, `meta migrate` and `meta verify --db` included. Those schema commands, the
binary's documented scope, now run; `meta gen` is still not supported inside the binary.

### Deprecated

Expand Down
11 changes: 7 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/features/own-your-codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ holds), the naming tables and the type-mapping tables (`names.ts`, `naming.ts`,
`column-mapper.ts`), the primary-key and TPH walks (`pk-resolver.ts`, `tph.ts`), and the
projection and report lowering that `meta migrate` and `meta verify` run. An owned file
imports the engine from the package's engine entry, `@metaobjectsdev/codegen-ts/engine`,
which also re-exports `ts-poet`'s `code`, `imp` and `joinCode`. The list is
`ENGINE_MODULES`, exported from that entry; a module
which also exports the code printer's `code`, `imp` and `joinCode` (`poet.ts`, the package's
vendored copy of `ts-poet`). The list is `ENGINE_MODULES`, exported from that entry; a module
that is not on it and that a generator reaches is copied. An owned generator therefore
imports no packaged module that returns emitted text, and a test ejects each generator alone
into an empty project to prove it: it compiles as your `tsconfig.codegen.json` checks it and
writes what the packaged generator writes, byte for byte.

A copy differs from the packaged module in its **import lines only**. A relative import of
an engine module becomes an import of `@metaobjectsdev/codegen-ts/engine`, a relative import of
another template module becomes the path to your copy of it, and `ts-poet` becomes the
engine's own (a copy must build `Code` with the same `ts-poet` the engine uses). Nothing else
another template module becomes the path to your copy of it, and the printer stays the
engine's (a copy must build `Code` with the same printer the engine uses). Nothing else
is touched, so "what did upstream change?" is a diff of two files whose body is the same.

- **Two generators that call one module share one copy.** `entity` and `queries` both call
Expand Down
1 change: 1 addition & 0 deletions fixtures/generator-registry-conformance/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
"codegen-ts/src/naming/name-claims.ts",
"codegen-ts/src/owned-runtime.ts",
"codegen-ts/src/pk-resolver.ts",
"codegen-ts/src/poet.ts",
"codegen-ts/src/projection/build-projection-views.ts",
"codegen-ts/src/projection/extract-view-spec.ts",
"codegen-ts/src/projection/projection-detector.ts",
Expand Down
62 changes: 62 additions & 0 deletions scripts/check-peer-ranges.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// The install-time guard (scripts/check-peer-ranges.ts, second rule): a publishable
// package cannot land dprint-node, ts-poet or a run-time @types/* in an adopter's
// tree through ANY manifest field npm installs by default. npm installs
// `optionalDependencies` by default (it skips an entry only when that install
// fails), so the guard must refuse them there exactly as it does under
// `dependencies` — otherwise a published manifest reintroduces the ~25 MB
// formatter while the gate stays green. The escape hatch stays an optional peer
// (`peerDependenciesMeta`), which npm leaves to the adopter. All three cases are
// pinned by driving `peerRangeReport` — the same walk the CLI runs — against a
// synthetic workspace.
import { afterAll, describe, expect, test } from "bun:test";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { peerRangeReport } from "./check-peer-ranges";

const created: string[] = [];
afterAll(() => { for (const d of created) rmSync(d, { recursive: true, force: true }); });

/** A throwaway workspace whose single publishable package has this manifest body. */
function workspaceWith(pkg: Record<string, unknown>): string {
const root = mkdtempSync(join(tmpdir(), "check-peer-ranges-"));
created.push(root);
const dir = join(root, "server/typescript/packages/fixture");
mkdirSync(dir, { recursive: true });
writeFileSync(join(dir, "package.json"), JSON.stringify({ name: "@metaobjectsdev/fixture", version: "1.2.0", ...pkg }));
return root;
}

describe("install-time guard — optionalDependencies are installed by default", () => {
test("dprint-node under optionalDependencies is refused, naming the field", () => {
const report = peerRangeReport(workspaceWith({ optionalDependencies: { "dprint-node": "^1.0.8" } }));
expect(report.installOnlyDeps).toEqual([
expect.objectContaining({ pkg: "@metaobjectsdev/fixture", dep: "dprint-node", field: "optionalDependencies" }),
]);
});

test("a run-time @types/* under optionalDependencies is refused too", () => {
const report = peerRangeReport(workspaceWith({ optionalDependencies: { "@types/node": "^22.0.0" } }));
expect(report.installOnlyDeps).toEqual([
expect.objectContaining({ dep: "@types/node", field: "optionalDependencies" }),
]);
});

test("a clean package passes: real dep, bounded peer counted", () => {
const report = peerRangeReport(workspaceWith({
dependencies: { "drizzle-orm": "^0.36.0" },
peerDependencies: { react: "^18.0.0" },
}));
expect(report.installOnlyDeps).toEqual([]);
expect(report.unboundedPeers).toEqual([]);
expect(report.peerRanges).toBe(1);
});

test("the documented escape hatch holds: an optional peer is not refused", () => {
const report = peerRangeReport(workspaceWith({
peerDependencies: { "dprint-node": "^1.0.8" },
peerDependenciesMeta: { "dprint-node": { optional: true } },
}));
expect(report.installOnlyDeps).toEqual([]);
});
});
Loading
Loading