From 5bdaf4697d13f72518361c03870e40945f787cba Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Thu, 18 May 2017 11:40:38 -0700 Subject: [PATCH] packager: do not use slashes in key Summary: Internally we use `multipart/form-data` to upload transformed files to the global cache, using the keys as file names. Unfortunately the server would read that and consider only the basename as the key, not the full path. So we wouldn't store the data under the right key. This is definitely a bug in the way upload is implemented: we should transmit the keys separately. But, this changeset offers a quick mitigation by avoiding slashes in the key, so that the whole key is a valid base file name. Reviewed By: davidaurelio Differential Revision: D5087780 fbshipit-source-id: 9e4a698c1f57c4c3b91b56b43eef82c1c7dd862b --- packages/metro-bundler/src/lib/GlobalTransformCache.js | 3 ++- .../__tests__/__snapshots__/GlobalTransformCache-test.js.snap | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/metro-bundler/src/lib/GlobalTransformCache.js b/packages/metro-bundler/src/lib/GlobalTransformCache.js index 1d2fe2c9..29585bee 100644 --- a/packages/metro-bundler/src/lib/GlobalTransformCache.js +++ b/packages/metro-bundler/src/lib/GlobalTransformCache.js @@ -232,9 +232,10 @@ class URIBasedGlobalTransformCache { hash.update(this._optionsHasher.getTransformWorkerOptionsDigest(transformOptions)); const cacheKey = props.getTransformCacheKey(transformOptions); hash.update(JSON.stringify(cacheKey)); + hash.update(JSON.stringify(localPath)); hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex')); const digest = hash.digest('hex'); - return `${digest}-${localPath}`; + return `${digest}-${path.basename(localPath)}`; } /** diff --git a/packages/metro-bundler/src/lib/__tests__/__snapshots__/GlobalTransformCache-test.js.snap b/packages/metro-bundler/src/lib/__tests__/__snapshots__/GlobalTransformCache-test.js.snap index 9fadc646..88ce1547 100644 --- a/packages/metro-bundler/src/lib/__tests__/__snapshots__/GlobalTransformCache-test.js.snap +++ b/packages/metro-bundler/src/lib/__tests__/__snapshots__/GlobalTransformCache-test.js.snap @@ -19,12 +19,12 @@ Object { exports[`GlobalTransformCache fetches results 1`] = ` Array [ Object { - "code": "/* code from http://globalcache.com/cd6df9b7e86839dafc5e9b5b493a28cbc55074e7-some/where/foo.js */", + "code": "/* code from http://globalcache.com/b23da8c74218e6155fcaf590a0fedbd1d117c2ae-foo.js */", "dependencies": Array [], "dependencyOffsets": Array [], }, Object { - "code": "/* code from http://globalcache.com/6329a317fcf94d74cc9a1de6442ee7c25e27a507-some/where/else/bar.js */", + "code": "/* code from http://globalcache.com/5e95f6c3e9bac0282480cda6f1a984ad8bc83e55-bar.js */", "dependencies": Array [], "dependencyOffsets": Array [], },