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

[RFC] User Workspace PoC #33

Merged
merged 22 commits into from
Apr 3, 2019
Merged

[RFC] User Workspace PoC #33

merged 22 commits into from
Apr 3, 2019

Conversation

hutchgrant
Copy link
Member

@hutchgrant hutchgrant commented Apr 2, 2019

Related Issue

Resolves #28

Summary of Changes

  • ContextReplacementPlugin didn't work, it seems to work only with 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.
  • I've removed the .md copying, and the component copying. Both will now be rewritten when bundled with webpack to use the user workspace.
  • Added a custom example with styles, header and navigation components.
  • Front-matter imports now work as expected. Resolves As a user I should be able to use additional CSS from front matter #8 As a user, I would like to import my own custom assets #27
  • Removes the need for index.js component page and instead uses index.md

I built this off the webpack error dev branch. This is just proof of concept.

run:

cp ./test/fixtures/mock-app/src ./src -R
yarn serve

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.

Copy link
Member

@thescientist13 thescientist13 left a 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"
Copy link
Member

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?

Copy link
Member Author

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

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 😁

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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

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?

Copy link
Member Author

@hutchgrant hutchgrant Apr 3, 2019

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.

Copy link
Member

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(
Copy link
Member

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)

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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

🤷‍♂️

Copy link
Member

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,

Copy link
Member Author

@hutchgrant hutchgrant Apr 3, 2019

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.

Copy link
Member Author

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.

Copy link
Member

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,
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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. 👍

Copy link
Member Author

@hutchgrant hutchgrant Apr 3, 2019

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

Copy link
Member

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.

@thescientist13 thescientist13 added the RFC Proposal and changes to workflows, architecture, APIs, etc label Apr 3, 2019
@@ -0,0 +1,39 @@
:host {
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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 🙃

Copy link
Member

@thescientist13 thescientist13 left a 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.

Copy link
Member

@thescientist13 thescientist13 left a 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!! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Proposal and changes to workflows, architecture, APIs, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] User Workspace Path Mapping As a user I should be able to use additional CSS from front matter
2 participants