-
Notifications
You must be signed in to change notification settings - Fork 637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add processModuleFilter and remove postProcessModules #215
Conversation
use processModuleFilter to skip some modules before code generating
Codecov Report
@@ Coverage Diff @@
## master #215 +/- ##
==========================================
+ Coverage 85.79% 85.83% +0.03%
==========================================
Files 137 137
Lines 4406 4411 +5
Branches 685 686 +1
==========================================
+ Hits 3780 3786 +6
+ Misses 554 553 -1
Partials 72 72
Continue to review full report at Codecov.
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! having a filtering function is much better than the previous method 👍
Please update the rest of the serializers and we're good to go 😃
docs/Configuration.md
Outdated
@@ -104,4 +104,4 @@ These options are only useful with React Native projects. | |||
| `getPolyfills` | `({platform: ?string}) => $ReadOnlyArray<string>` | An optional list of polyfills to include in the bundle. The list defaults to a set of common polyfills for Number, String, Array, Object... | | |||
| `postProcessBundleSourcemap` | `PostProcessBundleSourcemap` | An optional function that can modify the code and source map of the bundle before it is written. Applied once for the entire bundle. | | |||
| `getModulesRunBeforeMainModule` | `(entryFilePath: string) => Array<string>` | An array of modules to be required before the entry point. It should contain the absolute path of each module. | | |||
| `postProcessModules` | `(modules: Array<Module>, entryFiles: Array<string>) => Array<Module>` | A function that can change the resulting modules output. | | |||
| `processModuleFilter` | `(module: Array<Module>) => boolean` | A function that can change the resulting modules output. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the description to: A filter function to discard specific modules from the output
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it's better
@@ -42,6 +43,7 @@ function plainJSBundle( | |||
...getAppendScripts(entryPoint, graph, options), | |||
] | |||
.filter(isJsModule) | |||
.filter(options.processModuleFilter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be done to each of the serializers to have consistent results no matter the type of output that the user is generating (it's specially important to update the sourcemap serializers to not end up with incorrect sourcemaps).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 I'll have a try. Since I haven't read these files, it may take a while.
Thanks for review
// sourceMapObject.js
function fullSourceMapObject(
pre: $ReadOnlyArray<Module<>>,
graph: Graph<>,
options: {|
+excludeSource: boolean,
+processModuleFilter: (module: Module<>) => boolean,
|},
): BabelSourceMap {
const modules = [...pre, ...graph.dependencies.values()]
.filter(isJsModule)
.filter(options.processModuleFilter) // this line can be removed if we don't use it in `_sourceMapForURL` function below
.map(module => {
return {
...getJsOutput(module).data,
path: module.path,
source: options.excludeSource ? '' : module.getSource(),
};
});
return fromRawMappings(modules).toMap(undefined, {
excludeSource: options.excludeSource,
});
}
// Server.js
async _sourceMapForURL(reqUrl: string): Promise<MetroSourceMap> {
const options: DeltaOptions = this._getOptionsFromUrl(reqUrl);
const {graph, prepend} = await this._getGraphInfo(options, {
rebuild: false,
});
return sourceMapObject(prepend, graph, {
excludeSource: options.excludeSource,
processModuleFilter: this._config.serializer.processModuleFilter,
});
} |
The |
@rafeca thanks for explain that. It's very helpful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the comments so fast! Looks great now! (sorry for all the repetitive work on the serializers: we're planning create some helpers to be able to reuse logic there.
I'm going to import this PR to our systems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rafeca has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary
remove postProcessModules hook since it is not working now. Add a processModuleFilter hook to skip some modules before code generating. see #210
Test plan
pass