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

Update sourcemapPathTransform to also take the path to the sourcemap … #3617

Merged
merged 6 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion docs/999-big-list-of-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ The location of the generated bundle. If this is an absolute path, all the `sour
`sourcemapFile` is not required if `output` is specified, in which case an output filename will be inferred by adding ".map" to the output filename for the bundle.

#### output.sourcemapPathTransform
Type: `(sourcePath: string) => string`
Type: `(sourcePath: string, sourcemapPath: string) => string`

A transformation to apply to each path in a sourcemap. For instance the following will change all paths to be relative to the `src` directory.
Copy link
Member

Choose a reason for hiding this comment

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

I believe a short explanation of what sourcePath is as opposed to sourcemapPath here would help avoid a lot of confusion.


Expand Down
2 changes: 1 addition & 1 deletion src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ export default class Chunk {
const { sourcemapPathTransform } = options;

if (sourcemapPathTransform) {
const newSourcePath = sourcemapPathTransform(sourcePath);
const newSourcePath = sourcemapPathTransform(sourcePath, file + ".map");

if (typeof newSourcePath !== 'string') {
error(errFailedValidation(`sourcemapPathTransform function must return a string.`));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require('path');

module.exports = {
description:
'pass the file path to sourcemapPathTransform',
options: {
output: {
name: 'myModule',
sourcemap: true,
file: path.resolve(__dirname, 'main.js'),
sourcemapPathTransform: (relativePath, sourcemapPath) => path.resolve(path.dirname(sourcemapPath), relativePath)
}
},
generateError: {
code: 'VALIDATION_ERROR',
message: 'sourcemapPathTransform function must return a string.'
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this section is wrong but I didn't find a way to assert about the sourcemap output or even just the js output... pointers here would be helpful.

Copy link
Member

Choose a reason for hiding this comment

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

Why don't you just extend this one to use the new parameter: https://github.com/rollup/rollup/tree/master/test/sourcemaps/samples/transform-source-paths ? Alternatively, you can put a modified one next to it.

};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42;