From 7205e855f68519cd3bbef51324826c66d68f0d21 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski Date: Tue, 1 Dec 2020 14:52:29 +0100 Subject: [PATCH 1/4] Enhance the generateCertificate error result The `generateCertificate()` function had the try-catch result given only as the general failure message. To keep the user aware of issues during the RNW setup, this self-signed certificate generating try-catch block has been provided with the additional information included in the exception argument: err. Please note, that only the err is displayed, instead of extending it with additional parameters (such as ERRNO, or path) as these are developers details and it keeps the error message informative but still short. --- .../@react-native-windows/cli/src/generator-windows/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@react-native-windows/cli/src/generator-windows/index.ts b/packages/@react-native-windows/cli/src/generator-windows/index.ts index c89691d8554..d8fe00ed800 100644 --- a/packages/@react-native-windows/cli/src/generator-windows/index.ts +++ b/packages/@react-native-windows/cli/src/generator-windows/index.ts @@ -58,7 +58,8 @@ async function generateCertificate( ); return thumbprint; } catch (err) { - console.log(chalk.yellow('Failed to generate Self-signed certificate.')); + console.log(chalk.yellow('Unable to generate the self-signed certificate:')); + console.log(chalk.red(err)); } } From c4aab1c2ca35afa3ef76bf51d2aa796cc9b7297d Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski Date: Tue, 1 Dec 2020 15:11:39 +0100 Subject: [PATCH 2/4] Remove the timeout from self-signed certificate generating The timeout set to 10 seconds when generating the self-signed certificate was causing the error on slower machines for developers. Please see: https://github.com/microsoft/react-native-windows/issues/6281 The idea was also to make this timeout value configurable, but in the end this solution would just make each developer leave it as default (magic number 10) or set it to max just so it's not needed to be set again. This could also result in trials and errors when trying to set the proper timeout value, which would make using the RNW uncomfortable. --- .../@react-native-windows/cli/src/generator-windows/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/@react-native-windows/cli/src/generator-windows/index.ts b/packages/@react-native-windows/cli/src/generator-windows/index.ts index d8fe00ed800..ea02a065b98 100644 --- a/packages/@react-native-windows/cli/src/generator-windows/index.ts +++ b/packages/@react-native-windows/cli/src/generator-windows/index.ts @@ -34,11 +34,9 @@ async function generateCertificate( console.log('Generating self-signed certificate...'); if (os.platform() === 'win32') { try { - const timeout = 10000; // 10 seconds; const thumbprint = childProcess .execSync( `powershell -NoProfile -Command "Write-Output (New-SelfSignedCertificate -KeyUsage DigitalSignature -KeyExportPolicy Exportable -Subject 'CN=${currentUser}' -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.3', '2.5.29.19={text}Subject Type:End Entity') -CertStoreLocation 'Cert:\\CurrentUser\\My').Thumbprint"`, - {timeout}, ) .toString() .trim(); @@ -51,7 +49,6 @@ async function generateCertificate( newProjectName, newProjectName, )}_TemporaryKey.pfx -Password $pwd"`, - {timeout}, ); console.log( chalk.green('Self-signed certificate generated successfully.'), From aad7f4b061a69a796c2ab7efa936358e465bd283 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski Date: Wed, 2 Dec 2020 10:12:00 +0100 Subject: [PATCH 3/4] Change files --- ...e-windows-cli-4be26f48-0076-4686-9fb4-6fe14a114393.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@react-native-windows-cli-4be26f48-0076-4686-9fb4-6fe14a114393.json diff --git a/change/@react-native-windows-cli-4be26f48-0076-4686-9fb4-6fe14a114393.json b/change/@react-native-windows-cli-4be26f48-0076-4686-9fb4-6fe14a114393.json new file mode 100644 index 00000000000..ac6f0ef1be2 --- /dev/null +++ b/change/@react-native-windows-cli-4be26f48-0076-4686-9fb4-6fe14a114393.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Remove the timeout from self-signed certificate generating", + "packageName": "@react-native-windows/cli", + "email": "Bartosz.Klonowski@callstack.com", + "dependentChangeType": "patch" +} From 495bb44e6a2e8ed3ff902e61fb4800adfdf80958 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski Date: Wed, 2 Dec 2020 10:38:41 +0100 Subject: [PATCH 4/4] Fix code formatting --- .../@react-native-windows/cli/src/generator-windows/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@react-native-windows/cli/src/generator-windows/index.ts b/packages/@react-native-windows/cli/src/generator-windows/index.ts index ea02a065b98..bd892807d8a 100644 --- a/packages/@react-native-windows/cli/src/generator-windows/index.ts +++ b/packages/@react-native-windows/cli/src/generator-windows/index.ts @@ -55,7 +55,9 @@ async function generateCertificate( ); return thumbprint; } catch (err) { - console.log(chalk.yellow('Unable to generate the self-signed certificate:')); + console.log( + chalk.yellow('Unable to generate the self-signed certificate:'), + ); console.log(chalk.red(err)); } }