All files / tasks fixSourceMaps.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 6/6
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2742x                       1x 1x     42x 1x 1x 1x 1x 1x 1x        
export = function (grunt: IGrunt) {
 
	/**
	 * When compiling with --inlineSources, tsc generates sources which include folder
	 * paths. Until this is fixed, we need to remove paths leaving just the filename.
	 *
	 * ie '../../src/has.ts' -> 'has.ts'
	 *
	 * @param sourceMap input source map
	 * @return modified source map
	 */
	function fixSources(sourceMap: any): any {
		sourceMap.sources = sourceMap.sources.map((source: string) => source.replace(/.*\//, ''));
		return sourceMap;
	}
 
	grunt.registerTask('fixSourceMaps', <any> function () {
		const dist = grunt.config('distDirectory');
		const fixers = [ fixSources ];
		grunt.file.expand({ filter: 'isFile'}, [dist + '/**/*.js.map']).forEach(function(path) {
			const inputSourceMap = grunt.file.readJSON(path);
			const outputSourceMap = fixers.reduce((sourceMap, fixer) => fixer(sourceMap), inputSourceMap);
			grunt.file.write(path, JSON.stringify(outputSourceMap));
		});
	});
};