mirror of https://github.com/status-im/metro.git
[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:
parent
e4da97c24a
commit
581673ff3a
|
@ -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() {
|
||||
var root = '/root';
|
||||
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() {
|
||||
|
|
|
@ -144,8 +144,7 @@ DependecyGraph.prototype.getOrderedDependencies = function(entryPath) {
|
|||
function iter(mod) {
|
||||
var p = Promise.resolve();
|
||||
mod.dependencies.forEach(function(name) {
|
||||
var id = sansExtJs(name);
|
||||
var dep = self.resolveDependency(mod, id);
|
||||
var dep = self.resolveDependency(mod, name);
|
||||
|
||||
if (dep == null) {
|
||||
debug(
|
||||
|
|
Loading…
Reference in New Issue