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

[Analyser][Schema] Using Typescript as input results in TS file path in `def.declaration.module` rather than complied JS output #236

Closed xenobytezero closed 4 months ago

xenobytezero commented 4 months ago

Checklist

Expected behavior

When using TS files as the inputs to the analyzer, the output manifest for export items points at the source TS files rather than the compiled JS output.

While this is to be expected, as the plugin has no way of knowing where the compiled output would be, it means that the exports section of the manifest is essentially useless in a package where the source is not also distributed.

We are using the manifests internally as part of our system to determine which JS files to send to the client based on requested components, and this is the only parameter in the manifest that would provide this information.

We have built a plugin for the analyzer that uses the output d.ts.map to change this value on output so we are not neccessarily asking for changes to the core analyser, we more have questions.

  1. The definition of the schema describes the decleration section as

A reference to the class or other declaration that implements the custom element.

Does this imply that this should point at the compiled output rather than the source input?

  1. We are pointing at the input TS files since we strip all documentation out of the compiled version, and so lose features like CSS Part, etc. Is there some better way of doing this that would avoid this problem altogether?
thepassle commented 4 months ago

We are pointing at the input TS files since we strip all documentation out of the compiled version, and so lose features like CSS Part, etc. Is there some better way of doing this that would avoid this problem altogether?

... a plugin for the analyzer that uses the output d.ts.map to change this value on output

This describes exactly the problem :) The manifest, according to the Schema, should be pointing at the distributed code. However, we can't make assumptions on what kind of build systems of config settings every project has, so it's not feasible for the analyzer itself to make those assumptions. Instead you should indeed use a plugin that changes the paths/file extensions, like the one you built, or something like https://www.npmjs.com/package/cem-plugin-module-file-extensions

Additionally, running the analyzer on the TS output would lose a bunch of information.

xenobytezero commented 4 months ago

Thanks for the response, makes a lot of sense. Cheers!