Skip to content

Commit

Permalink
Fix up remark plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 1, 2023
1 parent d042d55 commit cd0be45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/plugins/remark/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { timerify } from '../../util/Performance.js';
import { hasDependency, load } from '../../util/plugin.js';
import type { RemarkConfig } from './types.js';
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';

// https://github.com/remarkjs/remark/blob/main/packages/remark-cli/readme.md

type RemarkConfig = {
plugins: string[];
};

export const NAME = 'Remark';

/** @public */
Expand Down Expand Up @@ -36,7 +33,14 @@ const findRemarkDependencies: GenericPluginCallback = async (configFilePath, opt

if (!localConfig) return [];

const plugins = localConfig.plugins?.map(plugin => `remark-${plugin}`) ?? [];
const plugins =
localConfig.plugins
?.flatMap(plugin => {
if (typeof plugin === 'string') return plugin;
if (Array.isArray(plugin) && typeof plugin[0] === 'string') return plugin[0];
return [];
})
.map(plugin => (plugin.startsWith('remark-') ? plugin : `remark-${plugin}`)) ?? [];
return plugins;
};

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/remark/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type RemarkConfig = {
plugins?: (string | [string, boolean] | unknown)[];
};

0 comments on commit cd0be45

Please sign in to comment.