Skip to content

fix: preserve selected barrels with remaining consumers - #9

Merged
webpro merged 2 commits into
webpro-nl:mainfrom
everton-dgn:fix/preserve-only-barrels-with-remaining-consumers
Nov 23, 2026
Merged

webpro merged 2 commits into
webpro-nl:mainfrom
everton-dgn:fix/preserve-only-barrels-with-remaining-consumers

Conversation

@everton-dgn

Copy link
Copy Markdown
Contributor

With --only, consumer registration was skipped. A selected barrel could be deleted while a dynamic import, namespace import or non-TypeScript file still needed it.

Track consumers for explicitly selected barrels, including imports inside files forced to be barrels. Register the full selection before checking its relationships so selection order does not affect preservation, and retain the correct reason for star re-exports. Supported JavaScript namespace consumers now report the same preservation reason as TypeScript consumers.

The 197-test suite passed on Node 24. All 16 focused cases passed on Node 24 and compiled Node 20, including before/after execution, selection-order controls and dry-run/check behavior. Build, typecheck, lint and formatting checks passed.

With --only, consumer registration was skipped. A selected barrel could be deleted while a dynamic import, namespace import or non-TypeScript file still needed it.

Track consumers for explicitly selected barrels, including imports inside files forced to be barrels. Register the full selection before checking its relationships so selection order does not affect preservation, and retain the correct reason for star re-exports. Supported JavaScript namespace consumers now report the same preservation reason as TypeScript consumers.

The 197-test suite passed on Node 24. All 16 focused cases passed on Node 24 and compiled Node 20, including before/after execution, selection-order controls and dry-run/check behavior. Build, typecheck, lint and formatting checks passed.

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Éverton! I reproduced this on main: with --only barrel.ts, the barrel was deleted even when a dynamic import, a namespace import or a .vue file still used it, while discovery mode kept it in all three cases. With this PR, --only reports the same as discovery mode, and the new tests fail without the change.

One structural request, inline: track consumers in one place for both modes.

Comment thread src/main.ts
Comment on lines 177 to 181
if (ctx.only.length === 0) {
await discoverBarrels(analysis, filePath, ctx);
} else {
trackExplicitBarrelConsumers(analysis, filePath, ctx);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discovery mode records the same consumers inside discoverBarrels, through its addDynamicConsumer and addConsumer calls, so consumers are now tracked in two places, one per mode. The bug came from that tracking living inside discoverBarrels, which --only skips. Could both modes call this function instead? The tracker ignores paths that aren't registered, so calling it after discoverBarrels records the same consumers, and those two calls in discoverBarrels can go. The full suite still passes with that change. A name without "Explicit" would then fit better.

Suggested change
if (ctx.only.length === 0) {
await discoverBarrels(analysis, filePath, ctx);
} else {
trackExplicitBarrelConsumers(analysis, filePath, ctx);
}
if (ctx.only.length === 0) {
await discoverBarrels(analysis, filePath, ctx);
}
trackExplicitBarrelConsumers(analysis, filePath, ctx);

Integrate the latest upstream main.

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! Both modes now track consumers in one place, and the --only cases still fail on main and pass with the change.

@webpro
webpro merged commit 0f68951 into webpro-nl:main Nov 23, 2026
5 checks passed
@webpro

webpro commented Nov 24, 2026

Copy link
Copy Markdown
Member

🚀 This pull request is included in v1.2.0. See Release 1.2.0 for release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants