Skip to content

feat: only publish esm bundles from @primer/react - #6425

Merged
joshblack merged 24 commits into
mainfrom
feat/add-esm-only-to-primer-react
Sep 15, 2025
Merged

feat: only publish esm bundles from @primer/react#6425
joshblack merged 24 commits into
mainfrom
feat/add-esm-only-to-primer-react

Conversation

@joshblack

@joshblackjoshblack commented Jul 31, 2025

Copy link
Copy Markdown
Member

Part of https://github.com/github/primer/issues/5541

Update @primer/react to be ESM-only

Changelog

New

Changed

  • Update our package's "type" field to be "module"
  • Update our package's "exports" configuration so that:
    • Each entrypoint has a types condition
    • Each entrypoint has a default condition (which will not be ESM)
  • Add a lint:publish step that checks that our package is setup correctly with its types
  • Update scripts that failed now that we're running in an ESM context instead of a CommonJS context by default

Removed

  • Removed the CommonJS and UMD builds from rollup

Rollout strategy

  • Major release; if selected, include a written rollout or migration plan

We are considering this a major release since the package is no longer publishing ESM bundles. With recent releases of Node.js, we should not need to handle migration (since you can now import ESM from a CommonJS context) but we will test against dotcom to confirm.

@changeset-bot

changeset-botBot commented Jul 31, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8824fb9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
NameType
@primer/reactMajor
@primer/styled-reactMajor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actionsgithub-actionsBot added the staff Author is a staff member label Jul 31, 2025
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@github-actionsgithub-actionsBot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jul 31, 2025
@github-actions

github-actionsBot commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
packages/react/dist/browser.esm.js0 B (-100% 🔽)
packages/react/dist/browser.umd.js0 B (-100% 🔽)
0 B (+100% 🔺)

@github-actions
github-actionsBot requested a deployment to storybook-preview-6425 July 31, 2025 15:02 Abandoned
@joshblack
joshblack marked this pull request as ready for review August 5, 2025 19:26
CopilotAI review requested due to automatic review settings August 5, 2025 19:26
@joshblack
joshblack requested a review from a team as a code ownerAugust 5, 2025 19:26

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR converts @primer/react to be ESM-only by removing CommonJS and UMD builds and updating the package configuration to use modern ESM conventions.

  • Simplifies build output to only ESM bundles in the dist directory
  • Updates package.json exports configuration with proper types and default conditions
  • Modernizes scripts and configurations to work in an ESM context

Reviewed Changes

Copilot reviewed 11 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
packages/react/package.jsonUpdates package type to "module", consolidates exports to single dist directory, adds publint for package validation
packages/react/rollup.config.mjsRemoves CommonJS and UMD build configurations, keeps only ESM output
packages/react/tsconfig.jsonChanges TypeScript output directory from lib to dist
packages/react/script/buildRemoves CommonJS-related build steps and file copying
packages/react/script/precompile-color-schemes.tsAdds ESM __dirname polyfill using import.meta.url
packages/react/script/components-json/build.tsUpdates Babel imports to use named exports for ESM compatibility
packages/react/tsconfig.build.jsonExpands test file exclusions to be more specific
packages/react/babel.config.cjsUpdates require path to use .cjs extension
.github/workflows/ci.ymlAdds publint validation step and updates script reference
.github/workflows/size.ymlRemoves size limit workflow
.changeset/slick-months-cry.mdAdds changeset for major version bump

"import": "./lib-esm/test-helpers.js",
"require": "./lib/test-helpers.js"
"types": "./dist/utils/test-helpers.d.ts",
"default": "./dist/test-helpers.js"

CopilotAIAug 5, 2025

Copy link

Choose a reason for hiding this comment

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

There's a mismatch between the types path (./dist/utils/test-helpers.d.ts) and the default path (./dist/test-helpers.js). Both should point to the same base file location - either both should be in the root or both should be in the utils directory.

Suggested change
"default": "./dist/test-helpers.js"
"default": "./dist/utils/test-helpers.js"

Copilot uses AI. Check for mistakes.
@github-actions
github-actionsBottemporarily deployed to storybook-preview-6425 August 5, 2025 19:34 Inactive
@github-actionsgithub-actionsBot removed the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Aug 5, 2025
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

@github-actions
github-actionsBottemporarily deployed to storybook-preview-6425 September 12, 2025 15:21 Inactive
@github-actionsgithub-actionsBot removed the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Sep 12, 2025
@github-actionsgithub-actionsBot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Sep 12, 2025
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

@github-actions
github-actionsBottemporarily deployed to storybook-preview-6425 September 12, 2025 16:18 Inactive
@github-actionsgithub-actionsBot added integration-tests: failing Changes in this PR cause breaking changes in gh/gh and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh labels Sep 12, 2025
@primer-integration

Copy link
Copy Markdown

👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/2540

@primer-integration

Copy link
Copy Markdown

🟢 ci completed with status success.

@github-actionsgithub-actionsBot added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh and removed integration-tests: failing Changes in this PR cause breaking changes in gh/gh labels Sep 15, 2025
@joshblack
joshblack added this pull request to the merge queueSep 15, 2025
Merged via the queue into main with commit e23d965Sep 15, 2025
43 checks passed
@joshblack
joshblack deleted the feat/add-esm-only-to-primer-react branch September 15, 2025 22:38
@primerprimerBot mentioned this pull request Sep 15, 2025
pksjce pushed a commit that referenced this pull request Sep 18, 2025
Co-authored-by: Marie Lucca <40550942+francinelucca@users.noreply.github.com>
swiing added a commit to swiing/react that referenced this pull request Dec 11, 2025
Since primer#6425, the package only exports ESM modules. As a consequence, the rollup configuration does not need to export an array of configuration objects, and as yet another consequence, there is no need to define a base config that could be shared.
Refactor rollup configuration to export a simple default object directly instead of an array.
@swiingswiing mentioned this pull request Dec 11, 2025
13 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: passingChanges in this PR do NOT cause breaking changes in gh/ghstaffAuthor is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@joshblack@francinelucca