Description
Running format-css via pnpm produces no output and exits with code 0. The file is silently left empty. The library itself works correctly when imported directly.
Steps to reproduce
Works
node -e "import('@projectwallace/format-css').then(({format}) => console.log(format('a{color:red}')))"
Produces no output, exits 0
echo "a { color: red }" | format-css
format-css styles.css
Root cause
The CLI entry point guards execution with:
if (process.argv[1] === import.meta.filename)
Under pnpm, the bin wrapper (node_modules/.bin/format-css) invokes the script
with an unresolved path:
process.argv[1] → /project/node_modules/@projectwallace/format-css/dist/cli.mjs
import.meta.filename → /project/node_modules/.pnpm/@projectwallace+format-css@3.1.2/node_modules/@projectwallace/format-css/dist/cli.mjs
These never match, so run() is never called.
Fix
Normalize process.argv[1] before comparing:
import { realpathSync } from 'node:fs'
if (realpathSync(process.argv[1]) === import.meta.filename)
Description
Running format-css via pnpm produces no output and exits with code 0. The file is silently left empty. The library itself works correctly when imported directly.
Steps to reproduce
Works
node -e "import('@projectwallace/format-css').then(({format}) => console.log(format('a{color:red}')))"Produces no output, exits 0
Root cause
The CLI entry point guards execution with:
Under pnpm, the bin wrapper (
node_modules/.bin/format-css) invokes the scriptwith an unresolved path:
These never match, so
run()is never called.Fix
Normalize
process.argv[1]before comparing: