Skip to content

Reduce @hexclave/cli bundle size by ~154 MB - #1544

Merged
N2D4 merged 6 commits into
devfrom
devin/1780509770-reduce-cli-bundle-size
Jun 4, 2026
Merged

N2D4 merged 6 commits into
devfrom
devin/1780509770-reduce-cli-bundle-size

Conversation

@N2D4

@N2D4 N2D4 commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reduces @hexclave/cli unpacked size from ~301 MB to ~147 MB by cleaning up the bundled dashboard standalone output in copy-runtime-assets.mjs:

  • Remove .pnpm/ store (~113 MB): After cpSync(..., { 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-level node_modules/ first.
  • Remove typescript (~20 MB): Traced by Next.js (via jiti) but never loaded at runtime.
  • Remove sharp + @img/* (~17 MB): Native image optimization binaries. The RDE standalone build now sets images.unoptimized: true so sharp is not needed.
  • Remove .nft.json files (~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

  • Chores
    • Post-process standalone dashboard builds to consolidate runtime dependencies, remove excluded build-time/native packages, and delete leftover build artifacts and metadata to reduce distribution size.
  • Bug Fixes
    • Disable image optimization for standalone dashboard outputs to ensure correct behavior of packaged builds.
  • Documentation
    • Added and reordered guidance reminding developers where to find JS SDK source/interfaces in installed packages.

Note

Medium Risk
Removing .pnpm and 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/cli unpacked size (~301 MB → ~147 MB) by changing how the dashboard standalone output is packaged and how standalone Next is configured.

When NEXT_CONFIG_OUTPUT is standalone, the dashboard Next config now sets images.unoptimized: true so the RDE does not need sharp (~17 MB of native binaries).

copy-runtime-assets.mjs post-processes the copied standalone tree: hoists packages from .pnpm/node_modules/ to top-level node_modules/, then removes the duplicate .pnpm/ store (~113 MB), strips build-time-only packages (typescript, sharp, @img/*) from runtime node_modules, and deletes .nft.json trace 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.

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-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@vercel

vercel Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment Jun 4, 2026 12:26am
stack-auth-internal-tool Ready Ready Preview, Comment Jun 4, 2026 12:26am
stack-auth-mcp Ready Ready Preview, Comment Jun 4, 2026 12:26am
stack-auth-skills Ready Ready Preview, Comment Jun 4, 2026 12:26am
stack-backend Ready Ready Preview, Comment Jun 4, 2026 12:26am
stack-dashboard Ready Ready Preview, Comment Jun 4, 2026 12:26am
stack-demo Ready Ready Preview, Comment Jun 4, 2026 12:26am
stack-docs Error Error Jun 4, 2026 12:26am
stack-preview-backend Ready Ready Preview, Comment Jun 4, 2026 12:26am
stack-preview-dashboard Ready Ready Preview, Comment Jun 4, 2026 12:26am

@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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 .nft.json manifests, and conditionally disables Next.js image optimization for standalone builds.

Changes

Dashboard runtime package cleanup

Layer / File(s) Summary
Next.js images config
apps/dashboard/next.config.mjs
Adds images.unoptimized: true when NEXT_CONFIG_OUTPUT === "standalone" to avoid bundling native image binaries.
Pnpm hoisting and cleanup utilities
packages/stack-cli/scripts/copy-runtime-assets.mjs
Defines excluded runtime package set and helpers to hoist packages from .pnpm/node_modules into top-level node_modules, remove the .pnpm store, delete excluded packages, and recursively remove .nft.json manifests.
Integration into dashboard asset build pipeline
packages/stack-cli/scripts/copy-runtime-assets.mjs
Wires hoisting and cleanup helpers into copyDashboardAssets() to run after copying dashboard standalone output.
Hexclave reminders updates
docs-mintlify/llms-full.txt, docs-mintlify/snippets/hexclave-agent-reminders.jsx
Inserts a medium-priority reminder pointing to the installed JS SDK source (src/lib/stack-app) and reorders related reminder bullets.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

A rabbit nibbles through the build,
Hoists the shared crumbs to the hill,
Prunes sharp bits and typescript leaves,
Cleans traces where the manifests spill—
Standalone lean, the bundle still. 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the primary change—reducing the @hexclave/cli bundle size by ~154 MB—which directly corresponds to the main objective of this pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the bundle size reduction strategy with specific package removals, file sizes saved, and technical justification for each cleanup step.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devin/1780509770-reduce-cli-bundle-size

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR reduces the @hexclave/cli bundle size by ~137 MB by eliminating duplicate pnpm store content from the standalone distribution. After cpSync with dereference: true resolves all symlinks into real copies, the .pnpm/ directory becomes pure duplication; this script now hoists any packages that live exclusively in .pnpm/node_modules/, deletes .pnpm/, strips build-only packages (typescript), and removes .nft.json manifests.

  • hoistPnpmNodeModules walks .pnpm/node_modules/ in the destination and copies anything not yet present at the top-level node_modules/, then removePnpmStore deletes the entire .pnpm/ tree (~113 MB saved).
  • removeExcludedPackages deletes build-time packages from the top-level node_modules/ after the store is gone, and removeNftJsonFiles recursively removes .nft.json trace manifests from .next/.

Confidence Score: 4/5

Safe 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

Filename Overview
packages/stack-cli/scripts/copy-runtime-assets.mjs Adds four new functions for post-copy cleanup: hoistPnpmNodeModules, removePnpmStore, removeExcludedPackages, and removeNftJsonFiles. Logic is correct for the happy path; minor robustness gaps around hardcoded global reference in hoistPnpmNodeModules and missing directory guard in removeNftJsonFiles.

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
Loading
Prompt To Fix All With AI
Fix 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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
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.

Comment on lines +132 to +136
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 })) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
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.

Comment on lines +114 to +121
function removePnpmStore(nodeModulesDir) {
const pnpmDir = join(nodeModulesDir, ".pnpm");
if (!existsSync(pnpmDir)) {
return;
}
hoistPnpmNodeModules(pnpmDir);
rmSync(pnpmDir, { recursive: true, force: true });
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

Copilot AI review requested due to automatic review settings June 4, 2026 00:17
@N2D4
N2D4 merged commit 6940aa6 into dev Jun 4, 2026
13 of 17 checks passed
@N2D4
N2D4 deleted the devin/1780509770-reduce-cli-bundle-size branch June 4, 2026 00:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_modules packages, then remove the .pnpm/ store, selected build-time/native packages, and .nft.json trace manifests.
  • Set images.unoptimized: true when NEXT_CONFIG_OUTPUT=standalone to avoid sharp being 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.

Comment on lines +101 to +113
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 });
}
}
Comment on lines +76 to +77
// sharp and its native bindings (@img/*) are excluded because the RDE
// standalone build sets images.unoptimized=true.

This branch was successfully deployed

5 active deployments
Preview – stack-preview-backend — 620b7c06 Deployed Jun 4, 2026 by vercel[bot]
Preview – stack-preview-dashboard — 620b7c06 Deployed Jun 4, 2026 by vercel[bot]
Preview – stack-auth-internal-tool — 620b7c06 Deployed Jun 4, 2026 by vercel[bot]
Preview – stack-auth-skills — 620b7c06 Deployed Jun 4, 2026 by vercel[bot]
Preview – stack-auth-mcp — 620b7c06 Deployed Jun 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants