From d9b6fd710212c665305e53a6b7508a16317e9308 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Wed, 14 Feb 2018 08:42:30 -0800 Subject: [PATCH] Pass cacheVersion param via the new API Reviewed By: BYK Differential Revision: D6980337 fbshipit-source-id: 72c01136b6720390ffec8593f0375c8756dc1d4a --- packages/metro/src/Config.js | 7 +++++++ packages/metro/src/Server/index.js | 2 +- packages/metro/src/index.js | 1 + packages/metro/src/shared/types.flow.js | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/metro/src/Config.js b/packages/metro/src/Config.js index 0107c802..2eb51ff6 100644 --- a/packages/metro/src/Config.js +++ b/packages/metro/src/Config.js @@ -32,6 +32,12 @@ type Middleware = (IncomingMessage, ServerResponse, ?() => mixed) => mixed; export type ConfigT = { assetRegistryPath: string, + /** + * Can be used to generate a key that will invalidate the whole metro cache + * (for example a global dependency version used by the transformer). + */ + cacheVersion: string, + /** * Called with the Metro middleware in parameter; can be used to wrap this * middleware inside another one @@ -163,6 +169,7 @@ const DEFAULT = ({ enhanceMiddleware: middleware => middleware, extraNodeModules: {}, assetTransforms: false, + cacheVersion: '1.0', dynamicDepsInPackages: 'throwAtRuntime', getAssetExts: () => [], getBlacklistRE: () => blacklist(), diff --git a/packages/metro/src/Server/index.js b/packages/metro/src/Server/index.js index 0990b3cd..d51b8f8f 100644 --- a/packages/metro/src/Server/index.js +++ b/packages/metro/src/Server/index.js @@ -121,7 +121,7 @@ class Server { assetExts: options.assetTransforms ? [] : assetExts, assetRegistryPath: options.assetRegistryPath, blacklistRE: options.blacklistRE, - cacheVersion: options.cacheVersion || '1.0', + cacheVersion: options.cacheVersion, dynamicDepsInPackages: options.dynamicDepsInPackages || 'throwAtRuntime', createModuleIdFactory: options.createModuleIdFactory, enableBabelRCLookup: diff --git a/packages/metro/src/index.js b/packages/metro/src/index.js index 17c935ec..15675838 100644 --- a/packages/metro/src/index.js +++ b/packages/metro/src/index.js @@ -123,6 +123,7 @@ async function runMetro({ assetExts: normalizedConfig.assetTransforms ? [] : assetExts, assetRegistryPath: normalizedConfig.assetRegistryPath, blacklistRE: normalizedConfig.getBlacklistRE(), + cacheVersion: normalizedConfig.cacheVersion, createModuleIdFactory: normalizedConfig.createModuleIdFactory, dynamicDepsInPackages: normalizedConfig.dynamicDepsInPackages, enableBabelRCLookup: normalizedConfig.getEnableBabelRCLookup(), diff --git a/packages/metro/src/shared/types.flow.js b/packages/metro/src/shared/types.flow.js index 95465616..5a23c96f 100644 --- a/packages/metro/src/shared/types.flow.js +++ b/packages/metro/src/shared/types.flow.js @@ -75,7 +75,7 @@ export type Options = {| +asyncRequireModulePath?: string, +assetRegistryPath: string, blacklistRE?: RegExp, - cacheVersion?: string, + cacheVersion: string, createModuleIdFactory?: () => (path: string) => number, +dynamicDepsInPackages: DynamicRequiresBehavior, enableBabelRCLookup: boolean,