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
Fix resolving of local common js wrapped modules. #4529
Conversation
@@ -57,7 +57,7 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate { | |||
], | |||
lf: [ | |||
"var XXX;", | |||
"!(XXX = #.call(exports, __webpack_require__, exports, module))" | |||
"!(XXX = #.call(exports, __webpack_require__, exports, module)); XXX === undefined && (XXX = module.exports)" |
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 must stay a single expression. Not a statement.
define
could be used this way:
a && define(...) && b
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.
Also fix the lof
case.
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.
Passing exports
and module
from the surrounding module is wrong here too.
Maybe this could fix it:
var XXX, XXX_module;
!(XXX_module = { id: YYY, exports: {}, loaded: false },
XXX = #.call(XXX_module.exports, __webpack_require__, XXX_module.exports, XXX_module),
XXX_module.loaded = true,
XXX === undefined && (XXX = XXX_module.exports)
)
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.
Hey, thanks for the review! Can you please explain a bit about
Passing exports and module from the surrounding module is wrong here too.
I don't really get why that's wrong.
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.
Please also add tests
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.
@sokra Could you please take a look? I'm a bit unsure about module id — where do I take it from and how is it used later on?
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.
Looks good.
We still need a test for this.
XXX = (typeof XXXfactory === 'function' ? | ||
(XXXfactory.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule)) : XXXfactory), | ||
(XXXmodule.loaded = true), | ||
XXX === undefined && (XXX = XXXmodule.exports))` |
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.
Please don't embed newlines/tabs into the generated source. This blow up the generated code with webpack stuff. Best keep it as equal to the original source as possible. Just generate a single line with this AMD wrapper code, that hides it the best.
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.
Hey, I added the id, removed new lines and added tests. Please, take a look once you will have time.
For define("nameOfModule", ...) But this is not yet available in |
@zastavnitskiy Thanks for your update. I labeled the Pull Request so reviewers will review it again. @sokra Please review the new changes. |
}); | ||
|
||
define("override-exports", function(require, exports, module) { | ||
exports = "this one overrides exports reference"; |
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 won't work.
Setting exports
is not a valid way to export stuff.
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.
It doesn't, but we should return empty object and not undefined as it was before.
"var XXX;", | ||
"!(XXX = #.call(exports, __webpack_require__, exports, module))" | ||
"var XXX,XXXmodule;", | ||
"!(XXXmodule = { id: 'YYY', exports: {}, loaded: false }, XXX = #.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule),XXXmodule.loaded = true,XXX === undefined && (XXX = XXXmodule.exports))" |
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.
'YYY'
-> YYY
@@ -112,6 +112,10 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate { | |||
definition = definition.replace(/XXX/g, localModuleVar.replace(/\$/g, "$$$$")); | |||
} | |||
|
|||
if(dependency.namedModule) { | |||
text = text.replace(/YYY/g, dependency.namedModule); |
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.
dependency.namedModule
-> JSON.stringify(dependency.namedModule)
`!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#), XXX = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? | ||
(__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__))` | ||
"var XXX,XXXfactory,XXXmodule;", | ||
"!(XXXfactory = (#),(XXXmodule = { id: 'YYY', exports: {}, loaded: false }),XXX = (typeof XXXfactory === 'function' ? (XXXfactory.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule)) : XXXfactory),(XXXmodule.loaded = true),XXX === undefined && (XXX = XXXmodule.exports))" |
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.
'YYY'
-> YYY
`!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#), XXX = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? | ||
(__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__))` | ||
"var XXX,XXXfactory,XXXmodule;", | ||
"!(XXXfactory = (#),(XXXmodule = { id: 'YYY', exports: {}, loaded: false }),XXX = (typeof XXXfactory === 'function' ? (XXXfactory.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule)) : XXXfactory),(XXXmodule.loaded = true),XXX === undefined && (XXX = XXXmodule.exports))" |
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.
Insert a single space
after each ,
like above
@zastavnitskiy Thanks for your update. I labeled the Pull Request so reviewers will review it again. @sokra Please review the new changes. |
Hey, I updated my forked repo and pushed requested changes. Now I also see commits from the main repo in the pull request. Do you know how to fix it? |
The most important CI builds succeeded. Great work so far. |
It looks like this Pull Request doesn't include enough test cases. @zastavnitskiy Please add more test cases. See test readme for details how to write test cases. |
ahh.. I accidentally destroyed it... |
Hi @zastavnitskiy. First thanks for your pull request. Just a little hint from a friendly bot about the best practice when submitting pull request:
You don't have to change it for this PR, just make sure to follow this hint the next time you submit a PR. |
What kind of change does this PR introduce?
Bugfix for #4511
Did you add tests for your changes?
Not really, struggling to understand where and hot add them. Help appreciated.
Summary
Currenly, commonjs wrapped local modules are not resolved. This is a fix.
Does this PR introduce a breaking change?
No