[react-packager] Support packages with '.' in the name

Summary:
@public
Fixes issue #1055
For some historical reason we used to strip the extension of the module name before passing it to `resolveDependency` which is completly capable of handling all kinds of names. The fix is one line, but added a few tests for this.

Test Plan:
* ./runJestTests.sh
* ./runJestTests.sh PacakgerIntegration
* Open app and click around
This commit is contained in:
Amjad Masad 2015-06-03 14:12:03 -07:00
parent 89a1e94a15
commit 856469a24b
2 changed files with 132 additions and 2 deletions

View File

@ -577,6 +577,80 @@ describe('DependencyGraph', function() {
}); });
}); });
pit('should work with packages with a dot in the name', function() {
var root = '/root';
fs.__setMockFilesystem({
'root': {
'index.js': [
'/**',
' * @providesModule index',
' */',
'require("sha.js")',
'require("x.y.z")',
].join('\n'),
'sha.js': {
'package.json': JSON.stringify({
name: 'sha.js',
main: 'main.js'
}),
'main.js': 'lol'
},
'x.y.z': {
'package.json': JSON.stringify({
name: 'x.y.z',
main: 'main.js'
}),
'main.js': 'lol'
}
}
});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher,
assetExts: ['png', 'jpg'],
});
return dgraph.getOrderedDependencies('/root/index.js').then(function(deps) {
expect(getDataFromModules(deps))
.toEqual([
{
id: 'index',
altId: '/root/index.js',
path: '/root/index.js',
dependencies: ['sha.js', 'x.y.z'],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: undefined,
isPolyfill: false,
resolution: undefined,
resolveDependency: undefined,
},
{
id: 'sha.js/main',
path: '/root/sha.js/main.js',
dependencies: [],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: undefined,
isPolyfill: false,
resolution: undefined,
resolveDependency: undefined,
},
{
id: 'x.y.z/main',
path: '/root/x.y.z/main.js',
dependencies: [],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: undefined,
isPolyfill: false,
resolution: undefined,
resolveDependency: undefined,
},
]);
});
});
pit('should default main package to index.js', function() { pit('should default main package to index.js', function() {
var root = '/root'; var root = '/root';
fs.__setMockFilesystem({ fs.__setMockFilesystem({
@ -2116,6 +2190,63 @@ describe('DependencyGraph', function() {
]); ]);
}); });
}); });
pit('should work with node packages with a .js in the name', function() {
var root = '/root';
fs.__setMockFilesystem({
'root': {
'index.js': [
'/**',
' * @providesModule index',
' */',
'require("sha.js")',
].join('\n'),
'node_modules': {
'sha.js': {
'package.json': JSON.stringify({
name: 'sha.js',
main: 'main.js'
}),
'main.js': 'lol'
}
}
}
});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher,
assetExts: ['png', 'jpg'],
});
return dgraph.getOrderedDependencies('/root/index.js').then(function(deps) {
expect(getDataFromModules(deps))
.toEqual([
{
id: 'index',
altId: '/root/index.js',
path: '/root/index.js',
dependencies: ['sha.js'],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: undefined,
isPolyfill: false,
resolution: undefined,
resolveDependency: undefined,
},
{
id: 'sha.js/main',
path: '/root/node_modules/sha.js/main.js',
dependencies: [],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: undefined,
isPolyfill: false,
resolution: undefined,
resolveDependency: undefined,
},
]);
});
});
}); });
describe('file watch updating', function() { describe('file watch updating', function() {

View File

@ -144,8 +144,7 @@ DependecyGraph.prototype.getOrderedDependencies = function(entryPath) {
function iter(mod) { function iter(mod) {
var p = Promise.resolve(); var p = Promise.resolve();
mod.dependencies.forEach(function(name) { mod.dependencies.forEach(function(name) {
var id = sansExtJs(name); var dep = self.resolveDependency(mod, name);
var dep = self.resolveDependency(mod, id);
if (dep == null) { if (dep == null) {
debug( debug(