fix export start reexports, add tests - #32
Merged
Conversation
cdc1996
force-pushed
the
export-start-reexport
branch
from
May 14, 2026 21:08
7f1f1c2 to
d7aad62
Compare
cdc1996
marked this pull request as ready for review
May 14, 2026 22:49
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a debarrel resolution gap where imports that reach a barrel through bare export * from "./x" re-exports were not rewritten, and it adds a regression fixture to cover the behavior (including preserving top-level import type across rewrites).
Changes:
- Add a manual
export *chain walker to resolve symbols when the semantic analyzer returnsdef.kind !== "external". - Extend path utilities with
resolveImportPath()to resolve./xto an on-disk module file (file vsindexprecedence). - Preserve top-level
import typewhen rewriting an entire import statement, and add a new fixture test for export-star re-exports.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
.changeset/export-star-rewrites.md |
Announces the export-star rewrite fix and import type preservation as a patch change. |
codemods/debarrel/scripts/codemod.ts |
Passes importer path context into specifier resolution and preserves top-level import type during rewrites. |
codemods/debarrel/scripts/utils/exportStar.ts |
New helper that walks export * from "./x" chains by reading files and finding which target exports a symbol. |
codemods/debarrel/scripts/utils/imports.ts |
Adds support for emitting import type ... in generated import text. |
codemods/debarrel/scripts/utils/paths.ts |
Adds resolveImportPath() for Node/TS-like file-vs-index resolution of relative imports. |
codemods/debarrel/scripts/utils/specifiers.ts |
Routes analyzer “punt” cases into the manual export-star walker and computes rewrite targets/metrics. |
codemods/debarrel/tests/export-star-reexport/** |
Adds a fixture validating rewrites through bare export * re-exports and import type preservation, plus metrics expectations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+173
to
+178
| const barrelDir = path.dirname(barrelFile); | ||
| let rel = path.relative(barrelDir, targetFile); | ||
| const ext = path.extname(rel); | ||
| if (ext) rel = rel.slice(0, -ext.length); | ||
| rel = rel.replace(/\/index$/, "") || "."; | ||
| const fromBarrel = rel.startsWith(".") ? rel : `./${rel}`; |
Comment on lines
143
to
147
| if (remainingSpecTexts.length > 0) { | ||
| const typeKeyword = isTypeOnlyImport ? "type " : ""; | ||
| lines.push( | ||
| `import { ${remainingSpecTexts.join(", ")} } from ${quoteChar}${importPath}${quoteChar};`, | ||
| `import ${typeKeyword}{ ${remainingSpecTexts.join(", ")} } from ${quoteChar}${importPath}${quoteChar};`, | ||
| ); |
mohebifar
approved these changes
May 18, 2026
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
Fixes a debarrel bug where consumer imports that reach the barrel through bare
export * from "./y"re-exports were silently left pointing at the barrel.Given a barrel like:
Imports of anything reached via the export * branch (here DEFAULT_CURRENCY, AddressFragment, CurrencyFragment) weren't being rewritten, defeating most of the point of running the codemod against barrels that re-export generated GraphQL types or similar.
Root cause
In this jssg runtime, localBinding.definition() does not chase through bare export * re-exports — it returns def.kind === "import" pointing back at the consumer's own import_specifier. The existing resolveSpecifier bailed early on anything that wasn't def.kind === "external", so those specifiers fell out of the rewrite loop entirely.
(The original issue writeup guessed the analyzer chased through the wildcard and landed in operations.ts. That turned out to be wrong for this runtime — the analyzer punts. The fix has to walk the chain manually.)
What changed
Tests
New fixture tests/export-star-reexport/ mirrors the shape of the reported repro:
Verified failing on main and passing after the change. Full suite stays green (85/85).
Test plan