Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile within single slice only #20

Merged
merged 26 commits into from
Feb 6, 2024
Merged

Compile within single slice only #20

merged 26 commits into from
Feb 6, 2024

Conversation

timriley
Copy link
Member

@timriley timriley commented Jan 9, 2024

Update our esbuild wrapper to compile a single assets directory at a time.

Previously, we crawled the entire app structure to find all assets directories (within the app and slices) and processed them all at once. This had some downsides:

  • It made our esbuild wrapper and plugin complicated.
  • It meant that we had to take extra steps to prevent naming conflicts for assets with the same name in different slices.
  • The above also meant that every slice's assets had to be referred to with the slice name as a leading namespace (e.g. "admin/app.js" for an admin slice), which didn't fit well with the idea of slices being fully self-contained.
  • In general, it meant we had redundant functionality in JS code (such as locating slices) that already existed in our Ruby code.

By processing a single assets directory at once, we have a much simpler interface with esbuild: we're not pushing it to do things outside its comfort zone. It also means we can eliminate that redundant logic and continue to leverage our Ruby code as the canonical source of knowledge around slices and the overall Hanami app structure.

To process a single directory and output the compiled files into the relevant location, we expect these to be passed as two new arguments when invoking config/assets.js:

  • --path: the path for the app or slice containing the assets to process; e.g. app or slices/admin
  • --dest: the directory to putout the compiled files; e.g. public/assets or public/assets/admin (in the case of the admin slice)

These args will not need to be supplied by the user. Instead, they'll be provided by the hanami assets compile and hanami assets watch commands, which will determine the slices with assets and then invoke one config/assets.js process per slice, along with the relevant CLI arguments. This means the user experience is still simple and streamlined.

Tests aren't fully green yet, but I've made one pass for this new approach.
We weren't using this at all
This will allow our CLI to call this from the outside and provide an appropriate --target for each slice.
This keeps the assets per slice completely self contained, and will allow us to have abitrarily deep structures of compiled slice asset directories while still retaining clarity.
This is invalid now that we're targeting single app or slice assets.
This means that .ts files will have .js extensions when referencing them, as before.
@timriley timriley marked this pull request as ready for review February 5, 2024 13:04
@timriley timriley merged commit b42a48f into main Feb 6, 2024
2 checks passed
@timriley timriley deleted the single-assets-dir-only branch February 6, 2024 12:40
@timriley timriley added this to the v2.1.0 milestone Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant