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.
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +18 -0
- package/dist/build-mdx-Q4RMDWYK.js +8 -0
- package/dist/bun/index.d.ts +16 -0
- package/dist/bun/index.js +36 -0
- package/dist/bun-DMNX4PBC.js +40 -0
- package/dist/chunk-3VQS3KSP.js +39 -0
- package/dist/chunk-4RMSJCK2.js +50 -0
- package/dist/chunk-6XDQG2GV.js +17 -0
- package/dist/chunk-AMBGM4OK.js +412 -0
- package/dist/chunk-BTRE6MOX.js +16 -0
- package/dist/chunk-E4HRKSP4.js +24 -0
- package/dist/chunk-ERBMAQYP.js +33 -0
- package/dist/chunk-IGLM4N4P.js +34 -0
- package/dist/chunk-LDBQ66H3.js +38 -0
- package/dist/chunk-M72VQL5M.js +40 -0
- package/dist/chunk-OUJENWQ4.js +45 -0
- package/dist/chunk-PNA5UGSL.js +104 -0
- package/dist/chunk-RMSV4HP6.js +85 -0
- package/dist/chunk-RXR7OL76.js +37 -0
- package/dist/chunk-VWJKRQZR.js +19 -0
- package/dist/chunk-Z7KHD7MS.js +368 -0
- package/dist/collections/handlers/fs.d.ts +10 -0
- package/dist/collections/handlers/fs.js +6 -0
- package/dist/collections/index.d.ts +10 -0
- package/dist/collections/index.js +6 -0
- package/dist/collections/mdx/loader-webpack.d.ts +17 -0
- package/dist/collections/mdx/loader-webpack.js +38 -0
- package/dist/collections/mdx/runtime-browser.d.ts +44 -0
- package/dist/collections/mdx/runtime-browser.js +74 -0
- package/dist/collections/mdx/runtime-dynamic.d.ts +42 -0
- package/dist/collections/mdx/runtime-dynamic.js +94 -0
- package/dist/collections/mdx/runtime.d.ts +69 -0
- package/dist/collections/mdx/runtime.js +45 -0
- package/dist/collections/mdx.d.ts +10 -0
- package/dist/collections/mdx.js +287 -0
- package/dist/collections/meta/loader-webpack.d.ts +17 -0
- package/dist/collections/meta/loader-webpack.js +41 -0
- package/dist/collections/meta/runtime.d.ts +19 -0
- package/dist/collections/meta/runtime.js +18 -0
- package/dist/collections/meta.d.ts +10 -0
- package/dist/collections/meta.js +166 -0
- package/dist/collections/runtime/file-store.d.ts +19 -0
- package/dist/collections/runtime/file-store.js +7 -0
- package/dist/collections/runtime/store.d.ts +28 -0
- package/dist/collections/runtime/store.js +6 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +7 -0
- package/dist/core-DxnSmTRe.d.ts +411 -0
- package/dist/index.d.ts +13 -31
- package/dist/index.js +0 -53
- package/dist/load-from-file-MLL4WQ5J.js +7 -0
- package/dist/loader-T756NSCS.js +7 -0
- package/dist/loader-VGDLYG4T.js +7 -0
- package/dist/next/index.cjs +571 -0
- package/dist/next/index.d.ts +27 -0
- package/dist/next/index.js +99 -0
- package/dist/node/loader.d.ts +5 -0
- package/dist/node/loader.js +46 -0
- package/dist/node-DCMYL4DL.js +34 -0
- package/dist/plugins/git.d.ts +10 -0
- package/dist/plugins/git.js +70 -0
- package/dist/plugins/json-schema.d.ts +10 -0
- package/dist/plugins/json-schema.js +59 -0
- package/dist/plugins/with-loader/index.d.ts +61 -0
- package/dist/plugins/with-loader/index.js +6 -0
- package/dist/plugins/with-loader/webpack.d.ts +27 -0
- package/dist/plugins/with-loader/webpack.js +11 -0
- package/dist/vite/index.d.ts +33 -0
- package/dist/vite/index.js +60 -0
- package/dist/vite-QCUPZHHB.js +32 -0
- package/package.json +103 -36
- package/dist/internal.d.ts +0 -108
- package/dist/internal.js +0 -384
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCache
|
|
3
|
+
} from "./chunk-6XDQG2GV.js";
|
|
4
|
+
|
|
5
|
+
// src/core.ts
|
|
6
|
+
import path2 from "path";
|
|
7
|
+
import fs from "fs/promises";
|
|
8
|
+
|
|
9
|
+
// src/utils/code-generator.ts
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { glob } from "tinyglobby";
|
|
12
|
+
function importInfo() {
|
|
13
|
+
return {
|
|
14
|
+
named: /* @__PURE__ */ new Map(),
|
|
15
|
+
namespaces: /* @__PURE__ */ new Set(),
|
|
16
|
+
isUsed: /* @__PURE__ */ new Set()
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var CodeGenerator = class {
|
|
20
|
+
lines = [];
|
|
21
|
+
globCache;
|
|
22
|
+
// specifier -> imported members/info
|
|
23
|
+
importInfos = /* @__PURE__ */ new Map();
|
|
24
|
+
eagerImportId = 0;
|
|
25
|
+
options;
|
|
26
|
+
constructor({
|
|
27
|
+
target = "default",
|
|
28
|
+
jsExtension = false,
|
|
29
|
+
globCache = /* @__PURE__ */ new Map(),
|
|
30
|
+
outDir = ""
|
|
31
|
+
}) {
|
|
32
|
+
this.options = {
|
|
33
|
+
target,
|
|
34
|
+
jsExtension,
|
|
35
|
+
globCache,
|
|
36
|
+
outDir
|
|
37
|
+
};
|
|
38
|
+
this.globCache = createCache(globCache);
|
|
39
|
+
}
|
|
40
|
+
addNamespaceImport(namespace, specifier, types = false) {
|
|
41
|
+
const info = this.importInfos.get(specifier) ?? importInfo();
|
|
42
|
+
this.importInfos.set(specifier, info);
|
|
43
|
+
if (!types) info.isUsed.add(namespace);
|
|
44
|
+
info.namespaces.add(namespace);
|
|
45
|
+
}
|
|
46
|
+
addNamedImport(names, specifier, types = false) {
|
|
47
|
+
const info = this.importInfos.get(specifier) ?? importInfo();
|
|
48
|
+
this.importInfos.set(specifier, info);
|
|
49
|
+
for (const name of names) {
|
|
50
|
+
const [memberName, importName = memberName] = name.split(/\s+as\s+/, 2);
|
|
51
|
+
info.named.set(importName, memberName);
|
|
52
|
+
if (!types) info.isUsed.add(importName);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
push(...insert) {
|
|
56
|
+
this.lines.push(...insert);
|
|
57
|
+
}
|
|
58
|
+
async pushAsync(insert) {
|
|
59
|
+
for (const line of await Promise.all(insert)) {
|
|
60
|
+
if (line === void 0) continue;
|
|
61
|
+
this.lines.push(line);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async generateGlobImport(patterns, options) {
|
|
65
|
+
if (this.options.target === "vite") {
|
|
66
|
+
return this.generateViteGlobImport(patterns, options);
|
|
67
|
+
}
|
|
68
|
+
return this.generateNodeGlobImport(patterns, options);
|
|
69
|
+
}
|
|
70
|
+
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
71
|
+
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
72
|
+
normalizeViteGlobPath
|
|
73
|
+
);
|
|
74
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
75
|
+
{
|
|
76
|
+
base: normalizeViteGlobPath(path.relative(this.options.outDir, base)),
|
|
77
|
+
...rest
|
|
78
|
+
},
|
|
79
|
+
null,
|
|
80
|
+
2
|
|
81
|
+
)})`;
|
|
82
|
+
}
|
|
83
|
+
async generateNodeGlobImport(patterns, { base, eager = false, query = {}, import: importName }) {
|
|
84
|
+
const files = await this.globCache.cached(
|
|
85
|
+
JSON.stringify({ patterns, base }),
|
|
86
|
+
() => glob(patterns, {
|
|
87
|
+
cwd: base
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
let code = "{";
|
|
91
|
+
for (const item of files) {
|
|
92
|
+
const fullPath = path.join(base, item);
|
|
93
|
+
const searchParams = new URLSearchParams();
|
|
94
|
+
for (const [k, v] of Object.entries(query)) {
|
|
95
|
+
if (v !== void 0) searchParams.set(k, v);
|
|
96
|
+
}
|
|
97
|
+
const importPath = `${this.formatImportPath(fullPath)}?${searchParams.toString()}`;
|
|
98
|
+
if (eager) {
|
|
99
|
+
const name = `__fd_glob_${this.eagerImportId++}`;
|
|
100
|
+
this.lines.unshift(
|
|
101
|
+
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
102
|
+
);
|
|
103
|
+
code += `${JSON.stringify(item)}: ${name}, `;
|
|
104
|
+
} else {
|
|
105
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
106
|
+
if (importName) {
|
|
107
|
+
line += `.then(mod => mod.${importName})`;
|
|
108
|
+
}
|
|
109
|
+
code += `${line}, `;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
code += "}";
|
|
113
|
+
return code;
|
|
114
|
+
}
|
|
115
|
+
formatImportPath(file) {
|
|
116
|
+
const ext = path.extname(file);
|
|
117
|
+
let filename;
|
|
118
|
+
if (ext === ".ts") {
|
|
119
|
+
filename = file.substring(0, file.length - ext.length);
|
|
120
|
+
if (this.options.jsExtension) filename += ".js";
|
|
121
|
+
} else {
|
|
122
|
+
filename = file;
|
|
123
|
+
}
|
|
124
|
+
const importPath = slash(path.relative(this.options.outDir, filename));
|
|
125
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
126
|
+
}
|
|
127
|
+
toString() {
|
|
128
|
+
const final = ["// @ts-nocheck"];
|
|
129
|
+
if (this.options.target === "vite") {
|
|
130
|
+
final.push('/// <reference types="vite/client" />');
|
|
131
|
+
}
|
|
132
|
+
for (const [specifier, info] of this.importInfos) {
|
|
133
|
+
const { namespaces, named, isUsed } = info;
|
|
134
|
+
for (const namespace of namespaces) {
|
|
135
|
+
final.push(
|
|
136
|
+
isUsed.has(namespace) ? `import * as ${namespace} from "${specifier}";` : `import type * as ${namespace} from "${specifier}";`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
const namedImports = [];
|
|
140
|
+
for (const [importName, memberName] of named) {
|
|
141
|
+
const item = importName === memberName ? importName : `${memberName} as ${importName}`;
|
|
142
|
+
namedImports.push(isUsed.has(importName) ? item : `type ${item}`);
|
|
143
|
+
}
|
|
144
|
+
if (namedImports.length > 0) {
|
|
145
|
+
final.push(
|
|
146
|
+
`import { ${namedImports.join(", ")} } from "${specifier}";`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
final.push(...this.lines);
|
|
151
|
+
return final.join("\n");
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
function normalizeViteGlobPath(file) {
|
|
155
|
+
file = slash(file);
|
|
156
|
+
if (file.startsWith("./")) return file;
|
|
157
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
158
|
+
return `./${file}`;
|
|
159
|
+
}
|
|
160
|
+
function slash(path3) {
|
|
161
|
+
const isExtendedLengthPath = path3.startsWith("\\\\?\\");
|
|
162
|
+
if (isExtendedLengthPath) {
|
|
163
|
+
return path3;
|
|
164
|
+
}
|
|
165
|
+
return path3.replaceAll("\\", "/");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/core.ts
|
|
169
|
+
async function getPlugins(pluginOptions) {
|
|
170
|
+
const plugins = [];
|
|
171
|
+
for (const option of await Promise.all(pluginOptions)) {
|
|
172
|
+
if (!option) continue;
|
|
173
|
+
if (Array.isArray(option)) plugins.push(...await getPlugins(option));
|
|
174
|
+
else plugins.push(option);
|
|
175
|
+
}
|
|
176
|
+
return plugins;
|
|
177
|
+
}
|
|
178
|
+
var Core = class _Core {
|
|
179
|
+
workspaces = /* @__PURE__ */ new Map();
|
|
180
|
+
options;
|
|
181
|
+
plugins = [];
|
|
182
|
+
config;
|
|
183
|
+
static defaultOptions = {
|
|
184
|
+
configPath: "content.config.ts",
|
|
185
|
+
outDir: ".content"
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Convenient cache store, reset when config changes.
|
|
189
|
+
*
|
|
190
|
+
* You can group namespaces in cache key with ":", like `my-plugin:data`
|
|
191
|
+
*/
|
|
192
|
+
cache = /* @__PURE__ */ new Map();
|
|
193
|
+
constructor(options) {
|
|
194
|
+
this.options = options;
|
|
195
|
+
}
|
|
196
|
+
async init({ config: newConfig }) {
|
|
197
|
+
this.config = await newConfig;
|
|
198
|
+
this.cache.clear();
|
|
199
|
+
this.workspaces.clear();
|
|
200
|
+
const loadedCollectionTypeIds = /* @__PURE__ */ new Set();
|
|
201
|
+
this.plugins = await getPlugins([
|
|
202
|
+
this.options.plugins,
|
|
203
|
+
this.config.plugins,
|
|
204
|
+
...this.config.collections.values().map(({ typeInfo }) => {
|
|
205
|
+
if (loadedCollectionTypeIds.has(typeInfo.id)) return false;
|
|
206
|
+
loadedCollectionTypeIds.add(typeInfo.id);
|
|
207
|
+
return typeInfo.plugins;
|
|
208
|
+
})
|
|
209
|
+
]);
|
|
210
|
+
const ctx = this.getPluginContext();
|
|
211
|
+
for (const plugin of this.plugins) {
|
|
212
|
+
const out = await plugin.config?.call(ctx, this.config);
|
|
213
|
+
if (out) this.config = out;
|
|
214
|
+
}
|
|
215
|
+
const { workspace, outDir } = this.options;
|
|
216
|
+
if (!workspace) {
|
|
217
|
+
await Promise.all(
|
|
218
|
+
Object.entries(this.config.workspaces).map(
|
|
219
|
+
async ([name, workspace2]) => {
|
|
220
|
+
const child = new _Core({
|
|
221
|
+
...this.options,
|
|
222
|
+
outDir: path2.join(outDir, name),
|
|
223
|
+
workspace: {
|
|
224
|
+
name,
|
|
225
|
+
parent: this,
|
|
226
|
+
dir: workspace2.dir
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
await child.init({ config: workspace2.config });
|
|
230
|
+
this.workspaces.set(name, child);
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
await Promise.all(
|
|
236
|
+
this.config.collections.values().map(async (collection) => {
|
|
237
|
+
for (const plugin of this.plugins) {
|
|
238
|
+
await plugin.collection?.call(ctx, collection);
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
getWorkspaces() {
|
|
244
|
+
return this.workspaces;
|
|
245
|
+
}
|
|
246
|
+
getOptions() {
|
|
247
|
+
return this.options;
|
|
248
|
+
}
|
|
249
|
+
getConfig() {
|
|
250
|
+
return this.config;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
254
|
+
*/
|
|
255
|
+
getCompiledConfigPath() {
|
|
256
|
+
return path2.join(this.options.outDir, "content.config.mjs");
|
|
257
|
+
}
|
|
258
|
+
getPlugins(workspace = false) {
|
|
259
|
+
if (workspace) {
|
|
260
|
+
const plugins = [...this.plugins];
|
|
261
|
+
for (const workspace2 of this.workspaces.values()) {
|
|
262
|
+
plugins.push(...workspace2.plugins);
|
|
263
|
+
}
|
|
264
|
+
return plugins;
|
|
265
|
+
}
|
|
266
|
+
return this.plugins;
|
|
267
|
+
}
|
|
268
|
+
getCollections(workspace = false) {
|
|
269
|
+
const list = Array.from(this.config.collections.values());
|
|
270
|
+
if (workspace) {
|
|
271
|
+
for (const workspace2 of this.workspaces.values()) {
|
|
272
|
+
list.push(...workspace2.getCollections());
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return list;
|
|
276
|
+
}
|
|
277
|
+
getCollection(name) {
|
|
278
|
+
return this.config.collections.get(name);
|
|
279
|
+
}
|
|
280
|
+
getPluginContext() {
|
|
281
|
+
return {
|
|
282
|
+
core: this
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
async initServer(server) {
|
|
286
|
+
const ctx = this.getPluginContext();
|
|
287
|
+
const promises = [];
|
|
288
|
+
for (const plugin of this.plugins) {
|
|
289
|
+
promises.push(plugin.configureServer?.call(ctx, server));
|
|
290
|
+
}
|
|
291
|
+
for (const workspace of this.workspaces.values()) {
|
|
292
|
+
promises.push(workspace.initServer(server));
|
|
293
|
+
}
|
|
294
|
+
await Promise.all(promises);
|
|
295
|
+
}
|
|
296
|
+
async emit(emitOptions = {}) {
|
|
297
|
+
const {
|
|
298
|
+
workspace,
|
|
299
|
+
outDir,
|
|
300
|
+
emit: { target, jsExtension } = {}
|
|
301
|
+
} = this.options;
|
|
302
|
+
const { filterPlugin, filterWorkspace, write = false } = emitOptions;
|
|
303
|
+
const start = performance.now();
|
|
304
|
+
const globCache = /* @__PURE__ */ new Map();
|
|
305
|
+
const ctx = {
|
|
306
|
+
...this.getPluginContext(),
|
|
307
|
+
createCodeGenerator: async (path3, content) => {
|
|
308
|
+
const codegen = new CodeGenerator({
|
|
309
|
+
target,
|
|
310
|
+
outDir,
|
|
311
|
+
jsExtension,
|
|
312
|
+
globCache
|
|
313
|
+
});
|
|
314
|
+
await content({
|
|
315
|
+
core: this,
|
|
316
|
+
codegen,
|
|
317
|
+
workspace: workspace?.name
|
|
318
|
+
});
|
|
319
|
+
return {
|
|
320
|
+
path: path3,
|
|
321
|
+
content: codegen.toString()
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
const added = /* @__PURE__ */ new Set();
|
|
326
|
+
const out = {
|
|
327
|
+
entries: [],
|
|
328
|
+
workspaces: {}
|
|
329
|
+
};
|
|
330
|
+
for (const li of await Promise.all(
|
|
331
|
+
this.plugins.map((plugin) => {
|
|
332
|
+
if (filterPlugin && !filterPlugin(plugin) || !plugin.emit)
|
|
333
|
+
return null;
|
|
334
|
+
return plugin.emit.call(ctx);
|
|
335
|
+
})
|
|
336
|
+
)) {
|
|
337
|
+
if (!li) continue;
|
|
338
|
+
for (const item of li) {
|
|
339
|
+
if (added.has(item.path)) continue;
|
|
340
|
+
out.entries.push(item);
|
|
341
|
+
added.add(item.path);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (write) {
|
|
345
|
+
await Promise.all(
|
|
346
|
+
out.entries.map(async (entry) => {
|
|
347
|
+
const file = path2.join(outDir, entry.path);
|
|
348
|
+
await fs.mkdir(path2.dirname(file), { recursive: true });
|
|
349
|
+
await fs.writeFile(file, entry.content);
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
console.log(
|
|
353
|
+
workspace ? `[MDX: ${workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
await Promise.all(
|
|
357
|
+
this.workspaces.entries().map(async ([name, workspace2]) => {
|
|
358
|
+
if (filterWorkspace && !filterWorkspace(name)) return;
|
|
359
|
+
out.workspaces[name] = (await workspace2.emit(emitOptions)).entries;
|
|
360
|
+
})
|
|
361
|
+
);
|
|
362
|
+
return out;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
export {
|
|
367
|
+
Core
|
|
368
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { m as FIleCollectionHandler, F as FileHandlerConfig, n as buildFileHandler } from '../../core-DxnSmTRe.js';
|
|
2
|
+
import 'chokidar';
|
|
3
|
+
import '@mdx-js/mdx';
|
|
4
|
+
import 'vfile';
|
|
5
|
+
import '@standard-schema/spec';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'mdast';
|
|
8
|
+
import 'vite';
|
|
9
|
+
import 'next';
|
|
10
|
+
import 'node:module';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { y as Collection, A as CollectionHandlers, z as CollectionTypeInfo, I as InitOptions, B as createCollection } from '../core-DxnSmTRe.js';
|
|
2
|
+
import 'chokidar';
|
|
3
|
+
import '@mdx-js/mdx';
|
|
4
|
+
import 'vfile';
|
|
5
|
+
import '@standard-schema/spec';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'mdast';
|
|
8
|
+
import 'vite';
|
|
9
|
+
import 'next';
|
|
10
|
+
import 'node:module';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LoaderContext } from 'webpack';
|
|
2
|
+
import { WebpackLoaderOptions } from '../../plugins/with-loader/webpack.js';
|
|
3
|
+
import '../../plugins/with-loader/index.js';
|
|
4
|
+
import '../../core-DxnSmTRe.js';
|
|
5
|
+
import 'chokidar';
|
|
6
|
+
import '@mdx-js/mdx';
|
|
7
|
+
import 'vfile';
|
|
8
|
+
import '@standard-schema/spec';
|
|
9
|
+
import 'unified';
|
|
10
|
+
import 'mdast';
|
|
11
|
+
import 'vite';
|
|
12
|
+
import 'next';
|
|
13
|
+
import 'node:module';
|
|
14
|
+
|
|
15
|
+
declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export { loader as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMdxLoader
|
|
3
|
+
} from "../../chunk-PNA5UGSL.js";
|
|
4
|
+
import {
|
|
5
|
+
getCore,
|
|
6
|
+
toWebpack
|
|
7
|
+
} from "../../chunk-4RMSJCK2.js";
|
|
8
|
+
import "../../chunk-OUJENWQ4.js";
|
|
9
|
+
import {
|
|
10
|
+
createDynamicCore
|
|
11
|
+
} from "../../chunk-LDBQ66H3.js";
|
|
12
|
+
import "../../chunk-VWJKRQZR.js";
|
|
13
|
+
import "../../chunk-Z7KHD7MS.js";
|
|
14
|
+
import "../../chunk-6XDQG2GV.js";
|
|
15
|
+
|
|
16
|
+
// src/collections/mdx/loader-webpack.ts
|
|
17
|
+
var instance;
|
|
18
|
+
async function loader(source) {
|
|
19
|
+
const callback = this.async();
|
|
20
|
+
const options = this.getOptions();
|
|
21
|
+
this.cacheable(true);
|
|
22
|
+
this.addDependency(options.absoluteCompiledConfigPath);
|
|
23
|
+
if (!instance) {
|
|
24
|
+
instance = toWebpack(
|
|
25
|
+
createMdxLoader(
|
|
26
|
+
createDynamicCore({
|
|
27
|
+
core: getCore(options),
|
|
28
|
+
buildConfig: false,
|
|
29
|
+
mode: options.isDev ? "dev" : "production"
|
|
30
|
+
})
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
await instance.call(this, source, callback);
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
loader as default
|
|
38
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { CompiledMDXProperties } from './runtime.js';
|
|
3
|
+
import { GetCollectionConfig } from '../../index.js';
|
|
4
|
+
import { M as MDXCollection, E as ExtractedReference, V as VersionControlFileData } from '../../core-DxnSmTRe.js';
|
|
5
|
+
import { SimpleCollectionStore } from '../runtime/store.js';
|
|
6
|
+
import '../runtime/file-store.js';
|
|
7
|
+
import 'mdx/types';
|
|
8
|
+
import 'chokidar';
|
|
9
|
+
import '@mdx-js/mdx';
|
|
10
|
+
import 'vfile';
|
|
11
|
+
import '@standard-schema/spec';
|
|
12
|
+
import 'unified';
|
|
13
|
+
import 'mdast';
|
|
14
|
+
import 'vite';
|
|
15
|
+
import 'next';
|
|
16
|
+
import 'node:module';
|
|
17
|
+
|
|
18
|
+
interface MDXStoreBrowserData<Frontmatter, CustomData> {
|
|
19
|
+
preload: () => Promise<CompiledMDXProperties<Frontmatter> & CustomData>;
|
|
20
|
+
_renderer: {
|
|
21
|
+
id: string;
|
|
22
|
+
renderers?: Map<string, FC>;
|
|
23
|
+
getStoreData: () => StoreData;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface StoreData {
|
|
27
|
+
preloaded: Map<string, Promise<CompiledMDXProperties>>;
|
|
28
|
+
}
|
|
29
|
+
declare const _internal_data: Map<string, StoreData>;
|
|
30
|
+
declare function mdxStoreBrowser<Config, Name extends string>(name: Name, _input: Record<string, () => Promise<unknown>>): SimpleCollectionStore<MDXStoreBrowserData<GetCollectionConfig<Config, Name> extends MDXCollection<infer Frontmatter> ? Frontmatter : never, unknown>>;
|
|
31
|
+
/**
|
|
32
|
+
* Renders content with `React.lazy`.
|
|
33
|
+
*/
|
|
34
|
+
declare function useRenderer<Frontmatter, CustomData>(entry: MDXStoreBrowserData<Frontmatter, CustomData> | undefined, renderFn: (data: CompiledMDXProperties<Frontmatter> & CustomData) => ReactNode): ReactNode;
|
|
35
|
+
declare function $attachCompiled<Add>(): <T>(data: T) => T extends MDXStoreBrowserData<infer Frontmatter, infer CustomData> ? MDXStoreBrowserData<Frontmatter, CustomData & Add> : T;
|
|
36
|
+
declare function $extractedReferences(): <T>(data: T) => T extends MDXStoreBrowserData<infer Frontmatter, infer CustomData> ? MDXStoreBrowserData<Frontmatter, CustomData & {
|
|
37
|
+
/**
|
|
38
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
39
|
+
*/
|
|
40
|
+
extractedReferences: ExtractedReference[];
|
|
41
|
+
}> : T;
|
|
42
|
+
declare function $versionControl(): <T>(data: T) => T extends MDXStoreBrowserData<infer Frontmatter, infer CustomData> ? MDXStoreBrowserData<Frontmatter, CustomData & VersionControlFileData> : T;
|
|
43
|
+
|
|
44
|
+
export { $attachCompiled, $extractedReferences, $versionControl, type MDXStoreBrowserData, _internal_data, mdxStoreBrowser, useRenderer };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
SimpleCollectionStore
|
|
4
|
+
} from "../../chunk-3VQS3KSP.js";
|
|
5
|
+
|
|
6
|
+
// src/collections/mdx/runtime-browser.ts
|
|
7
|
+
import { lazy, createElement } from "react";
|
|
8
|
+
var _internal_data = /* @__PURE__ */ new Map();
|
|
9
|
+
function mdxStoreBrowser(name, _input) {
|
|
10
|
+
const input = _input;
|
|
11
|
+
const merged = /* @__PURE__ */ new Map();
|
|
12
|
+
function getStoreData() {
|
|
13
|
+
const store = _internal_data.get(name) ?? {
|
|
14
|
+
preloaded: /* @__PURE__ */ new Map()
|
|
15
|
+
};
|
|
16
|
+
_internal_data.set(name, store);
|
|
17
|
+
return store;
|
|
18
|
+
}
|
|
19
|
+
for (const [key, value] of Object.entries(input)) {
|
|
20
|
+
merged.set(key, {
|
|
21
|
+
preload() {
|
|
22
|
+
const data = getStoreData();
|
|
23
|
+
const loaded = value();
|
|
24
|
+
data.preloaded.set(key, loaded);
|
|
25
|
+
return loaded;
|
|
26
|
+
},
|
|
27
|
+
_renderer: {
|
|
28
|
+
id: key,
|
|
29
|
+
getStoreData
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return new SimpleCollectionStore(merged);
|
|
34
|
+
}
|
|
35
|
+
function useRenderer(entry, renderFn) {
|
|
36
|
+
if (!entry) return null;
|
|
37
|
+
entry._renderer.renderers ??= /* @__PURE__ */ new Map();
|
|
38
|
+
const { id, renderers, getStoreData } = entry._renderer;
|
|
39
|
+
let renderer = renderers.get(id);
|
|
40
|
+
if (!renderer) {
|
|
41
|
+
const OnDemand = lazy(async () => {
|
|
42
|
+
const loaded = await entry.preload();
|
|
43
|
+
return { default: () => renderFn(loaded) };
|
|
44
|
+
});
|
|
45
|
+
renderer = () => {
|
|
46
|
+
const data = getStoreData();
|
|
47
|
+
let cached;
|
|
48
|
+
data.preloaded.get(id)?.then((v) => {
|
|
49
|
+
cached = v;
|
|
50
|
+
});
|
|
51
|
+
if (!cached) return createElement(OnDemand);
|
|
52
|
+
return renderFn(cached);
|
|
53
|
+
};
|
|
54
|
+
renderers.set(id, renderer);
|
|
55
|
+
}
|
|
56
|
+
return createElement(renderer);
|
|
57
|
+
}
|
|
58
|
+
function $attachCompiled() {
|
|
59
|
+
return (data) => data;
|
|
60
|
+
}
|
|
61
|
+
function $extractedReferences() {
|
|
62
|
+
return $attachCompiled();
|
|
63
|
+
}
|
|
64
|
+
function $versionControl() {
|
|
65
|
+
return $attachCompiled();
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
$attachCompiled,
|
|
69
|
+
$extractedReferences,
|
|
70
|
+
$versionControl,
|
|
71
|
+
_internal_data,
|
|
72
|
+
mdxStoreBrowser,
|
|
73
|
+
useRenderer
|
|
74
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { C as CoreOptions, b as MDXCollectionConfig, E as ExtractedReference, V as VersionControlFileData } from '../../core-DxnSmTRe.js';
|
|
2
|
+
import { MDXComponents } from 'mdx/types';
|
|
3
|
+
import { FC } from 'react';
|
|
4
|
+
import { FileCollectionStore } from '../runtime/file-store.js';
|
|
5
|
+
import { CompiledMDXProperties } from './runtime.js';
|
|
6
|
+
import { GetCollectionConfig } from '../../index.js';
|
|
7
|
+
import 'chokidar';
|
|
8
|
+
import '@mdx-js/mdx';
|
|
9
|
+
import 'vfile';
|
|
10
|
+
import '@standard-schema/spec';
|
|
11
|
+
import 'unified';
|
|
12
|
+
import 'mdast';
|
|
13
|
+
import 'vite';
|
|
14
|
+
import 'next';
|
|
15
|
+
import 'node:module';
|
|
16
|
+
import '../runtime/store.js';
|
|
17
|
+
|
|
18
|
+
interface MDXStoreDynamicData<Frontmatter> {
|
|
19
|
+
id: string;
|
|
20
|
+
frontmatter: Frontmatter;
|
|
21
|
+
compile: () => Promise<CompiledMDXProperties<Frontmatter>>;
|
|
22
|
+
}
|
|
23
|
+
declare function mdxStoreDynamic<Config, Name extends string>(config: Config, coreOptions: CoreOptions, name: Name, base: string, _frontmatter: Record<string, unknown>): Promise<FileCollectionStore<MDXStoreDynamicData<GetCollectionConfig<Config, Name> extends MDXCollectionConfig<infer Frontmatter> ? Frontmatter : never>>>;
|
|
24
|
+
type MdxContent = FC<{
|
|
25
|
+
components?: MDXComponents;
|
|
26
|
+
}>;
|
|
27
|
+
declare function $attachCompiled<Add>(): <T>(data: T) => T extends MDXStoreDynamicData<unknown> ? T & {
|
|
28
|
+
compile: () => Promise<Awaited<ReturnType<T["compile"]>> & Add>;
|
|
29
|
+
} : T;
|
|
30
|
+
declare function $extractedReferences(): <T>(data: T) => T extends MDXStoreDynamicData<unknown> ? T & {
|
|
31
|
+
compile: () => Promise<Awaited<ReturnType<T["compile"]>> & {
|
|
32
|
+
/**
|
|
33
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
34
|
+
*/
|
|
35
|
+
extractedReferences: ExtractedReference[];
|
|
36
|
+
}>;
|
|
37
|
+
} : T;
|
|
38
|
+
declare function $versionControl(): <T>(data: T) => T extends MDXStoreDynamicData<unknown> ? T & {
|
|
39
|
+
compile: () => Promise<Awaited<ReturnType<T["compile"]>> & VersionControlFileData>;
|
|
40
|
+
} : T;
|
|
41
|
+
|
|
42
|
+
export { $attachCompiled, $extractedReferences, $versionControl, type MDXStoreDynamicData, type MdxContent, mdxStoreDynamic };
|