@hanzo/docs-mdx 14.1.1 → 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.
Files changed (143) hide show
  1. package/dist/bin.d.ts +1 -1
  2. package/dist/bin.js +21 -12
  3. package/dist/bin.js.map +1 -0
  4. package/dist/build-GdAvxpd7.js +100 -0
  5. package/dist/build-GdAvxpd7.js.map +1 -0
  6. package/dist/build-mdx-COY0QD1z.js +153 -0
  7. package/dist/build-mdx-COY0QD1z.js.map +1 -0
  8. package/dist/build-mdx-DyJk_jWV.d.ts +53 -0
  9. package/dist/build-mdx-DyJk_jWV.d.ts.map +1 -0
  10. package/dist/build-mdx-hB1gzgHy.js +5 -0
  11. package/dist/bun/index.d.ts +10 -21
  12. package/dist/bun/index.d.ts.map +1 -0
  13. package/dist/bun/index.js +30 -49
  14. package/dist/bun/index.js.map +1 -0
  15. package/dist/codegen-Dd9ILNOr.js +101 -0
  16. package/dist/codegen-Dd9ILNOr.js.map +1 -0
  17. package/dist/config/index.d.ts +2 -18
  18. package/dist/config/index.js +50 -53
  19. package/dist/config/index.js.map +1 -0
  20. package/dist/config-DSrG5Dfc.js +144 -0
  21. package/dist/config-DSrG5Dfc.js.map +1 -0
  22. package/dist/core-D2BJuXMW.d.ts +364 -0
  23. package/dist/core-D2BJuXMW.d.ts.map +1 -0
  24. package/dist/core-DOav5JBx.js +212 -0
  25. package/dist/core-DOav5JBx.js.map +1 -0
  26. package/dist/fuma-matter-DL-PfQJ7.js +27 -0
  27. package/dist/fuma-matter-DL-PfQJ7.js.map +1 -0
  28. package/dist/index-Bc_4I1HE.d.ts +12 -0
  29. package/dist/index-Bc_4I1HE.d.ts.map +1 -0
  30. package/dist/index-file-B3LmDGdu.js +264 -0
  31. package/dist/index-file-B3LmDGdu.js.map +1 -0
  32. package/dist/index.d.ts +3 -61
  33. package/dist/index.js +1 -0
  34. package/dist/load-from-file-BoO9y-n6.js +5 -0
  35. package/dist/load-from-file-dsGIDpOc.js +38 -0
  36. package/dist/load-from-file-dsGIDpOc.js.map +1 -0
  37. package/dist/loaders-Mp-ZCdLT.js +7 -0
  38. package/dist/loaders-Mp-ZCdLT.js.map +1 -0
  39. package/dist/mdx-CJaKR3FR.js +91 -0
  40. package/dist/mdx-CJaKR3FR.js.map +1 -0
  41. package/dist/meta-CKrL1Sl9.js +81 -0
  42. package/dist/meta-CKrL1Sl9.js.map +1 -0
  43. package/dist/next/index.cjs +863 -1076
  44. package/dist/next/index.d.ts +17 -28
  45. package/dist/next/index.d.ts.map +1 -0
  46. package/dist/next/index.js +141 -170
  47. package/dist/next/index.js.map +1 -0
  48. package/dist/node/loader.d.ts +4 -2
  49. package/dist/node/loader.d.ts.map +1 -0
  50. package/dist/node/loader.js +26 -38
  51. package/dist/node/loader.js.map +1 -0
  52. package/dist/plugins/index-file.d.ts +2 -14
  53. package/dist/plugins/index-file.js +5 -8
  54. package/dist/plugins/json-schema.d.ts +14 -23
  55. package/dist/plugins/json-schema.d.ts.map +1 -0
  56. package/dist/plugins/json-schema.js +70 -78
  57. package/dist/plugins/json-schema.js.map +1 -0
  58. package/dist/plugins/last-modified.d.ts +21 -32
  59. package/dist/plugins/last-modified.d.ts.map +1 -0
  60. package/dist/plugins/last-modified.js +70 -78
  61. package/dist/plugins/last-modified.js.map +1 -0
  62. package/dist/preset-D_quDsKp.js +61 -0
  63. package/dist/preset-D_quDsKp.js.map +1 -0
  64. package/dist/remark-include-BbnDmUoc.js +247 -0
  65. package/dist/remark-include-BbnDmUoc.js.map +1 -0
  66. package/dist/runtime/browser.d.ts +32 -41
  67. package/dist/runtime/browser.d.ts.map +1 -0
  68. package/dist/runtime/browser.js +56 -63
  69. package/dist/runtime/browser.js.map +1 -0
  70. package/dist/runtime/dynamic.d.ts +13 -21
  71. package/dist/runtime/dynamic.d.ts.map +1 -0
  72. package/dist/runtime/dynamic.js +64 -76
  73. package/dist/runtime/dynamic.js.map +1 -0
  74. package/dist/runtime/server.d.ts +2 -14
  75. package/dist/runtime/server.js +111 -8
  76. package/dist/runtime/server.js.map +1 -0
  77. package/dist/runtime/types.d.ts +2 -61
  78. package/dist/runtime/types.js +1 -0
  79. package/dist/types-CBMeukTI.d.ts +63 -0
  80. package/dist/types-CBMeukTI.d.ts.map +1 -0
  81. package/dist/vite/index.d.ts +28 -39
  82. package/dist/vite/index.d.ts.map +1 -0
  83. package/dist/vite/index.js +79 -114
  84. package/dist/vite/index.js.map +1 -0
  85. package/dist/webpack/mdx.d.ts +6 -3
  86. package/dist/webpack/mdx.d.ts.map +1 -0
  87. package/dist/webpack/mdx.js +21 -34
  88. package/dist/webpack/mdx.js.map +1 -0
  89. package/dist/webpack/meta.d.ts +6 -3
  90. package/dist/webpack/meta.d.ts.map +1 -0
  91. package/dist/webpack/meta.js +23 -37
  92. package/dist/webpack/meta.js.map +1 -0
  93. package/dist/webpack-BHjsXgTD.js +15 -0
  94. package/dist/webpack-BHjsXgTD.js.map +1 -0
  95. package/loader-mdx.cjs +1 -3
  96. package/loader-meta.cjs +1 -3
  97. package/package.json +49 -49
  98. package/dist/build-mdx-LN7FEKIP.js +0 -8
  99. package/dist/build-mdx-RXJZQXGA.js +0 -8
  100. package/dist/chunk-4JSFLXXT.js +0 -8
  101. package/dist/chunk-5OBUOALK.js +0 -141
  102. package/dist/chunk-72JS4QVZ.js +0 -17
  103. package/dist/chunk-7I4W7XGI.js +0 -179
  104. package/dist/chunk-7W73RILB.js +0 -173
  105. package/dist/chunk-A3YIGE7S.js +0 -334
  106. package/dist/chunk-AOTZP2TV.js +0 -152
  107. package/dist/chunk-AXJB5MGS.js +0 -173
  108. package/dist/chunk-DMIIE3XZ.js +0 -179
  109. package/dist/chunk-DTFUANSF.js +0 -40
  110. package/dist/chunk-JWZR25CW.js +0 -116
  111. package/dist/chunk-K7N6GD4M.js +0 -17
  112. package/dist/chunk-LXB7WYAF.js +0 -334
  113. package/dist/chunk-MYAVS2LD.js +0 -116
  114. package/dist/chunk-OLD35ARB.js +0 -116
  115. package/dist/chunk-PW2AZGGD.js +0 -125
  116. package/dist/chunk-RGBNABKS.js +0 -334
  117. package/dist/chunk-RPUM7REY.js +0 -40
  118. package/dist/chunk-RR2X6AE6.js +0 -274
  119. package/dist/chunk-S7KOJHHO.js +0 -89
  120. package/dist/chunk-STUCUTJQ.js +0 -334
  121. package/dist/chunk-T6G5VOED.js +0 -116
  122. package/dist/chunk-U5YPLCO5.js +0 -89
  123. package/dist/chunk-UB55AMXC.js +0 -274
  124. package/dist/chunk-VITVHHR6.js +0 -334
  125. package/dist/chunk-VKSHE52K.js +0 -274
  126. package/dist/chunk-VWJKRQZR.js +0 -19
  127. package/dist/chunk-WAAWFNDX.js +0 -179
  128. package/dist/chunk-WGXYJGSZ.js +0 -141
  129. package/dist/chunk-WLJ6EKOZ.js +0 -17
  130. package/dist/chunk-WMYYALAS.js +0 -334
  131. package/dist/chunk-Y7ISNZ7X.js +0 -216
  132. package/dist/chunk-YKRCQ42E.js +0 -216
  133. package/dist/chunk-ZAYZWFWP.js +0 -89
  134. package/dist/core-BQcKaqmC.d.ts +0 -350
  135. package/dist/core-BhWOtait.d.ts +0 -350
  136. package/dist/core-CV8uFMUa.d.ts +0 -350
  137. package/dist/core-DAQ64Hkq.d.ts +0 -350
  138. package/dist/core-DZtRjhds.d.ts +0 -350
  139. package/dist/core-De5K4ixv.d.ts +0 -350
  140. package/dist/core-X5ggQtBM.d.ts +0 -350
  141. package/dist/index-BqkSNsGO.d.ts +0 -8
  142. package/dist/load-from-file-FHW724YY.js +0 -8
  143. package/dist/load-from-file-S5CQ4H6T.js +0 -8
@@ -1,18 +1,2 @@
1
- export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, f as DefaultMDXOptions, D as DocCollection, b as DocsCollection, G as GlobalConfig, g as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, h as applyMdxPreset, d as defineCollections, e as defineConfig, c as defineDocs } from '../core-CV8uFMUa.js';
2
- import { Processor, Transformer } from 'unified';
3
- import { Root } from 'mdast';
4
- export { pageSchema as frontmatterSchema, metaSchema } from '@hanzo/docs-core/source/schema';
5
- import '@mdx-js/mdx';
6
- import '@standard-schema/spec';
7
- import '@hanzo/docs-core/mdx-plugins';
8
- import 'chokidar';
9
- import 'vfile';
10
- import '@hanzo/docs-core/source';
11
- import '../runtime/types.js';
12
- import '@hanzo/docs-core/mdx-plugins/remark-structure';
13
- import '@hanzo/docs-core/toc';
14
- import 'mdx/types';
15
-
16
- declare function remarkInclude(this: Processor): Transformer<Root, Root>;
17
-
18
- export { remarkInclude };
1
+ import { A as BaseCollection, B as PostprocessOptions, D as metaSchema, E as frontmatterSchema, F as MetaCollection, H as MDXPresetOptions, I as defineCollections, L as defineConfig, M as DocCollection, N as DocsCollection, O as remarkInclude, P as GlobalConfig, R as defineDocs, U as applyMdxPreset, V as DefaultMDXOptions, j as CollectionSchema, k as AnyCollection } from "../core-D2BJuXMW.js";
2
+ export { AnyCollection, BaseCollection, CollectionSchema, DefaultMDXOptions, DocCollection, DocsCollection, GlobalConfig, MDXPresetOptions, MetaCollection, PostprocessOptions, applyMdxPreset, defineCollections, defineConfig, defineDocs, frontmatterSchema, metaSchema, remarkInclude };
@@ -1,63 +1,60 @@
1
- import {
2
- remarkInclude
3
- } from "../chunk-YKRCQ42E.js";
4
- import {
5
- applyMdxPreset
6
- } from "../chunk-U5YPLCO5.js";
7
- import "../chunk-VWJKRQZR.js";
8
-
9
- // ../core/dist/source/schema.js
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";
10
4
  import { z } from "zod";
11
- var metaSchema = z.object({
12
- title: z.string().optional(),
13
- pages: z.array(z.string()).optional(),
14
- description: z.string().optional(),
15
- root: z.boolean().optional(),
16
- defaultOpen: z.boolean().optional(),
17
- collapsible: z.boolean().optional(),
18
- icon: z.string().optional()
5
+
6
+ //#region ../core/dist/source/schema.js
7
+ /**
8
+ * Zod 4 schema
9
+ */
10
+ const metaSchema = z.object({
11
+ title: z.string().optional(),
12
+ pages: z.array(z.string()).optional(),
13
+ description: z.string().optional(),
14
+ root: z.boolean().optional(),
15
+ defaultOpen: z.boolean().optional(),
16
+ collapsible: z.boolean().optional(),
17
+ icon: z.string().optional()
19
18
  });
20
- var pageSchema = z.object({
21
- title: z.string(),
22
- description: z.string().optional(),
23
- icon: z.string().optional(),
24
- full: z.boolean().optional(),
25
- // Fumadocs OpenAPI generated
26
- _openapi: z.looseObject({}).optional()
19
+ /**
20
+ * Zod 4 schema
21
+ */
22
+ const pageSchema = z.object({
23
+ title: z.string(),
24
+ description: z.string().optional(),
25
+ icon: z.string().optional(),
26
+ full: z.boolean().optional(),
27
+ _openapi: z.looseObject({}).optional()
27
28
  });
28
29
 
29
- // src/config/define.ts
30
+ //#endregion
31
+ //#region src/config/define.ts
30
32
  function defineCollections(options) {
31
- return options;
33
+ return options;
32
34
  }
33
35
  function defineDocs(options) {
34
- const dir = options.dir ?? "content/docs";
35
- return {
36
- type: "docs",
37
- dir,
38
- docs: defineCollections({
39
- type: "doc",
40
- dir,
41
- schema: pageSchema,
42
- ...options?.docs
43
- }),
44
- meta: defineCollections({
45
- type: "meta",
46
- dir,
47
- schema: metaSchema,
48
- ...options?.meta
49
- })
50
- };
36
+ const dir = options.dir ?? "content/docs";
37
+ return {
38
+ type: "docs",
39
+ dir,
40
+ docs: defineCollections({
41
+ type: "doc",
42
+ dir,
43
+ schema: pageSchema,
44
+ ...options?.docs
45
+ }),
46
+ meta: defineCollections({
47
+ type: "meta",
48
+ dir,
49
+ schema: metaSchema,
50
+ ...options?.meta
51
+ })
52
+ };
51
53
  }
52
54
  function defineConfig(config = {}) {
53
- return config;
55
+ return config;
54
56
  }
55
- export {
56
- applyMdxPreset,
57
- defineCollections,
58
- defineConfig,
59
- defineDocs,
60
- pageSchema as frontmatterSchema,
61
- metaSchema,
62
- remarkInclude
63
- };
57
+
58
+ //#endregion
59
+ export { applyMdxPreset, defineCollections, defineConfig, defineDocs, pageSchema as frontmatterSchema, metaSchema, remarkInclude };
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../core/dist/source/schema.js","../../src/config/define.ts"],"sourcesContent":["import { z } from \"zod\";\n\n//#region src/source/schema.ts\n/**\n* Zod 4 schema\n*/\nconst metaSchema = z.object({\n\ttitle: z.string().optional(),\n\tpages: z.array(z.string()).optional(),\n\tdescription: z.string().optional(),\n\troot: z.boolean().optional(),\n\tdefaultOpen: z.boolean().optional(),\n\tcollapsible: z.boolean().optional(),\n\ticon: z.string().optional()\n});\n/**\n* Zod 4 schema\n*/\nconst pageSchema = z.object({\n\ttitle: z.string(),\n\tdescription: z.string().optional(),\n\ticon: z.string().optional(),\n\tfull: z.boolean().optional(),\n\t_openapi: z.looseObject({}).optional()\n});\n\n//#endregion\nexport { metaSchema, pageSchema };\n//# sourceMappingURL=schema.js.map","import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { MDXPresetOptions } from '@/config/preset';\nimport type { ProcessorOptions } from '@mdx-js/mdx';\nimport { metaSchema, pageSchema } from '@hanzo/docs-core/source/schema';\nimport type { PostprocessOptions } from '@/loaders/mdx/remark-postprocess';\nimport type { PluginOption } from '@/core';\nimport type { BuildEnvironment } from './build';\n\nexport type CollectionSchema<Schema extends StandardSchemaV1, Context> =\n | Schema\n | ((ctx: Context) => Schema);\n\nexport type AnyCollection = DocsCollection | DocCollection | MetaCollection;\n\nexport interface BaseCollection {\n /**\n * Directory to scan\n */\n dir: string;\n\n /**\n * what files to include/exclude (glob patterns)\n *\n * Include all files if not specified\n */\n files?: string[];\n}\n\nexport interface MetaCollection<\n Schema extends StandardSchemaV1 = StandardSchemaV1,\n> extends BaseCollection {\n type: 'meta';\n\n schema?: CollectionSchema<Schema, { path: string; source: string }>;\n}\n\nexport interface DocCollection<\n Schema extends StandardSchemaV1 = StandardSchemaV1,\n> extends BaseCollection {\n type: 'doc';\n\n postprocess?: Partial<PostprocessOptions>;\n mdxOptions?: ProcessorOptions | ((environment: BuildEnvironment) => Promise<ProcessorOptions>);\n\n /**\n * Load files with async\n */\n async?: boolean;\n\n /**\n * Compile files on-demand\n */\n dynamic?: boolean;\n\n schema?: CollectionSchema<Schema, { path: string; source: string }>;\n}\n\nexport interface DocsCollection<\n DocSchema extends StandardSchemaV1 = StandardSchemaV1,\n MetaSchema extends StandardSchemaV1 = StandardSchemaV1,\n> {\n type: 'docs';\n dir: string;\n\n docs: DocCollection<DocSchema>;\n meta: MetaCollection<MetaSchema>;\n}\n\nexport interface GlobalConfig {\n plugins?: PluginOption[];\n\n /**\n * Configure global MDX options\n */\n mdxOptions?: MDXPresetOptions | (() => Promise<MDXPresetOptions>);\n\n workspaces?: Record<\n string,\n {\n dir: string;\n config: Record<string, unknown>;\n }\n >;\n\n /**\n * specify a directory to access & store cache (disabled during development mode).\n *\n * The cache will never be updated, delete the cache folder to clean.\n */\n experimentalBuildCache?: string;\n}\n\nexport function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(\n options: DocCollection<Schema>,\n): DocCollection<Schema>;\nexport function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(\n options: MetaCollection<Schema>,\n): MetaCollection<Schema>;\n\nexport function defineCollections(\n options: DocCollection | MetaCollection,\n): DocCollection | MetaCollection {\n return options as any;\n}\n\nexport function defineDocs<\n DocSchema extends StandardSchemaV1 = typeof pageSchema,\n MetaSchema extends StandardSchemaV1 = typeof metaSchema,\n>(options: {\n /**\n * The content directory to scan files\n *\n * @defaultValue 'content/docs'\n */\n dir?: string;\n\n docs?: Omit<DocCollection<DocSchema>, 'dir' | 'type'>;\n meta?: Omit<MetaCollection<MetaSchema>, 'dir' | 'type'>;\n}): DocsCollection<DocSchema, MetaSchema> {\n const dir = options.dir ?? 'content/docs';\n\n return {\n type: 'docs',\n dir,\n docs: defineCollections({\n type: 'doc',\n dir,\n schema: pageSchema as any,\n ...options?.docs,\n }),\n meta: defineCollections({\n type: 'meta',\n dir,\n schema: metaSchema as any,\n ...options?.meta,\n }),\n };\n}\n\nexport function defineConfig(config: GlobalConfig = {}): GlobalConfig {\n return config;\n}\n"],"mappings":";;;;;;;;;AAMA,MAAM,aAAa,EAAE,OAAO;CAC3B,OAAO,EAAE,QAAQ,CAAC,UAAU;CAC5B,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACrC,aAAa,EAAE,QAAQ,CAAC,UAAU;CAClC,MAAM,EAAE,SAAS,CAAC,UAAU;CAC5B,aAAa,EAAE,SAAS,CAAC,UAAU;CACnC,aAAa,EAAE,SAAS,CAAC,UAAU;CACnC,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,CAAC;;;;AAIF,MAAM,aAAa,EAAE,OAAO;CAC3B,OAAO,EAAE,QAAQ;CACjB,aAAa,EAAE,QAAQ,CAAC,UAAU;CAClC,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,MAAM,EAAE,SAAS,CAAC,UAAU;CAC5B,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC,UAAU;CACtC,CAAC;;;;AC2EF,SAAgB,kBACd,SACgC;AAChC,QAAO;;AAGT,SAAgB,WAGd,SAUwC;CACxC,MAAM,MAAM,QAAQ,OAAO;AAE3B,QAAO;EACL,MAAM;EACN;EACA,MAAM,kBAAkB;GACtB,MAAM;GACN;GACA,QAAQ;GACR,GAAG,SAAS;GACb,CAAC;EACF,MAAM,kBAAkB;GACtB,MAAM;GACN;GACA,QAAQ;GACR,GAAG,SAAS;GACb,CAAC;EACH;;AAGH,SAAgB,aAAa,SAAuB,EAAE,EAAgB;AACpE,QAAO"}
@@ -0,0 +1,144 @@
1
+ import { r as ValidationError } from "./core-DOav5JBx.js";
2
+ import { readFileSync } from "node:fs";
3
+ import fs from "node:fs/promises";
4
+ import { fileURLToPath } from "node:url";
5
+ import { parse } from "node:querystring";
6
+
7
+ //#region src/loaders/adapter.ts
8
+ function toNode(loader) {
9
+ return async (url, _context, nextLoad) => {
10
+ if (url.startsWith("file:///") && (!loader.test || loader.test.test(url))) {
11
+ const parsedUrl = new URL(url);
12
+ const filePath = fileURLToPath(parsedUrl);
13
+ const result = await loader.load({
14
+ filePath,
15
+ query: Object.fromEntries(parsedUrl.searchParams.entries()),
16
+ async getSource() {
17
+ return (await fs.readFile(filePath)).toString();
18
+ },
19
+ development: false,
20
+ compiler: { addDependency() {} }
21
+ });
22
+ if (result) return {
23
+ source: result.code,
24
+ format: "module",
25
+ shortCircuit: true
26
+ };
27
+ }
28
+ return nextLoad(url);
29
+ };
30
+ }
31
+ function toVite(loader) {
32
+ return {
33
+ filter(id) {
34
+ return !loader.test || loader.test.test(id);
35
+ },
36
+ async transform(value, id) {
37
+ const [file, query = ""] = id.split("?", 2);
38
+ const result = await loader.load({
39
+ filePath: file,
40
+ query: parse(query),
41
+ getSource() {
42
+ return value;
43
+ },
44
+ development: this.environment.mode === "dev",
45
+ compiler: { addDependency: (file$1) => {
46
+ this.addWatchFile(file$1);
47
+ } }
48
+ });
49
+ if (result === null) return null;
50
+ return {
51
+ code: result.code,
52
+ map: result.map,
53
+ moduleType: result.moduleType
54
+ };
55
+ }
56
+ };
57
+ }
58
+ /**
59
+ * need to handle the `test` regex in Webpack config instead.
60
+ */
61
+ function toWebpack(loader) {
62
+ return async function(source, callback) {
63
+ try {
64
+ const result = await loader.load({
65
+ filePath: this.resourcePath,
66
+ query: parse(this.resourceQuery.slice(1)),
67
+ getSource() {
68
+ return source;
69
+ },
70
+ development: this.mode === "development",
71
+ compiler: this
72
+ });
73
+ if (result === null) callback(void 0, source);
74
+ else callback(void 0, result.code, result.map);
75
+ } catch (error) {
76
+ if (error instanceof ValidationError) return callback(new Error(await error.toStringFormatted()));
77
+ if (!(error instanceof Error)) throw error;
78
+ callback(error);
79
+ }
80
+ };
81
+ }
82
+ function toBun(loader) {
83
+ function toResult(output) {
84
+ if (!output) return;
85
+ return {
86
+ contents: output.code,
87
+ loader: output.moduleType ?? "js"
88
+ };
89
+ }
90
+ return (build) => {
91
+ build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {
92
+ const [filePath, query = ""] = args.path.split("?", 2);
93
+ const input = {
94
+ async getSource() {
95
+ return Bun.file(filePath).text();
96
+ },
97
+ query: parse(query),
98
+ filePath,
99
+ development: false,
100
+ compiler: { addDependency() {} }
101
+ };
102
+ if (loader.bun?.load) return loader.bun.load(readFileSync(filePath).toString(), input);
103
+ const result = loader.load(input);
104
+ if (result instanceof Promise) return result.then(toResult);
105
+ return toResult(result);
106
+ });
107
+ };
108
+ }
109
+
110
+ //#endregion
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
@@ -0,0 +1 @@
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,QAAQ,OAAO,KAAK,KAAK,IAAI,GAAG;GACzE,MAAM,YAAY,IAAI,IAAI,IAAI;GAC9B,MAAM,WAAW,cAAc,UAAU;GAEzC,MAAM,SAAS,MAAM,OAAO,KAAK;IAC/B;IACA,OAAO,OAAO,YAAY,UAAU,aAAa,SAAS,CAAC;IAC3D,MAAM,YAAY;AAChB,aAAQ,MAAM,GAAG,SAAS,SAAS,EAAE,UAAU;;IAEjD,aAAa;I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