Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate 'program' debug configuration property #1039

Merged
merged 14 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"description": "%reactNative.snippets.debugAndroid.description%",
"body": {
"name": "Debug Android",
"program": "^\"\\${workspaceRoot}/.vscode/launchReactNative.js\"",
"cwd": "^\"\\${workspaceFolder}\"",
"type": "reactnative",
"request": "launch",
"platform": "android"
Expand All @@ -137,7 +137,7 @@
"description": "%reactNative.snippets.debugiOS.description%",
"body": {
"name": "Debug iOS",
"program": "^\"\\${workspaceRoot}/.vscode/launchReactNative.js\"",
"cwd": "^\"\\${workspaceFolder}\"",
"type": "reactnative",
"request": "launch",
"platform": "ios"
Expand All @@ -148,7 +148,7 @@
"description": "%reactNative.snippets.attachPackager.description%",
"body": {
"name": "Attach to packager",
"program": "^\"\\${workspaceRoot}/.vscode/launchReactNative.js\"",
"cwd": "^\"\\${workspaceFolder}\"",
"type": "reactnative",
"request": "attach"
}
Expand All @@ -158,7 +158,7 @@
"description": "%reactNative.snippets.debugExpo.description%",
"body": {
"name": "Debug in Exponent",
"program": "^\"\\${workspaceRoot}/.vscode/launchReactNative.js\"",
"cwd": "^\"\\${workspaceFolder}\"",
"type": "reactnative",
"request": "launch",
"platform": "exponent"
Expand All @@ -168,13 +168,18 @@
"configurationAttributes": {
"attach": {
"required": [
"program"
"cwd"
],
"properties": {
"program": {
"type": "string",
"description": "%reactNative.attach.program.description%"
},
"cwd": {
"type": "string",
"description": "%reactNative.attach.cwd.description%",
"default": "${workspaceFolder}"
},
"sourceMaps": {
"type": "boolean",
"description": "%reactNative.attach.sourceMaps.description%",
Expand Down Expand Up @@ -233,7 +238,7 @@
},
"launch": {
"required": [
"program",
"cwd",
"platform"
],
"properties": {
Expand All @@ -252,6 +257,11 @@
"type": "string",
"description": "%reactNative.launch.program.description%"
},
"cwd": {
"type": "string",
"description": "%reactNative.launch.cwd.description%",
"default": "${workspaceFolder}"
},
"target": {
"anyOf": [
{
Expand Down
2 changes: 2 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"reactNative.snippets.attachPackager.description":"A new configuration for attaching to packager",
"reactNative.snippets.debugExpo.description":"A new configuration for launching Expo app",
"reactNative.attach.program.description":"The path to launchReactNative.js in the vscode folder",
SounD120 marked this conversation as resolved.
Show resolved Hide resolved
"reactNative.attach.cwd.description":"The path to project root folder",
"reactNative.attach.sourceMaps.description":"Whether to use JavaScript source maps to map the generated bundled code back to its original sources",
"reactNative.attach.sourceMapsPathOverrides.description":"A set of mappings for rewriting the locations of source files from what the source map says, to their locations on disk. See https://github.com/Microsoft/vscode-react-native/blob/master/doc/debugging.md#debugging-with-typescript-and-haul for details",
"reactNative.attach.trace.description":"Setup logging level in debugger.",
Expand All @@ -29,6 +30,7 @@
"reactNative.attach.debuggerWorkerUrlPath.description": "Path to the app debugger worker to override. For example, if debugger tries to attach to http://localhost:8081/debugger-ui/debuggerWorker.js and you get 404 error from packager output then you may want to change debuggerWorkerUrlPath to another value suitable for your packager (\"debugger-ui\" will be replaced with the value you provide).",
"reactNative.launch.platform.description":"The platform to target",
"reactNative.launch.program.description":"The path to launchReactNative.js in the vscode folder",
"reactNative.launch.cwd.description":"The path to project root folder",
SounD120 marked this conversation as resolved.
Show resolved Hide resolved
"reactNative.launch.target.description":"Device target to run on (either device or simulator)",
"reactNative.launch.sourceMaps.description":"Whether to use JavaScript source maps to map the generated bundled code back to its original sources",
"reactNative.launch.logCatArguments.description":"Arguments to be used for LogCat (The LogCat output will appear on an Output Channel). It can either be an array such as: [\":S\", \"ReactNative:V\", \"ReactNativeJS:V\"] or a string such as \":S ReactNative:V ReactNativeJS:V\"",
Expand Down
6 changes: 3 additions & 3 deletions src/common/remoteExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IExtensionApi extends ICommonApi {
stopMonitoringLogcat(): Q.Promise<void>;
sendTelemetry(telemetryRequest: Telemetry.TelemetryRequest): Q.Promise<any>;
openFileAtLocation(openFileRequest: OpenFileRequest): Q.Promise<void>;
getPackagerPort(program: string): Q.Promise<number>;
getPackagerPort(projectRoot: string): Q.Promise<number>;
showInformationMessage(infoMessage: string): Q.Promise<void>;
launch(request: any): Q.Promise<any>;
showDevMenu(deviceId?: string): Q.Promise<any>;
Expand Down Expand Up @@ -80,8 +80,8 @@ export class RemoteExtension {
return this._api.Extension.openFileAtLocation(request);
}

public getPackagerPort(program: string): Q.Promise<number> {
return this._api.Extension.getPackagerPort(program);
public getPackagerPort(projectRoot: string): Q.Promise<number> {
return this._api.Extension.getPackagerPort(projectRoot);
}

public showInformationMessage(infoMessage: string): Q.Promise<void> {
Expand Down
19 changes: 11 additions & 8 deletions src/debugger/nodeDebugWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import * as Q from "q";
import * as path from "path";
import * as fs from "fs";
import stripJsonComments = require("strip-json-comments");

import { Telemetry } from "../common/telemetry";
import { TelemetryHelper } from "../common/telemetryHelper";
import { RemoteExtension } from "../common/remoteExtension";
import { RemoteTelemetryReporter, ReassignableTelemetryReporter } from "../common/telemetryReporters";
import { ChromeDebugSession, IChromeDebugSessionOpts, ChromeDebugAdapter, logger } from "vscode-chrome-debug-core";
import { ContinuedEvent, TerminatedEvent, Logger, Response } from "vscode-debugadapter";
import { DebugProtocol } from "vscode-debugprotocol";

import { MultipleLifetimesAppWorker } from "./appWorker";

import { ReactNativeProjectHelper } from "../common/reactNativeProjectHelper";
import * as nls from "vscode-nls";
import { ErrorHelper } from "../common/error/errorHelper";
Expand Down Expand Up @@ -84,7 +81,7 @@ export function makeSession(
return this.remoteExtension.launch(request);
})
.then(() => {
return this.remoteExtension.getPackagerPort(request.arguments.program);
return this.remoteExtension.getPackagerPort(request.arguments.cwd || request.arguments.program);
})
.then((packagerPort: number) => {
this.attachRequest({
Expand All @@ -104,7 +101,7 @@ export function makeSession(
this.requestSetup(request.arguments)
.then(() => {
logger.verbose(`Handle attach request: ${JSON.stringify(request.arguments, null , 2)}`);
return this.remoteExtension.getPackagerPort(request.arguments.program);
return this.remoteExtension.getPackagerPort(request.arguments.cwd || request.arguments.program);
})
.then((packagerPort: number) => {
this.attachRequest({
Expand Down Expand Up @@ -149,6 +146,12 @@ export function makeSession(
} else {
logger.setup(Logger.LogLevel.Log, chromeDebugCoreLogs || false);
}
if (args.program) {
// Remove this warning when program property will be completely removed
SounD120 marked this conversation as resolved.
Show resolved Hide resolved
logger.warn(localize("ProgramPropertyDeprecationWarning", "Launched debug configuration contains 'program' property which is deprecated and will be removed soon. Please replace it by: \"cwd\": \"${workspaceFolder}\""));
SounD120 marked this conversation as resolved.
Show resolved Hide resolved
const useProgramEvent = TelemetryHelper.createTelemetryEvent("useProgramProperty");
Telemetry.send(useProgramEvent);
}

if (!args.sourceMaps) {
args.sourceMaps = true;
Expand Down Expand Up @@ -189,7 +192,7 @@ export function makeSession(
logger.log(localize("StartingDebuggerAppWorker", "Starting debugger app worker."));
// TODO: remove dependency on args.program - "program" property is technically
// no more required in launch configuration and could be removed
const workspaceRootPath = path.resolve(path.dirname(request.arguments.program), "..");
const workspaceRootPath = request.arguments.cwd ? path.resolve(request.arguments.cwd) : path.resolve(path.dirname(request.arguments.program), "..");
const sourcesStoragePath = path.join(workspaceRootPath, ".vscode", ".react");

// If launch is invoked first time, appWorker is undefined, so create it here
Expand Down Expand Up @@ -263,14 +266,14 @@ export function makeAdapter(debugAdapterClass: typeof ChromeDebugAdapter): typeo
*/
function getProjectRoot(args: any): string {
try {
let vsCodeRoot = path.resolve(args.program, "../..");
let vsCodeRoot = args.cwd ? path.resolve(args.cwd) : path.resolve(args.program, "../..");
let settingsPath = path.resolve(vsCodeRoot, ".vscode/settings.json");
let settingsContent = fs.readFileSync(settingsPath, "utf8");
settingsContent = stripJsonComments(settingsContent);
let parsedSettings = JSON.parse(settingsContent);
let projectRootPath = parsedSettings["react-native-tools.projectRoot"] || parsedSettings["react-native-tools"].projectRoot;
return path.resolve(vsCodeRoot, projectRootPath);
} catch (e) {
return path.resolve(args.program, "../..");
return args.cwd ? path.resolve(args.cwd) : path.resolve(args.program, "../..");
}
}
8 changes: 4 additions & 4 deletions src/extension/debugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ export class ReactNativeDebugConfigProvider implements vscode.DebugConfiguration
private debugConfigurations = {
"Debug Android": {
"name": "Debug Android",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "launch",
"platform": "android",
},
"Debug iOS": {
"name": "Debug iOS",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "launch",
"platform": "ios",
},
"Attach to packager": {
"name": "Attach to packager",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "attach",
},
"Debug in Exponent": {
"name": "Debug in Exponent",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "launch",
"platform": "exponent",
Expand Down
10 changes: 5 additions & 5 deletions src/extension/extensionServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export class ExtensionServer implements vscode.Disposable {
/**
* Message handler for GET_PACKAGER_PORT.
*/
private getPackagerPort(program: string): number {
return SettingsHelper.getPackagerPort(program);
private getPackagerPort(projectFolder: string): number {
return SettingsHelper.getPackagerPort(projectFolder);
}

/**
Expand Down Expand Up @@ -201,7 +201,7 @@ export class ExtensionServer implements vscode.Disposable {
mobilePlatformOptions.productName = request.arguments.productName;
}

mobilePlatformOptions.packagerPort = SettingsHelper.getPackagerPort(request.arguments.program);
mobilePlatformOptions.packagerPort = SettingsHelper.getPackagerPort(request.arguments.cwd || request.arguments.program);
const platformDeps: MobilePlatformDeps = {
packager: this.reactNativePackager,
};
Expand Down Expand Up @@ -266,7 +266,7 @@ function isNullOrUndefined(value: any): boolean {
}

function requestSetup(args: any): any {
const workspaceFolder: vscode.WorkspaceFolder = <vscode.WorkspaceFolder>vscode.workspace.getWorkspaceFolder(vscode.Uri.file(args.program));
const workspaceFolder: vscode.WorkspaceFolder = <vscode.WorkspaceFolder>vscode.workspace.getWorkspaceFolder(vscode.Uri.file(args.cwd || args.program));
const projectRootPath = getProjectRoot(args);
let mobilePlatformOptions: any = {
workspaceRoot: workspaceFolder.uri.fsPath,
Expand All @@ -288,5 +288,5 @@ function requestSetup(args: any): any {
}

function getProjectRoot(args: any): string {
return SettingsHelper.getReactNativeProjectRoot(args.program);
return SettingsHelper.getReactNativeProjectRoot(args.cwd || args.program);
}
2 changes: 1 addition & 1 deletion src/extension/rn-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {TelemetryHelper, ICommandTelemetryProperties} from "../common/telemetryH
import {ExtensionServer} from "./extensionServer";
import {OutputChannelLogger} from "./log/OutputChannelLogger";
import {ExponentHelper} from "./exponent/exponentHelper";
import { ReactNativeDebugConfigProvider } from "./debugConfigurationProvider";
import {ReactNativeDebugConfigProvider} from "./debugConfigurationProvider";
import * as nls from "vscode-nls";
const localize = nls.loadMessageBundle();

Expand Down
2 changes: 1 addition & 1 deletion src/extension/settingsHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
import * as vscode from "vscode";
import path = require("path");
import * as path from "path";
import {ConfigurationReader} from "../common/configurationReader";
import {Packager} from "../common/packager";
import {LogLevel} from "./log/LogHelper";
Expand Down
8 changes: 4 additions & 4 deletions test/smoke/resources/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
"configurations": [
{
"name": "Debug Android",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "launch",
"platform": "android"
},
{
"name": "Debug iOS",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "launch",
"platform": "ios"
},
{
"name": "Attach to packager",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "attach"
},
{
"name": "Debug in Exponent",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "launch",
"platform": "exponent"
Expand Down