From 98f8b7520a58b19b62d807c107bd6b1f6147c5ca Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Mon, 20 Apr 2020 13:55:39 -0700 Subject: [PATCH 1/2] Fix react-native-windows-init to work with tags (@master) --- packages/react-native-windows-init/src/Cli.ts | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/packages/react-native-windows-init/src/Cli.ts b/packages/react-native-windows-init/src/Cli.ts index 42c4bd320a4..512a797113a 100644 --- a/packages/react-native-windows-init/src/Cli.ts +++ b/packages/react-native-windows-init/src/Cli.ts @@ -8,7 +8,7 @@ import * as yargs from 'yargs'; import * as fs from 'fs'; import * as semver from 'semver'; -import {execSync} from 'child_process'; +import {exec, execSync} from 'child_process'; import * as validUrl from 'valid-url'; import * as prompts from 'prompts'; import * as findUp from 'find-up'; @@ -171,22 +171,38 @@ function getLatestMatchingVersion( }, ); } else { - // Assume that versionSemVer is actually a tag - npm.packages.release( - pkg, - versionSemVer, - (err: any, details: {version: string}[]) => { - if (err) { - reject(err); - } else if (details && details.length > 0) { - resolve(details[0].version); - return; - } - reject( - new Error(`No matching version of ${pkg}@${versionSemVer} found`), - ); - }, - ); + try { + exec( + `npm info ${pkg}@${versionSemVer} version --json`, + (err, stdout, _stderr) => { + try { + if (!err) { + let candidates = JSON.parse(stdout); + if (typeof candidates === 'string') { + resolve(candidates); + return; + } + candidates = candidates.sort(semver.rcompare); + if (candidates && candidates.length > 0) { + resolve(candidates[0]); + return; + } + } + reject( + new Error( + `No matching version of ${pkg}@${versionSemVer} found`, + ), + ); + } catch (e) { + reject(e); + } + }, + ); + } catch (err) { + reject( + new Error(`No matching version of ${pkg}@${versionSemVer} found`), + ); + } } }); } From 89362b2aa36423ec84fe4c7087cdd99c986b45a2 Mon Sep 17 00:00:00 2001 From: "Andrew Coates (REDMOND)" Date: Mon, 20 Apr 2020 13:55:49 -0700 Subject: [PATCH 2/2] Change files --- ...native-windows-init-2020-04-20-13-55-48-tagininit.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 change/react-native-windows-init-2020-04-20-13-55-48-tagininit.json diff --git a/change/react-native-windows-init-2020-04-20-13-55-48-tagininit.json b/change/react-native-windows-init-2020-04-20-13-55-48-tagininit.json new file mode 100644 index 00000000000..6bf0f618f2f --- /dev/null +++ b/change/react-native-windows-init-2020-04-20-13-55-48-tagininit.json @@ -0,0 +1,8 @@ +{ + "type": "patch", + "comment": "Fix react-native-windows-init to work with tags (@master)", + "packageName": "react-native-windows-init", + "email": "acoates@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-04-20T20:55:48.747Z" +} \ No newline at end of file