Skip to content

fix(functions): include shared modules reachable via parent-escape imports#563

Draft
guyofeck wants to merge 1 commit into
mainfrom
fix/function-shared-imports
Draft

fix(functions): include shared modules reachable via parent-escape imports#563
guyofeck wants to merge 1 commit into
mainfrom
fix/function-shared-imports

Conversation

@guyofeck

@guyofeck guyofeck commented Jul 9, 2026

Copy link
Copy Markdown

Note

Description

When a Base44 function imports a shared module that lives outside its own directory (e.g. ../../shared/response.ts), that file was previously not collected and therefore not deployed, breaking the function at runtime. This PR walks the relative-import graph starting from each function's files and includes any additional modules reachable inside the backend root, ensuring shared code is bundled and deployed alongside the functions that depend on it.

Related Issue

None

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Other (please describe):

Changes Made

  • Added packages/cli/src/core/resources/function/reachability.ts with collectReachableBackendFiles(), which BFS-walks relative imports (static/dynamic import, export ... from, and require) from a function's files and returns extra modules that live inside the backend root but outside the function directory.
  • Resolver handles TypeScript's import-.js/ship-.ts convention, extensionless specifiers, and index.{ts,js} directory imports; imports that escape the backend root are ignored.
  • Wired readFunction() and the config-less function path in readAllFunctions() (config.ts) to merge these reachable files into each function's filePaths (deduped), passing a computed backendRoot.
  • Added unit tests plus a function-shared-imports fixture (two functions sharing shared/response.ts) verifying the shared file is included and that its relative path is preserved for deploy.

Testing

  • I have tested these changes locally
  • I have added/updated tests as needed
  • All tests pass (`npm test`)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have updated `docs/` (AGENTS.md) if I made architectural changes

Additional Notes

The traversal is confined to `backendRoot` so imports pointing outside the project are safely skipped, and results are deduped against the function's own files to avoid duplicate paths.


🤖 Generated by Claude | 2026-07-09 14:20 UTC | 27b0341

…ports

Functions that import shared utilities via ../../shared/... were only
uploading files inside their own subfolder; the server bundler would
reject the missing imports at deploy time.

Walk the import graph from each function's file set and collect any
additional files inside base44/ (backendRoot) that are reachable via
relative specifiers but outside the function directory. The new files
are appended to filePaths before deploy — loadFunctionCode's existing
relative(functionDir, filePath) then produces the correct ../../shared/…
paths in the payload.

Closes #562

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant