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

Prefixing "file:///" to Windows absolute paths causes "Unknown source file" #63

Open
JoshMarler opened this issue Jun 17, 2020 · 1 comment

Comments

@JoshMarler
Copy link

JoshMarler commented Jun 17, 2020

Hi @harold-b !

I wonder if you could help me out. I'm hitting some problems setting breakpoints on Windows in my project. Everything is working great on Mac/Linux but the following code is causing issues when mapping source files with absolute paths/drive letters:

From sourceMaps.ts in SouceMap constructor

  for (let i = 0; i < sm.sources.length; i++) {
            sm.sources[i] = this.toUrl(sm.sources[i]);
        }

I'm hitting "Unknown source file" issues as a result of finding no matches in DukDebugger.ts scanDir.

This is happening because of the "file:///" prefix added to source paths containing drive letters in the toUrl function. The below comparison fails as a result:

DukDebugger.ts:2121

if (this.normPath(Path.resolve(this._outDir, candidateFile)) === path)

In my case at DukDebuffer.ts:2121 the debugger shows:

candidateFile="file:///d:/Development/Proj/Software/External/Libraries/blueprint/examples/GainPlugin/Source/jsui/src/Slider.js"

path="d:\Development\Proj\Software\External\Libraries\blueprint\examples\GainPlugin\Source\jsui\src\Slider.js"

Is this prefix to be expected here? Currently this comparison will always fail.

My webpack config uses the following source-map configuration:

 devtoolModuleFilenameTemplate: info =>
    `webpack:///${info.absoluteResourcePath.replace(/\\/g, '/')}`

In my outDir I have a single main.js and a single main.js.map file. Source paths in my map appear as below:

"webpack:///D:/Development/Proj/Software/External/Libraries/blueprint/examples/GainPlugin/Source/jsui/src/Slider.js"

My workspaceFolder/root is at D:/Development/Proj/Software/External/Libraries/blueprint/examples/GainPlugin/Source/jsui

Launch.json is as follows:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach (duk)",
            "type": "duk",
            "request": "attach",
            "address": "localhost",
            "port": 9091,
            "localRoot": "${workspaceFolder}",
            "sourceMaps": true,
            "outDir": "${workspaceFolder}/build/js",
            "stopOnEntry": true,
            "debugLog": true
        }
    ]

@JoshMarler
Copy link
Author

JoshMarler commented Jun 17, 2020

@harold-b, A quick test has shown the following implementation of toUrl resolves this for me but I suspect this isn't the correct fix:

 private toUrl(path: string, dflt?: string): string {
        if (path) {
            path = path.replace(/\\/g, "/");
            path = path.replace(/^webpack\:\/\/\//, "");

            // if path contains upper case drive letter convert to lower case
            if (/[A-Z]\:\//.test(path)) {
                const dl = path[0];
                path = path.replace(dl, dl.toLowerCase());
            }
            return path;
        }
        return dflt;
    }

FYI the desire to get this working is for the purposes of providing some debug support over at https://github.com/nick-thompson/blueprint

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

No branches or pull requests

1 participant