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
285 stars 138 forks source link

[App Extensibility ⚙️] Solve IDE wildcard import resolution (@W-16825282@) #2097

Closed adamraya closed 3 weeks ago

adamraya commented 1 month ago

Description

Problem

The IDEs are unable to resolve the overridable imports identified using a wildcard correctly and provide the proper navigation and IntelliSense.

This results in errors with red squiggly lines below the wildcard import syntax.

Example

import withRedBorder from '*/components/with-red-border'

Error

TS2307: Cannot find module '*/components/with-red-border'.

Solution

The PR implements two changes:

  1. Replace the wildcard import symbol * with the dollar override! symbol to comply with the ts compilerOptions.path pattern limitation of using at most one '*' character. See ts config wildcard substitutions docs.
  2. Add a tsconfig.json file with the compilerOption.path mapping the paths starting with override!/* to src/*.
{
    "compilerOptions": {
        ...
        "paths": {
            "override!/*": [
                "src/*",
            ]
        },
...

Using a different symbol to identify overridable imports solves the error caused by the wildcard symbol.

npx tsc --build
tsconfig.json:12:13 - error TS5061: Pattern '*/*' can have at most one '*' character.

12             "*/*": [
               ~~~~~

Found 1 error.

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

adamraya commented 4 weeks ago

What's the plan for the js/jsx files?

Similarly, we can add a jsconfig.json file.

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "override!/*": ["src/*"]
    }
  }
}

I assumed we only wanted to use ts for the extensions.