diff --git a/lib/node/fs.js b/lib/node/fs.js index 9a0dbce..19a6646 100644 --- a/lib/node/fs.js +++ b/lib/node/fs.js @@ -180,29 +180,25 @@ function overrideNode () { if (!resolved) { return false } else { - const resolved = pkglock.resolve(p) - if (!resolved) { + const stats = pkglock.statSync(resolved) + if (!stats) { return false - } else { - const stats = pkglock.statSync(resolved) - if (!stats) { - return false - } - return stats } + return stats } }) - patchFn('realpathSync', realpathSync => (...p) => { + patchFn('realpathSync', realpathSync => (p, ...args) => { try { - return realpathSync(...p) + return realpathSync(p, ...args) } catch (err) { if (err.code !== 'ENOENT') { throw err } - const resolved = pkglock.resolve(...p) + const resolved = pkglock.resolve(p) if (!resolved) { return notFoundError(p) + } else { + return resolved.resolvedPath } - return resolved.resolvedPath } }) @@ -418,16 +414,16 @@ function overrideNode () { found = true } catch (err) { if (err.code !== 'ENOENT') { throw err } - const resolved = pkglock.resolve(p) - if (resolved && resolved.isDir) { - files.push(...Object.keys(resolved.dir)) - found = true - } else { - if (!found) { - return notFoundError(p) - } else if (resolved && !resolved.isDir) { - return notDirError() - } + } + const resolved = pkglock.resolve(p) + if (resolved && resolved.isDir) { + files.push(...Object.keys(resolved.dir)) + found = true + } else { + if (!found) { + return notFoundError(p) + } else if (resolved && !resolved.isDir) { + return notDirError() } } return [...new Set(files)] @@ -468,7 +464,7 @@ function overrideNode () { pkglock.stat(resolved, true).then(stat => { if (!stat) { - notFoundError(p) + return notFoundError(p) } else if (flags === 'r') { // If we're only reading, we can read straight off cacache return open(stat.cachePath, flags, mode, cb) diff --git a/lib/pkglock.js b/lib/pkglock.js index dc46fdf..bc39bba 100644 --- a/lib/pkglock.js +++ b/lib/pkglock.js @@ -34,7 +34,16 @@ function resolve (...p) { while (subPath) { if (subPath.startsWith('/node_modules')) { subPath = subPath.substr('/node_modules'.length) - if (!subPath) { return false } + if (!subPath) { + return { + cache: process.tink.cache, + scope, + dir: scope.dependencies, + resolvedPath: resolved, + isDir: true, + isFile: false + } + } } [, pkgName, subPath, filePath] = subPath.match(/^[/\\]((?:@[^/\\]+[/\\])?[^/\\]+)([/\\]?(.*))/) let res = resolveEntity(process.tink.cache, scope, pkgName, filePath)