diff --git a/packages/metro-cache/src/FileStore.js b/packages/metro-cache/src/FileStore.js index 835a1d95..d8611fb5 100644 --- a/packages/metro-cache/src/FileStore.js +++ b/packages/metro-cache/src/FileStore.js @@ -20,6 +20,9 @@ export type Options = {| root: string, |}; +const JOINER_DATA = '\0\0'; +const JOINER_LIST = '\0'; + class FileStore { _root: string; @@ -35,7 +38,14 @@ class FileStore { get(key: Buffer): ?TransformedCode { try { - return JSON.parse(fs.readFileSync(this._getFilePath(key), 'utf-8')); + const data = fs.readFileSync(this._getFilePath(key), 'utf8'); + const [code, dependencies, map] = data.split(JOINER_DATA); + + return { + code, + dependencies: dependencies ? dependencies.split(JOINER_LIST) : [], + map: JSON.parse(map), + }; } catch (err) { if (err.code === 'ENOENT') { return null; @@ -46,7 +56,13 @@ class FileStore { } set(key: Buffer, value: TransformedCode): void { - fs.writeFileSync(this._getFilePath(key), JSON.stringify(value)); + const data = [ + value.code, + value.dependencies.join(JOINER_LIST), + JSON.stringify(value.map), + ].join(JOINER_DATA); + + fs.writeFileSync(this._getFilePath(key), data); } _getFilePath(key: Buffer): string {