diff --git a/change/react-native-windows-2020-04-08-09-04-34-direct_debugging_cli.json b/change/react-native-windows-2020-04-08-09-04-34-direct_debugging_cli.json new file mode 100644 index 00000000000..6e190fdc286 --- /dev/null +++ b/change/react-native-windows-2020-04-08-09-04-34-direct_debugging_cli.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Allow enabling of direct debugging through the CLI.", + "packageName": "react-native-windows", + "email": "12337821+nasadigital@users.noreply.github.com", + "dependentChangeType": "patch", + "date": "2020-04-08T16:04:34.634Z" +} \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/ReactApplicationDelegate.cpp b/vnext/Microsoft.ReactNative/ReactApplicationDelegate.cpp index 0dd35ba0e96..d4619d9d879 100644 --- a/vnext/Microsoft.ReactNative/ReactApplicationDelegate.cpp +++ b/vnext/Microsoft.ReactNative/ReactApplicationDelegate.cpp @@ -20,10 +20,27 @@ using namespace Windows::ApplicationModel::Activation; namespace winrt::Microsoft::ReactNative::implementation { -static void ApplyArguments(ReactNative::ReactNativeHost const & /*host*/, std::wstring const &arguments) noexcept { - // Microsoft::ReactNative::implementation::ReactNativeHost* hostImpl { - // get_self(host)}; +static void ApplyArguments(ReactNative::ReactNativeHost const &host, std::wstring const &arguments) noexcept { + Microsoft::ReactNative::implementation::ReactNativeHost *hostImpl{ + get_self(host)}; if (!arguments.empty() /*&& host.HasInstance()*/) { + constexpr wchar_t delimiter = L' '; + std::wistringstream argumentStream(arguments); + std::wstring token; + while (std::getline(argumentStream, token, delimiter)) { + if (token == L"-?") { + std::cout << "Options:" << std::endl + << " --direct-debugging Enable direct debugging on specified port." << std::endl; + } else if (token == L"--direct-debugging") { + if (std::getline(argumentStream, token, delimiter)) { + const uint16_t port = static_cast(std::wcstoul(token.c_str(), nullptr, 10)); + hostImpl->InstanceSettings().UseWebDebugger(false); + hostImpl->InstanceSettings().UseDirectDebugger(true); + hostImpl->InstanceSettings().DebuggerBreakOnNextLine(true); + hostImpl->InstanceSettings().DebuggerPort(port); + } + } + } // TODO: check for 'remoteDebugging'. Return if not found. Otherwise, // validate a value is provided and then parse it to set the // ReactInstanceManager.DevSupportManager.IsRemoteDebuggingEnabled flag diff --git a/vnext/local-cli/runWindows/runWindows.js b/vnext/local-cli/runWindows/runWindows.js index 3a4c9e40bea..a056a7f8636 100644 --- a/vnext/local-cli/runWindows/runWindows.js +++ b/vnext/local-cli/runWindows/runWindows.js @@ -124,6 +124,7 @@ runWindows({ * no-build: Boolean - Do not build the solution * no-deploy: Boolean - Do not deploy the app * msBuildProps: String - Comma separated props to pass to msbuild, eg: prop1=value1,prop2=value2 + * direct-debugging: Number - Enable direct debugging on specified port */ module.exports = { name: 'run-windows', @@ -142,7 +143,7 @@ module.exports = { }, { command: '--arch [string]', - description: 'The build architecture (ARM, x86, x64)', + description: 'The build architecture (ARM, ARM64, x86, x64)', default: 'x86', }, { @@ -206,5 +207,9 @@ module.exports = { description: 'Auto link native modules', default: false, }, + { + command: '--direct-debugging [number]', + description: 'Enable direct debugging on specified port', + }, ], }; diff --git a/vnext/local-cli/runWindows/utils/WindowsStoreAppUtils.ps1 b/vnext/local-cli/runWindows/utils/WindowsStoreAppUtils.ps1 index 68a76ce1874..ef23893d174 100644 --- a/vnext/local-cli/runWindows/utils/WindowsStoreAppUtils.ps1 +++ b/vnext/local-cli/runWindows/utils/WindowsStoreAppUtils.ps1 @@ -175,6 +175,6 @@ function Start-Locally { add-type -TypeDefinition $code $appActivator = new-object StoreAppRunner.ApplicationActivationManager - $args = [system.String]::Join(",", $argv) + $args = [system.String]::Join(" ", $argv) $appActivator.ActivateApplication($applicationUserModelId,$args,[StoreAppRunner.ActivateOptions]::None,[ref]0) | Out-Null } diff --git a/vnext/local-cli/runWindows/utils/build.js b/vnext/local-cli/runWindows/utils/build.js index 4d4ad38e431..e8d68401929 100644 --- a/vnext/local-cli/runWindows/utils/build.js +++ b/vnext/local-cli/runWindows/utils/build.js @@ -96,16 +96,15 @@ function getSolutionFile(options) { } function parseMsBuildProps(options) { + let result = {}; if (options.msbuildprops) { - var result = {}; - var props = options.msbuildprops.split(','); - for (var i = 0; i < props.length; i++) { - var prop = props[i].split('='); + const props = options.msbuildprops.split(','); + for (let i = 0; i < props.length; i++) { + const prop = props[i].split('='); result[prop[0]] = prop[1]; } - return result; } - return null; + return result; } module.exports = { diff --git a/vnext/local-cli/runWindows/utils/deploy.js b/vnext/local-cli/runWindows/utils/deploy.js index 5bddc239f59..1225885f681 100644 --- a/vnext/local-cli/runWindows/utils/deploy.js +++ b/vnext/local-cli/runWindows/utils/deploy.js @@ -162,7 +162,19 @@ async function deployToDesktop(options, verbose) { path.join(appPackageFolder, 'Add-AppDevPackage.ps1'), )[0]; - const args = ['remoteDebugging', options.proxy ? 'true' : 'false']; + let args = ['--remote-debugging', options.proxy ? 'true' : 'false']; + + if (options.directDebugging) { + const port = parseInt(options.directDebugging, 10); + if (!isNaN(port) && port > 1024 && port < 65535) { + args.push('--direct-debugging', port.toString()); + } else { + newError( + 'Direct debugging port not specified, invalid or out of bounds.', + ); + process.exit(1); + } + } const popd = pushd(options.root);