Skip to content

Commit 856469a

Browse files
author
Amjad Masad
committed
[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
1 parent 89a1e94 commit 856469a

2 files changed

Lines changed: 132 additions & 2 deletions

File tree

packager/react-packager/src/DependencyResolver/haste/DependencyGraph/__tests__/DependencyGraph-test.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,80 @@ describe('DependencyGraph', function() {
577577
});
578578
});
579579

580+
pit('should work with packages with a dot in the name', function() {
581+
var root = '/root';
582+
fs.__setMockFilesystem({
583+
'root': {
584+
'index.js': [
585+
'/**',
586+
' * @providesModule index',
587+
' */',
588+
'require("sha.js")',
589+
'require("x.y.z")',
590+
].join('\n'),
591+
'sha.js': {
592+
'package.json': JSON.stringify({
593+
name: 'sha.js',
594+
main: 'main.js'
595+
}),
596+
'main.js': 'lol'
597+
},
598+
'x.y.z': {
599+
'package.json': JSON.stringify({
600+
name: 'x.y.z',
601+
main: 'main.js'
602+
}),
603+
'main.js': 'lol'
604+
}
605+
}
606+
});
607+
608+
var dgraph = new DependencyGraph({
609+
roots: [root],
610+
fileWatcher: fileWatcher,
611+
assetExts: ['png', 'jpg'],
612+
});
613+
return dgraph.getOrderedDependencies('/root/index.js').then(function(deps) {
614+
expect(getDataFromModules(deps))
615+
.toEqual([
616+
{
617+
id: 'index',
618+
altId: '/root/index.js',
619+
path: '/root/index.js',
620+
dependencies: ['sha.js', 'x.y.z'],
621+
isAsset: false,
622+
isAsset_DEPRECATED: false,
623+
isJSON: undefined,
624+
isPolyfill: false,
625+
resolution: undefined,
626+
resolveDependency: undefined,
627+
},
628+
{
629+
id: 'sha.js/main',
630+
path: '/root/sha.js/main.js',
631+
dependencies: [],
632+
isAsset: false,
633+
isAsset_DEPRECATED: false,
634+
isJSON: undefined,
635+
isPolyfill: false,
636+
resolution: undefined,
637+
resolveDependency: undefined,
638+
},
639+
{
640+
id: 'x.y.z/main',
641+
path: '/root/x.y.z/main.js',
642+
dependencies: [],
643+
isAsset: false,
644+
isAsset_DEPRECATED: false,
645+
isJSON: undefined,
646+
isPolyfill: false,
647+
resolution: undefined,
648+
resolveDependency: undefined,
649+
},
650+
]);
651+
});
652+
});
653+
580654
pit('should default main package to index.js', function() {
581655
var root = '/root';
582656
fs.__setMockFilesystem({
@@ -2116,6 +2190,63 @@ describe('DependencyGraph', function() {
21162190
]);
21172191
});
21182192
});
2193+
2194+
pit('should work with node packages with a .js in the name', function() {
2195+
var root = '/root';
2196+
fs.__setMockFilesystem({
2197+
'root': {
2198+
'index.js': [
2199+
'/**',
2200+
' * @providesModule index',
2201+
' */',
2202+
'require("sha.js")',
2203+
].join('\n'),
2204+
'node_modules': {
2205+
'sha.js': {
2206+
'package.json': JSON.stringify({
2207+
name: 'sha.js',
2208+
main: 'main.js'
2209+
}),
2210+
'main.js': 'lol'
2211+
}
2212+
}
2213+
}
2214+
});
2215+
2216+
var dgraph = new DependencyGraph({
2217+
roots: [root],
2218+
fileWatcher: fileWatcher,
2219+
assetExts: ['png', 'jpg'],
2220+
});
2221+
return dgraph.getOrderedDependencies('/root/index.js').then(function(deps) {
2222+
expect(getDataFromModules(deps))
2223+
.toEqual([
2224+
{
2225+
id: 'index',
2226+
altId: '/root/index.js',
2227+
path: '/root/index.js',
2228+
dependencies: ['sha.js'],
2229+
isAsset: false,
2230+
isAsset_DEPRECATED: false,
2231+
isJSON: undefined,
2232+
isPolyfill: false,
2233+
resolution: undefined,
2234+
resolveDependency: undefined,
2235+
},
2236+
{
2237+
id: 'sha.js/main',
2238+
path: '/root/node_modules/sha.js/main.js',
2239+
dependencies: [],
2240+
isAsset: false,
2241+
isAsset_DEPRECATED: false,
2242+
isJSON: undefined,
2243+
isPolyfill: false,
2244+
resolution: undefined,
2245+
resolveDependency: undefined,
2246+
},
2247+
]);
2248+
});
2249+
});
21192250
});
21202251

21212252
describe('file watch updating', function() {

packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ DependecyGraph.prototype.getOrderedDependencies = function(entryPath) {
144144
function iter(mod) {
145145
var p = Promise.resolve();
146146
mod.dependencies.forEach(function(name) {
147-
var id = sansExtJs(name);
148-
var dep = self.resolveDependency(mod, id);
147+
var dep = self.resolveDependency(mod, name);
149148

150149
if (dep == null) {
151150
debug(

0 commit comments

Comments
 (0)