Repository navigation
fix(functions): include shared modules reachable via parent-escape imports - #563
Merged
Merged
Conversation
…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
force-pushed
the
fix/function-shared-imports
branch
from
July 12, 2026 07:43
58a4b19 to
48b795c
Compare
Contributor
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.1.3-pr.563.e8db973Prefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.1.3-pr.563.e8db973"Or add it to your {
"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>
…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
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
previously approved these changes
Jul 13, 2026
Paveltarno
left a comment
Collaborator
There was a problem hiding this comment.
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>
guyofeck
enabled auto-merge (squash)
July 13, 2026 13:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 entirebase44/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.jsoncfiles, centralized behind a newBACKEND_FILE_GLOBconstant.Related Issue
None
Type of Change
Changes Made
BACKEND_FILE_GLOB(**/*.{js,ts,json,jsonc}) toconsts.tsand used it for both function-directory and shared-directory file collection, adding.jsoncto the set of bundled file types.readSharedFiles()infunction/config.tsto collect every file underbase44/shared/(returning an empty list when the directory is absent).filePaths(deduped viaSet) for both configured functions and zero-config (entry-only) functions.tests/fixtures/function-shared-imports/(greet, farewell, hello-sibling functions plusshared/response.tsandshared/constants.jsonc)..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
npm test)Checklist
docs/(AGENTS.md) if I made architectural changesAdditional 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