|
4 | 4 |
|
5 | 5 | import javascript |
6 | 6 | private import NodeModuleResolutionImpl |
| 7 | +private import semmle.javascript.internal.paths.PackageJsonEx |
7 | 8 |
|
8 | 9 | /** A `package.json` configuration object. */ |
9 | 10 | class PackageJson extends JsonObject { |
@@ -93,7 +94,10 @@ class PackageJson extends JsonObject { |
93 | 94 | * `module` paths to be exported under the relative path `"."`. |
94 | 95 | */ |
95 | 96 | string getExportedPath(string relativePath) { |
96 | | - result = MainModulePath::of(this, relativePath).getValue() |
| 97 | + this.(PackageJsonEx).hasExactPathMapping(relativePath, result) |
| 98 | + or |
| 99 | + relativePath = "." and |
| 100 | + result = this.(PackageJsonEx).getMainPath() |
97 | 101 | } |
98 | 102 |
|
99 | 103 | /** Gets the path of a command defined for this package. */ |
@@ -220,20 +224,18 @@ class PackageJson extends JsonObject { |
220 | 224 | /** |
221 | 225 | * Gets the main module of this package. |
222 | 226 | */ |
223 | | - Module getMainModule() { result = this.getExportedModule(".") } |
| 227 | + Module getMainModule() { result.getFile() = this.(PackageJsonEx).getMainFileOrBestGuess() } |
224 | 228 |
|
225 | 229 | /** |
226 | 230 | * Gets the module exported under the given relative path. |
227 | 231 | * |
228 | 232 | * The main module is considered exported under the path `"."`. |
229 | 233 | */ |
230 | 234 | Module getExportedModule(string relativePath) { |
231 | | - result = |
232 | | - min(Module m, int prio | |
233 | | - m.getFile() = resolveMainModule(this, prio, relativePath) |
234 | | - | |
235 | | - m order by prio |
236 | | - ) |
| 235 | + this.(PackageJsonEx).hasExactPathMappingTo(relativePath, result.getFile()) |
| 236 | + or |
| 237 | + relativePath = "." and |
| 238 | + result = this.getMainModule() |
237 | 239 | } |
238 | 240 |
|
239 | 241 | /** |
|
0 commit comments