[Bug] build: Astryx source is compiled as product code on Windows (babel + postcss plugins match '/' paths)
Description
On Windows, @astryxdesign/build/babel and @astryxdesign/build/postcss never recognise Astryx's own source files as library files. In the documented "Next.js Setup (webpack)", Astryx components are therefore compiled with the product prefix (x) and their rules are emitted in @layer product instead of @layer astryx-base.
Both plugins classify a file with a substring match against forward-slash patterns:
babel.js:LIBRARY_PATTERNSand the match:libraryPatterns.some(p => filename.includes(p))index.js:LIBRARY_PATTERNSand the match, on paths built withpath.normalize(path.resolve(cwd, f))
On Windows, Babel's state.filename and path.normalize both give backslash paths, so 'node_modules/@astryxdesign/' never matches:
const path = require('node:path');
const f = path.win32.normalize(path.win32.resolve('C:\\app', 'node_modules/@astryxdesign/core/src/Button.tsx'));
// f === 'C:\\app\\node_modules\\@astryxdesign\\core\\src\\Button.tsx'
f.includes('node_modules/@astryxdesign/'); // false
Components still render, because both plugins misclassify the same way and class names agree. But the layer order is reset < astryx-base < astryx-theme < product, so Astryx's base rules now sit above astryx-theme, which is the case the header comment says "would break theme overrides".
next.js already handles separators (posix(), realpath + path.sep), and the Vite and Turbopack routes don't go through this match. No CI job builds this package on Windows; the only Windows workflow is cli-global-mode-smoke.yml.
Suggested fix: convert to posix before matching (filename.split(path.sep).join('/')) in both plugins, or classify against the realpaths of the installed packages the way next.js does. A Windows leg for the build tests would keep it fixed.
Reproduction
- On Windows, set up a Next.js app per "Next.js Setup (webpack)" in
packages/build/README.md:@astryxdesign/build/babelinbabel.config.jsand@astryxdesign/build/postcssinpostcss.config.js. - Run a webpack build and open the generated CSS.
- Expected: Astryx component rules use
astryx-prefixed classes inside@layer astryx-base. - Actual: they use
x-prefixed classes inside@layer product, and theme overrides of component styles no longer apply.
I found this by reading the code and checking the matcher in isolation (above); I haven't run the full Next.js build on Windows.
Astryx Version
@astryxdesign/[email protected] (code checked on main at 16fe6a8)
Environment
Windows (any), Node 22+, Next.js with webpack (not Turbopack)
I'll take this one. Plan: normalize filenames to posix separators before the LIBRARY_PATTERNS substring match in both packages/build/src/babel.js and packages/build/src/index.js (same approach next.js already uses), so backslash Windows paths match node_modules/@astryxdesign/ again. I'll add a regression test feeding Windows-style paths through the matcher and run the build package tests before opening a PR.
(Posted by Cindy's agent.) Thanks @richm-spp for tracking this down. A fix is in review in #11847 by @jaideepkrishna2008-ui; it makes the build plugins treat Windows paths like POSIX ones, so Astryx source is no longer compiled as product code. We'll update here when it lands.
🤖 (Posted by Cindy's agent.) Fixed by #11847, now merged, thanks to @jaideepkrishna2008-ui: the build tooling normalizes Windows path separators before matching library paths, so Astryx source is no longer treated as product code on Windows. Thanks for the detailed report, @richm-spp! It ships in the next release.