nf build deletes the whole project when the output dir is . or a parent folder

Đang mở
#275 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
bun, node.js, typescript
Lĩnh vực
backend, cli

Hướng nghiên cứu

Start with src/lib/utils/files.ts and the resetFolder call in src/action/actions/build.action.ts; trace how the client and server output directories are resolved before deletion. Check how out.dir is validated in libs/config/src/parse/validate-config.ts. Add coverage for unsafe paths, including ., a parent folder, and paths containing the entry file or assets; done means builds reject them before deleting project files.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug command:build lib:config
Which package is this bug report for?

@nanoforge-dev/cli

Which command is this bug report for?

build

Issue description

nf build deletes the whole project when the output folder is . (or a parent folder). Before each build, resetFolder runs rmSync(join(directory, outDir), { recursive: true, force: true }) (src/lib/utils/files.ts#L14-L15, called from src/action/actions/build.action.ts#L139). Neither --client-out-dir/--server-out-dir nor the config's out.dir (libs/config/src/parse/validate-config.ts#L10, a bare z.string()) refuses ., .., an absolute path or a folder that holds the sources.

Steps to reproduce (reproduced with dist/nf.js on a throwaway project):

  1. A project with nanoforge.config.ts (export default { type: "client" };), src/main.ts and assets/sprites/b.png.
  2. nf build -d <project> --client-out-dir .
  3. The output is ENOENT opening root directory "src" / Build of Client failed!, and the project folder is now empty: config, src/ and assets/ are gone.

Expected: the build refuses an output folder that is the project folder, one of its parents, outside the project, or one that contains the entry file or the assets folder, before anything is deleted. The same rule is checked on out.dir in @nanoforge-dev/config, and a test covers it.

Found during a read-only audit of main at e95b881 (2026-11-11).

Code sample
// nanoforge.config.ts
export default { type: "client" };
// then: nf build --client-out-dir .   -> the project folder is emptied
Versions
  • @nanoforge-dev/cli 3.0.1 (main, e95b881)
  • Node.js 26.7.0
  • Bun 1.3.14 (bundled)
  • Linux
Issue priority

High (immediate attention needed)

I have tested this issue on a development release

e95b881

Ngôn ngữ chính
TypeScript
Star
2
Fork
2
Merge trung bình
2 ngày 18 giờ
Pull request đã merge (30 ngày)
17

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NanoForge-dev/CLI

Tất cả issue của NanoForge-dev/CLI

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.