diff --git a/.changeset/lemon-carrots-cheer.md b/.changeset/lemon-carrots-cheer.md new file mode 100644 index 000000000000..f7ef5c228737 --- /dev/null +++ b/.changeset/lemon-carrots-cheer.md @@ -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 diff --git a/packages/markdown/remark/src/load-plugins.ts b/packages/markdown/remark/src/load-plugins.ts index 8229ddff2c1b..e1bad94a1c1a 100644 --- a/packages/markdown/remark/src/load-plugins.ts +++ b/packages/markdown/remark/src/load-plugins.ts @@ -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 { if (typeof p === 'string') { @@ -14,6 +14,7 @@ async function importPlugin(p: string | unified.Plugin): Promise } 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;