Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve --plugins resolution algorithm #9050

Closed
alekseykulikov opened this issue May 24, 2019 · 2 comments
Closed

Improve --plugins resolution algorithm #9050

alekseykulikov opened this issue May 24, 2019 · 2 comments

Comments

@alekseykulikov
Copy link
Contributor

alekseykulikov commented May 24, 2019

First of all, thank you for adding the way to define plugins. It's a fantastic feature!

We've just published the lighthouse-plugin-field-performance and discovered a few issues with --plugins resolution algorithm.

The story:

  1. Start local development using the recipe. It's not possible to run the current folder as a plugin since Lighthouse expects lighthouse-plugin- prefix. I have added the folder lighthouse-plugin-field-performance with all the related code.
  2. Release 🎉Check the published module, but --plugins algorithm does not recognize package.json's main field and can't find the code. So we used the exact structure from the recipe and ln -s ../ node_modules/lighthouse-plugin-field-performance a symlink to use the current directory as a part of node_modules.
  3. plugin.js is a wrong name since it can only resolve index.js.

The whole story explained with commit messages:
Screenshot 2019-05-24 at 16 22 45

Conclusion
In order to make the development of the plugins more straightforward, it would be great to improve --plugins resolution algorithm by adding support for package.json's main field and checking if the current folder is a lighthouse plugin. (for example, checking the name in package.json).

@patrickhulce
Copy link
Collaborator

patrickhulce commented May 24, 2019

Thanks for filing and being such an early adopter! :D

The behavior you'd like is the current intended behavior and the lighthouse-plugin-example works locally for me using "main": "./plugin.js" so we definitely want to make sure this is the experience for plugin developers as well.

A few notes:

It's not possible to run the current folder as a plugin since Lighthouse expects lighthouse-plugin- prefix.

Right now I get this to work by doing yarn add ./path/to/lighthouse-plugin-folder at which point its put into node_modules with the proper structure.

--plugins algorithm does not recognize package.json's main field and can't find the code

Our algorithm is require.resolve so if it can be required exactly as you pass it in to --plugins then it should work with us. If that doesn't work we start falling back to some workarounds but if it's in node_modules and require.resolve works, it should work here too.

If I edit your plugin locally back to plugin.js and a main property, it works as expected when I invoke it with lighthouse https://example.com --plugins=lighthouse-plugin-field-performance. Maybe I'm missing some additional information to bump into this though?

@alekseykulikov
Copy link
Contributor Author

Thank you for a kind detailed reply! You are absolutely right!

I've just found the typo in our package.json which uses source instead of main 🤦‍♂️
https://github.com/treosh/lighthouse-plugin-field-performance/blob/master/package.json#L8

Great tip with yarn add ./path/to/local. I will update the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants