diff --git a/.changeset/gentle-cows-yell.md b/.changeset/gentle-cows-yell.md new file mode 100644 index 0000000..9a4fed2 --- /dev/null +++ b/.changeset/gentle-cows-yell.md @@ -0,0 +1,5 @@ +--- +"@arethetypeswrong/core": patch +--- + +Fix a false positive of FalseExportDefault on packages that assign both to module.exports and module.exports.default diff --git a/packages/cli/test/snapshots/ajv@8.12.0.tgz.md b/packages/cli/test/snapshots/ajv@8.12.0.tgz.md index 1cd39cf..62c4ba8 100644 --- a/packages/cli/test/snapshots/ajv@8.12.0.tgz.md +++ b/packages/cli/test/snapshots/ajv@8.12.0.tgz.md @@ -4,16 +4,16 @@ $ attw ajv@8.12.0.tgz -f table-flipped -❗️ The resolved types use export default where the JavaScript file appears to use module.exports =. This will cause TypeScript under the node16 module mode to think an extra .default property access is required, but that will likely fail at runtime. These types should use export = instead of export default. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseExportDefault.md + No problems found 🌟 -┌───────┬────────┬───────────────────┬──────────────────────────────┬─────────┐ -│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │ -├───────┼────────┼───────────────────┼──────────────────────────────┼─────────┤ -│ "ajv" │ 🟢 │ 🟢 (CJS) │ ❗️ Incorrect default export │ 🟢 │ -└───────┴────────┴───────────────────┴──────────────────────────────┴─────────┘ +┌───────┬────────┬───────────────────┬───────────────────┬─────────┐ +│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │ +├───────┼────────┼───────────────────┼───────────────────┼─────────┤ +│ "ajv" │ 🟢 │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 │ +└───────┴────────┴───────────────────┴───────────────────┴─────────┘ ``` -Exit code: 1 \ No newline at end of file +Exit code: 0 \ No newline at end of file diff --git a/packages/core/src/checks/entrypointResolutionProblems.ts b/packages/core/src/checks/entrypointResolutionProblems.ts index 65387f1..7e2a25c 100644 --- a/packages/core/src/checks/entrypointResolutionProblems.ts +++ b/packages/core/src/checks/entrypointResolutionProblems.ts @@ -82,7 +82,12 @@ export function getEntrypointResolutionProblems( } const jsExports = jsSourceFile?.symbol?.exports; if (typesExports && jsExports) { - if (typesExports.has(ts.InternalSymbolName.Default) && jsExports.has(ts.InternalSymbolName.ExportEquals)) { + if ( + typesExports.has(ts.InternalSymbolName.Default) && + !typesExports.has(ts.InternalSymbolName.ExportEquals) && + jsExports.has(ts.InternalSymbolName.ExportEquals) && + !jsExports.has(ts.InternalSymbolName.Default) + ) { // Also need to check for `default` property on `jsModule["export="]`? problems.push({ kind: "FalseExportDefault", diff --git a/packages/core/test/snapshots/ajv@8.12.0.tgz.md b/packages/core/test/snapshots/ajv@8.12.0.tgz.md index 93d6620..b5ae95a 100644 --- a/packages/core/test/snapshots/ajv@8.12.0.tgz.md +++ b/packages/core/test/snapshots/ajv@8.12.0.tgz.md @@ -3,11 +3,5 @@ ## Problems ```json -[ - { - "kind": "FalseExportDefault", - "entrypoint": ".", - "resolutionKind": "node16-esm" - } -] +[] ``` \ No newline at end of file