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: Add client/extensions as root for server. #14731

Merged
merged 1 commit into from
Jun 6, 2017

Conversation

coderkevin
Copy link
Contributor

@coderkevin coderkevin commented Jun 2, 2017

This adds client/extensions as a root path for the server build. This
allows extension-based imports like is already allowed on the client.

Where this makes a difference is especially in the reducers and
sections, which are built by webpack loaders.

This also specifies the root directory for the index.js entry point,
because it was conflicting with client/extensions/index.js

To Test:

  1. Go to an extension's state/reducer.js file and change an import from a relative path to an absolute one (e.g. client/extensions/woocommerce/state/reducer.js, change './ui/reducer' to 'woocommerce/state/ui/reducer')
  2. Run npm start. With this change, it should build. Without this change, it will not.

@matticbot
Copy link
Contributor

@matticbot matticbot added the [Size] S Small sized issue label Jun 2, 2017
@@ -93,7 +93,7 @@ const webpackConfig = {
},
resolve: {
extensions: [ '', '.json', '.js', '.jsx' ],
root: [ path.join( __dirname, 'server' ), path.join( __dirname, 'client' ), __dirname ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better put __dirname at the start of this array instead of at the end. That was my fix, changing the entry path didn't even cross my mind :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess even with the entry path, __dirname should probably still be first. I'll update it.

Copy link
Member

@ryelle ryelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works 👍 and being explicit about the entry point seems smart in general

This adds `client/extensions` as a root path for the server build. This
allows extension-based imports like is already allowed on the client.

Where this makes a difference is especially in the reducers and
sections, which are built by webpack loaders.

This also specifies the root directory for the index.js entry point,
because it was conflicting with `client/extensions/index.js`
@coderkevin
Copy link
Contributor Author

@blowery or @apeatling Can you take a look over this just to ensure it's the right thing to do and won't cause problems elsewhere? Thanks.

@coderkevin coderkevin added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Ready to Merge labels Jun 2, 2017
@blowery
Copy link
Contributor

blowery commented Jun 2, 2017

How does this work with the test framework? We don't currently use the webpack module resolution stuff there.

@coderkevin
Copy link
Contributor Author

@blowery, there's already been a fix for tests by @ryelle here in #14688

@gziolo
Copy link
Member

gziolo commented Jun 3, 2017

Shouldn't be extensions folder moved to the root folder to reflect the way it's going to be referenced in the code? Having folder and its subfolder as root might be confusing.

@coderkevin
Copy link
Contributor Author

coderkevin commented Jun 5, 2017

Shouldn't be extensions folder moved to the root folder to reflect the way it's going to be referenced in the code? Having folder and its subfolder as root might be confusing.

That's a fair point, I think. Maybe it doesn't belong under client. But I do see that as a separate conversation.

For this conversation the question is: "Should we be able to import extension files by the extension's name as a context? (e.g. woocommerce/state/action-types)"

If the answer is "yes", then we need to merge this PR.
If the answer is "no", then we need to remove code from webpack.config.js that is already doing this. (And thereby forcing extension code to write ugly imports like ../../../../../action-types.js)

Right now, we've got one foot in this and one foot out. This PR seeks to put the other foot in to match the first. It operates under the assumption that this is the way we want it because there's already code to support it. If this is not the case, we need to decide this ASAP because code is already being written with this assumption in mind.

@coderkevin
Copy link
Contributor Author

@gziolo I've added a new issue/question to address your concern: #14772

@coderkevin coderkevin added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 5, 2017
@mtias
Copy link
Member

mtias commented Jun 6, 2017

It would be good to mention this change in the Readmes, specially on the Extensions one.

@ehg
Copy link
Member

ehg commented Jun 6, 2017

That's a fair point, I think. Maybe it doesn't belong under client. But I do see that as a separate conversation.

So we really want to rename client to app, as we're already using isomorphic code. The problem will be what to rename server. So extensions should live within client for now.

I think the changes look good here. My concern would be bloating the server bundle, as we add more extensions — is this a valid concern? I haven't looked too deeply yet.

@mtias
Copy link
Member

mtias commented Jun 6, 2017

See #2319 :)

@coderkevin
Copy link
Contributor Author

My concern would be bloating the server bundle, as we add more extensions — is this a valid concern? I haven't looked too deeply yet.

Given that the server bundle is already pulling in all extension reducers, I think that would be a different and potentially larger discussion. For that point, I'd say as long as we're building extensions statically in the same bundle, it will always be an issue.

@coderkevin
Copy link
Contributor Author

@ehg and @mtias I copied your comments to #14772. Let's continue that discussion either there or on #2319

@coderkevin
Copy link
Contributor Author

@mtias I added an "Imports" section in the readme in PR #14811

@coderkevin coderkevin merged commit 7e56b99 into master Jun 6, 2017
@coderkevin coderkevin deleted the fix/webpack-extensions-root branch June 6, 2017 16:35
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.

9 participants