summaryrefslogtreecommitdiff
path: root/packages/markdown/remark
diff options
context:
space:
mode:
Diffstat (limited to 'packages/markdown/remark')
-rw-r--r--packages/markdown/remark/package.json2
-rw-r--r--packages/markdown/remark/src/load-plugins.ts15
2 files changed, 16 insertions, 1 deletions
diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json
index 6178bf014..36b702d93 100644
--- a/packages/markdown/remark/package.json
+++ b/packages/markdown/remark/package.json
@@ -30,6 +30,8 @@
"acorn-jsx": "^5.3.2",
"github-slugger": "^1.4.0",
"hast-util-to-html": "^8.0.3",
+ "import-meta-resolve": "^2.1.0",
+ "mdast-util-from-markdown": "^1.2.0",
"mdast-util-mdx-expression": "^1.2.1",
"mdast-util-mdx-jsx": "^1.2.0",
"micromark-extension-mdx-expression": "^1.0.3",
diff --git a/packages/markdown/remark/src/load-plugins.ts b/packages/markdown/remark/src/load-plugins.ts
index c64d13543..37798db14 100644
--- a/packages/markdown/remark/src/load-plugins.ts
+++ b/packages/markdown/remark/src/load-plugins.ts
@@ -1,8 +1,21 @@
+import path from 'path';
+import { pathToFileURL } from 'url';
import * as unified from 'unified';
+import { resolve as importMetaResolve } from 'import-meta-resolve';
+
+const cwdUrlStr = pathToFileURL(path.join(process.cwd(), 'package.json')).toString();
async function importPlugin(p: string | unified.Plugin): Promise<unified.Plugin> {
if (typeof p === 'string') {
- const importResult = await import(p);
+ // Try import from this package first
+ try {
+ const importResult = await import(p);
+ return importResult.default;
+ } catch {}
+
+ // Try import from user project
+ const resolved = await importMetaResolve(p, cwdUrlStr);
+ const importResult = await import(resolved);
return importResult.default;
}