Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

feat: Add Expo Support for React Native Preset #183

Merged
merged 1 commit into from
Oct 1, 2023
Merged
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
24 changes: 24 additions & 0 deletions src/presets/react-native.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Preset } from '../config';
import nodePreset from './node';
import { list, resolveFilesSync } from '../fs';

Check warning on line 3 in src/presets/react-native.ts

View workflow job for this annotation

GitHub Actions / Eslint

'list' is defined but never used
import { typedBoolean } from '../meta';

function getEntry(target: string, rootExtensions: string[]) {
Expand All @@ -24,16 +24,40 @@
},
};
}

function getExpo(options, rootExtensions: string[]) {
const expoEntry = options.packageJson.main;

if (!expoEntry) {
return;
}

const [file] = resolveFilesSync([expoEntry], rootExtensions);

if (!file) {
return;
}
return {
file,
label: 'expo',
extend: {
extensions: rootExtensions,
},
};
}
const preset: Preset = {
name: 'react-native',
isMatch: ({ hasPackage }) => hasPackage('react-native'),
getConfig: async (options) => {
const base = await nodePreset.getConfig(options);
const extensions = base.extensions as string[];

const hasExpo = options.hasPackage('expo');

const entry = [
getEntry('android', extensions),
getEntry('ios', extensions),
hasExpo ? getExpo(options, extensions) : undefined,
].filter(typedBoolean);

return {
Expand Down
Loading