Skip to content

CLI produces no output when invoked via pnpm #213

@bartveneman

Description

@bartveneman

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions