Skip to content

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

Merged
guyofeck merged 8 commits into
mainfrom
fix/function-shared-imports
Jul 13, 2026
Merged

guyofeck merged 8 commits into
mainfrom
fix/function-shared-imports

Conversation

@guyofeck

@guyofeck guyofeck commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Note

Description

When deploying backend functions, shared modules imported from base44/shared/ (via ../../shared/...) previously had to be discovered by walking each functions import graph. This PR uploads the entire base44/shared/ directory wholesale alongside every function so those modules always bundle server-side, with the Deno bundler tree-shaking anything a given function does not import. It also extends the bundled-file glob to include .jsonc files, centralized behind a new BACKEND_FILE_GLOB constant.

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 BACKEND_FILE_GLOB (**/*.{js,ts,json,jsonc}) to consts.ts and used it for both function-directory and shared-directory file collection, adding .jsonc to the set of bundled file types.
  • Added readSharedFiles() in function/config.ts to collect every file under base44/shared/ (returning an empty list when the directory is absent).
  • Merged shared files into each functions filePaths (deduped via Set) for both configured functions and zero-config (entry-only) functions.
  • Added fixtures under tests/fixtures/function-shared-imports/ (greet, farewell, hello-sibling functions plus shared/response.ts and shared/constants.jsonc).
  • Added tests verifying shared files (including .jsonc) are uploaded with every function, that same-dir siblings are still included, and that a shared file resolves to the expected function-relative deploy path (../../shared/response.ts).

Testing

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

Checklist

  • My code follows the projects 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

Uploading the whole shared directory is simpler and more robust than import-graph walking; correctness relies on the server-side Deno bundler tree-shaking unused modules out of each functions payload.


🤖 Generated by Claude | 2026-07-13 13:28 UTC | e8db973

…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>
@guyofeck
guyofeck force-pushed the fix/function-shared-imports branch from 58a4b19 to 48b795c Compare July 12, 2026 07:43
@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/cli@0.1.3-pr.563.e8db973

Prefer not to change any import paths? Install using npm alias so your code still imports base44:

npm i "base44@npm:@base44-preview/cli@0.1.3-pr.563.e8db973"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "base44": "npm:@base44-preview/cli@0.1.3-pr.563.e8db973"
  }
}

Preview published to npm registry — try new features instantly!

…rror

- reachability.ts: track out-of-bounds imports (relative specifiers that
  resolve to a real file but escape past backendRoot) and return them
  alongside the extra files in a structured ReachabilityResult
- schema.ts: add outOfBoundsImports field to BackendFunctionSchema
- config.ts: populate outOfBoundsImports from reachability results
- deploy command: error and exit before uploading if any function has
  out-of-bounds imports — error message mirrors the apper bundler's own
  "Relative imports can't reach outside the function" language
- tests: add fixture (outside/secret.ts) and two new cases verifying the
  file is excluded from filePaths and that the specifier is reported

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
guyofeck and others added 4 commits July 12, 2026 11:11
…ssage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lity

Add hello-sibling fixture (entry.ts → ./util.ts → ../../shared/response.ts)
and two assertions: sibling util.ts is included via glob, and shared/response.ts
is reachable transitively through the sibling.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add farewell-js-ext fixture that imports "../../shared/response.js" and
assert response.ts is found — covering the TS project convention where
.js specifiers reference .ts source files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Format test assertions to satisfy biome line-width rules
- Un-export ReachabilityResult/OutOfBoundsImport (used only internally)
- Remove now-unused OutOfBoundsImport import from config.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@guyofeck
guyofeck marked this pull request as ready for review July 12, 2026 19:52
…ng imports

Replace the import-graph reachability walk with a simple glob of
base44/shared/**. Every function's payload now includes the shared dir;
the server bundler tree-shakes anything a function doesn't import.

Why: the regex-based walk was fragile (couldn't see through re-exports,
dynamic specifiers, or import maps) and needed extension-resolution
heuristics just to locate files. Uploading base44/shared/ wholesale is
simpler, robust, and makes the sharing convention explicit: shared code
lives in base44/shared/.

- Delete reachability.ts and its outOfBoundsImports plumbing
- config.ts: readSharedFiles() globs base44/shared/, appended to each fn
- schema.ts: drop outOfBoundsImports field
- deploy command: drop the out-of-bounds pre-check (the server bundler
  still rejects escaping imports at deploy time)
- tests/fixtures: simplify to the shared-upload model

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Paveltarno
Paveltarno previously approved these changes Jul 13, 2026

@Paveltarno Paveltarno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks great, left a comment for your consideration

Addresses review feedback (PR #563): the function-payload glob was a
duplicated "**/*.{js,ts,json}" literal in three places (function dir x2,
shared dir). Extract it to a single BACKEND_FILE_GLOB const so the
function and shared globs can't drift, and add .jsonc — base44 uses
.jsonc for config, so shared/function-local .jsonc files are now uploaded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@Paveltarno Paveltarno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🔥

@guyofeck
guyofeck merged commit d4e9633 into main Jul 13, 2026
14 checks passed
@guyofeck
guyofeck deleted the fix/function-shared-imports branch July 13, 2026 13:40
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