fuma-content 0.0.2 → 1.0.1

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 (75) hide show
  1. package/dist/bin.d.ts +1 -0
  2. package/dist/bin.js +18 -0
  3. package/dist/build-mdx-I4NROXCF.js +8 -0
  4. package/dist/bun/index.d.ts +16 -0
  5. package/dist/bun/index.js +37 -0
  6. package/dist/bun-DMNX4PBC.js +40 -0
  7. package/dist/chunk-3VQS3KSP.js +39 -0
  8. package/dist/chunk-BTRE6MOX.js +16 -0
  9. package/dist/chunk-E4HRKSP4.js +24 -0
  10. package/dist/chunk-ERBMAQYP.js +33 -0
  11. package/dist/chunk-GGL4EF6H.js +38 -0
  12. package/dist/chunk-JBZTQ55D.js +30 -0
  13. package/dist/chunk-KH5GT2Y5.js +104 -0
  14. package/dist/chunk-LUM7SIZN.js +40 -0
  15. package/dist/chunk-MT7RY65Y.js +167 -0
  16. package/dist/chunk-NRZ4GE5O.js +207 -0
  17. package/dist/chunk-OQQNA7L7.js +412 -0
  18. package/dist/chunk-OUJENWQ4.js +45 -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-W6HENTK7.js +44 -0
  23. package/dist/chunk-XR5N6ZXJ.js +50 -0
  24. package/dist/collections/handlers/fs.d.ts +10 -0
  25. package/dist/collections/handlers/fs.js +6 -0
  26. package/dist/collections/index.d.ts +10 -0
  27. package/dist/collections/index.js +6 -0
  28. package/dist/collections/mdx/loader-webpack.d.ts +17 -0
  29. package/dist/collections/mdx/loader-webpack.js +39 -0
  30. package/dist/collections/mdx/runtime-browser.d.ts +55 -0
  31. package/dist/collections/mdx/runtime-browser.js +82 -0
  32. package/dist/collections/mdx/runtime-dynamic.d.ts +43 -0
  33. package/dist/collections/mdx/runtime-dynamic.js +96 -0
  34. package/dist/collections/mdx/runtime.d.ts +70 -0
  35. package/dist/collections/mdx/runtime.js +45 -0
  36. package/dist/collections/mdx.d.ts +10 -0
  37. package/dist/collections/mdx.js +291 -0
  38. package/dist/collections/meta/loader-webpack.d.ts +17 -0
  39. package/dist/collections/meta/loader-webpack.js +42 -0
  40. package/dist/collections/meta/runtime.d.ts +19 -0
  41. package/dist/collections/meta/runtime.js +18 -0
  42. package/dist/collections/meta.d.ts +10 -0
  43. package/dist/collections/meta.js +170 -0
  44. package/dist/collections/runtime/file-store.d.ts +19 -0
  45. package/dist/collections/runtime/file-store.js +7 -0
  46. package/dist/collections/runtime/store.d.ts +28 -0
  47. package/dist/collections/runtime/store.js +6 -0
  48. package/dist/config/index.d.ts +10 -0
  49. package/dist/config/index.js +7 -0
  50. package/dist/core-Bo8KaWQz.d.ts +411 -0
  51. package/dist/index.d.ts +15 -31
  52. package/dist/index.js +6 -49
  53. package/dist/load-from-file-HL2VEY3M.js +7 -0
  54. package/dist/loader-NFSL6P5I.js +7 -0
  55. package/dist/loader-T756NSCS.js +7 -0
  56. package/dist/next/index.cjs +594 -0
  57. package/dist/next/index.d.ts +27 -0
  58. package/dist/next/index.js +100 -0
  59. package/dist/node/loader.d.ts +5 -0
  60. package/dist/node/loader.js +47 -0
  61. package/dist/node-DCMYL4DL.js +34 -0
  62. package/dist/plugins/git.d.ts +10 -0
  63. package/dist/plugins/git.js +70 -0
  64. package/dist/plugins/json-schema.d.ts +10 -0
  65. package/dist/plugins/json-schema.js +59 -0
  66. package/dist/plugins/with-loader/index.d.ts +61 -0
  67. package/dist/plugins/with-loader/index.js +6 -0
  68. package/dist/plugins/with-loader/webpack.d.ts +27 -0
  69. package/dist/plugins/with-loader/webpack.js +12 -0
  70. package/dist/vite/index.d.ts +33 -0
  71. package/dist/vite/index.js +61 -0
  72. package/dist/vite-QCUPZHHB.js +32 -0
  73. package/package.json +104 -36
  74. package/dist/internal.d.ts +0 -114
  75. package/dist/internal.js +0 -420
@@ -1,114 +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 OutputEntry extends Output {
7
- /**
8
- * extension of file, like: `md`
9
- */
10
- format: string;
11
- file: string;
12
- }
13
- interface CompilerWithCache$1 extends Compiler {
14
- _compileCache?: Map<string, OutputEntry>;
15
- }
16
- declare function compile(this: Compiler): Promise<OutputEntry[]>;
17
- declare function compileFile(this: CompilerWithCache$1, file: string): Promise<OutputEntry>;
18
-
19
- interface Output {
20
- dependencies?: OutputEntry[];
21
- content: string;
22
- _entryPoint?: unknown;
23
- _mdx?: {
24
- vfile: VFile;
25
- };
26
- }
27
- type Transformer = (this: Compiler, file: string, source: string) => Output | Promise<Output>;
28
-
29
- interface Options extends ProcessorOptions {
30
- /**
31
- * Fetch last modified time with specified version control
32
- * @defaultValue 'none'
33
- */
34
- lastModifiedTime?: "git" | "none";
35
- /**
36
- * @defaultValue `['frontmatter', 'lastModified']`
37
- */
38
- remarkExports?: string[];
39
- /**
40
- * Convert relative imports into absolute imports
41
- *
42
- * @defaultValue true
43
- */
44
- enableAbsoluteImport?: boolean;
45
- }
46
- /**
47
- * Load MDX/markdown files
48
- */
49
- declare const loadMDX: ({ lastModifiedTime, format: forceFormat, remarkExports, enableAbsoluteImport, ...rest }?: Options) => Transformer;
50
-
51
- interface EntryPointOptions {
52
- /**
53
- * Notice that `lazy` mode is not supported by `source` function
54
- *
55
- * @defaultValue 'import'
56
- */
57
- mode?: "lazy" | "import";
58
- /**
59
- * Use full-path for `file` property
60
- *
61
- * @defaultValue false
62
- */
63
- fullPath?: string;
64
- }
65
- declare function loadEntryPoint(this: Compiler, entries: OutputEntry[]): OutputEntry;
66
-
67
- interface EmitEntry extends OutputEntry {
68
- outputPath: string;
69
- }
70
- interface CompilerWithCache extends Compiler {
71
- _emitCache?: WeakMap<OutputEntry, EmitEntry>;
72
- }
73
- declare function emit(this: Compiler): Promise<void>;
74
- declare function emitEntry(this: CompilerWithCache, entry: OutputEntry): Promise<EmitEntry>;
75
-
76
- declare function watch(this: Compiler): FSWatcher;
77
-
78
- interface CompilerOptions {
79
- files: string[];
80
- cwd: string;
81
- outputDir: string;
82
- outputExt: string;
83
- loaders?: Record<string, Transformer>;
84
- entryPoint?: EntryPointOptions;
85
- mdxOptions?: Options;
86
- globOptions?: Options$1;
87
- }
88
- interface Compiler {
89
- options: CompilerOptions;
90
- /**
91
- * Files to compile
92
- */
93
- files: string[];
94
- compile: typeof compile;
95
- compileFile: typeof compileFile;
96
- emit: typeof emit;
97
- emitEntry: typeof emitEntry;
98
- watch: typeof watch;
99
- loaders: Record<string, Transformer>;
100
- _output?: OutputEntry[];
101
- _emit?: EmitEntry[];
102
- }
103
-
104
- declare const defaultOptions: {
105
- cwd: string;
106
- outputDir: string;
107
- outputExt: string;
108
- };
109
- type CreateCompilerOptions = Pick<Partial<CompilerOptions>, keyof typeof defaultOptions> & Omit<CompilerOptions, keyof typeof defaultOptions>;
110
- declare function createCompiler(options: CreateCompilerOptions): Promise<Compiler>;
111
-
112
- declare const defaultConfig: CreateCompilerOptions;
113
-
114
- export { type CreateCompilerOptions, type EntryPointOptions, type Options, createCompiler, defaultConfig, loadEntryPoint, loadMDX };
package/dist/internal.js DELETED
@@ -1,420 +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) return Promise.resolve(cachedTimestamp);
61
- return new Promise((resolve, reject) => {
62
- const cwd = path2.dirname(file);
63
- if (!fs.existsSync(cwd)) {
64
- resolve(void 0);
65
- return;
66
- }
67
- const fileName = path2.basename(file);
68
- const child = spawn("git", ["log", "-1", '--pretty="%ai"', fileName], {
69
- cwd
70
- });
71
- let output;
72
- child.stdout.on("data", (d) => output = new Date(String(d)));
73
- child.on("close", () => {
74
- if (output) cache.set(file, output);
75
- resolve(output);
76
- });
77
- child.on("error", reject);
78
- });
79
- }
80
-
81
- // src/remark-plugins/utils.ts
82
- import { valueToEstree } from "estree-util-value-to-estree";
83
- function getMdastExport(name, value) {
84
- return {
85
- type: "mdxjsEsm",
86
- value: "",
87
- data: {
88
- estree: {
89
- type: "Program",
90
- sourceType: "module",
91
- body: [
92
- {
93
- type: "ExportNamedDeclaration",
94
- specifiers: [],
95
- source: null,
96
- declaration: {
97
- type: "VariableDeclaration",
98
- kind: "const",
99
- declarations: [
100
- {
101
- type: "VariableDeclarator",
102
- id: {
103
- type: "Identifier",
104
- name
105
- },
106
- init: valueToEstree(value)
107
- }
108
- ]
109
- }
110
- }
111
- ]
112
- }
113
- }
114
- };
115
- }
116
-
117
- // src/remark-plugins/remark-exports.ts
118
- function remarkMdxExport({ values }) {
119
- return (tree, vfile) => {
120
- for (const name of values) {
121
- if (!(name in vfile.data)) return;
122
- tree.children.unshift(getMdastExport(name, vfile.data[name]));
123
- }
124
- };
125
- }
126
-
127
- // src/remark-plugins/remark-absolute-import.ts
128
- import * as path3 from "node:path";
129
- import { visit } from "unist-util-visit";
130
- function remarkAbsoluteImport({
131
- compiler,
132
- transformFormats
133
- }) {
134
- return async (tree, vfile) => {
135
- const transforms = [];
136
- visit(tree, "mdxjsEsm", (node) => {
137
- const body = node.data?.estree?.body ?? [];
138
- for (const statement of body) {
139
- if (statement.type !== "ImportDeclaration" || typeof statement.source.value !== "string")
140
- continue;
141
- const value = statement.source.value;
142
- if (!value.startsWith("./") && !value.startsWith("../")) continue;
143
- const file = path3.join(path3.dirname(vfile.path), value);
144
- if (transformFormats.includes(path3.extname(file).slice(1))) {
145
- const transform = compiler.compileFile(file).then((entry) => {
146
- statement.source.value = getImportPath(
147
- getOutputPath(compiler, entry)
148
- );
149
- delete statement.source.raw;
150
- return entry;
151
- });
152
- transforms.push(transform);
153
- continue;
154
- }
155
- const replace = getImportPath(file);
156
- statement.source.value = replace;
157
- delete statement.source.raw;
158
- }
159
- });
160
- vfile.data.ctx = { dependencies: await Promise.all(transforms) };
161
- };
162
- }
163
-
164
- // src/loader/mdx.ts
165
- function pluggable(enable, value) {
166
- return enable ? [value] : [];
167
- }
168
- function getProcessor(compiler, options) {
169
- if (!options.format) throw new Error("format is required");
170
- compiler._mdxCache ||= /* @__PURE__ */ new Map();
171
- let processor = compiler._mdxCache.get(options.format);
172
- if (!processor) {
173
- processor = createProcessor(options);
174
- compiler._mdxCache.set(options.format, processor);
175
- }
176
- return processor;
177
- }
178
- var loadMDX = ({
179
- lastModifiedTime,
180
- format: forceFormat,
181
- remarkExports = ["frontmatter", "lastModified"],
182
- enableAbsoluteImport = true,
183
- ...rest
184
- } = {}) => {
185
- return async function transform(file, source) {
186
- const { content, data: frontmatter } = grayMatter(source);
187
- const detectedFormat = file.endsWith(".mdx") ? "mdx" : "md";
188
- const format = forceFormat ?? detectedFormat;
189
- let timestamp;
190
- const processor = getProcessor(this, {
191
- format,
192
- development: process.env.NODE_ENV === "development",
193
- ...rest,
194
- remarkPlugins: [
195
- ...rest.remarkPlugins ?? [],
196
- ...pluggable(enableAbsoluteImport, [
197
- remarkAbsoluteImport,
198
- {
199
- compiler: this,
200
- transformFormats: Object.keys(this.loaders)
201
- }
202
- ]),
203
- [remarkMdxExport, { values: remarkExports }]
204
- ]
205
- });
206
- if (lastModifiedTime === "git")
207
- timestamp = (await getGitTimestamp(file))?.getTime();
208
- const vfile = await processor.process({
209
- value: content,
210
- path: file,
211
- data: {
212
- lastModified: timestamp,
213
- frontmatter
214
- }
215
- });
216
- return {
217
- dependencies: vfile.data.ctx.dependencies,
218
- content: String(vfile),
219
- _mdx: {
220
- vfile
221
- }
222
- };
223
- };
224
- };
225
-
226
- // src/loader/json.ts
227
- var loadJson = () => {
228
- return (_file, source) => {
229
- const parsed = JSON.parse(source);
230
- return {
231
- content: `export default ${JSON.stringify(parsed)}`
232
- };
233
- };
234
- };
235
-
236
- // src/compiler/emit.ts
237
- import * as path4 from "node:path";
238
- import * as fs2 from "node:fs/promises";
239
- async function emit() {
240
- const entires = await this.compile();
241
- const emits = entires.map(async (entry) => this.emitEntry(entry));
242
- this._emit = await Promise.all(emits);
243
- }
244
- async function emitEntry(entry) {
245
- this._emitCache ||= /* @__PURE__ */ new WeakMap();
246
- const cached = this._emitCache.get(entry);
247
- if (cached) return cached;
248
- const outputPath = getOutputPath(this, entry);
249
- await fs2.mkdir(path4.dirname(outputPath), { recursive: true });
250
- await fs2.writeFile(outputPath, entry.content);
251
- if (entry.dependencies) {
252
- await Promise.all(entry.dependencies.map((dep) => this.emitEntry(dep)));
253
- }
254
- const output = {
255
- ...entry,
256
- outputPath
257
- };
258
- this._emitCache.set(entry, output);
259
- return output;
260
- }
261
-
262
- // src/compiler/compile.ts
263
- import * as fs3 from "node:fs/promises";
264
- import * as path5 from "node:path";
265
-
266
- // src/loader/entry-point.ts
267
- function loadEntryPoint(entries) {
268
- const { mode = "import" } = this.options.entryPoint ?? {};
269
- let content;
270
- switch (mode) {
271
- case "import":
272
- content = generateImport(this, entries);
273
- break;
274
- default:
275
- content = generateLazy(this, entries);
276
- break;
277
- }
278
- return {
279
- format: "js",
280
- file: getAbsolutePath(this.options.cwd, "./index.js"),
281
- content,
282
- _entryPoint: {}
283
- };
284
- }
285
- function generateImport(compiler, output) {
286
- const { fullPath = false } = compiler.options.entryPoint ?? {};
287
- const formats = /* @__PURE__ */ new Map();
288
- output.forEach((entry, i) => {
289
- const b = formats.get(entry.format) ?? { imports: [], entries: [] };
290
- formats.set(entry.format, b);
291
- const importPath = getImportPath(getOutputPath(compiler, entry));
292
- const file = fullPath ? entry.file : getRelativePath(compiler.options.cwd, entry.file);
293
- const name = `p_${i.toString()}`;
294
- b.imports.push(`import * as ${name} from ${JSON.stringify(importPath)};`);
295
- b.entries.push(`{
296
- ...${name},
297
- file: ${JSON.stringify(file)},
298
- }`);
299
- });
300
- const imports = Array.from(formats.values()).flatMap((f) => f.imports).join("\n");
301
- const entires = Array.from(formats.entries()).map(([k, v]) => `${k}: [${v.entries.join(",")}]`).join(",");
302
- return `${imports}
303
- export default {${entires}};`;
304
- }
305
- function generateLazy(compiler, output) {
306
- const entries = [];
307
- for (const entry of output) {
308
- const fronmatter = entry._mdx ? entry._mdx.vfile.data.frontmatter : {};
309
- const importPath = getImportPath(getOutputPath(compiler, entry));
310
- const line = `{
311
- file: ${JSON.stringify(entry.file)},
312
- info: ${JSON.stringify(fronmatter)},
313
- load: () => import(${JSON.stringify(importPath)})
314
- }`;
315
- entries.push(line);
316
- }
317
- return `export default [${entries.join(",\n")}]`;
318
- }
319
-
320
- // src/compiler/compile.ts
321
- async function compile() {
322
- const output = [];
323
- await Promise.all(
324
- this.files.map(async (file) => {
325
- const entry = await this.compileFile(file);
326
- output.push(entry);
327
- })
328
- );
329
- output.push(loadEntryPoint.call(this, output));
330
- this._output = output;
331
- return output;
332
- }
333
- async function compileFile(file) {
334
- this._compileCache ||= /* @__PURE__ */ new Map();
335
- const cache2 = this._compileCache.get(file);
336
- if (cache2) return cache2;
337
- const format = path5.extname(file).slice(1);
338
- const content = (await fs3.readFile(file)).toString();
339
- const loader = this.loaders[format];
340
- const output = await loader?.call(this, file, content);
341
- if (!output) {
342
- throw new Error(`Unknown format: ${format}`);
343
- }
344
- const entry = {
345
- file,
346
- format,
347
- ...output
348
- };
349
- this._compileCache.set(file, entry);
350
- return entry;
351
- }
352
- function removeCache(compiler, file) {
353
- compiler._compileCache?.delete(file);
354
- }
355
-
356
- // src/compiler/watch.ts
357
- import { watch as watchFn } from "chokidar";
358
- function watch() {
359
- void this.emit();
360
- const watcher = watchFn(this.options.files, { cwd: this.options.cwd });
361
- watcher.on("all", (eventName, relativePath) => {
362
- const absolutePath = getAbsolutePath(this.options.cwd, relativePath);
363
- if (eventName === "add" && !this.files.includes(absolutePath)) {
364
- this.files.push(absolutePath);
365
- void this.emit();
366
- }
367
- if (eventName === "unlink") {
368
- this.files = this.files.filter((file) => file !== absolutePath);
369
- removeCache(this, absolutePath);
370
- void this.emit();
371
- }
372
- if (eventName === "change") {
373
- console.log("update", relativePath);
374
- removeCache(this, absolutePath);
375
- void this.compileFile(absolutePath).then(async (entry) => {
376
- await this.emitEntry(entry);
377
- });
378
- }
379
- });
380
- return watcher;
381
- }
382
-
383
- // src/compiler/index.ts
384
- var defaultOptions = {
385
- cwd: process.cwd(),
386
- outputDir: "./dist",
387
- outputExt: ".js"
388
- };
389
- async function createCompiler(options) {
390
- const compilerOptions = {
391
- ...defaultOptions,
392
- ...options
393
- };
394
- const files = await globFiles(compilerOptions);
395
- return {
396
- files,
397
- options: compilerOptions,
398
- compile,
399
- emitEntry,
400
- watch,
401
- emit,
402
- compileFile,
403
- loaders: createLoaders(compilerOptions)
404
- };
405
- }
406
- function createLoaders(options) {
407
- const mdx = loadMDX(options.mdxOptions);
408
- return {
409
- mdx,
410
- md: mdx,
411
- json: loadJson(),
412
- ...options.loaders
413
- };
414
- }
415
- export {
416
- createCompiler,
417
- defaultConfig,
418
- loadEntryPoint,
419
- loadMDX
420
- };