metro-file-map 0.80.2 → 0.80.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/fast_path.js +25 -7
- package/src/lib/fast_path.js.flow +24 -7
package/package.json
CHANGED
package/src/lib/fast_path.js
CHANGED
|
@@ -59,21 +59,39 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
59
59
|
// rootDir must be normalized and absolute, filename may be any absolute path.
|
|
60
60
|
// (but will optimally start with rootDir)
|
|
61
61
|
function relative(rootDir, filename) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
if (filename.indexOf(rootDir + path.sep) === 0) {
|
|
63
|
+
const relativePath = filename.substr(rootDir.length + 1);
|
|
64
|
+
// Allow any sequence of indirection fragments at the start of the path,
|
|
65
|
+
// e.g ../../foo, but bail out to Node's path.relative if we find a
|
|
66
|
+
// possible indirection after any other segment, or a leading "./".
|
|
67
|
+
for (let i = 0; ; i += UP_FRAGMENT_LENGTH) {
|
|
68
|
+
const nextIndirection = relativePath.indexOf(CURRENT_FRAGMENT, i);
|
|
69
|
+
if (nextIndirection === -1) {
|
|
70
|
+
return relativePath;
|
|
71
|
+
}
|
|
72
|
+
if (
|
|
73
|
+
nextIndirection !== i + 1 ||
|
|
74
|
+
// Fallback when ./ later in the path, or leading
|
|
75
|
+
relativePath[i] !== "." // and for anything other than a leading ../
|
|
76
|
+
) {
|
|
77
|
+
return path.relative(rootDir, filename);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return path.relative(rootDir, filename);
|
|
65
82
|
}
|
|
66
|
-
const
|
|
67
|
-
const
|
|
83
|
+
const UP_FRAGMENT = ".." + path.sep;
|
|
84
|
+
const UP_FRAGMENT_LENGTH = UP_FRAGMENT.length;
|
|
85
|
+
const CURRENT_FRAGMENT = "." + path.sep;
|
|
68
86
|
|
|
69
87
|
// rootDir must be an absolute path and normalPath must be a normal relative
|
|
70
88
|
// path (e.g.: foo/bar or ../foo/bar, but never ./foo or foo/../bar)
|
|
71
89
|
// As of Node 18 this is several times faster than path.resolve, over
|
|
72
90
|
// thousands of real calls with 1-3 levels of indirection.
|
|
73
91
|
function resolve(rootDir, normalPath) {
|
|
74
|
-
if (normalPath.startsWith(
|
|
92
|
+
if (normalPath.startsWith(UP_FRAGMENT)) {
|
|
75
93
|
const dirname = rootDir === "" ? "" : path.dirname(rootDir);
|
|
76
|
-
return resolve(dirname, normalPath.slice(
|
|
94
|
+
return resolve(dirname, normalPath.slice(UP_FRAGMENT_LENGTH));
|
|
77
95
|
} else {
|
|
78
96
|
return (
|
|
79
97
|
rootDir +
|
|
@@ -13,22 +13,39 @@ import * as path from 'path';
|
|
|
13
13
|
// rootDir must be normalized and absolute, filename may be any absolute path.
|
|
14
14
|
// (but will optimally start with rootDir)
|
|
15
15
|
export function relative(rootDir: string, filename: string): string {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (filename.indexOf(rootDir + path.sep) === 0) {
|
|
17
|
+
const relativePath = filename.substr(rootDir.length + 1);
|
|
18
|
+
// Allow any sequence of indirection fragments at the start of the path,
|
|
19
|
+
// e.g ../../foo, but bail out to Node's path.relative if we find a
|
|
20
|
+
// possible indirection after any other segment, or a leading "./".
|
|
21
|
+
for (let i = 0; ; i += UP_FRAGMENT_LENGTH) {
|
|
22
|
+
const nextIndirection = relativePath.indexOf(CURRENT_FRAGMENT, i);
|
|
23
|
+
if (nextIndirection === -1) {
|
|
24
|
+
return relativePath;
|
|
25
|
+
}
|
|
26
|
+
if (
|
|
27
|
+
nextIndirection !== i + 1 || // Fallback when ./ later in the path, or leading
|
|
28
|
+
relativePath[i] !== '.' // and for anything other than a leading ../
|
|
29
|
+
) {
|
|
30
|
+
return path.relative(rootDir, filename);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return path.relative(rootDir, filename);
|
|
19
35
|
}
|
|
20
36
|
|
|
21
|
-
const
|
|
22
|
-
const
|
|
37
|
+
const UP_FRAGMENT = '..' + path.sep;
|
|
38
|
+
const UP_FRAGMENT_LENGTH = UP_FRAGMENT.length;
|
|
39
|
+
const CURRENT_FRAGMENT = '.' + path.sep;
|
|
23
40
|
|
|
24
41
|
// rootDir must be an absolute path and normalPath must be a normal relative
|
|
25
42
|
// path (e.g.: foo/bar or ../foo/bar, but never ./foo or foo/../bar)
|
|
26
43
|
// As of Node 18 this is several times faster than path.resolve, over
|
|
27
44
|
// thousands of real calls with 1-3 levels of indirection.
|
|
28
45
|
export function resolve(rootDir: string, normalPath: string): string {
|
|
29
|
-
if (normalPath.startsWith(
|
|
46
|
+
if (normalPath.startsWith(UP_FRAGMENT)) {
|
|
30
47
|
const dirname = rootDir === '' ? '' : path.dirname(rootDir);
|
|
31
|
-
return resolve(dirname, normalPath.slice(
|
|
48
|
+
return resolve(dirname, normalPath.slice(UP_FRAGMENT_LENGTH));
|
|
32
49
|
} else {
|
|
33
50
|
return (
|
|
34
51
|
rootDir +
|