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/
227 stars 37 forks source link

Circular reference when converting to JSON schema #30

Closed p-ob closed 3 years ago

p-ob commented 3 years ago

Checklist

In writing a custom element to render custom elements manifest in a friendly format, we've encountered an issue when trying to generate the custom element manifest for this component.

I've included a txt file at the end so I could identify the cyclical items in the object that is being passed to JSON.stringify

We're using latest of lit (2.0.0-rc.2) and TypeScript 4.3.4.

Output [COLLECT PHASE]: src/ce-schema-viewer.ts [ANALYZE PHASE]: src/ce-schema-viewer.ts [MODULE LINK PHASE]: src/ce-schema-viewer.ts [PACKAGE LINK PHASE] Waiting for the debugger to disconnect... file:///C:/code/zywave/custom-element-viewer/node_modules/@custom-elements-manifest/analyzer/index.js:78 fs.writeFileSync(`${process.cwd()}${path.sep}custom-elements.json`, `${JSON.stringify(customElementsManifest, null, 2)}\n`); ^ TypeError: Converting circular structure to JSON --> starting at object with constructor 'SourceFileObject' | property 'statements' -> object with constructor 'Array' | index 0 -> object with constructor 'NodeObject' --- property 'parent' closes the circle at JSON.stringify () at run (file:///C:/code/zywave/custom-element-viewer/node_modules/@custom-elements-manifest/analyzer/index.js:78:83) at processTicksAndRejections (node:internal/process/task_queues:93:5) at async file:///C:/code/zywave/custom-element-viewer/node_modules/@custom-elements-manifest/analyzer/index.js:85:5

Expected behavior I'd expect for the custom element manifest JSON file to generate.

Reproduction Repro

custom element manifest bug.txt

thepassle commented 3 years ago

Seems to be a problem with the following comment:

Any valid path to load a JSON file that adheres to the custom element manifest schema: {@link https://github.com/webcomponents/custom-elements-manifest/}

Removing this stops it from crashing. :

 {@link https://github.com/webcomponents/custom-elements-manifest/}

Definitely a bug, not sure why this is happening exactly yet. I'll take a look and debug it.

Minimal repro:


@customElement("customelement-schema-viewer")
export class CustomElementSchemaViewerElement extends LitElement {
  /**
   * Any valid path to load a JSON file that adheres to the custom element manifest schema: {@link https://github.com/webcomponents/custom-elements-manifest/}
   */
  src;
}
thepassle commented 3 years ago

This should be fixed in https://github.com/open-wc/custom-elements-manifest/commit/03ade50e1db83c7cd6b946a7754dbb6bd6550f7f

Furthermore, I'd love to see the customelement-schema-viewer component when it's done 😄 Please do share it with us!