Skip to content

Commit

Permalink
feat(load_plugin): ignore pkg name endswith theme name (#4497)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 25, 2020
1 parent 39da369 commit 08c8b23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/hexo/load_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ function loadModuleList(ctx) {
return deps.concat(devDeps);
});
}).filter(name => {
// Ignore plugin whose name is "hexo-theme-[ctx.config.theme]"
if (name === `hexo-theme-${customThemeName}`) return false;
// Ignore plugin whose name endswith "hexo-theme-[ctx.config.theme]"
if (name.endsWith(`hexo-theme-${customThemeName}`)) return false;

// Ignore plugins whose name is not started with "hexo-"
if (!/^hexo-|^@[^/]+\/hexo-/.test(name)) return false;

// Ignore typescript definition file that is started with "@types/"
if (/^@types\//.test(name)) return false;
if (name.startsWith('@types/')) return false;

// Make sure the plugin exists
const path = ctx.resolvePlugin(name);
Expand Down
18 changes: 18 additions & 0 deletions test/scripts/hexo/load_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ describe('Load plugins', () => {
return fs.unlink(path);
});

it('ignore plugin whose name endswith "hexo-theme-[hexo.config.theme]"', async () => {
hexo.config.theme = 'test_theme';

const script = 'hexo._script_test = true';
const name = '@hexojs/hexo-theme-test_theme';
const path = join(hexo.plugin_dir, name, 'index.js');

await Promise.all([
createPackageFile(name),
fs.writeFile(path, script)
]);
await loadPlugins(hexo);

should.not.exist(hexo._script_test);
delete hexo.config.theme;
return fs.unlink(path);
});

it('ignore plugins whose name is not started with "hexo-"', async () => {
const script = 'hexo._script_test = true';
const name = 'another-plugin';
Expand Down

0 comments on commit 08c8b23

Please sign in to comment.