Skip to content

Allow .cjs and .mjs files to be shadowed - #8413

Merged
wesleybl merged 1 commit into
plone:mainfrom
kunalKumar-13:fix/8366-shadow-cjs-mjs
Sep 4, 2026
Merged

Allow .cjs and .mjs files to be shadowed#8413
wesleybl merged 1 commit into
plone:mainfrom
kunalKumar-13:fix/8366-shadow-cjs-mjs

Conversation

@kunalKumar-13

Copy link
Copy Markdown
Contributor

Closes #8366.

The customizations glob listed svg|png|jpg|jpeg|gif|ico|less|js|jsx|ts|tsx, so a shadow of a core .cjs module — canonically constants/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|mjs to that glob.

The alias-key extension strip (/\.(js|jsx|ts|tsx)$/) is deliberately left alone, per @mpalomaki's note on the issue. .cjs and .mjs modules are imported with their extension, so the alias key must keep it. That regex already does the right thing — .cjs does not match \.js$, since the character before js is c, not a dot — so the key comes out as @plone/volto/constants/Languages.cjs, which is what the exact-specifier match needs.

Test

A .cjs shadow pair is added to the existing test-volto-project fixture, and the alias assertion in addon-registry.test.js now expects @plone/volto/constants/Languages.cjs mapped to the customization — which also pins the extension-retention behaviour above.

The fixture's source side lives under __tests__/fixtures/.../node_modules/, so it needed git add -f like its neighbours.

packages/registry: 17/17 in addon-registry.test.js, 112 passing overall. src/vite-plugin.test.tsx fails to resolve @plone/registry/addon-registry in my environment, but it fails identically on a clean main, 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.

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
Copilot AI lite review requested due to automatic review settings September 2, 2026 18:51
@boring-cyborg

boring-cyborg Bot commented Sep 2, 2026

Copy link
Copy Markdown

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.
Read details.

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, read
Plone's Code of Conduct,
Contributing to Plone,
First-time contributors, and
Contributing to Volto,
as this will greatly help the review process.

Welcome to the Plone community! 🎉

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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/.mjs modules are collected and aliased.
  • Add a .cjs shadow 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.

@wesleybl
wesleybl merged commit 799e67d into plone:main Sep 4, 2026
48 checks passed
@boring-cyborg

boring-cyborg Bot commented Sep 4, 2026

Copy link
Copy Markdown

Congratulations on your first merged pull request in this project! 🎉
Congratulations

Thank you for contributing, we are very proud of you! ❤️

@wesleybl

wesleybl commented Sep 4, 2026

Copy link
Copy Markdown
Member

@kunalKumar-13 Thanks! Could you please backport this to the 18.x.x branch?

@kunalKumar-13

Copy link
Copy Markdown
Contributor Author

Done — backport to 18.x.x opened as #8418.

Cherry-picked from 799e67d81 with -x, no conflicts, and packages/registry is green on that branch (4 files, 83 tests). I also checked the backported test does its job there rather than passing regardless: reverting just the glob change fails addon-registry.test.js on the .cjs alias assertion.

Thanks for the merge and the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@plone/registry: customization (shadowing) glob omits cjs|mjs — core .cjs modules (e.g. Languages.cjs) cannot be shadowed

3 participants