Skip to content

Support Vite-style ?raw raw-text imports in CLI builds - #69

Merged
joostfarla merged 1 commit into
mainfrom
build-cli-raw-imports
Jul 15, 2026
Merged

Support Vite-style ?raw raw-text imports in CLI builds#69
joostfarla merged 1 commit into
mainfrom
build-cli-raw-imports

Conversation

@joostfarla

Copy link
Copy Markdown
Member

Generic follow-up to developer-overheid-nl/don-checker#66 (which fixes developer-overheid-nl/don-checker#55): consumer apps import example fixtures as raw text via Vite's ?raw suffix — YAML fixtures in particular, so the editor opens them in YAML mode. Vite and Vitest support the suffix natively, but the build-cli CLI bundle (rolldown) and tsc don't. This makes both work out of the box, so consumers need no local tsdown config or ambient module declaration.

Changes

  • bin/build-cli.mjs — now drives the tsdown JS API with the standard CLI-build options plus a raw-imports plugin that resolves *?raw specifiers and inlines the file content as a default-exported string.

    Why the JS API instead of spawning the tsdown CLI: plugins can only reach the CLI via a config file, and tsdown resolves relative paths (entry, tsconfig discovery) against the config file's directory — a config shipped inside this package made consumer builds resolve tsconfig: ../tsconfig.json (this package's own!) and fail on Cannot resolve entry module src/cli.ts. With the API everything stays relative to the consumer's cwd.

    Contract change: build-cli <entry> [...entry] takes entries only (flags now error with a usage message instead of being forwarded), and a consumer tsdown.config.ts is never loaded — the build is fully standard.

  • client.d.ts — declares *?raw modules as strings, so tsc accepts the imports. Consumers upgrading should remove any local equivalent declaration (a duplicate would conflict).

  • README + changeset (minor).

Verification

  • pnpm lint clean, pnpm test run passes (131 tests), pnpm build succeeds.
  • don-checker (has ?raw YAML/JSON imports): built with this build-cli after removing its local tsdown.config.ts shim — correct consumer tsconfig.json picked up, bundle validates both the YAML publiccode example and the JSON ADR example with 0 diagnostics. tsc -b also passes against the new client.d.ts with the local *?raw declaration removed.
  • ogc-checker (no ?raw imports): builds unchanged and its CLI validates the JSON-FG feature example clean — no regression for consumers not using the feature.

After this lands in a release, don-checker can drop its tsdown.config.ts and src/vite-env.d.ts shims when bumping the dependency.

build-cli now drives the tsdown JS API with the standard CLI-build options
plus a raw-imports plugin that resolves and inlines *?raw imports (rolldown
doesn't implement the suffix natively), and the client types declare *?raw
modules as strings. Consumers can import example fixtures (e.g. YAML files)
as raw text without a local tsdown config or ambient module declaration.

The JS API replaces spawning the tsdown CLI because plugins can only reach
the CLI via a config file, and tsdown resolves relative paths (entry,
tsconfig) against the config file's directory — a config shipped inside the
package would break consumer builds. build-cli now takes entries only and
never loads a consumer tsdown.config.ts.
@joostfarla
joostfarla requested a review from pasibun July 15, 2026 11:46
@joostfarla
joostfarla merged commit 98606e8 into main Jul 15, 2026
3 checks passed
@joostfarla
joostfarla deleted the build-cli-raw-imports branch July 15, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

file format op yml zetten als iemand switcht naar publiccode.yml ruleset

2 participants