From 3731fa7c3c0a6340ca1bc56e2126f71e55593542 Mon Sep 17 00:00:00 2001 From: yeyuanfeng Date: Tue, 29 Aug 2017 08:08:19 -0700 Subject: [PATCH] TransformCaching: fix GC condition judgement error Summary: **Summary** I am sending this PR to fix an error in TransformCaching module. See this issue [TransformCaching module try to collect cache every time I build bundle #46](https://github.com/facebook/metro-bundler/issues/46). **Test plan** ``` /** * When restarting packager we want to avoid running the collection over * again, so we store the last collection time in a file and we check that * first. */ _collectCacheIfOldSync() { const {_rootPath} = this; const cacheCollectionFilePath = path.join(_rootPath, 'last_collected'); const lastCollected = Number.parseInt( tryReadFileSync(cacheCollectionFilePath) || '', 10, ); if ( Number.isInteger(lastCollected) && Date.now() - lastCollected < GARBAGE_COLLECTION_PERIOD ) { return; } const effectiveCacheDirPath = path.join(_rootPath, CACHE_SUB_DIR); mkdirp.sync(effectiveCacheDirPath); collectCacheSync(effectiveCacheDirPath); fs.writeFileSync(cacheCollectionFilePath, Date.now().toString()); } ``` Steps: 1. Create a new react-native project. 2. Put your breakpoint at this sentence `collectCacheSync(effectiveCacheDirPath);`. 3. Bundle the project, program will break at `collectCacheSync(effectiveCacheDirPath);` 4. Resume the program, finish the first time bundle. 5. Bundle again, this time program won't break. Closes https://github.com/facebook/metro-bundler/pull/48 Differential Revision: D5726161 Pulled By: jeanlauliac fbshipit-source-id: 0865f1bf25d6eb36f067ac3dc7764df9fd5026dc --- packages/metro-bundler/src/lib/TransformCaching.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/metro-bundler/src/lib/TransformCaching.js b/packages/metro-bundler/src/lib/TransformCaching.js index d2283bc9..c9efb1df 100644 --- a/packages/metro-bundler/src/lib/TransformCaching.js +++ b/packages/metro-bundler/src/lib/TransformCaching.js @@ -272,7 +272,7 @@ class FileBasedCache { ); if ( Number.isInteger(lastCollected) && - Date.now() - lastCollected > GARBAGE_COLLECTION_PERIOD + Date.now() - lastCollected < GARBAGE_COLLECTION_PERIOD ) { return; }