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

absolute paths in sourcemap #52

Closed
baabgai opened this issue Jan 16, 2015 · 8 comments
Closed

absolute paths in sourcemap #52

baabgai opened this issue Jan 16, 2015 · 8 comments

Comments

@baabgai
Copy link

baabgai commented Jan 16, 2015

In the sourcemap files written together with gulp-sourcemaps the TypeScript files end up with absolute paths instead of relativ paths in the sources tag. This leads to errors when Firefox tries to read sourcemap files and to cumbersome long paths in Chrome.
When using gulp-sourcemaps on javascript files the expected relative paths are set.

@ivogabe
Copy link
Owner

ivogabe commented Jan 17, 2015

Does setting the sourceRoot option to '' solve this? Changing the default value of sourceRoot to an empty string might solve this issue. Mentioning @shiwano since he added sourceRoot option.

@baabgai
Copy link
Author

baabgai commented Jan 19, 2015

Setting sourceRoot to empty string did work, thanks!

On Sat, Jan 17, 2015 at 8:48 PM, Ivo Gabe de Wolff <[email protected]

wrote:

Does setting the sourceRoot option to '' solve this? Changing the default
value of sourceRoot to an empty string might solve this issue. Mentioning
@shiwano https://github.com/shiwano since he added sourceRoot option.


Reply to this email directly or view it on GitHub
#52 (comment)
.

@jon-hall
Copy link

Unfortunately, I'm getting the same issue, and setting sourceRoot to '' doesn't appear to resolve it. My build step looks like this:

gulp.task('tsc', [], function () {
    'use strict';
    var tsRes = gulp.src('src/*.ts', { base: './' })
                .pipe($.sourcemaps.init())
                .pipe($.typescript({
                    target: 'ES6',
                    sortOutput: true
                }));

    return tsRes.js
        .pipe($.concat('script.js'))
        .pipe($.sourcemaps.write('.', { includeContent: false, sourceRoot: '' }))
        .pipe(gulp.dest('./dist'));
});

My TypeScript files are all internal modules present under the 'src' directory, and the generated sourcemap's 'sources' collection ends up containing all absolute paths; while the map file the TypeScript compiler generates when using the --out flag has relative paths.

@ivogabe
Copy link
Owner

ivogabe commented Jan 27, 2015

Can you set the base property in the options object of gulp-typescript instead of gulp-sourcemaps?

@jon-hall
Copy link

That solved it, cheers for the help.

Edit: Looks like I was mistaken, the first step of the build is now as follows

var tsRes = gulp.src(files.ts)
                .pipe($.sourcemaps.init())
                .pipe($.typescript({
                    target: 'ES6',
                    sortOutput: true,
                    base: './'
                }));

And I'm still getting absolute filepaths in the sourcemap, any further suggestions would be appreciated.

@zivkan
Copy link

zivkan commented Feb 10, 2015

I'm also having the same problem. My gulpfile has this:

gulp.src("app/**/*.ts")
        .pipe(sourcemap.init())
//        .pipe(typescript({base:"."})).js
        .pipe(concat("app.js"))
        .pipe(uglify())
        .pipe(sourcemap.write(".", { includeContent: false }))
        .pipe(gulp.dest("."));

With the typescript line commented out (they're still plain javascript files, I'm trying to migrate to typescript), the map file contains relative paths. With the line uncommented, the map file contains absolute paths.

I tried:

  • adding {base:"."} to the call to src()
  • adding sourceRoot to sourcemap.write's options
  • changing, or removing the base option in the call to typescript
  • removing the .js call at the end of the line that calls typescipt

but I haven't found a way to get it to use relative urls with typescript yet.

@ejmarino
Copy link

I had solved the absolute path problem putting:

sourceRoot : ''

in my typescript project object like this:

   var typeScriptProject = typescript.createProject({
        declarationFiles: false,
        noExternalResolve: false,
        removeComments: false,
        sourceRoot: ''
    });

but a new problem arise...

I have source files organized in folders but when I put sourceRoot in project properties all the files paths are removed and the file are flattened out.

This is the section of map file without sourceRoot:

"sources": [
"C:/Development/FrontEnd/scripts/module.ts",
"C:/Development/FrontEnd/scripts/controllers/controllers.ts"
]

but with sourceRoot = '':

"sources": [
"module.ts",
"controllers.ts"
]

I would expect this kind of result:

"sources": [
"module.ts",
"controllers/controllers.ts"
]

as I get when i sourcemap javascript instead typescript.

ivogabe added a commit that referenced this issue May 1, 2015
ivogabe added a commit that referenced this issue May 1, 2015
@ivogabe
Copy link
Owner

ivogabe commented May 1, 2015

Solved by removing the sourceRoot option. Because the sourceRoot property was present in the source map, gulp-concat would add that to the source property of the source map generated by gulp-concat, which resulted in an absolute path. That's now fixed by removing sourceRoot from the source-map generated by TypeScript.

Also I removed the sourceRoot option, since gulp-sourcemap has a sourceRoot option. Gulpfiles should now look like:

return gulp.src('lib/**/**.ts')
    .pipe(sourcemaps.init())
    .pipe(ts())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('release'));

If you want to provide a sourceRoot option, you can use

.pipe(sourcemaps.write('.', { sourceRoot: 'foo' }))

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

5 participants