Skip to content

fix(framework): avoid excluding files with test in filename#15345

Open
Sonu99kr wants to merge 4 commits into
medusajs:developfrom
Sonu99kr:fix/backend-ignore-path-segments
Open

fix(framework): avoid excluding files with test in filename#15345
Sonu99kr wants to merge 4 commits into
medusajs:developfrom
Sonu99kr:fix/backend-ignore-path-segments

Conversation

@Sonu99kr
Copy link
Copy Markdown

@Sonu99kr Sonu99kr commented May 9, 2026

Fixes #15341

Replaced the substring match with path-segment based filtering to avoid incorrectly excluding files whose filenames contain test, while preserving exclusions for ignored directories such as src/test and src/admin.

Summary

What — What changes are introduced in this PR?

This PR fixes an issue in the framework build compiler where files were incorrectly excluded from the build output if their path contained the substring test, even when test appeared only in the filename.

Previously, the compiler filtered files using:

relativeFileName.includes(chunk)

which caused valid files such as:

  • reset-test-vendor-password.ts
  • seed-test-accounts.ts

to be silently skipped during medusa build.

The filtering logic now matches against path segments instead of arbitrary substrings.


Why — Why are these changes relevant or necessary?

The current behavior unintentionally excludes user-authored scripts and fixtures whose filenames contain test, even when they are not located inside ignored directories like:

  • src/test
  • integration-tests
  • unit-tests

This can silently prevent important scripts from appearing in the final build output, making the issue difficult to diagnose.

The fix preserves the intended behavior of ignoring test directories while allowing valid filenames containing test to compile correctly.


How — How have these changes been implemented?

The compiler filtering logic in:

packages/core/framework/src/build-tools/compiler.ts

was updated from substring matching:

relativeFileName.includes(chunk)

to path-segment matching:

const segments = relativeFileName.split(path.sep)

return !chunksToIgnore.some((chunk) => segments.includes(chunk))

This ensures only actual path segments such as test or integration-tests are excluded.


Testing — How have these changes been tested, or how can the reviewer test the feature?

Verified locally using a Medusa test application linked against the modified local framework package.

Reproduction Test

Created:

src/scripts/reset-test-vendor-password.ts

and ran:

npx medusa build

Verified that:

.medusa/server/src/scripts/reset-test-vendor-password.js

is now correctly generated.

Regression Verification

Created:

src/test/foo.ts

and verified that:

.medusa/server/src/test/foo.js

is still excluded from the build output.


Examples

// Previously excluded incorrectly
src/scripts/reset-test-vendor-password.ts

// Now included correctly after build
.medusa/server/src/scripts/reset-test-vendor-password.js

Additional Context

This issue was caused by broad substring matching against the full relative path, which unintentionally matched filenames containing test.

The updated implementation limits exclusion behavior to actual path segments, preserving the intended semantics of ignored directories.


Note

Medium Risk
Touches the build compiler’s file inclusion/exclusion logic; mistakes could cause unintended files to be skipped or included in build output across platforms.

Overview
Fixes Compiler.#emitBuildOutput filtering so ignored chunks (e.g., test, integration-tests) match path segments/prefixes rather than arbitrary substrings in the full relative path, preventing files like reset-test-*.ts from being incorrectly excluded.

Adds path normalization to / and differentiates single-segment ignores (segment match) vs multi-segment ignores (directory-prefix match). Includes a patch changeset for @medusajs/framework.

Reviewed by Cursor Bugbot for commit ead4adf. Bugbot is set up for automated code reviews on this repo. Configure here.

@Sonu99kr Sonu99kr requested a review from a team as a code owner May 9, 2026 10:31
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 9, 2026

🦋 Changeset detected

Latest commit: c71041f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 78 packages
Name Type
@medusajs/framework Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/draft-order Patch
@medusajs/loyalty-plugin Patch
@medusajs/core-flows Patch
integration-tests-http Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

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

@vercel
Copy link
Copy Markdown

vercel Bot commented May 9, 2026

@Sonu99kr is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit da5bdb5. Configure here.

Comment thread packages/core/framework/src/build-tools/compiler.ts Outdated
@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot Bot commented May 9, 2026

Thank you for your contribution, @Sonu99kr!

After reviewing this PR, we need a few things addressed before we can move forward:

Required changes:

  • Fix the regression introduced for the src/admin chunk — see Potential Bugs below
  • Add a changeset file under .changeset/ (run yarn changeset, select @medusajs/framework as patch)
  • Link a GitHub issue using a closing keyword (e.g., Closes #XXXX). If no issue exists yet, please open one describing the bug first
  • Add a unit test covering the fixed case (reset-test-vendor-password.ts is included) and the src/admin exclusion regression

Potential Bugs:

⚠️ packages/core/framework/src/build-tools/compiler.tssrc/admin chunk no longer matches after switching to segment-based lookup

const segments = relativeFileName.split(path.sep)

return \!chunksToIgnore.some((chunk) => segments.includes(chunk))

this.#backendIgnoreFiles includes "src/admin", which contains a path separator. When a file such as src/admin/widgets/product-widget.tsx is processed, relativeFileName.split(path.sep) produces ["src", "admin", "widgets", "product-widget.tsx"]. None of those elements equals the string "src/admin", so segments.includes("src/admin") returns false and the file is not excluded from the build output — the opposite of the intended behaviour.

The single-segment chunks ("integration-tests", "test", "unit-tests") continue to work correctly; only the multi-segment chunk is broken.

A fix that handles both cases:

const normalizedFile = relativeFileName.split(path.sep).join("/")
return \!chunksToIgnore.some((chunk) => {
  const normalizedChunk = chunk.split(/[\/]/).join("/")
  if (\!normalizedChunk.includes("/")) {
    // single-segment: match against path segments only
    return normalizedFile.split("/").includes(normalizedChunk)
  }
  // multi-segment: match as a path prefix
  return normalizedFile.startsWith(normalizedChunk + "/")
})

Once those changes are in place, we'll be happy to move this forward. Thanks again!

Triggered by: new PR opened

@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot Bot commented May 9, 2026

Thank you for your contribution, @Sonu99kr!

The src/admin chunk regression flagged in the previous review has been resolved — the new path-normalisation approach correctly handles both single-segment and multi-segment ignore entries. Good work on that fix.

The following items from the prior review are still outstanding:

Required changes:

  • Add a changeset file under .changeset/ (run yarn changeset, select @medusajs/framework as patch)
  • Link a GitHub issue using a closing keyword (e.g., Closes #XXXX). If no issue exists yet, please open one describing the bug first
  • Add a unit test covering the fixed cases — at minimum: a file whose name contains test is included, a file under src/test/ is excluded, and a file under src/admin/ is excluded. Add it under packages/core/framework/src/build-tools/__tests__/ following the existing __tests__ pattern used elsewhere in the framework package

Once those are addressed, we'll be happy to move this forward. Thanks again!

Triggered by: new commit pushed

@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot Bot commented May 9, 2026

Thank you for the continued progress, @Sonu99kr!

The src/admin regression is now correctly handled — the path-prefix approach for multi-segment chunks works as expected. Good fix.

The following items from the prior review are still outstanding, plus one new issue with the changeset:

Required changes:

  • Fix the changeset message format in .changeset/yellow-dots-slide.md — it must follow the convention fix(framework): short description (e.g., fix(framework): avoid excluding files with test in filename). The current message Fix compiler path filtering for files containing test in filename is missing the required prefix.
  • Link a GitHub issue using a closing keyword (e.g., Closes #XXXX). If no issue exists yet, please open one first.
  • Add a unit test covering the key cases — at minimum: a file whose name contains test (e.g., src/scripts/reset-test-vendor-password.ts) is included, a file under src/test/ is excluded, and a file under src/admin/ is excluded. Add it under packages/core/framework/src/build-tools/__tests__/ following the existing __tests__ pattern used elsewhere in the package.

Once those are addressed, we'll be happy to move this forward. Thanks!

Triggered by: new commit pushed

@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot Bot commented May 9, 2026

Thank you for the continued progress, @Sonu99kr!

Good work adding the linked issue — that resolves one of the outstanding items.

The following items from the prior review are still unresolved:

Required changes:

  • Fix the changeset message format in .changeset/yellow-dots-slide.md — the current message Fix compiler path filtering for files containing test in filename must be updated to follow the convention fix(package-name): short description, e.g. fix(framework): avoid excluding files with test in filename
  • Add a unit test covering the key cases: a file whose name contains test (e.g., src/scripts/reset-test-vendor-password.ts) is included; a file under src/test/ is excluded; and a file under src/admin/ is excluded. Add it under packages/core/framework/src/build-tools/__tests__/ following the existing __tests__ pattern used elsewhere in the package

Once those are addressed, we'll be happy to move this forward. Thanks!

Triggered by: PR description updated

@cursor
Copy link
Copy Markdown

cursor Bot commented May 9, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot Bot commented May 9, 2026

Thank you for your continued effort and patience on this, @Sonu99kr!

All items from the previous reviews have been resolved:

src/admin multi-segment chunk regression — correctly handled via path-prefix matching
✅ Changeset added with the correct format
✅ Issue linked (Fixes #15341)
✅ Unit tests added covering the key cases
✅ Follows Medusa's conventions

A team member will do a final review before this is merged. We appreciate your patience!


Notes:

The test in packages/core/framework/src/build-tools/__tests__/compiler.spec.ts defines a local shouldIgnore function that reimplements the filtering logic rather than importing and exercising the Compiler class directly. This means a future change to #emitBuildOutput in compiler.ts would not be caught by these tests if the local copy is not updated alongside it. This is non-blocking since the logic is correct and matches what's in the compiler, but ideally the test would drive the actual production code path.

Triggered by: new commit pushed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build silently excludes any file path containing 'test' substring (Compiler.backendIgnoreFiles)

1 participant