Typescript: sourceRoot should support relative paths and respect folder hirearchy

Created on 8 Oct 2015  ·  3Comments  ·  Source: microsoft/TypeScript

When supplying sourceRoot, it is just directly copied into the source map file as is. This doesn't work correctly with rootDir and outDir options. For example, if I have the following structure:

repo/src/www/foo.ts
repo/src/bar.ts

and I want to output the files into repo/out/, I tried using sourceRoot: '../src' and that works okay for bar.js, but not www/foo.js. I hope this explanation makes sense.

Question

Most helpful comment

@mhegazy @sheetalkamat I have following tsconfig.json:

{
    "compilerOptions": {
        "rootDir": "./",
        "outDir": "./out",
        "sourceMap": true
    }
}

my sources are in ./src
And in source maps I have "sources":["../../src/index.ts"]
This is correct for development, but what I want to do for production build is "sources":["src/index.ts"] (because I emit source maps with source code, and want in production build to have ts near its js). Is there way to do it?

All 3 comments

sourceRoot represents the root to use by the debug to locate the sources relative to. if you just want a relative path, do not set sourceRoot and the right thing should happen..

so here is my setup:

tsconfig.json

{
    "compilerOptions": {
        "rootDir": "./",
        "outDir": "./out",
        "sourceMap": true
    }
}

compiling, i get:

C:\test\5180>type out\bar.js.map
{"version":3,"file":"bar.js","sourceRoot":"","sources":["../src/bar.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAE,CAAC,CAAC"}
C:\test\5180>type out\www\foo.js.map
{"version":3,"file":"foo.js","sourceRoot":"","sources":["../../src/www/foo.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,CAAC,CAAC"}

My mistake, it looks like it works when I use tsc. It looks to be an issue with gulp integration. Thanks.

@mhegazy @sheetalkamat I have following tsconfig.json:

{
    "compilerOptions": {
        "rootDir": "./",
        "outDir": "./out",
        "sourceMap": true
    }
}

my sources are in ./src
And in source maps I have "sources":["../../src/index.ts"]
This is correct for development, but what I want to do for production build is "sources":["src/index.ts"] (because I emit source maps with source code, and want in production build to have ts near its js). Is there way to do it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kyasbal-1994 picture kyasbal-1994  ·  3Comments

remojansen picture remojansen  ·  3Comments

dlaberge picture dlaberge  ·  3Comments

DanielRosenwasser picture DanielRosenwasser  ·  3Comments

siddjain picture siddjain  ·  3Comments