Skip to content

fix: resolve version 0.0.0 and user CLI load failures (#788)#789

Merged
jackwener merged 1 commit intojackwener:mainfrom
Astro-Han:worktree-fix-788-version-and-shims
Apr 5, 2026
Merged

fix: resolve version 0.0.0 and user CLI load failures (#788)#789
jackwener merged 1 commit intojackwener:mainfrom
Astro-Han:worktree-fix-788-version-and-shims

Conversation

@Astro-Han
Copy link
Copy Markdown
Contributor

@Astro-Han Astro-Han commented Apr 5, 2026

Description

Fixes #788. Two regressions introduced by #784 (rootDir change from "src" to "."):

  • version.ts: single-level parent lookup for package.json broke because version.js now lives in dist/src/ instead of dist/. Added fallback to walk up one more level when package.json isn't found at the first parent.
  • discovery.ts: adapters copied to ~/.opencli/clis/ import ../../src/registry.js etc., which resolves to ~/.opencli/src/. Added src/ compat shims derived from the existing rootShims list (single source of truth, no duplicate mapping).

Related issue: #788

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Screenshots / Output

version.ts fix (prod mode):
```
$ node dist/src/version.js
version: 1.6.3
```

src/ shims generated:
```
~/.opencli/src/
errors.js
launcher.js
logger.js
registry.js
types.js
utils.js
```

Unit tests: 42 files, 496 passed, 1 skipped.

Bug 1: version.ts used a single-level parent lookup for package.json,
which broke after jackwener#784 changed rootDir from "src" to "." (version.js
now lives in dist/src/ instead of dist/).  Walk up until package.json
is found — works in both dev (src/) and prod (dist/src/).

Bug 2: adapters copied to ~/.opencli/clis/ import ../../src/registry.js
etc., which resolves to ~/.opencli/src/.  Derive src/ compat shims from
the existing rootShims list so these imports resolve correctly.
Copy link
Copy Markdown
Owner

@jackwener jackwener left a comment

Choose a reason for hiding this comment

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

LGTM. Both fixes are correct and minimal:

  1. version.ts: Walk up one more level to find package.json — handles both dev (src/) and prod (dist/src/) layouts correctly.
  2. discovery.ts: Add src/ compat shims — adapters compiled with rootDir '.' produce ../../src/registry.js imports, which resolve to ~/.opencli/src/registry.js. Creating shims there fixes the load failures.

Verified by rebuilding: dist/clis/36kr/hot.js indeed imports from ../../src/registry.js, confirming the root cause.

Closes #788, also fixes #791 (same underlying issue on Windows).

@jackwener jackwener merged commit 20957cb into jackwener:main Apr 5, 2026
11 checks passed
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.

bug: opencli --version reports 0.0.0 when installed from source + Failed to load module for user clis

2 participants