Skip to content

Commit

Permalink
fix: cannot find react-native-test-app when Metro starts (react-nat…
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Apr 1, 2022
1 parent 5805590 commit c6471ed
Showing 1 changed file with 30 additions and 57 deletions.
87 changes: 30 additions & 57 deletions react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
const fs = require('fs');
const path = require('path');

const windowsProjectFile = path.join(
'node_modules',
'.generated',
'windows',
'ReactTestApp',
'ReactTestApp.vcxproj',
);
const project = (() => {
const fs = require('fs');
const path = require('path');
try {
const {
androidManifestPath,
iosProjectPath,
windowsProjectPath,
} = require('react-native-test-app');
return {
android: {
sourceDir: path.join('example', 'android'),
manifestPath: androidManifestPath(
path.join(__dirname, 'example', 'android'),
),
},
ios: {
project: iosProjectPath('example/ios'),
},
windows: fs.existsSync('example/windows/WebviewExample.sln') && {
sourceDir: path.join('example', 'windows'),
solutionFile: 'WebviewExample.sln',
project: windowsProjectPath(path.join(__dirname, 'example', 'windows')),
},
};
} catch (_) {
return undefined;
}
})();

module.exports = {
dependencies: {
Expand All @@ -30,51 +49,5 @@ module.exports = {
},
},
},
project: {
android: {
sourceDir: path.join('example', 'android'),
manifestPath: path.relative(
path.join(__dirname, 'example', 'android'),
path.join(
path.dirname(require.resolve('react-native-test-app/package.json')),
'android',
'app',
'src',
'main',
'AndroidManifest.xml',
),
),
},
ios: {
project: (() => {
const {
packageSatisfiesVersionRange,
} = require('react-native-test-app/scripts/configure');
if (
packageSatisfiesVersionRange(
'@react-native-community/cli-platform-ios',
'<5.0.2',
)
) {
// Prior to @react-native-community/cli-platform-ios v5.0.0,
// `project` was only used to infer `sourceDir` and `podfile`.
return 'example/ios/ReactTestApp-Dummy.xcodeproj';
}
// `sourceDir` and `podfile` detection was fixed in
// @react-native-community/cli-platform-ios v5.0.2 (see
// https://github.com/react-native-community/cli/pull/1444).
return 'node_modules/.generated/ios/ReactTestApp.xcodeproj';
})(),
},
windows: fs.existsSync(windowsProjectFile) && {
sourceDir: path.join('example', 'windows'),
solutionFile: 'WebviewExample.sln',
project: {
projectFile: path.relative(
path.join(__dirname, 'example', 'windows'),
windowsProjectFile,
),
},
},
},
...(project ? { project } : undefined),
};

0 comments on commit c6471ed

Please sign in to comment.