SalesforceCommerceCloud / pwa-kit

React-based JavaScript frontend framework to create a progressive web app (PWA) storefront for Salesforce B2C Commerce.
https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pwa-kit-overview.html
BSD 3-Clause "New" or "Revised" License
276 stars 126 forks source link

[PWA-Kit Extensibility] Implement wild-card module resolution logic @W-15932154 #1826

Closed bendvc closed 3 weeks ago

bendvc commented 1 month ago

Description

The PWA-Kit platform uses babel-node to run our PWA-Kit applications (think, typescript-minimal and retail-react-app). Because of this, we have 2 distinct places in our code where it's required that we modify the module resolution algorithm to support extensibility overrides. The first place is via a webpack plugin and the other is the babel-node plugin.

The logic used by these plugins is for the most part the same, so it's important that we don't repeat ourselves and pull that logic out into a set of reusable utilities.

So, in this PR we create those utilities to be used by a webpack and a babel plugin in order to implement wildcard import statement syntax. What this syntax allows us to do is, import a module from a known list of packages where the modules being imported is known to exist in at least one of the packages.

This is the basis of "multi-extensibility" and those "known list" of packages are in fact the list of extensions.

Types of Changes

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

How to Test-Drive This PR

Checklists

General

Accessibility Compliance

You must check off all items in one of the follow two lists:

or...

Localization

bendvc commented 3 weeks ago

shall we create a feature branch for multi extensibility? this PR doesn't provide much value until we have the webpack/babel plugins

I was hoping someone was going to ask me about this so we can open up a dialog on what we want to do. I'm thinking this is the perfect time to create an next branch. This pr would merge into that branch which represents the next major version of the sdk pacakges in this lib.

Thoughts?

kevinxh commented 3 weeks ago

shall we create a feature branch for multi extensibility? this PR doesn't provide much value until we have the webpack/babel plugins

I was hoping someone was going to ask me about this so we can open up a dialog on what we want to do. I'm thinking this is the perfect time to create an next branch. This pr would merge into that branch which represents the next major version of the sdk pacakges in this lib.

Thoughts?

I think we could either do what you said, starting the next major version. Or try to ship this as a non-breaking minor version. I also am not sure how much effort would it take to make it a non-breaking change? 🤔

bendvc commented 3 weeks ago

shall we create a feature branch for multi extensibility? this PR doesn't provide much value until we have the webpack/babel plugins

I was hoping someone was going to ask me about this so we can open up a dialog on what we want to do. I'm thinking this is the perfect time to create an next branch. This pr would merge into that branch which represents the next major version of the sdk pacakges in this lib. Thoughts?

I think we could either do what you said, starting the next major version. Or try to ship this as a non-breaking minor version. I also am not sure how much effort would it take to make it a non-breaking change? 🤔

This is going to be a breaking change solely based on how we are configuring extensibility.. I suppose we can support both ways.. but I don't care for the additional complexity.

For now I've created a feature branch that has the SDKs bumped to 4.0.0-dev. Once we have the "next" branch created, I can rebase this PR to merge into "next"