load-config.ts — astro Source File
Architecture documentation for load-config.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR bed767c0_8e7f_8ca6_d8c0_dcaef61ca053["load-config.ts"] e0eab863_6cf9_cc6e_219c_2c937d09a9cd["./config.js"] bed767c0_8e7f_8ca6_d8c0_dcaef61ca053 --> e0eab863_6cf9_cc6e_219c_2c937d09a9cd 3349dcf7_c535_1ef1_37f1_278fa9b42d6d["./utils.js"] bed767c0_8e7f_8ca6_d8c0_dcaef61ca053 --> 3349dcf7_c535_1ef1_37f1_278fa9b42d6d e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] bed767c0_8e7f_8ca6_d8c0_dcaef61ca053 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"] bed767c0_8e7f_8ca6_d8c0_dcaef61ca053 --> d9a92db9_c95e_9165_13ac_24b3d859d946 f16d8c76_2866_6150_bd14_0347b59abfe9["astro"] bed767c0_8e7f_8ca6_d8c0_dcaef61ca053 --> f16d8c76_2866_6150_bd14_0347b59abfe9 972c6fe0_4a8d_d55e_c1b0_a57c5bf4ed60["esbuild"] bed767c0_8e7f_8ca6_d8c0_dcaef61ca053 --> 972c6fe0_4a8d_d55e_c1b0_a57c5bf4ed60 style bed767c0_8e7f_8ca6_d8c0_dcaef61ca053 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import * as fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import type { AstroConfig } from 'astro';
import { build as esbuild } from 'esbuild';
import type { AstroMarkdocConfig } from './config.js';
import { MarkdocError } from './utils.js';
export const SUPPORTED_MARKDOC_CONFIG_FILES = [
'markdoc.config.js',
'markdoc.config.mjs',
'markdoc.config.mts',
'markdoc.config.ts',
];
export type MarkdocConfigResult = {
config: AstroMarkdocConfig;
fileUrl: URL;
};
export async function loadMarkdocConfig(
astroConfig: Pick<AstroConfig, 'root'>,
): Promise<MarkdocConfigResult | undefined> {
let markdocConfigUrl: URL | undefined;
for (const filename of SUPPORTED_MARKDOC_CONFIG_FILES) {
const filePath = new URL(filename, astroConfig.root);
if (!fs.existsSync(filePath)) continue;
markdocConfigUrl = filePath;
break;
}
if (!markdocConfigUrl) return;
const { code } = await bundleConfigFile({
markdocConfigUrl,
astroConfig,
});
const config: AstroMarkdocConfig = await loadConfigFromBundledFile(astroConfig.root, code);
return {
config,
fileUrl: markdocConfigUrl,
};
}
/**
* 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({
markdocConfigUrl,
astroConfig,
}: {
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)],
outfile: 'out.js',
write: false,
target: ['node16'],
platform: 'node',
packages: 'external',
bundle: true,
format: 'esm',
sourcemap: 'inline',
metafile: true,
plugins: [
{
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. See https://docs.astro.build/en/guides/integrations-guide/markdoc/',
});
return {
// Stub with an unused default export.
path: 'data:text/javascript,export default true',
external: true,
};
});
},
},
],
});
if (markdocError) throw markdocError;
const { text } = result.outputFiles[0];
return {
code: text,
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : [],
};
}
/**
* Forked from Vite config loader, replacing CJS-based path concat
* with ESM only
* @see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/config.ts#L1074
*/
async function loadConfigFromBundledFile(root: URL, code: string): Promise<AstroMarkdocConfig> {
// Write it to disk, load it with native Node ESM, then delete the file.
const tmpFileUrl = new URL(`markdoc.config.timestamp-${Date.now()}.mjs`, root);
fs.writeFileSync(tmpFileUrl, code);
try {
return (await import(tmpFileUrl.pathname)).default;
} finally {
try {
fs.unlinkSync(tmpFileUrl);
} catch {
// already removed if this function is called twice simultaneously
}
}
}
Domain
Subdomains
Types
Dependencies
- ./config.js
- ./utils.js
- astro
- esbuild
- node:fs
- node:url
Source
Frequently Asked Questions
What does load-config.ts do?
load-config.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in load-config.ts?
load-config.ts defines 3 function(s): bundleConfigFile, loadConfigFromBundledFile, loadMarkdocConfig.
What does load-config.ts depend on?
load-config.ts imports 6 module(s): ./config.js, ./utils.js, astro, esbuild, node:fs, node:url.
Where is load-config.ts in the architecture?
load-config.ts is located at packages/integrations/markdoc/src/load-config.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/markdoc/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free