Skip to content

Commit fa8fad8

Browse files
Abbondanzometa-codesync[bot]
authored andcommitted
Fix helloworld e2e after core-cli-utils stopped publishing (#57308)
Summary: Pull Request resolved: #57308 `private/helloworld` depends on `react-native/core-cli-utils` (it imports `android`, `app`, and `apple` from it to build the app), but that package is no longer published to npm nor to the local Verdaccio proxy that the e2e build installs against. Since `private/helloworld` is excluded from the workspace, it installs standalone, so its `"*"` dependency on `react-native/core-cli-utils` could not resolve and `npm install` failed with `E404`. Resolve `"*"`-pinned in-repo `react-native/*` dependencies to a local `file:` path in `_prepareHelloWorld()`, so helloworld consumes `core-cli-utils` directly from its in-repo reference implementation regardless of whether it is published. This mirrors how the `react-native` package itself is already wired up for the e2e build. Changelog: [Internal] Reviewed By: javache Differential Revision: D109374920 fbshipit-source-id: b6668785387511fa54580ee75e81f13168782797
1 parent 53369ed commit fa8fad8

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

scripts/e2e/init-project-e2e.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ async function initNewProjectFromSource(
136136

137137
if (useHelloWorld) {
138138
console.log('Preparing private/helloworld/ to be built');
139-
_prepareHelloWorld(version, pathToLocalReactNative);
139+
const localPackages = await getPackages({
140+
includeReactNative: false,
141+
includePrivate: true,
142+
});
143+
_prepareHelloWorld(version, pathToLocalReactNative, localPackages);
140144
directory = path.join(PRIVATE_DIR, 'helloworld');
141145
} else {
142146
const pathToTemplate = _prepareTemplate(
@@ -209,31 +213,36 @@ async function installProjectUsingProxy(cwd /*: string */) {
209213
function _prepareHelloWorld(
210214
version /*: string */,
211215
pathToLocalReactNative /*: ?string*/,
216+
packages /*: ProjectInfo */,
212217
) {
213218
const helloworldDir = path.join(PRIVATE_DIR, 'helloworld');
214219
const helloworldPackageJson = path.join(helloworldDir, 'package.json');
215220
const packageJson = JSON.parse(
216221
fs.readFileSync(helloworldPackageJson, 'utf8'),
217222
);
218223

219-
// and update the dependencies and devDependencies of packages scoped as @react-native
220-
// to the version passed as parameter
221-
for (const key of Object.keys(packageJson.dependencies)) {
222-
if (
223-
key.startsWith('@react-native/') &&
224-
packageJson.dependencies[key] !== '*'
225-
) {
226-
packageJson.dependencies[key] = version;
224+
// Point each in-repo @react-native/* dependency at the version published to
225+
// the local proxy. Deps declared as `*` are unpublished reference packages
226+
// (e.g. @react-native/core-cli-utils, which lives in private/) and are absent
227+
// from the proxy, so resolve those to their local source via a `file:` path.
228+
const updateDependencies = (deps /*: Record<string, string> */) => {
229+
for (const key of Object.keys(deps)) {
230+
if (!key.startsWith('@react-native/')) {
231+
continue;
232+
}
233+
if (deps[key] === '*') {
234+
const localPackage = packages[key];
235+
if (localPackage != null) {
236+
deps[key] = `file:${path.relative(helloworldDir, localPackage.path)}`;
237+
}
238+
} else {
239+
deps[key] = version;
240+
}
227241
}
228-
}
229-
for (const key of Object.keys(packageJson.devDependencies)) {
230-
if (
231-
key.startsWith('@react-native/') &&
232-
packageJson.devDependencies[key] !== '*'
233-
) {
234-
packageJson.devDependencies[key] = version;
235-
}
236-
}
242+
};
243+
updateDependencies(packageJson.dependencies);
244+
updateDependencies(packageJson.devDependencies);
245+
237246
if (pathToLocalReactNative != null) {
238247
packageJson.dependencies['react-native'] = `file:${pathToLocalReactNative}`;
239248
}

0 commit comments

Comments
 (0)