Skip to content

Add classnames.js Set export to the CSS build - #4096

Merged
jonrohan merged 7 commits into
mainfrom
add-classnames-export
Jun 17, 2026
Merged

Add classnames.js Set export to the CSS build#4096
jonrohan merged 7 commits into
mainfrom
add-classnames-export

Conversation

@jonrohan

Copy link
Copy Markdown
Member

What

Extends the CSS build to emit a new static/classnames.js file that default-exports a JavaScript Set of every unique component CSS class name in the library, giving consumers and tooling a single published list of classnames. This is for parity with primer/css.

Changes

  • script/export-css-selectors — In the same build that already produces static/classes.json, collect every bare class token (without the leading .) from all rule selectors (traversing every compound/token, not just the first). Results are deduplicated via a Set and sorted alphabetically for stable diffs. @keyframes children are skipped as before. The utility/layout classes in app/lib/primer/css/utilities.css and app/lib/primer/css/layout.css are intentionally excluded via a new classNameExcludedFiles option.
  • static/classnames.js (generated) — emits:
    const classNames = new Set([
      'ActionBar',
      // ...sorted...
    ])
    
    export default classNames
    Formatted to satisfy the repo's eslint/prettier config (single quotes, trailing commas, no semicolons, named default export).
  • package.json — adds static/classnames.js to the published files list.
  • .changeset/classnames-export.mdminor changeset describing the new export.

Verification

  • static/classnames.js is generated, default-exports a non-empty Set (435 entries), contains known component classes (e.g. Label, Box-body), has no leading dots, and no duplicates.
  • eslint static/classnames.js passes clean.
  • static/classes.json and the per-file *.css.json outputs are unchanged.

Notes

The exports map step was skipped because the package does not currently use an exports field. Pre-existing unrelated package-lock.json changes were excluded from this branch.

Extend script/export-css-selectors to emit static/classnames.js, a default-exported Set of every unique component CSS class name (excluding the utilities.css and layout.css utility classes). Publish the file via package.json files.
@jonrohan
jonrohan requested a review from a team as a code owner June 17, 2026 16:15
@jonrohan
jonrohan requested review from Copilot and joshblack June 17, 2026 16:15
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9a247f9

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

This PR includes changesets to release 1 package
Name Type
@primer/view-components Minor

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

Introduce a package.json exports field so consumers can use @primer/view-components/classnames. Includes a ./* wildcard fallback to preserve existing deep imports.

Copilot AI 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 extends the CSS build pipeline to additionally emit static/classnames.js, intended to provide consumers/tooling with a single published list of all unique CSS class names used by Primer ViewComponents (similar to primer/css).

Changes:

  • Update script/export-css-selectors to collect class tokens across all selectors and write a new static/classnames.js artifact.
  • Publish static/classnames.js via package.json#files.
  • Add a changeset documenting the new export.
Show a summary per file
File Description
static/classnames.js New generated artifact exporting the collected class-name set.
script/export-css-selectors Adds cross-file class-name collection and writes static/classnames.js.
package.json Publishes static/classnames.js in the package files list.
.changeset/classnames-export.md Declares a minor release and documents the new export.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 2

Comment thread script/export-css-selectors
Comment thread script/export-css-selectors
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Emit static/classnames.cjs (module.exports = Set) and static/classnames.d.ts alongside the ESM static/classnames.js. Make ./classnames a conditional export (types/import/require) and publish the new files.
@jonrohan
jonrohan merged commit 3ba48a2 into main Jun 17, 2026
33 checks passed
@jonrohan
jonrohan deleted the add-classnames-export branch June 17, 2026 17:50
@primer primer Bot mentioned this pull request Jun 17, 2026
myabc added a commit to opf/primer_view_components that referenced this pull request Jul 21, 2026
Syncs the fork with primer/view_components up to upstream commit
6733f3c (parent of Release Tracking primer#4098), the last release in
this batch reaching v0.51.6.

Notable upstream changes pulled in:
- classnames.js Set export (primer#4096): static/classnames.{js,cjs,d.ts}
  plus the package.json exports subpath and files entries.
- perf(css): removed universal `*` subjects and expanded merged
  `:is()` selector lists (primer#4095).

Conflicts resolved keeping the fork's identity, scope and its higher
dependency versions; upstream's new exports/files additions and the
static class-name output were merged in and regenerated cleanly.
myabc added a commit to opf/primer_view_components that referenced this pull request Jul 21, 2026
Syncs the fork with primer/view_components up to upstream commit
6733f3c (parent of Release Tracking primer#4098), reaching v0.51.6.

Upstream changes pulled in:
- classnames.js Set export (primer#4096): static/classnames.{js,cjs,d.ts},
  the export-css-selectors collection logic, and the package.json
  exports subpath plus files entries.
- perf(css): removed universal `*` subjects and expanded merged
  `:is()` selector lists (primer#4095).

Conflict resolution kept the fork's identity, scope and its higher
dependency versions; upstream's new exports were merged in. The
recursive tsconfig include is re-applied here so nested component TS
keeps experimentalDecorators under Vite 8/rolldown. All generated
static files were regenerated from a clean tree.
myabc added a commit to opf/primer_view_components that referenced this pull request Jul 21, 2026
Syncs the fork with primer/view_components up to upstream commit
6733f3c (parent of Release Tracking primer#4098), reaching v0.51.6.

Upstream changes pulled in:
- classnames.js Set export (primer#4096): static/classnames.{js,cjs,d.ts},
  the export-css-selectors collection logic, and the package.json
  exports subpath plus files entries.
- perf(css): removed universal `*` subjects and expanded merged
  `:is()` selector lists (primer#4095).

Conflict resolution kept the fork's identity, scope and its higher
dependency versions; upstream's new exports were merged in. The
recursive tsconfig include is re-applied here so nested component TS
keeps experimentalDecorators under Vite 8/rolldown. All generated
static files were regenerated from a clean tree.
myabc added a commit to opf/primer_view_components that referenced this pull request Jul 21, 2026
Syncs the fork with primer/view_components up to upstream commit
6733f3c (parent of Release Tracking primer#4098), reaching v0.51.6.

Upstream changes pulled in:
- classnames.js Set export (primer#4096): static/classnames.{js,cjs,d.ts},
  the export-css-selectors collection logic, and the package.json
  exports subpath plus files entries.
- perf(css): removed universal `*` subjects and expanded merged
  `:is()` selector lists (primer#4095).

Conflict resolution kept the fork's identity, scope and its higher
dependency versions; upstream's new exports were merged in. The
recursive tsconfig include is re-applied here so nested component TS
keeps experimentalDecorators under Vite 8/rolldown. All generated
static files were regenerated from a clean tree.

The upstream css change makes CI lint the whole text_field.pcss, which
surfaced a pre-existing false positive: nesting-selector-no-missing-
scoping-root fires on the & selectors inside the fork's
FormControl-input-width @define-mixin (the & resolves at the @mixin
include site). Silenced with a scoped stylelint-disable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants