From a942123a26f11c50e6985b4ba6e340bd2af333d1 Mon Sep 17 00:00:00 2001 From: bluwy Date: Fri, 19 Jan 2024 21:55:48 +0800 Subject: [PATCH] Fix `@astrojs/markdown-remark` bundling for non-node runtimes --- .changeset/lemon-carrots-cheer.md | 5 +++++ packages/markdown/remark/src/load-plugins.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/lemon-carrots-cheer.md 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;