Skip to content

Fix: make es-components lib/cjs output resolvable by strict ESM loaders - #922

Open
JavierHuanca wants to merge 7 commits into
pre-prodfrom
esm-migration-plan
Open

JavierHuanca wants to merge 7 commits into
pre-prodfrom
esm-migration-plan

Conversation

@JavierHuanca

Copy link
Copy Markdown
Contributor

Adds explicit module boundaries and fixes dependency externalization so es-components can be consumed through native/strict ESM resolvers (e.g. esm.sh), without changing behavior for existing CJS, bundler, or UMD consumers.

  • package.json: add an exports map for . and ./build-utils/jest, pointing import at lib/index.js and require at cjs/index.js, alongside the existing main/module/types fields.
  • rollup.config.mjs: write a nested package.json into cjs/ and lib/ after build ({type:commonjs} / {type:module}) so resolvers don't have to guess the module format from the ambiguous .js extension. Also stop wildcard-externalizing text-mask-addons for the cjs/lib build, since it's imported via extensionless subpaths that only CJS/bundler resolution tolerates.
  • getPackageExternals.mjs: always bundle get-root-node-polyfill, react-transition-group, and text-mask-addons instead of leaving them external. Each is imported via a bare specifier pattern (missing extension or directory import) that Node's strict ESM resolver rejects, even though CJS/bundler resolution silently accepts it.

Verified built cjs/ and lib/ output resolves cleanly under Node's native ESM loader (import()) and CJS require(); UMD bundle output is unchanged; full es-components Jest suite (44 suites / 221 tests) still passes.

Adds explicit module boundaries and fixes dependency externalization so
es-components can be consumed through native/strict ESM resolvers
(e.g. esm.sh), without changing behavior for existing CJS, bundler, or
UMD consumers.

- package.json: add an exports map for . and ./build-utils/jest,
  pointing import at lib/index.js and require at cjs/index.js,
  alongside the existing main/module/types fields.
- rollup.config.mjs: write a nested package.json into cjs/ and lib/
  after build ({type:commonjs} / {type:module}) so resolvers
  don't have to guess the module format from the ambiguous .js
  extension. Also stop wildcard-externalizing text-mask-addons for the
  cjs/lib build, since it's imported via extensionless subpaths that
  only CJS/bundler resolution tolerates.
- getPackageExternals.mjs: always bundle get-root-node-polyfill,
  react-transition-group, and text-mask-addons instead of leaving them
  external. Each is imported via a bare specifier pattern (missing
  extension or directory import) that Node's strict ESM resolver
  rejects, even though CJS/bundler resolution silently accepts it.

Verified built cjs/ and lib/ output resolves cleanly under Node's
native ESM loader (import()) and CJS require(); UMD bundle output is
unchanged; full es-components Jest suite (44 suites / 221 tests)
still passes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Commitlint

commitlint results

All commit messages are correctly formatted.

@JavierHuanca
JavierHuanca marked this pull request as ready for review October 6, 2026 00:35
@JavierHuanca
JavierHuanca requested a review from a team as a code owner October 6, 2026 00:35
…age publishes

The theme packages (es-components-wtw-theme, es-components-via-theme,
es-components-wtw-legacy-theme) do not have npm Trusted Publishing
configured yet, so npm's automatic OIDC attempt fails with E404 when
id-token: write is present. Removing that permission forces npm to
fall back to the existing NPM_TOKEN secret for all packages in the
canary workflow, unblocking canary publishes without requiring admin
action on npm. The real ci.yml/preprod-ci.yml release pipelines are
left untouched pending a team decision.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Commitlint

commitlint results

All commit messages are correctly formatted.

The NPM_TOKEN secret used by this workflow does not have publish
access to es-components-wtw-theme, es-components-via-theme, or
es-components-wtw-legacy-theme (confirmed by identical E404s with and
without OIDC). Mark them private in the ephemeral CI checkout only
(never committed) so lerna skips them and es-components can still
publish a canary build on its own. Revert once an admin widens the
token's scope or configures npm Trusted Publishing for those packages.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Commitlint

commitlint results

All commit messages are correctly formatted.

lerna refuses to publish with an EUNCOMMIT error if the working tree
has uncommitted changes, so the private=true marker set on the theme
packages in the previous commit needs to be committed locally in the
ephemeral CI checkout (never pushed to origin) before lerna publish
runs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Commitlint

commitlint results

All commit messages are correctly formatted.

Removing id-token: write broke es-components' own publish, which
turns out to rely on working OIDC Trusted Publishing (not the classic
NPM_TOKEN as assumed). Only the theme packages lack Trusted Publishing
setup; the private-package exclusion step added earlier already
handles that correctly, so restoring this permission is all that's
needed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Commitlint

commitlint results

All commit messages are correctly formatted.

Reverting the temporary workaround now that the real root cause is
identified as an expired NPM_TOKEN. Once Steve regenerates the token,
all 4 packages should publish normally again, so this workaround is
no longer needed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Commitlint

commitlint results

All commit messages are correctly formatted.

Trusted Publishing is now enabled on npm, but only registered for one
workflow file, so the theme packages get E403 when publishing from
canary-publish.yml. Re-applying the private-flag workaround so
es-components can publish a canary build on its own in the meantime.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Commitlint

commitlint results

All commit messages are correctly formatted.

This branch was successfully deployed

1 active deployment
canary — 9c5a9a73 Deployed Oct 7, 2026 by JavierHuanca via Build And Deploy Canary Release #187
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.

1 participant