diff --git a/packages/metro-bundler/src/node-haste/__mocks__/graceful-fs.js b/packages/metro-bundler/src/node-haste/__mocks__/graceful-fs.js index 87597310ee..157b6dce0b 100644 --- a/packages/metro-bundler/src/node-haste/__mocks__/graceful-fs.js +++ b/packages/metro-bundler/src/node-haste/__mocks__/graceful-fs.js @@ -93,92 +93,55 @@ fs.readFileSync.mockImplementation(function(filepath, encoding) { return node; }); +function makeStatResult(node) { + const isSymlink = node != null && node.SYMLINK != null; + return { + isDirectory: () => node != null && typeof node === 'object' && !isSymlink, + isSymbolicLink: () => isSymlink, + mtime, + }; +} + +function statSync(filepath) { + const node = getToNode(filepath); + if (node.SYMLINK) { + return statSync(node.SYMLINK); + } + return makeStatResult(node); +} + fs.stat.mockImplementation((filepath, callback) => { callback = asyncCallback(callback); - let node; + let result; try { - node = getToNode(filepath); + result = statSync(filepath); } catch (e) { callback(e); return; } - - if (node.SYMLINK) { - fs.stat(node.SYMLINK, callback); - return; - } - - if (node && typeof node === 'object') { - callback(null, { - isDirectory: () => true, - isSymbolicLink: () => false, - mtime, - }); - } else { - callback(null, { - isDirectory: () => false, - isSymbolicLink: () => false, - mtime, - }); - } + callback(null, result); }); -fs.statSync.mockImplementation((filepath) => { - const node = getToNode(filepath); - - if (node.SYMLINK) { - return fs.statSync(node.SYMLINK); - } +fs.statSync.mockImplementation(statSync); - return { - isDirectory: () => node && typeof node === 'object', - isSymbolicLink: () => false, - mtime, - }; -}); +function lstatSync(filepath) { + const node = getToNode(filepath); + return makeStatResult(node); +} fs.lstat.mockImplementation((filepath, callback) => { callback = asyncCallback(callback); - let node; + let result; try { - node = getToNode(filepath); + result = lstatSync(filepath); } catch (e) { callback(e); return; } - - if (node && typeof node === 'object') { - callback(null, { - isDirectory: () => true, - isSymbolicLink: () => false, - mtime, - }); - } else { - callback(null, { - isDirectory: () => false, - isSymbolicLink: () => false, - mtime, - }); - } + callback(null, result); }); -fs.lstatSync.mockImplementation((filepath) => { - const node = getToNode(filepath); - - if (node.SYMLINK) { - return { - isDirectory: () => false, - isSymbolicLink: () => true, - mtime, - }; - } - - return { - isDirectory: () => node && typeof node === 'object', - isSymbolicLink: () => false, - mtime, - }; -}); +fs.lstatSync.mockImplementation(lstatSync); fs.open.mockImplementation(function(filepath) { const callback = arguments[arguments.length - 1] || noop; @@ -277,7 +240,6 @@ fs.createWriteStream.mockImplementation(file => { }); fs.createWriteStream.mock.returned = []; - fs.__setMockFilesystem = (object) => (filesystem = object); function getToNode(filepath) { diff --git a/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js b/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js index a1318d828f..cd11a1516b 100644 --- a/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js +++ b/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js @@ -1239,61 +1239,6 @@ describe('DependencyGraph', function() { }); }); - it('should work with packages with symlinked subdirs', function() { - var root = '/root'; - setMockFileSystem({ - 'symlinkedPackage': { - 'package.json': JSON.stringify({ - name: 'aPackage', - main: 'main.js', - }), - 'main.js': 'lol', - 'subdir': { - 'lolynot.js': 'lolynot', - }, - }, - 'root': { - 'index.js': [ - '/**', - ' * @providesModule index', - ' */', - 'require("aPackage/subdir/lolynot")', - ].join('\n'), - 'aPackage': { SYMLINK: '/symlinkedPackage' }, - }, - }); - - var dgraph = new DependencyGraph({ - ...defaults, - roots: [root], - }); - return getOrderedDependenciesAsJSON(dgraph, '/root/index.js').then(function(deps) { - expect(deps) - .toEqual([ - { - id: 'index', - path: '/root/index.js', - dependencies: ['aPackage/subdir/lolynot'], - isAsset: false, - isJSON: false, - isPolyfill: false, - resolution: undefined, - resolveDependency: undefined, - }, - { - id: 'aPackage/subdir/lolynot.js', - path: '/root/aPackage/subdir/lolynot.js', - dependencies: [], - isAsset: false, - isJSON: false, - isPolyfill: false, - resolution: undefined, - resolveDependency: undefined, - }, - ]); - }); - }); - it('should work with relative modules in packages', function() { var root = '/root'; setMockFileSystem({