Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): resolve docs.mjs package dir with fileURLToPath so it works on Windows (#3331)

Md Shahrier Islam Arham745e813fa631
diff --git a/.changeset/docs-mjs-windows-path.md b/.changeset/docs-mjs-windows-path.md
new file mode 100644
index 0000000000..07029aa8ba
--- /dev/null
+++ b/.changeset/docs-mjs-windows-path.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] docs.mjs: resolve the package directory with fileURLToPath so component docs work on Windows, where URL.pathname yields drive-letter paths like /D:/... that made --list silently print nothing and single-component lookup crash with ENOENT (#3331)
+@arham766
diff --git a/packages/core/docs.mjs b/packages/core/docs.mjs
index e5fa6b1489..9dd0aa916a 100644
--- a/packages/core/docs.mjs
+++ b/packages/core/docs.mjs
@@ -12,9 +12,9 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
-import {pathToFileURL} from 'node:url';
+import {fileURLToPath, pathToFileURL} from 'node:url';
-const coreDir = path.dirname(new URL(import.meta.url).pathname);
+const coreDir = path.dirname(fileURLToPath(import.meta.url));
const srcDir = path.join(coreDir, 'src');
// ── Discovery ────────────────────────────────────────────────────────
diff --git a/packages/core/src/docs-script.test.mjs b/packages/core/src/docs-script.test.mjs
new file mode 100644
index 0000000000..c57694d27d
--- /dev/null
+++ b/packages/core/src/docs-script.test.mjs
@@ -0,0 +1,50 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Subprocess smoke tests for the zero-dependency docs script.
+ *
+ * `docs.mjs` resolves the package directory from `import.meta.url`. Using
+ * `new URL(...).pathname` there breaks on Windows (drive-letter paths come
+ * back as `/D:/...`), which made `--list` print nothing and component
+ * lookups crash with ENOENT. These tests spawn the script as a real
+ * subprocess from a neutral cwd, so resolution can only come from the
+ * module URL, and assert it finds the component catalog on every platform.
+ */
+
+import {describe, it, expect} from 'vitest';
+import {spawnSync} from 'node:child_process';
+import * as os from 'node:os';
+import * as path from 'node:path';
+import {fileURLToPath} from 'node:url';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+const DOCS_SCRIPT = path.resolve(__dirname, '..', 'docs.mjs');
+
+function runDocs(args) {
+ return spawnSync(process.execPath, [DOCS_SCRIPT, ...args], {
+ cwd: os.tmpdir(),
+ encoding: 'utf8',
+ timeout: 20_000,
+ env: {...process.env, FORCE_COLOR: '0'},
+ });
+}
+
+describe('docs.mjs component discovery', () => {
+ it('--list discovers the component catalog', () => {
+ const r = runDocs(['--list']);
+ expect(r.error).toBeUndefined();
+ expect(r.signal).toBeNull();
+ expect(r.status).toBe(0);
+ expect(r.stdout).toMatch(/\bButton\b/);
+ expect(r.stdout).toMatch(/\bDialog\b/);
+ });
+
+ it('renders docs for a single component', () => {
+ const r = runDocs(['Button']);
+ expect(r.error).toBeUndefined();
+ expect(r.signal).toBeNull();
+ expect(r.status).toBe(0);
+ expect(r.stdout).toMatch(/^# Button$/m);
+ expect(r.stdout).toMatch(/## Props/);
+ });
+});