Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/uniwind/src/vite/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ type UniwindConfig = {
dtsFile?: string
}

const dirname = typeof __dirname !== 'undefined' ? __dirname : import.meta.dirname
const componentPath = path.resolve(
import.meta.dirname,
dirname,
'../module/components/web/index.js',
)
Comment on lines +17 to 21

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check Node.js engine requirements in package.json
echo "=== Checking Node.js engine requirements ==="
if [ -f "package.json" ]; then
    jq '.engines.node // "Not specified"' package.json
fi

# Also check monorepo root and specific package
echo -e "\n=== Checking packages/uniwind/package.json ==="
if [ -f "packages/uniwind/package.json" ]; then
    jq '.engines.node // "Not specified"' packages/uniwind/package.json
fi

# Check for other uses of import.meta.dirname in the codebase
echo -e "\n=== Checking for other import.meta.dirname usage ==="
rg -n 'import\.meta\.dirname' --type ts --type js 2>/dev/null | head -20

# Check the actual file to see the full context
echo -e "\n=== Full context of packages/uniwind/src/vite/vite.ts ==="
if [ -f "packages/uniwind/src/vite/vite.ts" ]; then
    wc -l packages/uniwind/src/vite/vite.ts
fi

Repository: uni-stack/uniwind

Length of output: 574


🏁 Script executed:

#!/bin/bash
# Check for fileURLToPath usage in the codebase to see if it's already imported/used
echo "=== Checking for fileURLToPath usage ==="
rg -n 'fileURLToPath' --type ts --type js 2>/dev/null

# Check if there are any Node.js version constraints mentioned
echo -e "\n=== Checking Vite and related dependency versions ==="
if [ -f "package.json" ]; then
    jq '.dependencies.vite, .devDependencies.vite // "Not found"' package.json
fi

# Check the actual diff/change to understand what was modified
echo -e "\n=== Checking git history for recent changes to this file ==="
git log --oneline -n 10 -- packages/uniwind/src/vite/vite.ts 2>/dev/null || echo "Git history not available"

Repository: uni-stack/uniwind

Length of output: 283


🏁 Script executed:

#!/bin/bash
# Get full content of the file to verify the fix
cat -n packages/uniwind/src/vite/vite.ts | head -30

Repository: uni-stack/uniwind

Length of output: 1156


Use import.meta.url for broader Node.js compatibility and address duplicate pattern in css/index.ts.

While the CJS/ESM detection is correct for Storybook 9, import.meta.dirname requires Node.js 20.11.0+. Since no Node.js version is constrained in package.json, this introduces a portability risk: ESM code on older Node.js would get undefined and fail with the same error. The same pattern exists in packages/uniwind/src/css/index.ts:7.

Use import.meta.url instead:

import { fileURLToPath } from 'url'
-const dirname = typeof __dirname !== 'undefined' ? __dirname : import.meta.dirname
+const dirname = typeof __dirname !== 'undefined' 
+    ? __dirname 
+    : path.dirname(fileURLToPath(import.meta.url))

This works across all Node.js versions supporting ESM. Apply the same fix to packages/uniwind/src/css/index.ts.

Additionally, verify this resolves the Storybook 9 issue by testing with the reproduction from issue #259.

🤖 Prompt for AI Agents
In packages/uniwind/src/vite/vite.ts around lines 17 to 21, replace the current
__dirname / import.meta.dirname detection with a robust ESM-compatible approach
using fileURLToPath(import.meta.url): import fileURLToPath from 'url', compute
dirname = typeof __dirname !== 'undefined' ? __dirname :
path.dirname(fileURLToPath(import.meta.url)), then use that dirname in
path.resolve to build componentPath; apply the same change to
packages/uniwind/src/css/index.ts at the same pattern (line ~7) so both modules
use fileURLToPath(import.meta.url) fallback for broader Node.js compatibility
and then run the reproduction from issue #259 to verify Storybook 9 is resolved.


Expand Down