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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
"@react-native-community/cli-platform-ios": ">=4.10.0",
"mustache": "^4.0.0",
"react": "~16.8.6 || ~16.9.0 || ~16.11.0 || ~16.13.1 || ~17.0.1 || ~17.0.2",
"react-native": "^0.0.0-0 || ^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63.2 || ^0.64.0 || ^0.65.0 || ^0.66.0 || 1000.0.0",
"react-native-macos": "^0.60.0 || ^0.61.0 || ^0.62.0 || ^0.63.0",
"react-native-windows": "^0.62.0 || ^0.63.0 || ^0.64.0 || ^0.65.0 || ^0.66.0"
"react-native": "^0.0.0-0 || ^0.60 || ^0.61 || ^0.62 || ^0.63 || ^0.64 || ^0.65 || ^0.66 || 1000.0.0",
"react-native-macos": "^0.0.0-0 || ^0.60 || ^0.61 || ^0.62 || ^0.63",
"react-native-windows": "^0.0.0-0 || ^0.62 || ^0.63 || ^0.64 || ^0.65 || ^0.66"
},
"peerDependenciesMeta": {
"mustache": {
Expand Down
19 changes: 6 additions & 13 deletions scripts/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,18 @@ function warn(message, tag = "[!]") {

/**
* Returns platform package at target version if it satisfies version range.
* @param {string} packageName
* @param {"react-native" | "react-native-macos" | "react-native-windows"} packageName
* @param {string} targetVersion
* @param {string} versionRange
* @returns {Record<string, string> | undefined}
*/
function getPlatformPackage(packageName, targetVersion, versionRange) {
function getPlatformPackage(packageName, targetVersion) {
const v = semver.coerce(targetVersion);
if (!v) {
throw new Error(`Invalid ${packageName} version: ${targetVersion}`);
}

const { peerDependencies } = require("../package.json");
const versionRange = peerDependencies[packageName];
if (!semver.satisfies(v.version, versionRange)) {
warn(
`${packageName}@${v.major}.${v.minor} cannot be added because it does not exist or is unsupported`
Expand Down Expand Up @@ -541,11 +542,7 @@ const getConfig = (() => {
},
dependencies: {},
getDependencies: ({ targetVersion }) => {
return getPlatformPackage(
"react-native-macos",
targetVersion,
"^0.0.0-0 || >=0.60.0 <0.64"
);
return getPlatformPackage("react-native-macos", targetVersion);
},
},
windows: {
Expand All @@ -571,11 +568,7 @@ const getConfig = (() => {
},
dependencies: {},
getDependencies: ({ targetVersion }) => {
return getPlatformPackage(
"react-native-windows",
targetVersion,
"^0.0.0-0 || >=0.62.0 <0.66"
);
return getPlatformPackage("react-native-windows", targetVersion);
},
},
};
Expand Down
14 changes: 7 additions & 7 deletions test/configure/getPlatformPackage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ describe("getPlatformPackage()", () => {

const consoleWarnSpy = jest.spyOn(global.console, "warn");

const name = "react-native-*";
const versionRange = "^0.0.0-0 || >=0.60.0 <0.64";
const name = "react-native";

afterEach(() => {
consoleWarnSpy.mockReset();
Expand All @@ -24,21 +23,21 @@ describe("getPlatformPackage()", () => {

test("returns dependency when target version is inside range", () => {
["0.0.0-canary", "^0.0.0-canary"].forEach((targetVersion) => {
const pkg = getPlatformPackage(name, targetVersion, versionRange);
const pkg = getPlatformPackage(name, targetVersion);
expect(pkg).toEqual({ [name]: "^0.0.0" });
expect(consoleWarnSpy).not.toHaveBeenCalled();
});

["0.63", "0.63.4", "^0.63", "^0.63.4"].forEach((targetVersion) => {
const pkg = getPlatformPackage(name, targetVersion, versionRange);
const pkg = getPlatformPackage(name, targetVersion);
expect(pkg).toEqual({ [name]: "^0.63.0" });
expect(consoleWarnSpy).not.toHaveBeenCalled();
});
});

test("returns `undefined` when target version is outside range", () => {
["0.59", "0.64"].forEach((targetVersion) => {
const pkg = getPlatformPackage(name, targetVersion, versionRange);
["0.59", "9999.0"].forEach((targetVersion) => {
const pkg = getPlatformPackage(name, targetVersion);
expect(pkg).toBeUndefined();
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);

Expand All @@ -47,6 +46,7 @@ describe("getPlatformPackage()", () => {
});

test("throws if target version is invalid", () => {
expect(() => getPlatformPackage("", "version", "")).toThrow();
// @ts-ignore intentional use of empty string to elicit an exception
expect(() => getPlatformPackage("", "version")).toThrow();
});
});
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10512,9 +10512,9 @@ fsevents@^2.3.2:
"@react-native-community/cli-platform-ios": ">=4.10.0"
mustache: ^4.0.0
react: ~16.8.6 || ~16.9.0 || ~16.11.0 || ~16.13.1 || ~17.0.1 || ~17.0.2
react-native: ^0.0.0-0 || ^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63.2 || ^0.64.0 || ^0.65.0 || ^0.66.0 || 1000.0.0
react-native-macos: ^0.60.0 || ^0.61.0 || ^0.62.0 || ^0.63.0
react-native-windows: ^0.62.0 || ^0.63.0 || ^0.64.0 || ^0.65.0 || ^0.66.0
react-native: ^0.0.0-0 || ^0.60 || ^0.61 || ^0.62 || ^0.63 || ^0.64 || ^0.65 || ^0.66 || 1000.0.0
react-native-macos: ^0.0.0-0 || ^0.60 || ^0.61 || ^0.62 || ^0.63
react-native-windows: ^0.0.0-0 || ^0.62 || ^0.63 || ^0.64 || ^0.65 || ^0.66
peerDependenciesMeta:
mustache:
optional: true
Expand Down