0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

Fix @astrojs/markdown-remark bundling for non-node runtimes (#9736)

This commit is contained in:
Bjorn Lu 2024-01-19 22:38:33 +08:00 committed by GitHub
parent 8d2e5db096
commit 53c69dcc82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/markdown-remark": patch
---
Initializes internal `cwdUrlStr` variable lazily for performance, and workaround Rollup side-effect detection bug when building for non-Node runtimes

View file

@ -3,7 +3,7 @@ import path from 'node:path';
import { pathToFileURL } from 'node:url';
import type * as unified from 'unified';
const cwdUrlStr = pathToFileURL(path.join(process.cwd(), 'package.json')).toString();
let cwdUrlStr: string | undefined;
async function importPlugin(p: string | unified.Plugin): Promise<unified.Plugin> {
if (typeof p === 'string') {
@ -14,6 +14,7 @@ async function importPlugin(p: string | unified.Plugin): Promise<unified.Plugin>
} catch {}
// Try import from user project
cwdUrlStr ??= pathToFileURL(path.join(process.cwd(), 'package.json')).toString();
const resolved = importMetaResolve(p, cwdUrlStr);
const importResult = await import(resolved);
return importResult.default;