From 83da63f2fd165d06cc52277567f82b2cc09e6c4e Mon Sep 17 00:00:00 2001 From: pngwn Date: Sat, 17 Aug 2024 02:08:52 +0100 Subject: [PATCH] fixes --- packages/mdsvex/src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/mdsvex/src/index.ts b/packages/mdsvex/src/index.ts index b62a851e..075ded39 100644 --- a/packages/mdsvex/src/index.ts +++ b/packages/mdsvex/src/index.ts @@ -25,6 +25,7 @@ import extract_frontmatter from 'remark-frontmatter'; import remark2rehype from 'remark-rehype'; //@ts-ignore import hast_to_html from '@starptech/prettyhtml-hast-to-html'; +import { createRequire } from 'module'; import { mdsvex_parser } from './parsers'; import { @@ -126,13 +127,15 @@ function to_posix(_path: string): string { return _path.replace(/\\/g, '/'); } +const _require = import.meta.url ? createRequire(import.meta.url) : require; + function resolve_layout(layout_path: string): string { try { - return to_posix(require.resolve(layout_path)); + return to_posix(_require.resolve(layout_path)); } catch (e) { try { const _path = join(process.cwd(), layout_path); - return to_posix(require.resolve(_path)); + return to_posix(_require.resolve(_path)); } catch (e) { throw new Error( `The layout path you provided couldn't be found at either ${layout_path} or ${join(