mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
JS: Pass source root to Node.js process
This commit is contained in:
@@ -48,6 +48,7 @@ interface ParseCommand {
|
||||
interface OpenProjectCommand {
|
||||
command: "open-project";
|
||||
tsConfig: string;
|
||||
sourceRoot: string | null;
|
||||
virtualSourceRoot: string | null;
|
||||
packageEntryPoints: [string, string][];
|
||||
packageJsonFiles: [string, string][];
|
||||
@@ -370,7 +371,7 @@ function handleOpenProjectCommand(command: OpenProjectCommand) {
|
||||
|
||||
let packageEntryPoints = new Map(command.packageEntryPoints);
|
||||
let packageJsonFiles = new Map(command.packageJsonFiles);
|
||||
let virtualSourceRoot = new VirtualSourceRoot(process.cwd(), command.virtualSourceRoot);
|
||||
let virtualSourceRoot = new VirtualSourceRoot(command.sourceRoot, command.virtualSourceRoot);
|
||||
|
||||
/**
|
||||
* Rewrites path segments of form `node_modules/PACK/suffix` to be relative to
|
||||
@@ -720,6 +721,7 @@ if (process.argv.length > 2) {
|
||||
tsConfig: argument,
|
||||
packageEntryPoints: [],
|
||||
packageJsonFiles: [],
|
||||
sourceRoot: null,
|
||||
virtualSourceRoot: null,
|
||||
});
|
||||
for (let sf of state.project.program.getSourceFiles()) {
|
||||
|
||||
@@ -7,20 +7,20 @@ import * as ts from "./typescript";
|
||||
*/
|
||||
export class VirtualSourceRoot {
|
||||
constructor(
|
||||
private sourceRoot: string,
|
||||
private sourceRoot: string | null,
|
||||
|
||||
/**
|
||||
* Directory whose folder structure mirrors the real source root, but with `node_modules` installed,
|
||||
* or undefined if no virtual source root exists.
|
||||
*/
|
||||
private virtualSourceRoot: string,
|
||||
private virtualSourceRoot: string | null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Maps a path under the real source root to the corresponding path in the virtual source root.
|
||||
*/
|
||||
public toVirtualPath(path: string) {
|
||||
if (!this.virtualSourceRoot) return null;
|
||||
if (!this.virtualSourceRoot || !this.sourceRoot) return null;
|
||||
let relative = pathlib.relative(this.sourceRoot, path);
|
||||
if (relative.startsWith('..') || pathlib.isAbsolute(relative)) return null;
|
||||
return pathlib.join(this.virtualSourceRoot, relative);
|
||||
|
||||
@@ -837,7 +837,7 @@ public class AutoBuild {
|
||||
}
|
||||
}
|
||||
|
||||
return new DependencyInstallationResult(virtualSourceRoot, packageMainFile, packagesInRepo);
|
||||
return new DependencyInstallationResult(sourceRoot, virtualSourceRoot, packageMainFile, packagesInRepo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,14 +6,16 @@ import java.util.Map;
|
||||
|
||||
/** Contains the results of installing dependencies. */
|
||||
public class DependencyInstallationResult {
|
||||
private Path sourceRoot;
|
||||
private Path virtualSourceRoot;
|
||||
private Map<String, Path> packageEntryPoints;
|
||||
private Map<String, Path> packageJsonFiles;
|
||||
|
||||
public static final DependencyInstallationResult empty =
|
||||
new DependencyInstallationResult(null, Collections.emptyMap(), Collections.emptyMap());
|
||||
new DependencyInstallationResult(null, null, Collections.emptyMap(), Collections.emptyMap());
|
||||
|
||||
public DependencyInstallationResult(
|
||||
Path sourceRoot,
|
||||
Path virtualSourceRoot,
|
||||
Map<String, Path> packageEntryPoints,
|
||||
Map<String, Path> packageJsonFiles) {
|
||||
@@ -21,6 +23,17 @@ public class DependencyInstallationResult {
|
||||
this.packageJsonFiles = packageJsonFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source root mirrored by {@link #getVirtualSourceRoot()} or <code>null</code>
|
||||
* if no virtual source root exists.
|
||||
* <p/>
|
||||
* When invoked from the AutoBuilder, this corresponds to the source root. When invoked
|
||||
* from ODASA, there is no notion of source root, so this is always <code>null</code> in that context.
|
||||
*/
|
||||
public Path getSourceRoot() {
|
||||
return sourceRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the virtual source root or <code>null</code> if no virtual source root exists.
|
||||
*
|
||||
|
||||
@@ -502,6 +502,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("sourceRoot", deps.getSourceRoot() == null
|
||||
? JsonNull.INSTANCE
|
||||
: new JsonPrimitive(deps.getSourceRoot().toString()));
|
||||
request.add("virtualSourceRoot", deps.getVirtualSourceRoot() == null
|
||||
? JsonNull.INSTANCE
|
||||
: new JsonPrimitive(deps.getVirtualSourceRoot().toString()));
|
||||
|
||||
Reference in New Issue
Block a user