Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
fix(fs): more fs tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Nov 11, 2018
1 parent d4e6ec6 commit 76451b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
42 changes: 19 additions & 23 deletions lib/node/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,29 +180,25 @@ function overrideNode () {
if (!resolved) {
return false
} else {
const resolved = pkglock.resolve(p)
if (!resolved) {
const stats = pkglock.statSync(resolved)

This comment has been minimized.

Copy link
@suchipi

suchipi Nov 11, 2018

Contributor

Ah my bad, this was bad copypasta. Should have caught it

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
}
})

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion lib/pkglock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 76451b8

Please sign in to comment.