Skip to content
Merged
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
5 changes: 4 additions & 1 deletion packages/metro-file-map/src/cache/DiskCacheManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ export class DiskCacheManager implements CacheManager {
): string {
const {rootDirHash, relativeConfigHash} =
rootRelativeCacheKeys(buildParameters);
// Bun's `node:v8` serialization isn't fully compatible with Node's, so a
// cache written by one can't be read by the other.
const runtimeSuffix = process.versions.bun != null ? '-bun' : '';

return path.join(
cacheDirectory ?? DEFAULT_DIRECTORY,
`${
cacheFilePrefix ?? DEFAULT_PREFIX
}-${rootDirHash}-${relativeConfigHash}`,
}-${rootDirHash}-${relativeConfigHash}${runtimeSuffix}`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ describe('cacheManager', () => {
);
});

test('creates different cache file paths under Bun', () => {
const nodePath = DiskCacheManager.getCacheFilePath(
buildParameters,
'file-prefix',
'/',
);
// `process.versions` is read-only, but its properties can be defined.
Object.defineProperty(process.versions, 'bun', {
configurable: true,
value: '1.3.0',
});
let bunPath;
try {
bunPath = DiskCacheManager.getCacheFilePath(
buildParameters,
'file-prefix',
'/',
);
} finally {
delete process.versions.bun;
}
expect(bunPath).toBe(nodePath + '-bun');
});

test('creates different cache file paths for different roots', () => {
const cacheManager1 = new DiskCacheManager(
{
Expand Down
Loading