Skip to content

[PF-25] Fix planforge init when installed via npm (templates path + bundle templates in package) - #37

Merged
chucoding merged 2 commits into
developfrom
bugfix/PF-25
Mar 15, 2026
Merged

[PF-25] Fix planforge init when installed via npm (templates path + bundle templates in package)#37
chucoding merged 2 commits into
developfrom
bugfix/PF-25

Conversation

@chucoding

Copy link
Copy Markdown
Owner

Purpose

Fix planforge init failing 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 the templates folder.

Description

  • Root cause

    • getTemplatesRoot() used a fixed “4 levels up” from dist/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.json files did not include templates, 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 from dist/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-root templates/ into packages/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" to files; extended build script with && node scripts/copy-templates.js after tsc.
    • .gitignore: Added packages/cli-js/templates so the build-time copy is not committed.
  • Unchanged

    • Repo-root templates/ remains the single source of truth; check:templates still validates against it before build.

How to test

  1. In the repo: cd packages/cli-js && pnpm run build. Confirm packages/cli-js/templates is created and contains e.g. config/default-both.json.
  2. From another directory (e.g. a test project): npm install -g <path-to-planforge>/packages/cli-js (or publish and npm i -g planforge). Run planforge init and confirm it completes without “Missing or invalid template” and that planforge.json is created.
  3. Optional: Run 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 under packages/cli-js and the file exists.

Review Requirement

  • Confirm getTemplatesRoot() semantics: two levels up from dist/utils is the package root in both dev and installed layouts.
  • Confirm copy-templates.js runs from packages/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

  • Related Notion: 프로젝트 구조 (project structure, template location, and why the copy script is used).
  • After merging, a new version should be published so users who install via npm get the fix.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chucoding chucoding self-assigned this Mar 15, 2026
@chucoding chucoding added the bug Something isn't working label Mar 15, 2026
@chucoding
chucoding merged commit 21c76bd into develop Mar 15, 2026
2 checks passed
@chucoding
chucoding deleted the bugfix/PF-25 branch March 15, 2026 05:02
chucoding added a commit that referenced this pull request Mar 15, 2026
…undle templates in package) (#37) (#38)

* fix : fixed a bug where templates could not be loaded.

* release : v0.1.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant