From 24ef4065139535d4cc6024c8d257975be887bf1b Mon Sep 17 00:00:00 2001 From: maokangren <767709667@qq.com> Date: Thu, 24 May 2018 20:57:53 +0800 Subject: [PATCH] [smart] #2 support filter exclude modules to package business bundle --- .gitignore | 4 +++- .../src/DeltaBundler/Serializers/Serializers.js | 13 ++++++++++++- packages/metro/src/Server/index.js | 3 ++- packages/metro/src/shared/output/bundle.js | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c03971270b..6ea3070c11 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ npm-debug.log* packages/*/build/ /packages-release -package-lock.json \ No newline at end of file +package-lock.json + +.idea/ \ No newline at end of file diff --git a/packages/metro/src/DeltaBundler/Serializers/Serializers.js b/packages/metro/src/DeltaBundler/Serializers/Serializers.js index 43ce1c4a1b..f79ec63b38 100644 --- a/packages/metro/src/DeltaBundler/Serializers/Serializers.js +++ b/packages/metro/src/DeltaBundler/Serializers/Serializers.js @@ -108,9 +108,20 @@ async function fullBundle( options, ); - const code = modules.map(m => m.code); + var finalModules = modules; + if(options.excludedModules) { + console.log("\n\nFilter before modules.length=="+finalModules.length+ "\n") + finalModules = finalModules.filter(module => { + const keep = !options.excludedModules[module.name]; + console.log("Filtering "+ (keep? "keep -> ": "remove -> ")+ module.name+ ", "+ module.path) + return keep + }) + console.log("\nFilter after modules.length=="+finalModules.length+ "\n") + } + const code = finalModules.map(m => m.code); return { + modules: finalModules, bundle: code.join('\n'), lastModified, numModifiedFiles, diff --git a/packages/metro/src/Server/index.js b/packages/metro/src/Server/index.js index 3a284c1789..0694780485 100644 --- a/packages/metro/src/Server/index.js +++ b/packages/metro/src/Server/index.js @@ -228,7 +228,7 @@ class Server { return this._deltaBundler; } - async build(options: BundleOptions): Promise<{code: string, map: string}> { + async build(options: BundleOptions): Promise<{code: string, map: string, modules: mixed}> { options = { ...options, runBeforeMainModule: this._opts.getModulesRunBeforeMainModule( @@ -249,6 +249,7 @@ class Server { return { code: fullBundle.bundle, map: fullMap, + modules: fullBundle.modules, }; } diff --git a/packages/metro/src/shared/output/bundle.js b/packages/metro/src/shared/output/bundle.js index 5481d7deb6..59dc6efd05 100644 --- a/packages/metro/src/shared/output/bundle.js +++ b/packages/metro/src/shared/output/bundle.js @@ -22,7 +22,7 @@ import type {MetroSourceMap} from 'metro-source-map'; function buildBundle( packagerClient: Server, requestOptions: RequestOptions, -): Promise<{code: string, map: string}> { +): Promise<{code: string, map: string, modules: mixed}> { return packagerClient.build({ ...Server.DEFAULT_BUNDLE_OPTIONS, ...requestOptions,