From b5e19adc02a3293cd3fdbe54cc45adc78f94d325 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Thu, 18 Jan 2018 07:50:53 -0800 Subject: [PATCH] metro: allow dynamic dependencies from within node_modules Summary: Tries to adress https://github.com/facebook/metro/issues/65. We need a reasonnable workaround to support modules like `moment.js` that do dynamic requires but only in some cases. By replacing the call by a function that throws, we move the exception at runtime instead of happening at compile time. We don't want to do that for non-node_modules file because they are fixable directly, while `node_modules` are not fixable by people and they get completely blocked by the error at compile time. Reviewed By: rafeca Differential Revision: D6736989 fbshipit-source-id: a6e1fd9b56fa83907400884efd8f8594018b7c37 --- local-cli/bundle/buildBundle.js | 1 + local-cli/dependencies/dependencies.js | 1 + local-cli/server/runServer.js | 1 + 3 files changed, 3 insertions(+) diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index 5d664097ee0372..2dbe14fb884b5d 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -94,6 +94,7 @@ async function buildBundle( assetExts: defaultAssetExts.concat(assetExts), assetRegistryPath: ASSET_REGISTRY_PATH, blacklistRE: config.getBlacklistRE(), + dynamicDepsInPackages: config.dynamicDepsInPackages, extraNodeModules: config.extraNodeModules, getModulesRunBeforeMainModule: config.getModulesRunBeforeMainModule, getPolyfills: config.getPolyfills, diff --git a/local-cli/dependencies/dependencies.js b/local-cli/dependencies/dependencies.js index 31a127a53b4a24..7bb480dd26cac5 100644 --- a/local-cli/dependencies/dependencies.js +++ b/local-cli/dependencies/dependencies.js @@ -31,6 +31,7 @@ function dependencies(argv, config, args, packagerInstance) { assetRegistryPath: ASSET_REGISTRY_PATH, projectRoots: config.getProjectRoots(), blacklistRE: config.getBlacklistRE(), + dynamicDepsInPackages: config.dynamicDepsInPackages, getPolyfills: config.getPolyfills, getTransformOptions: config.getTransformOptions, hasteImpl: config.hasteImpl, diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index e092f685a4b9bf..d143975daec596 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -179,6 +179,7 @@ function getPackagerServer(args, config, reporter) { cacheVersion: '3', enableBabelRCLookup: config.getEnableBabelRCLookup(), extraNodeModules: config.extraNodeModules, + dynamicDepsInPackages: config.dynamicDepsInPackages, getModulesRunBeforeMainModule: config.getModulesRunBeforeMainModule, getPolyfills: config.getPolyfills, getTransformOptions: config.getTransformOptions,