Skip to content

Commit e230187

Browse files
authored
feat: add deeplinks to our documentation (#1870)
* feat: add deeplinks to our documentation These changes will only start to work once our documentation is updated to support this feature: - facebook/react-native-website#3618 - facebook/react-native-website#3619 - facebook/react-native-website#3620 * refactor: decouple our version checks There was a single version check that would log an available stable version of React Native that was greater than the current version in a project. The change breaks that up into: - what is the current version - what is the next stable upgrade if available - log any stable upgrade if available
1 parent f3218c3 commit e230187

File tree

25 files changed

+325
-28
lines changed

25 files changed

+325
-28
lines changed

__e2e__/__snapshots__/config.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`shows up current config without unnecessary output 1`] = `
44
{
55
"root": "<<REPLACED_ROOT>>/TestProject",
66
"reactNativePath": "<<REPLACED_ROOT>>/TestProject/node_modules/react-native",
7+
"reactNativeVersion": "0.71",
78
"dependencies": {},
89
"commands": [
910
{

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
],
1919
plugins: [
2020
[require.resolve('@babel/plugin-transform-modules-commonjs'), {lazy: true}],
21+
'@babel/plugin-proposal-export-namespace-from',
2122
],
2223
sourceMaps: true,
2324
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"devDependencies": {
2525
"@babel/core": "^7.0.0",
26+
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
2627
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
2728
"@babel/plugin-transform-runtime": "^7.6.2",
2829
"@babel/preset-env": "^7.0.0",

packages/cli-config/src/__tests__/__snapshots__/index-test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Object {
2525
"platforms": Object {},
2626
"project": Object {},
2727
"reactNativePath": "<<REPLACED>>",
28+
"reactNativeVersion": "unknown",
2829
"root": "<<REPLACED>>",
2930
}
3031
`;

packages/cli-config/src/__tests__/index-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ test('should merge project configuration with default values', () => {
162162
test('should load commands from "react-native-foo" and "react-native-bar" packages', () => {
163163
DIR = getTempDirectory('config_test_packages');
164164
writeFiles(DIR, {
165+
'react-native.config.js': 'module.exports = { reactNativePath: "." }',
165166
'node_modules/react-native-foo/package.json': '{}',
166167
'node_modules/react-native-foo/react-native.config.js': `module.exports = {
167168
commands: [
@@ -220,6 +221,7 @@ test('does not use restricted "react-native" key to resolve config from package.
220221
'node_modules/react-native-netinfo/package.json': `{
221222
"react-native": "src/index.js"
222223
}`,
224+
'react-native.config.js': 'module.exports = { reactNativePath: "." }',
223225
'package.json': `{
224226
"dependencies": {
225227
"react-native-netinfo": "0.0.1"

packages/cli-config/src/loadConfig.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
} from '@react-native-community/cli-types';
99
import {
1010
findProjectRoot,
11+
version,
1112
resolveNodeModuleDir,
13+
UnknownProjectError,
1214
} from '@react-native-community/cli-tools';
1315
import findDependencies from './findDependencies';
1416
import resolveReactNativePath from './resolveReactNativePath';
@@ -65,6 +67,7 @@ function loadConfig(projectRoot: string = findProjectRoot()): Config {
6567
? path.resolve(projectRoot, userConfig.reactNativePath)
6668
: resolveReactNativePath(projectRoot);
6769
},
70+
reactNativeVersion: 'unknown',
6871
dependencies: userConfig.dependencies,
6972
commands: userConfig.commands,
7073
healthChecks: [],
@@ -89,6 +92,22 @@ function loadConfig(projectRoot: string = findProjectRoot()): Config {
8992
},
9093
};
9194

95+
// Try our best to figure out what version of React Native we're running. This is
96+
// currently being used to get our deeplinks working, so it's only worried with
97+
// the major and minor version.
98+
try {
99+
let semver = version.current(initialConfig.reactNativePath);
100+
if (semver) {
101+
// Retain only these version, since they correspond with our documentation.
102+
initialConfig.reactNativeVersion = `${semver.major}.${semver.minor}`;
103+
}
104+
} catch (e) {
105+
// If we don't seem to be in a well formed project, give up quietly.
106+
if (!(e instanceof UnknownProjectError)) {
107+
throw e;
108+
}
109+
}
110+
92111
const finalConfig = Array.from(
93112
new Set([
94113
...Object.keys(userConfig.dependencies),

packages/cli-doctor/src/commands/info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import getEnvironmentInfo from '../tools/envinfo';
9-
import {logger, releaseChecker} from '@react-native-community/cli-tools';
9+
import {logger, version} from '@react-native-community/cli-tools';
1010
import {Config} from '@react-native-community/cli-types';
1111

1212
const info = async function getInfo(_argv: Array<string>, ctx: Config) {
@@ -17,7 +17,7 @@ const info = async function getInfo(_argv: Array<string>, ctx: Config) {
1717
} catch (err) {
1818
logger.error(`Unable to print environment info.\n${err}`);
1919
} finally {
20-
await releaseChecker(ctx.root);
20+
await version.logIfUpdateAvailable(ctx.root);
2121
}
2222
};
2323

packages/cli-doctor/src/tools/healthchecks/androidSDK.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {findProjectRoot, logger} from '@react-native-community/cli-tools';
1+
import {findProjectRoot, logger, link} from '@react-native-community/cli-tools';
22
import chalk from 'chalk';
33
import fs from 'fs';
44
import path from 'path';
@@ -182,7 +182,11 @@ export default {
182182

183183
return logManualInstallation({
184184
healthcheck: 'Android SDK',
185-
url: 'https://reactnative.dev/docs/environment-setup',
185+
url: link.docs('environment-setup', {
186+
hash: 'android-sdk',
187+
guide: 'native',
188+
platform: 'android',
189+
}),
186190
});
187191
},
188192
} as HealthCheckInterface;

packages/cli-doctor/src/tools/healthchecks/androidStudio.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {join} from 'path';
22

3+
import {link} from '@react-native-community/cli-tools';
4+
35
import {HealthCheckInterface} from '../../types';
46

57
import {downloadAndUnzip} from '../downloadAndUnzip';
@@ -74,7 +76,11 @@ export default {
7476

7577
return logManualInstallation({
7678
healthcheck: 'Android Studio',
77-
url: 'https://reactnative.dev/docs/environment-setup',
79+
url: link.docs('environment-setup', {
80+
hash: 'android-studio',
81+
guide: 'native',
82+
platform: 'android',
83+
}),
7884
});
7985
},
8086
} as HealthCheckInterface;

packages/cli-doctor/src/tools/healthchecks/jdk.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import {join} from 'path';
2+
3+
import {link} from '@react-native-community/cli-tools';
4+
25
import versionRanges from '../versionRanges';
36
import {doesSoftwareNeedToBeFixed} from '../checkInstallation';
47
import {HealthCheckInterface} from '../../types';
@@ -58,7 +61,11 @@ export default {
5861
loader.fail();
5962
logManualInstallation({
6063
healthcheck: 'JDK',
61-
url: 'https://reactnative.dev/docs/environment-setup',
64+
url: link.docs('environment-setup', {
65+
hash: 'jdk-studio',
66+
guide: 'native',
67+
platform: 'android',
68+
}),
6269
});
6370
},
6471
} as HealthCheckInterface;

0 commit comments

Comments
 (0)