feat(shell): choose the import map entry point and map; opt out of the auto-pin
Merged
MH
14d ago+194+194+012345678901234567890123456789-1-1-0123456789
Summary
A host with several import maps can now give its docs their own entry point and map, and keep the docs-nav pin out of its shared map.
c.importmap_entry_point(default"application") andc.importmap(nil, anImportmap::Map, or a callable resolved on every render) feedDocsUI::Shell'sjavascript_importmap_tagsthrough a new private#importmap_tags.config.docs_kit.auto_pin = false(inconfig/application.rb) makes the engine'sdocs_kit.importmapinitializer return early, sodocs_kit/controllersstays out ofRails.application.importmap.- README "JavaScript" gains "A dedicated docs import map" (the multi-map setup); CHANGELOG
[Unreleased]→ Added.
With nothing configured the head is byte-identical to 1.2.1.
Closes #93
Test plan
-
spec/docs_kit/configuration_spec.rb:importmap_entry_pointdefault + override;resolved_importmapnil by default, a map as-is, a callable called per read -
spec/docs_ui/shell_spec.rb: default call passes only"application"(noimportmap:); configured entry point + map reach the helper; a callable map is resolved per render -
spec/docs_kit/engine_spec.rb:config.docs_kit.auto_pindefaults to true; the initializer adds the pin file + sweeper by default and adds neither whenauto_pin = false - Booted
docs/app: default<head>diffed againstorigin/main's, byte-identical (CSRF token masked); a customImportmap::Mapwith entrydocsrenders that map's JSON andimport "docs"; booting withauto_pin = falseleaves the gem'sconfig/importmap.rbout ofconfig.importmap.pathsand the drawn map -
bundle exec rspec— 1063 passed (two seeds) -
bundle exec rubocopon the changed files — no offenses
No screenshots: the change is <head>-only, and the default render is unchanged.
Deviations & judgment calls
- Judgment call: one type label,
enhancement. The issue also carriesperformance, but LABELS.md allows exactly one type. - Discovery: importmap-rails isn't in the gem's own bundle, so the Shell spec stubs
javascript_importmap_tagsin a subclass and checks the arguments it receives. The real helper was exercised in the booteddocs/app instead (see test plan). - Judgment call: the Shell passes
importmap:only when a map is configured, and always passes the entry point ("application"by default). That matches the helper's own defaults, so the default head is unchanged. Confirmed by a before/after head diff. - Judgment call:
auto_pin = falsealso skips thecache_sweepersregistration for the gem's JS directory, because the whole initializer returns early as the issue specifies. A host that pins the controllers itself only loses dev-time sweeping of the gem's own files. - Discovery:
config.docs_kitis declared on the engine's config, and Rails shares that with the app's config (class-levelRailtie::Configurationoptions). Soconfig.docs_kit.auto_pin = falseinconfig/application.rbworks, becauseBundler.requireloads the engine first. - Overlap: #92 and #95 edit
configuration.rb,shell.rb, README and CHANGELOG in parallel PRs. This diff stays limited to the import map lines, so any rebase conflicts should be trivial.
Summary by cubic
Lets a docs app render its import map from a dedicated Importmap::Map and entry point instead of the host's shared application map, and opt out of the engine's auto-pin.
c.importmap_entry_point(default"application") andc.importmap(anImportmap::Mapor a callable resolved per render) feed the Shell'sjavascript_importmap_tags.config.docs_kit.auto_pin = falseinconfig/application.rbkeeps the gem'sdocs-navpin out ofRails.application.importmap.- With nothing configured, the rendered head is byte-identical to 1.2.1.