Skip to content

bugc: expose canonical BUG examples via a subpath export#249

Merged
gnidan merged 2 commits into
mainfrom
compiler-dry-examples
Jul 11, 2026
Merged

bugc: expose canonical BUG examples via a subpath export#249
gnidan merged 2 commits into
mainfrom
compiler-dry-examples

Conversation

@gnidan

@gnidan gnidan commented Jul 11, 2026

Copy link
Copy Markdown
Member

The .bug files under packages/bugc/examples are bugc's canonical
example programs and double as its behavioral test fixtures. Rendering
them anywhere else meant copying sources by hand or globbing the raw
files — which webpack-based bundlers can't do.

This exposes them through a new @ethdebug/bugc/examples subpath export.

  • A build step (bin/generate-examples.js) reads the .bug files and
    emits src/examples/generated.ts, a source-by-path map, using the same
    generated-module pattern as @ethdebug/format's schema yamls.ts. The
    generated file is gitignored and (re)produced by prepare, so it exists
    after install and ships in dist.
  • src/examples/index.ts surfaces exampleSources, examplePaths, and
    stripTestAnnotations(), which strips the inline /*@test*/ blocks and
    // @wip / // @skip / // @expect-* directives the raw files carry so
    a source reads cleanly in an editor. Which examples to show, and how to
    label them, is left to each consumer.
  • Adds a package exports map (root . plus ./examples). The internal
    #-imports are a separate field and are unaffected; nothing in the repo
    deep-imports bugc.

The canonical .bug files remain the single source of truth and the
behavioral tests are unchanged. Stripping is purely cosmetic: the tests
confirm a stripped example compiles to byte-identical bytecode as its raw
counterpart.

The .bug files under packages/bugc/examples are bugc's canonical example
programs and double as its behavioral test fixtures. Rendering them
elsewhere meant copying sources by hand or globbing the raw files, which
webpack-based bundlers can't do.

Expose them through a new @ethdebug/bugc/examples subpath export:

- A build step (bin/generate-examples.js) reads the .bug files and emits
  src/examples/generated.ts, a source-by-path map — the same generated
  module pattern as @ethdebug/format's schema yamls. The generated file
  is gitignored and (re)produced by prepare.
- src/examples/index.ts surfaces exampleSources, examplePaths, and
  stripTestAnnotations(), which removes the inline /*@test*/ blocks and
  // @wip / // @Skip / // @expect-* directives the raw files carry so a
  source reads cleanly in an editor.
- Adds a package exports map (root "." plus "./examples"); the internal
  #-imports are a separate field and are unaffected.

Stripping is purely cosmetic: the tests confirm a stripped example
compiles to byte-identical bytecode as its raw counterpart.
@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-11 03:36 UTC

The root build calls tsc --build directly and bypasses each package's
prepare script, so add the examples generate step alongside the existing
schema-yamls step. This keeps the generated module current on the
standalone yarn build / yarn start paths, which don't reinstall.
@gnidan gnidan merged commit fedeb9a into main Jul 11, 2026
5 checks passed
@gnidan gnidan deleted the compiler-dry-examples branch July 11, 2026 03:32
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.

1 participant