@hanzo/docs-mdx 14.2.4 → 14.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-DP5xMGSd.js → build-GdAvxpd7.js} +2 -2
- package/dist/{build-DP5xMGSd.js.map → build-GdAvxpd7.js.map} +1 -1
- package/dist/{build-mdx-CNzC71ea.js → build-mdx-COY0QD1z.js} +2 -2
- package/dist/{build-mdx-CNzC71ea.js.map → build-mdx-COY0QD1z.js.map} +1 -1
- package/dist/build-mdx-hB1gzgHy.js +5 -0
- package/dist/bun/index.js +8 -8
- package/dist/{codegen-DleOVLNr.js → codegen-Dd9ILNOr.js} +1 -1
- package/dist/{codegen-DleOVLNr.js.map → codegen-Dd9ILNOr.js.map} +1 -1
- package/dist/config/index.js +3 -3
- package/dist/{adapter-Jwap8N8Y.js → config-DSrG5Dfc.js} +35 -35
- package/dist/{adapter-Jwap8N8Y.js.map → config-DSrG5Dfc.js.map} +1 -1
- package/dist/{core-BJualF84.js → core-DOav5JBx.js} +3 -3
- package/dist/{core-BJualF84.js.map → core-DOav5JBx.js.map} +1 -1
- package/dist/{fuma-matter-CHgJa_-B.js → fuma-matter-DL-PfQJ7.js} +1 -1
- package/dist/{fuma-matter-CHgJa_-B.js.map → fuma-matter-DL-PfQJ7.js.map} +1 -1
- package/dist/{index-file-Bil6OoJJ.js → index-file-B3LmDGdu.js} +4 -4
- package/dist/{index-file-Bil6OoJJ.js.map → index-file-B3LmDGdu.js.map} +1 -1
- package/dist/load-from-file-BoO9y-n6.js +5 -0
- package/dist/{load-from-file-CSjo1gN1.js → load-from-file-dsGIDpOc.js} +2 -2
- package/dist/{load-from-file-CSjo1gN1.js.map → load-from-file-dsGIDpOc.js.map} +1 -1
- package/dist/{loaders-BVwYfelL.js → loaders-Mp-ZCdLT.js} +1 -1
- package/dist/{loaders-BVwYfelL.js.map → loaders-Mp-ZCdLT.js.map} +1 -1
- package/dist/{mdx-QPp-1kXt.js → mdx-CJaKR3FR.js} +5 -5
- package/dist/{mdx-QPp-1kXt.js.map → mdx-CJaKR3FR.js.map} +1 -1
- package/dist/{meta-DyieTM4Z.js → meta-CKrL1Sl9.js} +3 -3
- package/dist/{meta-DyieTM4Z.js.map → meta-CKrL1Sl9.js.map} +1 -1
- package/dist/next/index.js +8 -8
- package/dist/node/loader.js +6 -6
- package/dist/plugins/index-file.js +3 -3
- package/dist/plugins/json-schema.js +1 -1
- package/dist/plugins/last-modified.js +1 -1
- package/dist/{preset-DtKimtBh.js → preset-D_quDsKp.js} +1 -1
- package/dist/{preset-DtKimtBh.js.map → preset-D_quDsKp.js.map} +1 -1
- package/dist/{remark-include-DirFkbLw.js → remark-include-BbnDmUoc.js} +4 -4
- package/dist/{remark-include-DirFkbLw.js.map → remark-include-BbnDmUoc.js.map} +1 -1
- package/dist/runtime/dynamic.js +7 -7
- package/dist/vite/index.js +10 -10
- package/dist/webpack/mdx.js +6 -6
- package/dist/webpack/meta.js +5 -5
- package/dist/{webpack-DKHWtYK4.js → webpack-BHjsXgTD.js} +2 -2
- package/dist/{webpack-DKHWtYK4.js.map → webpack-BHjsXgTD.js.map} +1 -1
- package/package.json +7 -7
- package/dist/build-mdx-B0MQbgVM.js +0 -5
- package/dist/load-from-file-BD2SdoUT.js +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as applyMdxPreset } from "./preset-
|
|
1
|
+
import { t as applyMdxPreset } from "./preset-D_quDsKp.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import picomatch from "picomatch";
|
|
4
4
|
|
|
@@ -97,4 +97,4 @@ function buildConfig(config, cwd = process.cwd()) {
|
|
|
97
97
|
|
|
98
98
|
//#endregion
|
|
99
99
|
export { buildConfig as t };
|
|
100
|
-
//# sourceMappingURL=build-
|
|
100
|
+
//# sourceMappingURL=build-GdAvxpd7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-
|
|
1
|
+
{"version":3,"file":"build-GdAvxpd7.js","names":["matcher: picomatch.Matcher","loaded: GlobalConfig","result: ProcessorOptions | Promise<ProcessorOptions>"],"sources":["../src/config/build.ts"],"sourcesContent":["import type { ProcessorOptions } from '@mdx-js/mdx';\nimport type {\n AnyCollection,\n DocCollection,\n DocsCollection,\n GlobalConfig,\n MetaCollection,\n} from '@/config/define';\nimport picomatch from 'picomatch';\nimport { applyMdxPreset } from '@/config/preset';\nimport path from 'node:path';\n\nexport type BuildEnvironment = 'bundler' | 'runtime';\n\nexport interface LoadedConfig {\n collections: Map<string, CollectionItem>;\n global: GlobalConfig;\n getMDXOptions(\n collection?: DocCollectionItem,\n environment?: BuildEnvironment,\n ): ProcessorOptions | Promise<ProcessorOptions>;\n workspaces: Record<\n string,\n {\n dir: string;\n config: LoadedConfig;\n }\n >;\n}\n\nexport type CollectionItem = MetaCollectionItem | DocCollectionItem | DocsCollectionItem;\n\ninterface PrimitiveCollectionItem {\n name: string;\n cwd: string;\n /**\n * content directory (absolute)\n */\n dir: string;\n hasFile: (filePath: string) => boolean;\n isFileSupported: (filePath: string) => boolean;\n patterns: string[];\n}\n\nexport type MetaCollectionItem = PrimitiveCollectionItem & Omit<MetaCollection, 'files' | 'dir'>;\nexport type DocCollectionItem = PrimitiveCollectionItem & Omit<DocCollection, 'files' | 'dir'>;\n\nexport interface DocsCollectionItem\n extends Omit<DocsCollection, 'dir' | 'meta' | 'docs'>, Omit<PrimitiveCollectionItem, 'patterns'> {\n meta: MetaCollectionItem;\n docs: DocCollectionItem;\n}\n\nconst SupportedFormats = {\n doc: ['mdx', 'md'],\n meta: ['json', 'yaml'],\n};\n\nexport function buildCollection(\n name: string,\n collection: AnyCollection,\n cwd: string,\n): CollectionItem {\n if (collection.type === 'docs') {\n return {\n ...collection,\n type: 'docs',\n get dir() {\n return this.docs.dir;\n },\n name,\n meta: buildCollection(name, collection.meta, cwd) as MetaCollectionItem,\n docs: buildCollection(name, collection.docs, cwd) as DocCollectionItem,\n hasFile(filePath) {\n return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);\n },\n isFileSupported(filePath) {\n return this.docs.isFileSupported(filePath) || this.meta.isFileSupported(filePath);\n },\n cwd,\n };\n }\n\n return {\n ...collection,\n ...buildPrimitiveCollection(name, collection, cwd),\n };\n}\n\nfunction buildPrimitiveCollection(\n name: string,\n config: DocCollection | MetaCollection,\n cwd: string,\n): PrimitiveCollectionItem {\n const supportedFormats = SupportedFormats[config.type];\n const patterns = config.files ?? [`**/*.{${supportedFormats.join(',')}}`];\n let matcher: picomatch.Matcher;\n\n return {\n dir: path.resolve(cwd, config.dir),\n cwd,\n name,\n patterns,\n isFileSupported(filePath) {\n return supportedFormats.some((format) => filePath.endsWith(`.${format}`));\n },\n hasFile(filePath) {\n if (!this.isFileSupported(filePath)) return false;\n\n const relativePath = path.relative(this.dir, filePath);\n if (relativePath.startsWith(`..${path.sep}`)) return false;\n\n return (matcher ??= picomatch(patterns))(relativePath);\n },\n };\n}\n\nexport function buildConfig(config: Record<string, unknown>, cwd = process.cwd()): LoadedConfig {\n const collections = new Map<string, CollectionItem>();\n const loaded: GlobalConfig = {};\n\n for (const [k, v] of Object.entries(config)) {\n if (!v) {\n continue;\n }\n\n if (typeof v === 'object' && 'type' in v) {\n if (v.type === 'docs' || v.type === 'doc' || v.type === 'meta') {\n collections.set(k, buildCollection(k, v as AnyCollection, cwd));\n continue;\n }\n }\n\n if (k === 'default' && v) {\n Object.assign(loaded, v);\n continue;\n }\n\n throw new Error(\n `Unknown export \"${k}\", you can only export collections from source configuration file.`,\n );\n }\n\n const mdxOptionsCache = new Map<string, ProcessorOptions | Promise<ProcessorOptions>>();\n return {\n global: loaded,\n collections,\n workspaces: Object.fromEntries(\n Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {\n return [\n key,\n {\n dir: value.dir,\n config: buildConfig(value.config, path.resolve(cwd, value.dir)),\n },\n ];\n }),\n ),\n getMDXOptions(collection, environment = 'bundler') {\n const key = collection ? `${environment}:${collection.name}` : environment;\n const cached = mdxOptionsCache.get(key);\n if (cached) return cached;\n let result: ProcessorOptions | Promise<ProcessorOptions>;\n\n if (collection?.mdxOptions) {\n const optionsFn = collection.mdxOptions;\n result = typeof optionsFn === 'function' ? optionsFn(environment) : optionsFn;\n } else {\n result = (async () => {\n const optionsFn = this.global.mdxOptions;\n const options = typeof optionsFn === 'function' ? await optionsFn() : optionsFn;\n\n return applyMdxPreset(options)(environment);\n })();\n }\n\n mdxOptionsCache.set(key, result);\n return result;\n },\n };\n}\n"],"mappings":";;;;;AAqDA,MAAM,mBAAmB;CACvB,KAAK,CAAC,OAAO,KAAK;CAClB,MAAM,CAAC,QAAQ,OAAO;CACvB;AAED,SAAgB,gBACd,MACA,YACA,KACgB;AAChB,KAAI,WAAW,SAAS,OACtB,QAAO;EACL,GAAG;EACH,MAAM;EACN,IAAI,MAAM;AACR,UAAO,KAAK,KAAK;;EAEnB;EACA,MAAM,gBAAgB,MAAM,WAAW,MAAM,IAAI;EACjD,MAAM,gBAAgB,MAAM,WAAW,MAAM,IAAI;EACjD,QAAQ,UAAU;AAChB,UAAO,KAAK,KAAK,QAAQ,SAAS,IAAI,KAAK,KAAK,QAAQ,SAAS;;EAEnE,gBAAgB,UAAU;AACxB,UAAO,KAAK,KAAK,gBAAgB,SAAS,IAAI,KAAK,KAAK,gBAAgB,SAAS;;EAEnF;EACD;AAGH,QAAO;EACL,GAAG;EACH,GAAG,yBAAyB,MAAM,YAAY,IAAI;EACnD;;AAGH,SAAS,yBACP,MACA,QACA,KACyB;CACzB,MAAM,mBAAmB,iBAAiB,OAAO;CACjD,MAAM,WAAW,OAAO,SAAS,CAAC,SAAS,iBAAiB,KAAK,IAAI,CAAC,GAAG;CACzE,IAAIA;AAEJ,QAAO;EACL,KAAK,KAAK,QAAQ,KAAK,OAAO,IAAI;EAClC;EACA;EACA;EACA,gBAAgB,UAAU;AACxB,UAAO,iBAAiB,MAAM,WAAW,SAAS,SAAS,IAAI,SAAS,CAAC;;EAE3E,QAAQ,U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AAY,GAAG;SAEpE,WAAU,YAAY;IACpB,MAAM,YAAY,KAAK,OAAO;AAG9B,WAAO,eAFS,OAAO,cAAc,aAAa,MAAM,WAAW,GAAG,UAExC,CAAC,YAAY;OACzC;AAGN,mBAAgB,IAAI,KAAK,OAAO;AAChC,UAAO;;EAEV"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as flattenNode, t as remarkInclude } from "./remark-include-
|
|
1
|
+
import { n as flattenNode, t as remarkInclude } from "./remark-include-BbnDmUoc.js";
|
|
2
2
|
import { visit } from "unist-util-visit";
|
|
3
3
|
import { VFile } from "vfile";
|
|
4
4
|
import { createProcessor } from "@mdx-js/mdx";
|
|
@@ -150,4 +150,4 @@ async function buildMDX(core, collection, { filePath, frontmatter, source, _comp
|
|
|
150
150
|
|
|
151
151
|
//#endregion
|
|
152
152
|
export { buildMDX as t };
|
|
153
|
-
//# sourceMappingURL=build-mdx-
|
|
153
|
+
//# sourceMappingURL=build-mdx-COY0QD1z.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-mdx-CNzC71ea.js","names":["_stringifyProcessor: Processor | undefined","urls: ExtractedReference[]","postprocessOptions: PostprocessOptions"],"sources":["../src/loaders/mdx/remark-postprocess.ts","../src/loaders/mdx/build-mdx.ts"],"sourcesContent":["import type { Processor, Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport { toMarkdown } from 'mdast-util-to-markdown';\nimport { valueToEstree } from 'estree-util-value-to-estree';\nimport { removePosition } from 'unist-util-remove-position';\nimport remarkMdx from 'remark-mdx';\nimport { flattenNode } from './mdast-utils';\n\nexport interface ExtractedReference {\n href: string;\n}\n\nexport interface PostprocessOptions {\n _format: 'md' | 'mdx';\n\n /**\n * Properties to export from `vfile.data`\n */\n valueToExport?: string[];\n\n /**\n * stringify MDAST and export via `_markdown`.\n */\n includeProcessedMarkdown?: boolean;\n\n /**\n * extract link references, export via `extractedReferences`.\n */\n extractLinkReferences?: boolean;\n\n /**\n * store MDAST and export via `_mdast`.\n */\n includeMDAST?:\n | boolean\n | {\n removePosition?: boolean;\n };\n}\n\n/**\n * - collect references\n * - write frontmatter (auto-title & description)\n */\nexport function remarkPostprocess(\n this: Processor,\n {\n _format,\n includeProcessedMarkdown = false,\n includeMDAST = false,\n extractLinkReferences = false,\n valueToExport = [],\n }: PostprocessOptions,\n): Transformer<Root, Root> {\n let _stringifyProcessor: Processor | undefined;\n const getStringifyProcessor = () => {\n return (_stringifyProcessor ??=\n _format === 'mdx'\n ? this\n : // force Markdown processor to stringify MDX nodes\n this().use(remarkMdx).freeze());\n };\n\n return (tree, file) => {\n const frontmatter = (file.data.frontmatter ??= {});\n if (!frontmatter.title) {\n visit(tree, 'heading', (node) => {\n if (node.depth === 1) {\n frontmatter.title = flattenNode(node);\n return false;\n }\n });\n }\n\n file.data['mdx-export'] ??= [];\n file.data['mdx-export'].push({\n name: 'frontmatter',\n value: frontmatter,\n });\n\n if (extractLinkReferences) {\n const urls: ExtractedReference[] = [];\n\n visit(tree, 'link', (node) => {\n urls.push({\n href: node.url,\n });\n return 'skip';\n });\n\n file.data['mdx-export'].push({\n name: 'extractedReferences',\n value: urls,\n });\n }\n\n if (includeProcessedMarkdown) {\n const processor = getStringifyProcessor();\n const markdown = toMarkdown(tree, {\n ...processor.data('settings'),\n // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js\n extensions: processor.data('toMarkdownExtensions') || [],\n });\n\n file.data['mdx-export'].push({\n name: '_markdown',\n value: markdown,\n });\n }\n\n if (includeMDAST) {\n const options = includeMDAST === true ? {} : includeMDAST;\n const mdast = JSON.stringify(\n options.removePosition ? removePosition(structuredClone(tree)) : tree,\n );\n\n file.data['mdx-export'].push({\n name: '_mdast',\n value: mdast,\n });\n }\n\n for (const { name, value } of file.data['mdx-export']) {\n tree.children.unshift(getMdastExport(name, value));\n }\n\n // reset the data to reduce memory usage\n file.data['mdx-export'] = [];\n\n for (const name of valueToExport) {\n if (!(name in file.data)) continue;\n\n tree.children.unshift(getMdastExport(name, file.data[name]));\n }\n };\n}\n\n/**\n * MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins\n *\n * Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node\n */\nfunction getMdastExport(name: string, value: unknown): RootContent {\n return {\n type: 'mdxjsEsm',\n value: '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExportNamedDeclaration',\n attributes: [],\n specifiers: [],\n source: null,\n declaration: {\n type: 'VariableDeclaration',\n kind: 'let',\n declarations: [\n {\n type: 'VariableDeclarator',\n id: {\n type: 'Identifier',\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n","import { createProcessor } from '@mdx-js/mdx';\nimport { VFile } from 'vfile';\nimport { remarkInclude } from '@/loaders/mdx/remark-include';\nimport type { StructuredData } from '@hanzo/docs-core/mdx-plugins';\nimport type { TOCItemType } from '@hanzo/docs-core/toc';\nimport type { FC } from 'react';\nimport type { MDXProps } from 'mdx/types';\nimport { type PostprocessOptions, remarkPostprocess } from '@/loaders/mdx/remark-postprocess';\nimport type { Core } from '@/core';\nimport type { DocCollectionItem } from '@/config/build';\n\ntype Processor = ReturnType<typeof createProcessor>;\n\ninterface BuildMDXOptions {\n /**\n * Specify a file path for source\n */\n filePath: string;\n source: string;\n frontmatter?: Record<string, unknown>;\n\n environment: 'bundler' | 'runtime';\n isDevelopment: boolean;\n _compiler?: CompilerOptions;\n}\n\nexport interface CompilerOptions {\n addDependency: (file: string) => void;\n}\n\nexport interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {\n frontmatter: Frontmatter;\n structuredData: StructuredData;\n toc: TOCItemType[];\n default: FC<MDXProps>;\n\n /**\n * Enable from `postprocess` option.\n */\n _markdown?: string;\n /**\n * Enable from `postprocess` option.\n */\n _mdast?: string;\n}\n\nexport interface FumadocsDataMap {\n /**\n * [Fumadocs MDX] raw frontmatter, you can modify it\n */\n frontmatter?: Record<string, unknown>;\n\n /**\n * [Fumadocs MDX] additional ESM exports to write\n */\n 'mdx-export'?: { name: string; value: unknown }[];\n\n /**\n * [Fumadocs MDX] The compiler object from loader\n */\n _compiler?: CompilerOptions;\n\n /**\n * [Fumadocs MDX] get internal processor, do not use this on user land.\n */\n _getProcessor?: (format: 'md' | 'mdx') => Processor;\n}\n\ndeclare module 'vfile' {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extend data map\n interface DataMap extends FumadocsDataMap {}\n}\n\nexport async function buildMDX(\n core: Core,\n collection: DocCollectionItem | undefined,\n { filePath, frontmatter, source, _compiler, environment, isDevelopment }: BuildMDXOptions,\n): Promise<VFile> {\n const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);\n\n function getProcessor(format: 'md' | 'mdx') {\n const cache = core.cache as Map<string, Processor>;\n const key = `build-mdx:${collection?.name ?? 'global'}:${format}`;\n let processor = cache.get(key);\n\n if (!processor) {\n const postprocessOptions: PostprocessOptions = {\n _format: format,\n ...collection?.postprocess,\n };\n\n processor = createProcessor({\n outputFormat: 'program',\n development: isDevelopment,\n ...mdxOptions,\n remarkPlugins: [\n remarkInclude,\n ...(mdxOptions.remarkPlugins ?? []),\n [remarkPostprocess, postprocessOptions],\n ],\n format,\n });\n\n cache.set(key, processor);\n }\n\n return processor;\n }\n\n let vfile = new VFile({\n value: source,\n path: filePath,\n cwd: collection?.cwd,\n data: { frontmatter, _compiler, _getProcessor: getProcessor },\n });\n\n if (collection) {\n vfile = await core.transformVFile({ collection, filePath, source }, vfile);\n }\n\n return getProcessor(filePath.endsWith('.mdx') ? 'mdx' : 'md').process(vfile);\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,SAAgB,kBAEd,EACE,SACA,2BAA2B,OAC3B,eAAe,OACf,wBAAwB,OACxB,gBAAgB,EAAE,IAEK;CACzB,IAAIA;CACJ,MAAM,8BAA8B;AAClC,SAAQ,wBACN,YA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AAM"}
|
|
1
|
+
{"version":3,"file":"build-mdx-COY0QD1z.js","names":["_stringifyProcessor: Processor | undefined","urls: ExtractedReference[]","postprocessOptions: PostprocessOptions"],"sources":["../src/loaders/mdx/remark-postprocess.ts","../src/loaders/mdx/build-mdx.ts"],"sourcesContent":["import type { Processor, Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport { toMarkdown } from 'mdast-util-to-markdown';\nimport { valueToEstree } from 'estree-util-value-to-estree';\nimport { removePosition } from 'unist-util-remove-position';\nimport remarkMdx from 'remark-mdx';\nimport { flattenNode } from './mdast-utils';\n\nexport interface ExtractedReference {\n href: string;\n}\n\nexport interface PostprocessOptions {\n _format: 'md' | 'mdx';\n\n /**\n * Properties to export from `vfile.data`\n */\n valueToExport?: string[];\n\n /**\n * stringify MDAST and export via `_markdown`.\n */\n includeProcessedMarkdown?: boolean;\n\n /**\n * extract link references, export via `extractedReferences`.\n */\n extractLinkReferences?: boolean;\n\n /**\n * store MDAST and export via `_mdast`.\n */\n includeMDAST?:\n | boolean\n | {\n removePosition?: boolean;\n };\n}\n\n/**\n * - collect references\n * - write frontmatter (auto-title & description)\n */\nexport function remarkPostprocess(\n this: Processor,\n {\n _format,\n includeProcessedMarkdown = false,\n includeMDAST = false,\n extractLinkReferences = false,\n valueToExport = [],\n }: PostprocessOptions,\n): Transformer<Root, Root> {\n let _stringifyProcessor: Processor | undefined;\n const getStringifyProcessor = () => {\n return (_stringifyProcessor ??=\n _format === 'mdx'\n ? this\n : // force Markdown processor to stringify MDX nodes\n this().use(remarkMdx).freeze());\n };\n\n return (tree, file) => {\n const frontmatter = (file.data.frontmatter ??= {});\n if (!frontmatter.title) {\n visit(tree, 'heading', (node) => {\n if (node.depth === 1) {\n frontmatter.title = flattenNode(node);\n return false;\n }\n });\n }\n\n file.data['mdx-export'] ??= [];\n file.data['mdx-export'].push({\n name: 'frontmatter',\n value: frontmatter,\n });\n\n if (extractLinkReferences) {\n const urls: ExtractedReference[] = [];\n\n visit(tree, 'link', (node) => {\n urls.push({\n href: node.url,\n });\n return 'skip';\n });\n\n file.data['mdx-export'].push({\n name: 'extractedReferences',\n value: urls,\n });\n }\n\n if (includeProcessedMarkdown) {\n const processor = getStringifyProcessor();\n const markdown = toMarkdown(tree, {\n ...processor.data('settings'),\n // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js\n extensions: processor.data('toMarkdownExtensions') || [],\n });\n\n file.data['mdx-export'].push({\n name: '_markdown',\n value: markdown,\n });\n }\n\n if (includeMDAST) {\n const options = includeMDAST === true ? {} : includeMDAST;\n const mdast = JSON.stringify(\n options.removePosition ? removePosition(structuredClone(tree)) : tree,\n );\n\n file.data['mdx-export'].push({\n name: '_mdast',\n value: mdast,\n });\n }\n\n for (const { name, value } of file.data['mdx-export']) {\n tree.children.unshift(getMdastExport(name, value));\n }\n\n // reset the data to reduce memory usage\n file.data['mdx-export'] = [];\n\n for (const name of valueToExport) {\n if (!(name in file.data)) continue;\n\n tree.children.unshift(getMdastExport(name, file.data[name]));\n }\n };\n}\n\n/**\n * MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins\n *\n * Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node\n */\nfunction getMdastExport(name: string, value: unknown): RootContent {\n return {\n type: 'mdxjsEsm',\n value: '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExportNamedDeclaration',\n attributes: [],\n specifiers: [],\n source: null,\n declaration: {\n type: 'VariableDeclaration',\n kind: 'let',\n declarations: [\n {\n type: 'VariableDeclarator',\n id: {\n type: 'Identifier',\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n","import { createProcessor } from '@mdx-js/mdx';\nimport { VFile } from 'vfile';\nimport { remarkInclude } from '@/loaders/mdx/remark-include';\nimport type { StructuredData } from '@hanzo/docs-core/mdx-plugins';\nimport type { TOCItemType } from '@hanzo/docs-core/toc';\nimport type { FC } from 'react';\nimport type { MDXProps } from 'mdx/types';\nimport { type PostprocessOptions, remarkPostprocess } from '@/loaders/mdx/remark-postprocess';\nimport type { Core } from '@/core';\nimport type { DocCollectionItem } from '@/config/build';\n\ntype Processor = ReturnType<typeof createProcessor>;\n\ninterface BuildMDXOptions {\n /**\n * Specify a file path for source\n */\n filePath: string;\n source: string;\n frontmatter?: Record<string, unknown>;\n\n environment: 'bundler' | 'runtime';\n isDevelopment: boolean;\n _compiler?: CompilerOptions;\n}\n\nexport interface CompilerOptions {\n addDependency: (file: string) => void;\n}\n\nexport interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {\n frontmatter: Frontmatter;\n structuredData: StructuredData;\n toc: TOCItemType[];\n default: FC<MDXProps>;\n\n /**\n * Enable from `postprocess` option.\n */\n _markdown?: string;\n /**\n * Enable from `postprocess` option.\n */\n _mdast?: string;\n}\n\nexport interface FumadocsDataMap {\n /**\n * [Fumadocs MDX] raw frontmatter, you can modify it\n */\n frontmatter?: Record<string, unknown>;\n\n /**\n * [Fumadocs MDX] additional ESM exports to write\n */\n 'mdx-export'?: { name: string; value: unknown }[];\n\n /**\n * [Fumadocs MDX] The compiler object from loader\n */\n _compiler?: CompilerOptions;\n\n /**\n * [Fumadocs MDX] get internal processor, do not use this on user land.\n */\n _getProcessor?: (format: 'md' | 'mdx') => Processor;\n}\n\ndeclare module 'vfile' {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extend data map\n interface DataMap extends FumadocsDataMap {}\n}\n\nexport async function buildMDX(\n core: Core,\n collection: DocCollectionItem | undefined,\n { filePath, frontmatter, source, _compiler, environment, isDevelopment }: BuildMDXOptions,\n): Promise<VFile> {\n const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);\n\n function getProcessor(format: 'md' | 'mdx') {\n const cache = core.cache as Map<string, Processor>;\n const key = `build-mdx:${collection?.name ?? 'global'}:${format}`;\n let processor = cache.get(key);\n\n if (!processor) {\n const postprocessOptions: PostprocessOptions = {\n _format: format,\n ...collection?.postprocess,\n };\n\n processor = createProcessor({\n outputFormat: 'program',\n development: isDevelopment,\n ...mdxOptions,\n remarkPlugins: [\n remarkInclude,\n ...(mdxOptions.remarkPlugins ?? []),\n [remarkPostprocess, postprocessOptions],\n ],\n format,\n });\n\n cache.set(key, processor);\n }\n\n return processor;\n }\n\n let vfile = new VFile({\n value: source,\n path: filePath,\n cwd: collection?.cwd,\n data: { frontmatter, _compiler, _getProcessor: getProcessor },\n });\n\n if (collection) {\n vfile = await core.transformVFile({ collection, filePath, source }, vfile);\n }\n\n return getProcessor(filePath.endsWith('.mdx') ? 'mdx' : 'md').process(vfile);\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,SAAgB,kBAEd,EACE,SACA,2BAA2B,OAC3B,eAAe,OACf,wBAAwB,OACxB,gBAAgB,EAAE,IAEK;CACzB,IAAIA;CACJ,MAAM,8BAA8B;AAClC,SAAQ,wBACN,YAAY,QACR,OAEA,MAAM,CAAC,IAAI,UAAU,CAAC,QAAQ;;AAGtC,SAAQ,MAAM,SAAS;EACrB,MAAM,cAAe,KAAK,KAAK,gBAAgB,EAAE;AACjD,MAAI,CAAC,YAAY,MACf,OAAM,MAAM,YAAY,SAAS;AAC/B,OAAI,KAAK,UAAU,GAAG;AACpB,gBAAY,QAAQ,YAAY,KAAK;AACrC,WAAO;;IAET;AAGJ,OAAK,KAAK,kBAAkB,EAAE;AAC9B,OAAK,KAAK,cAAc,KAAK;GAC3B,MAAM;GACN,OAAO;GACR,CAAC;AAEF,MAAI,uBAAuB;GACzB,MAAMC,OAA6B,EAAE;AAErC,SAAM,MAAM,SAAS,SAAS;AAC5B,SAAK,KAAK,EACR,MAAM,KAAK,KACZ,CAAC;AACF,WAAO;KACP;AAEF,QAAK,KAAK,cAAc,KAAK;IAC3B,MAAM;IACN,OAAO;IACR,CAAC;;AAGJ,MAAI,0BAA0B;GAC5B,MAAM,YAAY,uBAAuB;GACzC,MAAM,WAAW,WAA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AG;EACzD,IAAI,YAAY,MAAM,IAAI,IAAI;AAE9B,MAAI,CAAC,WAAW;GACd,MAAMC,qBAAyC;IAC7C,SAAS;IACT,GAAG,YAAY;IAChB;AAED,eAAY,gBAAgB;IAC1B,cAAc;IACd,aAAa;IACb,GAAG;IACH,eAAe;KACb;KACA,GAAI,WAAW,iBAAiB,EAAE;KAClC,CAAC,mBAAmB,mBAAmB;KACxC;IACD;IACD,CAAC;AAEF,SAAM,IAAI,KAAK,UAAU;;AAG3B,SAAO;;CAGT,IAAI,QAAQ,IAAI,MAAM;EACpB,OAAO;EACP,MAAM;EACN,KAAK,YAAY;EACjB,MAAM;GAAE;GAAa;GAAW,eAAe;GAAc;EAC9D,CAAC;AAEF,KAAI,WACF,SAAQ,MAAM,KAAK,eAAe;EAAE;EAAY;EAAU;EAAQ,EAAE,MAAM;AAG5E,QAAO,aAAa,SAAS,SAAS,OAAO,GAAG,QAAQ,KAAK,CAAC,QAAQ,MAAM"}
|
package/dist/bun/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import
|
|
3
|
-
import "../
|
|
4
|
-
import { t as
|
|
5
|
-
import
|
|
6
|
-
import "../
|
|
7
|
-
import {
|
|
8
|
-
import { t as createMetaLoader } from "../meta-
|
|
1
|
+
import "../preset-D_quDsKp.js";
|
|
2
|
+
import "../fuma-matter-DL-PfQJ7.js";
|
|
3
|
+
import { t as buildConfig } from "../build-GdAvxpd7.js";
|
|
4
|
+
import { n as createCore, t as _Defaults } from "../core-DOav5JBx.js";
|
|
5
|
+
import "../codegen-Dd9ILNOr.js";
|
|
6
|
+
import { t as createMdxLoader } from "../mdx-CJaKR3FR.js";
|
|
7
|
+
import { r as toBun, t as createIntegratedConfigLoader } from "../config-DSrG5Dfc.js";
|
|
8
|
+
import { t as createMetaLoader } from "../meta-CKrL1Sl9.js";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
10
|
|
|
11
11
|
//#region src/bun/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-
|
|
1
|
+
{"version":3,"file":"codegen-Dd9ILNOr.js","names":["banner: string[]","code: string","filename: string","path"],"sources":["../src/utils/codegen.ts"],"sourcesContent":["import path from 'node:path';\nimport { glob } from 'tinyglobby';\n\nexport interface GlobImportOptions {\n base: string;\n query?: Record<string, string | undefined>;\n import?: string;\n eager?: boolean;\n}\n\nexport interface CodeGenOptions {\n target: 'default' | 'vite';\n outDir: string;\n /**\n * add .js extenstion to imports\n */\n jsExtension: boolean;\n globCache: Map<string, Promise<string[]>>;\n}\n\nexport type CodeGen = ReturnType<typeof createCodegen>;\n\n/**\n * Code generator (one instance per file)\n */\nexport function createCodegen({\n target = 'default',\n outDir = '',\n jsExtension = false,\n globCache = new Map(),\n}: Partial<CodeGenOptions>) {\n let eagerImportId = 0;\n const banner: string[] = ['// @ts-nocheck'];\n\n if (target === 'vite') {\n banner.push('/// <reference types=\"vite/client\" />');\n }\n\n return {\n options: {\n target,\n outDir,\n } as CodeGenOptions,\n lines: [] as string[],\n addImport(statement: string) {\n this.lines.unshift(statement);\n },\n async pushAsync(insert: Promise<string | undefined>[]) {\n for (const line of await Promise.all(insert)) {\n if (line === undefined) continue;\n\n this.lines.push(line);\n }\n },\n\n async generateGlobImport(\n patterns: string | string[],\n options: GlobImportOptions,\n ): Promise<string> {\n if (target === 'vite') {\n return this.generateViteGlobImport(patterns, options);\n }\n\n return this.generateNodeGlobImport(patterns, options);\n },\n\n generateViteGlobImport(\n patterns: string | string[],\n { base, ...rest }: GlobImportOptions,\n ): string {\n patterns = (typeof patterns === 'string' ? [patterns] : patterns).map(normalizeViteGlobPath);\n\n return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(\n {\n base: normalizeViteGlobPath(path.relative(outDir, base)),\n ...rest,\n },\n null,\n 2,\n )})`;\n },\n async generateNodeGlobImport(\n patterns: string | string[],\n { base, eager = false, query = {}, import: importName }: GlobImportOptions,\n ): Promise<string> {\n const cacheKey = JSON.stringify({ patterns, base });\n let files = globCache.get(cacheKey);\n if (!files) {\n files = glob(patterns, {\n cwd: base,\n });\n globCache.set(cacheKey, files);\n }\n\n let code: string = '{';\n for (const item of await files) {\n const fullPath = path.join(base, item);\n const searchParams = new URLSearchParams();\n\n for (const [k, v] of Object.entries(query)) {\n if (v !== undefined) searchParams.set(k, v);\n }\n\n const importPath = this.formatImportPath(fullPath) + '?' + searchParams.toString();\n if (eager) {\n const name = `__fd_glob_${eagerImportId++}`;\n this.lines.unshift(\n importName\n ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}`\n : `import * as ${name} from ${JSON.stringify(importPath)}`,\n );\n\n code += `${JSON.stringify(item)}: ${name}, `;\n } else {\n let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;\n if (importName) {\n line += `.then(mod => mod.${importName})`;\n }\n\n code += `${line}, `;\n }\n }\n\n code += '}';\n return code;\n },\n formatImportPath(file: string) {\n const ext = path.extname(file);\n let filename: string;\n\n if (ext === '.ts') {\n filename = file.substring(0, file.length - ext.length);\n if (jsExtension) filename += '.js';\n } else {\n filename = file;\n }\n\n const importPath = slash(path.relative(outDir, filename));\n return importPath.startsWith('.') ? importPath : `./${importPath}`;\n },\n toString() {\n return [...banner, ...this.lines].join('\\n');\n },\n };\n}\n\n/**\n * convert into POSIX & relative file paths, such that Vite can accept it.\n */\nfunction normalizeViteGlobPath(file: string) {\n file = slash(file);\n if (file.startsWith('./')) return file;\n if (file.startsWith('/')) return `.${file}`;\n\n return `./${file}`;\n}\n\nexport function slash(path: string): string {\n const isExtendedLengthPath = path.startsWith('\\\\\\\\?\\\\');\n\n if (isExtendedLengthPath) {\n return path;\n }\n\n return path.replaceAll('\\\\', '/');\n}\n\nexport function ident(code: string, tab: number = 1) {\n return code\n .split('\\n')\n .map((v) => ' '.repeat(tab) + v)\n .join('\\n');\n}\n"],"mappings":";;;;;;;AAyBA,SAAgB,cAAc,EAC5B,SAAS,WACT,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AAG;AACnD,QAAO,KACJ,MAAM,KAAK,CACX,KAAK,MAAM,KAAK,OAAO,IAAI,GAAG,EAAE,CAChC,KAAK,KAAK"}
|
package/dist/config/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import
|
|
3
|
-
import { t as remarkInclude } from "../remark-include-
|
|
1
|
+
import { t as applyMdxPreset } from "../preset-D_quDsKp.js";
|
|
2
|
+
import "../fuma-matter-DL-PfQJ7.js";
|
|
3
|
+
import { t as remarkInclude } from "../remark-include-BbnDmUoc.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
//#region ../core/dist/source/schema.js
|
|
@@ -1,41 +1,9 @@
|
|
|
1
|
-
import { r as ValidationError } from "./core-
|
|
1
|
+
import { r as ValidationError } from "./core-DOav5JBx.js";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { parse } from "node:querystring";
|
|
6
6
|
|
|
7
|
-
//#region src/loaders/config.ts
|
|
8
|
-
function createStandaloneConfigLoader({ core, buildConfig, mode }) {
|
|
9
|
-
let prev;
|
|
10
|
-
async function getConfigHash() {
|
|
11
|
-
if (mode === "production") return "static";
|
|
12
|
-
return (await fs.stat(core.getOptions().configPath).catch(() => {
|
|
13
|
-
throw new Error("Cannot find config file");
|
|
14
|
-
})).mtime.getTime().toString();
|
|
15
|
-
}
|
|
16
|
-
return { async getCore() {
|
|
17
|
-
const hash = await getConfigHash();
|
|
18
|
-
if (!prev || hash !== prev.hash) prev = {
|
|
19
|
-
hash,
|
|
20
|
-
init: (async () => {
|
|
21
|
-
const { loadConfig } = await import("./load-from-file-BD2SdoUT.js");
|
|
22
|
-
await core.init({ config: loadConfig(core, buildConfig) });
|
|
23
|
-
})()
|
|
24
|
-
};
|
|
25
|
-
await prev.init;
|
|
26
|
-
return core;
|
|
27
|
-
} };
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* create config loader from initialized core
|
|
31
|
-
*/
|
|
32
|
-
function createIntegratedConfigLoader(core) {
|
|
33
|
-
return { async getCore() {
|
|
34
|
-
return core;
|
|
35
|
-
} };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
7
|
//#region src/loaders/adapter.ts
|
|
40
8
|
function toNode(loader) {
|
|
41
9
|
return async (url, _context, nextLoad) => {
|
|
@@ -140,5 +108,37 @@ function toBun(loader) {
|
|
|
140
108
|
}
|
|
141
109
|
|
|
142
110
|
//#endregion
|
|
143
|
-
|
|
144
|
-
|
|
111
|
+
//#region src/loaders/config.ts
|
|
112
|
+
function createStandaloneConfigLoader({ core, buildConfig, mode }) {
|
|
113
|
+
let prev;
|
|
114
|
+
async function getConfigHash() {
|
|
115
|
+
if (mode === "production") return "static";
|
|
116
|
+
return (await fs.stat(core.getOptions().configPath).catch(() => {
|
|
117
|
+
throw new Error("Cannot find config file");
|
|
118
|
+
})).mtime.getTime().toString();
|
|
119
|
+
}
|
|
120
|
+
return { async getCore() {
|
|
121
|
+
const hash = await getConfigHash();
|
|
122
|
+
if (!prev || hash !== prev.hash) prev = {
|
|
123
|
+
hash,
|
|
124
|
+
init: (async () => {
|
|
125
|
+
const { loadConfig } = await import("./load-from-file-BoO9y-n6.js");
|
|
126
|
+
await core.init({ config: loadConfig(core, buildConfig) });
|
|
127
|
+
})()
|
|
128
|
+
};
|
|
129
|
+
await prev.init;
|
|
130
|
+
return core;
|
|
131
|
+
} };
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* create config loader from initialized core
|
|
135
|
+
*/
|
|
136
|
+
function createIntegratedConfigLoader(core) {
|
|
137
|
+
return { async getCore() {
|
|
138
|
+
return core;
|
|
139
|
+
} };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
export { toVite as a, toNode as i, createStandaloneConfigLoader as n, toWebpack as o, toBun as r, createIntegratedConfigLoader as t };
|
|
144
|
+
//# sourceMappingURL=config-DSrG5Dfc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"config-DSrG5Dfc.js","names":["file","input: LoaderInput","prev:\n | {\n hash: string;\n init: Promise<void>;\n }\n | undefined"],"sources":["../src/loaders/adapter.ts","../src/loaders/config.ts"],"sourcesContent":["import type { CompilerOptions } from '@/loaders/mdx/build-mdx';\nimport type { LoadFnOutput, LoadHook } from 'node:module';\nimport { fileURLToPath } from 'node:url';\nimport fs from 'node:fs/promises';\nimport type { SourceMap, TransformPluginContext } from 'rollup';\nimport type { TransformResult } from 'vite';\nimport { parse } from 'node:querystring';\nimport { ValidationError } from '@/utils/validation';\nimport type { LoaderContext } from 'webpack';\nimport { readFileSync } from 'node:fs';\n\nexport interface LoaderInput {\n development: boolean;\n compiler: CompilerOptions;\n\n filePath: string;\n query: Record<string, string | string[] | undefined>;\n getSource: () => string | Promise<string>;\n}\n\nexport interface LoaderOutput {\n code: string;\n map?: unknown;\n\n /**\n * Only supported in Vite 8.\n *\n * Explicitly define the transformed module type, for unsupported environments, you need to consider the differences between each bundler.\n */\n moduleType?: 'js' | 'json';\n}\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport interface Loader {\n /**\n * Filter file paths, the input can be either a file URL or file path.\n *\n * Must take resource query into consideration.\n */\n test?: RegExp;\n\n /**\n * Transform input into JavaScript.\n *\n * Returns:\n * - `LoaderOutput`: JavaScript code & source map.\n * - `null`: skip the loader. Fallback to default behaviour if possible, otherwise the adapter will try workarounds.\n */\n load: (input: LoaderInput) => Awaitable<LoaderOutput | null>;\n\n bun?: {\n /**\n * 1. Bun doesn't allow `null` in loaders.\n * 2. Bun requires sync result to support dynamic require().\n */\n load?: (source: string, input: LoaderInput) => Awaitable<Bun.OnLoadResult>;\n };\n}\n\nexport function toNode(loader: Loader): LoadHook {\n return async (url, _context, nextLoad): Promise<LoadFnOutput> => {\n if (url.startsWith('file:///') && (!loader.test || loader.test.test(url))) {\n const parsedUrl = new URL(url);\n const filePath = fileURLToPath(parsedUrl);\n\n const result = await loader.load({\n filePath,\n query: Object.fromEntries(parsedUrl.searchParams.entries()),\n async getSource() {\n return (await fs.readFile(filePath)).toString();\n },\n development: false,\n compiler: {\n addDependency() {},\n },\n });\n\n if (result) {\n return {\n source: result.code,\n format: 'module',\n shortCircuit: true,\n };\n }\n }\n\n return nextLoad(url);\n };\n}\n\nexport interface ViteLoader {\n filter: (id: string) => boolean;\n\n transform: (\n this: TransformPluginContext,\n value: string,\n id: string,\n ) => Promise<TransformResult | null>;\n}\n\nexport function toVite(loader: Loader): ViteLoader {\n return {\n filter(id) {\n return !loader.test || loader.test.test(id);\n },\n async transform(value, id) {\n const [file, query = ''] = id.split('?', 2);\n\n const result = await loader.load({\n filePath: file,\n query: parse(query),\n getSource() {\n return value;\n },\n development: this.environment.mode === 'dev',\n compiler: {\n addDependency: (file) => {\n this.addWatchFile(file);\n },\n },\n });\n\n if (result === null) return null;\n return {\n code: result.code,\n map: result.map as SourceMap,\n moduleType: result.moduleType,\n };\n },\n };\n}\n\nexport type WebpackLoader = (\n this: LoaderContext<unknown>,\n source: string,\n callback: LoaderContext<unknown>['callback'],\n) => Promise<void>;\n\n/**\n * need to handle the `test` regex in Webpack config instead.\n */\nexport function toWebpack(loader: Loader): WebpackLoader {\n return async function (source, callback) {\n try {\n const result = await loader.load({\n filePath: this.resourcePath,\n query: parse(this.resourceQuery.slice(1)),\n getSource() {\n return source;\n },\n development: this.mode === 'development',\n compiler: this,\n });\n\n if (result === null) {\n callback(undefined, source);\n } else {\n callback(undefined, result.code, result.map as string);\n }\n } catch (error) {\n if (error instanceof ValidationError) {\n return callback(new Error(await error.toStringFormatted()));\n }\n\n if (!(error instanceof Error)) throw error;\n callback(error);\n }\n };\n}\n\nexport function toBun(loader: Loader) {\n function toResult(output: LoaderOutput | null): Bun.OnLoadResult {\n // it errors, treat this as an exception\n if (!output) return;\n\n return {\n contents: output.code,\n loader: output.moduleType ?? 'js',\n };\n }\n\n return (build: Bun.PluginBuilder) => {\n // avoid using async here, because it will cause dynamic require() to fail\n build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {\n const [filePath, query = ''] = args.path.split('?', 2);\n const input: LoaderInput = {\n async getSource() {\n return Bun.file(filePath).text();\n },\n query: parse(query),\n filePath,\n development: false,\n compiler: {\n addDependency() {},\n },\n };\n\n if (loader.bun?.load) {\n return loader.bun.load(readFileSync(filePath).toString(), input);\n }\n\n const result = loader.load(input);\n if (result instanceof Promise) {\n return result.then(toResult);\n }\n return toResult(result);\n });\n };\n}\n","import type { Core } from '@/core';\nimport fs from 'node:fs/promises';\n\nexport interface ConfigLoader {\n getCore(): Promise<Core>;\n}\n\nexport function createStandaloneConfigLoader({\n core,\n buildConfig,\n mode,\n}: {\n /**\n * core (not initialized)\n */\n core: Core;\n buildConfig: boolean;\n /**\n * In dev mode, the config file is dynamically re-loaded when it's updated.\n */\n mode: 'dev' | 'production';\n}): ConfigLoader {\n let prev:\n | {\n hash: string;\n init: Promise<void>;\n }\n | undefined;\n\n async function getConfigHash(): Promise<string> {\n if (mode === 'production') return 'static';\n\n const stats = await fs.stat(core.getOptions().configPath).catch(() => {\n throw new Error('Cannot find config file');\n });\n\n return stats.mtime.getTime().toString();\n }\n\n return {\n async getCore() {\n const hash = await getConfigHash();\n if (!prev || hash !== prev.hash) {\n prev = {\n hash,\n init: (async () => {\n const { loadConfig } = await import('../config/load-from-file');\n\n await core.init({\n config: loadConfig(core, buildConfig),\n });\n })(),\n };\n }\n\n await prev.init;\n return core;\n },\n };\n}\n\n/**\n * create config loader from initialized core\n */\nexport function createIntegratedConfigLoader(core: Core): ConfigLoader {\n return {\n async getCore() {\n return core;\n },\n };\n}\n"],"mappings":";;;;;;;AA4DA,SAAgB,OAAO,QAA0B;AAC/C,QAAO,OAAO,KAAK,UAAU,aAAoC;AAC/D,MAAI,IAAI,WAAW,WAAW,KAAK,CAAC,OAAO,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;IACjB,MAAM,EAAE,eAAe,MAAM,OAAO;AAEpC,UAAM,KAAK,KAAK,EACd,QAAQ,WAAW,MAAM,YAAY,EACtC,CAAC;OACA;GACL;AAGH,QAAM,KAAK;AACX,SAAO;IAEV;;;;;AAMH,SAAgB,6BAA6B,MAA0B;AACrE,QAAO,EACL,MAAM,UAAU;AACd,SAAO;IAEV"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as ident } from "./codegen-
|
|
2
|
-
import fs from "node:fs/promises";
|
|
1
|
+
import { n as ident } from "./codegen-Dd9ILNOr.js";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/validation.ts
|
|
6
6
|
var ValidationError = class extends Error {
|
|
@@ -209,4 +209,4 @@ function postprocessPlugin() {
|
|
|
209
209
|
|
|
210
210
|
//#endregion
|
|
211
211
|
export { createCore as n, ValidationError as r, _Defaults as t };
|
|
212
|
-
//# sourceMappingURL=core-
|
|
212
|
+
//# sourceMappingURL=core-DOav5JBx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-BJualF84.js","names":["plugins: Plugin[]","config: LoadedConfig","out: EmitOutput","options","lines: string[]","postprocessOptions: Partial<PostprocessOptions> | undefined"],"sources":["../src/utils/validation.ts","../src/core.ts"],"sourcesContent":["import type { CollectionSchema } from '@/config';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\n\nexport class ValidationError extends Error {\n title: string;\n issues: readonly StandardSchemaV1.Issue[];\n\n constructor(message: string, issues: readonly StandardSchemaV1.Issue[]) {\n super(`${message}:\\n${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join('\\n')}`);\n\n this.title = message;\n this.issues = issues;\n }\n\n async toStringFormatted() {\n // Handle ESM/CJS interop: picocolors is a CJS module that exports via\n // module.exports = createColors(). When dynamically imported in ESM context\n // (e.g., Next.js 16 Turbopack), the exports are wrapped under .default\n const picocolorsModule = await import('picocolors');\n const picocolors = picocolorsModule.default ?? picocolorsModule;\n\n return [\n picocolors.bold(`[MDX] ${this.title}:`),\n ...this.issues.map((issue) =>\n picocolors.redBright(\n `- ${picocolors.bold(issue.path?.join('.') ?? '*')}: ${issue.message}`,\n ),\n ),\n ].join('\\n');\n }\n}\n\nexport async function validate<Schema extends StandardSchemaV1, Context>(\n schema: CollectionSchema<Schema, Context>,\n data: unknown,\n context: Context,\n errorMessage: string,\n): Promise<StandardSchemaV1.InferOutput<Schema>> {\n if (typeof schema === 'function' && !('~standard' in schema)) {\n schema = schema(context);\n }\n\n if ('~standard' in schema) {\n const result = await (schema as StandardSchemaV1)['~standard'].validate(data);\n\n if (result.issues) {\n throw new ValidationError(errorMessage, result.issues);\n }\n\n return result.value;\n }\n\n return data;\n}\n","import type {\n CollectionItem,\n DocCollectionItem,\n LoadedConfig,\n MetaCollectionItem,\n} from '@/config/build';\nimport path from 'node:path';\nimport fs from 'node:fs/promises';\nimport type { FSWatcher } from 'chokidar';\nimport { validate } from './utils/validation';\nimport type { VFile } from 'vfile';\nimport type { IndexFilePlugin } from './plugins/index-file';\nimport type { PostprocessOptions } from './config';\nimport { ident } from './utils/codegen';\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport interface EmitEntry {\n /**\n * path relative to output directory\n */\n path: string;\n content: string;\n}\n\nexport interface PluginContext {\n core: Core;\n}\n\nexport type CompilationContext<Collection> = PluginContext & TransformOptions<Collection>;\n\nexport interface TransformOptions<Collection> {\n collection: Collection;\n filePath: string;\n source: string;\n}\n\nexport interface Plugin extends IndexFilePlugin {\n name?: string;\n\n /**\n * on config loaded/updated\n */\n config?: (this: PluginContext, config: LoadedConfig) => Awaitable<void | LoadedConfig>;\n\n /**\n * Generate files (e.g. types, index file, or JSON schemas)\n */\n emit?: (this: PluginContext) => Awaitable<EmitEntry[]>;\n\n /**\n * Configure Fumadocs dev server\n */\n configureServer?: (this: PluginContext, server: ServerContext) => Awaitable<void>;\n\n meta?: {\n /**\n * Transform metadata\n */\n transform?: (\n this: CompilationContext<MetaCollectionItem>,\n data: unknown,\n ) => Awaitable<unknown | void>;\n };\n\n doc?: {\n /**\n * Transform frontmatter\n */\n frontmatter?: (\n this: CompilationContext<DocCollectionItem>,\n data: Record<string, unknown>,\n ) => Awaitable<Record<string, unknown> | void>;\n\n /**\n * Transform `vfile` on compilation stage\n */\n vfile?: (this: CompilationContext<DocCollectionItem>, file: VFile) => Awaitable<VFile | void>;\n };\n}\n\nexport type PluginOption = Awaitable<Plugin | PluginOption[] | false | undefined>;\n\nexport interface ServerContext {\n /**\n * the file watcher, by default all content files are watched, along with other files.\n *\n * make sure to filter when listening to events\n */\n watcher?: FSWatcher;\n}\n\nexport interface CoreOptions {\n environment: string;\n configPath: string;\n outDir: string;\n plugins?: PluginOption[];\n\n /**\n * the workspace info if this instance is created as a workspace\n */\n workspace?: {\n parent: Core;\n name: string;\n dir: string;\n };\n}\n\nexport interface EmitOptions {\n /**\n * filter the plugins to run emit\n */\n filterPlugin?: (plugin: Plugin) => boolean;\n\n /**\n * filter the workspaces to run emit\n */\n filterWorkspace?: (workspace: string) => boolean;\n\n /**\n * write files\n */\n write?: boolean;\n}\n\nexport interface EmitOutput {\n entries: EmitEntry[];\n workspaces: Record<string, EmitEntry[]>;\n}\n\nexport const _Defaults = {\n configPath: 'source.config.ts',\n outDir: '.docs',\n};\n\nasync function getPlugins(pluginOptions: PluginOption[]): Promise<Plugin[]> {\n const plugins: Plugin[] = [];\n\n for await (const option of pluginOptions) {\n if (!option) continue;\n if (Array.isArray(option)) plugins.push(...(await getPlugins(option)));\n else plugins.push(option);\n }\n\n return plugins;\n}\n\nexport function createCore(options: CoreOptions) {\n let config: LoadedConfig;\n let plugins: Plugin[];\n const workspaces = new Map<string, Core>();\n\n async function transformMetadata<T>(\n { collection, filePath, source }: TransformOptions<DocCollectionItem | MetaCollectionItem>,\n data: unknown,\n ): Promise<T> {\n if (collection.schema) {\n data = await validate(\n collection.schema,\n data,\n { path: filePath, source },\n collection.type === 'doc'\n ? `invalid frontmatter in ${filePath}`\n : `invalid data in ${filePath}`,\n );\n }\n\n return data as T;\n }\n\n return {\n /**\n * Convenient cache store, reset when config changes\n */\n cache: new Map<string, unknown>(),\n async init({ config: newConfig }: { config: Awaitable<LoadedConfig> }) {\n config = await newConfig;\n this.cache.clear();\n workspaces.clear();\n plugins = await getPlugins([postprocessPlugin(), options.plugins, config.global.plugins]);\n\n for (const plugin of plugins) {\n const out = await plugin.config?.call(this.getPluginContext(), config);\n if (out) config = out;\n }\n\n // only support workspaces with max depth 1\n if (!options.workspace) {\n await Promise.all(\n Object.entries(config.workspaces).map(async ([name, workspace]) => {\n const core = createCore({\n ...options,\n outDir: path.join(options.outDir, name),\n workspace: {\n name,\n parent: this,\n dir: workspace.dir,\n },\n });\n await core.init({ config: workspace.config });\n workspaces.set(name, core);\n }),\n );\n }\n },\n getWorkspaces() {\n return workspaces;\n },\n getOptions() {\n return options;\n },\n getConfig(): LoadedConfig {\n return config;\n },\n /**\n * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)\n */\n getCompiledConfigPath(): string {\n return path.join(options.outDir, 'source.config.mjs');\n },\n getPlugins() {\n return plugins;\n },\n getCollections(): CollectionItem[] {\n return Array.from(config.collections.values());\n },\n getCollection(name: string): CollectionItem | undefined {\n return config.collections.get(name);\n },\n getPluginContext(): PluginContext {\n return {\n core: this,\n };\n },\n async initServer(server: ServerContext): Promise<void> {\n const ctx = this.getPluginContext();\n for (const plugin of plugins) {\n await plugin.configureServer?.call(ctx, server);\n }\n for (const workspace of workspaces.values()) {\n await workspace.initServer(server);\n }\n },\n async emit(emitOptions: EmitOptions = {}): Promise<EmitOutput> {\n const { filterPlugin, filterWorkspace, write = false } = emitOptions;\n const start = performance.now();\n const ctx = this.getPluginContext();\n const added = new Set<string>();\n const out: EmitOutput = {\n entries: [],\n workspaces: {},\n };\n\n for (const li of await Promise.all(\n plugins.map((plugin) => {\n if ((filterPlugin && !filterPlugin(plugin)) || !plugin.emit) return;\n return plugin.emit.call(ctx);\n }),\n )) {\n if (!li) continue;\n for (const item of li) {\n if (added.has(item.path)) continue;\n out.entries.push(item);\n added.add(item.path);\n }\n }\n\n if (write) {\n await Promise.all(\n out.entries.map(async (entry) => {\n const file = path.join(options.outDir, entry.path);\n\n await fs.mkdir(path.dirname(file), { recursive: true });\n await fs.writeFile(file, entry.content);\n }),\n );\n\n console.log(\n options.workspace\n ? `[MDX: ${options.workspace.name}] generated files in ${performance.now() - start}ms`\n : `[MDX] generated files in ${performance.now() - start}ms`,\n );\n }\n\n for (const [name, workspace] of workspaces) {\n if (filterWorkspace && !filterWorkspace(name)) continue;\n out.workspaces[name] = (await workspace.emit(emitOptions)).entries;\n }\n\n return out;\n },\n async transformMeta(\n options: TransformOptions<MetaCollectionItem>,\n data: unknown,\n ): Promise<unknown> {\n const ctx = {\n ...this.getPluginContext(),\n ...options,\n };\n\n data = await transformMetadata(options, data);\n for (const plugin of plugins) {\n if (plugin.meta?.transform) data = (await plugin.meta.transform.call(ctx, data)) ?? data;\n }\n\n return data;\n },\n async transformFrontmatter(\n options: TransformOptions<DocCollectionItem>,\n data: Record<string, unknown>,\n ): Promise<Record<string, unknown>> {\n const ctx = {\n ...this.getPluginContext(),\n ...options,\n };\n\n data = await transformMetadata(options, data);\n for (const plugin of plugins) {\n if (plugin.doc?.frontmatter) data = (await plugin.doc.frontmatter.call(ctx, data)) ?? data;\n }\n\n return data;\n },\n async transformVFile(\n options: TransformOptions<DocCollectionItem>,\n file: VFile,\n ): Promise<VFile> {\n const ctx = {\n ...this.getPluginContext(),\n ...options,\n };\n\n for (const plugin of plugins) {\n if (plugin.doc?.vfile) file = (await plugin.doc.vfile.call(ctx, file)) ?? file;\n }\n\n return file;\n },\n };\n}\n\nfunction postprocessPlugin(): Plugin {\n const LinkReferenceTypes = `{\n /**\n * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.\n */\n extractedReferences: import(\"@hanzo/docs-mdx\").ExtractedReference[];\n}`;\n\n return {\n 'index-file': {\n generateTypeConfig() {\n const lines: string[] = [];\n lines.push('{');\n lines.push(' DocData: {');\n for (const collection of this.core.getCollections()) {\n let postprocessOptions: Partial<PostprocessOptions> | undefined;\n switch (collection.type) {\n case 'doc':\n postprocessOptions = collection.postprocess;\n break;\n case 'docs':\n postprocessOptions = collection.docs.postprocess;\n break;\n }\n\n if (postprocessOptions?.extractLinkReferences) {\n lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));\n }\n }\n lines.push(' }');\n lines.push('}');\n return lines.join('\\n');\n },\n serverOptions(options) {\n options.doc ??= {};\n options.doc.passthroughs ??= [];\n options.doc.passthroughs.push('extractedReferences');\n },\n },\n };\n}\n\nexport type Core = ReturnType<typeof createCore>;\n"],"mappings":";;;;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAIzC,YAAY,SAAiB,QAA2C;AACtE,QAAM,GAAG,QAAQ,KAAK,OAAO,KAAK,UAAU,KAAK,MAAM,KAAK,IAAI,MAAM,UAAU,CAAC,KAAK,KAAK,GAAG;AAE9F,OAAK,QAAQ;AACb,OAAK,SAAS;;CAGhB,MAAM,oBAAoB;EAIxB,MAAM,mBAAmB,MAAM,OAAO;EACtC,MAAM,aAAa,iBAAiB,WAAW;AAE/C,SAAO,CACL,WAAW,KAAK,SAAS,KAAK,MAAM,GAAG,EACvC,GAAG,KAAK,OAAO,KAAK,UAClB,WAAW,UACT,KAAK,WAAW,KAAK,MAAM,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,MAAM,UAC9D,CACF,CACF,CAAC,KAAK,KAAK;;;AAIhB,eAAsB,SACpB,QACA,MACA,SACA,cAC+C;AAC/C,KAAI,OAAO,WAAW,cAAc,EAAE,eAAe,QACnD,UAAS,OAAO,QAAQ;AAG1B,KAAI,eAAe,QAAQ;EACzB,MAAM,SAAS,MAAO,OAA4B,aAAa,SAAS,KAAK;AAE7E,MAAI,OAAO,OACT,OAAM,IAAI,gBAAgB,cAAc,OAAO,O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EAEV;;AAGH,SAAS,oBAA4B;CACnC,MAAM,qBAAqB;;;;;;AAO3B,QAAO,EACL,cAAc;EACZ,qBAAqB;GACnB,MAAMC,QAAkB,EAAE;AAC1B,SAAM,KAAK,IAAI;AACf,SAAM,KAAK,eAAe;AAC1B,QAAK,MAAM,cAAc,KAAK,KAAK,gBAAgB,EAAE;IACnD,IAAIC;AACJ,YAAQ,WAAW,MAAnB;KACE,KAAK;AACH,2BAAqB,WAAW;AAChC;KACF,KAAK;AACH,2BAAqB,WAAW,KAAK;AACrC;;AAGJ,QAAI,oBAAoB,sBACtB,OAAM,KAAK,MAAM,GAAG,WAAW,KAAK,IAAI,mBAAmB,IAAI,EAAE,CAAC;;AAGtE,SAAM,KAAK,MAAM;AACjB,SAAM,KAAK,IAAI;AACf,UAAO,MAAM,KAAK,KAAK;;EAEzB,cAAc,SAAS;AACrB,WAAQ,QAAQ,EAAE;AAClB,WAAQ,IAAI,iBAAiB,EAAE;AAC/B,WAAQ,IAAI,aAAa,KAAK,sBAAsB;;EAEvD,EACF"}
|
|
1
|
+
{"version":3,"file":"core-DOav5JBx.js","names":["plugins: Plugin[]","config: LoadedConfig","out: EmitOutput","options","lines: string[]","postprocessOptions: Partial<PostprocessOptions> | undefined"],"sources":["../src/utils/validation.ts","../src/core.ts"],"sourcesContent":["import type { CollectionSchema } from '@/config';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\n\nexport class ValidationError extends Error {\n title: string;\n issues: readonly StandardSchemaV1.Issue[];\n\n constructor(message: string, issues: readonly StandardSchemaV1.Issue[]) {\n super(`${message}:\\n${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join('\\n')}`);\n\n this.title = message;\n this.issues = issues;\n }\n\n async toStringFormatted() {\n // Handle ESM/CJS interop: picocolors is a CJS module that exports via\n // module.exports = createColors(). When dynamically imported in ESM context\n // (e.g., Next.js 16 Turbopack), the exports are wrapped under .default\n const picocolorsModule = await import('picocolors');\n const picocolors = picocolorsModule.default ?? picocolorsModule;\n\n return [\n picocolors.bold(`[MDX] ${this.title}:`),\n ...this.issues.map((issue) =>\n picocolors.redBright(\n `- ${picocolors.bold(issue.path?.join('.') ?? '*')}: ${issue.message}`,\n ),\n ),\n ].join('\\n');\n }\n}\n\nexport async function validate<Schema extends StandardSchemaV1, Context>(\n schema: CollectionSchema<Schema, Context>,\n data: unknown,\n context: Context,\n errorMessage: string,\n): Promise<StandardSchemaV1.InferOutput<Schema>> {\n if (typeof schema === 'function' && !('~standard' in schema)) {\n schema = schema(context);\n }\n\n if ('~standard' in schema) {\n const result = await (schema as StandardSchemaV1)['~standard'].validate(data);\n\n if (result.issues) {\n throw new ValidationError(errorMessage, result.issues);\n }\n\n return result.value;\n }\n\n return data;\n}\n","import type {\n CollectionItem,\n DocCollectionItem,\n LoadedConfig,\n MetaCollectionItem,\n} from '@/config/build';\nimport path from 'node:path';\nimport fs from 'node:fs/promises';\nimport type { FSWatcher } from 'chokidar';\nimport { validate } from './utils/validation';\nimport type { VFile } from 'vfile';\nimport type { IndexFilePlugin } from './plugins/index-file';\nimport type { PostprocessOptions } from './config';\nimport { ident } from './utils/codegen';\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport interface EmitEntry {\n /**\n * path relative to output directory\n */\n path: string;\n content: string;\n}\n\nexport interface PluginContext {\n core: Core;\n}\n\nexport type CompilationContext<Collection> = PluginContext & TransformOptions<Collection>;\n\nexport interface TransformOptions<Collection> {\n collection: Collection;\n filePath: string;\n source: string;\n}\n\nexport interface Plugin extends IndexFilePlugin {\n name?: string;\n\n /**\n * on config loaded/updated\n */\n config?: (this: PluginContext, config: LoadedConfig) => Awaitable<void | LoadedConfig>;\n\n /**\n * Generate files (e.g. types, index file, or JSON schemas)\n */\n emit?: (this: PluginContext) => Awaitable<EmitEntry[]>;\n\n /**\n * Configure Fumadocs dev server\n */\n configureServer?: (this: PluginContext, server: ServerContext) => Awaitable<void>;\n\n meta?: {\n /**\n * Transform metadata\n */\n transform?: (\n this: CompilationContext<MetaCollectionItem>,\n data: unknown,\n ) => Awaitable<unknown | void>;\n };\n\n doc?: {\n /**\n * Transform frontmatter\n */\n frontmatter?: (\n this: CompilationContext<DocCollectionItem>,\n data: Record<string, unknown>,\n ) => Awaitable<Record<string, unknown> | void>;\n\n /**\n * Transform `vfile` on compilation stage\n */\n vfile?: (this: CompilationContext<DocCollectionItem>, file: VFile) => Awaitable<VFile | void>;\n };\n}\n\nexport type PluginOption = Awaitable<Plugin | PluginOption[] | false | undefined>;\n\nexport interface ServerContext {\n /**\n * the file watcher, by default all content files are watched, along with other files.\n *\n * make sure to filter when listening to events\n */\n watcher?: FSWatcher;\n}\n\nexport interface CoreOptions {\n environment: string;\n configPath: string;\n outDir: string;\n plugins?: PluginOption[];\n\n /**\n * the workspace info if this instance is created as a workspace\n */\n workspace?: {\n parent: Core;\n name: string;\n dir: string;\n };\n}\n\nexport interface EmitOptions {\n /**\n * filter the plugins to run emit\n */\n filterPlugin?: (plugin: Plugin) => boolean;\n\n /**\n * filter the workspaces to run emit\n */\n filterWorkspace?: (workspace: string) => boolean;\n\n /**\n * write files\n */\n write?: boolean;\n}\n\nexport interface EmitOutput {\n entries: EmitEntry[];\n workspaces: Record<string, EmitEntry[]>;\n}\n\nexport const _Defaults = {\n configPath: 'source.config.ts',\n outDir: '.docs',\n};\n\nasync function getPlugins(pluginOptions: PluginOption[]): Promise<Plugin[]> {\n const plugins: Plugin[] = [];\n\n for await (const option of pluginOptions) {\n if (!option) continue;\n if (Array.isArray(option)) plugins.push(...(await getPlugins(option)));\n else plugins.push(option);\n }\n\n return plugins;\n}\n\nexport function createCore(options: CoreOptions) {\n let config: LoadedConfig;\n let plugins: Plugin[];\n const workspaces = new Map<string, Core>();\n\n async function transformMetadata<T>(\n { collection, filePath, source }: TransformOptions<DocCollectionItem | MetaCollectionItem>,\n data: unknown,\n ): Promise<T> {\n if (collection.schema) {\n data = await validate(\n collection.schema,\n data,\n { path: filePath, source },\n collection.type === 'doc'\n ? `invalid frontmatter in ${filePath}`\n : `invalid data in ${filePath}`,\n );\n }\n\n return data as T;\n }\n\n return {\n /**\n * Convenient cache store, reset when config changes\n */\n cache: new Map<string, unknown>(),\n async init({ config: newConfig }: { config: Awaitable<LoadedConfig> }) {\n config = await newConfig;\n this.cache.clear();\n workspaces.clear();\n plugins = await getPlugins([postprocessPlugin(), options.plugins, config.global.plugins]);\n\n for (const plugin of plugins) {\n const out = await plugin.config?.call(this.getPluginContext(), config);\n if (out) config = out;\n }\n\n // only support workspaces with max depth 1\n if (!options.workspace) {\n await Promise.all(\n Object.entries(config.workspaces).map(async ([name, workspace]) => {\n const core = createCore({\n ...options,\n outDir: path.join(options.outDir, name),\n workspace: {\n name,\n parent: this,\n dir: workspace.dir,\n },\n });\n await core.init({ config: workspace.config });\n workspaces.set(name, core);\n }),\n );\n }\n },\n getWorkspaces() {\n return workspaces;\n },\n getOptions() {\n return options;\n },\n getConfig(): LoadedConfig {\n return config;\n },\n /**\n * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)\n */\n getCompiledConfigPath(): string {\n return path.join(options.outDir, 'source.config.mjs');\n },\n getPlugins() {\n return plugins;\n },\n getCollections(): CollectionItem[] {\n return Array.from(config.collections.values());\n },\n getCollection(name: string): CollectionItem | undefined {\n return config.collections.get(name);\n },\n getPluginContext(): PluginContext {\n return {\n core: this,\n };\n },\n async initServer(server: ServerContext): Promise<void> {\n const ctx = this.getPluginContext();\n for (const plugin of plugins) {\n await plugin.configureServer?.call(ctx, server);\n }\n for (const workspace of workspaces.values()) {\n await workspace.initServer(server);\n }\n },\n async emit(emitOptions: EmitOptions = {}): Promise<EmitOutput> {\n const { filterPlugin, filterWorkspace, write = false } = emitOptions;\n const start = performance.now();\n const ctx = this.getPluginContext();\n const added = new Set<string>();\n const out: EmitOutput = {\n entries: [],\n workspaces: {},\n };\n\n for (const li of await Promise.all(\n plugins.map((plugin) => {\n if ((filterPlugin && !filterPlugin(plugin)) || !plugin.emit) return;\n return plugin.emit.call(ctx);\n }),\n )) {\n if (!li) continue;\n for (const item of li) {\n if (added.has(item.path)) continue;\n out.entries.push(item);\n added.add(item.path);\n }\n }\n\n if (write) {\n await Promise.all(\n out.entries.map(async (entry) => {\n const file = path.join(options.outDir, entry.path);\n\n await fs.mkdir(path.dirname(file), { recursive: true });\n await fs.writeFile(file, entry.content);\n }),\n );\n\n console.log(\n options.workspace\n ? `[MDX: ${options.workspace.name}] generated files in ${performance.now() - start}ms`\n : `[MDX] generated files in ${performance.now() - start}ms`,\n );\n }\n\n for (const [name, workspace] of workspaces) {\n if (filterWorkspace && !filterWorkspace(name)) continue;\n out.workspaces[name] = (await workspace.emit(emitOptions)).entries;\n }\n\n return out;\n },\n async transformMeta(\n options: TransformOptions<MetaCollectionItem>,\n data: unknown,\n ): Promise<unknown> {\n const ctx = {\n ...this.getPluginContext(),\n ...options,\n };\n\n data = await transformMetadata(options, data);\n for (const plugin of plugins) {\n if (plugin.meta?.transform) data = (await plugin.meta.transform.call(ctx, data)) ?? data;\n }\n\n return data;\n },\n async transformFrontmatter(\n options: TransformOptions<DocCollectionItem>,\n data: Record<string, unknown>,\n ): Promise<Record<string, unknown>> {\n const ctx = {\n ...this.getPluginContext(),\n ...options,\n };\n\n data = await transformMetadata(options, data);\n for (const plugin of plugins) {\n if (plugin.doc?.frontmatter) data = (await plugin.doc.frontmatter.call(ctx, data)) ?? data;\n }\n\n return data;\n },\n async transformVFile(\n options: TransformOptions<DocCollectionItem>,\n file: VFile,\n ): Promise<VFile> {\n const ctx = {\n ...this.getPluginContext(),\n ...options,\n };\n\n for (const plugin of plugins) {\n if (plugin.doc?.vfile) file = (await plugin.doc.vfile.call(ctx, file)) ?? file;\n }\n\n return file;\n },\n };\n}\n\nfunction postprocessPlugin(): Plugin {\n const LinkReferenceTypes = `{\n /**\n * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.\n */\n extractedReferences: import(\"@hanzo/docs-mdx\").ExtractedReference[];\n}`;\n\n return {\n 'index-file': {\n generateTypeConfig() {\n const lines: string[] = [];\n lines.push('{');\n lines.push(' DocData: {');\n for (const collection of this.core.getCollections()) {\n let postprocessOptions: Partial<PostprocessOptions> | undefined;\n switch (collection.type) {\n case 'doc':\n postprocessOptions = collection.postprocess;\n break;\n case 'docs':\n postprocessOptions = collection.docs.postprocess;\n break;\n }\n\n if (postprocessOptions?.extractLinkReferences) {\n lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));\n }\n }\n lines.push(' }');\n lines.push('}');\n return lines.join('\\n');\n },\n serverOptions(options) {\n options.doc ??= {};\n options.doc.passthroughs ??= [];\n options.doc.passthroughs.push('extractedReferences');\n },\n },\n };\n}\n\nexport type Core = ReturnType<typeof createCore>;\n"],"mappings":";;;;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAIzC,YAAY,SAAiB,QAA2C;AACtE,QAAM,GAAG,QAAQ,KAAK,OAAO,KAAK,UAAU,KAAK,MAAM,KAAK,IAAI,MAAM,UAAU,CAAC,KAAK,KAAK,GAAG;AAE9F,OAAK,QAAQ;AACb,OAAK,SAAS;;CAGhB,MAAM,oBAAoB;EAIxB,MAAM,mBAAmB,MAAM,OAAO;EACtC,MAAM,aAAa,iBAAiB,WAAW;AAE/C,SAAO,CACL,WAAW,KAAK,SAAS,KAAK,MAAM,GAAG,EACvC,GAAG,KAAK,OAAO,KAAK,UAClB,WAAW,UACT,KAAK,WAAW,KAAK,MAAM,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,MAAM,UAC9D,CACF,CACF,CAAC,KAAK,KAAK;;;AAIhB,eAAsB,SACpB,QACA,MACA,SACA,cAC+C;AAC/C,KAAI,OAAO,WAAW,cAAc,EAAE,eAAe,QACnD,UAAS,OAAO,QAAQ;AAG1B,KAAI,eAAe,QAAQ;EACzB,MAAM,SAAS,MAAO,OAA4B,aAAa,SAAS,KAAK;AAE7E,MAAI,OAAO,OACT,OAAM,IAAI,gBAAgB,cAAc,OAAO,OAAO;AAGxD,SAAO,OAAO;;AAGhB,QA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AAM,qBAAqB;;;;;;AAO3B,QAAO,EACL,cAAc;EACZ,qBAAqB;GACnB,MAAMC,QAAkB,EAAE;AAC1B,SAAM,KAAK,IAAI;AACf,SAAM,KAAK,eAAe;AAC1B,QAAK,MAAM,cAAc,KAAK,KAAK,gBAAgB,EAAE;IACnD,IAAIC;AACJ,YAAQ,WAAW,MAAnB;KACE,KAAK;AACH,2BAAqB,WAAW;AAChC;KACF,KAAK;AACH,2BAAqB,WAAW,KAAK;AACrC;;AAGJ,QAAI,oBAAoB,sBACtB,OAAM,KAAK,MAAM,GAAG,WAAW,KAAK,IAAI,mBAAmB,IAAI,EAAE,CAAC;;AAGtE,SAAM,KAAK,MAAM;AACjB,SAAM,KAAK,IAAI;AACf,UAAO,MAAM,KAAK,KAAK;;EAEzB,cAAc,SAAS;AACrB,WAAQ,QAAQ,EAAE;AAClB,WAAQ,IAAI,iBAAiB,EAAE;AAC/B,WAAQ,IAAI,aAAa,KAAK,sBAAsB;;EAEvD,EACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fuma-matter-
|
|
1
|
+
{"version":3,"file":"fuma-matter-DL-PfQJ7.js","names":["output: Output"],"sources":["../src/utils/fuma-matter.ts"],"sourcesContent":["/**\n * Inspired by https://github.com/jonschlinkert/gray-matter\n */\nimport { load } from 'js-yaml';\n\ninterface Output {\n /**\n * The matter section, including the delimiter.\n */\n matter: string;\n content: string;\n data: unknown;\n}\n\nconst regex = /^---\\r?\\n(.+?)\\r?\\n---\\r?\\n?/s;\n\n/**\n * parse frontmatter, it supports only yaml format\n */\nexport function fumaMatter(input: string): Output {\n const output: Output = { matter: '', data: {}, content: input };\n const match = regex.exec(input);\n if (!match) {\n return output;\n }\n\n // get the raw front-matter block\n output.matter = match[0];\n output.content = input.slice(match[0].length);\n\n const loaded = load(match[1]);\n output.data = loaded ?? {};\n\n return output;\n}\n"],"mappings":";;;;;;AAcA,MAAM,QAAQ;;;;AAKd,SAAgB,WAAW,OAAuB;CAChD,MAAMA,SAAiB;EAAE,QAAQ;EAAI,MAAM,EAAE;EAAE,SAAS;EAAO;CAC/D,MAAM,QAAQ,MAAM,KAAK,MAAM;AAC/B,KAAI,CAAC,MACH,QAAO;AAIT,QAAO,SAAS,MAAM;AACtB,QAAO,UAAU,MAAM,MAAM,MAAM,GAAG,OAAO;AAG7C,QAAO,OADQ,KAAK,MAAM,GAAG,IACL,EAAE;AAE1B,QAAO"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as fumaMatter } from "./fuma-matter-
|
|
2
|
-
import { n as ident, r as slash, t as createCodegen } from "./codegen-
|
|
3
|
-
import fs from "node:fs/promises";
|
|
1
|
+
import { t as fumaMatter } from "./fuma-matter-DL-PfQJ7.js";
|
|
2
|
+
import { n as ident, r as slash, t as createCodegen } from "./codegen-Dd9ILNOr.js";
|
|
4
3
|
import path from "node:path";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
5
|
import { glob } from "tinyglobby";
|
|
6
6
|
import path$1 from "path";
|
|
7
7
|
import { createHash } from "crypto";
|
|
@@ -261,4 +261,4 @@ function generateMetaCollectionGlob({ codegen, workspace }, collection, eager =
|
|
|
261
261
|
|
|
262
262
|
//#endregion
|
|
263
263
|
export { indexFile as t };
|
|
264
|
-
//# sourceMappingURL=index-file-
|
|
264
|
+
//# sourceMappingURL=index-file-B3LmDGdu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-file-Bil6OoJJ.js","names":["dynamicCollections: CollectionItem[]","serverOptions: ServerOptions","typeConfigs: string[]","out: Promise<EmitEntry>[]","metaGlob","partialOptions: CoreOptions","path","infoStr: string[]","collection: DocCollectionItem | undefined"],"sources":["../src/utils/fs-cache.ts","../src/plugins/index-file.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\n\nconst map = new Map<string, Promise<string>>();\n\nexport function createFSCache() {\n return {\n read(file: string): Promise<string> {\n const fullPath = toFullPath(file);\n const cached = map.get(fullPath);\n if (cached) return cached;\n\n const read = fs.readFile(fullPath).then((s) => s.toString());\n map.set(fullPath, read);\n return read;\n },\n\n delete(file: string) {\n map.delete(toFullPath(file));\n },\n };\n}\n\n/**\n * make file paths relative to cwd\n */\nfunction toFullPath(file: string) {\n if (path.isAbsolute(file)) {\n return path.relative(process.cwd(), file);\n }\n\n return file;\n}\n","import type { Core, CoreOptions, Plugin, PluginContext } from '@/core';\nimport type { CollectionItem, DocCollectionItem, MetaCollectionItem } from '@/config/build';\nimport path from 'path';\nimport { type CodeGen, createCodegen, ident, slash } from '@/utils/codegen';\nimport { glob } from 'tinyglobby';\nimport { createFSCache } from '@/utils/fs-cache';\nimport { createHash } from 'crypto';\nimport type { LazyEntry } from '@/runtime/dynamic';\nimport type { EmitEntry } from '@/core';\nimport { fumaMatter } from '@/utils/fuma-matter';\nimport type { ServerOptions } from '@/runtime/server';\n\nexport interface IndexFilePluginOptions {\n target?: 'default' | 'vite';\n\n /**\n * add `.js` extensions to imports, needed for ESM without bundler resolution\n */\n addJsExtension?: boolean;\n\n /**\n * Generate entry point for browser\n * @defaultValue true\n */\n browser?: boolean;\n\n /**\n * Generate entry point for dynamic compilation\n * @defaultValue true\n */\n dynamic?: boolean;\n}\n\nexport interface IndexFilePlugin {\n ['index-file']?: {\n generateTypeConfig?: (this: PluginContext) => string | void;\n serverOptions?: (this: PluginContext, options: ServerOptions) => void;\n };\n}\n\ninterface FileGenContext {\n core: Core;\n workspace?: string;\n codegen: CodeGen;\n serverOptions: ServerOptions;\n tc: string;\n}\n\nconst indexFileCache = createFSCache();\n\nexport default function indexFile(options: IndexFilePluginOptions = {}): Plugin {\n const { target = 'default', addJsExtension, browser = true, dynamic = true } = options;\n let dynamicCollections: CollectionItem[];\n\n function isDynamic(collection: CollectionItem) {\n return (\n (collection.type === 'docs' && collection.docs.dynamic) ||\n (collection.type === 'doc' && collection.dynamic)\n );\n }\n\n function generateConfigs(core: Core): {\n serverOptions: ServerOptions;\n tc: string;\n } {\n const serverOptions: ServerOptions = {};\n const typeConfigs: string[] = ['import(\"@hanzo/docs-mdx/runtime/types\").InternalTypeConfig'];\n const ctx = core.getPluginContext();\n\n for (const plugin of core.getPlugins()) {\n const indexFilePlugin = plugin['index-file'];\n if (!indexFilePlugin) continue;\n\n indexFilePlugin.serverOptions?.call(ctx, serverOptions);\n const config = indexFilePlugin.generateTypeConfig?.call(ctx);\n if (config) typeConfigs.push(config);\n }\n\n return {\n serverOptions,\n tc: typeConfigs.join(' & '),\n };\n }\n\n return {\n name: 'index-file',\n config() {\n dynamicCollections = this.core.getCollections().filter(isDynamic);\n },\n configureServer(server) {\n if (!server.watcher) return;\n\n server.watcher.on('all', async (event, file) => {\n indexFileCache.delete(file);\n\n // dynamic collections always require re-generation on change\n if (dynamicCollections.length === 0) {\n // vite uses `import.meta.glob`, no need to re-generate\n if (target === 'vite') return;\n // only re-generate when adding/deleting entries\n if (target === 'default' && event === 'change') return;\n }\n\n const updatedCollection = this.core\n .getCollections()\n .find((collection) => collection.hasFile(file));\n\n if (!updatedCollection) return;\n if (!isDynamic(updatedCollection)) {\n if (target === 'vite') return;\n if (target === 'default' && event === 'change') return;\n }\n\n await this.core.emit({\n filterPlugin: (plugin) => plugin.name === 'index-file',\n filterWorkspace: () => false,\n write: true,\n });\n });\n },\n async emit() {\n const globCache = new Map<string, Promise<string[]>>();\n const { workspace, outDir } = this.core.getOptions();\n const { serverOptions, tc } = generateConfigs(this.core);\n const toEmitEntry = async (\n path: string,\n content: (ctx: FileGenContext) => Promise<void>,\n ): Promise<EmitEntry> => {\n const codegen = createCodegen({\n target,\n outDir: outDir,\n jsExtension: addJsExtension,\n globCache,\n });\n await content({\n core: this.core,\n codegen,\n serverOptions,\n tc,\n workspace: workspace?.name,\n });\n return {\n path,\n content: codegen.toString(),\n };\n };\n\n const out: Promise<EmitEntry>[] = [toEmitEntry('server.ts', generateServerIndexFile)];\n\n if (dynamic) out.push(toEmitEntry('dynamic.ts', generateDynamicIndexFile));\n\n if (browser) out.push(toEmitEntry('browser.ts', generateBrowserIndexFile));\n\n return await Promise.all(out);\n },\n };\n}\n\nasync function generateServerIndexFile(ctx: FileGenContext) {\n const { core, codegen, serverOptions, tc } = ctx;\n codegen.lines.push(\n `import { server } from '@hanzo/docs-mdx/runtime/server';`,\n `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,\n '',\n `const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`,\n );\n\n async function generateCollectionObject(collection: CollectionItem): Promise<string | undefined> {\n const base = getBase(collection);\n\n switch (collection.type) {\n case 'docs': {\n if (collection.docs.dynamic) return;\n\n if (collection.docs.async) {\n const [metaGlob, headGlob, bodyGlob] = await Promise.all([\n generateMetaCollectionGlob(ctx, collection.meta, true),\n generateDocCollectionFrontmatterGlob(ctx, collection.docs, true),\n generateDocCollectionGlob(ctx, collection.docs),\n ]);\n\n return `await create.docsLazy(\"${collection.name}\", \"${base}\", ${metaGlob}, ${headGlob}, ${bodyGlob})`;\n }\n\n const [metaGlob, docGlob] = await Promise.all([\n generateMetaCollectionGlob(ctx, collection.meta, true),\n generateDocCollectionGlob(ctx, collection.docs, true),\n ]);\n\n return `await create.docs(\"${collection.name}\", \"${base}\", ${metaGlob}, ${docGlob})`;\n }\n case 'doc':\n if (collection.dynamic) return;\n\n if (collection.async) {\n const [headGlob, bodyGlob] = await Promise.all([\n generateDocCollectionFrontmatterGlob(ctx, collection, true),\n generateDocCollectionGlob(ctx, collection),\n ]);\n\n return `await create.docLazy(\"${collection.name}\", \"${base}\", ${headGlob}, ${bodyGlob})`;\n }\n\n return `await create.doc(\"${collection.name}\", \"${base}\", ${await generateDocCollectionGlob(\n ctx,\n collection,\n true,\n )})`;\n case 'meta':\n return `await create.meta(\"${collection.name}\", \"${base}\", ${await generateMetaCollectionGlob(\n ctx,\n collection,\n true,\n )})`;\n }\n }\n\n await codegen.pushAsync(\n core.getCollections().map(async (collection) => {\n const obj = await generateCollectionObject(collection);\n if (!obj) return;\n\n return `\\nexport const ${collection.name} = ${obj};`;\n }),\n );\n}\n\nasync function generateDynamicIndexFile(ctx: FileGenContext) {\n const { core, codegen, serverOptions, tc } = ctx;\n const { configPath, environment, outDir } = core.getOptions();\n // serializable config options\n const partialOptions: CoreOptions = {\n configPath,\n environment,\n outDir,\n };\n codegen.lines.push(\n `import { dynamic } from '@hanzo/docs-mdx/runtime/dynamic';`,\n `import * as Config from '${codegen.formatImportPath(configPath)}';`,\n '',\n `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(partialOptions)}, ${JSON.stringify(serverOptions)});`,\n );\n\n async function generateCollectionObjectEntry(\n collection: DocCollectionItem,\n absolutePath: string,\n ) {\n const fullPath = path.relative(process.cwd(), absolutePath);\n const content = await indexFileCache.read(fullPath).catch(() => '');\n const parsed = fumaMatter(content);\n const data = await core.transformFrontmatter(\n {\n collection,\n filePath: fullPath,\n source: content,\n },\n parsed.data as Record<string, unknown>,\n );\n\n const hash = createHash('md5').update(content).digest('hex');\n const infoStr: string[] = [\n // make sure it's included in vercel/nft\n `absolutePath: path.resolve(${JSON.stringify(fullPath)})`,\n ];\n for (const [k, v] of Object.entries({\n info: {\n fullPath,\n path: path.relative(collection.dir, absolutePath),\n },\n data,\n hash,\n } satisfies LazyEntry)) {\n infoStr.push(`${k}: ${JSON.stringify(v)}`);\n }\n\n return `{ ${infoStr.join(', ')} }`;\n }\n\n async function generateCollectionObject(parent: CollectionItem): Promise<string | undefined> {\n let collection: DocCollectionItem | undefined;\n if (parent.type === 'doc') collection = parent;\n else if (parent.type === 'docs') collection = parent.docs;\n\n if (!collection || !collection.dynamic) return;\n\n const files = await glob(collection.patterns, {\n cwd: collection.dir,\n absolute: true,\n });\n const entries = await Promise.all(\n files.map((file) => generateCollectionObjectEntry(collection, file)),\n );\n\n switch (parent.type) {\n case 'docs': {\n const metaGlob = await generateMetaCollectionGlob(ctx, parent.meta, true);\n\n return `await create.docs(\"${parent.name}\", \"${getBase(parent)}\", ${metaGlob}, ${entries.join(', ')})`;\n }\n case 'doc':\n return `await create.doc(\"${collection.name}\", \"${getBase(collection)}\", ${entries.join(', ')})`;\n }\n }\n\n await codegen.pushAsync(\n core.getCollections().map(async (collection) => {\n const obj = await generateCollectionObject(collection);\n if (!obj) return;\n\n return `\\nexport const ${collection.name} = ${obj};`;\n }),\n );\n}\n\nasync function generateBrowserIndexFile(ctx: FileGenContext) {\n const { core, codegen, tc } = ctx;\n codegen.lines.push(\n `import { browser } from '@hanzo/docs-mdx/runtime/browser';`,\n `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,\n '',\n `const create = browser<typeof Config, ${tc}>();`,\n );\n\n async function generateCollectionObject(collection: CollectionItem): Promise<string | undefined> {\n switch (collection.type) {\n case 'docs': {\n if (collection.docs.dynamic) return;\n\n return generateCollectionObject(collection.docs);\n }\n case 'doc':\n if (collection.dynamic) return;\n\n return `create.doc(\"${collection.name}\", ${await generateDocCollectionGlob(ctx, collection)})`;\n }\n }\n\n codegen.lines.push('const browserCollections = {');\n\n await codegen.pushAsync(\n core.getCollections().map(async (collection) => {\n const obj = await generateCollectionObject(collection);\n if (!obj) return;\n\n return ident(`${collection.name}: ${obj},`);\n }),\n );\n\n codegen.lines.push('};', 'export default browserCollections;');\n}\n\nfunction getBase(collection: CollectionItem) {\n return slash(path.relative(process.cwd(), collection.dir));\n}\n\nfunction generateDocCollectionFrontmatterGlob(\n { codegen, workspace }: FileGenContext,\n collection: DocCollectionItem,\n eager = false,\n) {\n return codegen.generateGlobImport(collection.patterns, {\n query: {\n collection: collection.name,\n only: 'frontmatter',\n workspace,\n },\n import: 'frontmatter',\n base: collection.dir,\n eager,\n });\n}\n\nfunction generateDocCollectionGlob(\n { codegen, workspace }: FileGenContext,\n collection: DocCollectionItem,\n eager = false,\n) {\n return codegen.generateGlobImport(collection.patterns, {\n query: {\n collection: collection.name,\n workspace,\n },\n base: collection.dir,\n eager,\n });\n}\n\nfunction generateMetaCollectionGlob(\n { codegen, workspace }: FileGenContext,\n collection: MetaCollectionItem,\n eager = false,\n) {\n return codegen.generateGlobImport(collection.patterns, {\n query: {\n collection: collection.name,\n workspace,\n },\n import: 'default',\n base: collection.dir,\n eager,\n });\n}\n"],"mappings":";;;;;;;;;AAGA,MAAM,sBAAM,IAAI,KAA8B;AAE9C,SAAgB,gBAAgB;AAC9B,QAAO;EACL,KAAK,MAA+B;GAClC,MAAM,WAAW,WAAW,KAAK;GACjC,MAAM,SAAS,IAAI,IAAI,SAAS;AAChC,OAAI,OAAQ,QAAO;GAEnB,MAAM,OAAO,GAAG,SAAS,SAAS,CAAC,MAAM,MAAM,EAAE,UAAU,CAAC;AAC5D,OAAI,IAAI,UAAU,KAAK;AACvB,UAAO;;EAGT,OAAO,MAAc;AACnB,OAAI,OAAO,WAAW,KAAK,CAAC;;EAE/B;;;;;AAMH,SAAS,WAAW,MAAc;AAChC,KAAI,KAAK,WAAW,KAAK,CACvB,QAAO,KAAK,SAAS,QAAQ,KAAK,EAAE,KAAK;AAG3C,QAAO;;;;;ACiBT,MAAM,iBAAiB,eAAe;AAEtC,SAAwB,UAAU,UAAkC,EAAE,EAAU;CAC9E,MAAM,EAAE,SAAS,WAAW,gBAAgB,UAAU,MAAM,UAAU,SAAS;CAC/E,IAAIA;CAEJ,SAAS,UAAU,YAA4B;AAC7C,SACG,WAAW,SAAS,UAAU,WAAW,KAAK,WAC9C,WAAW,SAAS,SAAS,WAAW;;CAI7C,SAAS,gBAAgB,MAGvB;EACA,MAAMC,gBAA+B,EAAE;EACvC,MAAMC,cAAwB,CAAC,+DAA6D;EAC5F,MAAM,MAAM,KAAK,kBAAkB;AAEnC,OAAK,MAAM,UAAU,KAAK,YAAY,EAAE;GACtC,MAAM,kBAAkB,OAAO;AAC/B,OAAI,CAAC,gBAAiB;AAEtB,mBAAgB,eAAe,KAAK,KAAK,cAAc;GACvD,MAAM,SAAS,gBAAgB,oBAAoB,KAAK,IAAI;AAC5D,OAAI,OAAQ,aAAY,KAAK,OAAO;;AAGt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B,KAAK,WAAW,CAAC;;;AAIlG,SAAQ,MAAM,KAAK,+BAA+B;AAElD,OAAM,QAAQ,UACZ,KAAK,gBAAgB,CAAC,IAAI,OAAO,eAAe;EAC9C,MAAM,MAAM,MAAM,yBAAyB,WAAW;AACtD,MAAI,CAAC,IAAK;AAEV,SAAO,MAAM,GAAG,WAAW,KAAK,IAAI,IAAI,GAAG;GAC3C,CACH;AAED,SAAQ,MAAM,KAAK,MAAM,qCAAqC;;AAGhE,SAAS,QAAQ,YAA4B;AAC3C,QAAO,MAAMF,OAAK,SAAS,QAAQ,KAAK,EAAE,WAAW,IAAI,CAAC;;AAG5D,SAAS,qCACP,EAAE,SAAS,aACX,YACA,QAAQ,OACR;AACA,QAAO,QAAQ,mBAAmB,WAAW,UAAU;EACrD,OAAO;GACL,YAAY,WAAW;GACvB,MAAM;GACN;GACD;EACD,QAAQ;EACR,MAAM,WAAW;EACjB;EACD,CAAC;;AAGJ,SAAS,0BACP,EAAE,SAAS,aACX,YACA,QAAQ,OACR;AACA,QAAO,QAAQ,mBAAmB,WAAW,UAAU;EACrD,OAAO;GACL,YAAY,WAAW;GACvB;GACD;EACD,MAAM,WAAW;EACjB;EACD,CAAC;;AAGJ,SAAS,2BACP,EAAE,SAAS,aACX,YACA,QAAQ,OACR;AACA,QAAO,QAAQ,mBAAmB,WAAW,UAAU;EACrD,OAAO;GACL,YAAY,WAAW;GACvB;GACD;EACD,QAAQ;EACR,MAAM,WAAW;EACjB;EACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index-file-B3LmDGdu.js","names":["dynamicCollections: CollectionItem[]","serverOptions: ServerOptions","typeConfigs: string[]","out: Promise<EmitEntry>[]","metaGlob","partialOptions: CoreOptions","path","infoStr: string[]","collection: DocCollectionItem | undefined"],"sources":["../src/utils/fs-cache.ts","../src/plugins/index-file.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\n\nconst map = new Map<string, Promise<string>>();\n\nexport function createFSCache() {\n return {\n read(file: string): Promise<string> {\n const fullPath = toFullPath(file);\n const cached = map.get(fullPath);\n if (cached) return cached;\n\n const read = fs.readFile(fullPath).then((s) => s.toString());\n map.set(fullPath, read);\n return read;\n },\n\n delete(file: string) {\n map.delete(toFullPath(file));\n },\n };\n}\n\n/**\n * make file paths relative to cwd\n */\nfunction toFullPath(file: string) {\n if (path.isAbsolute(file)) {\n return path.relative(process.cwd(), file);\n }\n\n return file;\n}\n","import type { Core, CoreOptions, Plugin, PluginContext } from '@/core';\nimport type { CollectionItem, DocCollectionItem, MetaCollectionItem } from '@/config/build';\nimport path from 'path';\nimport { type CodeGen, createCodegen, ident, slash } from '@/utils/codegen';\nimport { glob } from 'tinyglobby';\nimport { createFSCache } from '@/utils/fs-cache';\nimport { createHash } from 'crypto';\nimport type { LazyEntry } from '@/runtime/dynamic';\nimport type { EmitEntry } from '@/core';\nimport { fumaMatter } from '@/utils/fuma-matter';\nimport type { ServerOptions } from '@/runtime/server';\n\nexport interface IndexFilePluginOptions {\n target?: 'default' | 'vite';\n\n /**\n * add `.js` extensions to imports, needed for ESM without bundler resolution\n */\n addJsExtension?: boolean;\n\n /**\n * Generate entry point for browser\n * @defaultValue true\n */\n browser?: boolean;\n\n /**\n * Generate entry point for dynamic compilation\n * @defaultValue true\n */\n dynamic?: boolean;\n}\n\nexport interface IndexFilePlugin {\n ['index-file']?: {\n generateTypeConfig?: (this: PluginContext) => string | void;\n serverOptions?: (this: PluginContext, options: ServerOptions) => void;\n };\n}\n\ninterface FileGenContext {\n core: Core;\n workspace?: string;\n codegen: CodeGen;\n serverOptions: ServerOptions;\n tc: string;\n}\n\nconst indexFileCache = createFSCache();\n\nexport default function indexFile(options: IndexFilePluginOptions = {}): Plugin {\n const { target = 'default', addJsExtension, browser = true, dynamic = true } = options;\n let dynamicCollections: CollectionItem[];\n\n function isDynamic(collection: CollectionItem) {\n return (\n (collection.type === 'docs' && collection.docs.dynamic) ||\n (collection.type === 'doc' && collection.dynamic)\n );\n }\n\n function generateConfigs(core: Core): {\n serverOptions: ServerOptions;\n tc: string;\n } {\n const serverOptions: ServerOptions = {};\n const typeConfigs: string[] = ['import(\"@hanzo/docs-mdx/runtime/types\").InternalTypeConfig'];\n const ctx = core.getPluginContext();\n\n for (const plugin of core.getPlugins()) {\n const indexFilePlugin = plugin['index-file'];\n if (!indexFilePlugin) continue;\n\n indexFilePlugin.serverOptions?.call(ctx, serverOptions);\n const config = indexFilePlugin.generateTypeConfig?.call(ctx);\n if (config) typeConfigs.push(config);\n }\n\n return {\n serverOptions,\n tc: typeConfigs.join(' & '),\n };\n }\n\n return {\n name: 'index-file',\n config() {\n dynamicCollections = this.core.getCollections().filter(isDynamic);\n },\n configureServer(server) {\n if (!server.watcher) return;\n\n server.watcher.on('all', async (event, file) => {\n indexFileCache.delete(file);\n\n // dynamic collections always require re-generation on change\n if (dynamicCollections.length === 0) {\n // vite uses `import.meta.glob`, no need to re-generate\n if (target === 'vite') return;\n // only re-generate when adding/deleting entries\n if (target === 'default' && event === 'change') return;\n }\n\n const updatedCollection = this.core\n .getCollections()\n .find((collection) => collection.hasFile(file));\n\n if (!updatedCollection) return;\n if (!isDynamic(updatedCollection)) {\n if (target === 'vite') return;\n if (target === 'default' && event === 'change') return;\n }\n\n await this.core.emit({\n filterPlugin: (plugin) => plugin.name === 'index-file',\n filterWorkspace: () => false,\n write: true,\n });\n });\n },\n async emit() {\n const globCache = new Map<string, Promise<string[]>>();\n const { workspace, outDir } = this.core.getOptions();\n const { serverOptions, tc } = generateConfigs(this.core);\n const toEmitEntry = async (\n path: string,\n content: (ctx: FileGenContext) => Promise<void>,\n ): Promise<EmitEntry> => {\n const codegen = createCodegen({\n target,\n outDir: outDir,\n jsExtension: addJsExtension,\n globCache,\n });\n await content({\n core: this.core,\n codegen,\n serverOptions,\n tc,\n workspace: workspace?.name,\n });\n return {\n path,\n content: codegen.toString(),\n };\n };\n\n const out: Promise<EmitEntry>[] = [toEmitEntry('server.ts', generateServerIndexFile)];\n\n if (dynamic) out.push(toEmitEntry('dynamic.ts', generateDynamicIndexFile));\n\n if (browser) out.push(toEmitEntry('browser.ts', generateBrowserIndexFile));\n\n return await Promise.all(out);\n },\n };\n}\n\nasync function generateServerIndexFile(ctx: FileGenContext) {\n const { core, codegen, serverOptions, tc } = ctx;\n codegen.lines.push(\n `import { server } from '@hanzo/docs-mdx/runtime/server';`,\n `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,\n '',\n `const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`,\n );\n\n async function generateCollectionObject(collection: CollectionItem): Promise<string | undefined> {\n const base = getBase(collection);\n\n switch (collection.type) {\n case 'docs': {\n if (collection.docs.dynamic) return;\n\n if (collection.docs.async) {\n const [metaGlob, headGlob, bodyGlob] = await Promise.all([\n generateMetaCollectionGlob(ctx, collection.meta, true),\n generateDocCollectionFrontmatterGlob(ctx, collection.docs, true),\n generateDocCollectionGlob(ctx, collection.docs),\n ]);\n\n return `await create.docsLazy(\"${collection.name}\", \"${base}\", ${metaGlob}, ${headGlob}, ${bodyGlob})`;\n }\n\n const [metaGlob, docGlob] = await Promise.all([\n generateMetaCollectionGlob(ctx, collection.meta, true),\n generateDocCollectionGlob(ctx, collection.docs, true),\n ]);\n\n return `await create.docs(\"${collection.name}\", \"${base}\", ${metaGlob}, ${docGlob})`;\n }\n case 'doc':\n if (collection.dynamic) return;\n\n if (collection.async) {\n const [headGlob, bodyGlob] = await Promise.all([\n generateDocCollectionFrontmatterGlob(ctx, collection, true),\n generateDocCollectionGlob(ctx, collection),\n ]);\n\n return `await create.docLazy(\"${collection.name}\", \"${base}\", ${headGlob}, ${bodyGlob})`;\n }\n\n return `await create.doc(\"${collection.name}\", \"${base}\", ${await generateDocCollectionGlob(\n ctx,\n collection,\n true,\n )})`;\n case 'meta':\n return `await create.meta(\"${collection.name}\", \"${base}\", ${await generateMetaCollectionGlob(\n ctx,\n collection,\n true,\n )})`;\n }\n }\n\n await codegen.pushAsync(\n core.getCollections().map(async (collection) => {\n const obj = await generateCollectionObject(collection);\n if (!obj) return;\n\n return `\\nexport const ${collection.name} = ${obj};`;\n }),\n );\n}\n\nasync function generateDynamicIndexFile(ctx: FileGenContext) {\n const { core, codegen, serverOptions, tc } = ctx;\n const { configPath, environment, outDir } = core.getOptions();\n // serializable config options\n const partialOptions: CoreOptions = {\n configPath,\n environment,\n outDir,\n };\n codegen.lines.push(\n `import { dynamic } from '@hanzo/docs-mdx/runtime/dynamic';`,\n `import * as Config from '${codegen.formatImportPath(configPath)}';`,\n '',\n `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(partialOptions)}, ${JSON.stringify(serverOptions)});`,\n );\n\n async function generateCollectionObjectEntry(\n collection: DocCollectionItem,\n absolutePath: string,\n ) {\n const fullPath = path.relative(process.cwd(), absolutePath);\n const content = await indexFileCache.read(fullPath).catch(() => '');\n const parsed = fumaMatter(content);\n const data = await core.transformFrontmatter(\n {\n collection,\n filePath: fullPath,\n source: content,\n },\n parsed.data as Record<string, unknown>,\n );\n\n const hash = createHash('md5').update(content).digest('hex');\n const infoStr: string[] = [\n // make sure it's included in vercel/nft\n `absolutePath: path.resolve(${JSON.stringify(fullPath)})`,\n ];\n for (const [k, v] of Object.entries({\n info: {\n fullPath,\n path: path.relative(collection.dir, absolutePath),\n },\n data,\n hash,\n } satisfies LazyEntry)) {\n infoStr.push(`${k}: ${JSON.stringify(v)}`);\n }\n\n return `{ ${infoStr.join(', ')} }`;\n }\n\n async function generateCollectionObject(parent: CollectionItem): Promise<string | undefined> {\n let collection: DocCollectionItem | undefined;\n if (parent.type === 'doc') collection = parent;\n else if (parent.type === 'docs') collection = parent.docs;\n\n if (!collection || !collection.dynamic) return;\n\n const files = await glob(collection.patterns, {\n cwd: collection.dir,\n absolute: true,\n });\n const entries = await Promise.all(\n files.map((file) => generateCollectionObjectEntry(collection, file)),\n );\n\n switch (parent.type) {\n case 'docs': {\n const metaGlob = await generateMetaCollectionGlob(ctx, parent.meta, true);\n\n return `await create.docs(\"${parent.name}\", \"${getBase(parent)}\", ${metaGlob}, ${entries.join(', ')})`;\n }\n case 'doc':\n return `await create.doc(\"${collection.name}\", \"${getBase(collection)}\", ${entries.join(', ')})`;\n }\n }\n\n await codegen.pushAsync(\n core.getCollections().map(async (collection) => {\n const obj = await generateCollectionObject(collection);\n if (!obj) return;\n\n return `\\nexport const ${collection.name} = ${obj};`;\n }),\n );\n}\n\nasync function generateBrowserIndexFile(ctx: FileGenContext) {\n const { core, codegen, tc } = ctx;\n codegen.lines.push(\n `import { browser } from '@hanzo/docs-mdx/runtime/browser';`,\n `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,\n '',\n `const create = browser<typeof Config, ${tc}>();`,\n );\n\n async function generateCollectionObject(collection: CollectionItem): Promise<string | undefined> {\n switch (collection.type) {\n case 'docs': {\n if (collection.docs.dynamic) return;\n\n return generateCollectionObject(collection.docs);\n }\n case 'doc':\n if (collection.dynamic) return;\n\n return `create.doc(\"${collection.name}\", ${await generateDocCollectionGlob(ctx, collection)})`;\n }\n }\n\n codegen.lines.push('const browserCollections = {');\n\n await codegen.pushAsync(\n core.getCollections().map(async (collection) => {\n const obj = await generateCollectionObject(collection);\n if (!obj) return;\n\n return ident(`${collection.name}: ${obj},`);\n }),\n );\n\n codegen.lines.push('};', 'export default browserCollections;');\n}\n\nfunction getBase(collection: CollectionItem) {\n return slash(path.relative(process.cwd(), collection.dir));\n}\n\nfunction generateDocCollectionFrontmatterGlob(\n { codegen, workspace }: FileGenContext,\n collection: DocCollectionItem,\n eager = false,\n) {\n return codegen.generateGlobImport(collection.patterns, {\n query: {\n collection: collection.name,\n only: 'frontmatter',\n workspace,\n },\n import: 'frontmatter',\n base: collection.dir,\n eager,\n });\n}\n\nfunction generateDocCollectionGlob(\n { codegen, workspace }: FileGenContext,\n collection: DocCollectionItem,\n eager = false,\n) {\n return codegen.generateGlobImport(collection.patterns, {\n query: {\n collection: collection.name,\n workspace,\n },\n base: collection.dir,\n eager,\n });\n}\n\nfunction generateMetaCollectionGlob(\n { codegen, workspace }: FileGenContext,\n collection: MetaCollectionItem,\n eager = false,\n) {\n return codegen.generateGlobImport(collection.patterns, {\n query: {\n collection: collection.name,\n workspace,\n },\n import: 'default',\n base: collection.dir,\n eager,\n });\n}\n"],"mappings":";;;;;;;;;AAGA,MAAM,sBAAM,IAAI,KAA8B;AAE9C,SAAgB,gBAAgB;AAC9B,QAAO;EACL,KAAK,MAA+B;GAClC,MAAM,WAAW,WAAW,KAAK;GACjC,MAAM,SAAS,IAAI,IAAI,SAAS;AAChC,OAAI,OAAQ,QAAO;GAEnB,MAAM,OAAO,GAAG,SAAS,SAAS,CAAC,MAAM,MAAM,EAAE,UAAU,CAAC;AAC5D,OAAI,IAAI,UAAU,KAAK;AACvB,UAAO;;EAGT,OAAO,MAAc;AACnB,OAAI,OAAO,WAAW,KAAK,CAAC;;EAE/B;;;;;AAMH,SAAS,WAAW,MAAc;AAChC,KAAI,KAAK,WAAW,KAAK,CACvB,QAAO,KAAK,SAAS,QAAQ,KAAK,EAAE,KAAK;AAG3C,QAAO;;;;;ACiBT,MAAM,iBAAiB,eAAe;AAEtC,SAAwB,UAAU,UAAkC,EAAE,EAAU;CAC9E,MAAM,EAAE,SAAS,WAAW,gBAAgB,UAAU,MAAM,UAAU,SAAS;CAC/E,IAAIA;CAEJ,SAAS,UAAU,YAA4B;AAC7C,SACG,WAAW,SAAS,UAAU,WAAW,KAAK,WAC9C,WAAW,SAAS,SAAS,WAAW;;CAI7C,SAAS,gBAAgB,MAGvB;EACA,MAAMC,gBAA+B,EAAE;EACvC,MAAMC,cAAwB,CAAC,+DAA6D;EAC5F,MAAM,MAAM,KAAK,kBAAkB;AAEnC,OAAK,MAAM,UAAU,KAAK,YAAY,EAAE;GACtC,MAAM,kBAAkB,OAAO;AAC/B,OAAI,CAAC,gBAAiB;AAEtB,mBAAgB,eAAe,KAAK,KAAK,cAAc;GACvD,MAAM,SAAS,gBAAgB,oBAAoB,KAAK,IAA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AExB,WAAO,eAAe,WAAW,KAAK,KAAK,MAAM,0BAA0B,KAAK,WAAW,CAAC;;;AAIlG,SAAQ,MAAM,KAAK,+BAA+B;AAElD,OAAM,QAAQ,UACZ,KAAK,gBAAgB,CAAC,IAAI,OAAO,eAAe;EAC9C,MAAM,MAAM,MAAM,yBAAyB,WAAW;AACtD,MAAI,CAAC,IAAK;AAEV,SAAO,MAAM,GAAG,WAAW,KAAK,IAAI,IAAI,GAAG;GAC3C,CACH;AAED,SAAQ,MAAM,KAAK,MAAM,qCAAqC;;AAGhE,SAAS,QAAQ,YAA4B;AAC3C,QAAO,MAAMF,OAAK,SAAS,QAAQ,KAAK,EAAE,WAAW,IAAI,CAAC;;AAG5D,SAAS,qCACP,EAAE,SAAS,aACX,YACA,QAAQ,OACR;AACA,QAAO,QAAQ,mBAAmB,WAAW,UAAU;EACrD,OAAO;GACL,YAAY,WAAW;GACvB,MAAM;GACN;GACD;EACD,QAAQ;EACR,MAAM,WAAW;EACjB;EACD,CAAC;;AAGJ,SAAS,0BACP,EAAE,SAAS,aACX,YACA,QAAQ,OACR;AACA,QAAO,QAAQ,mBAAmB,WAAW,UAAU;EACrD,OAAO;GACL,YAAY,WAAW;GACvB;GACD;EACD,MAAM,WAAW;EACjB;EACD,CAAC;;AAGJ,SAAS,2BACP,EAAE,SAAS,aACX,YACA,QAAQ,OACR;AACA,QAAO,QAAQ,mBAAmB,WAAW,UAAU;EACrD,OAAO;GACL,YAAY,WAAW;GACvB;GACD;EACD,QAAQ;EACR,MAAM,WAAW;EACjB;EACD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as buildConfig } from "./build-
|
|
1
|
+
import { t as buildConfig } from "./build-GdAvxpd7.js";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
|
|
4
4
|
//#region src/config/load-from-file.ts
|
|
@@ -35,4 +35,4 @@ async function loadConfig(core, build = false) {
|
|
|
35
35
|
|
|
36
36
|
//#endregion
|
|
37
37
|
export { loadConfig as t };
|
|
38
|
-
//# sourceMappingURL=load-from-file-
|
|
38
|
+
//# sourceMappingURL=load-from-file-dsGIDpOc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-from-file-
|
|
1
|
+
{"version":3,"file":"load-from-file-dsGIDpOc.js","names":[],"sources":["../src/config/load-from-file.ts"],"sourcesContent":["import { pathToFileURL } from 'node:url';\nimport type { LoadedConfig } from '@/config/build';\nimport { buildConfig } from '@/config/build';\nimport type { Core } from '@/core';\n\nasync function compileConfig(core: Core) {\n const { build } = await import('esbuild');\n const { configPath, outDir } = core.getOptions();\n\n const transformed = await build({\n entryPoints: [{ in: configPath, out: 'source.config' }],\n bundle: true,\n outdir: outDir,\n target: 'node20',\n write: true,\n platform: 'node',\n format: 'esm',\n packages: 'external',\n outExtension: {\n '.js': '.mjs',\n },\n allowOverwrite: true,\n });\n\n if (transformed.errors.length > 0) {\n throw new Error('failed to compile configuration file');\n }\n}\n\n/**\n * Load config\n *\n * @param build - By default, it assumes the config file has been compiled. Set this `true` to compile the config first.\n */\nexport async function loadConfig(core: Core, build = false): Promise<LoadedConfig> {\n if (build) await compileConfig(core);\n\n const url = pathToFileURL(core.getCompiledConfigPath());\n // always return a new config\n url.searchParams.set('hash', Date.now().toString());\n\n const config = import(url.href).then((loaded) => buildConfig(loaded as Record<string, unknown>));\n\n return await config;\n}\n"],"mappings":";;;;AAKA,eAAe,cAAc,MAAY;CACvC,MAAM,EAAE,UAAU,MAAM,OAAO;CAC/B,MAAM,EAAE,YAAY,WAAW,KAAK,YAAY;AAiBhD,MAfoB,MAAM,MAAM;EAC9B,aAAa,CAAC;GAAE,IAAI;GAAY,KAAK;GAAiB,CAAC;EACvD,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,UAAU;EACV,QAAQ;EACR,UAAU;EACV,cAAc,EACZ,OAAO,QACR;EACD,gBAAgB;EACjB,CAAC,EAEc,OAAO,SAAS,EAC9B,OAAM,IAAI,MAAM,uCAAuC;;;;;;;AAS3D,eAAsB,WAAW,MAAY,QAAQ,OAA8B;AACjF,KAAI,MAAO,OAAM,cAAc,KAAK;CAEpC,MAAM,MAAM,cAAc,KAAK,uBAAuB,CAAC;AAEvD,KAAI,aAAa,IAAI,QAAQ,KAAK,KAAK,CAAC,UAAU,CAAC;AAInD,QAAO,MAFQ,OAAO,IAAI,MAAM,MAAM,WAAW,YAAY,OAAkC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loaders-
|
|
1
|
+
{"version":3,"file":"loaders-Mp-ZCdLT.js","names":[],"sources":["../src/loaders/index.ts"],"sourcesContent":["export const metaLoaderGlob = /\\.(json|yaml)(\\?.+?)?$/;\nexport const mdxLoaderGlob = /\\.mdx?(\\?.+?)?$/;\n"],"mappings":";AAAA,MAAa,iBAAiB;AAC9B,MAAa,gBAAgB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as fumaMatter } from "./fuma-matter-
|
|
2
|
-
import { t as mdxLoaderGlob } from "./loaders-
|
|
1
|
+
import { t as fumaMatter } from "./fuma-matter-DL-PfQJ7.js";
|
|
2
|
+
import { t as mdxLoaderGlob } from "./loaders-Mp-ZCdLT.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import fs from "node:fs/promises";
|
|
5
4
|
import path from "node:path";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
|
|
8
8
|
//#region src/loaders/mdx/index.ts
|
|
@@ -59,7 +59,7 @@ function createMdxLoader({ getCore }) {
|
|
|
59
59
|
code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
|
|
60
60
|
map: null
|
|
61
61
|
};
|
|
62
|
-
const { buildMDX } = await import("./build-mdx-
|
|
62
|
+
const { buildMDX } = await import("./build-mdx-hB1gzgHy.js");
|
|
63
63
|
const compiled = await buildMDX(core, docCollection, {
|
|
64
64
|
isDevelopment,
|
|
65
65
|
source: "\n".repeat(countLines(matter.matter)) + matter.content,
|
|
@@ -88,4 +88,4 @@ function countLines(s) {
|
|
|
88
88
|
|
|
89
89
|
//#endregion
|
|
90
90
|
export { createMdxLoader as t };
|
|
91
|
-
//# sourceMappingURL=mdx-
|
|
91
|
+
//# sourceMappingURL=mdx-CJaKR3FR.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx-
|
|
1
|
+
{"version":3,"file":"mdx-CJaKR3FR.js","names":["after: (() => Promise<void>) | undefined","docCollection: DocCollectionItem | undefined"],"sources":["../src/loaders/mdx/index.ts"],"sourcesContent":["import { fumaMatter } from '@/utils/fuma-matter';\nimport type { SourceMap } from 'rollup';\nimport type { Loader } from '@/loaders/adapter';\nimport { z } from 'zod';\nimport type { DocCollectionItem } from '@/config/build';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { createHash } from 'node:crypto';\nimport type { ConfigLoader } from '@/loaders/config';\nimport { mdxLoaderGlob } from '..';\n\nconst querySchema = z\n .object({\n only: z.literal(['frontmatter', 'all']).default('all'),\n collection: z.string().optional(),\n workspace: z.string().optional(),\n })\n .loose();\n\nconst cacheEntry = z.object({\n code: z.string(),\n map: z.any().optional(),\n hash: z.string().optional(),\n});\n\ntype CacheEntry = z.infer<typeof cacheEntry>;\n\nexport function createMdxLoader({ getCore }: ConfigLoader): Loader {\n return {\n test: mdxLoaderGlob,\n async load({ getSource, development: isDevelopment, query, compiler, filePath }) {\n let core = await getCore();\n const value = await getSource();\n const matter = fumaMatter(value);\n const { collection: collectionName, workspace, only } = querySchema.parse(query);\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n let after: (() => Promise<void>) | undefined;\n\n const { experimentalBuildCache = false } = core.getConfig().global;\n if (!isDevelopment && experimentalBuildCache) {\n const cacheDir = experimentalBuildCache;\n const cacheKey = `${collectionName ?? 'global'}_${generateCacheHash(filePath)}`;\n\n const cached = await fs\n .readFile(path.join(cacheDir, cacheKey))\n .then((content) => cacheEntry.parse(JSON.parse(content.toString())))\n .catch(() => null);\n\n if (cached && cached.hash === generateCacheHash(value)) return cached;\n after = async () => {\n await fs.mkdir(cacheDir, { recursive: true });\n await fs.writeFile(\n path.join(cacheDir, cacheKey),\n JSON.stringify({\n ...out,\n hash: generateCacheHash(value),\n } satisfies CacheEntry),\n );\n };\n }\n\n const collection = collectionName ? core.getCollection(collectionName) : undefined;\n\n let docCollection: DocCollectionItem | undefined;\n switch (collection?.type) {\n case 'doc':\n docCollection = collection;\n break;\n case 'docs':\n docCollection = collection.docs;\n break;\n }\n\n if (docCollection) {\n matter.data = await core.transformFrontmatter(\n { collection: docCollection, filePath, source: value },\n matter.data as Record<string, unknown>,\n );\n }\n\n if (only === 'frontmatter') {\n return {\n code: `export const frontmatter = ${JSON.stringify(matter.data)}`,\n map: null,\n };\n }\n\n const { buildMDX } = await import('@/loaders/mdx/build-mdx');\n const compiled = await buildMDX(core, docCollection, {\n isDevelopment,\n // ensure the line number is correct in errors\n source: '\\n'.repeat(countLines(matter.matter)) + matter.content,\n filePath,\n frontmatter: matter.data as Record<string, unknown>,\n _compiler: compiler,\n environment: 'bundler',\n });\n\n const out = {\n code: String(compiled.value),\n map: compiled.map as SourceMap,\n };\n\n await after?.();\n return out;\n },\n };\n}\n\nfunction generateCacheHash(input: string): string {\n return createHash('md5').update(input).digest('hex');\n}\n\nfunction countLines(s: string) {\n let num = 0;\n\n for (const c of s) {\n if (c === '\\n') num++;\n }\n\n return num;\n}\n"],"mappings":";;;;;;;;AAWA,MAAM,cAAc,EACjB,OAAO;CACN,MAAM,EAAE,QAAQ,CAAC,eAAe,MAAM,CAAC,CAAC,QAAQ,MAAM;CACtD,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC,CACD,OAAO;AAEV,MAAM,aAAa,EAAE,OAAO;CAC1B,MAAM,EAAE,QAAQ;CAChB,KAAK,EAAE,KAAK,CAAC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O,EACtD,OAAO,KACR;AAGH,OAAI,SAAS,cACX,QAAO;IACL,MAAM,8BAA8B,KAAK,UAAU,OAAO,KAAK;IAC/D,KAAK;IACN;GAGH,MAAM,EAAE,aAAa,MAAM,OAAO;GAClC,MAAM,WAAW,MAAM,SAAS,MAAM,eAAe;IACnD;IAEA,QAAQ,KAAK,OAAO,WAAW,OAAO,OAAO,CAAC,GAAG,OAAO;IACxD;IACA,aAAa,OAAO;IACpB,WAAW;IACX,aAAa;IACd,CAAC;GAEF,MAAM,MAAM;IACV,MAAM,OAAO,SAAS,MAAM;IAC5B,KAAK,SAAS;IACf;AAED,SAAM,SAAS;AACf,UAAO;;EAEV;;AAGH,SAAS,kBAAkB,OAAuB;AAChD,QAAO,WAAW,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGtD,SAAS,WAAW,GAAW;CAC7B,IAAI,MAAM;AAEV,MAAK,MAAM,KAAK,EACd,KAAI,MAAM,KAAM;AAGlB,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as metaLoaderGlob } from "./loaders-
|
|
2
|
-
import { load } from "js-yaml";
|
|
1
|
+
import { n as metaLoaderGlob } from "./loaders-Mp-ZCdLT.js";
|
|
3
2
|
import { z } from "zod";
|
|
3
|
+
import { load } from "js-yaml";
|
|
4
4
|
|
|
5
5
|
//#region src/loaders/meta.ts
|
|
6
6
|
const querySchema = z.object({
|
|
@@ -78,4 +78,4 @@ function createMetaLoader({ getCore }, resolve = {}) {
|
|
|
78
78
|
|
|
79
79
|
//#endregion
|
|
80
80
|
export { createMetaLoader as t };
|
|
81
|
-
//# sourceMappingURL=meta-
|
|
81
|
+
//# sourceMappingURL=meta-CKrL1Sl9.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta-
|
|
1
|
+
{"version":3,"file":"meta-CKrL1Sl9.js","names":["metaCollection: MetaCollectionItem | undefined"],"sources":["../src/loaders/meta.ts"],"sourcesContent":["import type { Loader, LoaderInput } from '@/loaders/adapter';\nimport type { ConfigLoader } from '@/loaders/config';\nimport { load } from 'js-yaml';\nimport { z } from 'zod';\nimport { metaLoaderGlob } from '.';\nimport type { MetaCollectionItem } from '@/config/build';\n\nconst querySchema = z\n .object({\n collection: z.string().optional(),\n workspace: z.string().optional(),\n })\n .loose();\n\n/**\n * load meta files, fallback to bundler's built-in plugins when ?collection is unspecified.\n */\nexport function createMetaLoader(\n { getCore }: ConfigLoader,\n resolve: {\n json?: 'json' | 'js';\n yaml?: 'js';\n } = {},\n): Loader {\n const { json: resolveJson = 'js' } = resolve;\n\n function parse(filePath: string, source: string) {\n try {\n if (filePath.endsWith('.json')) return JSON.parse(source);\n if (filePath.endsWith('.yaml')) return load(source);\n } catch (e) {\n throw new Error(`invalid data in ${filePath}`, { cause: e });\n }\n\n throw new Error('Unknown file type ' + filePath);\n }\n\n function onMeta(source: string, { filePath, query }: LoaderInput) {\n const parsed = querySchema.safeParse(query);\n if (!parsed.success || !parsed.data.collection) return null;\n const { collection: collectionName, workspace } = parsed.data;\n\n return async (): Promise<unknown> => {\n let core = await getCore();\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n const collection = core.getCollection(collectionName);\n let metaCollection: MetaCollectionItem | undefined;\n\n switch (collection?.type) {\n case 'meta':\n metaCollection = collection;\n break;\n case 'docs':\n metaCollection = collection.meta;\n break;\n }\n\n const data = parse(filePath, source);\n\n if (!metaCollection) return data;\n return core.transformMeta(\n {\n collection: metaCollection,\n filePath,\n source,\n },\n data,\n );\n };\n }\n\n return {\n test: metaLoaderGlob,\n async load(input) {\n const result = onMeta(await input.getSource(), input);\n if (result === null) return null;\n const data = await result();\n\n if (input.filePath.endsWith('.json')) {\n return {\n moduleType: resolveJson,\n code:\n resolveJson === 'json'\n ? JSON.stringify(data)\n : `export default ${JSON.stringify(data)}`,\n };\n } else {\n return {\n moduleType: 'js',\n code: `export default ${JSON.stringify(data)}`,\n };\n }\n },\n bun: {\n load(source, input) {\n const result = onMeta(source, input);\n if (result === null)\n return {\n loader: 'object',\n exports: parse(input.filePath, source),\n };\n\n return result().then((data) => ({\n loader: 'object',\n exports: { default: data },\n }));\n },\n },\n };\n}\n"],"mappings":";;;;;AAOA,MAAM,cAAc,EACjB,OAAO;CACN,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC,CACD,OAAO;;;;AAKV,SAAgB,iBACd,EAAE,WACF,UAGI,EAAE,EACE;CACR,MAAM,EAAE,MAAM,cAAc,SAAS;CAErC,SAAS,MAAM,UAAkB,QAAgB;AAC/C,MAAI;AACF,OAAI,SAAS,SAAS,QAAQ,CAAE,QAAO,KAAK,MAAM,OAAO;AACzD,OAAI,SAAS,SAAS,QAAQ,CAAE,QAAO,KAAK,OAAO;WAC5C,GAAG;AACV,SAAM,IAAI,MAAM,mBAAmB,YAAY,EAAE,OAAO,GAAG,CAAC;;AAG9D,QAAM,IAAI,MAAM,uBAAuB,SAAS;;CAGlD,SAAS,OAAO,QAAgB,EAAE,UAAU,SAAsB;EAChE,MAAM,SAAS,YAAY,UAAU,MAAM;AAC3C,MAAI,CAAC,OAAO,WAAW,CAAC,OAAO,KAAK,WAAY,QAAO;EACvD,MAAM,EAAE,YAAY,gBAAgB,cAAc,OAAO;AAEzD,SAAO,YAA8B;GACnC,IAAI,OAAO,MAAM,SAAS;AAC1B,OAAI,UACF,QAAO,KAAK,eAAe,CAAC,IAAI,UAAU,IAAI;GAGhD,MAAM,aAAa,KAAK,cAAc,eAAe;GACrD,IAAIA;AAEJ,WAAQ,YAAY,MAApB;IACE,KAAK;AACH,sBAAiB;AACjB;IACF,KAAK;AACH,sBAAiB,WAAW;AAC5B;;GAGJ,MAAM,OAAO,MAAM,UAAU,OAAO;AAEpC,OAAI,CAAC,eAAgB,QAAO;AAC5B,UAAO,KAAK,cACV;IACE,YAAY;IACZ;IACA;IACD,EACD,KACD;;;AAIL,QAAO;EACL,MAAM;EACN,MAAM,KAAK,OAAO;GAChB,MAAM,SAAS,OAAO,MAAM,MAAM,WAAW,EAAE,MAAM;AACrD,OAAI,WAAW,KAAM,QAAO;GAC5B,MAAM,OAAO,MAAM,QAAQ;AAE3B,OAAI,MAAM,SAAS,SAAS,QAAQ,CAClC,QAAO;IACL,YAAY;IACZ,MACE,gBAAgB,SACZ,KAAK,UAAU,KAAK,GACpB,kBAAkB,KAAK,UAAU,KAAK;IAC7C;OAED,QAAO;IACL,YAAY;IACZ,MAAM,kBAAkB,KAAK,UAAU,KAAK;IAC7C;;EAGL,KAAK,EACH,KAAK,QAAQ,OAAO;GAClB,MAAM,SAAS,OAAO,QAAQ,MAAM;AACpC,OAAI,WAAW,KACb,QAAO;IACL,QAAQ;IACR,SAAS,MAAM,MAAM,UAAU,OAAO;IACvC;AAEH,UAAO,QAAQ,CAAC,MAAM,UAAU;IAC9B,QAAQ;IACR,SAAS,EAAE,SAAS,MAAM;IAC3B,EAAE;KAEN;EACF"}
|
package/dist/next/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import
|
|
3
|
-
import "../
|
|
4
|
-
import "../
|
|
5
|
-
import { n as createCore, t as _Defaults } from "../core-
|
|
6
|
-
import "../codegen-
|
|
7
|
-
import { t as
|
|
8
|
-
import { t as indexFile } from "../index-file-
|
|
1
|
+
import "../preset-D_quDsKp.js";
|
|
2
|
+
import "../fuma-matter-DL-PfQJ7.js";
|
|
3
|
+
import "../build-GdAvxpd7.js";
|
|
4
|
+
import { t as loadConfig } from "../load-from-file-dsGIDpOc.js";
|
|
5
|
+
import { n as createCore, t as _Defaults } from "../core-DOav5JBx.js";
|
|
6
|
+
import "../codegen-Dd9ILNOr.js";
|
|
7
|
+
import { n as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-Mp-ZCdLT.js";
|
|
8
|
+
import { t as indexFile } from "../index-file-B3LmDGdu.js";
|
|
9
9
|
import * as path$1 from "node:path";
|
|
10
10
|
|
|
11
11
|
//#region src/next/index.ts
|
package/dist/node/loader.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../fuma-matter-
|
|
2
|
-
import { t as
|
|
3
|
-
import
|
|
4
|
-
import "../
|
|
5
|
-
import {
|
|
6
|
-
import { t as createMetaLoader } from "../meta-
|
|
1
|
+
import "../fuma-matter-DL-PfQJ7.js";
|
|
2
|
+
import { n as createCore, t as _Defaults } from "../core-DOav5JBx.js";
|
|
3
|
+
import "../codegen-Dd9ILNOr.js";
|
|
4
|
+
import { t as createMdxLoader } from "../mdx-CJaKR3FR.js";
|
|
5
|
+
import { i as toNode, n as createStandaloneConfigLoader } from "../config-DSrG5Dfc.js";
|
|
6
|
+
import { t as createMetaLoader } from "../meta-CKrL1Sl9.js";
|
|
7
7
|
|
|
8
8
|
//#region src/node/loader.ts
|
|
9
9
|
const configLoader = createStandaloneConfigLoader({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../fuma-matter-
|
|
2
|
-
import "../codegen-
|
|
3
|
-
import { t as indexFile } from "../index-file-
|
|
1
|
+
import "../fuma-matter-DL-PfQJ7.js";
|
|
2
|
+
import "../codegen-Dd9ILNOr.js";
|
|
3
|
+
import { t as indexFile } from "../index-file-B3LmDGdu.js";
|
|
4
4
|
|
|
5
5
|
export { indexFile as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset-
|
|
1
|
+
{"version":3,"file":"preset-D_quDsKp.js","names":[],"sources":["../src/config/preset.ts"],"sourcesContent":["import type { ProcessorOptions } from '@mdx-js/mdx';\nimport type { Pluggable } from 'unified';\nimport type * as Plugins from '@hanzo/docs-core/mdx-plugins';\nimport type { BuildEnvironment } from './build';\n\ntype ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);\n\nexport type DefaultMDXOptions = Omit<\n NonNullable<ProcessorOptions>,\n 'rehypePlugins' | 'remarkPlugins' | '_ctx'\n> & {\n rehypePlugins?: ResolvePlugins;\n remarkPlugins?: ResolvePlugins;\n\n /**\n * Properties to export from `vfile.data`\n */\n valueToExport?: string[];\n\n remarkStructureOptions?: Plugins.StructureOptions | false;\n remarkHeadingOptions?: Plugins.RemarkHeadingOptions;\n remarkImageOptions?: Plugins.RemarkImageOptions | false;\n remarkCodeTabOptions?: Plugins.RemarkCodeTabOptions | false;\n remarkNpmOptions?: Plugins.RemarkNpmOptions | false;\n rehypeCodeOptions?: Plugins.RehypeCodeOptions | false;\n};\n\nfunction pluginOption(\n def: (v: Pluggable[]) => (Pluggable | false)[],\n options: ResolvePlugins = [],\n): Pluggable[] {\n const list = def(Array.isArray(options) ? options : []).filter(Boolean) as Pluggable[];\n\n if (typeof options === 'function') {\n return options(list);\n }\n\n return list;\n}\n\nexport type MDXPresetOptions =\n | ({ preset?: 'hanzo-docs' } & DefaultMDXOptions)\n | ({\n preset: 'minimal';\n } & ProcessorOptions);\n\n/**\n * apply MDX processor presets\n */\nexport function applyMdxPreset(\n options: MDXPresetOptions = {},\n): (environment: BuildEnvironment) => Promise<ProcessorOptions> {\n return async (environment = 'bundler') => {\n if (options.preset === 'minimal') return options;\n\n const plugins = await import('@hanzo/docs-core/mdx-plugins');\n const {\n valueToExport = [],\n rehypeCodeOptions,\n remarkImageOptions,\n remarkHeadingOptions,\n remarkStructureOptions,\n remarkCodeTabOptions,\n remarkNpmOptions,\n ...mdxOptions\n } = options;\n\n const remarkPlugins = pluginOption(\n (v) => [\n plugins.remarkGfm,\n [\n plugins.remarkHeading,\n {\n generateToc: false,\n ...remarkHeadingOptions,\n },\n ],\n remarkImageOptions !== false && [\n plugins.remarkImage,\n {\n ...remarkImageOptions,\n useImport: remarkImageOptions?.useImport ?? environment === 'bundler',\n },\n ],\n 'remarkCodeTab' in plugins &&\n remarkCodeTabOptions !== false && [plugins.remarkCodeTab, remarkCodeTabOptions],\n 'remarkNpm' in plugins &&\n remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],\n ...v,\n remarkStructureOptions !== false && [\n plugins.remarkStructure,\n {\n exportAs: 'structuredData',\n ...remarkStructureOptions,\n } satisfies Plugins.StructureOptions,\n ],\n valueToExport.length > 0 &&\n (() => {\n return (_, file) => {\n file.data['mdx-export'] ??= [];\n\n for (const name of valueToExport) {\n if (!(name in file.data)) continue;\n\n file.data['mdx-export'].push({\n name,\n value: file.data[name],\n });\n }\n };\n }),\n ],\n mdxOptions.remarkPlugins,\n );\n\n const rehypePlugins = pluginOption(\n (v) => [\n rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],\n ...v,\n plugins.rehypeToc,\n ],\n mdxOptions.rehypePlugins,\n );\n\n return {\n ...mdxOptions,\n outputFormat: environment === 'runtime' ? 'function-body' : mdxOptions.outputFormat,\n remarkPlugins,\n rehypePlugins,\n };\n };\n}\n"],"mappings":";AA2BA,SAAS,aACP,KACA,UAA0B,EAAE,EACf;CACb,MAAM,OAAO,IAAI,MAAM,QAAQ,QAAQ,GAAG,UAAU,EAAE,CAAC,CAAC,OAAO,QAAQ;AAEvE,KAAI,OAAO,YAAY,WACrB,QAAO,QAAQ,KAAK;AAGtB,QAAO;;;;;AAYT,SAAgB,eACd,UAA4B,EAAE,EACgC;AAC9D,QAAO,OAAO,cAAc,cAAc;AACxC,MAAI,QAAQ,WAAW,UAAW,QAAO;EAEzC,MAAM,UAAU,MAAM,OAAO;EAC7B,MAAM,EACJ,gBAAgB,EAAE,EAClB,mBACA,oBACA,sBACA,wBACA,sBACA,kBACA,GAAG,eACD;EAEJ,MAAM,gBAAgB,cACnB,MAAM;GACL,QAAQ;GACR,CACE,QAAQ,eACR;IACE,aAAa;IACb,GAAG;IACJ,CACF;GACD,uBAAuB,SAAS,CAC9B,QAAQ,aACR;IACE,GAAG;IACH,WAAW,oBAAoB,aAAa,gBAAgB;IAC7D,CACF;GACD,mBAAmB,WACjB,yBAAyB,SAAS,CAAC,QAAQ,eAAe,qBAAqB;GACjF,eAAe,WACb,qBAAqB,SAAS,CAAC,QAAQ,WAAW,iBAAiB;GACrE,GAAG;GACH,2BAA2B,SAAS,CAClC,QAAQ,iBACR;IACE,UAAU;IACV,GAAG;IACJ,CACF;GACD,cAAc,SAAS,YACd;AACL,YAAQ,GAAG,SAAS;AAClB,UAAK,KAAK,kBAAkB,EAAE;AAE9B,UAAK,MAAM,QAAQ,eAAe;AAChC,UAAI,EAAE,QAAQ,KAAK,MAAO;AAE1B,WAAK,KAAK,cAAc,KAAK;OAC3B;OACA,OAAO,KAAK,KAAK;OAClB,CAAC;;;;GAIX,EACD,WAAW,cACZ;EAED,MAAM,gBAAgB,cACnB,MAAM;GACL,sBAAsB,SAAS,CAAC,QAAQ,YAAY,kBAAkB;GACtE,GAAG;GACH,QAAQ;GACT,EACD,WAAW,cACZ;AAED,SAAO;GACL,GAAG;GACH,cAAc,gBAAgB,YAAY,kBAAkB,WAAW;GACvE;GACA;GACD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as fumaMatter } from "./fuma-matter-
|
|
2
|
-
import * as fs$1 from "node:fs/promises";
|
|
3
|
-
import * as path$1 from "node:path";
|
|
1
|
+
import { t as fumaMatter } from "./fuma-matter-DL-PfQJ7.js";
|
|
4
2
|
import { unified } from "unified";
|
|
5
3
|
import { visit } from "unist-util-visit";
|
|
4
|
+
import * as path$1 from "node:path";
|
|
5
|
+
import * as fs$1 from "node:fs/promises";
|
|
6
6
|
import { remarkHeading } from "@hanzo/docs-core/mdx-plugins";
|
|
7
7
|
import { VFile } from "vfile";
|
|
8
8
|
|
|
@@ -244,4 +244,4 @@ function remarkInclude() {
|
|
|
244
244
|
|
|
245
245
|
//#endregion
|
|
246
246
|
export { flattenNode as n, remarkInclude as t };
|
|
247
|
-
//# sourceMappingURL=remark-include-
|
|
247
|
+
//# sourceMappingURL=remark-include-BbnDmUoc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-include-DirFkbLw.js","names":["newChildren: RootContent[]","extractedLines: string[]","ElementLikeTypes: ElementLikeContent['type'][]","attributes: Record<string, string | null>","nodes: RootContent[] | undefined","content: string","fs","path","queue: Promise<void>[]"],"sources":["../src/loaders/mdx/remark-unravel.ts","../src/loaders/mdx/mdast-utils.ts","../src/loaders/mdx/remark-include.ts"],"sourcesContent":["// from internal remark plugins in https://github.com/mdx-js/mdx/blob/main/packages/mdx/lib/plugin/remark-mark-and-unravel.js\n// we need to ensure consistency with MDX.js when parsing embed content in `remark-include`\nimport { visit } from 'unist-util-visit';\nimport type { Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\n\nexport function remarkMarkAndUnravel(): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, function (node, index, parent) {\n let offset = -1;\n let all = true;\n let oneOrMore = false;\n\n if (parent && typeof index === 'number' && node.type === 'paragraph') {\n const children = node.children;\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === 'mdxJsxTextElement' || child.type === 'mdxTextExpression') {\n oneOrMore = true;\n } else if (child.type === 'text' && child.value.trim().length === 0) {\n // Empty.\n } else {\n all = false;\n break;\n }\n }\n\n if (all && oneOrMore) {\n offset = -1;\n const newChildren: RootContent[] = [];\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === 'mdxJsxTextElement') {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = 'mdxJsxFlowElement';\n }\n\n if (child.type === 'mdxTextExpression') {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = 'mdxFlowExpression';\n }\n\n if (child.type === 'text' && /^[\\t\\r\\n ]+$/.test(String(child.value))) {\n // Empty.\n } else {\n newChildren.push(child);\n }\n }\n\n parent.children.splice(index, 1, ...newChildren);\n return index;\n }\n }\n });\n };\n}\n","import type { RootContent } from 'mdast';\n\nexport function flattenNode(node: RootContent): string {\n if ('children' in node) return node.children.map((child) => flattenNode(child)).join('');\n\n if ('value' in node) return node.value;\n\n return '';\n}\n","import { type Processor, type Transformer, unified } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { Code, Node, Root, RootContent } from 'mdast';\nimport * as path from 'node:path';\nimport * as fs from 'node:fs/promises';\nimport { fumaMatter } from '@/utils/fuma-matter';\nimport type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';\nimport { remarkHeading } from '@hanzo/docs-core/mdx-plugins';\nimport { VFile } from 'vfile';\nimport type { Directives } from 'mdast-util-directive';\nimport { remarkMarkAndUnravel } from '@/loaders/mdx/remark-unravel';\nimport { flattenNode } from './mdast-utils';\n\n/**\n * VS Code–style region extraction\n * Adapted from VitePress:\n * https://github.com/vuejs/vitepress/blob/main/src/node/markdown/plugins/snippet.ts\n */\n\n// region marker regexes\nconst REGION_MARKERS = [\n {\n start: /^\\s*\\/\\/\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*\\/\\/\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*<!--\\s*#?region\\b\\s*(.*?)\\s*-->/,\n end: /^\\s*<!--\\s*#?endregion\\b\\s*(.*?)\\s*-->/,\n },\n {\n start: /^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\//,\n end: /^\\s*\\/\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\//,\n },\n {\n start: /^\\s*#[rR]egion\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#[eE]nd ?[rR]egion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*(?:--|::|@?REM)\\s*#region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*(?:--|::|@?REM)\\s*#endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#pragma\\s+region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#pragma\\s+endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*\\(\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\)/,\n end: /^\\s*\\(\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\)/,\n },\n];\n\nfunction dedent(lines: string[]): string {\n const minIndent = lines.reduce((min, line) => {\n const match = line.match(/^(\\s*)\\S/);\n return match ? Math.min(min, match[1].length) : min;\n }, Infinity);\n\n return minIndent === Infinity\n ? lines.join('\\n')\n : lines.map((l) => l.slice(minIndent)).join('\\n');\n}\n\nfunction extractCodeRegion(content: string, regionName: string): string {\n const lines = content.split('\\n');\n\n for (let i = 0; i < lines.length; i++) {\n for (const re of REGION_MARKERS) {\n let match = re.start.exec(lines[i]);\n if (match?.[1] !== regionName) continue;\n\n let depth = 1;\n const extractedLines: string[] = [];\n for (let j = i + 1; j < lines.length; j++) {\n match = re.start.exec(lines[j]);\n if (match) {\n depth++;\n continue;\n }\n\n match = re.end.exec(lines[j]);\n if (match) {\n if (match[1] === regionName) depth = 0;\n else if (match[1] === '') depth--;\n else continue;\n\n if (depth > 0) continue;\n return dedent(extractedLines);\n } else {\n extractedLines.push(lines[j]);\n }\n }\n }\n }\n throw new Error(`Region \"${regionName}\" not found`);\n}\n\nexport interface Params {\n lang?: string;\n meta?: string;\n}\n\nconst ElementLikeTypes: ElementLikeContent['type'][] = [\n 'mdxJsxFlowElement',\n 'mdxJsxTextElement',\n 'containerDirective',\n 'textDirective',\n 'leafDirective',\n];\ntype ElementLikeContent = MdxJsxFlowElement | MdxJsxTextElement | Directives;\n\nfunction isElementLike(node: Node): node is ElementLikeContent {\n return ElementLikeTypes.includes(node.type as ElementLikeContent['type']);\n}\n\nfunction parseElementAttributes(\n element: ElementLikeContent,\n): Record<string, string | null | undefined> {\n if (Array.isArray(element.attributes)) {\n const attributes: Record<string, string | null> = {};\n\n for (const attr of element.attributes) {\n if (\n attr.type === 'mdxJsxAttribute' &&\n (typeof attr.value === 'string' || attr.value === null)\n ) {\n attributes[attr.name] = attr.value;\n }\n }\n\n return attributes;\n }\n\n return element.attributes ?? {};\n}\n\nfunction parseSpecifier(specifier: string): {\n file: string;\n section?: string;\n} {\n const idx = specifier.lastIndexOf('#');\n if (idx === -1) return { file: specifier };\n\n return {\n file: specifier.slice(0, idx),\n section: specifier.slice(idx + 1),\n };\n}\n\nfunction extractSection(root: Root, section: string): Root | undefined {\n let nodes: RootContent[] | undefined;\n let capturingHeadingContent = false;\n\n visit(root, (node) => {\n if (node.type === 'heading') {\n if (capturingHeadingContent) {\n return false;\n }\n\n if (node.data?.hProperties?.id === section) {\n capturingHeadingContent = true;\n nodes = [node];\n return 'skip';\n }\n\n return;\n }\n\n if (capturingHeadingContent) {\n nodes?.push(node as RootContent);\n return 'skip';\n }\n\n if (isElementLike(node) && node.name === 'section') {\n const attributes = parseElementAttributes(node);\n\n if (attributes.id === section) {\n nodes = node.children;\n return false;\n }\n }\n });\n\n if (nodes)\n return {\n type: 'root',\n children: nodes,\n };\n}\n\nexport function remarkInclude(this: Processor): Transformer<Root, Root> {\n const TagName = 'include';\n\n const embedContent = async (\n targetPath: string,\n heading: string | undefined,\n params: Params,\n parent: VFile,\n ) => {\n const { _getProcessor = () => this, _compiler } = parent.data;\n let content: string;\n try {\n content = (await fs.readFile(targetPath)).toString();\n } catch (e) {\n throw new Error(\n `failed to read file ${targetPath}\\n${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n );\n }\n\n const ext = path.extname(targetPath);\n _compiler?.addDependency(targetPath);\n // For non-Markdown files, support VS Code–style region extraction\n if (params.lang || (ext !== '.md' && ext !== '.mdx')) {\n const lang = params.lang ?? ext.slice(1);\n let value = content;\n if (heading) {\n value = extractCodeRegion(content, heading.trim());\n }\n return {\n type: 'code',\n lang,\n meta: params.meta,\n value,\n data: {},\n } satisfies Code;\n }\n\n const parser = _getProcessor(ext === '.mdx' ? 'mdx' : 'md');\n const parsed = fumaMatter(content);\n const targetFile = new VFile({\n path: targetPath,\n value: parsed.content,\n data: {\n ...parent.data,\n frontmatter: parsed.data as Record<string, unknown>,\n },\n });\n let mdast = parser.parse(targetFile) as Root;\n const baseProcessor = unified().use(remarkMarkAndUnravel);\n\n if (heading) {\n // parse headings before extraction\n const extracted = extractSection(await baseProcessor.use(remarkHeading).run(mdast), heading);\n if (!extracted)\n throw new Error(\n `Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id=\"${heading}\"> tag, or a :::section directive with remark-directive configured.`,\n );\n\n mdast = extracted;\n } else {\n mdast = await baseProcessor.run(mdast);\n }\n\n await update(mdast, targetFile);\n return mdast;\n };\n\n async function update(tree: Root, file: VFile) {\n const queue: Promise<void>[] = [];\n\n visit(tree, ElementLikeTypes, (_node, _, parent) => {\n const node = _node as ElementLikeContent;\n if (node.name !== TagName) return;\n\n const specifier = flattenNode(node);\n if (specifier.length === 0) return 'skip';\n\n const attributes = parseElementAttributes(node);\n const { file: relativePath, section } = parseSpecifier(specifier);\n const targetPath = path.resolve('cwd' in attributes ? file.cwd : file.dirname!, relativePath);\n\n queue.push(\n embedContent(targetPath, section, attributes, file).then((replace) => {\n Object.assign(parent && parent.type === 'paragraph' ? parent : node, replace);\n }),\n );\n\n return 'skip';\n });\n\n await Promise.all(queue);\n }\n\n return async (tree, file) => {\n await update(tree, file);\n };\n}\n"],"mappings":";;;;;;;;;AAMA,SAAgB,uBAAgD;AAC9D,SAAQ,SAAS;AACf,QAAM,MAAM,SAAU,MAAM,OAAO,QAAQ;GACzC,IAAI,SAAS;GACb,IAAI,MAAM;GACV,IAAI,YAAY;AAEhB,OAAI,UAAU,OAAO,UAAU,YAAY,KAAK,SAAS,aAAa;IACpE,MAAM,WAAW,KAAK;AAEtB,WAAO,EAAE,SAAS,SAAS,QAAQ;KACjC,MAAM,QAAQ,SAAS;AAEvB,SAAI,MAAM,SAAS,uBAAuB,MAAM,SAAS,oBACvD,aAAY;cACH,MAAM,SAAS,UAAU,MAAM,MAAM,MAAM,CAAC,WAAW,GAAG,QAE9D;AACL,YAAM;AACN;;;AAIJ,QAAI,OAAO,WAAW;AACpB,cAAS;KACT,MAAMA,cAA6B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,IAAI,QAAQ,OAAO,MAAM,WAAW;EACpC,MAAM,gBAAgB,SAAS,CAAC,IAAI,qBAAqB;AAEzD,MAAI,SAAS;GAEX,MAAM,YAAY,eAAe,MAAM,cAAc,IAAI,cAAc,CAAC,IAAI,MAAM,EAAE,QAAQ;AAC5F,OAAI,CAAC,UACH,OAAM,IAAI,MACR,uBAAuB,QAAQ,MAAM,WAAW,kEAAkE,QAAQ,qEAC3H;AAEH,WAAQ;QAER,SAAQ,MAAM,cAAc,IAAI,MAAM;AAGxC,QAAM,OAAO,OAAO,WAAW;AAC/B,SAAO;;CAGT,eAAe,OAAO,MAAY,MAAa;EAC7C,MAAMC,QAAyB,EAAE;AAEjC,QAAM,MAAM,mBAAmB,OAAO,GAAG,WAAW;GAClD,MAAM,OAAO;AACb,OAAI,KAAK,SAAS,QAAS;GAE3B,MAAM,YAAY,YAAY,KAAK;AACnC,OAAI,UAAU,WAAW,EAAG,QAAO;GAEnC,MAAM,aAAa,uBAAuB,KAAK;GAC/C,MAAM,EAAE,MAAM,cAAc,YAAY,eAAe,UAAU;GACjE,MAAM,aAAaD,OAAK,QAAQ,SAAS,aAAa,KAAK,MAAM,KAAK,SAAU,aAAa;AAE7F,SAAM,KACJ,aAAa,YAAY,SAAS,YAAY,KAAK,CAAC,MAAM,YAAY;AACpE,WAAO,OAAO,UAAU,OAAO,SAAS,cAAc,SAAS,MAAM,QAAQ;KAC7E,CACH;AAED,UAAO;IACP;AAEF,QAAM,QAAQ,IAAI,MAAM;;AAG1B,QAAO,OAAO,MAAM,SAAS;AAC3B,QAAM,OAAO,MAAM,KAAK"}
|
|
1
|
+
{"version":3,"file":"remark-include-BbnDmUoc.js","names":["newChildren: RootContent[]","extractedLines: string[]","ElementLikeTypes: ElementLikeContent['type'][]","attributes: Record<string, string | null>","nodes: RootContent[] | undefined","content: string","fs","path","queue: Promise<void>[]"],"sources":["../src/loaders/mdx/remark-unravel.ts","../src/loaders/mdx/mdast-utils.ts","../src/loaders/mdx/remark-include.ts"],"sourcesContent":["// from internal remark plugins in https://github.com/mdx-js/mdx/blob/main/packages/mdx/lib/plugin/remark-mark-and-unravel.js\n// we need to ensure consistency with MDX.js when parsing embed content in `remark-include`\nimport { visit } from 'unist-util-visit';\nimport type { Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\n\nexport function remarkMarkAndUnravel(): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, function (node, index, parent) {\n let offset = -1;\n let all = true;\n let oneOrMore = false;\n\n if (parent && typeof index === 'number' && node.type === 'paragraph') {\n const children = node.children;\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === 'mdxJsxTextElement' || child.type === 'mdxTextExpression') {\n oneOrMore = true;\n } else if (child.type === 'text' && child.value.trim().length === 0) {\n // Empty.\n } else {\n all = false;\n break;\n }\n }\n\n if (all && oneOrMore) {\n offset = -1;\n const newChildren: RootContent[] = [];\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === 'mdxJsxTextElement') {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = 'mdxJsxFlowElement';\n }\n\n if (child.type === 'mdxTextExpression') {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = 'mdxFlowExpression';\n }\n\n if (child.type === 'text' && /^[\\t\\r\\n ]+$/.test(String(child.value))) {\n // Empty.\n } else {\n newChildren.push(child);\n }\n }\n\n parent.children.splice(index, 1, ...newChildren);\n return index;\n }\n }\n });\n };\n}\n","import type { RootContent } from 'mdast';\n\nexport function flattenNode(node: RootContent): string {\n if ('children' in node) return node.children.map((child) => flattenNode(child)).join('');\n\n if ('value' in node) return node.value;\n\n return '';\n}\n","import { type Processor, type Transformer, unified } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { Code, Node, Root, RootContent } from 'mdast';\nimport * as path from 'node:path';\nimport * as fs from 'node:fs/promises';\nimport { fumaMatter } from '@/utils/fuma-matter';\nimport type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';\nimport { remarkHeading } from '@hanzo/docs-core/mdx-plugins';\nimport { VFile } from 'vfile';\nimport type { Directives } from 'mdast-util-directive';\nimport { remarkMarkAndUnravel } from '@/loaders/mdx/remark-unravel';\nimport { flattenNode } from './mdast-utils';\n\n/**\n * VS Code–style region extraction\n * Adapted from VitePress:\n * https://github.com/vuejs/vitepress/blob/main/src/node/markdown/plugins/snippet.ts\n */\n\n// region marker regexes\nconst REGION_MARKERS = [\n {\n start: /^\\s*\\/\\/\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*\\/\\/\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*<!--\\s*#?region\\b\\s*(.*?)\\s*-->/,\n end: /^\\s*<!--\\s*#?endregion\\b\\s*(.*?)\\s*-->/,\n },\n {\n start: /^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\//,\n end: /^\\s*\\/\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\//,\n },\n {\n start: /^\\s*#[rR]egion\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#[eE]nd ?[rR]egion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*(?:--|::|@?REM)\\s*#region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*(?:--|::|@?REM)\\s*#endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#pragma\\s+region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#pragma\\s+endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*\\(\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\)/,\n end: /^\\s*\\(\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\)/,\n },\n];\n\nfunction dedent(lines: string[]): string {\n const minIndent = lines.reduce((min, line) => {\n const match = line.match(/^(\\s*)\\S/);\n return match ? Math.min(min, match[1].length) : min;\n }, Infinity);\n\n return minIndent === Infinity\n ? lines.join('\\n')\n : lines.map((l) => l.slice(minIndent)).join('\\n');\n}\n\nfunction extractCodeRegion(content: string, regionName: string): string {\n const lines = content.split('\\n');\n\n for (let i = 0; i < lines.length; i++) {\n for (const re of REGION_MARKERS) {\n let match = re.start.exec(lines[i]);\n if (match?.[1] !== regionName) continue;\n\n let depth = 1;\n const extractedLines: string[] = [];\n for (let j = i + 1; j < lines.length; j++) {\n match = re.start.exec(lines[j]);\n if (match) {\n depth++;\n continue;\n }\n\n match = re.end.exec(lines[j]);\n if (match) {\n if (match[1] === regionName) depth = 0;\n else if (match[1] === '') depth--;\n else continue;\n\n if (depth > 0) continue;\n return dedent(extractedLines);\n } else {\n extractedLines.push(lines[j]);\n }\n }\n }\n }\n throw new Error(`Region \"${regionName}\" not found`);\n}\n\nexport interface Params {\n lang?: string;\n meta?: string;\n}\n\nconst ElementLikeTypes: ElementLikeContent['type'][] = [\n 'mdxJsxFlowElement',\n 'mdxJsxTextElement',\n 'containerDirective',\n 'textDirective',\n 'leafDirective',\n];\ntype ElementLikeContent = MdxJsxFlowElement | MdxJsxTextElement | Directives;\n\nfunction isElementLike(node: Node): node is ElementLikeContent {\n return ElementLikeTypes.includes(node.type as ElementLikeContent['type']);\n}\n\nfunction parseElementAttributes(\n element: ElementLikeContent,\n): Record<string, string | null | undefined> {\n if (Array.isArray(element.attributes)) {\n const attributes: Record<string, string | null> = {};\n\n for (const attr of element.attributes) {\n if (\n attr.type === 'mdxJsxAttribute' &&\n (typeof attr.value === 'string' || attr.value === null)\n ) {\n attributes[attr.name] = attr.value;\n }\n }\n\n return attributes;\n }\n\n return element.attributes ?? {};\n}\n\nfunction parseSpecifier(specifier: string): {\n file: string;\n section?: string;\n} {\n const idx = specifier.lastIndexOf('#');\n if (idx === -1) return { file: specifier };\n\n return {\n file: specifier.slice(0, idx),\n section: specifier.slice(idx + 1),\n };\n}\n\nfunction extractSection(root: Root, section: string): Root | undefined {\n let nodes: RootContent[] | undefined;\n let capturingHeadingContent = false;\n\n visit(root, (node) => {\n if (node.type === 'heading') {\n if (capturingHeadingContent) {\n return false;\n }\n\n if (node.data?.hProperties?.id === section) {\n capturingHeadingContent = true;\n nodes = [node];\n return 'skip';\n }\n\n return;\n }\n\n if (capturingHeadingContent) {\n nodes?.push(node as RootContent);\n return 'skip';\n }\n\n if (isElementLike(node) && node.name === 'section') {\n const attributes = parseElementAttributes(node);\n\n if (attributes.id === section) {\n nodes = node.children;\n return false;\n }\n }\n });\n\n if (nodes)\n return {\n type: 'root',\n children: nodes,\n };\n}\n\nexport function remarkInclude(this: Processor): Transformer<Root, Root> {\n const TagName = 'include';\n\n const embedContent = async (\n targetPath: string,\n heading: string | undefined,\n params: Params,\n parent: VFile,\n ) => {\n const { _getProcessor = () => this, _compiler } = parent.data;\n let content: string;\n try {\n content = (await fs.readFile(targetPath)).toString();\n } catch (e) {\n throw new Error(\n `failed to read file ${targetPath}\\n${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n );\n }\n\n const ext = path.extname(targetPath);\n _compiler?.addDependency(targetPath);\n // For non-Markdown files, support VS Code–style region extraction\n if (params.lang || (ext !== '.md' && ext !== '.mdx')) {\n const lang = params.lang ?? ext.slice(1);\n let value = content;\n if (heading) {\n value = extractCodeRegion(content, heading.trim());\n }\n return {\n type: 'code',\n lang,\n meta: params.meta,\n value,\n data: {},\n } satisfies Code;\n }\n\n const parser = _getProcessor(ext === '.mdx' ? 'mdx' : 'md');\n const parsed = fumaMatter(content);\n const targetFile = new VFile({\n path: targetPath,\n value: parsed.content,\n data: {\n ...parent.data,\n frontmatter: parsed.data as Record<string, unknown>,\n },\n });\n let mdast = parser.parse(targetFile) as Root;\n const baseProcessor = unified().use(remarkMarkAndUnravel);\n\n if (heading) {\n // parse headings before extraction\n const extracted = extractSection(await baseProcessor.use(remarkHeading).run(mdast), heading);\n if (!extracted)\n throw new Error(\n `Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id=\"${heading}\"> tag, or a :::section directive with remark-directive configured.`,\n );\n\n mdast = extracted;\n } else {\n mdast = await baseProcessor.run(mdast);\n }\n\n await update(mdast, targetFile);\n return mdast;\n };\n\n async function update(tree: Root, file: VFile) {\n const queue: Promise<void>[] = [];\n\n visit(tree, ElementLikeTypes, (_node, _, parent) => {\n const node = _node as ElementLikeContent;\n if (node.name !== TagName) return;\n\n const specifier = flattenNode(node);\n if (specifier.length === 0) return 'skip';\n\n const attributes = parseElementAttributes(node);\n const { file: relativePath, section } = parseSpecifier(specifier);\n const targetPath = path.resolve('cwd' in attributes ? file.cwd : file.dirname!, relativePath);\n\n queue.push(\n embedContent(targetPath, section, attributes, file).then((replace) => {\n Object.assign(parent && parent.type === 'paragraph' ? parent : node, replace);\n }),\n );\n\n return 'skip';\n });\n\n await Promise.all(queue);\n }\n\n return async (tree, file) => {\n await update(tree, file);\n };\n}\n"],"mappings":";;;;;;;;;AAMA,SAAgB,uBAAgD;AAC9D,SAAQ,SAAS;AACf,QAAM,MAAM,SAAU,MAAM,OAAO,QAAQ;GACzC,IAAI,SAAS;GACb,IAAI,MAAM;GACV,IAAI,YAAY;AAEhB,OAAI,UAAU,OAAO,UAAU,YAAY,KAAK,SAAS,aAAa;IACpE,MAAM,WAAW,KAAK;AAEtB,WAAO,EAAE,SAAS,SAAS,QAAQ;KACjC,MAAM,QAAQ,SAAS;AAEvB,SAAI,MAAM,SAAS,uBAAuB,MAAM,SAAS,oBACvD,aAAY;cACH,MAAM,SAAS,UAAU,MAAM,MAAM,MAAM,CAAC,WAAW,GAAG,QAE9D;AACL,YAAM;AACN;;;AAIJ,QAAI,OAAO,WAAW;AACpB,cAAS;KACT,MAAMA,cAA6B,EAAE;AAErC,YAAO,EAAE,SAAS,SAAS,QAAQ;MACjC,MAAM,QAAQ,SAAS;AAEvB,UAAI,MAAM,SAAS,oBAEjB,OAAM,OAAO;AAGf,UAAI,MAAM,SAAS,oBAEjB,O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AC,IAAI,MAAM,EAAE,QAAQ;AAC5F,OAAI,CAAC,UACH,OAAM,IAAI,MACR,uBAAuB,QAAQ,MAAM,WAAW,kEAAkE,QAAQ,qEAC3H;AAEH,WAAQ;QAER,SAAQ,MAAM,cAAc,IAAI,MAAM;AAGxC,QAAM,OAAO,OAAO,WAAW;AAC/B,SAAO;;CAGT,eAAe,OAAO,MAAY,MAAa;EAC7C,MAAMC,QAAyB,EAAE;AAEjC,QAAM,MAAM,mBAAmB,OAAO,GAAG,WAAW;GAClD,MAAM,OAAO;AACb,OAAI,KAAK,SAAS,QAAS;GAE3B,MAAM,YAAY,YAAY,KAAK;AACnC,OAAI,UAAU,WAAW,EAAG,QAAO;GAEnC,MAAM,aAAa,uBAAuB,KAAK;GAC/C,MAAM,EAAE,MAAM,cAAc,YAAY,eAAe,UAAU;GACjE,MAAM,aAAaD,OAAK,QAAQ,SAAS,aAAa,KAAK,MAAM,KAAK,SAAU,aAAa;AAE7F,SAAM,KACJ,aAAa,YAAY,SAAS,YAAY,KAAK,CAAC,MAAM,YAAY;AACpE,WAAO,OAAO,UAAU,OAAO,SAAS,cAAc,SAAS,MAAM,QAAQ;KAC7E,CACH;AAED,UAAO;IACP;AAEF,QAAM,QAAQ,IAAI,MAAM;;AAG1B,QAAO,OAAO,MAAM,SAAS;AAC3B,QAAM,OAAO,MAAM,KAAK"}
|
package/dist/runtime/dynamic.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "../
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import "../
|
|
6
|
-
import "../
|
|
7
|
-
import { t as buildMDX } from "../build-mdx-
|
|
1
|
+
import "../preset-D_quDsKp.js";
|
|
2
|
+
import { t as fumaMatter } from "../fuma-matter-DL-PfQJ7.js";
|
|
3
|
+
import "../remark-include-BbnDmUoc.js";
|
|
4
|
+
import { t as buildConfig } from "../build-GdAvxpd7.js";
|
|
5
|
+
import { n as createCore } from "../core-DOav5JBx.js";
|
|
6
|
+
import "../codegen-Dd9ILNOr.js";
|
|
7
|
+
import { t as buildMDX } from "../build-mdx-COY0QD1z.js";
|
|
8
8
|
import { server } from "./server.js";
|
|
9
9
|
import fs from "node:fs/promises";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
package/dist/vite/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import
|
|
3
|
-
import "../
|
|
4
|
-
import { t as
|
|
5
|
-
import
|
|
6
|
-
import "../
|
|
7
|
-
import {
|
|
8
|
-
import { t as
|
|
9
|
-
import { t as
|
|
1
|
+
import "../preset-D_quDsKp.js";
|
|
2
|
+
import "../fuma-matter-DL-PfQJ7.js";
|
|
3
|
+
import { t as buildConfig } from "../build-GdAvxpd7.js";
|
|
4
|
+
import { n as createCore, r as ValidationError, t as _Defaults } from "../core-DOav5JBx.js";
|
|
5
|
+
import "../codegen-Dd9ILNOr.js";
|
|
6
|
+
import { t as indexFile } from "../index-file-B3LmDGdu.js";
|
|
7
|
+
import { t as createMdxLoader } from "../mdx-CJaKR3FR.js";
|
|
8
|
+
import { a as toVite, t as createIntegratedConfigLoader } from "../config-DSrG5Dfc.js";
|
|
9
|
+
import { t as createMetaLoader } from "../meta-CKrL1Sl9.js";
|
|
10
10
|
import { mergeConfig } from "vite";
|
|
11
11
|
|
|
12
12
|
//#region src/vite/index.ts
|
|
@@ -56,7 +56,7 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
async function postInstall(pluginOptions = {}) {
|
|
59
|
-
const { loadConfig } = await import("../load-from-file-
|
|
59
|
+
const { loadConfig } = await import("../load-from-file-BoO9y-n6.js");
|
|
60
60
|
const core = createViteCore(applyDefaults(pluginOptions));
|
|
61
61
|
await core.init({ config: loadConfig(core, true) });
|
|
62
62
|
await core.emit({ write: true });
|
package/dist/webpack/mdx.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../fuma-matter-
|
|
2
|
-
import
|
|
3
|
-
import "../
|
|
4
|
-
import "../
|
|
5
|
-
import {
|
|
6
|
-
import { t as getCore } from "../webpack-
|
|
1
|
+
import "../fuma-matter-DL-PfQJ7.js";
|
|
2
|
+
import "../core-DOav5JBx.js";
|
|
3
|
+
import "../codegen-Dd9ILNOr.js";
|
|
4
|
+
import { t as createMdxLoader } from "../mdx-CJaKR3FR.js";
|
|
5
|
+
import { n as createStandaloneConfigLoader, o as toWebpack } from "../config-DSrG5Dfc.js";
|
|
6
|
+
import { t as getCore } from "../webpack-BHjsXgTD.js";
|
|
7
7
|
|
|
8
8
|
//#region src/webpack/mdx.ts
|
|
9
9
|
let instance;
|
package/dist/webpack/meta.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "../core-
|
|
2
|
-
import "../codegen-
|
|
3
|
-
import {
|
|
4
|
-
import { t as createMetaLoader } from "../meta-
|
|
5
|
-
import { t as getCore } from "../webpack-
|
|
1
|
+
import "../core-DOav5JBx.js";
|
|
2
|
+
import "../codegen-Dd9ILNOr.js";
|
|
3
|
+
import { n as createStandaloneConfigLoader, o as toWebpack } from "../config-DSrG5Dfc.js";
|
|
4
|
+
import { t as createMetaLoader } from "../meta-CKrL1Sl9.js";
|
|
5
|
+
import { t as getCore } from "../webpack-BHjsXgTD.js";
|
|
6
6
|
|
|
7
7
|
//#region src/webpack/meta.ts
|
|
8
8
|
let instance;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createCore } from "./core-
|
|
1
|
+
import { n as createCore } from "./core-DOav5JBx.js";
|
|
2
2
|
|
|
3
3
|
//#region src/webpack/index.ts
|
|
4
4
|
let core;
|
|
@@ -12,4 +12,4 @@ function getCore(options) {
|
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
export { getCore as t };
|
|
15
|
-
//# sourceMappingURL=webpack-
|
|
15
|
+
//# sourceMappingURL=webpack-BHjsXgTD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-
|
|
1
|
+
{"version":3,"file":"webpack-BHjsXgTD.js","names":["core: Core"],"sources":["../src/webpack/index.ts"],"sourcesContent":["import { type Core, createCore } from '@/core';\n\nexport interface WebpackLoaderOptions {\n absoluteCompiledConfigPath: string;\n configPath: string;\n outDir: string;\n isDev: boolean;\n}\n\nlet core: Core;\n\nexport function getCore(options: WebpackLoaderOptions) {\n return (core ??= createCore({\n environment: 'webpack',\n outDir: options.outDir,\n configPath: options.configPath,\n }));\n}\n"],"mappings":";;;AASA,IAAIA;AAEJ,SAAgB,QAAQ,SAA+B;AACrD,QAAQ,SAAS,WAAW;EAC1B,aAAa;EACb,QAAQ,QAAQ;EAChB,YAAY,QAAQ;EACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/docs-mdx",
|
|
3
|
-
"version": "14.2.
|
|
4
|
-
"description": "The built-in source for
|
|
3
|
+
"version": "14.2.5",
|
|
4
|
+
"description": "The built-in source for Hanzo Docs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
7
7
|
"NextJs"
|
|
8
8
|
],
|
|
9
|
-
"homepage": "https://
|
|
9
|
+
"homepage": "https://hanzo.ai/docs",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"author": "Fuma Nama",
|
|
12
|
-
"repository": "github:
|
|
12
|
+
"repository": "github:hanzoai/docs",
|
|
13
13
|
"bin": "./dist/bin.js",
|
|
14
14
|
"files": [
|
|
15
15
|
"loader-mdx.cjs",
|
|
@@ -97,10 +97,10 @@
|
|
|
97
97
|
"tsdown": "^0.18.3",
|
|
98
98
|
"vite": "^7.3.0",
|
|
99
99
|
"webpack": "^5.104.1",
|
|
100
|
-
"@hanzo/mdx-runtime": "1.5.1",
|
|
101
|
-
"@hanzo/docs-core": "16.4.2",
|
|
102
100
|
"tsconfig": "0.0.0",
|
|
103
|
-
"eslint-config-custom": "0.0.0"
|
|
101
|
+
"eslint-config-custom": "0.0.0",
|
|
102
|
+
"@hanzo/docs-core": "16.4.3",
|
|
103
|
+
"@hanzo/mdx-runtime": "1.5.2"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"@hanzo/mdx-runtime": "^1.4.0",
|