Skip to content

fix(cli): resolve bundled config and package.json relative to module#25

Merged
hcodes merged 1 commit into
typograf:mainfrom
Corvus278:fix/cli-cwd-relative-paths
Jun 26, 2026
Merged

fix(cli): resolve bundled config and package.json relative to module#25
hcodes merged 1 commit into
typograf:mainfrom
Corvus278:fix/cli-cwd-relative-paths

Conversation

@Corvus278

Copy link
Copy Markdown
Contributor

The CLI reads ./typograf.json (bundled default config) and ./package.json (for --version) relative to the current working directory. As a result the command crashes with ENOENT: no such file or directory, open './typograf.json' when run from any directory other than the package root — which is every real invocation of a globally installed CLI.

$ echo "текст" | typograf --stdin
Error: ENOENT: no such file or directory, open './typograf.json'
    at readFileSync (node:fs:440:20)
    at .../bin/utils.mjs:10:34

This was introduced when the CLI moved to ESM (6.2.0); the previous CJS version resolved these via require(.../typograf.json), which is module-relative.

Fix: resolve both paths from import.meta.url instead of CWD.

  • bin/utils.mjs — bundled typograf.json
  • bin/cli.mjspackage.json for --version

Verified the CLI now works from an arbitrary CWD (stdin processing and --version); npm test (eslint) passes.

🤖 Generated with Claude Code

CLI read './typograf.json' and './package.json' relative to the current
working directory, so it crashed with ENOENT from any directory other than
the package root. Resolve both paths from import.meta.url instead.
@Corvus278 Corvus278 force-pushed the fix/cli-cwd-relative-paths branch from 2858353 to 30bfcb0 Compare June 22, 2026 23:03
@hcodes hcodes merged commit 4e6f10d into typograf:main Jun 26, 2026
1 check passed
@hcodes

hcodes commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants