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

feat(load_plugin): ignore pkg name endswith theme name #4497

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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