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

Sourcemap sourceRoot #1141

Merged
merged 9 commits into from
Apr 9, 2018
Merged

Sourcemap sourceRoot #1141

merged 9 commits into from
Apr 9, 2018

Conversation

DeMoorJasper
Copy link
Member

@DeMoorJasper DeMoorJasper commented Apr 6, 2018

Closes #1100 Closes #1078

@@ -16,7 +16,7 @@ class SourceMapPackager extends Packager {

async end() {
let file = path.basename(this.bundle.name);
await this.write(this.sourceMap.stringify(file));
await this.write(this.sourceMap.stringify(file, this.options.rootDir));
Copy link
Member

Choose a reason for hiding this comment

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

Should the sourceRoot be a relative path rather than absolute? seems like maybe path.relative(options.outDir, options.rootDir)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to relative from outDir path

@DeMoorJasper DeMoorJasper changed the title Sourcemap rootDir and improved tests Sourcemap sourceRoot Apr 8, 2018
@devongovett devongovett merged commit 3b1a585 into master Apr 9, 2018
@devongovett devongovett deleted the sourcemap-fixes branch April 9, 2018 06:22
devongovett pushed a commit that referenced this pull request Oct 15, 2018
devongovett pushed a commit that referenced this pull request Oct 15, 2018
);
assert(
fs.existsSync(
path.resolve(
Copy link

@felixfbecker felixfbecker Feb 24, 2019

Choose a reason for hiding this comment

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

This is not a sufficient test, because it passes as long as path.resolve() can resolve it. But sourceRoot is a URL, so you need to test that resolving it as URL results in the right location. Which it currently doesn't, because sourceRoot doesn't contain a trailing slash, and the spec says sourceRoot gets prepended to each source (without magically adding a slash in between as path.resolve() will do).

Copy link

@felixfbecker felixfbecker Feb 24, 2019

Choose a reason for hiding this comment

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

See the source map spec:

Line 4: An optional source root, useful for relocating source files on a server or removing repeated values in the “sources” entry. This value is prepended to the individual entries in the “source” field.

Resolving Sources

If the sources are not absolute URLs after prepending of the “sourceRoot”, the sources are resolved relative to the SourceMap (like resolving script src in a html document).

https://sourcemaps.info/spec.html

let mapObject = JSON.parse(map);
assert(
mapObject.sourceRoot ===
path.relative(b.options.outDir, b.options.rootDir),

Choose a reason for hiding this comment

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

This test is incorrect on Windows because sourceRoot should always be a URL with forward slashes, but on Windows this will assert that it's a path with backslashes

@mischnic
Copy link
Member

@felixfbecker Please open a new issue, otherwise this will be forgotten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants