Skip to content

Conversation

@ggazzo
Copy link
Member

@ggazzo ggazzo commented Sep 25, 2025

…ing functions and improving local package handling

Summary by CodeRabbit

  • Refactor

    • Modularized dependency collection across packages for dependencies, devDependencies, and peerDependencies.
    • Replaced inline extraction with package-based helpers, aggregated dependencies, and filtered workspace: references.
    • Automatically excludes local packages from build externals and updates merged package metadata accordingly.
    • Preserves existing build flow while improving reliability of dependency resolution.
  • Chores

    • Keeps output artifact generation and TypeScript declaration emission intact.

…ing functions and improving local package handling
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors tools/bundle.ts to modularize dependency discovery and aggregation via new helpers (getLocalPackages, getDependencies, getDependenciesFromPackages, filterWorkspace), computes externals excluding local packages, and updates package.json merging; build and declaration emission flow remain intact. (≈34 words)

Changes

Cohort / File(s) Summary
Dependency collection refactor
tools/bundle.ts
Replace inline dependency scanning with helpers: getLocalPackages, getDependencies, getDependenciesFromPackages, filterWorkspace. Aggregate deps/devDeps/peerDeps across packages, filter workspace: references, compute externals = allDeps - localPackages, and merge filtered deps into package.json before Bun.build. Build outputs and d.ts emission unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI as CLI/Runner
  participant Bundle as tools/bundle.ts
  participant Graph as Package Graph
  participant FS as FS/package.json
  participant Bun as Bun.build

  Note over Bundle: Modularized dependency collection

  CLI->>Bundle: run()
  Bundle->>Graph: getLocalPackages(packages)
  Graph-->>Bundle: localPackageNames

  par Collect dependency maps
    Bundle->>FS: getDependencies(pkg, "dependencies")
    FS-->>Bundle: deps
    Bundle->>FS: getDependencies(pkg, "devDependencies")
    FS-->>Bundle: devDeps
    Bundle->>FS: getDependencies(pkg, "peerDependencies")
    FS-->>Bundle: peerDeps
  end

  Bundle->>Bundle: getDependenciesFromPackages(...)\nfilterWorkspace(...)
  Bundle->>Bundle: externals = union(allDeps) - localPackageNames
  Bundle->>FS: merge filtered deps into package.json
  Bundle->>Bun: Bun.build({ external: externals })
  Bun-->>Bundle: artifacts
  Bundle-->>CLI: artifacts + updated package.json
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • rodrigok

Poem

I twitch my whiskers at each new tweak,
Hopping through packages, nimble and sleek.
Workspace weeds swept, externals aligned,
Bun bakes the bundle — carrots well-timed. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title succinctly describes the core change as a refactor that enhances dependency management in the bundle script by modularizing functions and improving local package handling, which aligns directly with the new helper functions and refactored logic introduced. It avoids unnecessary detail while clearly conveying the primary intent of the update.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8688f4a and 3732fef.

📒 Files selected for processing (1)
  • bundle.ts (2 hunks)

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.

@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.07%. Comparing base (648cc56) to head (3732fef).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #222   +/-   ##
=======================================
  Coverage   81.07%   81.07%           
=======================================
  Files          63       63           
  Lines        4719     4719           
=======================================
  Hits         3826     3826           
  Misses        893      893           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ggazzo ggazzo marked this pull request as ready for review September 25, 2025 02:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 648cc56 and 8688f4a.

📒 Files selected for processing (1)
  • bundle.ts (2 hunks)

Comment on lines +70 to +72
external: Object.keys(dependencies).filter(
(dep) => !localPackagesNames.has(dep),
),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Include peer dependencies in Bun externals

Line 70 currently ignores peerDependencies, so Bun tries to bundle them. That breaks builds whenever a peer isn’t installed locally (common) and defeats the purpose of peer deps.

-		external: Object.keys(dependencies).filter(
-			(dep) => !localPackagesNames.has(dep),
-		),
+		external: [
+			...new Set([
+				...Object.keys(dependencies),
+				...Object.keys(peerDependencies),
+			]),
+		].filter((dep) => !localPackagesNames.has(dep)),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
external: Object.keys(dependencies).filter(
(dep) => !localPackagesNames.has(dep),
),
external: [
...new Set([
...Object.keys(dependencies),
...Object.keys(peerDependencies),
]),
].filter((dep) => !localPackagesNames.has(dep)),
🤖 Prompt for AI Agents
In bundle.ts around lines 70-72, the externals array is built only from
Object.keys(dependencies) which omits peerDependencies and causes Bun to attempt
bundling peers; update the externals construction to include keys from both
dependencies and peerDependencies (guarding for undefined) and then filter out
localPackagesNames, e.g. combine Object.keys(dependencies || {}) with
Object.keys(peerDependencies || {}) before filtering so peer deps are treated as
externals.

Comment on lines +81 to +92
packageJson.dependencies = filterWorkspace({
...packageJson.dependencies,
...dependencies,
});
packageJson.devDependencies = filterWorkspace({
...packageJson.devDependencies,
...devDependencies,
});
packageJson.peerDependencies = filterWorkspace({
...packageJson.peerDependencies,
...peerDependencies,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Guard against spreading undefined dependency maps

Line 81 will throw TypeError: Cannot convert undefined or null to object whenever the source package.json omits one of these sections (peer/dev deps are optional). Please coalesce to {} before spreading.

-	packageJson.dependencies = filterWorkspace({
-		...packageJson.dependencies,
-		...dependencies,
-	});
-	packageJson.devDependencies = filterWorkspace({
-		...packageJson.devDependencies,
-		...devDependencies,
-	});
-	packageJson.peerDependencies = filterWorkspace({
-		...packageJson.peerDependencies,
-		...peerDependencies,
-	});
+	packageJson.dependencies = filterWorkspace({
+		...(packageJson.dependencies ?? {}),
+		...dependencies,
+	});
+	packageJson.devDependencies = filterWorkspace({
+		...(packageJson.devDependencies ?? {}),
+		...devDependencies,
+	});
+	packageJson.peerDependencies = filterWorkspace({
+		...(packageJson.peerDependencies ?? {}),
+		...peerDependencies,
+	});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
packageJson.dependencies = filterWorkspace({
...packageJson.dependencies,
...dependencies,
});
packageJson.devDependencies = filterWorkspace({
...packageJson.devDependencies,
...devDependencies,
});
packageJson.peerDependencies = filterWorkspace({
...packageJson.peerDependencies,
...peerDependencies,
});
packageJson.dependencies = filterWorkspace({
...(packageJson.dependencies ?? {}),
...dependencies,
});
packageJson.devDependencies = filterWorkspace({
...(packageJson.devDependencies ?? {}),
...devDependencies,
});
packageJson.peerDependencies = filterWorkspace({
...(packageJson.peerDependencies ?? {}),
...peerDependencies,
});
🤖 Prompt for AI Agents
In bundle.ts around lines 81 to 92, spreading
packageJson.dependencies/devDependencies/peerDependencies will throw when those
properties are undefined; coalesce each source section to an empty object before
spreading (e.g., use packageJson.dependencies || {} etc.) so you merge into a
safe object, then pass the result to filterWorkspace.

@sampaiodiego sampaiodiego merged commit 8207e0d into main Sep 25, 2025
2 of 3 checks passed
@sampaiodiego sampaiodiego deleted the chore/improve-bundle branch September 25, 2025 02:50
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.

4 participants