fix(debarrel): Harden alias resolution, type imports, and namespace barrel preservation - #36
Merged
codemod-com-bot merged 13 commits intoJul 4, 2026
Conversation
Package-boundary guard previously skipped every import whose prefix matched the workspace package.json name, which left consumers pointing at deleted barrels when the import was actually a tsconfig/webpack subpath alias. Also teach path resolution to follow alias mappings when walking export * chains and when semantic analysis resolves through a barrel file. Co-authored-by: Cursor <cursoragent@cursor.com>
Walk explicit `export { … } from` re-exports before falling back to export *
chains so default imports through `export { Foo as default }` barrels are
rewritten when semantic analysis punts. Preserve inline `import { type Foo }`
specifiers when splitting partial barrel imports to stay compatible with
verbatimModuleSyntax.
Co-authored-by: Cursor <cursoragent@cursor.com>
Stop emitting invalid `import type { type Foo }` when rewriting top-level
type-only imports, and skip barrel deletion when the workspace still
namespace-imports the barrel path.
Co-authored-by: Cursor <cursoragent@cursor.com>
Fix double `type` in rewritten type-only imports, resolve barrels already renamed in the same pass, match namespace barrels by directory, and add test fixtures for the Sentry migration failures. Co-authored-by: Cursor <cursoragent@cursor.com>
Look up barrel symbols by imported name (not local alias) so folder barrels and wildcard aliases debarrel correctly, and replace path.relative with JSSG-safe helpers for export path computation. Co-authored-by: Cursor <cursoragent@cursor.com>
Inverse-map tsconfig path aliases and scan MDX files so barrels like sentry/stories are kept when consumers use namespace imports. Co-authored-by: Cursor <cursoragent@cursor.com>
Ensure pure barrels rename even with no import edits, and add test fixtures mirroring sentry/stories and sentry/icons namespace imports. Co-authored-by: Cursor <cursoragent@cursor.com>
alexbit-codemod
requested review from
Copilot,
mohebifar and
sahilmob
and removed request for
mohebifar
July 3, 2026 08:30
alexbit-codemod
requested review from
mohebifar and
sahilmob
and removed request for
sahilmob
July 3, 2026 08:31
Add the missing SgNode import so check-types passes in CI. Co-Authored-By: Cursor <noreply@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the debarrel codemod to handle real-world TS/JS import patterns more robustly (tsconfig paths aliases, default re-exports-as-default, inline type specifiers, namespace-imported barrels, and same-pass barrel renames), and adds fixtures modeled after Sentry’s frontend layout to lock in the behavior across 0.7.4–0.7.10.
Changes:
- Harden import resolution by following tsconfig alias mappings (including wildcard aliases) and recognizing same-pass renamed barrels (
index.barrel.bak.*). - Fix import rewriting edge cases (default re-export-as-default, inline
typespecifiers, relative folder imports) and preserve barrels when they have namespace importers (including in.mdx). - Bump
debarrelversion to 0.7.10 and add multiple new JSSG test fixtures covering the above behaviors.
Reviewed changes
Copilot reviewed 203 out of 203 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| codemods/debarrel/scripts/codemod.ts | Integrates type-specifier tracking, namespace-barrel preservation, and ensures barrel renames commit even without import edits. |
| codemods/debarrel/scripts/utils/specifiers.ts | Improves specifier resolution (aliases, default re-export handling, export-walk fallback) for debarreling rewrites. |
| codemods/debarrel/scripts/utils/paths.ts | Adds alias/module resolution helpers, portable relative-path helpers, and workspace scanning utilities. |
| codemods/debarrel/scripts/utils/exportStar.ts | Adds explicit re-export walking and namespace-importer detection (including MDX + alias awareness). |
| codemods/debarrel/scripts/utils/imports.ts | Fixes invalid import type { type Foo } generation and improves type-only import emission. |
| codemods/debarrel/scripts/utils/barrel.ts | Extends barrel export parsing to support default-import consumers through export { X as default }. |
| codemods/debarrel/scripts/utils/ast.ts | Adds helper to distinguish imported name vs local alias for import { Foo as Bar }. |
| codemods/debarrel/package.json | Bumps package version to 0.7.10. |
| codemods/debarrel/codemod.yaml | Bumps codemod version metadata to 0.7.10. |
| codemods/debarrel/CHANGELOG.md | Documents 0.7.4–0.7.10 fixes and newly added fixtures. |
| codemods/debarrel/tests/wildcard-scraps-alias/metrics.json | Adds fixture metrics for wildcard alias debarreling behavior. |
| codemods/debarrel/tests/wildcard-scraps-alias/input/tsconfig.json | Adds fixture tsconfig with wildcard paths alias. |
| codemods/debarrel/tests/wildcard-scraps-alias/input/src/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/wildcard-scraps-alias/input/src/core/badge/tag.ts | Adds fixture module export used through a barrel. |
| codemods/debarrel/tests/wildcard-scraps-alias/input/src/core/badge/index.ts | Adds fixture barrel file re-exporting a symbol. |
| codemods/debarrel/tests/wildcard-scraps-alias/input/src/App.ts | Adds fixture consumer using wildcard alias import. |
| codemods/debarrel/tests/wildcard-scraps-alias/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/wildcard-scraps-alias/expected/src/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/wildcard-scraps-alias/expected/src/core/badge/tag.ts | Expected source module preserved. |
| codemods/debarrel/tests/wildcard-scraps-alias/expected/src/core/badge/index.barrel.bak.ts | Expected renamed barrel after debarreling. |
| codemods/debarrel/tests/wildcard-scraps-alias/expected/src/App.ts | Expected rewritten consumer import to concrete module path. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/metrics.json | Adds fixture metrics for MDX namespace-import barrel preservation. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/input/tsconfig.json | Adds Sentry-style sentry/* alias mapping to static/app/*. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/input/static/app/stories/storybook.ts | Adds fixture storybook module. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/input/static/app/stories/index.tsx | Adds fixture barrel re-export used by MDX namespace import. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/input/static/app/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/input/static/app/components/button.mdx | Adds MDX namespace import that should preserve the barrel. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/input/package.json | Adds fixture package metadata (package name sentry). |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/expected/static/app/stories/storybook.ts | Expected module preserved. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/expected/static/app/stories/index.tsx | Expected barrel preserved (namespace-imported). |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/expected/static/app/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/expected/static/app/components/button.mdx | Expected MDX unchanged (still namespace-importing barrel). |
| codemods/debarrel/tests/sentry-stories-mdx-namespace-barrel/expected/package.json | Expected package metadata preserved. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/metrics.json | Adds fixture metrics for Sentry-shaped workspace with namespace barrels. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/tsconfig.json | Adds fixture tsconfig with both @sentry/scraps/* and sentry/* aliases. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/stories/view/storyHeader.tsx | Adds fixture consuming both sentry/icons and namespace sentry/stories. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/stories/storybook.ts | Adds fixture storybook implementation. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/stories/index.tsx | Adds fixture barrel that must be preserved due to namespace importers. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/stories/demo.ts | Adds fixture export used under Storybook namespace. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/icons/index.tsx | Adds fixture icons barrel (namespace-imported by stories). |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/icons/icons.stories.tsx | Adds fixture namespace importer for sentry/icons. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/icons/iconAdd.ts | Adds fixture icon module. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/components/Page.tsx | Adds fixture consumer using wildcard alias import. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/components/core/button/button.mdx | Adds MDX namespace importer for sentry/stories. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/components/core/alert/index.ts | Adds fixture barrel expected to be renamed (no namespace importers). |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/static/app/components/core/alert/alert.ts | Adds fixture alert module. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/input/package.json | Adds fixture package metadata (package name sentry). |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/stories/view/storyHeader.tsx | Expected TSX preserved (barrels preserved where needed). |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/stories/storybook.ts | Expected module preserved. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/stories/index.tsx | Expected barrel preserved (namespace-imported). |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/stories/demo.ts | Expected module preserved. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/icons/index.tsx | Expected barrel preserved (namespace-imported). |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/icons/icons.stories.tsx | Expected consumer unchanged (still namespace-importing). |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/icons/iconAdd.ts | Expected module preserved. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/components/Page.tsx | Expected alias import rewrite output preserved. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/components/core/button/button.mdx | Expected MDX unchanged (still namespace-importing barrel). |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/components/core/alert/index.barrel.bak.ts | Expected renamed barrel output. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/static/app/components/core/alert/alert.ts | Expected module preserved. |
| codemods/debarrel/tests/sentry-static-app-namespace-barrels/expected/package.json | Expected package metadata preserved. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/metrics.json | Adds fixture metrics for sentry/icons namespace barrel preservation. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/input/tsconfig.json | Adds fixture tsconfig alias mapping sentry/* to static/app/*. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/input/static/app/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/input/static/app/icons/index.tsx | Adds fixture icons barrel. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/input/static/app/icons/icons.stories.tsx | Adds fixture namespace importer for icons barrel. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/input/static/app/icons/iconAdd.ts | Adds fixture icon module. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/input/package.json | Adds fixture package metadata. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/expected/static/app/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/expected/static/app/icons/index.tsx | Expected barrel preserved (namespace-imported). |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/expected/static/app/icons/icons.stories.tsx | Expected consumer unchanged (still namespace-importing). |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/expected/static/app/icons/iconAdd.ts | Expected module preserved. |
| codemods/debarrel/tests/sentry-icons-namespace-barrel/expected/package.json | Expected package metadata preserved. |
| codemods/debarrel/tests/relative-folder-import/metrics.json | Adds fixture metrics for relative folder import rewriting. |
| codemods/debarrel/tests/relative-folder-import/input/tsconfig.json | Adds fixture tsconfig for relative import case. |
| codemods/debarrel/tests/relative-folder-import/input/src/textarea/textarea.ts | Adds fixture module exported through a folder barrel. |
| codemods/debarrel/tests/relative-folder-import/input/src/textarea/index.ts | Adds fixture folder barrel. |
| codemods/debarrel/tests/relative-folder-import/input/src/input/metrics.json | Adds fixture input metrics for consumer folder. |
| codemods/debarrel/tests/relative-folder-import/input/src/input/inputGroup.ts | Adds fixture consumer using relative folder imports. |
| codemods/debarrel/tests/relative-folder-import/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/relative-folder-import/expected/src/textarea/textarea.ts | Expected module preserved. |
| codemods/debarrel/tests/relative-folder-import/expected/src/textarea/index.barrel.bak.ts | Expected renamed folder barrel. |
| codemods/debarrel/tests/relative-folder-import/expected/src/input/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/relative-folder-import/expected/src/input/inputGroup.ts | Expected rewritten relative imports to concrete module. |
| codemods/debarrel/tests/partial-with-type-specifiers/expected/src/consumer.ts | Updates expected output to keep rewritten type imports as import type. |
| codemods/debarrel/tests/package-name-subpath-alias/metrics.json | Adds fixture metrics for package-name-prefix subpath alias rewriting. |
| codemods/debarrel/tests/package-name-subpath-alias/input/tsconfig.json | Adds fixture tsconfig alias myapp/*. |
| codemods/debarrel/tests/package-name-subpath-alias/input/src/widgets/Widget.ts | Adds fixture module exported through barrel. |
| codemods/debarrel/tests/package-name-subpath-alias/input/src/widgets/index.ts | Adds fixture barrel. |
| codemods/debarrel/tests/package-name-subpath-alias/input/src/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/package-name-subpath-alias/input/src/App.ts | Adds fixture consumer importing via subpath alias. |
| codemods/debarrel/tests/package-name-subpath-alias/input/package.json | Adds fixture package name matching alias prefix. |
| codemods/debarrel/tests/package-name-subpath-alias/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/package-name-subpath-alias/expected/src/widgets/Widget.ts | Expected module preserved. |
| codemods/debarrel/tests/package-name-subpath-alias/expected/src/widgets/index.barrel.bak.ts | Expected renamed barrel. |
| codemods/debarrel/tests/package-name-subpath-alias/expected/src/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/package-name-subpath-alias/expected/src/App.ts | Expected rewritten import path into concrete module. |
| codemods/debarrel/tests/package-name-subpath-alias/expected/package.json | Expected package metadata preserved. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/tsconfig.json | Adds fixture with alias sharing package name and namespace barrels. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/src/z-widget.stories.tsx | Adds TSX namespace importer of aliased barrel. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/src/stories/storybook.ts | Adds fixture story function implementation. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/src/stories/index.tsx | Adds fixture barrel that must be preserved. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/src/stories/demo.ts | Adds fixture story export. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/src/icons/index.tsx | Adds fixture icons barrel. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/src/icons/iconAdd.ts | Adds fixture icon export. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/src/icons.stories.tsx | Adds fixture namespace importer for icons barrel. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/src/docs/widget.mdx | Adds MDX namespace importer for aliased barrel. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/input/package.json | Adds fixture package metadata (package name sentry). |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/src/z-widget.stories.tsx | Expected namespace import unchanged. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/src/stories/storybook.ts | Expected module preserved. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/src/stories/index.tsx | Expected barrel preserved (namespace-imported). |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/src/stories/demo.ts | Expected module preserved. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/src/icons/index.tsx | Expected barrel preserved (namespace-imported). |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/src/icons/iconAdd.ts | Expected module preserved. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/src/icons.stories.tsx | Expected namespace import unchanged. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/src/docs/widget.mdx | Expected MDX unchanged. |
| codemods/debarrel/tests/package-name-alias-namespace-barrel/expected/package.json | Expected package metadata preserved. |
| codemods/debarrel/tests/namespace-barrel-import/input/tsconfig.json | Adds fixture for namespace import requiring barrel preservation. |
| codemods/debarrel/tests/namespace-barrel-import/input/src/stories/storybook.ts | Adds fixture story module. |
| codemods/debarrel/tests/namespace-barrel-import/input/src/stories/index.ts | Adds fixture barrel module. |
| codemods/debarrel/tests/namespace-barrel-import/input/src/stories/demo.ts | Adds fixture demo module. |
| codemods/debarrel/tests/namespace-barrel-import/input/src/consumer.ts | Adds fixture consumer using namespace import. |
| codemods/debarrel/tests/namespace-barrel-import/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/namespace-barrel-import/expected/src/stories/storybook.ts | Expected module preserved. |
| codemods/debarrel/tests/namespace-barrel-import/expected/src/stories/index.ts | Expected barrel preserved (namespace-imported). |
| codemods/debarrel/tests/namespace-barrel-import/expected/src/stories/demo.ts | Expected module preserved. |
| codemods/debarrel/tests/namespace-barrel-import/expected/src/consumer.ts | Expected consumer unchanged (namespace import cannot be debarreled). |
| codemods/debarrel/tests/inline-type-only-import/metrics.json | Adds fixture metrics for inline type-only import handling. |
| codemods/debarrel/tests/inline-type-only-import/input/tsconfig.json | Adds fixture tsconfig for type-only import cases. |
| codemods/debarrel/tests/inline-type-only-import/input/src/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/inline-type-only-import/input/src/lib/index.ts | Adds fixture barrel exporting only a type via inline type. |
| codemods/debarrel/tests/inline-type-only-import/input/src/lib/config.ts | Adds fixture type definition module. |
| codemods/debarrel/tests/inline-type-only-import/input/src/App.ts | Adds fixture consumer using inline type-only import from barrel. |
| codemods/debarrel/tests/inline-type-only-import/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/inline-type-only-import/expected/src/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/inline-type-only-import/expected/src/lib/index.barrel.bak.ts | Expected renamed barrel after debarreling. |
| codemods/debarrel/tests/inline-type-only-import/expected/src/lib/config.ts | Expected module preserved. |
| codemods/debarrel/tests/inline-type-only-import/expected/src/App.ts | Expected rewrite to import type from the concrete module. |
| codemods/debarrel/tests/full-type-only-import/metrics.json | Adds fixture metrics for top-level import type rewriting. |
| codemods/debarrel/tests/full-type-only-import/input/tsconfig.json | Adds fixture tsconfig for top-level import type. |
| codemods/debarrel/tests/full-type-only-import/input/src/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/full-type-only-import/input/src/components/index.ts | Adds fixture barrel exporting only a type. |
| codemods/debarrel/tests/full-type-only-import/input/src/components/button.ts | Adds fixture type definition module. |
| codemods/debarrel/tests/full-type-only-import/input/src/App.ts | Adds fixture consumer using import type from barrel. |
| codemods/debarrel/tests/full-type-only-import/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/full-type-only-import/expected/src/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/full-type-only-import/expected/src/components/index.barrel.bak.ts | Expected renamed barrel after debarreling. |
| codemods/debarrel/tests/full-type-only-import/expected/src/components/button.ts | Expected module preserved. |
| codemods/debarrel/tests/full-type-only-import/expected/src/App.ts | Expected rewrite to import type from the concrete module. |
| codemods/debarrel/tests/default-reexport-as-default/metrics.json | Adds fixture metrics for default re-export-as-default handling. |
| codemods/debarrel/tests/default-reexport-as-default/input/tsconfig.json | Adds fixture tsconfig with wildcard alias. |
| codemods/debarrel/tests/default-reexport-as-default/input/src/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/default-reexport-as-default/input/src/core/interactionStateLayer/interactionStateLayer.ts | Adds fixture source module export. |
| codemods/debarrel/tests/default-reexport-as-default/input/src/core/interactionStateLayer/index.ts | Adds fixture barrel re-exporting named symbol as default. |
| codemods/debarrel/tests/default-reexport-as-default/input/src/App.ts | Adds fixture consumer default-importing from barrel. |
| codemods/debarrel/tests/default-reexport-as-default/input/package.json | Adds fixture package metadata. |
| codemods/debarrel/tests/default-reexport-as-default/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/default-reexport-as-default/expected/src/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/default-reexport-as-default/expected/src/core/interactionStateLayer/interactionStateLayer.ts | Expected module preserved. |
| codemods/debarrel/tests/default-reexport-as-default/expected/src/core/interactionStateLayer/index.barrel.bak.ts | Expected renamed barrel after debarreling. |
| codemods/debarrel/tests/default-reexport-as-default/expected/src/App.ts | Expected rewrite from default import to named import at concrete path. |
| codemods/debarrel/tests/default-reexport-as-default/expected/package.json | Expected package metadata preserved. |
| codemods/debarrel/tests/barrel-processing-order/metrics.json | Adds fixture metrics for same-pass rename ordering. |
| codemods/debarrel/tests/barrel-processing-order/input/tsconfig.json | Adds fixture tsconfig for ordering case. |
| codemods/debarrel/tests/barrel-processing-order/input/src/z-consumer.ts | Adds consumer processed after barrel rename in same pass. |
| codemods/debarrel/tests/barrel-processing-order/input/src/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/barrel-processing-order/input/src/a-stories/storybook.ts | Adds fixture story module. |
| codemods/debarrel/tests/barrel-processing-order/input/src/a-stories/index.ts | Adds fixture barrel. |
| codemods/debarrel/tests/barrel-processing-order/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/barrel-processing-order/expected/src/z-consumer.ts | Expected rewrite that resolves against renamed barrel. |
| codemods/debarrel/tests/barrel-processing-order/expected/src/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/barrel-processing-order/expected/src/a-stories/storybook.ts | Expected module preserved. |
| codemods/debarrel/tests/barrel-processing-order/expected/src/a-stories/index.barrel.bak.ts | Expected renamed barrel after debarreling. |
| codemods/debarrel/tests/alias-wildcard-folder-import/metrics.json | Adds fixture metrics for aliased imports + wildcard alias path rewriting. |
| codemods/debarrel/tests/alias-wildcard-folder-import/input/tsconfig.json | Adds fixture tsconfig with wildcard alias. |
| codemods/debarrel/tests/alias-wildcard-folder-import/input/src/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/alias-wildcard-folder-import/input/src/core/image/index.ts | Adds fixture image barrel. |
| codemods/debarrel/tests/alias-wildcard-folder-import/input/src/core/image/image.ts | Adds fixture image module. |
| codemods/debarrel/tests/alias-wildcard-folder-import/input/src/core/badge/tag.ts | Adds fixture badge module. |
| codemods/debarrel/tests/alias-wildcard-folder-import/input/src/core/badge/index.ts | Adds fixture badge barrel. |
| codemods/debarrel/tests/alias-wildcard-folder-import/input/src/App.ts | Adds fixture consumer with aliased named imports. |
| codemods/debarrel/tests/alias-wildcard-folder-import/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/alias-wildcard-folder-import/expected/src/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/alias-wildcard-folder-import/expected/src/core/image/index.barrel.bak.ts | Expected renamed barrel. |
| codemods/debarrel/tests/alias-wildcard-folder-import/expected/src/core/image/image.ts | Expected module preserved. |
| codemods/debarrel/tests/alias-wildcard-folder-import/expected/src/core/badge/tag.ts | Expected module preserved. |
| codemods/debarrel/tests/alias-wildcard-folder-import/expected/src/core/badge/index.barrel.bak.ts | Expected renamed barrel. |
| codemods/debarrel/tests/alias-wildcard-folder-import/expected/src/App.ts | Expected rewritten imports to concrete modules (preserving local aliases). |
| codemods/debarrel/tests/alias-relative-folder-import/metrics.json | Adds fixture metrics for relative folder imports with local aliases. |
| codemods/debarrel/tests/alias-relative-folder-import/input/tsconfig.json | Adds fixture tsconfig for relative folder case. |
| codemods/debarrel/tests/alias-relative-folder-import/input/src/textarea/textarea.ts | Adds fixture module exported via folder barrel. |
| codemods/debarrel/tests/alias-relative-folder-import/input/src/textarea/index.ts | Adds fixture folder barrel. |
| codemods/debarrel/tests/alias-relative-folder-import/input/src/input/metrics.json | Adds fixture input metrics. |
| codemods/debarrel/tests/alias-relative-folder-import/input/src/input/inputGroup.ts | Adds fixture consumer using relative folder imports with an alias. |
| codemods/debarrel/tests/alias-relative-folder-import/expected/tsconfig.json | Expected tsconfig preserved after codemod. |
| codemods/debarrel/tests/alias-relative-folder-import/expected/src/textarea/textarea.ts | Expected module preserved. |
| codemods/debarrel/tests/alias-relative-folder-import/expected/src/textarea/index.barrel.bak.ts | Expected renamed folder barrel. |
| codemods/debarrel/tests/alias-relative-folder-import/expected/src/input/metrics.json | Expected metrics output for fixture. |
| codemods/debarrel/tests/alias-relative-folder-import/expected/src/input/inputGroup.ts | Expected rewritten relative imports to concrete module paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sahilmob
reviewed
Jul 3, 2026
sahilmob
reviewed
Jul 3, 2026
Real-world tsconfigs (including Sentry) use comments and trailing commas, which caused JSON.parse to fail silently and skip path alias rewriting. Add a JSONC-tolerant tsconfig reader and a fixture that proves alias debarreling works when paths are declared in a commented tsconfig. Co-Authored-By: Auto <noreply@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
When the semantic analyzer resolved through a barrel to the source file,
rewrites always used named imports and keyed metrics on the target file
instead of the barrel. Route through buildRewriteFromTarget and distinguish
`export { default }` from `export { Foo as default }` when picking import
type.
Co-Authored-By: Auto <noreply@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
barrelHasNamespaceImporters walked the full project tree for every barrel candidate. Cache the file list by workspace root for the duration of a codemod run to avoid repeated recursive directory scans. Co-Authored-By: Auto <noreply@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Replace the hand-rolled relative path helper with path.relative, which is available in the JSSG runtime. joinImportPaths still avoids path.join due to its leading-../ bug. Co-Authored-By: Auto <noreply@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Co-Authored-By: Auto <noreply@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
codemod-com-bot
approved these changes
Jul 4, 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.
Debarrel 0.7.4–0.7.10 fixes a cluster of failures discovered while running the codemod against the Sentry frontend. The package-boundary guard, tsconfig alias handling, type-import rewriting, and namespace-barrel detection were each too conservative or incomplete on their own; together they left consumers pointing at deleted barrels, emitted invalid TypeScript, or removed barrels that Storybook and MDX still namespace-import.
This PR bumps
debarrelfrom 0.7.3 → 0.7.10 and adds 14 new JSSG test fixtures (including Sentry-shapedsentry/storiesandsentry/iconslayouts) that lock in the corrected behavior.Tsconfig and package-boundary alias resolution (0.7.4)
The package-boundary guard previously treated every import whose prefix matched the workspace
package.jsonname as a root package import and skipped rewriting. That broke subpath aliases likemyapp/widgetswhen the package is namedmyapp, leaving consumers pointing at deleted barrel files after debarreling.myapp,@acme/ui) from subpath aliases (myapp/widgets,@acme/ui/internal) viaisPackageRootImport.pathsaliases to absolute module files (resolveAliasImportPath,resolveModuleImportPath).export *chains and when semantic analysis resolves through a barrel to the source file.Default re-exports and inline type specifiers (0.7.5)
export { … } from "./y"re-exports before falling back toexport *chains (findSymbolViaBarrelReexports).export { Foo as default }barrels when the semantic analyzer cannot resolve the binding.import { type Foo }specifiers when splitting partial barrel imports across paths (compatible withverbatimModuleSyntax).Namespace barrel preservation (0.7.6)
Namespace imports (
import * as Ns from "…") cannot be debarreled to a single module, so barrels with namespace consumers must be kept.barrelHasNamespaceImportersfinds any workspace file namespace-importing the barrel path.import type { type Foo }output: inlinetypequalifiers on specifiers are now only emitted for mixed value/type imports split across paths, not for top-levelimport typestatements.Same-pass ordering and relative folder imports (0.7.7)
index.barrel.bak.*when a barrel was already renamed earlier in the same migration pass, so later consumers still rewrite correctly.isBarrelFile(index.barrel.bak.tspattern).../textarea) to the concrete module when the directory barrel is removed.typekeyword in rewrittenimport type { … }when specifiers carry inlinetypequalifiers.Aliased imports and JSSG-safe path helpers (0.7.8)
Fooinimport { Foo as Bar }), not the local alias, so folder barrels and wildcard aliases debarrel correctly (getImportSpecifierNames).path.relativewith portablerelativePath/relativePathFromDirhelpers for the JSSG runtime when computing export paths.Package-name tsconfig aliases and MDX scanning (0.7.9)
Sentry-style layouts map
sentry/*→./static/app/*, so consumers importsentry/storiesrather than a relative path. The namespace-importer scan must understand those aliases.getAliasImportPathsForBarrel)..mdxfiles for namespace imports when deciding whether to keep a barrel (fileHasMdxNamespaceImportFrom).findWorkspaceSourceRoot,normalizeAbsolutePath).Barrel rename commit and Sentry fixtures (0.7.10)
.tsxbarrels being skipped wheneditsis empty).sentry/storiesandsentry/iconsnamespace barrel preservation.New test fixtures
package-name-subpath-aliaspackage.jsonnamedefault-reexport-as-defaultexport { Foo as default }inline-type-only-import/full-type-only-importnamespace-barrel-importbarrel-processing-orderrelative-folder-import/alias-relative-folder-importalias-wildcard-folder-import/wildcard-scraps-aliaspackage-name-alias-namespace-barrelsentry/*-style alias + namespace barrel preservationsentry-static-app-namespace-barrelssentry-icons-namespace-barrelsentry/iconsnamespace barrelsentry-stories-mdx-namespace-barrelsentry/storiesReview focus
Start with
scripts/utils/paths.tsandscripts/utils/exportStar.tsfor the alias and namespace-importer logic, thenscripts/utils/specifiers.tsandscripts/utils/imports.tsfor import rewriting. The test fixtures undertests/are the behavioral contract for the Sentry migration failures that motivated this work.Made with Cursor