getsentry / spotlight

Your Universal Debug Toolbar
https://spotlightjs.com
Other
377 stars 11 forks source link

Declared TypeScript declaration paths for `@spotlightjs/spotlight` are incorrect in `package.json` #446

Closed jarrodldavis closed 4 months ago

jarrodldavis commented 4 months ago

Environment

Node v20.14.0, pnpm v9.6.0

Steps to Reproduce

  1. Updated @spotlightjs/spotlight from 2.0.0 to 2.1.0 using pnpm update --latest

Expected Result

TypeScript types still work.

Actual Result

I get an error from TypeScript that it can't find a declaration file for @spotlightjs/spotlight. Inspecting node_modules confirms that indeed, no declaration files (*.d.ts) files are present for the @spotlightjs/spotlight package where package.json declares them to be:

https://github.com/getsentry/spotlight/blob/87c82e8fa61cc378b9cc81bfde9d971af69502c7/packages/spotlight/package.json#L23-L26

Here is the dist folder for 2.0.0 (which TypeScript was happy with):

`dist` in v2.0.0

And here is dist in 2.1.0:

`dist` in v2.1.0

It appears that the declaration files have been moved into that new dist/src folder:

`dist/src` in v2.1.0

Patching package.json like this seems to work:

diff --git a/package.json b/package.json
index 6dc8d1165c43ac10dcdd7196b9264f48c3ac0726..51821588b38f23fa86ea18857d38b2dd5d73a518 100644
--- a/package.json
+++ b/package.json
@@ -13,20 +13,20 @@
   },
   "main": "./dist/overlay.cjs",
   "module": "./dist/overlay.js",
-  "types": "./dist/overlay.d.ts",
+  "types": "./dist/src/overlay.d.ts",
   "exports": {
     ".": {
-      "types": "./dist/overlay.d.ts",
+      "types": "./dist/src/overlay.d.ts",
       "import": "./dist/overlay.js",
       "require": "./dist/overlay.cjs"
     },
     "./sidecar": {
-      "types": "./dist/sidecar.d.ts",
+      "types": "./dist/src/sidecar.d.ts",
       "import": "./dist/sidecar.js",
       "require": "./dist/sidecar.cjs"
     },
     "./vite-plugin": {
-      "types": "./dist/vite-plugin.d.ts",
+      "types": "./dist/src/vite-plugin.d.ts",
       "import": "./dist/vite-plugin.js",
       "require": "./dist/vite-plugin.cjs"
     }
jarrodldavis commented 4 months ago

I ran a git bisect locally and it points to this PR: https://github.com/getsentry/spotlight/pull/434

Looking at that PR, no configuration changes seem obvious to cause this change, but I did notice that vite-plugin.ts imports from ../package.json. By default, TypeScript automatically computes a rootDir, and uses that value to preserve the directory structure in outDir. Because of that new import, the computed rootDir changed from src under packages/spotlight to packages/spotlight itself, causing all of the type declarations to be emitted to the new dist/src directory.

Updating tsconfig.json like this fixes the issue and emits the declaration files to the same place they were in 2.0.0:

diff --git a/packages/spotlight/tsconfig.json b/packages/spotlight/tsconfig.json
index 421f99c..908d68e 100644
--- a/packages/spotlight/tsconfig.json
+++ b/packages/spotlight/tsconfig.json
@@ -6,7 +6,8 @@
     "emitDeclarationOnly": true,
     "declaration": true,
     "noEmit": false,
-    "outDir": "dist"
+    "outDir": "dist",
+    "rootDir": "src"
   },
   "include": ["src"],
   "references": [{ "path": "./tsconfig.node.json" }]
BYK commented 4 months ago

Ouch and thanks so much for the detective work @jarrodldavis! Patch coming up now!