Add --sourcemap-sources-root to RN packager

Reviewed By: davidaurelio

Differential Revision: D4357122

fbshipit-source-id: dc19474aa54ea4684a6b1c586a9d1e5da0980327
This commit is contained in:
Chris Hopman 2017-01-04 20:45:55 -08:00 committed by Facebook Github Bot
parent ebf8731ae4
commit 2165eedb71
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';
const path = require('path');
import type { MixedSourceMap } from './SourceMap';
function relativizeSourceMapInternal(sourceMap: any, sourcesRoot: string) {
if (sourceMap.sections) {
for (var i = 0; i < sourceMap.sections.length; i++) {
relativizeSourceMapInternal(sourceMap.sections[i].map, sourcesRoot);
}
} else {
for (var i = 0; i < sourceMap.sources.length; i++) {
sourceMap.sources[i] = path.relative(sourcesRoot, sourceMap.sources[i]);
}
}
}
function relativizeSourceMap(sourceMap: MixedSourceMap, sourcesRoot?: string): MixedSourceMap {
if (!sourcesRoot) {
return sourceMap;
}
relativizeSourceMapInternal(sourceMap, sourcesRoot);
return sourceMap;
}
module.exports = relativizeSourceMap;