Repository navigation
Reduce @hexclave/cli bundle size by ~154 MB - #1544
Conversation
The copy-runtime-assets script copies the Next.js standalone output with dereference:true, which resolves all pnpm symlinks to real files. This means every package exists twice: once in the .pnpm/ store and once at the hoisted level. The .pnpm/ directory alone accounts for ~113 MB of redundant data. Changes: - After copying, hoist any packages from .pnpm/node_modules/ that don't already exist at the top-level node_modules/ (so resolution still works) - Delete the entire .pnpm/ directory (~113 MB saved) - Remove typescript from the output (not needed at runtime, pulled in by jiti/next file tracing but never loaded in production) (~20 MB saved) - Remove .nft.json file-trace manifests (build-time metadata, ~4 MB saved) Total estimated reduction: ~137 MB unpacked (from ~301 MB to ~164 MB). Co-Authored-By: Konstantin Wohlwend <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds post-copy cleanup for dashboard standalone output: hoists pnpm shared packages into top-level node_modules, removes the pnpm store and excluded build-time/native packages, deletes Next.js ChangesDashboard runtime package cleanup
Sequence Diagram(s)sequenceDiagram
participant Builder as build/copy step
participant copyScript as copy-runtime-assets.mjs
participant pnpmStore as dashboardDist/.pnpm
participant nodeModules as dashboardDist/node_modules
participant nextDist as dashboardDist/apps/dashboard/.next
Builder->>copyScript: copy standalone dashboard output into dashboardDist
copyScript->>pnpmStore: find .pnpm/node_modules shared packages
copyScript->>nodeModules: hoist shared packages into top-level node_modules
copyScript->>pnpmStore: remove .pnpm store directory
copyScript->>nodeModules: remove excluded runtime packages (typescript, sharp, `@img/`*)
copyScript->>nextDist: recursively delete all .nft.json manifests
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Greptile SummaryThis PR reduces the
Confidence Score: 4/5Safe to merge — the cleanup logic correctly handles the happy path and the pnpm store removal is well-reasoned. The core approach is sound: after cpSync dereferences all pnpm symlinks, the .pnpm/ tree is genuinely duplicate content, and hoistPnpmNodeModules correctly fills in the one gap (packages living only in .pnpm/node_modules/). The two minor issues are a hardcoded global reference in hoistPnpmNodeModules that would silently misdirect files if the function were reused, and a missing existsSync guard in removeNftJsonFiles that would surface an unhelpful ENOENT on a partial build. Neither affects the current call site. packages/stack-cli/scripts/copy-runtime-assets.mjs — specifically the destination path in hoistPnpmNodeModules and the missing guard in removeNftJsonFiles. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[cpSync standalone → dashboardDist\ndereference:true — all symlinks resolved] --> B[copyDashboardHoistedDependencies\ncopies hoisted pkgs from SOURCE .pnpm symlinks]
B --> C[removePnpmStore\ndashboardDist/node_modules]
C --> D[hoistPnpmNodeModules\nwalk .pnpm/node_modules/\ncopy missing pkgs to top-level node_modules/]
D --> E[rmSync .pnpm/ — ~113 MB freed]
E --> F[removeExcludedPackages\ndelete typescript, etc. from top-level node_modules/]
F --> G[removeNftJsonFiles\nrecursively delete *.nft.json under .next/]
G --> H[✅ dashboardDist — ~164 MB]
style A fill:#d4e8ff
style E fill:#ffd4d4
style H fill:#d4ffd4
Prompt To Fix All With AIFix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
packages/stack-cli/scripts/copy-runtime-assets.mjs:89
`hoistPnpmNodeModules` takes `pnpmDir` as a parameter but ignores it for the *destination*, hardcoding the module-level `dashboardDist` global instead. The destination should be derived from the caller-supplied path (`dirname(pnpmDir)`) so the function is consistent with how `removePnpmStore` parameterises it. As written, if `removePnpmStore` is ever called with a path other than `join(dashboardDist, "node_modules")`, the hoisted files would land in the wrong directory without any error.
```suggestion
const destNodeModules = dirname(pnpmDir);
```
### Issue 2 of 3
packages/stack-cli/scripts/copy-runtime-assets.mjs:132-136
`removeNftJsonFiles` calls `readdirSync` directly without first checking whether `dir` exists. If the `.next` directory is absent for any reason (partial build, first-run edge case), this throws a bare `ENOENT` instead of a useful diagnostic message. Adding an early guard keeps error output consistent with the `assertExists` style used elsewhere in the script.
```suggestion
function removeNftJsonFiles(dir) {
// .nft.json files are Next.js file-trace manifests used only during the build
// to determine which files to include in standalone output. They are not
// needed at runtime and add ~4 MB to the package.
if (!existsSync(dir)) {
return;
}
for (const entry of readdirSync(dir, { withFileTypes: true })) {
```
### Issue 3 of 3
packages/stack-cli/scripts/copy-runtime-assets.mjs:114-121
**Excluded packages are unnecessarily hoisted before deletion**
`removePnpmStore` (and therefore `hoistPnpmNodeModules`) runs before `removeExcludedPackages`. If an excluded package like `typescript` lives in `.pnpm/node_modules/` but not yet at the top level, `hoistPnpmNodeModules` will copy it there — only for `removeExcludedPackages` to delete it moments later. Filtering against `EXCLUDED_RUNTIME_PACKAGES` inside `hoistPnpmNodeModules`, or calling `removeExcludedPackages` before `removePnpmStore`, would skip the unnecessary copy. This is a performance concern only, not a correctness bug — the end state is correct.
Reviews (1): Last reviewed commit: "Reduce @hexclave/cli bundle size by remo..." | Re-trigger Greptile |
| if (!existsSync(sharedNodeModules)) { | ||
| return; | ||
| } | ||
| const destNodeModules = join(dashboardDist, "node_modules"); |
There was a problem hiding this comment.
hoistPnpmNodeModules takes pnpmDir as a parameter but ignores it for the destination, hardcoding the module-level dashboardDist global instead. The destination should be derived from the caller-supplied path (dirname(pnpmDir)) so the function is consistent with how removePnpmStore parameterises it. As written, if removePnpmStore is ever called with a path other than join(dashboardDist, "node_modules"), the hoisted files would land in the wrong directory without any error.
| const destNodeModules = join(dashboardDist, "node_modules"); | |
| const destNodeModules = dirname(pnpmDir); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/stack-cli/scripts/copy-runtime-assets.mjs
Line: 89
Comment:
`hoistPnpmNodeModules` takes `pnpmDir` as a parameter but ignores it for the *destination*, hardcoding the module-level `dashboardDist` global instead. The destination should be derived from the caller-supplied path (`dirname(pnpmDir)`) so the function is consistent with how `removePnpmStore` parameterises it. As written, if `removePnpmStore` is ever called with a path other than `join(dashboardDist, "node_modules")`, the hoisted files would land in the wrong directory without any error.
```suggestion
const destNodeModules = dirname(pnpmDir);
```
How can I resolve this? If you propose a fix, please make it concise.| function removeNftJsonFiles(dir) { | ||
| // .nft.json files are Next.js file-trace manifests used only during the build | ||
| // to determine which files to include in standalone output. They are not | ||
| // needed at runtime and add ~4 MB to the package. | ||
| for (const entry of readdirSync(dir, { withFileTypes: true })) { |
There was a problem hiding this comment.
removeNftJsonFiles calls readdirSync directly without first checking whether dir exists. If the .next directory is absent for any reason (partial build, first-run edge case), this throws a bare ENOENT instead of a useful diagnostic message. Adding an early guard keeps error output consistent with the assertExists style used elsewhere in the script.
| function removeNftJsonFiles(dir) { | |
| // .nft.json files are Next.js file-trace manifests used only during the build | |
| // to determine which files to include in standalone output. They are not | |
| // needed at runtime and add ~4 MB to the package. | |
| for (const entry of readdirSync(dir, { withFileTypes: true })) { | |
| function removeNftJsonFiles(dir) { | |
| // .nft.json files are Next.js file-trace manifests used only during the build | |
| // to determine which files to include in standalone output. They are not | |
| // needed at runtime and add ~4 MB to the package. | |
| if (!existsSync(dir)) { | |
| return; | |
| } | |
| for (const entry of readdirSync(dir, { withFileTypes: true })) { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/stack-cli/scripts/copy-runtime-assets.mjs
Line: 132-136
Comment:
`removeNftJsonFiles` calls `readdirSync` directly without first checking whether `dir` exists. If the `.next` directory is absent for any reason (partial build, first-run edge case), this throws a bare `ENOENT` instead of a useful diagnostic message. Adding an early guard keeps error output consistent with the `assertExists` style used elsewhere in the script.
```suggestion
function removeNftJsonFiles(dir) {
// .nft.json files are Next.js file-trace manifests used only during the build
// to determine which files to include in standalone output. They are not
// needed at runtime and add ~4 MB to the package.
if (!existsSync(dir)) {
return;
}
for (const entry of readdirSync(dir, { withFileTypes: true })) {
```
How can I resolve this? If you propose a fix, please make it concise.| function removePnpmStore(nodeModulesDir) { | ||
| const pnpmDir = join(nodeModulesDir, ".pnpm"); | ||
| if (!existsSync(pnpmDir)) { | ||
| return; | ||
| } | ||
| hoistPnpmNodeModules(pnpmDir); | ||
| rmSync(pnpmDir, { recursive: true, force: true }); | ||
| } |
There was a problem hiding this comment.
Excluded packages are unnecessarily hoisted before deletion
removePnpmStore (and therefore hoistPnpmNodeModules) runs before removeExcludedPackages. If an excluded package like typescript lives in .pnpm/node_modules/ but not yet at the top level, hoistPnpmNodeModules will copy it there — only for removeExcludedPackages to delete it moments later. Filtering against EXCLUDED_RUNTIME_PACKAGES inside hoistPnpmNodeModules, or calling removeExcludedPackages before removePnpmStore, would skip the unnecessary copy. This is a performance concern only, not a correctness bug — the end state is correct.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/stack-cli/scripts/copy-runtime-assets.mjs
Line: 114-121
Comment:
**Excluded packages are unnecessarily hoisted before deletion**
`removePnpmStore` (and therefore `hoistPnpmNodeModules`) runs before `removeExcludedPackages`. If an excluded package like `typescript` lives in `.pnpm/node_modules/` but not yet at the top level, `hoistPnpmNodeModules` will copy it there — only for `removeExcludedPackages` to delete it moments later. Filtering against `EXCLUDED_RUNTIME_PACKAGES` inside `hoistPnpmNodeModules`, or calling `removeExcludedPackages` before `removePnpmStore`, would skip the unnecessary copy. This is a performance concern only, not a correctness bug — the end state is correct.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…excluded pkgs during hoist Co-Authored-By: Konstantin Wohlwend <[email protected]>
…rom bundle Co-Authored-By: Konstantin Wohlwend <[email protected]>
…e-cli-bundle-size
Co-Authored-By: Konstantin Wohlwend <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR reduces the unpacked size of @hexclave/cli by post-processing the bundled dashboard standalone output to remove duplicated pnpm store content and other build-time/native-only artifacts, and by disabling Next image optimization for standalone/RDE builds to avoid shipping sharp.
Changes:
- Add a post-copy cleanup step to hoist needed pnpm shared
node_modulespackages, then remove the.pnpm/store, selected build-time/native packages, and.nft.jsontrace manifests. - Set
images.unoptimized: truewhenNEXT_CONFIG_OUTPUT=standaloneto avoidsharpbeing needed in standalone builds.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/stack-cli/scripts/copy-runtime-assets.mjs | Hoists pnpm shared deps and removes .pnpm, excluded packages, and .nft.json files to shrink the packaged dashboard runtime. |
| apps/dashboard/next.config.mjs | Disables image optimization for standalone builds to avoid bundling sharp binaries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (name.startsWith("@")) { | ||
| // Scoped package — iterate one level deeper | ||
| const scopeDir = join(sharedNodeModules, name); | ||
| for (const scopedEntry of readdirSync(scopeDir, { withFileTypes: true })) { | ||
| const fullName = join(name, scopedEntry.name); | ||
| if (EXCLUDED_RUNTIME_PACKAGES.has(fullName)) { | ||
| continue; | ||
| } | ||
| const dest = join(destNodeModules, fullName); | ||
| if (!existsSync(dest)) { | ||
| cpSync(join(scopeDir, scopedEntry.name), dest, { recursive: true, dereference: true }); | ||
| } | ||
| } |
| // sharp and its native bindings (@img/*) are excluded because the RDE | ||
| // standalone build sets images.unoptimized=true. |
Summary
Reduces
@hexclave/cliunpacked size from ~301 MB to ~147 MB by cleaning up the bundled dashboard standalone output incopy-runtime-assets.mjs:.pnpm/store (~113 MB): AftercpSync(..., { dereference: true })resolves all symlinks, the.pnpm/directory is entirely duplicate content. Packages that only exist in.pnpm/node_modules/are hoisted to the top-levelnode_modules/first.typescript(~20 MB): Traced by Next.js (via jiti) but never loaded at runtime.sharp+@img/*(~17 MB): Native image optimization binaries. The RDE standalone build now setsimages.unoptimized: trueso sharp is not needed..nft.jsonfiles (~4 MB): Build-time file-trace manifests, not needed at runtime.Link to Devin session: https://app.devin.ai/sessions/5139d8298ba24201af9cf85bbf45e48f
Requested by: @N2D4
Summary by CodeRabbit
Note
Medium Risk
Removing
.pnpmand excluded packages could break runtime module resolution if hoisting misses a dependency; unoptimized images only affect standalone/RDE builds, not default production deploys.Overview
Reduces
@hexclave/cliunpacked size (~301 MB → ~147 MB) by changing how the dashboard standalone output is packaged and how standalone Next is configured.When
NEXT_CONFIG_OUTPUTisstandalone, the dashboard Next config now setsimages.unoptimized: trueso the RDE does not need sharp (~17 MB of native binaries).copy-runtime-assets.mjspost-processes the copied standalone tree: hoists packages from.pnpm/node_modules/to top-levelnode_modules/, then removes the duplicate.pnpm/store (~113 MB), strips build-time-only packages (typescript, sharp, @img/*) from runtimenode_modules, and deletes.nft.jsontrace manifests under.next(~4 MB).Reviewed by Cursor Bugbot for commit 620b7c0. Bugbot is set up for automated code reviews on this repo. Configure here.