mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-30 18:24:25 +08:00
Calculate asset hash from file contents, cache hashes
Summary: This makes the `hash` property of asset data depend on asset file contents rather than modification time of files. That means that bundles will be consistent across different checkouts. Reviewed By: martinbigio Differential Revision: D3856815 fbshipit-source-id: 8bfea4e0a714f48fc6a4ae5ed2a1426dc8d5868e
This commit is contained in:
committed by
Facebook Github Bot 8
parent
3e153b2a5b
commit
cacc31d759
@@ -9,6 +9,7 @@
|
||||
'use strict';
|
||||
|
||||
const fs = jest.genMockFromModule('fs');
|
||||
const stream = require.requireActual('stream');
|
||||
const noop = () => {};
|
||||
|
||||
function asyncCallback(cb) {
|
||||
@@ -185,7 +186,35 @@ fs.close.mockImpl((fd, callback = noop) => {
|
||||
|
||||
let filesystem;
|
||||
|
||||
fs.__setMockFilesystem = (object) => filesystem = object;
|
||||
fs.createReadStream.mockImpl(path => {
|
||||
if (!path.startsWith('/')) {
|
||||
throw Error('Cannot open file ' + path);
|
||||
}
|
||||
|
||||
const parts = path.split('/').slice(1);
|
||||
let file = filesystem;
|
||||
|
||||
for (const part of parts) {
|
||||
file = file[part];
|
||||
if (!file) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof file !== 'string') {
|
||||
throw Error('Cannot open file ' + path);
|
||||
}
|
||||
|
||||
return new stream.Readable({
|
||||
read() {
|
||||
this.push(file, 'utf8');
|
||||
this.push(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
fs.__setMockFilesystem = (object) => (filesystem = object);
|
||||
|
||||
function getToNode(filepath) {
|
||||
// Ignore the drive for Windows paths.
|
||||
|
||||
Reference in New Issue
Block a user