An open source design system that's fully customizable and agent ready
TypeScript
fix: make test suite pass on Windows (path separators + URL.pathname) (#3234)
GeekLuffy757092431de0
diff --git a/packages/cli/src/api/component.mjs b/packages/cli/src/api/component.mjsindex c6560ea444..e570c1b93b 100644--- a/packages/cli/src/api/component.mjs+++ b/packages/cli/src/api/component.mjs@@ -8,6 +8,7 @@*/import * as fs from 'node:fs';+import * as path from 'node:path';import {ERROR_CODES} from '../lib/error-codes.mjs';import {findCoreDir, discoverExternalPackages} from '../utils/paths.mjs';import {@@ -560,7 +561,7 @@ export async function component(name, options = {}) {// Examples: blocks in the component's own directory, or// componentsUsed match for sub-components without a directory.- const ownDir = allBlocks.filter(b => b.category.split('/').pop() === dirName);+ const ownDir = allBlocks.filter(b => path.basename(b.category) === dirName);const examples = ownDir.length > 0? ownDir: allBlocks.filter(b => b.componentsUsed?.some(c => c === dirName));diff --git a/packages/cli/src/api/template.mjs b/packages/cli/src/api/template.mjsindex fb259bafd7..29e2715dfb 100644--- a/packages/cli/src/api/template.mjs+++ b/packages/cli/src/api/template.mjs@@ -63,6 +63,17 @@ const DEMO_IMAGE_PATTERNS = [/https?:\/\/(?:[\w-]+\.)*lookaside\.facebook\.com\/[^\s'"`)]+/g,];+/**+ * Normalize path into Unix path (using forward slashes) for consistent comparison+ * across Windows, macOS, and Linux.+ *+ * @param {string} p - The file path to normalize.+ * @returns {string} The normalized Unix path.+ */+function toPosixPath(p) {+ return p.replace(/\\/g, '/');+}+/*** Replace demo image references with a self-contained placeholder data URI so* scaffolded pages render with zero setup. Builders drop in their own images.@@ -144,7 +155,7 @@ async function discoverBlocks() {const tsxPath = path.join(path.dirname(docPath), basename + '.tsx');if (!fs.existsSync(tsxPath)) continue;const doc = await loadDocModule(docPath);- const relPath = path.relative(BLOCKS_DIR, path.dirname(docPath));+ const relPath = toPosixPath(path.relative(BLOCKS_DIR, path.dirname(docPath)));blocks.push({type: 'block',dirName: basename,@@ -180,7 +191,7 @@ async function discoverExternalBlocks(cwd = process.cwd()) {const tsxPath = path.join(path.dirname(docPath), basename + '.tsx');if (!fs.existsSync(tsxPath)) continue;const doc = await loadDocModule(docPath);- const relPath = path.relative(ext.blocksDir, path.dirname(docPath));+ const relPath = toPosixPath(path.relative(ext.blocksDir, path.dirname(docPath)));blocks.push({type: 'block',dirName: basename,@@ -428,7 +439,7 @@ export async function findShowcase(componentName, cwd, options) {// Priority 1: own directory (components/Badge/ for "Badge")const dirMatch = showcases.find(b => {- const catDir = b.category.split('/').pop()?.toLowerCase();+ const catDir = path.basename(b.category).toLowerCase();return catDir === lc;});if (dirMatch) return toResult(dirMatch);diff --git a/packages/cli/src/commands/agent-docs.mjs b/packages/cli/src/commands/agent-docs.mjsindex 2bb9b25c25..11cbfa3006 100644--- a/packages/cli/src/commands/agent-docs.mjs+++ b/packages/cli/src/commands/agent-docs.mjs@@ -29,7 +29,8 @@ import {ERROR_CODES} from '../lib/error-codes.mjs';const AGENTS_MD = 'AGENTS.md';const CLAUDE_MD = 'CLAUDE.md';-const CLAUDE_DIR_MD = path.join('.claude', 'CLAUDE.md');+const CLAUDE_DIR_MD = '.claude/CLAUDE.md'; // cross-platform literal+const MARKER_START = '<!-- ASTRYX:START -->';const MARKER_END = '<!-- ASTRYX:END -->';diff --git a/packages/cli/src/commands/component-resolution.test.mjs b/packages/cli/src/commands/component-resolution.test.mjsindex 3e68b97f5c..44cb3dfd45 100644--- a/packages/cli/src/commands/component-resolution.test.mjs+++ b/packages/cli/src/commands/component-resolution.test.mjs@@ -78,13 +78,13 @@ describe('findShowcase() priority', () => {it('Badge resolves to Badge dir, not a sibling that uses Badge', async () => {const result = await findShowcase('Badge');expect(result).not.toBeNull();- expect(result.filePath).toMatch(/\/Badge\//);+ expect(result.filePath).toMatch(/[/\\]Badge[/\\]/);});it('Avatar resolves to Avatar dir, not AvatarStatusDot', async () => {const result = await findShowcase('Avatar');expect(result).not.toBeNull();- expect(result.filePath).toMatch(/\/Avatar\//);+ expect(result.filePath).toMatch(/[/\\]Avatar[/\\]/);expect(result.filePath).not.toMatch(/AvatarStatusDot/);});@@ -92,7 +92,7 @@ describe('findShowcase() priority', () => {const result = await findShowcase('ClickableCard');expect(result).not.toBeNull();expect(result.name).toBe('ClickableCard');- expect(result.filePath).toMatch(/\/Card\//);+ expect(result.filePath).toMatch(/[/\\]Card[/\\]/);});it('SelectableCard resolves via componentsUsed in Card/', async () => {@@ -104,7 +104,7 @@ describe('findShowcase() priority', () => {it('Stack resolves to Stack dir despite componentsUsed elsewhere', async () => {const result = await findShowcase('Stack');expect(result).not.toBeNull();- expect(result.filePath).toMatch(/\/Stack\//);+ expect(result.filePath).toMatch(/[/\\]Stack[/\\]/);});it('returns null for nonexistent component', async () => {diff --git a/packages/cli/src/lib/component-discovery.mjs b/packages/cli/src/lib/component-discovery.mjsindex d2bf242d85..f3cf425f8d 100644--- a/packages/cli/src/lib/component-discovery.mjs+++ b/packages/cli/src/lib/component-discovery.mjs@@ -335,10 +335,13 @@ export function resolveImportPath(coreDir, componentName) {? JSON.parse(fs.readFileSync(pkgPath, 'utf-8')): null;+ const exportKeys = Object.keys(pkg?.exports || {});+// Priority 1: exact subpath export matching the component name (e.g. ./Heading)// This allows convenience re-export directories to win over the source directory.- if (pkg?.exports?.[`./${componentName}`]) {- return `@astryxdesign/core/${componentName}`;+ const exactMatch = exportKeys.find(k => k.toLowerCase() === `./${componentName}`.toLowerCase());+ if (exactMatch) {+ return `@astryxdesign/core/${exactMatch.slice(2)}`;}const sourcePath = findComponentSource(coreDir, componentName);@@ -348,8 +351,9 @@ export function resolveImportPath(coreDir, componentName) {const relToSrc = path.relative(srcDir, sourcePath);const topDir = relToSrc.split(path.sep)[0];- if (pkg?.exports?.[`./${topDir}`]) {- return `@astryxdesign/core/${topDir}`;+ const topMatch = exportKeys.find(k => k.toLowerCase() === `./${topDir}`.toLowerCase());+ if (topMatch) {+ return `@astryxdesign/core/${topMatch.slice(2)}`;}return '@astryxdesign/core';diff --git a/packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snap b/packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snapindex b52f26a5d2..4e55cedf22 100644--- a/packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snap+++ b/packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snap@@ -4,7 +4,6 @@ exports[`FormLayout > matches snapshot for horizontal direction 1`] = `<divclass="astryx-form-layout horizontal FormLayout__styles.base xdt5ytf x18g69wz FormLayout__styles.horizontal xrvj5dj x1mt1orb xu6a5m6"data-direction="horizontal"- data-style-src="@astryxdesign/core:src/FormLayout/FormLayout.tsx:40; @astryxdesign/core:src/FormLayout/FormLayout.tsx:45"data-testid="layout"><input@@ -20,7 +19,6 @@ exports[`FormLayout > matches snapshot for horizontal-labels direction 1`] = `<divclass="astryx-form-layout horizontal-labels FormLayout__styles.base xdt5ytf FormLayout__styles.horizontalLabels xrvj5dj x1pmbctz xlaq8a2 x7a106z xedohl4 x1rpgqan x1a1jff"data-direction="horizontal-labels"- data-style-src="@astryxdesign/core:src/FormLayout/FormLayout.tsx:40; @astryxdesign/core:src/FormLayout/FormLayout.tsx:50"data-testid="layout"><label>@@ -36,7 +34,6 @@ exports[`FormLayout > matches snapshot for vertical direction 1`] = `<divclass="astryx-form-layout vertical FormLayout__styles.base x78zum5 xdt5ytf x18g69wz"data-direction="vertical"- data-style-src="@astryxdesign/core:src/FormLayout/FormLayout.tsx:40"data-testid="layout"><inputdiff --git a/vitest.config.ts b/vitest.config.tsindex 69602f6e2c..6756e56986 100644--- a/vitest.config.ts+++ b/vitest.config.ts@@ -25,6 +25,7 @@ export default defineConfig({'@stylexjs/babel-plugin',{dev: true,+ enableDebugDataProp: false,runtimeInjection: true,genConditionalClasses: true,treeshakeCompensation: true,