diff --git a/packages/slidev/node/options.ts b/packages/slidev/node/options.ts index b5529c017f..20b0e79050 100644 --- a/packages/slidev/node/options.ts +++ b/packages/slidev/node/options.ts @@ -61,13 +61,25 @@ export function getCLIRoot() { return resolve(__dirname, '..') } -export function getThemeRoots(name: string) { +export function isRelative(name: string) { + return /^\.\.?[\/\\]/.test(name) +} + +export function getThemeRoots(name: string, entry: string) { if (!name) return [] - return [ - dirname(require.resolve(`${name}/package.json`)), - ] + // TODO: handle theme inherit + if (isRelative(name)) { + return [ + resolve(dirname(entry), name), + ] + } + else { + return [ + dirname(require.resolve(`${name}/package.json`)), + ] + } } export async function resolveOptions( @@ -95,7 +107,7 @@ export async function resolveOptions( const clientRoot = getClientRoot() const cliRoot = getCLIRoot() - const themeRoots = getThemeRoots(theme) + const themeRoots = getThemeRoots(theme, entry) const roots = uniq([clientRoot, ...themeRoots, userRoot]) return { diff --git a/packages/slidev/node/themes.ts b/packages/slidev/node/themes.ts index 00c41ce800..5cddcfb836 100644 --- a/packages/slidev/node/themes.ts +++ b/packages/slidev/node/themes.ts @@ -1,5 +1,6 @@ import prompts from 'prompts' import { parseNi, run } from '@antfu/ni' +import { isRelative } from './options' const officialThemes: Record = { none: '', @@ -21,6 +22,8 @@ export function resolveThemeName(name: string) { return '' if (name.startsWith('@slidev/theme-') || name.startsWith('slidev-theme-')) return name + if (name.startsWith('.')) + return name if (officialThemes[name] !== null) return officialThemes[name] @@ -32,7 +35,7 @@ export async function promptForThemeInstallation(name: string) { if (!name) return name - if (packageExists(name)) + if (isRelative(name) || packageExists(name)) return name const { confirm } = await prompts({