filecoin-project / filecoin-project/filecoin-pin
Browser entry does not export UNIXFS_PROFILE or importerOptions
- Dominant language
- TypeScript
- Stars
- 26
- Forks
- 21
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 27
Description
## Description
The browser build of `filecoin-pin/core/unixfs` re-exports the CAR builders but not `importer-options.js`, so `UNIXFS_PROFILE` and `importerOptions` are reachable from Node and not from a browser bundle.
```
$ node --input-type=module -e "import('filecoin-pin/core/unixfs').then(m=>console.log(Object.keys(m).sort().join(', ')))"
UNIXFS_PROFILE, cleanupTempCar, createCarFromPath, createUnixfsCarBuilder, importerOptions
$ node --conditions=browser --input-type=module -e "import('filecoin-pin/core/unixfs').then(m=>console.log(Object.keys(m).sort().join(', ')))"
createCarFromFile, createCarFromFileList, createCarFromFiles
```
On filecoin-pin 2.0.1. `src/core/unixfs/index.ts` has the re-export and `src/core/unixfs/browser.ts` does not.
## Impact
A browser consumer that wants to hash bytes the way an upload will hash them cannot use `createCarFromFile` for it. That builds the whole CAR, which is the wrong shape when the answer wanted is a CID: for a file a user drops in to check against a CID they already hold, or for showing a CID before deciding whether to upload. The path that fits is `@helia/unixfs` over a throwaway blockstore, and that needs the same importer options the library uploads with.
With no browser export the consumer writes `{ profile: 'unixfs-v1-2025' }` by hand. That copy then has to track this library, and nothing tells anyone when it stops matching. The failure is quiet and late: CIDs computed in the browser stop equaling the CIDs the same bytes upload under, and the mismatch surfaces as a verification failure against content that was never wrong.
## Suggested fix
`src/core/unixfs/importer-options.ts` has one import and it is `import type`, so the module has no runtime dependency of any kind, let alone a Node one. Adding the re-export to `src/core/unixfs/browser.ts` costs a constant and a small object:
```ts
export * from './browser-car-builder.js'
export { importerOptions, UNIXFS_PROFILE } from './importer-options.js'
```
`src/index.browser.ts` is worth the same treatment, since `createCarFromFile` is already exported there and the options that govern it are not.
Contributor guide
Assessment
This issue has not been assessed yet.