Skip to content

feat(cli-build): derive vendor import-map entry points from package.json exports#1222

Draft
stipsan wants to merge 2 commits into
mainfrom
cursor/derive-vendor-exports-from-package-json-5804
Draft

feat(cli-build): derive vendor import-map entry points from package.json exports#1222
stipsan wants to merge 2 commits into
mainfrom
cursor/derive-vendor-exports-from-package-json-5804

Conversation

@stipsan

@stipsan stipsan commented Jun 8, 2026

Copy link
Copy Markdown
Member

Description

Vendor import-map entry points for react, react-dom, and styled-components were hardcoded per package/version/subpath in buildVendorDependencies.ts. When upstream packages add new exports subpaths, studios cannot use them until we manually update the table and cut a CLI release.

This PR resolves vendor entry points automatically from each package's package.json:

  • react / react-dom: enumerate subpaths from exports, resolving targets with browser bundler conditions (browserimportdefault).
  • styled-components: special-case fallback using the webpack-style top-level browser field (picks module, then applies the browser remap), since it does not yet use exports.
  • CJS named exports: wrapper entries (e.g. react/index.jscjs/react.production.js) are followed when extracting named exports for the vendor build plugin.

Version range checks remain in place; only the subpath table is derived dynamically.

Fixes #1209

What to review

  • resolveVendorEntryPoints.ts — export resolution logic and styled-components browser-field fallback
  • resolveCjsNamedExportsSource.ts — production CJS wrapper following for named-export extraction
  • buildVendorDependencies.ts — wiring: version validation + dynamic entry-point resolution
  • New unit tests against the installed react/react-dom/styled-components package.json files
  • Existing buildVendorDependencies.test.ts integration tests (named exports, external require rewrite, styled-components)

Testing

  • resolveVendorEntryPoints.test.ts — export condition resolution, react/react-dom/styled-components entry-point derivation
  • resolveCjsNamedExportsSource.test.ts — CJS wrapper following for named-export extraction
  • buildVendorDependencies.test.ts — end-to-end vendor build (react, react-dom, styled-components named exports + no runtime require shims)
  • pnpm check:types --filter=@sanity/cli-build
  • pnpm lint in @sanity/cli-build
  • pnpm knip --workspace @sanity/cli-build
Open in Web Open in Cursor 

cursoragent and others added 2 commits June 8, 2026 12:35
…son exports

Replace hardcoded VENDOR_IMPORTS subpath tables with resolution from each
package's package.json exports, applying browser bundler conditions
(browser/import/default). styled-components keeps a browser-field fallback
since it does not yet use exports. CJS wrapper entries are followed when
extracting named exports for the vendor build plugin.

Fixes #1209
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @sanity/cli

Compared against main (cdd349bf)

@sanity/cli

Metric Value vs main (cdd349b)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 11.13 MB -
Bundled (gzip) 2.10 MB -
Import time 863ms +2ms, +0.3%

bin:sanity

Metric Value vs main (cdd349b)
Internal (raw) 1023 B -
Internal (gzip) 486 B -
Bundled (raw) 9.87 MB -
Bundled (gzip) 1.77 MB -
Import time 1.95s -2ms, -0.1%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against main (cdd349bf)

Metric Value vs main (cdd349b)
Internal (raw) 96.3 KB -
Internal (gzip) 22.7 KB -
Bundled (raw) 21.70 MB -
Bundled (gzip) 3.45 MB -
Import time 772ms +4ms, +0.6%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — create-sanity

Compared against main (cdd349bf)

Metric Value vs main (cdd349b)
Internal (raw) 908 B -
Internal (gzip) 483 B -
Bundled (raw) 931 B -
Bundled (gzip) 491 B -
Import time ❌ ChildProcess denied: node -
Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli-build/src/actions/build/buildVendorDependencies.ts 73.2% (+ 2.1%)
packages/@sanity/cli-build/src/actions/build/resolveCjsNamedExportsSource.ts 100.0% (new)
packages/@sanity/cli-build/src/actions/build/resolveVendorEntryPoints.ts 87.5% (new)

Comparing 3 changed files against main @ cdd349bffd310e9d2a1225e298a9ef46d83508be

Overall Coverage

Metric Coverage
Statements 79.9% (- 0.5%)
Branches 71.6% (- 0.3%)
Functions 78.7% (- 0.3%)
Lines 80.3% (- 0.5%)

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.

Derive vendor import-map entry points from package.json exports instead of hardcoding

2 participants