Skip to content

Commit

Permalink
Fix @astrojs/markdown-remark bundling for non-node runtimes (#9736)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Jan 19, 2024
1 parent 8d2e5db commit 53c69dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lemon-carrots-cheer.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion packages/markdown/remark/src/load-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
Expand Down

0 comments on commit 53c69dc

Please sign in to comment.