metro-file-map
Advanced tools
Comparing version 0.80.9 to 0.80.10
{ | ||
"name": "metro-file-map", | ||
"version": "0.80.9", | ||
"version": "0.80.10", | ||
"description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro", | ||
@@ -19,2 +19,3 @@ "main": "src/index.js", | ||
"fb-watchman": "^2.0.0", | ||
"flow-enums-runtime": "^0.0.6", | ||
"graceful-fs": "^4.2.4", | ||
@@ -21,0 +22,0 @@ "invariant": "^2.2.4", |
@@ -48,4 +48,5 @@ "use strict"; | ||
} | ||
const UP_FRAGMENT = ".." + path.sep; | ||
const UP_FRAGMENT_LENGTH = UP_FRAGMENT.length; | ||
const UP_FRAGMENT_SEP = ".." + path.sep; | ||
const SEP_UP_FRAGMENT = path.sep + ".."; | ||
const UP_FRAGMENT_SEP_LENGTH = UP_FRAGMENT_SEP.length; | ||
const CURRENT_FRAGMENT = "." + path.sep; | ||
@@ -74,2 +75,5 @@ class RootPathUtils { | ||
} | ||
getBasenameOfNthAncestor(n) { | ||
return this.#rootParts[this.#rootParts.length - 1 - n]; | ||
} | ||
absoluteToNormal(absolutePath) { | ||
@@ -105,7 +109,7 @@ let endOfMatchingPrefix = 0; | ||
while ( | ||
normalPath.startsWith(UP_FRAGMENT, pos) || | ||
normalPath.startsWith(UP_FRAGMENT_SEP, pos) || | ||
(normalPath.endsWith("..") && normalPath.length === 2 + pos) | ||
) { | ||
left = this.#rootDirnames[i === this.#rootDepth ? this.#rootDepth : ++i]; | ||
pos += UP_FRAGMENT_LENGTH; | ||
pos += UP_FRAGMENT_SEP_LENGTH; | ||
} | ||
@@ -127,2 +131,14 @@ const right = pos === 0 ? normalPath : normalPath.slice(pos); | ||
} | ||
joinNormalToRelative(normalPath, relativePath) { | ||
if (normalPath === "") { | ||
return relativePath; | ||
} | ||
if (relativePath === "") { | ||
return normalPath; | ||
} | ||
if (normalPath === ".." || normalPath.endsWith(SEP_UP_FRAGMENT)) { | ||
return this.relativeToNormal(normalPath + path.sep + relativePath); | ||
} | ||
return normalPath + path.sep + relativePath; | ||
} | ||
#tryCollapseIndirectionsInSuffix( | ||
@@ -134,3 +150,3 @@ fullPath, | ||
let totalUpIndirections = implicitUpIndirections; | ||
for (let pos = startOfRelativePart; ; pos += UP_FRAGMENT_LENGTH) { | ||
for (let pos = startOfRelativePart; ; pos += UP_FRAGMENT_SEP_LENGTH) { | ||
const nextIndirection = fullPath.indexOf(CURRENT_FRAGMENT, pos); | ||
@@ -157,3 +173,3 @@ if (nextIndirection === -1) { | ||
) { | ||
return UP_FRAGMENT.repeat(totalUpIndirections).slice(0, -1); | ||
return UP_FRAGMENT_SEP.repeat(totalUpIndirections).slice(0, -1); | ||
} | ||
@@ -163,3 +179,3 @@ if (totalUpIndirections === 0) { | ||
} | ||
return UP_FRAGMENT.repeat(totalUpIndirections) + right; | ||
return UP_FRAGMENT_SEP.repeat(totalUpIndirections) + right; | ||
} | ||
@@ -166,0 +182,0 @@ if (totalUpIndirections < this.#rootParts.length - 1) { |
@@ -108,18 +108,16 @@ "use strict"; | ||
const normalPath = this._normalizePath(mixedPath); | ||
const links = new Set(); | ||
const result = this._lookupByNormalPath(normalPath, { | ||
collectLinkPaths: links, | ||
followLeaf: true, | ||
}); | ||
if (!result.exists) { | ||
const { canonicalMissingPath, canonicalLinkPaths } = result; | ||
const { canonicalMissingPath } = result; | ||
return { | ||
exists: false, | ||
links: new Set( | ||
canonicalLinkPaths.map((canonicalPath) => | ||
this.#pathUtils.normalToAbsolute(canonicalPath) | ||
) | ||
), | ||
links, | ||
missing: this.#pathUtils.normalToAbsolute(canonicalMissingPath), | ||
}; | ||
} | ||
const { canonicalPath, canonicalLinkPaths, node } = result; | ||
const { canonicalPath, node } = result; | ||
const type = | ||
@@ -139,7 +137,3 @@ node instanceof Map | ||
exists: true, | ||
links: new Set( | ||
canonicalLinkPaths.map((canonicalPath) => | ||
this.#pathUtils.normalToAbsolute(canonicalPath) | ||
) | ||
), | ||
links, | ||
realPath: this.#pathUtils.normalToAbsolute(canonicalPath), | ||
@@ -185,4 +179,8 @@ type, | ||
} | ||
const { canonicalPath: rootRealPath, node: contextRoot } = | ||
contextRootResult; | ||
const { | ||
ancestorOfRootIdx, | ||
canonicalPath: rootRealPath, | ||
node: contextRoot, | ||
parentNode: contextRootParent, | ||
} = contextRootResult; | ||
if (!(contextRoot instanceof Map)) { | ||
@@ -200,9 +198,14 @@ return; | ||
: contextRootAbsolutePath; | ||
for (const relativePathForComparison of this._pathIterator(contextRoot, { | ||
alwaysYieldPosix: filterComparePosix, | ||
canonicalPathOfRoot: rootRealPath, | ||
follow, | ||
recursive, | ||
subtreeOnly: rootDir != null, | ||
})) { | ||
for (const relativePathForComparison of this._pathIterator( | ||
contextRoot, | ||
contextRootParent, | ||
ancestorOfRootIdx, | ||
{ | ||
alwaysYieldPosix: filterComparePosix, | ||
canonicalPathOfRoot: rootRealPath, | ||
follow, | ||
recursive, | ||
subtreeOnly: rootDir != null, | ||
} | ||
)) { | ||
if ( | ||
@@ -302,6 +305,6 @@ filter == null || | ||
let targetNormalPath = requestedNormalPath; | ||
const canonicalLinkPaths = []; | ||
let seen; | ||
let fromIdx = 0; | ||
let parentNode = this.#rootNode; | ||
let ancestorOfRootIdx = null; | ||
while (targetNormalPath.length > fromIdx) { | ||
@@ -318,6 +321,11 @@ const nextSepIdx = targetNormalPath.indexOf(_path.default.sep, fromIdx); | ||
let segmentNode = parentNode.get(segmentName); | ||
if (segmentName === "..") { | ||
ancestorOfRootIdx = | ||
ancestorOfRootIdx == null ? 1 : ancestorOfRootIdx + 1; | ||
} else if (segmentNode != null) { | ||
ancestorOfRootIdx = null; | ||
} | ||
if (segmentNode == null) { | ||
if (opts.makeDirectories !== true && segmentName !== "..") { | ||
return { | ||
canonicalLinkPaths, | ||
canonicalMissingPath: isLastSegment | ||
@@ -341,3 +349,3 @@ ? targetNormalPath | ||
return { | ||
canonicalLinkPaths, | ||
ancestorOfRootIdx, | ||
canonicalPath: targetNormalPath, | ||
@@ -357,3 +365,2 @@ exists: true, | ||
return { | ||
canonicalLinkPaths, | ||
canonicalMissingPath: currentPath, | ||
@@ -367,8 +374,13 @@ exists: false, | ||
); | ||
canonicalLinkPaths.push(currentPath); | ||
if (opts.collectLinkPaths) { | ||
opts.collectLinkPaths.add( | ||
this.#pathUtils.normalToAbsolute(currentPath) | ||
); | ||
} | ||
targetNormalPath = isLastSegment | ||
? normalSymlinkTarget | ||
: normalSymlinkTarget + | ||
_path.default.sep + | ||
targetNormalPath.slice(fromIdx); | ||
: this.#pathUtils.joinNormalToRelative( | ||
normalSymlinkTarget, | ||
targetNormalPath.slice(fromIdx) | ||
); | ||
if (seen == null) { | ||
@@ -379,3 +391,2 @@ seen = new Set([requestedNormalPath]); | ||
return { | ||
canonicalLinkPaths, | ||
canonicalMissingPath: targetNormalPath, | ||
@@ -395,3 +406,3 @@ exists: false, | ||
return { | ||
canonicalLinkPaths, | ||
ancestorOfRootIdx: null, | ||
canonicalPath: targetNormalPath, | ||
@@ -436,6 +447,26 @@ exists: true, | ||
} | ||
*_pathIterator(rootNode, opts, pathPrefix = "", followedLinks = new Set()) { | ||
*#directoryNodeIterator(node, parent, ancestorOfRootIdx) { | ||
if (ancestorOfRootIdx != null && parent) { | ||
yield [ | ||
this.#pathUtils.getBasenameOfNthAncestor(ancestorOfRootIdx - 1), | ||
parent, | ||
]; | ||
} | ||
yield* node.entries(); | ||
} | ||
*_pathIterator( | ||
iterationRootNode, | ||
iterationRootParentNode, | ||
ancestorOfRootIdx, | ||
opts, | ||
pathPrefix = "", | ||
followedLinks = new Set() | ||
) { | ||
const pathSep = opts.alwaysYieldPosix ? "/" : _path.default.sep; | ||
const prefixWithSep = pathPrefix === "" ? pathPrefix : pathPrefix + pathSep; | ||
for (const [name, node] of rootNode ?? this.#rootNode) { | ||
for (const [name, node] of this.#directoryNodeIterator( | ||
iterationRootNode, | ||
iterationRootParentNode, | ||
ancestorOfRootIdx | ||
)) { | ||
if (opts.subtreeOnly && name === "..") { | ||
@@ -473,2 +504,4 @@ continue; | ||
target, | ||
resolved.parentNode, | ||
resolved.ancestorOfRootIdx, | ||
opts, | ||
@@ -481,3 +514,12 @@ nodePath, | ||
} else if (opts.recursive) { | ||
yield* this._pathIterator(node, opts, nodePath, followedLinks); | ||
yield* this._pathIterator( | ||
node, | ||
iterationRootParentNode, | ||
ancestorOfRootIdx != null && ancestorOfRootIdx > 1 | ||
? ancestorOfRootIdx - 1 | ||
: null, | ||
opts, | ||
nodePath, | ||
followedLinks | ||
); | ||
} | ||
@@ -484,0 +526,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
323607
4841
12
+ Addedflow-enums-runtime@^0.0.6
+ Addedflow-enums-runtime@0.0.6(transitive)