plausible / plausible-tracker

Frontend library to interact with Plausible Analytics
https://github.com/plausible/plausible-tracker
MIT License
214 stars 46 forks source link

Include src/ directory in npm package to fix source map loading #23

Closed tchebb closed 2 years ago

tchebb commented 2 years ago

Description

The compiled JavaScript we ship includes embedded source maps because we enable "inlineSourceMap" in tsconfig.json. Those source maps reference the original TypeScript files by name instead of embedding their contents because we don't set "inlineSources".

However, we currently don't include those TypeScript files in the package we distribute. We only include the compiled files from build/. This causes a warning when source-map-loader, run from a downstream package, tries to load maps:

WARNING in ./node_modules/plausible-tracker/build/module/index.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '.../node_modules/plausible-tracker/src/index.ts' file: Error: ENOENT: no such file or directory, open '.../node_modules/plausible-tracker/src/index.ts'
 @ ./src/analytics/plausible.ts 3:0-42 11:29-38
 @ ./src/index.tsx 8:0-55 13:0-14

To fix the issue, add src/ to "files" in package.json. Alternatively, we could have set "inlineSources" to true in tsconfig.json, but that results in the TypeScript being encoded as Base64, which is less efficient than just shipping the files directly.

Related Issue

22

Types of changes

Checklist:

ukutaht commented 2 years ago

Makes sense, thank you!

ukutaht commented 2 years ago

Just published v0.3.5 on NPM. Give it a try