open-wc / custom-elements-manifest

Custom Elements Manifest is a file format that describes custom elements in your project.
https://custom-elements-manifest.open-wc.org/
225 stars 37 forks source link

Fails to get dependency information if using an import alias #214

Open matteematt opened 1 year ago

matteematt commented 1 year ago

Checklist

Apologies because this is quite compliated

Abstract: cem analyzer does not correctly find the package dependency of an import if it is aliased upon import

Basic Example

Lib code:

export class Avatar extends FoundationElement {
   @attr title = 'default title';
}

This will produce the following in the cem manifest:

...
            {
              "name": "title",
              "type": {
                "text": "string"
              },
              "fieldName": "title"
            },
...

App code:

import {Avatar as BaseAvatar } from 'test-lib';

export class Avatar extends BaseAvatar {
   @attr avatar = ':)';
}

In this case we expect the manifest from the library to be picked up and add the title attribute with an inherited from. But it seems to not pick it up. However if we change the app code to:

import {Avatar } from 'test-lib';

export class AvatarTwo extends Avatar {
   @attr avatar = ':)';
}

This does work as a workaround.

Real Example

  1. I have a fork of microsoft fast here in which I am setitng up the manifest for a deprecated library.
  2. it contains a base class called button which is generated in a manifest (exporting attributes such as autofocus
  3. there is a seperate package that also defines a button class, which extends the button from the above link and uses a type alias to avoid a name clash
  4. The output manifest only contains the attribute for the button subclass
  5. I then do a commit which removes the type alias import
  6. Observe that the attributes are now pulled in from the superclass in the manifest (You will need to expand the large manifest file to see my linked line, github collapses the manifest by default)

Notes

I can't recreate this in the playground as this is an issue with the interaction between the analyzer and a package that contains a manifest. Using an import alias in the same package is no issue, and therefore I cannot recreate it in the playground

matteematt commented 11 months ago

Hi. It has been a few month since I raised this, any movement or investigation? Cheers

matteematt commented 8 months ago

I ended up writing a plugin that lets you work around for this https://www.npmjs.com/package/@genesiscommunitysuccess/analyzer-import-alias-plugin