@@ -90,21 +90,18 @@ bindingset[name]
90
90
private string getStem ( string name ) { result = name .regexpCapture ( "(.+?)(?:\\.([^.]+))?" , 1 ) }
91
91
92
92
/**
93
- * Gets the main module described by `pkg` with the given `priority`.
93
+ * Gets a file that a main module from `pkg` exported as `mainPath` with the given `priority`.
94
+ * `mainPath` is "." if it's the main module of the package.
94
95
*/
95
- File resolveMainModule ( PackageJson pkg , int priority ) {
96
- exists ( PathExpr main , int subPriority , string mainPath |
97
- main = MainModulePath:: of ( pkg , mainPath ) and
98
- if mainPath = "." then subPriority = priority else priority = subPriority + 1000
99
- |
100
- result = main .resolve ( ) and subPriority = 0
96
+ private File resolveMainPath ( PackageJson pkg , string mainPath , int priority ) {
97
+ exists ( PathExpr main | main = MainModulePath:: of ( pkg , mainPath ) |
98
+ result = main .resolve ( ) and priority = 0
101
99
or
102
- result = tryExtensions ( main .resolve ( ) , "index" , subPriority )
100
+ result = tryExtensions ( main .resolve ( ) , "index" , priority )
103
101
or
104
102
not main .resolve ( ) instanceof File and
105
103
exists ( int n | n = main .getNumComponent ( ) |
106
- result =
107
- tryExtensions ( main .resolveUpTo ( n - 1 ) , getStem ( main .getComponent ( n - 1 ) ) , subPriority )
104
+ result = tryExtensions ( main .resolveUpTo ( n - 1 ) , getStem ( main .getComponent ( n - 1 ) ) , priority )
108
105
)
109
106
or
110
107
// assuming the files get moved from one dir to another during compilation:
@@ -114,9 +111,19 @@ File resolveMainModule(PackageJson pkg, int priority) {
114
111
// is in one folder below the package.json, and has the right basename
115
112
result =
116
113
tryExtensions ( subFolder , getStem ( main .getComponent ( main .getNumComponent ( ) - 1 ) ) ,
117
- subPriority - 999 )
114
+ priority - 999 ) // very high priority, to make sure everything else is tried first
118
115
)
119
116
)
117
+ }
118
+
119
+ /**
120
+ * Gets the main module described by `pkg` with the given `priority`.
121
+ */
122
+ File resolveMainModule ( PackageJson pkg , int priority ) {
123
+ exists ( int subPriority , string mainPath |
124
+ result = resolveMainPath ( pkg , mainPath , subPriority ) and
125
+ if mainPath = "." then subPriority = priority else priority = subPriority + 1000
126
+ )
120
127
or
121
128
exists ( Folder folder , Folder child |
122
129
child = folder or
0 commit comments