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

🙋 sourceRoot support for sourcemaps #1078

Closed
Hammster opened this issue Mar 27, 2018 · 6 comments
Closed

🙋 sourceRoot support for sourcemaps #1078

Hammster opened this issue Mar 27, 2018 · 6 comments

Comments

@Hammster
Copy link
Contributor

Hammster commented Mar 27, 2018

Currently there is no way to define the sourceRoot property via parcel

💁 Possible Solution

Adding a option for the API, which tells where the sourceRoot is located

🔦 Context

The only way to to debug my electron application that has been bundled with parcel is by overriding the sourcemaps paths through the vscode debugger.

My .vscode/launch.json

{
      "type": "node",
      "request": "launch",
      "name": "Electron: Main",
      "protocol": "inspector",
      "runtimeExecutable": "yarn",
      "runtimeArgs": ["start", "-- --remote-debugging-port=9223"],
      "cwd": "${workspaceRoot}",
      "sourceMaps": true,
      "outFiles": [ "${workspaceRoot}/dist/electron/**/*.js" ],
      "sourceMapPathOverrides": {
        "*": "${workspaceRoot}/src/electron/*",
      }
    }

Normally this should be handled via the sourceRoot property of a sourcemap.

💻 Code Sample

const options = {
  outDir: './dist', // The out directory to put the build files in, defaults to dist
  outFile: 'index.html', // The name of the outputFile
  publicUrl: './dist/',
  target: 'electron',
  sourceMaps: true,
  sourceRoot: './src/'
};
@teabyii
Copy link

teabyii commented Mar 30, 2018

I have created #1100 for this feature, @Hammster can you help me to check whether it's what you want?

@Hammster
Copy link
Contributor Author

Hammster commented Mar 30, 2018

@teabyii looks great API and cli did work fine 👍! One thing though that i missed to mention in my example and i feel terrible sorry for only seeing it now is that the sourceRoot uses the relative path of the sourcemap file to navigate.

lets say your output file is in /dist/www/ containing a index.js and index.map. The sourceRoot value of ./src/www would point to /dist/www/src/www and not /src/www

Maybe a simple 'path.relative()' can fix this ?

@teabyii
Copy link

teabyii commented Mar 31, 2018

I have appended a commit to make sure sourceRoot is relative to the project. @Hammster

@Hammster
Copy link
Contributor Author

Hammster commented Apr 3, 2018

Sorry for the late reply, the path looks good for POSIX systems but on windows you end up with a .\\..\\src//www path. Browser and sourcemap reader/parser do use the POSIX format for that handling, at least to my expirience.

options.sourceRoot.split(path.sep) should give you the individual paths that you can cancat into the proper format, sadly node does not offer a built-in Windows <-> POSIX path conversion

@teabyii
Copy link

teabyii commented Apr 3, 2018

That's a problem, I forgot the Windows. Thank you, I will try to fix it as soon as possible. At first, I should get a Windows virtual machine to have a test 😃. Maybe I will try to add some tests for it.

@felixfbecker
Copy link

Btw this is because sourceRoot is a (possibly relative) URL and URLs always use slashes.

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

No branches or pull requests

4 participants