fuma-content 0.0.1 → 1.0.0

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 (74) hide show
  1. package/dist/bin.d.ts +1 -0
  2. package/dist/bin.js +18 -0
  3. package/dist/build-mdx-Q4RMDWYK.js +8 -0
  4. package/dist/bun/index.d.ts +16 -0
  5. package/dist/bun/index.js +36 -0
  6. package/dist/bun-DMNX4PBC.js +40 -0
  7. package/dist/chunk-3VQS3KSP.js +39 -0
  8. package/dist/chunk-4RMSJCK2.js +50 -0
  9. package/dist/chunk-6XDQG2GV.js +17 -0
  10. package/dist/chunk-AMBGM4OK.js +412 -0
  11. package/dist/chunk-BTRE6MOX.js +16 -0
  12. package/dist/chunk-E4HRKSP4.js +24 -0
  13. package/dist/chunk-ERBMAQYP.js +33 -0
  14. package/dist/chunk-IGLM4N4P.js +34 -0
  15. package/dist/chunk-LDBQ66H3.js +38 -0
  16. package/dist/chunk-M72VQL5M.js +40 -0
  17. package/dist/chunk-OUJENWQ4.js +45 -0
  18. package/dist/chunk-PNA5UGSL.js +104 -0
  19. package/dist/chunk-RMSV4HP6.js +85 -0
  20. package/dist/chunk-RXR7OL76.js +37 -0
  21. package/dist/chunk-VWJKRQZR.js +19 -0
  22. package/dist/chunk-Z7KHD7MS.js +368 -0
  23. package/dist/collections/handlers/fs.d.ts +10 -0
  24. package/dist/collections/handlers/fs.js +6 -0
  25. package/dist/collections/index.d.ts +10 -0
  26. package/dist/collections/index.js +6 -0
  27. package/dist/collections/mdx/loader-webpack.d.ts +17 -0
  28. package/dist/collections/mdx/loader-webpack.js +38 -0
  29. package/dist/collections/mdx/runtime-browser.d.ts +44 -0
  30. package/dist/collections/mdx/runtime-browser.js +74 -0
  31. package/dist/collections/mdx/runtime-dynamic.d.ts +42 -0
  32. package/dist/collections/mdx/runtime-dynamic.js +94 -0
  33. package/dist/collections/mdx/runtime.d.ts +69 -0
  34. package/dist/collections/mdx/runtime.js +45 -0
  35. package/dist/collections/mdx.d.ts +10 -0
  36. package/dist/collections/mdx.js +287 -0
  37. package/dist/collections/meta/loader-webpack.d.ts +17 -0
  38. package/dist/collections/meta/loader-webpack.js +41 -0
  39. package/dist/collections/meta/runtime.d.ts +19 -0
  40. package/dist/collections/meta/runtime.js +18 -0
  41. package/dist/collections/meta.d.ts +10 -0
  42. package/dist/collections/meta.js +166 -0
  43. package/dist/collections/runtime/file-store.d.ts +19 -0
  44. package/dist/collections/runtime/file-store.js +7 -0
  45. package/dist/collections/runtime/store.d.ts +28 -0
  46. package/dist/collections/runtime/store.js +6 -0
  47. package/dist/config/index.d.ts +10 -0
  48. package/dist/config/index.js +7 -0
  49. package/dist/core-DxnSmTRe.d.ts +411 -0
  50. package/dist/index.d.ts +13 -31
  51. package/dist/index.js +0 -53
  52. package/dist/load-from-file-MLL4WQ5J.js +7 -0
  53. package/dist/loader-T756NSCS.js +7 -0
  54. package/dist/loader-VGDLYG4T.js +7 -0
  55. package/dist/next/index.cjs +571 -0
  56. package/dist/next/index.d.ts +27 -0
  57. package/dist/next/index.js +99 -0
  58. package/dist/node/loader.d.ts +5 -0
  59. package/dist/node/loader.js +46 -0
  60. package/dist/node-DCMYL4DL.js +34 -0
  61. package/dist/plugins/git.d.ts +10 -0
  62. package/dist/plugins/git.js +70 -0
  63. package/dist/plugins/json-schema.d.ts +10 -0
  64. package/dist/plugins/json-schema.js +59 -0
  65. package/dist/plugins/with-loader/index.d.ts +61 -0
  66. package/dist/plugins/with-loader/index.js +6 -0
  67. package/dist/plugins/with-loader/webpack.d.ts +27 -0
  68. package/dist/plugins/with-loader/webpack.js +11 -0
  69. package/dist/vite/index.d.ts +33 -0
  70. package/dist/vite/index.js +60 -0
  71. package/dist/vite-QCUPZHHB.js +32 -0
  72. package/package.json +103 -36
  73. package/dist/internal.d.ts +0 -108
  74. package/dist/internal.js +0 -384
package/package.json CHANGED
@@ -1,64 +1,131 @@
1
1
  {
2
2
  "name": "fuma-content",
3
- "version": "0.0.1",
4
- "description": "Write content for web apps",
3
+ "version": "1.0.0",
4
+ "description": "The content processing layer for your app.",
5
5
  "keywords": [
6
- "Content",
7
- "Docs"
6
+ "Docs",
7
+ "Contentlayer"
8
8
  ],
9
9
  "repository": "github:fuma-nama/fuma-content",
10
10
  "license": "MIT",
11
- "type": "module",
12
11
  "author": "Fuma Nama",
13
- "files": [
14
- "dist/*"
15
- ],
16
- "main": "./dist/index.js",
17
- "types": "./dist/index.d.ts",
12
+ "homepage": "https://fuma-content.vercel.app",
13
+ "type": "module",
18
14
  "exports": {
15
+ "./config": {
16
+ "import": "./dist/config/index.js",
17
+ "types": "./dist/config/index.d.ts"
18
+ },
19
+ "./next": {
20
+ "import": "./dist/next/index.js",
21
+ "types": "./dist/next/index.d.ts",
22
+ "require": "./dist/next/index.cjs"
23
+ },
24
+ "./vite": {
25
+ "import": "./dist/vite/index.js",
26
+ "types": "./dist/vite/index.d.ts"
27
+ },
19
28
  ".": {
20
29
  "import": "./dist/index.js",
21
30
  "types": "./dist/index.d.ts"
22
31
  },
23
- "./internal": {
24
- "import": "./dist/internal.js",
25
- "types": "./dist/internal.d.ts"
26
- }
27
- },
28
- "typesVersions": {
29
- "*": {
30
- "internal": [
31
- "./dist/internal.d.ts"
32
- ]
32
+ "./collections": {
33
+ "import": "./dist/collections/index.js",
34
+ "types": "./dist/collections/index.d.ts"
35
+ },
36
+ "./collections/*": {
37
+ "import": "./dist/collections/*.js",
38
+ "types": "./dist/collections/*.d.ts",
39
+ "default": "./dist/collections/*.js"
40
+ },
41
+ "./node/loader": {
42
+ "import": "./dist/node/loader.js",
43
+ "types": "./dist/node/loader.d.ts"
44
+ },
45
+ "./bun": {
46
+ "import": "./dist/bun/index.js",
47
+ "types": "./dist/bun/index.d.ts"
48
+ },
49
+ "./plugins/with-loader": {
50
+ "import": "./dist/plugins/with-loader/index.js",
51
+ "types": "./dist/plugins/with-loader/index.d.ts"
52
+ },
53
+ "./plugins/*": {
54
+ "import": "./dist/plugins/*.js",
55
+ "types": "./dist/plugins/*.d.ts"
33
56
  }
34
57
  },
58
+ "main": "./dist/index.js",
59
+ "types": "./dist/index.d.ts",
60
+ "bin": "./dist/bin.js",
61
+ "files": [
62
+ "dist/*",
63
+ "loader-mdx.cjs",
64
+ "loader-meta.cjs"
65
+ ],
35
66
  "dependencies": {
36
- "@mdx-js/mdx": "^3.0.0",
37
- "chokidar": "^3.5.3",
38
- "cross-spawn": "^7.0.3",
39
- "estree-util-value-to-estree": "^3.0.1",
40
- "fast-glob": "^3.3.2",
41
- "gray-matter": "^4.0.3",
42
- "micromatch": "^4.0.5",
67
+ "@mdx-js/mdx": "^3.1.1",
68
+ "@standard-schema/spec": "^1.0.0",
69
+ "chokidar": "^5.0.0",
70
+ "esbuild": "^0.27.1",
71
+ "estree-util-value-to-estree": "^3.5.0",
72
+ "js-yaml": "^4.1.1",
73
+ "mdast-util-to-markdown": "^2.1.2",
74
+ "picocolors": "^1.1.1",
75
+ "picomatch": "^4.0.3",
76
+ "remark-mdx": "^3.1.1",
77
+ "tinyexec": "^1.0.2",
78
+ "tinyglobby": "^0.2.15",
79
+ "unified": "^11.0.5",
80
+ "unist-util-remove-position": "^5.0.0",
43
81
  "unist-util-visit": "^5.0.0",
44
- "zod": "^3.22.4"
82
+ "vfile": "^6.0.3",
83
+ "zod": "^4.1.13"
45
84
  },
46
85
  "devDependencies": {
47
- "@types/cross-spawn": "^6.0.6",
48
- "@types/mdast": "^4.0.3",
49
- "@types/mdx": "^2.0.11",
50
- "@types/micromatch": "^4.0.6",
51
- "typescript": "^5.3.3",
52
- "unified": "^11.0.4",
53
- "eslint-config": "0.0.0",
86
+ "@types/bun": "^1.3.4",
87
+ "@types/js-yaml": "^4.0.9",
88
+ "@types/mdast": "^4.0.4",
89
+ "@types/mdx": "^2.0.13",
90
+ "@types/node": "^24.10.2",
91
+ "@types/picomatch": "^4.0.2",
92
+ "@types/react": "^19.2.7",
93
+ "fumadocs-core": "^16.2.5",
94
+ "mdast-util-directive": "^3.1.0",
95
+ "mdast-util-mdx-jsx": "^3.2.0",
96
+ "next": "16.0.10",
97
+ "react": "^19.2.3",
98
+ "remark": "^15.0.1",
99
+ "remark-directive": "^4.0.0",
100
+ "remark-stringify": "^11.0.0",
101
+ "rollup": "^4.53.3",
102
+ "vite": "^7.2.7",
103
+ "webpack": "^5.103.0",
54
104
  "typescript-config": "0.0.0"
55
105
  },
106
+ "peerDependencies": {
107
+ "next": "^15.3.0 || ^16.0.0",
108
+ "react": "*",
109
+ "vite": "6.x.x || 7.x.x"
110
+ },
111
+ "peerDependenciesMeta": {
112
+ "react": {
113
+ "optional": true
114
+ },
115
+ "next": {
116
+ "optional": true
117
+ },
118
+ "vite": {
119
+ "optional": true
120
+ }
121
+ },
56
122
  "publishConfig": {
57
123
  "access": "public"
58
124
  },
59
125
  "scripts": {
60
126
  "build": "tsup",
127
+ "clean": "rimraf dist",
61
128
  "dev": "tsup --watch",
62
- "lint": "eslint ."
129
+ "types:check": "tsc --noEmit"
63
130
  }
64
131
  }
@@ -1,108 +0,0 @@
1
- import { Options as Options$1 } from 'fast-glob';
2
- import { ProcessorOptions } from '@mdx-js/mdx';
3
- import { VFile } from '@mdx-js/mdx/internal-create-format-aware-processors';
4
- import { FSWatcher } from 'chokidar';
5
-
6
- interface Output {
7
- content: string;
8
- _entryPoint?: unknown;
9
- _mdx?: {
10
- vfile: VFile;
11
- };
12
- }
13
- type Transformer = (this: Compiler, file: string, source: string) => Output | Promise<Output>;
14
-
15
- interface Options extends ProcessorOptions {
16
- /**
17
- * Fetch last modified time with specified version control
18
- * @defaultValue 'none'
19
- */
20
- lastModifiedTime?: "git" | "none";
21
- /**
22
- * @defaultValue `['frontmatter', 'lastModified']`
23
- */
24
- remarkExports?: string[];
25
- /**
26
- * Convert relative imports into absolute imports
27
- *
28
- * @defaultValue true
29
- */
30
- enableAbsoluteImport?: boolean;
31
- }
32
- /**
33
- * Load MDX/markdown files
34
- */
35
- declare const loadMDX: ({ lastModifiedTime, format: forceFormat, remarkExports, enableAbsoluteImport, ...rest }?: Options) => Transformer;
36
-
37
- interface OutputEntry extends Output {
38
- /**
39
- * extension of file, like: `md`
40
- */
41
- format: string;
42
- file: string;
43
- }
44
- declare function compile(this: Compiler): Promise<OutputEntry[]>;
45
- declare function compileFile(this: Compiler, file: string): Promise<OutputEntry>;
46
-
47
- interface EntryPointOptions {
48
- /**
49
- * Notice that `lazy` mode is not supported by `source` function
50
- *
51
- * @defaultValue 'import'
52
- */
53
- mode?: "lazy" | "import";
54
- /**
55
- * Use full-path for `file` property
56
- *
57
- * @defaultValue false
58
- */
59
- fullPath?: string;
60
- }
61
- declare function loadEntryPoint(this: Compiler, entries: OutputEntry[]): OutputEntry;
62
-
63
- interface EmitEntry extends OutputEntry {
64
- outputPath: string;
65
- }
66
- declare function emit(this: Compiler): Promise<void>;
67
- declare function emitEntry(this: Compiler, entry: OutputEntry): Promise<EmitEntry>;
68
-
69
- declare function watch(this: Compiler): FSWatcher;
70
-
71
- interface CompilerOptions {
72
- files: string[];
73
- cwd: string;
74
- outputDir: string;
75
- outputExt: string;
76
- loaders?: Record<string, Transformer>;
77
- entryPoint?: EntryPointOptions;
78
- mdxOptions?: Options;
79
- globOptions?: Options$1;
80
- }
81
- interface Compiler {
82
- options: CompilerOptions;
83
- /**
84
- * Files to compile
85
- */
86
- files: string[];
87
- compile: typeof compile;
88
- compileFile: typeof compileFile;
89
- emit: typeof emit;
90
- emitEntry: typeof emitEntry;
91
- watch: typeof watch;
92
- loaders: Record<string, Transformer>;
93
- _output?: OutputEntry[];
94
- _emit?: EmitEntry[];
95
- _cache: Map<string, OutputEntry>;
96
- }
97
-
98
- declare const defaultOptions: {
99
- cwd: string;
100
- outputDir: string;
101
- outputExt: string;
102
- };
103
- type CreateCompilerOptions = Pick<Partial<CompilerOptions>, keyof typeof defaultOptions> & Omit<CompilerOptions, keyof typeof defaultOptions>;
104
- declare function createCompiler(options: CreateCompilerOptions): Promise<Compiler>;
105
-
106
- declare const defaultConfig: CreateCompilerOptions;
107
-
108
- export { type CreateCompilerOptions, type EntryPointOptions, type Options, createCompiler, defaultConfig, loadEntryPoint, loadMDX };
package/dist/internal.js DELETED
@@ -1,384 +0,0 @@
1
- // src/constants.ts
2
- var defaultConfig = {
3
- files: ["./content/**/*"]
4
- };
5
-
6
- // src/utils/path.ts
7
- import * as path from "node:path";
8
- import FastGlob from "fast-glob";
9
- function getAbsolutePath(cwd, relativePath) {
10
- return path.join(cwd, relativePath);
11
- }
12
- function getRelativePath(cwd, absolutePath) {
13
- return slash(
14
- path.join(
15
- path.relative(cwd, path.dirname(absolutePath)),
16
- path.basename(absolutePath)
17
- )
18
- );
19
- }
20
- function getImportPath(absolutePath) {
21
- return slash(absolutePath);
22
- }
23
- function slash(anyPath) {
24
- const isExtendedLengthPath = anyPath.startsWith("\\\\?\\");
25
- if (isExtendedLengthPath) {
26
- return anyPath;
27
- }
28
- return anyPath.replaceAll("\\", "/");
29
- }
30
- async function globFiles({
31
- cwd,
32
- globOptions,
33
- files
34
- }) {
35
- return FastGlob.glob(files, {
36
- cwd,
37
- ...globOptions
38
- }).then((result) => result.map((file) => getAbsolutePath(cwd, file)));
39
- }
40
- function getOutputPath({ options }, entry) {
41
- return path.join(
42
- options.cwd,
43
- options.outputDir,
44
- path.relative(options.cwd, path.dirname(entry.file)),
45
- `${path.basename(entry.file, path.extname(entry.file))}${options.outputExt}`
46
- );
47
- }
48
-
49
- // src/loader/mdx.ts
50
- import { createProcessor } from "@mdx-js/mdx";
51
- import grayMatter from "gray-matter";
52
-
53
- // src/utils/git-timpstamp.ts
54
- import path2 from "node:path";
55
- import fs from "node:fs";
56
- import { spawn } from "cross-spawn";
57
- var cache = /* @__PURE__ */ new Map();
58
- function getGitTimestamp(file) {
59
- const cachedTimestamp = cache.get(file);
60
- if (cachedTimestamp)
61
- return Promise.resolve(cachedTimestamp);
62
- return new Promise((resolve, reject) => {
63
- const cwd = path2.dirname(file);
64
- if (!fs.existsSync(cwd)) {
65
- resolve(void 0);
66
- return;
67
- }
68
- const fileName = path2.basename(file);
69
- const child = spawn("git", ["log", "-1", '--pretty="%ai"', fileName], {
70
- cwd
71
- });
72
- let output;
73
- child.stdout.on("data", (d) => output = new Date(String(d)));
74
- child.on("close", () => {
75
- if (output)
76
- cache.set(file, output);
77
- resolve(output);
78
- });
79
- child.on("error", reject);
80
- });
81
- }
82
-
83
- // src/remark-plugins/utils.ts
84
- import { valueToEstree } from "estree-util-value-to-estree";
85
- function getMdastExport(name, value) {
86
- return {
87
- type: "mdxjsEsm",
88
- value: "",
89
- data: {
90
- estree: {
91
- type: "Program",
92
- sourceType: "module",
93
- body: [
94
- {
95
- type: "ExportNamedDeclaration",
96
- specifiers: [],
97
- source: null,
98
- declaration: {
99
- type: "VariableDeclaration",
100
- kind: "const",
101
- declarations: [
102
- {
103
- type: "VariableDeclarator",
104
- id: {
105
- type: "Identifier",
106
- name
107
- },
108
- init: valueToEstree(value)
109
- }
110
- ]
111
- }
112
- }
113
- ]
114
- }
115
- }
116
- };
117
- }
118
-
119
- // src/remark-plugins/remark-exports.ts
120
- function remarkMdxExport({ values }) {
121
- return (tree, vfile) => {
122
- for (const name of values) {
123
- if (!(name in vfile.data))
124
- return;
125
- tree.children.unshift(getMdastExport(name, vfile.data[name]));
126
- }
127
- };
128
- }
129
-
130
- // src/remark-plugins/remark-absolute-import.ts
131
- import * as path3 from "node:path";
132
- import { visit } from "unist-util-visit";
133
- function remarkAbsoluteImport({ enabled }) {
134
- return (tree, vfile) => {
135
- if (!enabled)
136
- return;
137
- visit(tree, ["mdxjsEsm"], (node) => {
138
- if (node.type !== "mdxjsEsm")
139
- return;
140
- const body = node.data?.estree?.body ?? [];
141
- body.forEach((statement) => {
142
- if (statement.type === "ImportDeclaration" && typeof statement.source.value === "string") {
143
- const value = statement.source.value;
144
- if (value.startsWith("./") || value.startsWith("../")) {
145
- const replace = getImportPath(
146
- path3.join(path3.dirname(vfile.path), value)
147
- );
148
- statement.source.value = replace;
149
- statement.source.raw = JSON.stringify(replace);
150
- }
151
- }
152
- });
153
- });
154
- };
155
- }
156
-
157
- // src/loader/mdx.ts
158
- var cache2 = /* @__PURE__ */ new Map();
159
- var loadMDX = ({
160
- lastModifiedTime,
161
- format: forceFormat,
162
- remarkExports = ["frontmatter", "lastModified"],
163
- enableAbsoluteImport = true,
164
- ...rest
165
- } = {}) => {
166
- return async (file, source) => {
167
- const { content, data: frontmatter } = grayMatter(source);
168
- const detectedFormat = file.endsWith(".mdx") ? "mdx" : "md";
169
- const format = forceFormat ?? detectedFormat;
170
- let timestamp;
171
- let processor = cache2.get(format);
172
- if (processor === void 0) {
173
- processor = createProcessor({
174
- format,
175
- development: process.env.NODE_ENV === "development",
176
- ...rest,
177
- remarkPlugins: [
178
- ...rest.remarkPlugins ?? [],
179
- [remarkAbsoluteImport, { enabled: enableAbsoluteImport }],
180
- [remarkMdxExport, { values: remarkExports }]
181
- ]
182
- });
183
- cache2.set(format, processor);
184
- }
185
- if (lastModifiedTime === "git")
186
- timestamp = (await getGitTimestamp(file))?.getTime();
187
- const vfile = await processor.process({
188
- value: content,
189
- path: file,
190
- data: {
191
- lastModified: timestamp,
192
- frontmatter
193
- }
194
- });
195
- return {
196
- content: String(vfile),
197
- _mdx: {
198
- vfile
199
- }
200
- };
201
- };
202
- };
203
-
204
- // src/loader/json.ts
205
- var loadJson = () => {
206
- return (_file, source) => {
207
- const parsed = JSON.parse(source);
208
- return {
209
- content: `export default ${JSON.stringify(parsed)}`
210
- };
211
- };
212
- };
213
-
214
- // src/compiler/emit.ts
215
- import * as path4 from "node:path";
216
- import * as fs2 from "node:fs/promises";
217
- async function emit() {
218
- const entires = await this.compile();
219
- const emits = entires.map(async (entry) => this.emitEntry(entry));
220
- this._emit = await Promise.all(emits);
221
- }
222
- async function emitEntry(entry) {
223
- const outputPath = getOutputPath(this, entry);
224
- await fs2.mkdir(path4.dirname(outputPath), { recursive: true });
225
- await fs2.writeFile(outputPath, entry.content);
226
- return {
227
- ...entry,
228
- outputPath
229
- };
230
- }
231
-
232
- // src/compiler/compile.ts
233
- import * as fs3 from "node:fs/promises";
234
- import * as path5 from "node:path";
235
-
236
- // src/loader/entry-point.ts
237
- function loadEntryPoint(entries) {
238
- const { mode = "import" } = this.options.entryPoint ?? {};
239
- let content;
240
- switch (mode) {
241
- case "import":
242
- content = generateImport(this, entries);
243
- break;
244
- default:
245
- content = generateLazy(this, entries);
246
- break;
247
- }
248
- return {
249
- format: "js",
250
- file: getAbsolutePath(this.options.cwd, "./index.js"),
251
- content,
252
- _entryPoint: {}
253
- };
254
- }
255
- function generateImport(compiler, output) {
256
- const { fullPath = false } = compiler.options.entryPoint ?? {};
257
- const formats = /* @__PURE__ */ new Map();
258
- output.forEach((entry, i) => {
259
- const b = formats.get(entry.format) ?? { imports: [], entries: [] };
260
- formats.set(entry.format, b);
261
- const importPath = getImportPath(getOutputPath(compiler, entry));
262
- const file = fullPath ? entry.file : getRelativePath(compiler.options.cwd, entry.file);
263
- const name = `p_${i}`;
264
- b.imports.push(`import * as ${name} from ${JSON.stringify(importPath)};`);
265
- b.entries.push(`{
266
- ...${name},
267
- format: ${JSON.stringify(entry.format)},
268
- file: ${JSON.stringify(file)},
269
- }`);
270
- });
271
- const imports = Array.from(formats.values()).flatMap((f) => f.imports).join("\n");
272
- const entires = Array.from(formats.entries()).map(([k, v]) => `${k}: [${v.entries.join(",")}]`).join(",");
273
- return `${imports}
274
- export default {${entires}};`;
275
- }
276
- function generateLazy(compiler, output) {
277
- const entries = [];
278
- for (const entry of output) {
279
- const fronmatter = entry._mdx ? entry._mdx.vfile.data.frontmatter : {};
280
- const importPath = getImportPath(getOutputPath(compiler, entry));
281
- const line = `{
282
- file: ${JSON.stringify(entry.file)},
283
- info: ${JSON.stringify(fronmatter)},
284
- load: () => import(${JSON.stringify(importPath)})
285
- }`;
286
- entries.push(line);
287
- }
288
- return `export default [${entries.join(",\n")}]`;
289
- }
290
-
291
- // src/compiler/compile.ts
292
- async function compile() {
293
- this._output = await Promise.all(
294
- this.files.map((file) => this.compileFile(file))
295
- );
296
- this._output.push(loadEntryPoint.call(this, this._output));
297
- return this._output;
298
- }
299
- async function compileFile(file) {
300
- const cache3 = this._cache.get(file);
301
- if (cache3)
302
- return cache3;
303
- const format = path5.extname(file).slice(1);
304
- const content = (await fs3.readFile(file)).toString();
305
- const loader = this.loaders[format];
306
- const output = await loader?.call(this, file, content);
307
- if (!output) {
308
- throw new Error(`Unknown format: ${format}`);
309
- }
310
- const entry = {
311
- file,
312
- format,
313
- ...output
314
- };
315
- this._cache.set(file, entry);
316
- return entry;
317
- }
318
-
319
- // src/compiler/watch.ts
320
- import { watch as watchFn } from "chokidar";
321
- function watch() {
322
- void this.emit();
323
- const watcher = watchFn(this.options.files, { cwd: this.options.cwd });
324
- watcher.on("all", (eventName, relativePath) => {
325
- const absolutePath = getAbsolutePath(this.options.cwd, relativePath);
326
- if (eventName === "add" && !this.files.includes(absolutePath)) {
327
- this.files.push(absolutePath);
328
- void this.emit();
329
- }
330
- if (eventName === "unlink") {
331
- this.files = this.files.filter((file) => file !== absolutePath);
332
- this._cache.delete(absolutePath);
333
- void this.emit();
334
- }
335
- if (eventName === "change") {
336
- console.log("update", relativePath);
337
- this._cache.delete(absolutePath);
338
- void this.compileFile(absolutePath).then(async (entry) => {
339
- await this.emitEntry(entry);
340
- });
341
- }
342
- });
343
- return watcher;
344
- }
345
-
346
- // src/compiler/index.ts
347
- var defaultOptions = {
348
- cwd: process.cwd(),
349
- outputDir: "./dist",
350
- outputExt: ".js"
351
- };
352
- async function createCompiler(options) {
353
- const compilerOptions = {
354
- ...defaultOptions,
355
- ...options
356
- };
357
- const files = await globFiles(compilerOptions);
358
- return {
359
- files,
360
- options: compilerOptions,
361
- compile,
362
- emitEntry,
363
- watch,
364
- emit,
365
- compileFile,
366
- loaders: createLoaders(compilerOptions),
367
- _cache: /* @__PURE__ */ new Map()
368
- };
369
- }
370
- function createLoaders(options) {
371
- const mdx = loadMDX(options.mdxOptions);
372
- return {
373
- mdx,
374
- md: mdx,
375
- json: loadJson(),
376
- ...options.loaders
377
- };
378
- }
379
- export {
380
- createCompiler,
381
- defaultConfig,
382
- loadEntryPoint,
383
- loadMDX
384
- };