metro-file-map
Advanced tools
Comparing version 0.80.2 to 0.80.3
{ | ||
"name": "metro-file-map", | ||
"version": "0.80.2", | ||
"version": "0.80.3", | ||
"description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -62,8 +62,26 @@ "use strict"; | ||
function relative(rootDir, filename) { | ||
return filename.indexOf(rootDir + path.sep) === 0 | ||
? filename.substr(rootDir.length + 1) | ||
: path.relative(rootDir, filename); | ||
if (filename.indexOf(rootDir + path.sep) === 0) { | ||
const relativePath = filename.substr(rootDir.length + 1); | ||
// Allow any sequence of indirection fragments at the start of the path, | ||
// e.g ../../foo, but bail out to Node's path.relative if we find a | ||
// possible indirection after any other segment, or a leading "./". | ||
for (let i = 0; ; i += UP_FRAGMENT_LENGTH) { | ||
const nextIndirection = relativePath.indexOf(CURRENT_FRAGMENT, i); | ||
if (nextIndirection === -1) { | ||
return relativePath; | ||
} | ||
if ( | ||
nextIndirection !== i + 1 || | ||
// Fallback when ./ later in the path, or leading | ||
relativePath[i] !== "." // and for anything other than a leading ../ | ||
) { | ||
return path.relative(rootDir, filename); | ||
} | ||
} | ||
} | ||
return path.relative(rootDir, filename); | ||
} | ||
const INDIRECTION_FRAGMENT = ".." + path.sep; | ||
const INDIRECTION_FRAGMENT_LENGTH = INDIRECTION_FRAGMENT.length; | ||
const UP_FRAGMENT = ".." + path.sep; | ||
const UP_FRAGMENT_LENGTH = UP_FRAGMENT.length; | ||
const CURRENT_FRAGMENT = "." + path.sep; | ||
@@ -75,5 +93,5 @@ // rootDir must be an absolute path and normalPath must be a normal relative | ||
function resolve(rootDir, normalPath) { | ||
if (normalPath.startsWith(INDIRECTION_FRAGMENT)) { | ||
if (normalPath.startsWith(UP_FRAGMENT)) { | ||
const dirname = rootDir === "" ? "" : path.dirname(rootDir); | ||
return resolve(dirname, normalPath.slice(INDIRECTION_FRAGMENT_LENGTH)); | ||
return resolve(dirname, normalPath.slice(UP_FRAGMENT_LENGTH)); | ||
} else { | ||
@@ -80,0 +98,0 @@ return ( |
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
336316
5521