Skip to content

test: stop relying on pnpm's NODE_PATH in build and core tests - #6372

Merged
cixzhang merged 4 commits into
facebook:mainfrom
Han5991:chore/declare-shim-only-requires
Oct 5, 2026
Merged

cixzhang merged 4 commits into
facebook:mainfrom
Han5991:chore/declare-shim-only-requires

Conversation

@Han5991

@Han5991 Han5991 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

pnpm's command shims put node_modules/.pnpm/node_modules on NODE_PATH. Under vitest, that lets three tests resolve packages their own package does not declare, and each fails when run without it:

  • packages/build/src/next.test.mjs → enhanced-resolve (fix(build): resolve app imports of astryx to source in withAstryx #5932), which reached build only through next
  • ButtonGroup.test.tsx → @babel/preset-typescript, passed to Babel by bare name and looked up from the cwd (the repo root)
  • Selector.source-build.test.mjs → next (as next/babel), which core does not declare

The shipped @astryxdesign/build side of this is covered by #6605. This PR is limited to the tests.

Intended invariant

A package resolves only what it declares (#5327).

Change

  • Declare enhanced-resolve as a build dev dependency. The lockfile gains an importer entry and no new package versions.
  • ButtonGroup.test.tsx resolves its Babel presets from core, which declares them.
  • Selector.source-build.test.mjs no longer runs next/babel. It uses core's TypeScript and React presets plus a small plugin that lowers arrows to function expressions, which is all Selector's linePad helper breaks any consumer that runs next/babel over the package source #5464 needs.
  • vite.build.test.ts checks for -webkit-user-select, a prefix only the lightningcss pass adds. The old -webkit- check also matched the -webkit-box-orient authored in source.

Evidence

  • Failure before the change: without NODE_PATH, the three tests fail with Cannot find module 'enhanced-resolve', Cannot find module '@babel/preset-typescript', and Cannot find package 'next'. With the lightningcss pass forced to skip, the old vite assertion stays green.
  • Success after the change: all four tests pass without NODE_PATH. With the pass forced to skip, the new vite assertion fails. With Selector's linePad helper breaks any consumer that runs next/babel over the package source #5464's linePad helper restored, the Selector test still fails with Unsupported expression: FunctionExpression. Across all 226 core files that call stylex.create, next/babel and the new pipeline fail the same set: none.
  • Product/runtime behavior verified unchanged: only tests and a dev dependency change.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm install --frozen-lockfile
  • vitest run directly with node node_modules/vitest/vitest.mjs and NODE_PATH unset (the pnpm shim always sets it): packages/build/src (64 passed), ButtonGroup.test.tsx, Selector.source-build.test.mjs
  • Each test's main version run the same way, to confirm the failures above
  • pnpm -F @astryxdesign/core typecheck, eslint and prettier on the changed files, and check:repo (commit hook)

@vercel

vercel Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 25, 2026 7:45am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 19, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Sep 19, 2026
Han5991 added a commit to Han5991/astryx that referenced this pull request Sep 19, 2026
Addresses the review on facebook#6372.

- ./postcss required postcss only to parse its generated CSS. It now passes
  replaceWith() a string, which the host's own postcss parses, so both the
  require and the optional peer the earlier commit declared go away.
- ./vite required lightningcss and browserslist from its own location, where
  neither is declared, and its try/catch turned the miss into a silently
  skipped pass. It now resolves both from @stylexjs/unplugin, which depends on
  them and whose output that pass reproduces. The test guarding the pass looked
  for any -webkit- prefix, which an authored one always satisfied. It now
  checks a prefix only the pass adds, and fails on the old code without
  NODE_PATH.
- apps/sandbox declares autoprefixer. build's postcss() config adds it, and
  Next resolves it from the app.
Han5991 added a commit to Han5991/astryx that referenced this pull request Sep 19, 2026
Addresses the review on facebook#6372.

- ./postcss required postcss only to parse its generated CSS. It now passes
  replaceWith() a string, which the host's own postcss parses, so both the
  require and the optional peer the earlier commit declared go away.
- ./vite required lightningcss and browserslist from its own location, where
  neither is declared, and its try/catch turned the miss into a silently
  skipped pass. It now resolves both from @stylexjs/unplugin, which depends on
  them and whose output that pass reproduces. The test guarding the pass looked
  for any -webkit- prefix, which an authored one always satisfied. It now
  checks a prefix only the pass adds, and fails on the old code without
  NODE_PATH.
- apps/sandbox declares autoprefixer. build's postcss() config adds it, and
  Next resolves it from the app.
@Han5991 Han5991 changed the title chore(deps): declare the three requires that resolved only through NODE_PATH fix(deps): stop relying on pnpm's NODE_PATH for undeclared packages Sep 19, 2026
@Han5991
Han5991 marked this pull request as ready for review September 19, 2026 05:54
github-actions Bot added a commit that referenced this pull request Sep 19, 2026
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

25 of 420 shot(s) changed. View the report

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Chat Full AI Chat probe light 42,708
Chat Empty State probe light 42,708
Chat Full AI Chat probe dark 41,786
Chat Empty State probe dark 41,786
Slider Default probe light 15,617
Slider Default probe dark 15,615
Chat With Attachments probe light 12,964
Chat With Attachments probe dark 12,114
InputGroup With Typeahead probe light 11,012
InputGroup With Typeahead probe dark 9,189
ComplexSelector Tree list with search probe light 6,245
TextArea Vertical Form Alignment probe light 5,634
ComplexSelector Tree list with search probe dark 5,602
TextArea Vertical Form Alignment probe dark 5,047
ComplexSelector Fruit ripeness selector neutral light 4,007
ComplexSelector Fruit ripeness selector neutral dark 3,825
ToggleButton Group Single probe dark 1,538
ToggleButton Group Single probe light 1,538
MediaTheme On Dark neutral dark 838
Banner Collapsible Content (Expanded) probe dark 92

and 5 more.

Chat — Full AI Chat — probe light
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame
Chat — Empty State — probe light
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame
Chat — Full AI Chat — probe dark
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot

astracat-bot Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Sep 25, 2026, 4:13 PM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change makes each package resolve only what it declares, so strict installs stop breaking: the PostCSS entry hands the host parser a CSS string, the Vite entry resolves lightningcss/browserslist from @stylexjs/unplugin, the missing enhanced-resolve/autoprefixer/next declarations are added with no new lockfile versions, and the dead lexical$ alias is removed. That all looks right.

One thing to fix before approval: the CLI MultiSelectorColumnVisibilitySelector template drops its formatValue prop (plus a doc tweak), which changes the generated block's trigger text from "N columns shown" to the component default "N selected". It's unrelated to this fix and isn't mentioned in the PR description, so please revert those two template files here and move that copy change to its own change — or explain in the description why it belongs here.

Also non-blocking: core pins next exactly at a preview release while the sandbox tracks ^15; fine for tests, but consider a caret or catalog entry so it doesn't rot.

[Automated review]

@Han5991

Han5991 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! This PR doesn't touch MultiSelectorColumnVisibilitySelector. The template is the same at the branch point, the PR head, and current main, and none of them has formatValue.

I think the diff used the PR's recorded base.sha (7ccd6c8a47c, #3354), which added formatValue and was later reverted in #6373. A two-dot diff from there makes #3354's change look like this PR removed it. git diff --stat 7ccd6c8a47c bc27ba78e00 shows exactly those two files. Against the merge base the template is untouched, so there's nothing to revert here.

@Han5991

Han5991 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

On the non-blocking next note: core no longer depends on next (b182bf4), so there's no preview pin left to drift.

Selector.source-build.test.mjs guards only #5464: a consumer preset lowering module-scope arrows to function expressions, which StyleX can't evaluate. Instead of next/babel, it now runs the TS/React presets core already declares plus a small plugin that lowers arrows.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This fix makes each package resolve only what it declares, so strict installs stop breaking: the PostCSS entry hands the host parser a CSS string instead of requiring its own postcss, the Vite entry resolves lightningcss/browserslist from @stylexjs/unplugin, enhanced-resolve and autoprefixer are now declared where they are resolved, core tests resolve their Babel presets from core, and the Selector source-build test guards the arrow-lowering case without needing next/babel. The dead sandbox lexical$ alias is also removed, and the lockfile adds no new package versions.

The two points from the earlier review are addressed in this revision: the CLI template files are not changed by this PR (that difference came from the recorded base), and core no longer depends on next. With the stronger Vite test checking a prefix only the lightningcss pass adds, this looks ready to approve.

[Automated review]

@cixzhang

Copy link
Copy Markdown
Contributor

Thanks @Han5991 for tracking down the strict-resolution / NODE_PATH leaks and for strengthening the regression coverage here.

We validated the published-package path separately and landed #6605, which now owns the consumer-facing @astryxdesign/build correction: package-owned Autoprefixer, Browserslist, and Lightning CSS; host PostCSS parsing; and a packed-consumer regression test.

Could you rebase this PR onto current main and trim the superseded overlap? The remaining independent pieces worth keeping are:

  • declare enhanced-resolve as a direct Build dev dependency for next.test.mjs;
  • resolve the Babel presets in ButtonGroup.test.tsx from Core, which declares them;
  • keep the focused Selector source-build test that replaces next/babel with the declared presets plus arrow lowering.

The Build PostCSS/Vite ownership changes and Build changeset are superseded by #6605. The sandbox next.config.mjs is gone on current main, and its Autoprefixer dependency is already present there, so those changes can drop too. The stronger Vite prefix assertion is fine to retain, although the packed test now covers that behavior end to end.

Once rebased, we’ll let fresh CI and CodeBunny run on the new head and re-review the remaining change. Thanks again!

…DE_PATH

After facebook#5327 made node_modules strict, packages/build/src/next.test.mjs kept
resolving enhanced-resolve (facebook#5932) without a declaration: it arrives only
transitively through next, and pnpm's vitest shim puts
node_modules/.pnpm/node_modules on NODE_PATH, which require folds in. Run
without it, the test fails with MODULE_NOT_FOUND.

Declare it as a build dev dependency at the version the lockfile already
carries, so the lockfile gains an importer entry and no new package
versions.

The other two requires this commit first declared are covered elsewhere:
facebook#6605 has ./postcss let the host's postcss parse its CSS, and facebook#6627
removed the sandbox's next.config.mjs.
ButtonGroup.test.tsx and Selector.source-build.test.mjs hand Babel bare preset
names. Babel looks those up from the cwd -- the repo root, which declares none
of them -- so they resolved only through the node_modules/.pnpm/node_modules
entry pnpm's vitest shim puts on NODE_PATH. Without it, the first fails on
@babel/preset-typescript and the second on next.

Resolve each preset from the test's own package instead. core already declares
both Babel presets; it now declares next too, at the 16.3.0-preview.5 the test
was already running against, so the lockfile reuses the existing snapshot.
postProcessCss catches any failure and returns the CSS unprocessed, so
the test guarding that pass has to see something only the pass produces.
It looked for any -webkit- prefix, which the -webkit-box-orient authored
in source always satisfies: with the pass forced to skip, it stays green.
Check for -webkit-user-select, which only the pass adds and which fails
when it is skipped.

This commit first also had ./postcss and ./vite resolve only what build
can reach itself. facebook#6605 covers that, along with a packed-consumer test of
the same pass; this keeps the in-repo build test honest too.
The Selector source-build test guards one thing: a consumer preset
lowering module-scope arrows to function expressions, which StyleX
cannot evaluate (facebook#5464). A plugin that does only that reproduces it, so
core no longer needs next, and there is no exact preview pin to drift
from docsite's.

With linePad restored, the test still fails with facebook#5464's error
(Unsupported expression: FunctionExpression). Across all 226 core files
that call stylex.create, next/babel and this pipeline fail the same set:
none.
@Han5991
Han5991 force-pushed the chore/declare-shim-only-requires branch from b182bf4 to 0dc1aec Compare September 25, 2026 07:38
@Han5991 Han5991 changed the title fix(deps): stop relying on pnpm's NODE_PATH for undeclared packages test: stop relying on pnpm's NODE_PATH in build and core tests Sep 25, 2026
@Han5991

Han5991 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @cixzhang, and for landing #6605. I rebased onto current main and trimmed the overlap:

  • 30e8e0a now declares only enhanced-resolve as a Build dev dependency.
  • 409afd7 and b182bf4 (Core's Babel presets, and the Selector test's arrow lowering in place of next/babel) apply unchanged.
  • bc27ba7 keeps only the stronger Vite assertion. With the lightningcss pass forced to skip, the old -webkit- check still passes and the new one fails, so the in-repo build test catches it alongside the packed test.
  • Dropped: e3275fa and 545036be (the changeset) and the rest of bc27ba7, superseded by fix(build): own packed consumer dependencies #6605; a576352 and 39c3c5b (the sandbox's lexical alias), made moot by build(sandbox): migrate static export from Next to Vite #6627.

I updated the description to match.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change stops the build and core tests from relying on pnpm's NODE_PATH shim, so each package resolves only what it declares. The build package now declares the enhanced-resolve its Next.js test requires (the lockfile only gains an importer entry, with no new package versions), the ButtonGroup and Selector tests resolve their Babel presets from the core package that declares them, and the Selector source-build test replaces next/babel with those presets plus a small plugin that lowers arrows — which is the effect the regression guard actually needs. The Vite build test is also stronger: it now checks for a vendor prefix only the lightningcss pass adds, instead of one that was already authored in source.

No public API or product behavior changes, and the earlier template and next-pin points do not apply to this revision — no template files are touched and core no longer depends on next. This looks ready to approve.

[Automated review]

@cixzhang
cixzhang enabled auto-merge (squash) October 5, 2026 14:44
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Oct 5, 2026
@cixzhang
cixzhang merged commit b0d1e92 into facebook:main Oct 5, 2026
43 checks passed
@Han5991
Han5991 deleted the chore/declare-shim-only-requires branch October 5, 2026 15:50

This branch was successfully deployed

1 active deployment
Preview — 0dc1aece Deployed Sep 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants