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
Add sourcemapBaseUrl option #4527
Merged
lukastaegert
merged 8 commits into
rollup:master
from
nickgarlis:add-sourcemap-base-url-option
Jul 8, 2022
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
23c6a15
Add sourcemapBaseUrl option
nickgarlis 588f35f
Use sourcemapBaseUrl if it's present
nickgarlis 4f99c5c
Add tests
nickgarlis cc9c2fd
Update docs
nickgarlis 81dde77
Run lint
nickgarlis d557fa1
Extend documentation, add bad URL test
lukastaegert 35c93b3
Merge branch 'master' into add-sourcemap-base-url-option
lukastaegert b922bc3
Align CLI docs
lukastaegert File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function isValidUrl(url: string): boolean { | ||
try { | ||
new URL(url); | ||
} catch (_) { | ||
return false; | ||
} | ||
return true; | ||
} |
14 changes: 14 additions & 0 deletions
14
test/function/samples/sourcemap-base-url-invalid/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
description: 'throws for invalid sourcemapBaseUrl', | ||
options: { | ||
output: { | ||
sourcemapBaseUrl: 'example.com' | ||
} | ||
}, | ||
generateError: { | ||
code: 'INVALID_OPTION', | ||
message: | ||
'Invalid value for option "output.sourcemapBaseUrl" - must be a valid URL, received "example.com".', | ||
url: 'https://rollupjs.org/guide/en/#outputsourcemapbaseurl' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log( 42 ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
description: 'adds a sourcemap base url', | ||
options: { | ||
output: { | ||
sourcemapBaseUrl: 'https://example.com' | ||
} | ||
}, | ||
test: (code, map, profile) => { | ||
assert.equal(map.file, `bundle.${profile.format}.js`); | ||
const bundlePath = path.join(__dirname, `_actual/bundle.${profile.format}.js`); | ||
const bundledCode = fs.readFileSync(bundlePath, { encoding: 'utf8', flag: 'r' }); | ||
const sourceMappingURL = bundledCode.split('\n').slice(-2)[0]; | ||
assert.equal( | ||
sourceMappingURL, | ||
`//# sourceMappingURL=https://example.com/bundle.${profile.format}.js.map` | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log( 42 ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure where I should add tests for functions like these. It looks like all of the tests in the project are end-to-end tests and do not import typescript code from
src
. @lukastaegert I'd be happy to open a separate PR adding unit tests that execute withmocha -r ts-node/register
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, please don't. Then we would still need a test that actually uses the option, i.e. an E2E test. I mean that is the point, to test the effect of this option. As e2e tests in Rollup are REALLY fast, there is really no point in writing unit tests that need to be adapted with every refactoring.
A very simple way could be to add a chunking-form test because those tests just snapshot the output directory and that would include the source map. Or you add a sourcemap test, those tests pass you the source map and you make assertions on the generated map. If all else fails, I will need to look into writing a test myself.