This repository was archived by the owner on Nov 4, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +40
-15
lines changed Expand file tree Collapse file tree 2 files changed +40
-15
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { extname, sep } from "../safe/path.js"
2
2
3
3
import CHAR_CODE from "../constant/char-code.js"
4
4
5
+ import Loader from "../loader.js"
5
6
import Module from "../module.js"
6
7
7
8
import esmResolveFilename from "../module/esm/resolve-filename.js"
@@ -48,15 +49,38 @@ function init() {
48
49
}
49
50
50
51
function tryResolveFilename ( request , parent , isMain ) {
51
- try {
52
- return esmResolveFilename ( request , parent , isMain )
53
- } catch { }
52
+ const entryState = shared . entry
53
+ const entryCache = entryState . cache
54
+
55
+ const pkgState = Loader . state . package
56
+ const pkgCache = pkgState . cache
57
+
58
+ entryState . cache = new WeakMap
59
+ pkgState . cache = new Map
60
+
61
+ let result
62
+ let threw = true
54
63
55
64
try {
56
- return Module . _resolveFilename ( request , parent , isMain )
65
+ result = esmResolveFilename ( request , parent , isMain )
66
+ threw = false
57
67
} catch { }
58
68
59
- return ""
69
+ if ( threw ) {
70
+ try {
71
+ result = Module . _resolveFilename ( request , parent , isMain )
72
+ threw = false
73
+ } catch { }
74
+ }
75
+
76
+ entryState . cache = entryCache
77
+ pkgState . cache = pkgCache
78
+
79
+ if ( threw ) {
80
+ return ""
81
+ }
82
+
83
+ return result
60
84
}
61
85
62
86
return hasLoaderValue
Original file line number Diff line number Diff line change @@ -17,12 +17,16 @@ function init() {
17
17
18
18
const args = argv . slice ( 2 )
19
19
20
- let filename
21
- let nodeModulesIndex = - 1
20
+ if ( args . length === 0 ) {
21
+ return false
22
+ }
23
+
24
+ const filename = realpath ( argv [ 1 ] )
25
+ const nodeModulesIndex = normalize ( filename ) . lastIndexOf ( "/node_modules/" )
22
26
23
- if ( args . length ) {
24
- filename = realpath ( argv [ 1 ] )
25
- nodeModulesIndex = normalize ( filename ) . lastIndexOf ( "/node_modules/" )
27
+ if ( nodeModulesIndex === - 1 ||
28
+ ! hasLoaderArg ( args ) ) {
29
+ return false
26
30
}
27
31
28
32
const entryState = shared . entry
@@ -36,11 +40,8 @@ function init() {
36
40
37
41
let result = false
38
42
39
- // From a package like Mocha.
40
- if ( nodeModulesIndex !== - 1 &&
41
- hasLoaderArg ( args ) &&
42
- ( Package . get ( cwd ( ) ) !== null ||
43
- Package . get ( filename . slice ( 0 , nodeModulesIndex + 1 ) ) !== null ) ) {
43
+ if ( Package . get ( cwd ( ) ) !== null ||
44
+ Package . get ( filename . slice ( 0 , nodeModulesIndex + 1 ) ) !== null ) {
44
45
result = true
45
46
}
46
47
You can’t perform that action at this time.
0 commit comments