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

feat(devex): Refactor Venia to be portable and importable #788

Merged
merged 8 commits into from
Jan 29, 2019

Conversation

zetlen
Copy link
Contributor

@zetlen zetlen commented Jan 28, 2019

Description

Change the build configuration and dependency graph of Venia and Peregrine so that community developers can use individual Venia components in external apps.

  • Add "partially transpiled" build targets to Venia and Peregrine, producing ES Modules that external build processes can parse, and that web packaging tools can tree-shake.
    • Add and refactor package scripts and Babel configuration
    • Add module resolver plugin to Babel so it transpiles package-relative paths
    • Add export directives to Peregrine package.json and Venia package.json to tell dependency managers where to find different transpilations and/or raw source
  • Refactor Venia components to pull their context-driven dependencies from a single aggregate file of such deps, "drivers"
    • Reroute all imports of <Query />, connect(), <Link >, <Route />, and others through the central drivers file
    • Consolidate Context Providers into an also-exported <VeniaAdapter />
    • Adjust babel config to map the drivers file to a friendly, unique dep name @magento/venia-drivers
  • Refactor Webpack plugins and other build time configuration to streamline builds and reduce custom code
    • Add doc comments

Motivation and Context

PWA Studio needs to be modular and its components need to be usable and mix-and-matchable at release time. We don't offer "inheritance" in the way of Magento themes, so we have to live up to our promise of modularity and composability. We sacrificed some of that for velocity, and it's time to get that back.

How Has This Been Tested?

Refactored unit tests and restored coverage.
Tested all changed code.
Ran all NPM scripts.

Screenshots (if appropriate):

I built an example app to show how these changes enable import of Venia components á la carte:
image

https://venia-consuming-app.now.sh/

Its source code is at https://github.com/magento-research/venia-consumer-example and a build artifact is inspectable at https://venia-consuming-app.now.sh/_src . Check it out!

Proposed Labels for Change Type/Package

feature, documentation

peregrine, pwa-buildpack, venia-concept

Checklist:

  • I have read the CONTRIBUTING document.
  • I have linked an issue to this PR.
  • I have indicated the change type and relevant package(s).
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All CI checks are green (linting, build/deploy, etc).
  • At least one core contributor has approved this PR.

@vercel
Copy link

vercel bot commented Jan 28, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

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

Nice. This is a clean set of changes; it's mostly just import swaps, as we discussed. I've left comments in a few places. Other things we've got to do:

  • Workshop the name of @magento-venia/drivers. It feels inconsistent with our other packages.
  • Remove package-lock.json. Looks like at least one is included in this diff.

backgroundImage: `url(${makeProductMediaPath(image.file)})`
backgroundImage: `url(${new ResourceUrl(
makeProductMediaPath(image.file)
).toString()})`
Copy link
Contributor

Choose a reason for hiding this comment

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

We could omit .toString() in places like this, right? It should be automatically called for expressions in template literal placeholders.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right that this would be called implicitly, but that's a little bit magic. It's also there to indicate that ResourceUrl will probably have other instance methods in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Naming that method toString is the magic part, though. 😉

packages/pwa-buildpack/.babelrc.js Show resolved Hide resolved
package.json Outdated
"bundlesize": "~0.17.1",
"chalk": "~2.4.2",
"chokidar": "~2.0.4",
"concurrently": "~4.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this being used anywhere?

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, in Venia's build script.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it's used in the Peregrine's build script, not Venia's. In either case, the dependency should be listed as a devDependency of the package itself, not here in the root.

yarn workspace @magento/peregrine add --dev --tilde concurrently

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jimbo Thanks. You shouldn't need the tilde anymore now that we've got a .yarnrc.

Speaking of which: One downside of Yarn is that it doesn't warn you on the command line if two packages have slightly different semver strings for the same dependency. I think we should strive to not let our dependencies between packages drift apart.

package.json Outdated
@@ -45,9 +46,11 @@
"devDependencies": {
"@magento/eslint-config": "~1.3.0",
"babel-eslint": "~10.0.1",
"babel-plugin-module-resolver": "^3.1.3",
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider --tilde here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoa, how'd that get in there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like Yarn doesn't respect our .npmrc, so I added a .yarnrc to set the default save prefix.

@zetlen
Copy link
Contributor Author

zetlen commented Jan 29, 2019

@jimbo Thanks for taking a look. What would you suggest instead of @magento-venia/drivers?

@zetlen zetlen force-pushed the zetlen/portable-venia-components branch from 080f285 to d4e3a9a Compare January 29, 2019 02:16
@jochienabuurs
Copy link

@zetlen
Copy link
Contributor Author

zetlen commented Jan 29, 2019

@jochienabuurs It would! The only reason I did this for Venia first is that Peregrine is about to go through some major API changes after our release. For now, large Peregrine changes are on hold, and Venia is the more useful and feature-complete of the two.

However, this PR also makes the existing Peregrine components easier to import.

@zetlen
Copy link
Contributor Author

zetlen commented Jan 29, 2019

Switched to @magento/venia-drivers based on @jimbo 's observation that @magento/ is our consistent NPM namespace. Good catch! Any other @magento-research/core-pwa-devs have input? I'd like to expedite this

sirugh
sirugh previously approved these changes Jan 29, 2019
Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

This is great! I couldn't find anything that jumped out to me, and it all makes sense. Do we have a follow-up issue for @jcalcaben to add/update docs?

And 👍 for the rename to @magento/venia-drivers.

@jimbo
Copy link
Contributor

jimbo commented Jan 29, 2019

@zetlen Thanks for responding to the feedback. Take a look through the comments again. One or two minor changes remain, then we're good.

@zetlen zetlen force-pushed the zetlen/portable-venia-components branch from 77aa493 to b5de6c7 Compare January 29, 2019 19:52
@jimbo
Copy link
Contributor

jimbo commented Jan 29, 2019

@zetlen This is approved and ready to go.

I'd like to note here that we should probably find a way to do something about the noisy warnings about module resolution. Same for the missing peer dependencies from my Yarn PR. Let's figure out what our options are.

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

Successfully merging this pull request may close these issues.

5 participants