Multiple File support in debugger (#2130)

Summary:
Release Notes: Add support for multiple input files for the debugger, in both debugger-cli and prepack-cli (used by debugger when launched from Nuclide).
Closes https://github.com/facebook/prepack/pull/2130

Differential Revision: D8554746

Pulled By: caiismyname

fbshipit-source-id: ffba51d0bc6f2b7fa171072a358bdfc5c911a2d7
This commit is contained in:
David Cai 2018-06-20 18:08:03 -07:00 committed by Facebook Github Bot
parent 5af00f1ed0
commit 9486a4c4e0
6 changed files with 26 additions and 17 deletions

View File

@ -116,7 +116,7 @@ class PrepackDebugSession extends DebugSession {
this._registerMessageCallbacks();
let launchArgs: PrepackLaunchArguments = {
kind: "launch",
sourceFile: args.sourceFile,
sourceFiles: args.sourceFiles,
prepackRuntime: args.prepackRuntime,
prepackArguments: args.prepackArguments,
debugInFilePath: inFilePath,

View File

@ -86,7 +86,7 @@ export class AdapterChannel {
launch(requestID: number, args: PrepackLaunchArguments, callback: DebuggerResponse => void) {
this.sendDebuggerStart(requestID);
this.listenOnFile(this._processPrepackMessage.bind(this));
let prepackCommand = [args.sourceFile].concat(args.prepackArguments);
let prepackCommand = args.sourceFiles.concat(args.prepackArguments);
// Note: here the input file for the adapter is the output file for Prepack, and vice versa.
prepackCommand = prepackCommand.concat([
"--debugInFilePath",

View File

@ -33,7 +33,7 @@ export type PrepackLaunchArguments = {
kind: "launch",
prepackRuntime: string,
prepackArguments: Array<string>,
sourceFile: string,
sourceFiles: Array<string>,
debugInFilePath: string,
debugOutFilePath: string,
outputCallback: Buffer => void,
@ -167,7 +167,7 @@ export type EvaluateResult = {
export type LaunchRequestArguments = {
...DebugProtocol.LaunchRequestArguments,
noDebug?: boolean,
sourceFile: string,
sourceFiles: Array<string>,
prepackRuntime: string,
prepackArguments: Array<string>,
};

View File

@ -19,7 +19,7 @@ import type { LaunchRequestArguments } from "./../common/types.js";
export type DebuggerCLIArguments = {
adapterPath: string,
prepackRuntime: string,
sourceFile: string,
sourceFiles: Array<string>,
prepackArguments: Array<string>,
};
@ -35,7 +35,7 @@ export class UISession {
this._proc = proc;
this._adapterPath = args.adapterPath;
this._prepackRuntime = args.prepackRuntime;
this._sourceFile = args.sourceFile;
this._sourceFiles = args.sourceFiles;
this._prepackArguments = args.prepackArguments;
this._sequenceNum = 1;
this._invalidCount = 0;
@ -57,8 +57,8 @@ export class UISession {
_invalidCount: number;
// Prepack runtime command (e.g. lib/prepack-cli.js)
_prepackRuntime: string;
// input source file to Prepack
_sourceFile: string;
// Array of input source files to Prepack
_sourceFiles: Array<string>;
// arguments to start Prepack with
_prepackArguments: Array<string>;
// handler for any received messages
@ -157,7 +157,7 @@ export class UISession {
_processInitializeResponse(response: DebugProtocol.InitializeResponse) {
let launchArgs: LaunchRequestArguments = {
prepackRuntime: this._prepackRuntime,
sourceFile: this._sourceFile,
sourceFiles: this._sourceFiles,
prepackArguments: this._prepackArguments,
};
this._sendLaunchRequest(launchArgs);

View File

@ -30,7 +30,7 @@ function readCLIArguments(process, console): DebuggerCLIArguments {
let adapterPath = "";
let prepackRuntime = "";
let prepackArguments = [];
let sourceFile = "";
let sourceFiles = [];
let args = Array.from(process.argv);
args.splice(0, 2);
@ -41,15 +41,21 @@ function readCLIArguments(process, console): DebuggerCLIArguments {
console.error("Invalid argument: " + arg);
process.exit(1);
}
arg = arg.slice(2);
arg = arg.slice(2); // Slice off the -- prefix
if (arg === "adapterPath") {
adapterPath = args.shift();
} else if (arg === "prepackRuntime") {
prepackRuntime = args.shift();
} else if (arg === "prepackArguments") {
prepackArguments = args.shift().split(" ");
} else if (arg === "sourceFile") {
sourceFile = args.shift();
} else if (arg === "sourceFiles") {
// Support multiple source files.
// Assumes everything between --sourceFile and the next --[flag] is a source file.
while (!arg.startsWith("--")) {
sourceFiles.push(args.shift());
if (args.length === 0) break;
arg = args[0];
}
} else if (arg === "diagnosticSeverity") {
arg = args.shift();
if (arg !== "FatalError" && arg !== "RecoverableError" && arg !== "Warning" && arg !== "Information") {
@ -70,14 +76,14 @@ function readCLIArguments(process, console): DebuggerCLIArguments {
console.error("No Prepack runtime given to start Prepack");
process.exit(1);
}
if (sourceFile.length === 0) {
if (sourceFiles.length === 0) {
console.error("No source code input file provided");
}
let result: DebuggerCLIArguments = {
adapterPath: adapterPath,
prepackRuntime: prepackRuntime,
prepackArguments: prepackArguments,
sourceFile: sourceFile,
sourceFiles: sourceFiles,
};
return result;
}

View File

@ -132,8 +132,11 @@ function run(
while (args.length) {
let arg = args.shift();
if (!arg.startsWith("--")) {
inputFilenames.push(arg);
reproArguments.push(inputFile(arg));
let inputs = arg.trim().split(/\s+/g); // Split on all whitespace
for (let input of inputs) {
inputFilenames.push(input);
reproArguments.push(inputFile(input));
}
} else {
arg = arg.slice(2);
switch (arg) {