-
Notifications
You must be signed in to change notification settings - Fork 130
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
Sources relative paths rewritten incorrectly #538
Comments
When looking at the docs of gulp-sourcemaps this seems to be correct. Quote:
As an example, consider So I think that this behavior is correct, but not always desired. I'd suggest you to take a look at the docs of gulp-sourcemaps, I think that setting the |
Thanks for the reply ivogabe. They do actually have documentation for adding relative paths that looks like this: sourcemaps.write('.', {includeContent: false, sourceRoot: '../src'}) If you set the sourceRoot path it will override whatever sourceRoot is set in the compiler and replace it with this static path. This is the code from gulp-sourcemaps (you can tell if sourceRoot is set in the options it sets the root the same for all files regardless of how they are nested): function setSourceRoot(file) {
var debug = rootDebug.spawn('setSourceRoot');
var sourceMap = file.sourceMap;
if (typeof options.sourceRoot === 'function') {
debug(function() { return 'is function'; });
sourceMap.sourceRoot = options.sourceRoot(file);
} else {
debug(function() { return 'from options'; });
sourceMap.sourceRoot = options.sourceRoot;
}
if (sourceMap.sourceRoot === null) {
debug(function() { return 'undefined'; });
sourceMap.sourceRoot = undefined;
}
} My reason for submitting this bug though is that if you leave off the sourceRoot option it uses the sourceRoot set by the compiler. The typescript compiler actually returns a proper relative path but this module seems to overwrite it in the relativeToOutput function I modified in output.ts. I was thinking gulp-typescript could either A) not modify the sources attribute and assume the compiler output would be correct or B) re-write the path with proper relative sources path. It would make gulp-typescript more reliable for other modules that may use the sources path and expect it to be a proper relative path. |
Thanks for the clarification, I agree that we should do something about it. Option A wouldn't match the description of gulp-sourcemaps, but option B sounds like a good idea. This can break some users so this will be something for the next major release. |
Cool. I believe my PR should be a good start when the next release rolls around. Thanks for this project, super useful. |
I've taken another look at it, and compared the output of gulp-typescript with gulp-sourcemaps' identityMap. The paths are generated the same way, so I believe that the paths of gulp-typescript are correct. The sourceRoot property is not present in the source maps generated by I found that setting a relative path as sourceRoot will actually work. gulp-sourcemaps will automatically modify the sourceRoot for files in subdirectories (i.e. add
I've updated the readme and its examples with this information. |
Awesome, thanks ivogabe! |
@Tiberriver256 Have you tried in on your own project? |
Sorry not yet. I'll give it a shot tonight with the fake project structure given at the start of this issue.. |
That worked. As you suggested removing outDir from tsconfig and just using gulp.dest seems to have done the trick. Final adjusted working files (using the same structure): tsconfig.json {
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"sourceMap": true
},
"compileOnSave": true,
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
} gulpfile.js const gulp = require('gulp');
const ts = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
// pull in the project TypeScript config
const tsProject = ts.createProject('tsconfig.json');
gulp.task('scripts', () => {
var tsResult = tsProject.src()
.pipe(sourcemaps.init()) // This means sourcemaps will be generated
.pipe(tsProject());
return tsResult.js
.pipe(
sourcemaps.write({sourceRoot: '../src'})
)
.pipe(gulp.dest("./dist"));
}); |
Expected behavior:
Sources file paths in compiled .js.map files should be have correct relative paths for files in subfolders.
Directory structure:
MyFile.js.map should begin with
Actual behavior:
MyFile.js.map and begins with
Your gulpfile:
tsconfig.json
Include your tsconfig, if related to this issue.
Running the debugger it looks like the output from the typescript compiler actually has the correct relative path but gets rewritten when it hits this line (46) of release/output.js
The text was updated successfully, but these errors were encountered: