diff --git a/change/react-native-windows-2020-03-25-15-49-46-noadmininit.json b/change/react-native-windows-2020-03-25-15-49-46-noadmininit.json new file mode 100644 index 00000000000..a837dc311dd --- /dev/null +++ b/change/react-native-windows-2020-03-25-15-49-46-noadmininit.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Fix hang on react-native-init when run from a non-elevated prompt", + "packageName": "react-native-windows", + "email": "acoates@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-03-25T22:49:46.943Z" +} \ No newline at end of file diff --git a/vnext/.eslintignore b/vnext/.eslintignore index fe4ae497b63..e8f78012d7b 100644 --- a/vnext/.eslintignore +++ b/vnext/.eslintignore @@ -2,7 +2,6 @@ /flow /lib /Libraries -/local-cli/generator-windows/templates/index.windows.js **/node_modules /packages /ReactCopies diff --git a/vnext/local-cli/generator-windows/index.js b/vnext/local-cli/generator-windows/index.js index 6b66a15a385..d1fe9b871e5 100644 --- a/vnext/local-cli/generator-windows/index.js +++ b/vnext/local-cli/generator-windows/index.js @@ -20,24 +20,19 @@ function generateCertificate(srcPath, destPath, newProjectName, currentUser) { console.log('Generating self-signed certificate...'); let toCopyTempKey = false; if (os.platform() === 'win32') { - const certGenCommand = [ - `$cert = 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"`, - '$pwd = ConvertTo-SecureString -String password -Force -AsPlainText', - `New-Item -ErrorAction Ignore -ItemType directory -Path ${path.join(windowsDir, newProjectName)}`, - `Export-PfxCertificate -Cert "cert:\\CurrentUser\\My\\$($cert.Thumbprint)" -FilePath ${path.join(windowsDir, newProjectName, newProjectName)}_TemporaryKey.pfx -Password $pwd`, - '$cert.Thumbprint', - ]; - const certGenProcess = childProcess.spawnSync('powershell', ['-command', certGenCommand.join(';')]); - - if (certGenProcess.status === 0) { - const certGenProcessOutput = certGenProcess.stdout.toString().trim().split('\n'); + try { + const thumbprint = childProcess.execSync(`powershell -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"`).toString().trim(); + if (!fs.existsSync(path.join(windowsDir, newProjectName))) { + fs.createDir(path.join(windowsDir, newProjectName)); + } + childProcess.execSync(`powershell -command "$pwd = (ConvertTo-SecureString -String password -Force -AsPlainText); Export-PfxCertificate -Cert 'cert:\\CurrentUser\\My\\${thumbprint}' -FilePath ${path.join(windowsDir, newProjectName, newProjectName)}_TemporaryKey.pfx -Password $pwd"`); console.log(chalk.green('Self-signed certificate generated successfully.')); - return certGenProcessOutput[certGenProcessOutput.length - 1]; + return thumbprint; + } catch (err) { + console.log(chalk.yellow('Failed to generate Self-signed certificate. Using Default Certificate. Use Visual Studio to renew it.')); + toCopyTempKey = true; + } } else { - console.log(chalk.yellow('Failed to generate Self-signed certificate. Using Default Certificate. Use Visual Studio to renew it.')); - toCopyTempKey = true; - } - } else { console.log(chalk.yellow('Using Default Certificate. Use Visual Studio to renew it.')); toCopyTempKey = true; } diff --git a/vnext/local-cli/generator-windows/templates/cpp/keys/MyApp_TemporaryKey.pfx b/vnext/local-cli/generator-windows/templates/cpp/keys/MyApp_TemporaryKey.pfx new file mode 100644 index 00000000000..08328fc1518 Binary files /dev/null and b/vnext/local-cli/generator-windows/templates/cpp/keys/MyApp_TemporaryKey.pfx differ diff --git a/vnext/local-cli/generator-windows/templates/cs/keys/MyApp_TemporaryKey.pfx b/vnext/local-cli/generator-windows/templates/cs/keys/MyApp_TemporaryKey.pfx new file mode 100644 index 00000000000..08328fc1518 Binary files /dev/null and b/vnext/local-cli/generator-windows/templates/cs/keys/MyApp_TemporaryKey.pfx differ