Skip to content

Add path mapping for app directory in package.json - #4099

Merged
jonrohan merged 2 commits into
mainfrom
jonrohan-patch-1
Jun 18, 2026
Merged

Add path mapping for app directory in package.json#4099
jonrohan merged 2 commits into
mainfrom
jonrohan-patch-1

Conversation

@jonrohan

Copy link
Copy Markdown
Member

What are you trying to accomplish?

PR #4096 introduced an exports map to package.json for the first time (to publish the new ./classnames subpath). Before that PR there was no exports field, so consumers could deep-import compiled component modules directly from the filesystem, e.g.:

import type {ActionMenuElement} from '@primer/view-components/app/components/primer/alpha/action_menu/action_menu_element'

Once the exports map was added, the only thing covering those deep paths is the catch-all "./*": "./*". Because that target is a plain string with no types condition, TypeScript (under moduleResolution: bundler/node16) maps the extensionless import to a literal path with no extension and can't locate the adjacent .d.ts. This broke type resolution for every @primer/view-components/app/... deep import across consumers (e.g. github-ui has ~27 such imports), surfacing as:

Cannot find module '@primer/view-components/app/components/primer/alpha/action_menu/action_menu_element' or its corresponding type declarations.

This PR restores type resolution for deep app/* imports by adding a conditional subpath that exposes the types, import, and default conditions, placed before the catch-all so it takes precedence:

"exports": {
  ".": {
    "types": "./app/components/primer/primer.d.ts",
    "import": "./app/components/primer/primer.js",
    "require": "./app/assets/javascripts/primer_view_components.js"
  },
  "./classnames": {
    "types": "./static/classnames.d.ts",
    "import": "./static/classnames.js",
    "require": "./static/classnames.cjs"
  },
  "./app/*": {
    "types": "./app/*.d.ts",
    "import": "./app/*.js",
    "default": "./app/*.js"
  },
  "./*": "./*"
}

Integration

No production runtime/behavior change — this only affects how the published package's subpaths resolve for type-checkers and bundlers. It restores the pre-#4096 ability for consumers to deep-import app/* modules with full type information. Consumers (e.g. github-ui) require no code changes once a version including this fix is published.

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.

This is an additive exports subpath that only widens resolution back to pre-#4096 behavior. It is trivially reverted and verifiable via tsc --traceResolution.

What approach did you choose and why?

I chose to add an explicit ./app/* conditional subpath rather than change the catch-all "./*" because:

  • The types condition is required for TypeScript to map an extensionless deep import to its .d.ts; a bare string target ("./*": "./*") cannot express conditions.
  • Scoping the conditional pattern to ./app/* keeps the change narrow and intentional (the published files list only ships app/** JS/d.ts plus static/*), while leaving the catch-all in place for any other static asset paths.
  • Ordering matters: the more specific ./app/* pattern is listed before ./* so it wins for app/... imports.

I verified the fix against the installed package with a resolution trace:

Matched 'exports' condition 'types'.
Using 'exports' subpath './app/*' with target './app/components/primer/alpha/action_menu/action_menu_element.d.ts'.
... was successfully resolved

Anything you want to highlight for special attention from reviewers?

  • Please confirm the . subpath types/import/require targets match the canonical entry points (I mirrored main/module/types from the existing package.json).
  • Worth double-checking whether any consumers rely on deep-importing non-app/ paths through "./*"; those remain covered by the unchanged catch-all.
  • Consider whether this warrants a patch changeset framed as a regression fix for Add classnames.js Set export to the CSS build #4096.

Accessibility

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Lookbook)
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Copilot AI review requested due to automatic review settings June 18, 2026 23:39
@jonrohan
jonrohan requested a review from a team as a code owner June 18, 2026 23:39
@jonrohan
jonrohan requested a review from siddharthkp June 18, 2026 23:39
@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5bf2e1d

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 Patch

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

Add path mapping for the app directory to improve module resolution.

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 updates the published npm package subpath exports to restore TypeScript type resolution for deep @primer/view-components/app/... imports after an exports map was introduced previously.

Changes:

  • Add an ./app/* conditional exports pattern that provides types/import/default targets for deep app/** imports.
  • Add a patch changeset to publish the fix.
Show a summary per file
File Description
package.json Adds an exports subpath for ./app/* intended to restore TypeScript resolution for deep app/** imports.
.changeset/sunny-trams-turn.md Adds a patch changeset to release the package.json exports adjustment.

Copilot's findings

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

Comment thread package.json
Comment on lines +19 to 24
"./app/*": {
"types": "./app/*.d.ts",
"import": "./app/*.js",
"default": "./app/*.js"
},
"./*": "./*"
@jonrohan
jonrohan merged commit 91c1e26 into main Jun 18, 2026
32 checks passed
@jonrohan
jonrohan deleted the jonrohan-patch-1 branch June 18, 2026 23:55
@primer primer Bot mentioned this pull request Jun 18, 2026
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.

2 participants