Skip to content

Commit 628df24

Browse files
committed
fix: fetch correct version of packages for web support
1 parent 1e31449 commit 628df24

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

packages/create-react-native-library/src/utils/generateExampleApp.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs-extra';
22
import spawn from 'cross-spawn';
33
import path from 'path';
4+
import https from 'https';
45

56
const FILES_TO_DELETE = [
67
'__tests__',
@@ -120,16 +121,51 @@ export default async function generateExampleApp({
120121
scripts.pods = 'pod-install --quiet';
121122
}
122123

123-
PACKAGES_TO_REMOVE.forEach((pkg) => {
124+
PACKAGES_TO_REMOVE.forEach((name) => {
124125
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
125-
delete devDependencies[pkg];
126+
delete devDependencies[name];
126127
});
127128

128129
Object.assign(devDependencies, PACKAGES_TO_ADD_DEV);
129130

130131
if (type === 'expo') {
131-
Object.assign(dependencies, PACKAGES_TO_ADD_WEB);
132-
Object.assign(devDependencies, PACKAGES_TO_ADD_WEB_DEV);
132+
const sdkVersion = dependencies.expo.split('.')[0].replace(/[^\d]/, '');
133+
134+
let bundledNativeModules: Record<string, string>;
135+
136+
try {
137+
bundledNativeModules = await new Promise((resolve, reject) => {
138+
https
139+
.get(
140+
`https://raw.githubusercontent.com/expo/expo/sdk-${sdkVersion}/packages/expo/bundledNativeModules.json`,
141+
(res) => {
142+
let data = '';
143+
144+
res.on('data', (chunk) => (data += chunk));
145+
res.on('end', () => {
146+
try {
147+
resolve(JSON.parse(data));
148+
} catch (e) {
149+
reject(e);
150+
}
151+
});
152+
}
153+
)
154+
.on('error', reject);
155+
});
156+
} catch (e) {
157+
bundledNativeModules = {};
158+
}
159+
160+
Object.entries(PACKAGES_TO_ADD_WEB).forEach(([name, version]) => {
161+
dependencies[name] = bundledNativeModules[name] || version;
162+
});
163+
164+
Object.entries(PACKAGES_TO_ADD_WEB_DEV).forEach(([name, version]) => {
165+
devDependencies[name] = bundledNativeModules[name] || version;
166+
});
167+
168+
scripts.web = 'expo start --web';
133169
}
134170

135171
await fs.writeFile(

0 commit comments

Comments
 (0)