-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support windows paths on windows, both absolute and relative #108
Comments
I aim to resolve URLs, and URL-like paths (basically posix, function toUrl(str) {
if (str.indexOf('\\') === -1) return str;
str = str.replace(/\\/g, '/');
if (/^[a-z]:/i.test(str)) str = 'file:///' + str;
return str;
}
function toWindows(str) {
if (str.startsWith('file:///')) str = str.slice('file:///'.length);
return str.replace(/\//g, '\\');
}
const resolve = require('@jridgewell/resolve-uri');
const resolved = resolve(toUrl('c:\\foo.js.map'), toUrl('C:\\foo.js'));
console.log(toWindows(resolved));
// c:\foo.js.map I could try adding helpers to the library to handle this. |
The problem for this project is that the resolved output needs to match the format/style of the input. If the input is a windows path, the output should also be a windows path in that same style. For CommonJS modules on nodejs, this means backslashes, without file://. When we rewrite a stack frame, the input we get may look like this:
So we should mimic that style through the remapping:
This is what you'd get from node if you really were natively executing |
To achieve this, I've avoided using resolve-uri when the base is an absolute path and the URL is neither a protocol-relative nor absolute URL. In these cases I use To do this, I copied |
Trying to get this working for cspotcode/node-source-map-support#38, and hitting issues where it cannot handle Windows paths on Windows.
When pulling sourcemaps from source files, I need to resolve their sourcemap URLs relative to the file's path. For example, I get
C:\foo\bar.js
as a path, I read the file contents and parse out the source-map comment, then use resolve-uri to resolve that source-map comment relative to the windows path.Per the readme, I believe this should be supported. Is this something we can get working?
The text was updated successfully, but these errors were encountered: