-
Notifications
You must be signed in to change notification settings - Fork 9
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
[RFC] User Workspace PoC #33
Conversation
…ix/webpack-errors
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 pretty solid!!
Not a change in this PR, but was reviewing the code in general and found this in init.js
https://github.com/ProjectEvergreen/greenwood/blob/master/packages/cli/lib/init.js#L26
/// set homepage component to user's ./src/component directory instead of def templates folder
config.homeComponent = path.join(process.cwd(), './src/components', 'index.js');
not sure if this problematic, but I wouldn't expect to have a directory like that hardcoded?
Overall, great to see some code going away, always a good sign!
package.json
Outdated
@@ -11,7 +11,8 @@ | |||
"lint": "eslint \"./packages/**/**/*.js\" \"./test/**/**/*.js\"", | |||
"build": "node ./packages/cli/index.js", | |||
"serve": "yarn clean && yarn build && cd ./public && ws", | |||
"test": "mocha test --timeout 15000" | |||
"test": "mocha test --timeout 15000", | |||
"prod-test": "webpack --config ./packages/cli/config/webpack.config.prod.js --progress --debug --display verbose" |
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.
what's the distinction between this and running yarn build
, since that is also running webpack with this same configuration, right?
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 was for a quick test, it can be removed.
const fs = require('fs-extra'); | ||
const webpack = require('webpack'); | ||
|
||
const userLand = path.join(process.cwd(), 'src'); |
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.
maybe we should standardize our terminologies here.
I think to refer to the user's repository / code, we could call it their workspace? I think userLand is a little too on the 👃 , so to speak 😁
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, maybe we should make Greenwood's default configuration a file as well, so it can be shared across webpack and nodejs?
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.
Unifying the config, maybe a separate PR and issue?
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.
good call, we have one here #11
// TODO webpack errors don't break this task | ||
if (err) { | ||
console.log(err); | ||
return webpack(webpackConfig, (err, stats) => { |
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'm pretty sure this change shouldn't be in this PR, right?
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's from the webpack error fix in #23. This PR was a continuation of that branch accidentally.
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 guess too late to rollback at this point since this PR is pretty much ready, but will again just appeal to please, please be mindful about conflating unrelated issues / changes, in particular to really intensive PRs like this where anything else is just a distraction, and makes tracking history harder. ✌️
@@ -61,6 +81,26 @@ module.exports = { | |||
}, | |||
|
|||
plugins: [ | |||
new webpack.NormalModuleReplacementPlugin( |
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.
Interesting, I think that makes sense about ContextReplacementPlugin.
So maybe for this, instead of hardcoding, we "scan" the user's workspace and read all the top level directories, and then use a forEach
on all these paths?
This way we won't have to know all the directories ahead time, we literally just provide a mapping mechanism, to essentially create a unified workspace experience. (kind of like mounting volumes with Docker)
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 we do that in a separate PR?
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 want to avoid hardcoding though.
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.
That's not a simple fix and is a new feature
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.
that was the goal though?
With this, we can tell webpack where to look when resolving paths so that Greendwood can dynamically look up and link to a user's entire project without needing to configure everything other than
🤷♂️
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 say it's the same feature, just refactored to be dyanmic instead of hardcoded? I'll see if i can give it a try, I think it's worth the effort given the payoff, IMO,
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.
True, but for now, it's best to just make sure a few predetermined directories work(which they now do). You'll have to walk the src directory(if it exists), then create an array of plugins(one for each folder), with a unique regex and replacement. You'll have to do some string manipulation, test it all, etc.
A flexible user workspace through import or @import
components/
assets/
styles/
whatever/!
Is simpler to start with.
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 mean the function that does that will be useful, if no src directory exists, you'll want a specific replacement for styles for the default template.
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.
whatever/!
that was meant imply it was supposed to be dynamic but no problem, I think I'm pretty close to implementing the needed change.
@@ -10,7 +10,7 @@ | |||
"rules": { | |||
"comma-dangle": [2,"never"], | |||
"no-cond-assign": 2, | |||
"no-console": 1, | |||
"no-console": 0, |
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.
yeah, my plan to handle this was to implement a logging package or something in #15
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.
for now its just throwing unnecessary warnings so I disabled it.
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.
understood, but there's already an issue for handling that and this still leaves all those // eslint disable line
comments.
just in general, let's try and keep PRs as focused as possible to the immediate task at hand, in particular if there is an existing and overlapping issue open. 👍
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.
right but even with that PR implemented, we will still have to deal with the lint issue(which isn't mentioned in that issue).
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.
well, not debate it or anything, but in the issue I proposed we add a logging library, which would then be a dependency in our packages, e.g.
const LOG_LEVEL = isDebug ? 0 : 2;
const logger = require('logger')(LOG_LEVEL);
and not a console
anymore and allow us to programmatically set logging levels, etc.
anyway, the main takeaway here is just avoid cross pollinating is all, please.
@@ -0,0 +1,39 @@ | |||
:host { |
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.
does CSS actually work in our build right now? or are these tests here just for testing the directory mapping with webpack?
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.
css does work, only in userworkspace
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.
neat! looks we should start building a website soon with this or something 🙃
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.
refactored webpack here #33 . I think we can merge that, and then this should mostly be ready to merge as well.
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.
Awesome stuff, excited to merger this in, didn't think we would solve it so fast!! 👏
Related Issue
Resolves #28
Summary of Changes
require('some/library')
and not with imports? I couldn't get it to change paths. However, NormalModuleReplacementPlugin does work, it will still likely require some modification, but this is a great start with userland..md
copying, and the component copying. Both will now be rewritten when bundled with webpack to use the user workspace.I built this off the webpack error dev branch. This is just proof of concept.
run:
go to http://localhost:8000/ to see
go to http://localhost:8000/hello to see
Problems
I'm aware of a problem with the default template styles replacement. Since we're not importing from a styles directory, the regex will not pick it up and because we're not copying assets/styles, the css file therefore cannot be imported in the default template we supply.
I'm also aware that some of these import replacements may break with the recursive walkdirectory for pages.