[react-packager] Implement getJSModulePaths API

This commit is contained in:
Amjad Masad 2015-05-20 13:38:02 -07:00
parent 0d227c0eb2
commit 8bb65215b1
2 changed files with 29 additions and 0 deletions

View File

@ -249,6 +249,15 @@ Package.prototype._getMappings = function() {
return mappings;
};
Package.prototype.getJSModulePaths = function() {
return this._modules.filter(function(module) {
// Filter out non-js files. Like images etc.
return !module.virtual;
}).map(function(module) {
return module.sourcePath;
});
};
Package.prototype.getDebugInfo = function() {
return [
'<div><h3>Main Module:</h3> ' + this._mainModuleId + '</div>',

View File

@ -204,8 +204,28 @@ describe('Package', function() {
expect(p.getAssets()).toEqual([asset1, asset2]);
});
});
describe('getJSModulePaths()', function() {
it('should return module paths', function() {
var p = new Package('test_url');
p.addModule(new ModuleTransport({
code: 'transformed foo;\n',
sourceCode: 'source foo',
sourcePath: 'foo path'
}));
p.addModule(new ModuleTransport({
code: 'image module;\nimage module;',
virtual: true,
sourceCode: 'image module;\nimage module;',
sourcePath: 'image.png',
}));
expect(p.getJSModulePaths()).toEqual(['foo path']);
});
});
});
function genSourceMap(modules) {
var sourceMapGen = new SourceMapGenerator({file: 'bundle.js', version: 3});
var packageLineNo = 0;