Skip to content

Commit 5c77e97

Browse files
committed
JS: Implement some PackageJson members using new path resolution
1 parent c34b14c commit 5c77e97

File tree

1 file changed

+10
-8
lines changed
  • javascript/ql/lib/semmle/javascript

1 file changed

+10
-8
lines changed

javascript/ql/lib/semmle/javascript/NPM.qll

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import javascript
66
private import NodeModuleResolutionImpl
7+
private import semmle.javascript.internal.paths.PackageJsonEx
78

89
/** A `package.json` configuration object. */
910
class PackageJson extends JsonObject {
@@ -93,7 +94,10 @@ class PackageJson extends JsonObject {
9394
* `module` paths to be exported under the relative path `"."`.
9495
*/
9596
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()
97101
}
98102

99103
/** Gets the path of a command defined for this package. */
@@ -220,20 +224,18 @@ class PackageJson extends JsonObject {
220224
/**
221225
* Gets the main module of this package.
222226
*/
223-
Module getMainModule() { result = this.getExportedModule(".") }
227+
Module getMainModule() { result.getFile() = this.(PackageJsonEx).getMainFileOrBestGuess() }
224228

225229
/**
226230
* Gets the module exported under the given relative path.
227231
*
228232
* The main module is considered exported under the path `"."`.
229233
*/
230234
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()
237239
}
238240

239241
/**

0 commit comments

Comments
 (0)