-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Avoid exporting "ready" promise on the module object #21564
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
Conversation
I believe the "ready" promise was set on the Module object here primarily so that closure would not minify the name. Instead of polluting the Module namespace we can instead just tell closure not to minify it. In addition to polluting the `Module` namespace exporting a `ready` promise is also confusing since the only way to get a module object when `-sMODULARIZE` is used is via waiting on the promise returned from the factory function. So, by definition, the promise has already resolved before anyone can access it. Instead we use the `closure-externs.js` file to suppress the minifiction which matches the behavior of the incoming `moduleArg` argument.
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 am not sure if there is not another use for .ready
in ES6 modules or CommonJS or something else, but lgtm if @brendandahl confirms no problem there.
I'm pretty sure there would be no way to call access |
You could technically get access to let m = require('./a.out.js');
let settings = {};
m(settings);
console.log(settings.ready);
// main wouldn't run until next tick Anyway, I don't really see a need for defining it on the module and returning it from the ModuleFactory for modularize/es6. |
Very tricky yes. I wonder if we should remove that feature? i.e. should we
Agreed. I think this should be fine to land. |
This probably warrants a mention in the changelog. |
I believe the "ready" promise was set on the Module object here primarily so that closure would not minify the name. Instead of polluting the Module namespace we can instead just tell closure not to minify it.
In addition to polluting the
Module
namespace exporting aready
promise is also confusing since the only way to get a module object when-sMODULARIZE
is used is via waiting on the promise returned from the factory function. So, by definition, the promise has already resolved before anyone can access it.Instead we use the
closure-externs.js
file to suppress the minifiction which matches the behavior of the incomingmoduleArg
argument.