Treat opendir failures as empty directories#186
Conversation
🦋 Changeset detectedLatest commit: 12e9c20 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
opendir failures as empty directoriesopendir failures as empty directories
| "react-native-node-api", // The host package itself | ||
| "react-native", // React Native core |
There was a problem hiding this comment.
Two known packages known not to have Node-API prebuilds which we want to link in.
There was a problem hiding this comment.
Pull Request Overview
This PR updates the Node-API module discovery to treat directory read failures as empty directories and completely exclude the host and React Native packages.
- Wraps
fs.promises.opendirin atry/catchto skip over unreadable directories. - Removes the path-based exclusion for
react-native-node-apiand adds a package-name exclusion list. - Filters out
react-native-node-apiandreact-nativeinfindNodeApiModulePathsByDependencyand adds a test for the unreadable-directory case.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/host/src/node/path-utils.ts | Wrap opendir in try/catch, remove path exclude, add package-name exclude. |
| packages/host/src/node/path-utils.test.ts | Adjust existing test and add new test for unreadable directories. |
| .changeset/stale-coins-drop.md | Add changeset entry summarizing the fix. |
Comments suppressed due to low confidence (2)
packages/host/src/node/path-utils.ts:354
- [nitpick] The comment refers to 'patterns' but the constant is a list of package names. Update the doc to clearly state these are package names being excluded.
* Default patterns to use when excluding package names from the search for Node-API modules.
packages/host/src/node/path-utils.ts:385
- There’s no test verifying that 'react-native-node-api' and 'react-native' are actually excluded. Add a test case to cover the
excludePackagesbehavior infindNodeApiModulePathsByDependency.
.filter(([name]) => !excludePackages.includes(name))
packages/host/src/node/path-utils.ts
Outdated
| } catch { | ||
| // Intentionally left empty: if the directory cannot be read, we skip it |
There was a problem hiding this comment.
[nitpick] Catching all errors here may mask unexpected issues (e.g., permission vs. path-not-found). Consider narrowing this to specific filesystem errors like ENOENT or EACCES to avoid hiding genuine failures.
| } catch { | |
| // Intentionally left empty: if the directory cannot be read, we skip it | |
| } catch (error: any) { | |
| if (error.code === "ENOENT" || error.code === "EACCES") { | |
| // Skip the directory if it does not exist or access is denied | |
| } else { | |
| throw error; // Re-throw unexpected errors | |
| } |
f5af8fd to
12e9c20
Compare
Merging this PR fixes #185 by introducing a few changes to the implementation used when looking for Node-API modules on the filesystem:
opendirfailures as empty directories.react-native-node-apiandreact-nativepackages completely.