Skip to content
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

Closed
wants to merge 0 commits into from

Conversation

zastavnitskiy
Copy link
Contributor

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

@@ -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)"
Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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)
)

Copy link
Contributor Author

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.

Copy link
Member

@sokra sokra left a 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

Copy link
Contributor Author

@zastavnitskiy zastavnitskiy left a 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?

Copy link
Member

@sokra sokra left a 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))`
Copy link
Member

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.

Copy link
Contributor Author

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.

@sokra
Copy link
Member

sokra commented Mar 23, 2017

For id best use the user provided id.

define("nameOfModule", ...)

But this is not yet available in AMDDefineDependency. You need to pass it from AMDDefineParserPlugin into AMDDefineDependency. Just add a constructor argument.

@webpack-bot
Copy link
Contributor

@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";
Copy link
Member

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.

Copy link
Contributor Author

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))"
Copy link
Member

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);
Copy link
Member

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))"
Copy link
Member

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))"
Copy link
Member

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

@webpack-bot
Copy link
Contributor

@zastavnitskiy Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@zastavnitskiy
Copy link
Contributor Author

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?

@webpack-bot
Copy link
Contributor

The most important CI builds succeeded. Great work so far.

@webpack-bot
Copy link
Contributor

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.

@sokra
Copy link
Member

sokra commented Apr 3, 2017

ahh.. I accidentally destroyed it...

@webpack-bot
Copy link
Contributor

Hi @zastavnitskiy.

First thanks for your pull request.

Just a little hint from a friendly bot about the best practice when submitting pull request:

Don't submit pull request from your own master branch. It's recommended to create a feature branch for the PR.

You don't have to change it for this PR, just make sure to follow this hint the next time you submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants