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/
234 stars 43 forks source link

Consider custom element manifest files of imported packages #130

Open daKmoR opened 3 years ago

daKmoR commented 3 years ago

my deps

node_modules/base/MyBase.js
node_modules/base/package.json
node_modules/base/custom-elements-manifst.json

👉 node_modules/base/MyBase.js

import { LitElement } from 'lit-element';

export class MyElement extends LitElement {
  static get properties() {
    return {
      awesome: { type: Boolean }
    }
  }

  constructor() {
    super();
    this.awesome = true;
  }
}

👉 node_modules/base/custom-elements-manifst.json

// ...
          "members": [
            {
              "kind": "field",
              "name": "awesome",
              "type": {
                "text": "boolean"
              },
              "default": "true",
              "privacy": "public",
              "attribute": "awesome"
            }
          ],
// ...

https://custom-elements-manifest.netlify.app/?source=CmltcG9ydCB7IExpdEVsZW1lbnQgfSBmcm9tICdsaXQtZWxlbWVudCc7CgpleHBvcnQgY2xhc3MgTXlCYXNlIGV4dGVuZHMgTGl0RWxlbWVudCB7CiAgc3RhdGljIGdldCBwcm9wZXJ0aWVzKCkgewogICAgcmV0dXJuIHsKICAgICAgYXdlc29tZTogeyB0eXBlOiBCb29sZWFuIH0KICAgIH0KICB9CgogIGNvbnN0cnVjdG9yKCkgewogICAgc3VwZXIoKTsKICAgIHRoaXMuYXdlc29tZSA9IHRydWU7CiAgfQp9Cg%3D%3D&library=litelement

my element

class MyEl extends MyBase {
  static get properties() {
    return {
      rainbow: { type: Boolean }
    }
  }

  constructor() {
     super();
     this.rainbow = true;
  }
}

Actual behavior

Generated CEM or docs for MyEl lists only rainbow as a member but not awesome.

// ...
          "members": [
            {
              "kind": "field",
              "name": "rainbow",
              "type": {
                "text": "boolean"
              },
              "default": "true",
              "privacy": "public",
              "attribute": "rainbow"
            }
          ],
// ...

Expected behavior

Generated CEM or docs for MyEl should list rainbow and awesome as a member.

// ...
          "members": [
            {
              "kind": "field",
              "name": "rainbow",
              "type": {
                "text": "boolean"
              },
              "default": "true",
              "privacy": "public",
              "attribute": "rainbow"
            },
            {
              "kind": "field",
              "name": "awesome",
              "type": {
                "text": "boolean"
              },
              "default": "true",
              "privacy": "public",
              "attribute": "awesome",
              "inheritedFrom": {
                "name": "MyBase",
                "module": "base/MyBase.js"
              }
            }
          ],
// ...
thepassle commented 3 years ago

This should be fixed when this pr lands https://github.com/open-wc/custom-elements-manifest/pull/129

daKmoR commented 3 years ago

I think #129 will mean it analyzes the code in my node_modules?

but what I mean is that it reads the costume-elements-manifest.json in node_modules and not the code. (e.g. do not analyze the code again)

thepassle commented 3 years ago

Ah yes I suppose we can try to see if the dependency doesnt already have a custom-elements-manifest.json before we try to analyze. That might be hard because of the whole export map situation, but we can always analyze as a fallback. I'll take a look.