summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/src/load-config.ts
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2023-06-27 15:05:17 -0400
committerGravatar GitHub <noreply@github.com> 2023-06-27 15:05:17 -0400
commitfb7af551148f5ca6c4f98a4e556c8948c5690919 (patch)
tree7c65c758ead74ee129bc958279a6cf02e931cb4d /packages/integrations/markdoc/src/load-config.ts
parent8821f0504845b351247ce6c1e2ae581a71806209 (diff)
downloadastro-fb7af551148f5ca6c4f98a4e556c8948c5690919.tar.gz
astro-fb7af551148f5ca6c4f98a4e556c8948c5690919.tar.zst
astro-fb7af551148f5ca6c4f98a4e556c8948c5690919.zip
feat: New Markdoc `render` API (#7468)
* feat: URL support for markdoc tags * refactor: move to separate file * feat: support URL for markdoc nodes * feat: support `extends` with URL * chore: changeset * fix: bad AstroMarkdocConfig type * fix: experimentalAssetsConfig missing * fix: correctly merge runtime config * chore: formatting * deps: astro internal helpers * feat: component() util, new astro bundling * chore: remove now unused code * todo: missing hint * fix: import.meta.url type error * wip: test nested collection calls * feat: resolve paths from project root * refactor: move getHeadings() to runtime module * fix: broken collectHeadings * test: update fixture configs * chore: remove suggestions. Out of scope! * fix: throw outside esbuild * refactor: shuffle imports around * Revert "wip: test nested collection calls" This reverts commit 9354b3cf9222fd65b974b0cddf4e7a95ab3cd2b2. * chore: revert back to mjs config * chore: add jsdocs to stringified helpers * fix: restore updated changeset --------- Co-authored-by: bholmesdev <bholmesdev@gmail.com>
Diffstat (limited to 'packages/integrations/markdoc/src/load-config.ts')
-rw-r--r--packages/integrations/markdoc/src/load-config.ts17
1 files changed, 13 insertions, 4 deletions
diff --git a/packages/integrations/markdoc/src/load-config.ts b/packages/integrations/markdoc/src/load-config.ts
index a912051b5..207749251 100644
--- a/packages/integrations/markdoc/src/load-config.ts
+++ b/packages/integrations/markdoc/src/load-config.ts
@@ -3,6 +3,7 @@ import { build as esbuild } from 'esbuild';
import * as fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import type { AstroMarkdocConfig } from './config.js';
+import { MarkdocError } from './utils.js';
export const SUPPORTED_MARKDOC_CONFIG_FILES = [
'markdoc.config.js',
@@ -42,9 +43,8 @@ export async function loadMarkdocConfig(
}
/**
- * Forked from Vite's `bundleConfigFile` function
- * with added handling for `.astro` imports,
- * and removed unused Deno patches.
+ * Bundle config file to support `.ts` files.
+ * Simplified fork from Vite's `bundleConfigFile` function:
* @see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/config.ts#L961
*/
async function bundleConfigFile({
@@ -54,6 +54,8 @@ async function bundleConfigFile({
markdocConfigUrl: URL;
astroConfig: Pick<AstroConfig, 'root'>;
}): Promise<{ code: string; dependencies: string[] }> {
+ let markdocError: MarkdocError | undefined;
+
const result = await esbuild({
absWorkingDir: fileURLToPath(astroConfig.root),
entryPoints: [fileURLToPath(markdocConfigUrl)],
@@ -71,8 +73,14 @@ async function bundleConfigFile({
name: 'stub-astro-imports',
setup(build) {
build.onResolve({ filter: /.*\.astro$/ }, () => {
+ // Avoid throwing within esbuild.
+ // This swallows the `hint` and blows up the stacktrace.
+ markdocError = new MarkdocError({
+ message: '`.astro` files are no longer supported in the Markdoc config.',
+ hint: 'Use the `component()` utility to specify a component path instead.',
+ });
return {
- // Stub with an unused default export
+ // Stub with an unused default export.
path: 'data:text/javascript,export default true',
external: true,
};
@@ -81,6 +89,7 @@ async function bundleConfigFile({
},
],
});
+ if (markdocError) throw markdocError;
const { text } = result.outputFiles[0];
return {
code: text,