fix(bff): make cross-project client declarations portable#8735
Open
omarshibli wants to merge 3 commits into
Open
fix(bff): make cross-project client declarations portable#8735omarshibli wants to merge 3 commits into
omarshibli wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: cdfa1c3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 118 packages
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 |
✅ Deploy Preview for modernjs-byted ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
941facd to
164e525
Compare
164e525 to
af4e073
Compare
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.

Summary
With
bff.crossProject: trueanddeclaration: true, consuming projects cannot resolve the generated<package>/api/*client types, failing with errors like:Two independent defects compound here:
compileByTsapplies the tsconfig-paths transformer only as abeforecustom transformer, and TypeScript runs those solely on the JS emit — declaration emit keeps aliases exactly as authored (Alias for TypeScript declaration emitting microsoft/TypeScript#30952). So the emitted JS getsrequire("../shared/index")while the sibling.d.tskeepsfrom '@shared/index'.clientGeneratorcopies each handler's declaration fromdist/<lambda>/…intodist/client/…verbatim. The copy lands one directory shallower than its origin, so the relative specifiers TypeScript emitted for the origin (including inlineimport("…")types) no longer resolve from the copy.Fix
Each defect is fixed in the layer that creates it:
@modern-js/server-utils— the existing tsconfig-paths transformer now also runs on declaration emit (afterDeclarations), reusing the same path matcher. The declaration variant additionally handles inlineimport("…")types (ImportTypeNode), reads specifiers via.text(declaration nodes are synthesized without source positions, sogetText()is unavailable), and keeps specifiers extensionless, matching tsc's own declaration output.@modern-js/plugin-bff— the client generator re-bases relative specifiers onto the copy's location at copy time, where the origin and destination of each file are both known.Because both fixes live where dev and build converge, dev output is fixed as well, and no post-build processing step is needed.
Real output from the
bff-corss-projectintegration fixture, before → after:Bare package specifiers (e.g.
import("@modern-js/plugin-bff/server")) are left untouched.Behavior notes
All
server-utilscompileconsumers (the BFF api compile and app-tools' server compile) now get alias-free declarations whendeclarationis enabled. The previously emitted aliased specifiers were unresolvable outside the project, and the JS emit already received the identical rewrite, so this is strictly a fix rather than a behavior change consumers could have relied on.Test plan
packages/server/utils/tests/ts.test.ts— new declaration-emit case: an aliased named import and an inlineimport("…")type are rewritten to relative specifiers; existing JS-emit cases unchanged.packages/cli/plugin-bff/tests/clientGenerator.test.ts— unit tests for specifier re-basing (from/import(…)/require(…)forms; bare specifiers untouched; no-op when origin and target match).tests/integration/bff-corss-project—bff-api-appnow has an aliased type in a handler signature; a new prod-suite test walks every generateddist-1/client/**/*.d.ts, asserts no path alias leaks, and asserts every relative specifier resolves inside the dist tree.server-utilsandplugin-bffunit suites plus the fullbff client-app in prodintegration describe are green.Related Links
Checklist
pnpm run change.