ContentHashScalaJSModule: linker-wrapper via mill.scalajslib vendoring with topological hash ordering#43
Conversation
…output Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
….yml Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
|
@copilot please change the tests and implementation to be [name].[hash].js/wasm. Add a test for WASM too please, by configuring the module to use the |
…M test Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
Done in commit
All 12 tests pass. |
…l.scalajslib package Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
|
@copilot I've written the scaffolding for some integration tests in the plugin.integration folder. you can run them with Currently, the WASM test seems to fail. The JS test passes, but it does the wrong thing. If you inspect the files created by the plugin, it renames them according to the hash, but it does so and breaks their internal links. Please review the hint;
Please scan the modules and recover their dependancies. Then, in topological order do the hashing and re-write the header imports. |
Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
Fixed in commit WASM test failure: The test had JS broken internal links: Scala.js ESModule output always uses The hint about scanning dependencies and doing topological ordering was also implemented:
Integration tests now assert that all cross-module imports in each output file resolve to a file that actually exists in the output directory (verifying links are correct). |
|
@copilot run formatting |
Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
Done in commit |
|
@copilot remove only tag that is causing co to fail |
Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
Done in commit |
[name]-[hash].jsto[name].[hash].jslinkJs, capture output in temp dir, hash toctx.dest.onlytag from test causing CI failureOriginal prompt
This section details on the original issue you should resolve
<issue_title>Content Hash mill plugin</issue_title>
<issue_description># 📌 Implementation Plan: Mill Plugin for Content‑Hashed Scala.js Output
🎯 Goal
Create a Mill plugin that:
Re-use Mill’s existing tasks where possible, extend from mill's existing ScalaJSModule
🧰 Background
ScalaJSModuleinmill.scalajslibfor Scala.js projects. ([mill-build.org]1)ScalaJSWorkerImpl). ([mill-build.org][2])📦 Plugin Structure
🔧 Step‑by‑Step Tasks
1️⃣ Define Plugin Entrypoint
Create
plugin.scalawhich declares the plugin:2️⃣ Extend ScalaJSModule
Create
ContentHashScalaJSModule.scalathat mixes in withScalaJSModule:This module will override the linking step to use a custom content‑hashing linker instead of the default.
3️⃣ Add In‑Memory Output Directory
Define an in‑memory directory to capture linker output:
4️⃣ Implement ContentHashLinker Wrapper
Create a class that wraps the default Scala.js
LinkerImpl:5️⃣ Override ScalaJS Linker in Mill Module
Inside
ContentHashScalaJSModule, override the Scala.js linker:This ensures the custom wrapper is used for all linking tasks.
🔍 Internal Reference Rewriting (Optional/Advanced)
To fully support hashed references (e.g., dynamic imports), you’ll need to scan JS output for module names and replace them with hashed ones. This is trickiest part.
Implementation notes:
Example (text‑based):
🧪 Testing & Validation
ScalaJSModulein a test project.import ContentHashPlugin._.mill <module>.fullLinkJSand inspect output directory — you should see hashed JS filenames.Your opinion.
Before starting implementation, read this plan. Analyse feasibility and double check your imlementation plan.
Write the plugin tests first, using mill's plugin test infrastructure.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.