Skip to content

Detect webpack-bundled CommonJS default exports#276

Merged
andrewbranch merged 1 commit into
arethetypeswrong:mainfrom
morgan-coded:fix/212-bundled-library-default
Jul 9, 2026
Merged

Detect webpack-bundled CommonJS default exports#276
andrewbranch merged 1 commit into
arethetypeswrong:mainfrom
morgan-coded:fix/212-bundled-library-default

Conversation

@morgan-coded

Copy link
Copy Markdown
Contributor

Webpack-bundled CommonJS libraries could be reported as incorrect default exports when the wrapper hid the actual exports.default assignment inside the entry module. The export detector now follows that wrapper and aliased exports object; the esbuild, Babel, and SWC helper paths stay on their current branches.

Verification covered the bundled fixture, core tests, pnpm tsgo, pnpm check-dts, pnpm build, and the full workspace test suite with 58 core tests and 30 CLI tests passing. Fixes #212

Copilot AI review requested due to automatic review settings July 2, 2026 21:02
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c4be7e8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@arethetypeswrong/core Patch
@arethetypeswrong/cli Patch

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Improves @arethetypeswrong/core’s export-shape inference to correctly recognize default exports in webpack-bundled CommonJS output where the effective exports object is passed/aliased through the bootstrap wrapper, preventing false “incorrect default export” reports (Fixes #212).

Changes:

  • Extend probable-export detection to recognize webpack bootstrap patterns and extract assignments to the entry module’s exports parameter.
  • Add coverage for webpack-bundled CJS default exports in both getProbableExports and the exportDefaultDisagreement rule tests.
  • Publish a patch changeset for the core package.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/internal/getProbableExports.ts Adds a webpack bootstrap detector as a fallback to infer probable exports from bundled entry modules.
packages/core/test/getProbableExports.test.ts Adds a webpack CJS fixture asserting __esModule and default are detected.
packages/core/test/problems/exportDefaultDisagreement.test.ts Adds a regression test ensuring the default-export disagreement rule ignores the webpack-bundled CJS wrapper case.
.changeset/gentle-bundles-detect.md Declares a patch release for the core package describing the fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +190 to +204
function isModuleExports(node: ts.Expression) {
return (
ts.isAccessExpression(node) &&
ts.isIdentifier(node.expression) &&
node.expression.text === "module" &&
getNameOfAccessExpression(node) === "exports"
);
}

function getNameOfAccessExpression(accessExpression: ts.AccessExpression): string | undefined {
const node = ts.getNameOfAccessExpression(accessExpression);
if (ts.isIdentifier(node) || ts.isStringLiteralLike(node)) {
return node.text;
}
}

@andrewbranch andrewbranch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@andrewbranch andrewbranch merged commit c1b5eac into arethetypeswrong:main Jul 9, 2026
2 checks passed
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.

False positive for bundled library

3 participants