Skip to content

Commit fec7910

Browse files
authored
chore(init): use a stricter tsconfig.json (#2240)
1 parent 95834df commit fec7910

File tree

4 files changed

+44
-41
lines changed

4 files changed

+44
-41
lines changed

packages/react-native-macos-init/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
"name": "react-native-macos-init",
33
"version": "2.1.3",
44
"description": "CLI to add react-native-macos to an existing react-native project",
5-
"main": "index.js",
6-
"repository": "https://github.com/microsoft/react-native-macos",
75
"license": "MIT",
6+
"main": "index.js",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/microsoft/react-native-macos",
10+
"directory": "packages/react-native-macos-init"
11+
},
812
"scripts": {
913
"change": "beachball change",
1014
"check": "beachball check",
@@ -22,10 +26,10 @@
2226
"npm-registry-fetch": "^14.0.0",
2327
"prompts": "^2.3.0",
2428
"semver": "^7.5.2",
25-
"valid-url": "^1.0.9",
2629
"yargs": "^15.1.0"
2730
},
2831
"devDependencies": {
32+
"@rnx-kit/tsconfig": "^2.0.0",
2933
"@types/chalk": "^2.2.0",
3034
"@types/npm-registry-fetch": "^8.0.0",
3135
"@types/prompts": "^2.0.3",

packages/react-native-macos-init/src/cli.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55
* @format
66
*/
77

8-
import * as yargs from 'yargs';
9-
import * as fs from 'fs';
10-
import * as semver from 'semver';
8+
import chalk from 'chalk';
119
import {execSync} from 'child_process';
12-
import * as validUrl from 'valid-url';
13-
import * as prompts from 'prompts';
1410
import * as findUp from 'find-up';
15-
import * as chalk from 'chalk';
11+
import * as fs from 'fs';
1612
import * as npmFetch from 'npm-registry-fetch';
17-
18-
const npmConfReg = execSync('npm config get registry').toString().trim();
19-
const NPM_REGISTRY_URL = validUrl.isUri(npmConfReg)
20-
? npmConfReg
21-
: 'http://registry.npmjs.org';
13+
import prompts from 'prompts';
14+
import * as semver from 'semver';
15+
import * as yargs from 'yargs';
2216

2317
const argv = yargs.version(false).options({
2418
version: {
@@ -52,6 +46,19 @@ function reactNativeMacOSGeneratePath() {
5246
});
5347
}
5448

49+
function getNpmRegistryUrl(): string {
50+
const reg = execSync('npm config get registry', {encoding: 'utf-8'}).trim();
51+
try {
52+
const url = new URL(reg);
53+
if (url) {
54+
return reg;
55+
}
56+
} catch (_) {
57+
// ignore
58+
}
59+
return 'https://registry.npmjs.org';
60+
}
61+
5562
function getReactNativeAppName() {
5663
console.log(`Reading ${chalk.cyan('application name')} from package.json…`);
5764
const cwd = process.cwd();
@@ -104,9 +111,12 @@ function getReactNativeMacOSVersion() {
104111
return getPackageVersion(MACOSPKG, false);
105112
}
106113

107-
function errorOutOnUnsupportedVersionOfReactNative(rnVersion: string) {
108-
printError(`Unsupported version of ${RNPKG}: ${chalk.cyan(rnVersion)}
109-
${MACOSPKG} supports ${RNPKG} versions ${chalk.cyan('>=0.60')}`);
114+
function errorOutOnUnsupportedVersionOfReactNative(rnVersion: string): never {
115+
const version = chalk.cyan(rnVersion);
116+
const supportedVersions = chalk.cyan('>=0.60');
117+
printError(
118+
`Unsupported version of ${RNPKG}: ${version}\n${MACOSPKG} supports ${RNPKG} versions ${supportedVersions}`,
119+
);
110120
process.exit(EXITCODE_UNSUPPORTED_VERION_RN);
111121
}
112122

@@ -147,7 +157,7 @@ async function getLatestMatchingVersion(
147157
pkg: string,
148158
versionSemVer: string,
149159
): Promise<string> {
150-
const npmResponse = await npmFetch.json(pkg, {registry: NPM_REGISTRY_URL});
160+
const npmResponse = await npmFetch.json(pkg, {registry: getNpmRegistryUrl()});
151161

152162
// Check if versionSemVer is a tag (i.e. 'canary', 'latest', 'preview', etc.)
153163
if ('dist-tags' in npmResponse) {
@@ -306,7 +316,7 @@ You can either downgrade your version of ${chalk.yellow(RNPKG)} to ${chalk.cyan(
306316
verbose,
307317
});
308318
} catch (error) {
309-
printError(error.message, error);
319+
printError(`${error}`, error);
310320
process.exit(EXITCODE_UNKNOWN_ERROR);
311321
}
312322
})();
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
{
2-
"compilerOptions": {
3-
"baseUrl": ".",
4-
"target": "es6",
5-
"sourceMap": true,
6-
"noImplicitAny": true,
7-
"preserveConstEnums": true,
8-
"moduleResolution": "node",
9-
"noUnusedLocals": true,
10-
"skipLibCheck": true,
11-
"rootDirs": ["src"],
12-
},
13-
"include": ["src"],
14-
"exclude": ["node_modules"]
15-
}
2+
"extends": "@rnx-kit/tsconfig/tsconfig.json",
3+
"include": ["src"]
4+
}

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,6 +4132,13 @@ __metadata:
41324132
languageName: node
41334133
linkType: hard
41344134

4135+
"@rnx-kit/tsconfig@npm:^2.0.0":
4136+
version: 2.0.0
4137+
resolution: "@rnx-kit/tsconfig@npm:2.0.0"
4138+
checksum: 10c0/b31353cb1a3b75d4827373887806f5495eccb9e38e9edcf111a85a3e6967256e13f18a7acfbb9eabd7bfbe04b6b5e6ac3ec0a638d31b55f9231ffd3d946c735c
4139+
languageName: node
4140+
linkType: hard
4141+
41354142
"@rushstack/node-core-library@npm:3.61.0":
41364143
version: 3.61.0
41374144
resolution: "@rushstack/node-core-library@npm:3.61.0"
@@ -12909,6 +12916,7 @@ __metadata:
1290912916
version: 0.0.0-use.local
1291012917
resolution: "react-native-macos-init@workspace:packages/react-native-macos-init"
1291112918
dependencies:
12919+
"@rnx-kit/tsconfig": "npm:^2.0.0"
1291212920
"@types/chalk": "npm:^2.2.0"
1291312921
"@types/npm-registry-fetch": "npm:^8.0.0"
1291412922
"@types/prompts": "npm:^2.0.3"
@@ -12923,7 +12931,6 @@ __metadata:
1292312931
prompts: "npm:^2.3.0"
1292412932
semver: "npm:^7.5.2"
1292512933
typescript: "npm:^5.6.3"
12926-
valid-url: "npm:^1.0.9"
1292712934
yargs: "npm:^15.1.0"
1292812935
bin:
1292912936
react-native-macos-init: ./bin.js
@@ -14891,13 +14898,6 @@ __metadata:
1489114898
languageName: node
1489214899
linkType: hard
1489314900

14894-
"valid-url@npm:^1.0.9":
14895-
version: 1.0.9
14896-
resolution: "valid-url@npm:1.0.9"
14897-
checksum: 10c0/3995e65f9942dbcb1621754c0f9790335cec61e9e9310c0a809e9ae0e2ae91bb7fc6a471fba788e979db0418d9806639f681ecebacc869bc8c3de88efa562ee6
14898-
languageName: node
14899-
linkType: hard
14900-
1490114901
"validate-npm-package-license@npm:^3.0.1":
1490214902
version: 3.0.4
1490314903
resolution: "validate-npm-package-license@npm:3.0.4"

0 commit comments

Comments
 (0)