Closed chris48s closed 2 months ago
Problem:
I would like to support both plugins installed from NPM and also local plugins.
i.e: It should be possible to load both
'v8r-plugin-foobar'
'./subdir/my-local-plugin.mjs'
The problem with this is for the local ones, I'm going to need to path.resolve(process.cwd(), './subdir/my-local-plugin.mjs')
to load it from the right place. Whereas for the remote ones, I just want to use the installed name. So I can see a few options here:
For example
plugins:
- npm:v8r-plugin-foobar
- local:./subdir/my-local-plugin.mjs
This is a bit "magical", but it is probably the simplest option.
For example:
plugins:
npm:
- v8r-plugin-foobar
local:
- ./subdir/my-local-plugin.mjs
This is more explicit and less magical, but now ordering is hard (both for me and the user). Which of those two plugins should I run first? How does the user configure this?
For example:
plugins:
- ./node_modules/v8r-plugin-emoji-output/index.js
- ./subdir/my-local-plugin.mjs
This is explicit but ugly and requires the user to dig about in node_modules
to configure it correctly.
Bin off json and yaml config (breaking change), require javascript config file and have the user do the imports. For example:
import FooBarPlugin from 'v8r-plugin-foobar'
import BazQuxPlugin from './subdir/my-local-plugin.mjs'
const config = {
plugins: [
FooBarPlugin,
BazQuxPlugin,
]
}
export default config
If I didn't already have json/yaml config files, I'd probably do this if I were starting from scratch today but I think I'd rather not make the breaking change.
Conclusion: Option 1 - use a prefix.
I went with package:
and file:
rather than npm:
and local:
https://github.com/chris48s/v8r/blob/900952a9939dba81a39e42c8c91569b9d1ba52e7/src/bootstrap.js#L192-L196