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

Allow local plugins #1670

Closed
mshick opened this issue Dec 22, 2015 · 6 comments · Fixed by #4475
Closed

Allow local plugins #1670

mshick opened this issue Dec 22, 2015 · 6 comments · Fixed by #4475

Comments

@mshick
Copy link

mshick commented Dec 22, 2015

I would find it very useful to be able to make small, local plugins, not tied to my package.json in any way. This would be similar to jekyll with supports custom local code in a _plugins directory, as well as plugins loaded from gem.

Ideal scenario:

  • a plugins array is standardized in _config.yml
    • e.g.
plugins:
  - my-plugin1
  - my-plugin2
  • a plugins directory is standardized as the place to put your local plugin code -- obeying all conventions of a standard plugin
  • plugins defined in the array are loaded first from the local plugins dir, secondarily by requireing the plugin name -- this allows someone to override an npm plugin for easier development (maybe if they are developing it actively, and don't want to involve npm)

Some of this duplicated hexojs/hexo-cli#174 but I think that is a much bigger request.

I would also find it preferable if, once standardized, a config.yml plugins array became the only way of loading plugins. The current package.json parsing approach seems very clever and "magical", and not in keeping with the practice of many other node apps I've encountered.

A PR to follow, this is actually pretty easy to implement, but I want to gauge interest first.

@tommy351 tommy351 added this to the 3.2 milestone Dec 27, 2015
@amobiz
Copy link
Contributor

amobiz commented Jan 7, 2016

+1 for plugins in _config.yml

Note that hexo can load simple scripts already:
https://hexo.io/docs/plugins.html#Script

Implementation tip for load local plugin:
https://github.com/aseemk/requireDir

@amobiz
Copy link
Contributor

amobiz commented Jan 7, 2016

Also, I don't like the way hexo using vm.runInThisContext(script, path) to load plugins.
Is there any plan replacing it with standard CommonJS module (and fall back to old one)?

Added a poc:
https://github.com/amobiz/hexo-plugin-loader-poc

@mshick
Copy link
Author

mshick commented Jan 8, 2016

There are also several hexo plugins that in turn load modules (hexo-renderer-markdown-it, for example). They use the native node require system effectively and have plugin lists done in _config.yml.

@tommy351
Copy link
Member

tommy351 commented Jan 9, 2016

The reason Hexo uses vm.runInThisContext is to prevent injecting hexo to global namespace.

@amobiz
Copy link
Contributor

amobiz commented Jan 9, 2016

@tommy351
Thank you for great hexo and quick reply.

I know what vm.runInThisContext trying to achieve, and I believe it is for backward compatible reasons. But that's because plugins are not in standard CommonJS format. If they do, they can export a function that take hexo instance like this:

module.exports = function (hexo) {
    hexo.extend.renderer.register('commonjs_plugin');
};

Then there is no reason injecting hexo to global namespace.

Back to backward compatible issue, the loader can fall back to old behavior when plugin is not in CommonJS format, and that's what my poc trying to prove.

@stevenjoezhang
Copy link
Member

stevenjoezhang commented Aug 11, 2020

plugins option in _config.yml is misleading and is used incorrectly by many users:
#4202
#4382
#2989
#1442 (comment)
#2973
#1848

You either DO NOT define plugins and let Hexo search for them or define ALL the plugins you used.

Originally posted by @leesei in #1848 (comment)

CC @hexojs/core

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

Successfully merging a pull request may close this issue.

4 participants