diff --git a/packages/mdsvex/src/index.ts b/packages/mdsvex/src/index.ts index b1e3fc37..3188167c 100644 --- a/packages/mdsvex/src/index.ts +++ b/packages/mdsvex/src/index.ts @@ -16,6 +16,7 @@ export * from './types'; import { join } from 'path'; import fs from 'fs'; +import { fileURLToPath } from 'url'; import { parse } from 'svelte/compiler'; import unified from 'unified'; import markdown from 'remark-parse'; @@ -128,11 +129,11 @@ function to_posix(_path: string): string { function resolve_layout(layout_path: string): string { try { - return to_posix(require.resolve(layout_path)); + return to_posix(fileURLToPath(import.meta.resolve(layout_path))); } catch (e) { try { const _path = join(process.cwd(), layout_path); - return to_posix(require.resolve(_path)); + return to_posix(fileURLToPath(import.meta.resolve(_path))); } catch (e) { throw new Error( `The layout path you provided couldn't be found at either ${layout_path} or ${join( diff --git a/packages/mdsvex/test/it/code_highlighting.test.ts b/packages/mdsvex/test/it/code_highlighting.test.ts index c3ad4926..cba68cc7 100644 --- a/packages/mdsvex/test/it/code_highlighting.test.ts +++ b/packages/mdsvex/test/it/code_highlighting.test.ts @@ -220,7 +220,7 @@ highlight( code: string, lang: string | undefined ): Promise { - // const shiki = require('shiki'); + // const shiki = await import('shiki'); const highlighter = await shiki.getHighlighter({ theme: 'material-theme-palenight', }); @@ -347,8 +347,8 @@ highlight( highlight( 'Should be possible to add additional highlighting grammars', async () => { - require('prismjs'); - require('prism-svelte'); + await import('prismjs'); + await import('prism-svelte'); const output = await mdsvex({ highlight: { alias: { beeboo: 'html' } }, }).markup({