mirror of
https://github.com/github/codeql.git
synced 2026-01-10 13:10:26 +01:00
TS: Support tsconfig.json extending from ./node_modules
This commit is contained in:
@@ -782,7 +782,7 @@ public class AutoBuild {
|
||||
}
|
||||
}
|
||||
|
||||
return new DependencyInstallationResult(packageMainFile);
|
||||
return new DependencyInstallationResult(packageMainFile, packagesInRepo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,20 +6,31 @@ import java.util.Map;
|
||||
|
||||
/** Contains the results of installing dependencies. */
|
||||
public class DependencyInstallationResult {
|
||||
private Map<String, Path> packageLocations;
|
||||
private Map<String, Path> packageEntryPoints;
|
||||
private Map<String, Path> packageJsonFiles;
|
||||
|
||||
public static final DependencyInstallationResult empty =
|
||||
new DependencyInstallationResult(Collections.emptyMap());
|
||||
new DependencyInstallationResult(Collections.emptyMap(), Collections.emptyMap());
|
||||
|
||||
public DependencyInstallationResult(Map<String, Path> localPackages) {
|
||||
this.packageLocations = localPackages;
|
||||
public DependencyInstallationResult(
|
||||
Map<String, Path> packageEntryPoints,
|
||||
Map<String, Path> packageJsonFiles) {
|
||||
this.packageEntryPoints = packageEntryPoints;
|
||||
this.packageJsonFiles = packageJsonFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapping from package names to the TypeScript file that should
|
||||
* act as its main entry point.
|
||||
*/
|
||||
public Map<String, Path> getPackageLocations() {
|
||||
return packageLocations;
|
||||
public Map<String, Path> getPackageEntryPoints() {
|
||||
return packageEntryPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapping from package name to corresponding package.json.
|
||||
*/
|
||||
public Map<String, Path> getPackageJsonFiles() {
|
||||
return packageJsonFiles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,12 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -404,6 +406,21 @@ public class TypeScriptParser {
|
||||
checkResponseType(response, "ok");
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a map to an array of [key, value] pairs.
|
||||
*/
|
||||
private JsonArray mapToArray(Map<String, Path> map) {
|
||||
JsonArray result = new JsonArray();
|
||||
map.forEach(
|
||||
(key, path) -> {
|
||||
JsonArray entry = new JsonArray();
|
||||
entry.add(key);
|
||||
entry.add(path.toString());
|
||||
result.add(entry);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a new project based on a tsconfig.json file. The compiler will analyze all files in the
|
||||
* project.
|
||||
@@ -416,16 +433,8 @@ public class TypeScriptParser {
|
||||
JsonObject request = new JsonObject();
|
||||
request.add("command", new JsonPrimitive("open-project"));
|
||||
request.add("tsConfig", new JsonPrimitive(tsConfigFile.getPath()));
|
||||
JsonArray packageLocations = new JsonArray();
|
||||
deps.getPackageLocations()
|
||||
.forEach(
|
||||
(packageName, packageDir) -> {
|
||||
JsonArray entry = new JsonArray();
|
||||
entry.add(packageName);
|
||||
entry.add(packageDir.toString());
|
||||
packageLocations.add(entry);
|
||||
});
|
||||
request.add("packageLocations", packageLocations);
|
||||
request.add("packageEntryPoints", mapToArray(deps.getPackageEntryPoints()));
|
||||
request.add("packageJsonFiles", mapToArray(deps.getPackageJsonFiles()));
|
||||
JsonObject response = talkToParserWrapper(request);
|
||||
try {
|
||||
checkResponseType(response, "project-opened");
|
||||
|
||||
Reference in New Issue
Block a user