Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sourcemap sources removes webpack path #1122

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 6 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const resolve = require("resolve");
const fs = require("graceful-fs");
const crypto = require("crypto");
const { join, dirname, extname, relative, resolve: pathResolve } = require("path");
const { join, dirname, extname, resolve: pathResolve } = require("path");
const webpack = require("webpack");
const MemoryFS = require("memory-fs");
const terser = require("terser");
Expand Down Expand Up @@ -475,22 +475,11 @@ function ncc (
map = JSON.parse(map);
// make source map sources relative to output
map.sources = map.sources.map(source => {
// webpack:///webpack:/// happens too for some reason
while (source.startsWith('webpack:///'))
source = source.slice(11);
if (source.startsWith('//'))
source = source.slice(1);
if (source.startsWith('/'))
source = relative(process.cwd(), source).replace(/\\/g, '/');
if (source.startsWith('external '))
source = 'node:' + source.slice(9);
if (source.startsWith('./'))
source = source.slice(2);
if (source.startsWith('(webpack)'))
source = 'webpack' + source.slice(9);
if (source.startsWith('webpack/'))
return '/webpack/' + source.slice(8);
return sourceMapBasePrefix + source;
// webpack://[namespace]/[resourcePath]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this no longer accounts for the webpack:///webpack:/// case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, look at output.devtoolModuleFilenameTemplate , I think using webpack config is a better choice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Is there a way to add a test to confirm this fixes the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I've added tests

return join(
sourceMapBasePrefix,
source.replace(/^webpack:[\/]*([^\/]+\/)/, '')
);
});
}

Expand Down