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

Source Maps: Still (but less) Broken #1669

Open
bdkjones opened this issue Aug 22, 2014 · 6 comments
Open

Source Maps: Still (but less) Broken #1669

bdkjones opened this issue Aug 22, 2014 · 6 comments

Comments

@bdkjones
Copy link

Hi guys. The source map implementation in 0.48.1 is still not quite right. Here's my project folder structure. Directories are bracketed in all-caps:

[PROJECT]
    index.html
    [STYLESHEETS]
        [STYLUS]
            basic.styl
        [CSS]
            basic.css
            basic.styl.map

I compile basic.styl with these options:

--out [full path to `CSS` folder]
--source-map
--sourcemap-base [full path to 'PROJECT' folder]

Note that the paths in the options are full paths from my disk root, like this:

/Users/myusername/documents/websites/PROJECT/STYLESHEETS/CSS

The Problem

In the scenario above, the compiler creates a source map but sets the wrong path in the "sources" array to get to the basic.styl file. Here's the path the compiler sets in the sources array within the source map file:

../stylus/stylesheets/stylus/basic.styl

But that's not correct. If my base path is [PROJECT], then the correct path for this source is:

stylesheets/stylus/basic.styl

A Workaround

If you set the --base-path option to the same path as --out, the compiler will set a correct, relative path from the source map to the basic.styl asset:

../stylus/basic.styl

While this works, the compiler should be robust enough to determine the correct paths no matter WHAT path you set as the --base-path option.

The Ultimate goal

If no --base-path option is set, the Stylus compiler should look at where the file.css.map file is being written and then calculate correct, relative paths from THAT location to each asset listed in the sources array within the source map file. This currently works correctly!

If a --base-path option IS set, then the compiler should figure out the path FROM the base-path TO each asset listed in the sources array within the source map file. (Rather than creating relative paths from the map file to each asset.) This is what's currently broken.

Recommendation

Take a look at the Uglify.js 2 repo and examine the -p relative option, which causes Uglify.js to build relative paths for all URLs involved in source maps. It may help.

@Panya
Copy link
Member

Panya commented Aug 22, 2014

If a --base-path option IS set, then the compiler should figure out the path FROM the base-path TO each asset listed in the sources array within the source map file. (Rather than creating relative paths from the map file to each asset.) This is what's currently broken.

I'm not sure that is right. From the sourcemaps spec:

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).

So --sourcemap-base should be same as --out dir in case if --out is present.

@Panya
Copy link
Member

Panya commented Aug 22, 2014

And from the --help, --sourcemap-base is not the same path as a document root of a web site. It is a path from which all sources are relative (--out in your case).

@Panya
Copy link
Member

Panya commented Aug 22, 2014

Actually we should ignore --sourcemap-base if --out is present to avoid confusion.

@Panya
Copy link
Member

Panya commented Aug 22, 2014

But that's not correct. If my base path is [PROJECT], then the correct path for this source is:

stylesheets/stylus/basic.styl

It would be correct only if you set sourceRoot to /, otherwise this path would be resolved relative to [PROJECT]/stylesheets/css/ ([PROJECT]/stylesheets/css/stylesheets/stylus/basic.styl is 404 for sure).

@bdkjones
Copy link
Author

Sorry; yep. I forgot to put in my explanation that I set the --source-root option to /. In this case, the paths in the sources array SHOULD be constructed relative to the --base-path value.

But even if you ignore that, the current implementation is not producing correct paths as you pointed out: ([PROJECT]/stylesheets/css/stylesheets/stylus/basic.styl is 404 for sure).

@Panya
Copy link
Member

Panya commented Aug 22, 2014

Yep, but --sourcemap-base is actually a base of the source map file, not a base of the project. I see 3 options here:

  1. We can ignore --sourcemap-base if --out is present (all sources will be relative to the --out).
  2. We can set paths relative to --sourcemap-base if --sourcemap-root is present (but then we should rename --sourcemap-base to just --base-path to avoid confusion).
  3. We can add an option to provide full path where the source map file will be saved (and all sources will be relative to the dirname of this path).
    BUT "workaround" (with --sourcemap-base === --out) is working completely as it should.

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

3 participants