Skip to content

Add --names to generate static names for crunched files - #73

Open
er433 wants to merge 1 commit into
mirage:mainfrom
er433:static-names
Open

Add --names to generate static names for crunched files#73
er433 wants to merge 1 commit into
mirage:mainfrom
er433:static-names

Conversation

@er433

@er433 er433 commented Aug 27, 2026

Copy link
Copy Markdown

By default the generated module is accessed by strings, so a bad path compiles fine and fails at run time:

match Assets.read "css/app.css" with Some s -> s | None -> assert false

This PR adds a --names flag that generates a module with one value per crunched file, named after its path, so the compiler checks the reference:

$ ocaml-crunch --mode=plain --names -o assets.ml assets/
Assets.Name.contents Assets.Name.css__app_css

Now, in this way, we'll have a compile time error if passing a "bad path".

The generated module exposes an abstract type with name, path, contents and size accessors plus an all list.

It also carries its own module type S listing just the bindings, which lets a wrapper library re-export the names while hiding everything else... this might be useful when the contents should not be readable directly:

module Files : Assets.Name.S with type t = Assets.Name.t = Assets.Name

I think this covers partially the request of #44 , although I discovered the issue afterwards.

Disclaimer: the changes in this PR were partially made with AI-assisted coding using Claude Code.

@dinosaure

Copy link
Copy Markdown
Member

I think you should definitely take a look on mcrunch. As we said, this package is less and less maintained and we would like to replace it by mcrunch (see #44 for more details).

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.

2 participants