[APPS-2792] Add: reject Node built-in imports in backend files - #476
Draft
tyffical wants to merge 1 commit into
Draft
[APPS-2792] Add: reject Node built-in imports in backend files#476tyffical wants to merge 1 commit into
tyffical wants to merge 1 commit into
Conversation
Backend functions run in a restricted environment (isomorphic/fetch-based APIs only), so direct static imports of Node built-in modules (fs, child_process, net, etc.) in .backend.ts files are now rejected at build time in the Vite transform hook, right after AST parsing. This is a best-effort, defense-in-depth check on static import specifiers only — it does not catch require() or dynamic import() of a computed specifier.
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.
Motivation
fs,child_process,net, etc.) in.backend.tsfiles are rejected at build time, so an author gets immediate, actionable feedback instead of code that silently behaves differently (or breaks) once local Node execution lands.$that omit Node-specific types) is deferred — see Out of Scope below.Changes
rejectNodeBuiltinImports, which walks a.backend.tsfile's staticImportDeclarations and throws if any source is a Node built-in (vianode:prefix or Node's ownbuiltinModuleslist).this.parse(code)and before export extraction.node:fs, barefs,child_process,net,fs/promises), and edge cases (type-only imports, non-import statements)..backend.tsfile with anode:fsimport through the actual transform handler (using rollup's realparseAst, not a hand-built AST) to confirm the rejection fires through the genuine pipeline.QA Instructions
Build the plugin and link it into a scratch Vite project, then confirm a backend file importing a Node built-in is rejected while an ordinary backend file still transforms correctly.
Blast Radius
.backend.tsfiles' static imports only. No feature flag — this is a build-time compile error for a pattern (importing Node built-ins in a restricted-runtime file) that wasn't previously usable in practice anyway, since there's no Node/Deno runtime backing.backend.tsexecution yet.importspecifiers, notrequire()or a dynamically computedimport()..backend.tsfile that doesn't import a Node built-in directly (297/297 existing apps-plugin tests pass unchanged).Out of Scope / Follow-ups
backend-function-globals.d.ts(ambient TypeScript type for$that omitsDeno/process/Node-builtin globals).d.tsinto the publisheddist/tarball requires new build-tooling wiring inpackages/tools/src/rollupConfig.mjs(shared by all 5 published bundler plugins), which is disproportionate scope for this PR. Revisit once a scaffold tool exists to actually wire the type into a consumer'stsconfig.json.Documentation
.plans/high-code-apps-local-node-execution-design.md(dd-source repo)