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
10 changes: 6 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,12 @@ workflows:
ignore: /.*/ # [macOS] Disable failing test

# Gather coverage
- js_coverage:
filters:
branches:
ignore: gh-pages
# [macOS Disable test as it depends on npm package `coveralls`, which depends on deprecated `request` package
# - js_coverage:
# filters:
# branches:
# ignore: gh-pages
# macOS]

nightly:
unless: << pipeline.parameters.run_package_release_workflow_only >>
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-macos-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
"dependencies": {
"chalk": "^3",
"find-up": "^4.1.0",
"npm-registry": "^0.1.13",
"npm-registry-fetch": "^14.0.0",
"prompts": "^2.3.0",
"semver": "^7.1.3",
"valid-url": "^1.0.9",
"yargs": "^15.1.0"
},
"devDependencies": {
"@types/chalk": "^2.2.0",
"@types/npm-registry-fetch": "^8.0.0",
"@types/prompts": "^2.0.3",
"@types/semver": "^7.1.0",
"@types/valid-url": "^1.0.2",
Expand Down
75 changes: 27 additions & 48 deletions packages/react-native-macos-init/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ import * as prompts from 'prompts';
import * as findUp from 'find-up';
import * as chalk from 'chalk';
// @ts-ignore
import * as Registry from 'npm-registry';
import npmFetch from 'npm-registry';

const npmConfReg = execSync('npm config get registry').toString().trim();
const NPM_REGISTRY_URL = validUrl.isUri(npmConfReg)
? npmConfReg
: 'http://registry.npmjs.org';
const npm = new Registry({registry: NPM_REGISTRY_URL});

const argv = yargs.version(false).options({
version: {
Expand Down Expand Up @@ -145,56 +144,36 @@ function getMatchingReactNativeSemVerForReactNativeMacOSVersion(
return 'unknown';
}

function getLatestMatchingVersion(
async function getLatestMatchingVersion(
pkg: string,
versionSemVer: string,
): Promise<string> {
return new Promise((resolve, reject) => {
if (semver.validRange(versionSemVer)) {
// Ideally we'd be able to just use npm.packages.range(pkg, versionSemVer) here,
// but alas it fails to give us the right result for react-native-macos@^0.60.0-microsoft.57
// as it fails to return pre-release versions
npm.packages.releases(
pkg,
(err: any, details: {[key: string]: object}) => {
if (err) {
reject(err);
} else if (details) {
const versions = Object.keys(details);
if (versions.length > 0) {
const candidates = versions
.filter(v => semver.satisfies(v, versionSemVer))
.sort(semver.rcompare);
if (candidates && candidates.length > 0) {
resolve(candidates[0]);
return;
}
}
}
reject(
new Error(`No matching version of ${pkg}@${versionSemVer} found!`),
);
},
);
} 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!`),
);
},
);
const npmResponse = await npmFetch.json(pkg, {registry: NPM_REGISTRY_URL});

// Check if versionSemVer is a tag (i.e. 'canary', 'latest', 'preview', etc.)
if ('dist-tags' in npmResponse) {
const distTags = npmResponse['dist-tags'] as Record<string, string>;
if (versionSemVer in distTags) {
return distTags[versionSemVer];
}
});
}

// Check if versionSemVer is a semver version (i.e. '^0.60.0-0', '0.63.1', etc.)
if ('versions' in npmResponse) {
const versions = Object.keys(
npmResponse.versions as Record<string, unknown>,
);
if (versions.length > 0) {
const candidates = versions
.filter(v => semver.satisfies(v, versionSemVer))
.sort(semver.rcompare);
if (candidates.length > 0) {
return candidates[0];
}
}
}

throw new Error(`No matching version of ${pkg}@${versionSemVer} found`);
}

async function getLatestMatchingReactNativeMacOSVersion(
Expand Down
1 change: 0 additions & 1 deletion repo-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"babel-eslint": "^10.1.0",
"clang-format": "^1.2.4",
"connect": "^3.6.5",
"coveralls": "^3.0.2",
"eslint": "^7.32.0",
"eslint-config-fb-strict": "^26.0.0",
"eslint-config-fbjs": "^3.1.1",
Expand Down
Loading