Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -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"
}
50 changes: 33 additions & 17 deletions packages/react-native-windows-init/src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can there be more than one match (e.g. wildcards)? if so, print them and error out

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`),
);
}
}
});
}
Expand Down