Skip to content
Open
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
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ docs
.prettierrc
tsconfig.json
type-test.tsx
__tests__
typedocs
54 changes: 54 additions & 0 deletions __tests__/apple-button-resolution.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');

const libDir = path.join(__dirname, '..', 'lib');

// Source extensions from the Expo/EAS Metro error in issue #375. That resolver
// tries `AppleButton` + these exts only — not AppleButton.ios.js / .android.js.
const expoWebSourceExts = [
'.web.ts',
'.ts',
'.web.tsx',
'.tsx',
'.web.js',
'.js',
'.web.jsx',
'.jsx',
'.web.json',
'.json',
'.web.cjs',
'.cjs',
'.web.mjs',
'.mjs',
'.web.scss',
'.scss',
'.web.sass',
'.sass',
'.web.css',
'.css',
];

function resolveWithExpoWebSourceExts(moduleName) {
for (const ext of expoWebSourceExts) {
const candidate = path.join(libDir, moduleName + ext);
if (fs.existsSync(candidate)) {
return candidate;
}
}
const exact = path.join(libDir, moduleName);
if (fs.existsSync(exact)) {
return exact;
}
return null;
}

test('AppleButton resolves with Expo web Metro sourceExts (#375)', () => {
const resolved = resolveWithExpoWebSourceExts('AppleButton');
assert.ok(
resolved,
'Unable to resolve module ./AppleButton: none of the Expo web sourceExt candidates exist',
);
assert.equal(path.basename(resolved), 'AppleButton.js');
});
10 changes: 10 additions & 0 deletions lib/AppleButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Platform } from 'react-native';

const AppleButton = Platform.select({
ios: require('./AppleButton.ios').default,
android: require('./AppleButton.android').default,
macos: require('./AppleButton.macos').default,
default: require('./AppleButton.android').default,
});

export default AppleButton;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"postinstallDev": "yarn build && yarn tsc:compile",
"tsc:compile": "tsc --noEmit",
"lint": "eslint lib/",
"test": "node --test __tests__/apple-button-resolution.test.js",
"build": "genversion --semi lib/version.js --verbose",
"build:all": "yarn build:clean && yarn build && yarn example:build:android && yarn example:build:ios",
"build:clean": "rimraf ios/build android/build example/android/app/build example/ios/build example-old/macos/build example-old/visionos/build",
Expand Down