fix(elizaos): use actual CLI version when rewriting workspace:* deps in scaffolded projects#6698
Conversation
…PackageJson Workspace: * references in scaffolded package.json were replaced with ^1.0.0 regardless of the installed CLI version. Read the version from the CLI own package.json at runtime (same pattern as version.ts). Export fixPackageJson and add 5 unit tests. Made-with: Cursor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| function getCliVersion(): string { | ||
| const pkgPath = path.join(__dirname, "..", "..", "package.json"); | ||
| const content = fs.readFileSync(pkgPath, "utf-8"); | ||
| const pkg = JSON.parse(content) as { version: string }; | ||
| return pkg.version; | ||
| } |
There was a problem hiding this comment.
Missing error-handling fallback (unlike
version.ts)
The sibling version.ts wraps the same path resolution in a try/catch with a fallback one directory higher. getCliVersion() has no fallback, so if the path resolution ever fails (e.g., unusual install layouts or bundler outputs that shift __dirname), fixPackageJson will throw an unhandled error and crash the CLI during elizaos create.
Consider mirroring the pattern from version.ts:
function getCliVersion(): string {
const primaryPath = path.join(__dirname, "..", "..", "package.json");
try {
const pkg = JSON.parse(fs.readFileSync(primaryPath, "utf-8")) as { version: string };
return pkg.version;
} catch {
// Fallback for unusual install layouts (mirrors version.ts)
const fallbackPath = path.join(__dirname, "..", "..", "..", "package.json");
const pkg = JSON.parse(fs.readFileSync(fallbackPath, "utf-8")) as { version: string };
return pkg.version;
}
}
Problem
elizaos createcallsfixPackageJsonto replaceworkspace:*referencesin a scaffolded project's
package.json. The replacement was hardcoded to"^1.0.0"which is already behind the current release (2.0.0-alpha.109)and will grow more stale with every release.
Users scaffolding TypeScript examples that depend on elizaos packages receive
an incorrect (stale) semver range, causing
bun install/npm installtoresolve the wrong version.
Fix
Read the version from the CLI's own
package.jsonat runtime — the sameapproach already used in
commands/version.ts.Changes
packages/elizaos/src/commands/create.ts: addgetCliVersion()helper,replace hardcoded
"^1.0.0"with`^${getCliVersion()}`, exportfixPackageJsonfor testabilitypackages/elizaos/src/__tests__/create.test.ts: 5 new unit testsTesting
Comments Outside Diff (1)
packages/elizaos/src/commands/create.ts, line 114-123 (link)getCliVersion()invoked on everyworkspace:*entrygetCliVersion()reads and parsespackage.jsonfrom disk on each loop iteration. For a scaffolded project with severalworkspace:*deps acrossdependencies,devDependencies, andpeerDependencies, this means multiple redundant file-system reads. The version can be resolved once before the loop:Reviews (1): Last reviewed commit: "fix(elizaos): replace hardcoded ^1.0.0 w..." | Re-trigger Greptile