-
-
Couldn't load subscription status.
- Fork 305
Description
Description
np should warn users when they try to publish a sourcemap that points to source files that don't exist in the package being published.
Is the feature request related to a problem?
Lately I've been wasting a lot of time chasing down libraries that publish broken sourcemaps to npm, where "broken" means that the sourcemap's sources array includes paths to source files that are either not published or are published to different locations than what's specified in the sourcemap. There are two basic cases:
- node_modules libraries that were published without source code. I've filed several PRs recently for various libraries to add their source. Most library authors have been happy to oblige. Example: Remove /source from .npmignore (for debugging with sourcemap) catamphetamine/libphonenumber-js#306
- monorepos or other cases where the sourcemap contains relative paths to source files that don't exist in the same locations after
npm installthat they did at build time. More details: map.sources converted to absolute paths + other changes webpack-contrib/source-map-loader#75 (comment)
It would be very helpful for the ecosystem if publishing tools like np showed warnings if a sourcemap points to non-existent files.
Possible solution
A solution could be something like this:
- run
npm packto generate the tarball that would be published - unpack that tarball
- Find all *.map files inside the package
- Pull out the
sourcesarray from each sourcemap - For each path in
sources, verify that that path (usually a relative path) is present in the package - If not present, show a warning, e.g.
WARN: sourcemap ${sourcemap file} references ${filePath} which does not exist. Please publish source folders for debugging!
Alternatives
- Get
npm publishto add this warning instead, which I think is the right long-term solution, but it might be helpful to first get it into a faster-evolving tool likenp.