[PF-25] Fix planforge init when installed via npm (templates path + bundle templates in package) - #37
Merged
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Fix
planforge initfailing after installing the published npm package (e.g. global install). The CLI was resolving the templates path to the Node/nvm install directory instead of the package directory, and the published tarball did not include thetemplatesfolder.Description
Root cause
getTemplatesRoot()used a fixed “4 levels up” fromdist/utils, which in a monorepo points to repo root but when installed globally (e.g. under nvm) points to the Node version root (e.g.…\nvm\v22.20.0\templates\), so the template file was not found.package.jsonfilesdid not includetemplates, so the npm package did not ship template files.Changes
packages/cli-js/src/utils/paths.ts:getTemplatesRoot()now resolves relative to the package root (two levels up fromdist/utils), so it works both in the monorepo (after build) and when installed from npm.packages/cli-js/scripts/copy-templates.js(new): Copies repo-roottemplates/intopackages/cli-js/templates/at build time so the published package contains templates (npm only includes files under the package directory).packages/cli-js/package.json: Added"templates"tofiles; extendedbuildscript with&& node scripts/copy-templates.jsaftertsc..gitignore: Addedpackages/cli-js/templatesso the build-time copy is not committed.Unchanged
templates/remains the single source of truth;check:templatesstill validates against it before build.How to test
cd packages/cli-js && pnpm run build. Confirmpackages/cli-js/templatesis created and contains e.g.config/default-both.json.npm install -g <path-to-planforge>/packages/cli-js(or publish andnpm i -g planforge). Runplanforge initand confirm it completes without “Missing or invalid template” and thatplanforge.jsonis created.node -e "const { getTemplatesRoot } = require('./packages/cli-js/dist/utils/paths.js'); const fs = require('fs'); const p = require('path'); console.log(getTemplatesRoot(), fs.existsSync(p.join(getTemplatesRoot(), 'config', 'default-both.json')));"from repo root and confirm the path is underpackages/cli-jsand the file exists.Review Requirement
getTemplatesRoot()semantics: two levels up fromdist/utilsis the package root in both dev and installed layouts.copy-templates.jsruns frompackages/cli-js(script location) and that repo root is correctly derived (__dirname→ scripts → cli-js → packages → repo root = three levels up from scripts).Additional Info