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/
230 stars 42 forks source link

pluggable module resolution? #96

Open bennypowers opened 3 years ago

bennypowers commented 3 years ago

Goal: Plug in to analyzer's module resolution so I can resolve across monorepo packages

Relevant Code: https://github.com/open-wc/custom-elements-manifest/blob/d8bb5a6f33563abffb61f4a3d749656cb8804feb/packages/analyzer/src/utils/index.js#L18-L34

Given input like:

// @apollo-elements/core/index.js
export { ApolloQueryController } from './apollo-query-controller.js';
// @apollo-elements/fast/apollo-query-behavior.js
import { ApolloQueryController } from '@apollo-elements/core/apollo-query-controller';

export class ApolloQueryBehavior extends ApolloQueryController {...}

Analyser will identify '@apollo-elements/core/apollo-query-controller'; as a bare specifier and quit. The final manifest for @apollo-elements/fast will contain the members of ApolloQueryBehavior, but not the members of its ancestor ApolloQueryController.

I'd like to write a small plugin to hook into the module resolution so that I can point local monorepo imports to their relevant source files.

Alternatives

I think I could write a large plugin to collate manifest members across packages in packageLinkPhase, but it would be nicer to just use the core's code to do that stuff rather than replicate what analyzer does anyways.

thepassle commented 3 years ago

Yeah, monorepos are currently not very well supported yet, but I think it'll take more work than just the resolveModuleOrPackageSpecifier function. That function really just only checks where an identifier comes from.

I think there will also be some changes needed in the inheritance plugin, which currently isnt very pluggable yet.

peschee commented 3 years ago

What would already also be helpful in a monorepo setup is the ability to define a path to the configuration file.

I think the CLI does not allow this. Manifest analyzer settings could be stored in a central file and (re-)used across packages.

thepassle commented 2 years ago

What would already also be helpful in a monorepo setup is the ability to define a path to the configuration file.

This was implemented in v0.5.0