mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
TS: Pass virtual source root explicitly to Node.js process
This commit is contained in:
@@ -48,6 +48,7 @@ interface ParseCommand {
|
||||
interface OpenProjectCommand {
|
||||
command: "open-project";
|
||||
tsConfig: string;
|
||||
virtualSourceRoot: string | null;
|
||||
packageEntryPoints: [string, string][];
|
||||
packageJsonFiles: [string, string][];
|
||||
}
|
||||
@@ -261,7 +262,7 @@ function handleOpenProjectCommand(command: OpenProjectCommand) {
|
||||
|
||||
let packageEntryPoints = new Map(command.packageEntryPoints);
|
||||
let packageJsonFiles = new Map(command.packageJsonFiles);
|
||||
let virtualSourceRoot = new VirtualSourceRoot(process.cwd(), process.env["CODEQL_EXTRACTOR_JAVASCRIPT_SCRATCH_DIR"]);
|
||||
let virtualSourceRoot = new VirtualSourceRoot(process.cwd(), command.virtualSourceRoot);
|
||||
|
||||
/**
|
||||
* Rewrites path segments of form `node_modules/PACK/suffix` to be relative to
|
||||
@@ -582,6 +583,7 @@ if (process.argv.length > 2) {
|
||||
tsConfig: argument,
|
||||
packageEntryPoints: [],
|
||||
packageJsonFiles: [],
|
||||
virtualSourceRoot: null,
|
||||
});
|
||||
for (let sf of state.project.program.getSourceFiles()) {
|
||||
if (pathlib.basename(sf.fileName) === "lib.d.ts") continue;
|
||||
|
||||
@@ -784,7 +784,7 @@ public class AutoBuild {
|
||||
}
|
||||
}
|
||||
|
||||
return new DependencyInstallationResult(packageMainFile, packagesInRepo);
|
||||
return new DependencyInstallationResult(virtualSourceRoot, packageMainFile, packagesInRepo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,19 +6,31 @@ import java.util.Map;
|
||||
|
||||
/** Contains the results of installing dependencies. */
|
||||
public class DependencyInstallationResult {
|
||||
private Path virtualSourceRoot;
|
||||
private Map<String, Path> packageEntryPoints;
|
||||
private Map<String, Path> packageJsonFiles;
|
||||
|
||||
public static final DependencyInstallationResult empty =
|
||||
new DependencyInstallationResult(Collections.emptyMap(), Collections.emptyMap());
|
||||
new DependencyInstallationResult(null, Collections.emptyMap(), Collections.emptyMap());
|
||||
|
||||
public DependencyInstallationResult(
|
||||
Path virtualSourceRoot,
|
||||
Map<String, Path> packageEntryPoints,
|
||||
Map<String, Path> packageJsonFiles) {
|
||||
this.packageEntryPoints = packageEntryPoints;
|
||||
this.packageJsonFiles = packageJsonFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the virtual source root or <code>null</code> if no virtual source root exists.
|
||||
*
|
||||
* The virtual source root is a directory hierarchy that mirrors the real source
|
||||
* root, where dependencies are installed.
|
||||
*/
|
||||
public Path getVirtualSourceRoot() {
|
||||
return virtualSourceRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapping from package names to the TypeScript file that should
|
||||
* act as its main entry point.
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
@@ -435,6 +436,9 @@ public class TypeScriptParser {
|
||||
request.add("tsConfig", new JsonPrimitive(tsConfigFile.getPath()));
|
||||
request.add("packageEntryPoints", mapToArray(deps.getPackageEntryPoints()));
|
||||
request.add("packageJsonFiles", mapToArray(deps.getPackageJsonFiles()));
|
||||
request.add("virtualSourceRoot", deps.getVirtualSourceRoot() == null
|
||||
? JsonNull.INSTANCE
|
||||
: new JsonPrimitive(deps.getVirtualSourceRoot().toString()));
|
||||
JsonObject response = talkToParserWrapper(request);
|
||||
try {
|
||||
checkResponseType(response, "project-opened");
|
||||
|
||||
Reference in New Issue
Block a user