Allow .cjs and .mjs files to be shadowed - #8413
Conversation
The customizations glob omitted cjs and mjs, so a shadow of a core module such as constants/Languages.cjs was never collected and never became a webpack alias. Nothing warned; the shadow was silently ignored. The alias-key extension strip is left alone on purpose: cjs and mjs modules are imported with their extension, so the key must retain it. Closes plone#8366
|
Caution The Volto Team has suspended its review of new pull requests from first-time contributors until the release of Plone 7, which is preliminarily scheduled for the second quarter of 2026. Thanks for submitting your first pull request! You are awesome! 🤗 If you haven't done so already, read Welcome to the Plone community! 🎉 |
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped to the customization glob and is backed by a targeted fixture-based test that pins the intended .cjs aliasing behavior.
Pull request overview
This PR fixes Volto’s addon/project customization (shadowing) file collection so that .cjs and .mjs modules can be shadowed just like .js/.ts/.tsx modules. It updates the customization glob in @plone/registry and adds a fixture + assertion to lock in the expected alias key behavior for .cjs (extension retained).
Changes:
- Extend the customization discovery glob to include
cjs|mjs, so shadows of core.cjs/.mjsmodules are collected and aliased. - Add a
.cjsshadow pair to the existing test fixture and assert the alias key retains.cjs(matching exact-specifier imports). - Add a registry news fragment documenting the bugfix.
File summaries
| File | Description |
|---|---|
packages/registry/src/addon-registry/addon-registry.ts |
Adds `cjs |
packages/registry/news/8366.bugfix |
Documents the bugfix in the registry changelog/news system. |
packages/registry/__tests__/fixtures/test-volto-project/src/customizations/constants/Languages.cjs |
Adds a project customization .cjs file used to validate shadowing behavior. |
packages/registry/__tests__/fixtures/test-volto-project/node_modules/@plone/volto/src/constants/Languages.cjs |
Adds the corresponding “upstream” .cjs module in the fixture to be shadowed. |
packages/registry/__tests__/addon-registry.test.js |
Updates expected customization alias map to include the .cjs specifier with extension preserved. |
Review details
- Files reviewed: 4/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@kunalKumar-13 Thanks! Could you please backport this to the 18.x.x branch? |
|
Done — backport to Cherry-picked from Thanks for the merge and the review. |

Closes #8366.
The customizations glob listed
svg|png|jpg|jpeg|gif|ico|less|js|jsx|ts|tsx, so a shadow of a core.cjsmodule — canonicallyconstants/Languages.cjs— was never collected and never became a webpack alias. Nothing warned: the shadow was simply ignored, which is what made it expensive to diagnose.Adds
cjs|mjsto that glob.The alias-key extension strip (
/\.(js|jsx|ts|tsx)$/) is deliberately left alone, per @mpalomaki's note on the issue..cjsand.mjsmodules are imported with their extension, so the alias key must keep it. That regex already does the right thing —.cjsdoes not match\.js$, since the character beforejsisc, not a dot — so the key comes out as@plone/volto/constants/Languages.cjs, which is what the exact-specifier match needs.Test
A
.cjsshadow pair is added to the existingtest-volto-projectfixture, and the alias assertion inaddon-registry.test.jsnow expects@plone/volto/constants/Languages.cjsmapped to the customization — which also pins the extension-retention behaviour above.The fixture's source side lives under
__tests__/fixtures/.../node_modules/, so it neededgit add -flike its neighbours.packages/registry: 17/17 inaddon-registry.test.js, 112 passing overall.src/vite-plugin.test.tsxfails to resolve@plone/registry/addon-registryin my environment, but it fails identically on a cleanmain, so it is unrelated to this change. Prettier clean.I did not implement the optional build-time warning suggested in the issue — happy to add it here or in a follow-up if you'd like it.