fuma-content 1.0.1 → 1.0.3

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 (147) hide show
  1. package/dist/async-cache-C0J_pTbk.js +29 -0
  2. package/dist/async-cache-C0J_pTbk.js.map +1 -0
  3. package/dist/bin.d.ts +1 -1
  4. package/dist/bin.js +21 -14
  5. package/dist/bin.js.map +1 -0
  6. package/dist/build-mdx-CSrSOQxF.js +4 -0
  7. package/dist/build-mdx-DugsQ0sk.js +395 -0
  8. package/dist/build-mdx-DugsQ0sk.js.map +1 -0
  9. package/dist/bun/index.d.ts +6 -13
  10. package/dist/bun/index.d.ts.map +1 -0
  11. package/dist/bun/index.js +18 -34
  12. package/dist/bun/index.js.map +1 -0
  13. package/dist/bun-Br1ReMiq.js +35 -0
  14. package/dist/bun-Br1ReMiq.js.map +1 -0
  15. package/dist/code-generator-BvuyL0UO.js +133 -0
  16. package/dist/code-generator-BvuyL0UO.js.map +1 -0
  17. package/dist/collections/handlers/fs.d.ts +2 -10
  18. package/dist/collections/handlers/fs.js +31 -6
  19. package/dist/collections/handlers/fs.js.map +1 -0
  20. package/dist/collections/index.d.ts +2 -10
  21. package/dist/collections/index.js +16 -6
  22. package/dist/collections/index.js.map +1 -0
  23. package/dist/collections/mdx/loader-webpack.d.ts +6 -14
  24. package/dist/collections/mdx/loader-webpack.d.ts.map +1 -0
  25. package/dist/collections/mdx/loader-webpack.js +23 -36
  26. package/dist/collections/mdx/loader-webpack.js.map +1 -0
  27. package/dist/collections/mdx/runtime-browser.d.ts +27 -37
  28. package/dist/collections/mdx/runtime-browser.d.ts.map +1 -0
  29. package/dist/collections/mdx/runtime-browser.js +57 -70
  30. package/dist/collections/mdx/runtime-browser.js.map +1 -0
  31. package/dist/collections/mdx/runtime-dynamic.d.ts +22 -30
  32. package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -0
  33. package/dist/collections/mdx/runtime-dynamic.js +62 -85
  34. package/dist/collections/mdx/runtime-dynamic.js.map +1 -0
  35. package/dist/collections/mdx/runtime.d.ts +31 -52
  36. package/dist/collections/mdx/runtime.d.ts.map +1 -0
  37. package/dist/collections/mdx/runtime.js +24 -34
  38. package/dist/collections/mdx/runtime.js.map +1 -0
  39. package/dist/collections/mdx.d.ts +2 -10
  40. package/dist/collections/mdx.js +241 -284
  41. package/dist/collections/mdx.js.map +1 -0
  42. package/dist/collections/meta/loader-webpack.d.ts +6 -14
  43. package/dist/collections/meta/loader-webpack.d.ts.map +1 -0
  44. package/dist/collections/meta/loader-webpack.js +22 -39
  45. package/dist/collections/meta/loader-webpack.js.map +1 -0
  46. package/dist/collections/meta/runtime.d.ts +7 -15
  47. package/dist/collections/meta/runtime.d.ts.map +1 -0
  48. package/dist/collections/meta/runtime.js +9 -15
  49. package/dist/collections/meta/runtime.js.map +1 -0
  50. package/dist/collections/meta.d.ts +2 -10
  51. package/dist/collections/meta.js +125 -164
  52. package/dist/collections/meta.js.map +1 -0
  53. package/dist/collections/runtime/file-store.d.ts +17 -14
  54. package/dist/collections/runtime/file-store.d.ts.map +1 -0
  55. package/dist/collections/runtime/file-store.js +30 -6
  56. package/dist/collections/runtime/file-store.js.map +1 -0
  57. package/dist/collections/runtime/store.d.ts +3 -28
  58. package/dist/collections/runtime/store.js +3 -6
  59. package/dist/config/index.d.ts +2 -10
  60. package/dist/config/index.js +6 -5
  61. package/dist/config/index.js.map +1 -0
  62. package/dist/core-CRWvbE7W.d.ts +588 -0
  63. package/dist/core-CRWvbE7W.d.ts.map +1 -0
  64. package/dist/core-CnZQDCJ1.js +205 -0
  65. package/dist/core-CnZQDCJ1.js.map +1 -0
  66. package/dist/dynamic.d.ts +24 -0
  67. package/dist/dynamic.d.ts.map +1 -0
  68. package/dist/dynamic.js +28 -0
  69. package/dist/dynamic.js.map +1 -0
  70. package/dist/fuma-matter-D3kkMkdj.js +27 -0
  71. package/dist/fuma-matter-D3kkMkdj.js.map +1 -0
  72. package/dist/index.d.ts +17 -16
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +6 -8
  75. package/dist/load-from-file-BctwhOUd.js +3 -0
  76. package/dist/load-from-file-XiM8eZha.js +37 -0
  77. package/dist/load-from-file-XiM8eZha.js.map +1 -0
  78. package/dist/loader-BHMDOncZ.js +4 -0
  79. package/dist/loader-C7W_Rwj8.js +80 -0
  80. package/dist/loader-C7W_Rwj8.js.map +1 -0
  81. package/dist/loader-DLSJPUiO.js +69 -0
  82. package/dist/loader-DLSJPUiO.js.map +1 -0
  83. package/dist/loader-DkmGoUvo.js +4 -0
  84. package/dist/next/index.cjs +457 -554
  85. package/dist/next/index.d.ts +16 -22
  86. package/dist/next/index.d.ts.map +1 -0
  87. package/dist/next/index.js +71 -89
  88. package/dist/next/index.js.map +1 -0
  89. package/dist/node/loader.d.ts +4 -2
  90. package/dist/node/loader.d.ts.map +1 -0
  91. package/dist/node/loader.js +29 -44
  92. package/dist/node/loader.js.map +1 -0
  93. package/dist/node-CVAU22o3.js +31 -0
  94. package/dist/node-CVAU22o3.js.map +1 -0
  95. package/dist/pipe-UEMV1mRg.js +31 -0
  96. package/dist/pipe-UEMV1mRg.js.map +1 -0
  97. package/dist/plugins/git.d.ts +2 -10
  98. package/dist/plugins/git.js +57 -65
  99. package/dist/plugins/git.js.map +1 -0
  100. package/dist/plugins/json-schema.d.ts +2 -10
  101. package/dist/plugins/json-schema.js +60 -58
  102. package/dist/plugins/json-schema.js.map +1 -0
  103. package/dist/plugins/with-loader/index.d.ts +2 -61
  104. package/dist/plugins/with-loader/index.js +28 -6
  105. package/dist/plugins/with-loader/index.js.map +1 -0
  106. package/dist/plugins/with-loader/webpack.d.ts +10 -18
  107. package/dist/plugins/with-loader/webpack.d.ts.map +1 -0
  108. package/dist/plugins/with-loader/webpack.js +43 -12
  109. package/dist/plugins/with-loader/webpack.js.map +1 -0
  110. package/dist/store-BtGmZUAC.d.ts +31 -0
  111. package/dist/store-BtGmZUAC.d.ts.map +1 -0
  112. package/dist/store-D166MOLw.js +37 -0
  113. package/dist/store-D166MOLw.js.map +1 -0
  114. package/dist/validation-BYUzZIfc.js +37 -0
  115. package/dist/validation-BYUzZIfc.js.map +1 -0
  116. package/dist/vite/index.d.ts +22 -28
  117. package/dist/vite/index.d.ts.map +1 -0
  118. package/dist/vite/index.js +44 -53
  119. package/dist/vite/index.js.map +1 -0
  120. package/dist/vite-6awgG092.js +33 -0
  121. package/dist/vite-6awgG092.js.map +1 -0
  122. package/package.json +47 -42
  123. package/dist/build-mdx-I4NROXCF.js +0 -8
  124. package/dist/bun-DMNX4PBC.js +0 -40
  125. package/dist/chunk-3VQS3KSP.js +0 -39
  126. package/dist/chunk-BTRE6MOX.js +0 -16
  127. package/dist/chunk-E4HRKSP4.js +0 -24
  128. package/dist/chunk-ERBMAQYP.js +0 -33
  129. package/dist/chunk-GGL4EF6H.js +0 -38
  130. package/dist/chunk-JBZTQ55D.js +0 -30
  131. package/dist/chunk-KH5GT2Y5.js +0 -104
  132. package/dist/chunk-LUM7SIZN.js +0 -40
  133. package/dist/chunk-MT7RY65Y.js +0 -167
  134. package/dist/chunk-NRZ4GE5O.js +0 -207
  135. package/dist/chunk-OQQNA7L7.js +0 -412
  136. package/dist/chunk-OUJENWQ4.js +0 -45
  137. package/dist/chunk-RMSV4HP6.js +0 -85
  138. package/dist/chunk-RXR7OL76.js +0 -37
  139. package/dist/chunk-VWJKRQZR.js +0 -19
  140. package/dist/chunk-W6HENTK7.js +0 -44
  141. package/dist/chunk-XR5N6ZXJ.js +0 -50
  142. package/dist/core-Bo8KaWQz.d.ts +0 -411
  143. package/dist/load-from-file-HL2VEY3M.js +0 -7
  144. package/dist/loader-NFSL6P5I.js +0 -7
  145. package/dist/loader-T756NSCS.js +0 -7
  146. package/dist/node-DCMYL4DL.js +0 -34
  147. package/dist/vite-QCUPZHHB.js +0 -32
@@ -1,167 +0,0 @@
1
- import {
2
- createCache
3
- } from "./chunk-JBZTQ55D.js";
4
-
5
- // src/utils/code-generator.ts
6
- import path from "path";
7
- import { glob } from "tinyglobby";
8
- function importInfo() {
9
- return {
10
- named: /* @__PURE__ */ new Map(),
11
- namespaces: /* @__PURE__ */ new Set(),
12
- isUsed: /* @__PURE__ */ new Set()
13
- };
14
- }
15
- var CodeGenerator = class {
16
- lines = [];
17
- globCache;
18
- // specifier -> imported members/info
19
- importInfos = /* @__PURE__ */ new Map();
20
- eagerImportId = 0;
21
- options;
22
- constructor({
23
- target = "default",
24
- jsExtension = false,
25
- globCache = /* @__PURE__ */ new Map(),
26
- outDir = ""
27
- }) {
28
- this.options = {
29
- target,
30
- jsExtension,
31
- globCache,
32
- outDir
33
- };
34
- this.globCache = createCache(globCache);
35
- }
36
- addNamespaceImport(namespace, specifier, types = false) {
37
- const info = this.importInfos.get(specifier) ?? importInfo();
38
- this.importInfos.set(specifier, info);
39
- if (!types) info.isUsed.add(namespace);
40
- info.namespaces.add(namespace);
41
- }
42
- addNamedImport(names, specifier, types = false) {
43
- const info = this.importInfos.get(specifier) ?? importInfo();
44
- this.importInfos.set(specifier, info);
45
- for (const name of names) {
46
- const [memberName, importName = memberName] = name.split(/\s+as\s+/, 2);
47
- info.named.set(importName, memberName);
48
- if (!types) info.isUsed.add(importName);
49
- }
50
- }
51
- push(...insert) {
52
- this.lines.push(...insert);
53
- }
54
- async pushAsync(insert) {
55
- for (const line of await Promise.all(insert)) {
56
- if (line === void 0) continue;
57
- this.lines.push(line);
58
- }
59
- }
60
- async generateGlobImport(patterns, options) {
61
- if (this.options.target === "vite") {
62
- return this.generateViteGlobImport(patterns, options);
63
- }
64
- return this.generateNodeGlobImport(patterns, options);
65
- }
66
- generateViteGlobImport(patterns, { base, ...rest }) {
67
- patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
68
- normalizeViteGlobPath
69
- );
70
- return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
71
- {
72
- base: normalizeViteGlobPath(path.relative(this.options.outDir, base)),
73
- ...rest
74
- },
75
- null,
76
- 2
77
- )})`;
78
- }
79
- async generateNodeGlobImport(patterns, { base, eager = false, query = {}, import: importName }) {
80
- const files = await this.globCache.cached(
81
- JSON.stringify({ patterns, base }),
82
- () => glob(patterns, {
83
- cwd: base
84
- })
85
- );
86
- let code = "{";
87
- for (const item of files) {
88
- const fullPath = path.join(base, item);
89
- const searchParams = new URLSearchParams();
90
- for (const [k, v] of Object.entries(query)) {
91
- if (v !== void 0) searchParams.set(k, v);
92
- }
93
- const importPath = `${this.formatImportPath(fullPath)}?${searchParams.toString()}`;
94
- if (eager) {
95
- const name = `__fd_glob_${this.eagerImportId++}`;
96
- this.lines.unshift(
97
- importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
98
- );
99
- code += `${JSON.stringify(item)}: ${name}, `;
100
- } else {
101
- let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
102
- if (importName) {
103
- line += `.then(mod => mod.${importName})`;
104
- }
105
- code += `${line}, `;
106
- }
107
- }
108
- code += "}";
109
- return code;
110
- }
111
- formatImportPath(file) {
112
- const ext = path.extname(file);
113
- let filename;
114
- if (ext === ".ts") {
115
- filename = file.substring(0, file.length - ext.length);
116
- if (this.options.jsExtension) filename += ".js";
117
- } else {
118
- filename = file;
119
- }
120
- const importPath = slash(path.relative(this.options.outDir, filename));
121
- return importPath.startsWith(".") ? importPath : `./${importPath}`;
122
- }
123
- toString() {
124
- const final = ["// @ts-nocheck"];
125
- if (this.options.target === "vite") {
126
- final.push('/// <reference types="vite/client" />');
127
- }
128
- for (const [specifier, info] of this.importInfos) {
129
- const { namespaces, named, isUsed } = info;
130
- for (const namespace of namespaces) {
131
- final.push(
132
- isUsed.has(namespace) ? `import * as ${namespace} from "${specifier}";` : `import type * as ${namespace} from "${specifier}";`
133
- );
134
- }
135
- const namedImports = [];
136
- for (const [importName, memberName] of named) {
137
- const item = importName === memberName ? importName : `${memberName} as ${importName}`;
138
- namedImports.push(isUsed.has(importName) ? item : `type ${item}`);
139
- }
140
- if (namedImports.length > 0) {
141
- final.push(
142
- `import { ${namedImports.join(", ")} } from "${specifier}";`
143
- );
144
- }
145
- }
146
- final.push(...this.lines);
147
- return final.join("\n");
148
- }
149
- };
150
- function normalizeViteGlobPath(file) {
151
- file = slash(file);
152
- if (file.startsWith("./")) return file;
153
- if (file.startsWith("/")) return `.${file}`;
154
- return `./${file}`;
155
- }
156
- function slash(path2) {
157
- const isExtendedLengthPath = path2.startsWith("\\\\?\\");
158
- if (isExtendedLengthPath) {
159
- return path2;
160
- }
161
- return path2.replaceAll("\\", "/");
162
- }
163
-
164
- export {
165
- CodeGenerator,
166
- slash
167
- };
@@ -1,207 +0,0 @@
1
- import {
2
- CodeGenerator
3
- } from "./chunk-MT7RY65Y.js";
4
-
5
- // src/core.ts
6
- import path from "path";
7
- import fs from "fs/promises";
8
- async function getPlugins(pluginOptions) {
9
- const plugins = [];
10
- for (const option of await Promise.all(pluginOptions)) {
11
- if (!option) continue;
12
- if (Array.isArray(option)) plugins.push(...await getPlugins(option));
13
- else plugins.push(option);
14
- }
15
- return plugins;
16
- }
17
- var Core = class _Core {
18
- workspaces = /* @__PURE__ */ new Map();
19
- options;
20
- plugins = [];
21
- config;
22
- static defaultOptions = {
23
- configPath: "content.config.ts",
24
- outDir: ".content"
25
- };
26
- /**
27
- * Convenient cache store, reset when config changes.
28
- *
29
- * You can group namespaces in cache key with ":", like `my-plugin:data`
30
- */
31
- cache = /* @__PURE__ */ new Map();
32
- constructor(options) {
33
- this.options = options;
34
- }
35
- async init({ config: newConfig }) {
36
- this.config = await newConfig;
37
- this.cache.clear();
38
- this.workspaces.clear();
39
- const loadedCollectionTypeIds = /* @__PURE__ */ new Set();
40
- this.plugins = await getPlugins([
41
- this.options.plugins,
42
- this.config.plugins,
43
- ...this.config.collections.values().map(({ typeInfo }) => {
44
- if (loadedCollectionTypeIds.has(typeInfo.id)) return false;
45
- loadedCollectionTypeIds.add(typeInfo.id);
46
- return typeInfo.plugins;
47
- })
48
- ]);
49
- const ctx = this.getPluginContext();
50
- for (const plugin of this.plugins) {
51
- const out = await plugin.config?.call(ctx, this.config);
52
- if (out) this.config = out;
53
- }
54
- const { workspace, outDir } = this.options;
55
- if (!workspace) {
56
- await Promise.all(
57
- Object.entries(this.config.workspaces).map(
58
- async ([name, workspace2]) => {
59
- const child = new _Core({
60
- ...this.options,
61
- outDir: path.join(outDir, name),
62
- workspace: {
63
- name,
64
- parent: this,
65
- dir: workspace2.dir
66
- }
67
- });
68
- await child.init({ config: workspace2.config });
69
- this.workspaces.set(name, child);
70
- }
71
- )
72
- );
73
- }
74
- await Promise.all(
75
- this.config.collections.values().map(async (collection) => {
76
- for (const plugin of this.plugins) {
77
- await plugin.collection?.call(ctx, collection);
78
- }
79
- })
80
- );
81
- }
82
- getWorkspaces() {
83
- return this.workspaces;
84
- }
85
- getOptions() {
86
- return this.options;
87
- }
88
- getConfig() {
89
- return this.config;
90
- }
91
- /**
92
- * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
93
- */
94
- getCompiledConfigPath() {
95
- return path.join(this.options.outDir, "content.config.mjs");
96
- }
97
- getPlugins(workspace = false) {
98
- if (workspace) {
99
- const plugins = [...this.plugins];
100
- for (const workspace2 of this.workspaces.values()) {
101
- plugins.push(...workspace2.plugins);
102
- }
103
- return plugins;
104
- }
105
- return this.plugins;
106
- }
107
- getCollections(workspace = false) {
108
- const list = Array.from(this.config.collections.values());
109
- if (workspace) {
110
- for (const workspace2 of this.workspaces.values()) {
111
- list.push(...workspace2.getCollections());
112
- }
113
- }
114
- return list;
115
- }
116
- getCollection(name) {
117
- return this.config.collections.get(name);
118
- }
119
- getPluginContext() {
120
- return {
121
- core: this
122
- };
123
- }
124
- async initServer(server) {
125
- const ctx = this.getPluginContext();
126
- const promises = [];
127
- for (const plugin of this.plugins) {
128
- promises.push(plugin.configureServer?.call(ctx, server));
129
- }
130
- for (const workspace of this.workspaces.values()) {
131
- promises.push(workspace.initServer(server));
132
- }
133
- await Promise.all(promises);
134
- }
135
- async emit(emitOptions = {}) {
136
- const {
137
- workspace,
138
- outDir,
139
- emit: { target, jsExtension } = {}
140
- } = this.options;
141
- const { filterPlugin, filterWorkspace, write = false } = emitOptions;
142
- const start = performance.now();
143
- const globCache = /* @__PURE__ */ new Map();
144
- const ctx = {
145
- ...this.getPluginContext(),
146
- createCodeGenerator: async (path2, content) => {
147
- const codegen = new CodeGenerator({
148
- target,
149
- outDir,
150
- jsExtension,
151
- globCache
152
- });
153
- await content({
154
- core: this,
155
- codegen,
156
- workspace: workspace?.name
157
- });
158
- return {
159
- path: path2,
160
- content: codegen.toString()
161
- };
162
- }
163
- };
164
- const added = /* @__PURE__ */ new Set();
165
- const out = {
166
- entries: [],
167
- workspaces: {}
168
- };
169
- for (const li of await Promise.all(
170
- this.plugins.map((plugin) => {
171
- if (filterPlugin && !filterPlugin(plugin) || !plugin.emit)
172
- return null;
173
- return plugin.emit.call(ctx);
174
- })
175
- )) {
176
- if (!li) continue;
177
- for (const item of li) {
178
- if (added.has(item.path)) continue;
179
- out.entries.push(item);
180
- added.add(item.path);
181
- }
182
- }
183
- if (write) {
184
- await Promise.all(
185
- out.entries.map(async (entry) => {
186
- const file = path.join(outDir, entry.path);
187
- await fs.mkdir(path.dirname(file), { recursive: true });
188
- await fs.writeFile(file, entry.content);
189
- })
190
- );
191
- console.log(
192
- workspace ? `[MDX: ${workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`
193
- );
194
- }
195
- await Promise.all(
196
- this.workspaces.entries().map(async ([name, workspace2]) => {
197
- if (filterWorkspace && !filterWorkspace(name)) return;
198
- out.workspaces[name] = (await workspace2.emit(emitOptions)).entries;
199
- })
200
- );
201
- return out;
202
- }
203
- };
204
-
205
- export {
206
- Core
207
- };