From 9206aa72a82f6d10efe2179e860789d5759e557a Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Sat, 15 Jul 2023 17:18:50 -0500 Subject: [PATCH 1/2] Fix false positive of FalseExportDefault --- packages/cli/test/snapshots/ajv@8.12.0.tgz.md | 14 +++++++------- .../src/checks/entrypointResolutionProblems.ts | 7 ++++++- packages/core/test/snapshots/ajv@8.12.0.tgz.md | 8 +------- 3 files changed, 14 insertions(+), 15 deletions(-) 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 From c8993b9e0aed7a6f83ea730dbf730b7eda574999 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Sat, 15 Jul 2023 17:21:53 -0500 Subject: [PATCH 2/2] Add changeset --- .changeset/gentle-cows-yell.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gentle-cows-yell.md 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