fix(deployer): preserve safe externals with custom bundler externals#17120
fix(deployer): preserve safe externals with custom bundler externals#17120Akash504-ai wants to merge 1 commit into
Conversation
|
@Akash504-ai is attempting to deploy a commit to the Mastra Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: b595184 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughThis PR fixes a bundler regression where user externals could override Mastra's runtime externals, risking ESM top-level await deadlocks. It introduces ChangesSafe Runtime Externals Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
🚥 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 unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: lockfile failed supply-chain policy check. Run 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 |
PR triageLinked issue check passed (#17115). Mastra uses CodeRabbit for automated code reviews. Please address all feedback from CodeRabbit by either making changes to your PR or leaving a comment explaining why you disagree with the feedback. Since CodeRabbit is an AI, it may occasionally provide incorrect feedback. PR complexity score
Applied label: Changed test gateChanged Test Gate is pending. The |
Description
Fixes a regression where custom
bundler.externalscould override Mastra’s safe runtime externals and allow internal runtime packages to be bundled into generated chunks.This could rewrite internal dynamic imports such as:
into generated self-imports like:
or:
reintroducing the ESM top-level-await deadlock fixed in #14860 / #14863.
This change centralizes safe runtime externals, preserves user-provided externals additively, and ensures protected Mastra runtime packages remain externalized even when custom
bundler.externalsare configured.Related issue(s)
Fixes #17115
Related:
Type of change
What changed
MASTRA_RUNTIME_EXTERNALSmergeBundlerExternals()getSafeBundlerExternals()externals: truebehavior@mastra/core/storageRegression coverage added
Added tests covering:
@mastra/core/storagesubpath imports./index.mjs,./mastra.mjs)mastra.mjschunk safetyValidation
Passed:
Generated bundle output was also inspected directly to verify:
Checklist
ELI5
This PR fixes a bug where custom external package configurations could accidentally bundle Mastra's internal packages into the output, breaking the application. The fix ensures Mastra's core internal packages always stay external (not bundled) while still allowing you to specify your own external packages.
Overview
Fixes a regression in the deployer bundler where user-provided
bundler.externalscould override Mastra's safe runtime externals, causing internal runtime packages to be bundled into generated chunks. This could rewrite internal dynamic imports (e.g.,await import('@mastra/core/storage')) into self-imports (e.g.,await import('./index.mjs')), reintroducing an ESM top-level-await deadlock previously fixed in#14860/#14863.Changes
New utilities in
packages/deployer/src/build/analyze/constants.ts:MASTRA_RUNTIME_EXTERNALSconstant to centralize safe runtime externals for Mastra packagesmergeBundlerExternals()function to deduplicate and flatten external package listsgetSafeBundlerExternals()function to produce the final externals set by combining global externals, optional deprecated externals, Mastra runtime externals, and user-provided externalsUpdated integration points:
bundleExternals.ts: Now usesgetSafeBundlerExternals()instead of manual concatenation of constantsanalyze.ts: Now usesgetSafeBundlerExternals()to deriveallExternalsfrom user-provided externals, replacing prior manual concatenation and filtering logicTest coverage in
packages/deployer/src/build/analyze.test.ts:readGeneratedModulesto load and concatenate generated.mjsmodule contentssafe runtime externalstest suite validating:getSafeBundlerExternalspreserves user externals while ensuring Mastra runtime packages remain externalized and deduplicatedanalyzeBundlemarks@mastra/coreas external even with custom externals, preventing rewritten internal dynamic imports@mastra/core/storagewithout generating self-importsChangeset:
.changeset/lucky-places-wonder.mddocumenting the patch-level fix for the bundler regressionKey Improvements
externals: truebehavior@mastra/core/storage)