trunk icon indicating copy to clipboard operation
trunk copied to clipboard

Hooks and SRI?

Open TimNN opened this issue 9 months ago • 6 comments

I've been trying to use hooks to run a JS bundler on the output of wasm-bindgen.

Running the bundler works reasonably well (though it's a bit sad that I have to guess the name of the .js file).

I update the .js file in-place in the .stage directory.

However, this does not seem to trigger a re-calculation of the SRI hash.

Would it be feasible to support this use case?

E.g. one option that I've hacked together is support for a data-js-bundler="bun build --outfile=$TRUNK_OUTPUT $TRUNK_INPUT" attribute for rust assets, but based on my reading of #32, that's not a direction you want to take the project in.

Another alternative I could imagine: is re-calculate (or defer calculating) all the SRI hashes to just before writing the final HTML.

TimNN avatar Apr 05 '25 10:04 TimNN

I guess I've found a way to make this work by using a fake wasm-bindgen executable, and running the bundler immediately after the actual wasm-bindgen.

It's a bit annoying to use because there doesn't seem to be a way to explicitly provide the path to wasm-bindgen (only its version), but it's doable.

TimNN avatar Apr 05 '25 11:04 TimNN

Yea, the SRI stuff is being processed before putting it to the .stage directory IIRC. Maybe it needs another hook type?

ctron avatar Apr 07 '25 08:04 ctron

Thanks for taking a look at this issue! Just FYI: I reported this while prototyping some things, and ended up not actually needing a bundler. (So this problem doesn't affect me any more).

TimNN avatar Apr 07 '25 10:04 TimNN

good idea but maybe for now this can be closed @ctron ("So this problem doesn't affect me any more")

duke-m avatar May 12 '25 21:05 duke-m

I guess we can leave it open. It's a valid point, isn't it?

ctron avatar May 13 '25 07:05 ctron

I guess we can leave it open. It's a valid point, isn't it?

It is. Still I am asking myself how to offer a better overview for "onboarding developers", like a triage or something like a PRODUCTVISION.md.

duke-m avatar May 13 '25 08:05 duke-m