Skip to content

Explore using urls instead of absolute paths in source-map 'sources' array #8226

@loganfsmyth

Description

@loganfsmyth

Feature request

I've been exploring improvements to the source-map library to bring it more in line with the source-map specification, and one of the things I've run into is the fact that Webpack expects tooling to use the absolute path as the entry in the 'sources' array.

This directly conflicts with the spec, in the case of Windows paths, because

C:\\some\directory\file.js

will just be parsed as a URL with c: being the protocol and a pathname as

\\some\directory\file.js

which is clearly not helpful.

What is the expected behavior?

The 'sources' entry should be a valid URL, either a relative path as a simple UUID, or as a absolute path to the file itself?

What is motivation or use case for adding/changing the behavior?

Bugs like

How should this be implemented in your opinion?

In a perfect world it seems like Webpack would slowly transition to supporting file: URLs in source-map sources so that loaders could output that, and checks like

const module = self.compilation.findModule(source);
could perform a lookup based on that URL, and fall back to doing the looking based on identifier.

For instance, if loader added support for a this.resourceURL, they could transition to inserting the URL, if the property is present, and fall back to using the resourcePath for older Webpack versions.

For the example above for instance, the URL would be

file:///C://some/directory/file.js

The downside here being that if some other loader in the chain wants to process the sourcemap and it expected the non-URL versions, they'll likely have issues and would also need to be updated to handle the file: URL implementation. I think that's acceptable though as long as loaders bump their major versions when switching to use the URL version.

Are you willing to work on this yourself?
possibly!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Priority - Low

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions