fuma-content 1.1.3 → 1.1.4
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/{async-cache-CBEZB25o.d.ts → async-cache-BVuJiIDT.d.ts} +1 -1
- package/dist/{async-cache-CBEZB25o.d.ts.map → async-cache-BVuJiIDT.d.ts.map} +1 -1
- package/dist/{build-mdx-DkAvzRNg.d.ts → build-mdx-DRqbcE1d.d.ts} +10 -4
- package/dist/build-mdx-DRqbcE1d.d.ts.map +1 -0
- package/dist/{build-mdx-oug7zk0w.js → build-mdx-DgzggXIL.js} +6 -6
- package/dist/build-mdx-DgzggXIL.js.map +1 -0
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.js +1 -1
- package/dist/{bun-cxKGeSx6.js → bun-Be5pgXW_.js} +4 -3
- package/dist/bun-Be5pgXW_.js.map +1 -0
- package/dist/{code-generator-C_Gu9y3h.js → code-generator-CHcOrCeM.js} +2 -4
- package/dist/code-generator-CHcOrCeM.js.map +1 -0
- package/dist/collections/data/runtime.d.ts +2 -2
- package/dist/collections/data.d.ts +2 -2
- package/dist/collections/data.js +3 -3
- package/dist/collections/fs.d.ts +1 -1
- package/dist/collections/index.d.ts +1 -1
- package/dist/collections/json/loader-webpack.d.ts +2 -2
- package/dist/collections/json/loader-webpack.js +2 -2
- package/dist/collections/mdx/loader-webpack.d.ts +2 -2
- package/dist/collections/mdx/loader-webpack.js +2 -2
- package/dist/collections/mdx/react.d.ts +2 -3
- package/dist/collections/mdx/react.d.ts.map +1 -1
- package/dist/collections/mdx/react.js +2 -1
- package/dist/collections/mdx/react.js.map +1 -1
- package/dist/collections/mdx/runtime-browser.d.ts +3 -4
- package/dist/collections/mdx/runtime-browser.d.ts.map +1 -1
- package/dist/collections/mdx/runtime-dynamic.d.ts +2 -3
- package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -1
- package/dist/collections/mdx/runtime-dynamic.js +9 -4
- package/dist/collections/mdx/runtime-dynamic.js.map +1 -1
- package/dist/collections/mdx/runtime.d.ts +2 -3
- package/dist/collections/mdx/runtime.d.ts.map +1 -1
- package/dist/collections/mdx.d.ts +2 -3
- package/dist/collections/mdx.d.ts.map +1 -1
- package/dist/collections/mdx.js +24 -26
- package/dist/collections/mdx.js.map +1 -1
- package/dist/collections/obsidian.d.ts +10 -0
- package/dist/collections/obsidian.d.ts.map +1 -0
- package/dist/collections/obsidian.js +497 -0
- package/dist/collections/obsidian.js.map +1 -0
- package/dist/collections/runtime/file-store.d.ts +1 -1
- package/dist/collections/runtime/store.d.ts +1 -1
- package/dist/collections/yaml/loader-webpack.d.ts +2 -2
- package/dist/collections/yaml/loader-webpack.js +2 -2
- package/dist/config/index.d.ts +1 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/{core-DmbQk8Z2.js → core-BuUsOElL.js} +2 -2
- package/dist/{core-DmbQk8Z2.js.map → core-BuUsOElL.js.map} +1 -1
- package/dist/{core-CG2zTL4c.d.ts → core-FjA_Xoho.d.ts} +1 -2
- package/dist/core-FjA_Xoho.d.ts.map +1 -0
- package/dist/dynamic.d.ts +2 -2
- package/dist/dynamic.js +1 -1
- package/dist/{fuma-matter-Pwr2S9Ab.js → fuma-matter-B4gT09gM.js} +1 -1
- package/dist/{fuma-matter-Pwr2S9Ab.js.map → fuma-matter-B4gT09gM.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/is-promise-like-DYHv0Yap.js +8 -0
- package/dist/is-promise-like-DYHv0Yap.js.map +1 -0
- package/dist/{load-from-file-BeLFB77e.js → load-from-file-BhdBOcQT.js} +1 -1
- package/dist/{load-from-file-BeLFB77e.js.map → load-from-file-BhdBOcQT.js.map} +1 -1
- package/dist/{load-from-file-CpA8UQXX.d.ts → load-from-file-CIYdu-B5.d.ts} +1 -1
- package/dist/load-from-file-CIYdu-B5.d.ts.map +1 -0
- package/dist/{loader-DTODFdmk.js → loader-BOYLUNfh.js} +2 -2
- package/dist/{loader-DTODFdmk.js.map → loader-BOYLUNfh.js.map} +1 -1
- package/dist/{loader-DOjRBsog.js → loader-BT4fwLTJ.js} +9 -5
- package/dist/loader-BT4fwLTJ.js.map +1 -0
- package/dist/{loader-DKTW82eK.js → loader-Cb9kSSxT.js} +2 -2
- package/dist/{loader-DKTW82eK.js.map → loader-Cb9kSSxT.js.map} +1 -1
- package/dist/{loader-gwXIGo5Q.js → loader-UhlX4xbz.js} +1 -1
- package/dist/{loader-gwXIGo5Q.js.map → loader-UhlX4xbz.js.map} +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +2 -2
- package/dist/node/index.d.ts +1 -1
- package/dist/node/loader.d.ts +1 -1
- package/dist/node/loader.js +1 -1
- package/dist/{node-l03HaPSS.js → node-Cu5Pqxxo.js} +2 -2
- package/dist/node-Cu5Pqxxo.js.map +1 -0
- package/dist/plugins/git.d.ts +1 -1
- package/dist/plugins/json-schema.d.ts +1 -1
- package/dist/plugins/loader/index.d.ts +4 -7
- package/dist/plugins/loader/index.d.ts.map +1 -1
- package/dist/plugins/loader/index.js +5 -4
- package/dist/plugins/loader/index.js.map +1 -1
- package/dist/plugins/loader/webpack.d.ts +2 -2
- package/dist/plugins/loader/webpack.js +4 -2
- package/dist/plugins/loader/webpack.js.map +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +3 -14
- package/dist/vite/index.js.map +1 -1
- package/dist/{vite-mAc2TZyp.js → vite-CoJIMNWk.js} +3 -3
- package/dist/vite-CoJIMNWk.js.map +1 -0
- package/package.json +14 -7
- package/dist/build-mdx-DkAvzRNg.d.ts.map +0 -1
- package/dist/build-mdx-oug7zk0w.js.map +0 -1
- package/dist/bun-cxKGeSx6.js.map +0 -1
- package/dist/code-generator-C_Gu9y3h.js.map +0 -1
- package/dist/core-CG2zTL4c.d.ts.map +0 -1
- package/dist/load-from-file-CpA8UQXX.d.ts.map +0 -1
- package/dist/loader-DOjRBsog.js.map +0 -1
- package/dist/node-l03HaPSS.js.map +0 -1
- package/dist/vite-mAc2TZyp.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-DmbQk8Z2.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport type { FSWatcher } from \"chokidar\";\nimport { Collection } from \"@/collections\";\nimport type * as Vite from \"vite\";\nimport type { NextConfig } from \"next\";\nimport type { LoadHook } from \"node:module\";\nimport { CodeGenerator } from \"@/utils/code-generator\";\nimport type { Awaitable } from \"@/types\";\nimport type { GlobalConfig } from \"./config\";\n\nexport interface ResolvedConfig extends Omit<GlobalConfig, \"collections\"> {\n collections: Map<string, Collection>;\n}\n\nexport interface EmitEntry {\n /**\n * path relative to output directory\n */\n path: string;\n content: string;\n}\n\nexport interface PluginContext {\n core: Core;\n}\n\nexport interface EmitContext extends PluginContext {\n createCodeGenerator: (\n path: string,\n content: (ctx: { codegen: CodeGenerator }) => Awaitable<void>,\n ) => Promise<EmitEntry>;\n}\n\nexport interface Plugin {\n /**\n * unique name for plugin\n *\n * @example `my-package:my-plugin`\n */\n name: string;\n\n /** when `true`, only keep the last plugin with same `name`. */\n dedupe?: boolean;\n\n /**\n * on config loaded/updated\n */\n config?: (this: PluginContext, config: ResolvedConfig) => Awaitable<void | ResolvedConfig>;\n\n /**\n * called after collection initialization\n */\n collection?: (this: PluginContext, collection: Collection) => Awaitable<void>;\n\n /**\n * Configure watch/dev server\n */\n configureServer?: (this: PluginContext, server: ServerContext) => void;\n\n vite?: {\n createPlugin?: (this: PluginContext) => Vite.PluginOption;\n };\n\n bun?: {\n setup?: (this: PluginContext, build: Bun.PluginBuilder) => Awaitable<void>;\n };\n\n next?: {\n config?: (this: PluginContext, config: NextConfig) => NextConfig;\n };\n\n node?: {\n createLoad?: (this: PluginContext) => Awaitable<LoadHook>;\n };\n}\n\nexport type PluginOption = Awaitable<Plugin | PluginOption[] | false | undefined>;\n\nexport interface ServerContext {\n /**\n * the file watcher, by default all content files are watched, along with other files.\n *\n * make sure to filter when listening to events\n */\n watcher?: FSWatcher;\n}\n\nexport type CoreOptions = Partial<ResolvedCoreOptions>;\n\n/**\n * the resolved options, all paths are absolute\n */\nexport interface ResolvedCoreOptions {\n cwd: string;\n /**\n * Path to source configuration file\n *\n * @defaultValue content.config.ts\n */\n configPath: string;\n /**\n * Directory for output files\n *\n * @defaultValue '.content'\n */\n outDir: string;\n /**\n * the workspace info if this instance is created as a workspace\n */\n workspace?: {\n parent: Core;\n name: string;\n dir: string;\n };\n plugins?: PluginOption;\n}\n\nexport interface EmitOptions {\n /**\n * filter the collections to run emit\n */\n filterCollection?: (collection: Collection) => boolean;\n\n /**\n * filter the workspaces to run emit\n */\n filterWorkspace?: (workspace: string) => boolean;\n\n /**\n * write files\n */\n write?: boolean;\n}\n\nexport interface EmitOutput {\n entries: EmitEntry[];\n workspaces: Record<string, EmitEntry[]>;\n}\n\nasync function getPlugins(pluginOptions: PluginOption[], dedupe = true): Promise<Plugin[]> {\n const plugins: Plugin[] = [];\n for (const option of await Promise.all(pluginOptions)) {\n if (!option) continue;\n if (Array.isArray(option)) plugins.push(...(await getPlugins(option, false)));\n else plugins.push(option);\n }\n\n if (!dedupe) return plugins;\n\n const excludedName = new Set<string>();\n const deduped: Plugin[] = [];\n for (let i = plugins.length - 1; i >= 0; i--) {\n const plugin = plugins[i];\n if (excludedName.has(plugin.name)) continue;\n deduped.unshift(plugin);\n if (plugin.dedupe) excludedName.add(plugin.name);\n }\n return deduped;\n}\n\nexport class Core {\n private readonly workspaces = new Map<string, Core>();\n private readonly options: ResolvedCoreOptions;\n private plugins: Plugin[] = [];\n private config!: ResolvedConfig;\n static defaultOptions = {\n configPath: \"content.config.ts\",\n outDir: \".content\",\n };\n\n /**\n * Convenient cache store, reset when config changes.\n *\n * You can group namespaces in cache key with \":\", like `my-plugin:data`\n */\n readonly cache = new Map<string, unknown>();\n\n constructor(options: CoreOptions = {}) {\n const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();\n this.options = {\n ...options,\n cwd,\n outDir: path.resolve(cwd, options.outDir ?? Core.defaultOptions.outDir),\n configPath: path.resolve(cwd, options.configPath ?? Core.defaultOptions.configPath),\n };\n }\n\n async init({\n config: newConfig,\n }: {\n /**\n * either the default export or all exports of config file.\n */\n config: Awaitable<Record<string, unknown>>;\n }) {\n this.config = await this.initConfig(await newConfig);\n this.cache.clear();\n this.workspaces.clear();\n this.plugins = await getPlugins([\n this.options.plugins,\n this.config.plugins,\n ...this.config.collections.values().map((collection) => collection.plugins),\n ]);\n\n const ctx = this.getPluginContext();\n for (const plugin of this.plugins) {\n const out = await plugin.config?.call(ctx, this.config);\n if (out) this.config = out;\n }\n\n await Promise.all(\n this.config.collections.values().map(async (collection) => {\n collection.onConfig.run({ collection, core: this, config: this.config });\n\n for (const plugin of this.plugins) {\n await plugin.collection?.call(ctx, collection);\n }\n }),\n );\n\n // only support workspaces with max depth 1\n if (!this.options.workspace && this.config.workspaces) {\n await Promise.all(\n Object.entries(this.config.workspaces).map(async ([name, workspace]) => {\n const child = new Core({\n ...this.options,\n cwd: path.resolve(this.options.cwd, workspace.dir),\n workspace: {\n name,\n parent: this,\n dir: workspace.dir,\n },\n });\n\n await child.init({ config: workspace.config as Record<string, unknown> });\n this.workspaces.set(name, child);\n }),\n );\n }\n }\n\n getWorkspace() {\n return this.options.workspace;\n }\n getWorkspaces() {\n return this.workspaces;\n }\n getOptions() {\n return this.options;\n }\n getConfig(): ResolvedConfig {\n return this.config;\n }\n /**\n * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)\n */\n getCompiledConfigPath(): string {\n return path.join(this.options.outDir, \"content.config.mjs\");\n }\n getPlugins(workspace = false) {\n if (workspace) {\n const plugins = [...this.plugins];\n for (const workspace of this.workspaces.values()) {\n plugins.push(...workspace.plugins);\n }\n return plugins;\n }\n\n return this.plugins;\n }\n getCollections(workspace = false): Collection[] {\n const list = Array.from(this.config.collections.values());\n if (workspace) {\n for (const workspace of this.workspaces.values()) {\n list.push(...workspace.getCollections());\n }\n }\n return list;\n }\n getCollection(name: string): Collection | undefined {\n return this.config.collections.get(name);\n }\n getPluginContext(): PluginContext {\n return {\n core: this,\n };\n }\n async initServer(server: ServerContext) {\n const ctx = this.getPluginContext();\n\n server.watcher?.add(this.options.configPath);\n for (const plugin of this.plugins) {\n plugin.configureServer?.call(ctx, server);\n }\n for (const collection of this.getCollections()) {\n collection.onServer.run({ collection, core: this, server });\n }\n for (const workspace of this.workspaces.values()) {\n await workspace.initServer(server);\n }\n }\n\n async clearOutputDirectory() {\n await fs.rm(this.options.outDir, { recursive: true, force: true });\n }\n\n async emit(emitOptions: EmitOptions = {}): Promise<EmitOutput> {\n const emitConfig = this.config.emit;\n const { workspace, outDir } = this.options;\n const { filterCollection, filterWorkspace, write = false } = emitOptions;\n const start = performance.now();\n const ctx: EmitContext = {\n core: this,\n async createCodeGenerator(path, content) {\n const codegen = new CodeGenerator({\n ...emitConfig,\n outDir,\n });\n await content({\n codegen,\n });\n return {\n path,\n content: codegen.toString(),\n };\n },\n };\n\n const out: EmitOutput = {\n entries: [],\n workspaces: {},\n };\n\n const entryMap = new Map<string, EmitEntry>();\n const generated: Awaitable<EmitEntry[]>[] = [];\n for (const collection of this.getCollections()) {\n if (filterCollection && !filterCollection(collection)) continue;\n generated.push(collection.onEmit.run([], ctx));\n }\n for (const entries of await Promise.all(generated)) {\n for (const item of entries) {\n entryMap.set(item.path, item);\n }\n }\n out.entries = Array.from(entryMap.values());\n\n if (write) {\n await Promise.all(\n out.entries.map(async (entry) => {\n const file = path.join(outDir, entry.path);\n await fs.mkdir(path.dirname(file), { recursive: true });\n await fs.writeFile(file, entry.content);\n }),\n );\n\n console.log(\n workspace\n ? `[fuma-content: ${workspace.name}] generated files in ${performance.now() - start}ms`\n : `[fuma-content] generated files in ${performance.now() - start}ms`,\n );\n }\n\n for (const [name, workspace] of this.workspaces.entries()) {\n if (filterWorkspace && !filterWorkspace(name)) continue;\n out.workspaces[name] = (await workspace.emit(emitOptions)).entries;\n }\n\n return out;\n }\n\n /**\n * convert absolute path into a runtime path (relative to **runtime** cwd)\n */\n _toRuntimePath(absolutePath: string) {\n return path.relative(process.cwd(), absolutePath);\n }\n\n private async initConfig(config: Record<string, unknown>): Promise<ResolvedConfig> {\n const collections = new Map<string, Collection>();\n let globalConfig: GlobalConfig;\n\n if (\"default\" in config) {\n globalConfig = config.default as GlobalConfig;\n for (const [k, v] of Object.entries(config)) {\n if (v instanceof Collection) {\n globalConfig.collections ??= {};\n globalConfig.collections[k] = v;\n }\n }\n } else {\n globalConfig = config as GlobalConfig;\n }\n\n globalConfig.collections ??= {};\n await Promise.all(\n Object.entries(globalConfig.collections).map(async ([name, collection]) => {\n collection.name = name;\n collections.set(name, collection);\n await collection.onInit.run({ collection, core: this });\n }),\n );\n return {\n ...globalConfig,\n collections,\n };\n }\n}\n"],"mappings":";;;;;;AA4IA,eAAe,WAAW,eAA+B,SAAS,MAAyB;CACzF,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,UAAU,MAAM,QAAQ,IAAI,cAAc,EAAE;AACrD,MAAI,CAAC,OAAQ;AACb,MAAI,MAAM,QAAQ,OAAO,CAAE,SAAQ,KAAK,GAAI,MAAM,WAAW,QAAQ,MAAM,CAAE;MACxE,SAAQ,KAAK,OAAO;;AAG3B,KAAI,CAAC,OAAQ,QAAO;CAEpB,MAAM,+BAAe,IAAI,KAAa;CACtC,MAAM,UAAoB,EAAE;AAC5B,MAAK,IAAI,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;EAC5C,MAAM,SAAS,QAAQ;AACvB,MAAI,aAAa,IAAI,OAAO,KAAK,CAAE;AACnC,UAAQ,QAAQ,OAAO;AACvB,MAAI,OAAO,OAAQ,cAAa,IAAI,OAAO,KAAK;;AAElD,QAAO;;AAGT,IAAa,OAAb,MAAa,KAAK;CAChB,AAAiB,6B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,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,UAAM,GAAG,UAAU,MAAM,MAAM,QAAQ;KACvC,CACH;AAED,WAAQ,IACN,YACI,kBAAkB,UAAU,KAAK,uBAAuB,YAAY,KAAK,GAAG,MAAM,MAClF,qCAAqC,YAAY,KAAK,GAAG,MAAM,IACpE;;AAGH,OAAK,MAAM,CAAC,MAAM,cAAc,KAAK,WAAW,SAAS,EAAE;AACzD,OAAI,mBAAmB,CAAC,gBAAgB,KAAK,CAAE;AAC/C,OAAI,WAAW,SAAS,MAAM,UAAU,KAAK,YAAY,EAAE;;AAG7D,SAAO;;;;;CAMT,eAAe,cAAsB;AACnC,SAAO,KAAK,SAAS,QAAQ,KAAK,EAAE,aAAa;;CAGnD,MAAc,WAAW,QAA0D;EACjF,MAAM,8BAAc,IAAI,KAAyB;EACjD,IAAI;AAEJ,MAAI,aAAa,QAAQ;AACvB,kBAAe,OAAO;AACtB,QAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,OAAO,CACzC,KAAI,aAAa,YAAY;AAC3B,iBAAa,gBAAgB,EAAE;AAC/B,iBAAa,YAAY,KAAK;;QAIlC,gBAAe;AAGjB,eAAa,gBAAgB,EAAE;AAC/B,QAAM,QAAQ,IACZ,OAAO,QAAQ,aAAa,YAAY,CAAC,IAAI,OAAO,CAAC,MAAM,gBAAgB;AACzE,cAAW,OAAO;AAClB,eAAY,IAAI,MAAM,WAAW;AACjC,SAAM,WAAW,OAAO,IAAI;IAAE;IAAY,MAAM;IAAM,CAAC;IACvD,CACH;AACD,SAAO;GACL,GAAG;GACH;GACD"}
|
|
1
|
+
{"version":3,"file":"core-BuUsOElL.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport type { FSWatcher } from \"chokidar\";\nimport { Collection } from \"@/collections\";\nimport type * as Vite from \"vite\";\nimport type { NextConfig } from \"next\";\nimport type { LoadHook } from \"node:module\";\nimport { CodeGenerator } from \"@/utils/code-generator\";\nimport type { Awaitable } from \"@/types\";\nimport type { GlobalConfig } from \"./config\";\n\nexport interface ResolvedConfig extends Omit<GlobalConfig, \"collections\"> {\n collections: Map<string, Collection>;\n}\n\nexport interface EmitEntry {\n /**\n * path relative to output directory\n */\n path: string;\n content: string;\n}\n\nexport interface PluginContext {\n core: Core;\n}\n\nexport interface EmitContext extends PluginContext {\n createCodeGenerator: (\n path: string,\n content: (ctx: { codegen: CodeGenerator }) => Awaitable<void>,\n ) => Promise<EmitEntry>;\n}\n\nexport interface Plugin {\n /**\n * unique name for plugin\n *\n * @example `my-package:my-plugin`\n */\n name: string;\n\n /** when `true`, only keep the last plugin with same `name`. */\n dedupe?: boolean;\n\n /**\n * on config loaded/updated\n */\n config?: (this: PluginContext, config: ResolvedConfig) => Awaitable<void | ResolvedConfig>;\n\n /**\n * called after collection initialization\n */\n collection?: (this: PluginContext, collection: Collection) => Awaitable<void>;\n\n /**\n * Configure watch/dev server\n */\n configureServer?: (this: PluginContext, server: ServerContext) => void;\n\n vite?: {\n createPlugin?: (this: PluginContext) => Vite.PluginOption;\n };\n\n bun?: {\n setup?: (this: PluginContext, build: Bun.PluginBuilder) => Awaitable<void>;\n };\n\n next?: {\n config?: (this: PluginContext, config: NextConfig) => NextConfig;\n };\n\n node?: {\n createLoad?: (this: PluginContext) => Awaitable<LoadHook>;\n };\n}\n\nexport type PluginOption = Awaitable<Plugin | PluginOption[] | false | undefined>;\n\nexport interface ServerContext {\n /**\n * the file watcher, by default all content files are watched, along with other files.\n *\n * make sure to filter when listening to events\n */\n watcher?: FSWatcher;\n}\n\nexport type CoreOptions = Partial<ResolvedCoreOptions>;\n\n/**\n * the resolved options, all paths are absolute\n */\nexport interface ResolvedCoreOptions {\n cwd: string;\n /**\n * Path to source configuration file\n *\n * @defaultValue content.config.ts\n */\n configPath: string;\n /**\n * Directory for output files\n *\n * @defaultValue '.content'\n */\n outDir: string;\n /**\n * the workspace info if this instance is created as a workspace\n */\n workspace?: {\n parent: Core;\n name: string;\n dir: string;\n };\n plugins?: PluginOption;\n}\n\nexport interface EmitOptions {\n /**\n * filter the collections to run emit\n */\n filterCollection?: (collection: Collection) => boolean;\n\n /**\n * filter the workspaces to run emit\n */\n filterWorkspace?: (workspace: string) => boolean;\n\n /**\n * write files\n */\n write?: boolean;\n}\n\nexport interface EmitOutput {\n entries: EmitEntry[];\n workspaces: Record<string, EmitEntry[]>;\n}\n\nasync function getPlugins(pluginOptions: PluginOption[], dedupe = true): Promise<Plugin[]> {\n const plugins: Plugin[] = [];\n for (const option of await Promise.all(pluginOptions)) {\n if (!option) continue;\n if (Array.isArray(option)) plugins.push(...(await getPlugins(option, false)));\n else plugins.push(option);\n }\n\n if (!dedupe) return plugins;\n\n const excludedName = new Set<string>();\n const deduped: Plugin[] = [];\n for (let i = plugins.length - 1; i >= 0; i--) {\n const plugin = plugins[i];\n if (excludedName.has(plugin.name)) continue;\n deduped.unshift(plugin);\n if (plugin.dedupe) excludedName.add(plugin.name);\n }\n return deduped;\n}\n\nexport class Core {\n private readonly workspaces = new Map<string, Core>();\n private readonly options: ResolvedCoreOptions;\n private plugins: Plugin[] = [];\n private config!: ResolvedConfig;\n static defaultOptions = {\n configPath: \"content.config.ts\",\n outDir: \".content\",\n };\n\n /**\n * Convenient cache store, reset when config changes.\n *\n * You can group namespaces in cache key with \":\", like `my-plugin:data`\n */\n readonly cache = new Map<string, unknown>();\n\n constructor(options: CoreOptions = {}) {\n const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();\n this.options = {\n ...options,\n cwd,\n outDir: path.resolve(cwd, options.outDir ?? Core.defaultOptions.outDir),\n configPath: path.resolve(cwd, options.configPath ?? Core.defaultOptions.configPath),\n };\n }\n\n async init({\n config: newConfig,\n }: {\n /**\n * either the default export or all exports of config file.\n */\n config: Awaitable<Record<string, unknown>>;\n }) {\n this.config = await this.initConfig(await newConfig);\n this.cache.clear();\n this.workspaces.clear();\n this.plugins = await getPlugins([\n this.options.plugins,\n this.config.plugins,\n ...this.config.collections.values().map((collection) => collection.plugins),\n ]);\n\n const ctx = this.getPluginContext();\n for (const plugin of this.plugins) {\n const out = await plugin.config?.call(ctx, this.config);\n if (out) this.config = out;\n }\n\n await Promise.all(\n this.config.collections.values().map(async (collection) => {\n collection.onConfig.run({ collection, core: this, config: this.config });\n\n for (const plugin of this.plugins) {\n await plugin.collection?.call(ctx, collection);\n }\n }),\n );\n\n // only support workspaces with max depth 1\n if (!this.options.workspace && this.config.workspaces) {\n await Promise.all(\n Object.entries(this.config.workspaces).map(async ([name, workspace]) => {\n const child = new Core({\n ...this.options,\n cwd: path.resolve(this.options.cwd, workspace.dir),\n workspace: {\n name,\n parent: this,\n dir: workspace.dir,\n },\n });\n\n await child.init({ config: workspace.config as Record<string, unknown> });\n this.workspaces.set(name, child);\n }),\n );\n }\n }\n\n getWorkspace() {\n return this.options.workspace;\n }\n getWorkspaces() {\n return this.workspaces;\n }\n getOptions() {\n return this.options;\n }\n getConfig(): ResolvedConfig {\n return this.config;\n }\n /**\n * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)\n */\n getCompiledConfigPath(): string {\n return path.join(this.options.outDir, \"content.config.mjs\");\n }\n getPlugins(workspace = false) {\n if (workspace) {\n const plugins = [...this.plugins];\n for (const workspace of this.workspaces.values()) {\n plugins.push(...workspace.plugins);\n }\n return plugins;\n }\n\n return this.plugins;\n }\n getCollections(workspace = false): Collection[] {\n const list = Array.from(this.config.collections.values());\n if (workspace) {\n for (const workspace of this.workspaces.values()) {\n list.push(...workspace.getCollections());\n }\n }\n return list;\n }\n getCollection(name: string): Collection | undefined {\n return this.config.collections.get(name);\n }\n getPluginContext(): PluginContext {\n return {\n core: this,\n };\n }\n async initServer(server: ServerContext) {\n const ctx = this.getPluginContext();\n\n server.watcher?.add(this.options.configPath);\n for (const plugin of this.plugins) {\n plugin.configureServer?.call(ctx, server);\n }\n for (const collection of this.getCollections()) {\n collection.onServer.run({ collection, core: this, server });\n }\n for (const workspace of this.workspaces.values()) {\n await workspace.initServer(server);\n }\n }\n\n async clearOutputDirectory() {\n await fs.rm(this.options.outDir, { recursive: true, force: true });\n }\n\n async emit(emitOptions: EmitOptions = {}): Promise<EmitOutput> {\n const emitConfig = this.config.emit;\n const { workspace, outDir } = this.options;\n const { filterCollection, filterWorkspace, write = false } = emitOptions;\n const start = performance.now();\n const ctx: EmitContext = {\n core: this,\n async createCodeGenerator(path, content) {\n const codegen = new CodeGenerator({\n ...emitConfig,\n outDir,\n });\n await content({\n codegen,\n });\n return {\n path,\n content: codegen.toString(),\n };\n },\n };\n\n const out: EmitOutput = {\n entries: [],\n workspaces: {},\n };\n\n const entryMap = new Map<string, EmitEntry>();\n const generated: Awaitable<EmitEntry[]>[] = [];\n for (const collection of this.getCollections()) {\n if (filterCollection && !filterCollection(collection)) continue;\n generated.push(collection.onEmit.run([], ctx));\n }\n for (const entries of await Promise.all(generated)) {\n for (const item of entries) {\n entryMap.set(item.path, item);\n }\n }\n out.entries = Array.from(entryMap.values());\n\n if (write) {\n await Promise.all(\n out.entries.map(async (entry) => {\n const file = path.join(outDir, entry.path);\n await fs.mkdir(path.dirname(file), { recursive: true });\n await fs.writeFile(file, entry.content);\n }),\n );\n\n console.log(\n workspace\n ? `[fuma-content: ${workspace.name}] generated files in ${performance.now() - start}ms`\n : `[fuma-content] generated files in ${performance.now() - start}ms`,\n );\n }\n\n for (const [name, workspace] of this.workspaces.entries()) {\n if (filterWorkspace && !filterWorkspace(name)) continue;\n out.workspaces[name] = (await workspace.emit(emitOptions)).entries;\n }\n\n return out;\n }\n\n /**\n * convert absolute path into a runtime path (relative to **runtime** cwd)\n */\n _toRuntimePath(absolutePath: string) {\n return path.relative(process.cwd(), absolutePath);\n }\n\n private async initConfig(config: Record<string, unknown>): Promise<ResolvedConfig> {\n const collections = new Map<string, Collection>();\n let globalConfig: GlobalConfig;\n\n if (\"default\" in config) {\n globalConfig = config.default as GlobalConfig;\n for (const [k, v] of Object.entries(config)) {\n if (v instanceof Collection) {\n globalConfig.collections ??= {};\n globalConfig.collections[k] = v;\n }\n }\n } else {\n globalConfig = config as GlobalConfig;\n }\n\n globalConfig.collections ??= {};\n await Promise.all(\n Object.entries(globalConfig.collections).map(async ([name, collection]) => {\n collection.name = name;\n collections.set(name, collection);\n await collection.onInit.run({ collection, core: this });\n }),\n );\n return {\n ...globalConfig,\n collections,\n };\n }\n}\n"],"mappings":";;;;;;AA4IA,eAAe,WAAW,eAA+B,SAAS,MAAyB;CACzF,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,UAAU,MAAM,QAAQ,IAAI,cAAc,EAAE;AACrD,MAAI,CAAC,OAAQ;AACb,MAAI,MAAM,QAAQ,OAAO,CAAE,SAAQ,KAAK,GAAI,MAAM,WAAW,QAAQ,MAAM,CAAE;MACxE,SAAQ,KAAK,OAAO;;AAG3B,KAAI,CAAC,OAAQ,QAAO;CAEpB,MAAM,+BAAe,IAAI,KAAa;CACtC,MAAM,UAAoB,EAAE;AAC5B,MAAK,IAAI,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;EAC5C,MAAM,SAAS,QAAQ;AACvB,MAAI,aAAa,IAAI,OAAO,KAAK,CAAE;AACnC,UAAQ,QAAQ,OAAO;AACvB,MAAI,OAAO,OAAQ,cAAa,IAAI,OAAO,KAAK;;AAElD,QAAO;;AAGT,IAAa,OAAb,MAAa,KAAK;CAChB,AAAiB,6BAAa,IAAI,KAAmB;CACrD,AAAiB;CACjB,AAAQ,UAAoB,EAAE;CAC9B,AAAQ;CACR,OAAO,iBAAiB;EACtB,YAAY;EACZ,QAAQ;EACT;;;;;;CAOD,AAAS,wBAAQ,IAAI,KAAsB;CAE3C,YAAY,UAAuB,EAAE,EAAE;EACrC,MAAM,MAAM,QAAQ,MAAM,KAAK,QAAQ,QAAQ,IAAI,GAAG,QAAQ,KAAK;AACnE,OAAK,UAAU;GACb,GAAG;GACH;GACA,QAAQ,KAAK,QAAQ,KAAK,QAAQ,UAAU,KAA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AAU,KAAK,YAAY,EAAE;;AAG7D,SAAO;;;;;CAMT,eAAe,cAAsB;AACnC,SAAO,KAAK,SAAS,QAAQ,KAAK,EAAE,aAAa;;CAGnD,MAAc,WAAW,QAA0D;EACjF,MAAM,8BAAc,IAAI,KAAyB;EACjD,IAAI;AAEJ,MAAI,aAAa,QAAQ;AACvB,kBAAe,OAAO;AACtB,QAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,OAAO,CACzC,KAAI,aAAa,YAAY;AAC3B,iBAAa,gBAAgB,EAAE;AAC/B,iBAAa,YAAY,KAAK;;QAIlC,gBAAe;AAGjB,eAAa,gBAAgB,EAAE;AAC/B,QAAM,QAAQ,IACZ,OAAO,QAAQ,aAAa,YAAY,CAAC,IAAI,OAAO,CAAC,MAAM,gBAAgB;AACzE,cAAW,OAAO;AAClB,eAAY,IAAI,MAAM,WAAW;AACjC,SAAM,WAAW,OAAO,IAAI;IAAE;IAAY,MAAM;IAAM,CAAC;IACvD,CACH;AACD,SAAO;GACL,GAAG;GACH;GACD"}
|
|
@@ -72,7 +72,6 @@ declare class CodeGenerator {
|
|
|
72
72
|
private eagerImportId;
|
|
73
73
|
readonly options: CodeGeneratorOptions;
|
|
74
74
|
constructor({
|
|
75
|
-
target,
|
|
76
75
|
jsExtension,
|
|
77
76
|
outDir
|
|
78
77
|
}: Partial<CodeGeneratorOptions>);
|
|
@@ -247,4 +246,4 @@ declare class Core {
|
|
|
247
246
|
}
|
|
248
247
|
//#endregion
|
|
249
248
|
export { GetCollectionConfig as C, Awaitable as S, pipe as _, EmitOptions as a, asyncHook as b, PluginContext as c, ResolvedCoreOptions as d, ServerContext as f, asyncPipe as g, Pipe as h, EmitEntry as i, PluginOption$1 as l, AsyncPipe as m, CoreOptions as n, EmitOutput as o, CodeGenerator as p, EmitContext as r, Plugin as s, Core as t, ResolvedConfig as u, AsyncHook as v, hook as x, Hook as y };
|
|
250
|
-
//# sourceMappingURL=core-
|
|
249
|
+
//# sourceMappingURL=core-FjA_Xoho.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-FjA_Xoho.d.ts","names":[],"sources":["../src/types.ts","../src/utils/hook.ts","../src/utils/pipe.ts","../src/utils/code-generator.ts","../src/core.ts"],"mappings":";;;;;;;;KAIY,mBAAA,gCACV,MAAA,SAAe,MAAA,CAAO,IAAA,EAAM,UAAA,IACxB,MAAA,CAAO,IAAA,IACP,MAAA;EACI,OAAA,EAAS,YAAA;AAAA,IAEX,WAAA,CAAY,IAAA;AAAA,KAGR,SAAA,MAAe,CAAA,GAAI,WAAA,CAAY,CAAA;;;UCX1B,IAAA;;;;;;EAMf,IAAA,GAAO,EAAA,GAAK,OAAA,EAAS,OAAA,cAAqB,IAAA,CAAK,OAAA;EAC/C,GAAA,GAAM,OAAA,EAAS,OAAA;EACf,aAAA,GAAgB,OAAA,EAAS,OAAA,KAAY,SAAA;AAAA;AAAA,UAGtB,SAAA;EDRO;;;;;ECctB,IAAA,GAAO,EAAA,GAAK,OAAA,EAAS,OAAA,KAAY,SAAA,WAAoB,SAAA,CAAU,OAAA;EAC/D,GAAA,GAAM,OAAA,EAAS,OAAA,KAAY,SAAA;EAC3B,aAAA,GAAgB,OAAA,EAAS,OAAA,KAAY,SAAA;AAAA;AAAA,iBAGvB,IAAA,SAAA,CAAc,KAAA,KAAS,GAAA,EAAK,OAAA,eAA2B,IAAA,CAAK,OAAA;AAAA,iBAa5D,SAAA,SAAA,CACd,KAAA,KAAS,GAAA,EAAK,OAAA,KAAY,SAAA,YACzB,SAAA,CAAU,OAAA;;;UCrCI,IAAA;;;;;;EAMf,IAAA,GAAO,EAAA,GAAK,IAAA,EAAM,IAAA,EAAM,OAAA,EAAS,OAAA,KAAY,IAAA,KAAS,IAAA,CAAK,IAAA,EAAM,OAAA;EACjE,GAAA,GAAM,IAAA,EAAM,IAAA,EAAM,OAAA,EAAS,OAAA,KAAY,IAAA;EACvC,aAAA,GAAgB,IAAA,EAAM,IAAA,EA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t as Core } from "./core-
|
|
2
|
-
import { t as CompileMode } from "./load-from-file-
|
|
1
|
+
import { t as Core } from "./core-FjA_Xoho.js";
|
|
2
|
+
import { t as CompileMode } from "./load-from-file-CIYdu-B5.js";
|
|
3
3
|
|
|
4
4
|
//#region src/dynamic.d.ts
|
|
5
5
|
interface DynamicCore {
|
package/dist/dynamic.js
CHANGED
|
@@ -10,7 +10,7 @@ function createDynamicCore({ core, compileMode = true, mode }) {
|
|
|
10
10
|
})).mtime.getTime().toString();
|
|
11
11
|
}
|
|
12
12
|
async function init() {
|
|
13
|
-
const { loadConfig } = await import("./load-from-file-
|
|
13
|
+
const { loadConfig } = await import("./load-from-file-BhdBOcQT.js").then((n) => n.n);
|
|
14
14
|
await core.init({ config: loadConfig(core, compileMode) });
|
|
15
15
|
}
|
|
16
16
|
return { async getCore() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fuma-matter-
|
|
1
|
+
{"version":3,"file":"fuma-matter-B4gT09gM.js","names":[],"sources":["../src/collections/mdx/fuma-matter.ts"],"sourcesContent":["/**\n * Inspired by https://github.com/jonschlinkert/gray-matter\n */\nimport { load } from \"js-yaml\";\n\ninterface Output {\n /**\n * The matter section, including the delimiter.\n */\n matter: string;\n content: string;\n data: unknown;\n}\n\nconst regex = /^---\\r?\\n(.+?)\\r?\\n---\\r?\\n/s;\n\n/**\n * parse frontmatter, it supports only yaml format\n */\nexport function fumaMatter(input: string): Output {\n const output: Output = { matter: \"\", data: {}, content: input };\n const match = regex.exec(input);\n if (!match) {\n return output;\n }\n\n // get the raw front-matter block\n output.matter = match[0];\n output.content = input.slice(match[0].length);\n\n const loaded = load(match[1]);\n output.data = loaded ?? {};\n\n return output;\n}\n"],"mappings":";;;;;;AAcA,MAAM,QAAQ;;;;AAKd,SAAgB,WAAW,OAAuB;CAChD,MAAM,SAAiB;EAAE,QAAQ;EAAI,MAAM,EAAE;EAAE,SAAS;EAAO;CAC/D,MAAM,QAAQ,MAAM,KAAK,MAAM;AAC/B,KAAI,CAAC,MACH,QAAO;AAIT,QAAO,SAAS,MAAM;AACtB,QAAO,UAAU,MAAM,MAAM,MAAM,GAAG,OAAO;AAG7C,QAAO,OADQ,KAAK,MAAM,GAAG,IACL,EAAE;AAE1B,QAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as GetCollectionConfig, _ as pipe, a as EmitOptions, b as asyncHook, c as PluginContext, d as ResolvedCoreOptions, f as ServerContext, g as asyncPipe, h as Pipe, i as EmitEntry, l as PluginOption, m as AsyncPipe, n as CoreOptions, o as EmitOutput, r as EmitContext, s as Plugin, t as Core, u as ResolvedConfig, v as AsyncHook, x as hook, y as Hook } from "./core-
|
|
1
|
+
import { C as GetCollectionConfig, _ as pipe, a as EmitOptions, b as asyncHook, c as PluginContext, d as ResolvedCoreOptions, f as ServerContext, g as asyncPipe, h as Pipe, i as EmitEntry, l as PluginOption, m as AsyncPipe, n as CoreOptions, o as EmitOutput, r as EmitContext, s as Plugin, t as Core, u as ResolvedConfig, v as AsyncHook, x as hook, y as Hook } from "./core-FjA_Xoho.js";
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/validation.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as hook, n as pipe, r as asyncHook, t as asyncPipe } from "./pipe-CvCqOpXX.js";
|
|
2
|
-
import { t as Core } from "./core-
|
|
2
|
+
import { t as Core } from "./core-BuUsOElL.js";
|
|
3
3
|
import { n as getJSONSchema, r as validate, t as ValidationError } from "./validation-C3kXuveD.js";
|
|
4
4
|
|
|
5
5
|
export { Core, ValidationError, asyncHook, asyncPipe, getJSONSchema, hook, pipe, validate };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/utils/is-promise-like.ts
|
|
2
|
+
function isPromiseLike(v) {
|
|
3
|
+
return typeof v === "object" && v !== null && "then" in v && typeof v.then === "function";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isPromiseLike as t };
|
|
8
|
+
//# sourceMappingURL=is-promise-like-DYHv0Yap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-promise-like-DYHv0Yap.js","names":[],"sources":["../src/utils/is-promise-like.ts"],"sourcesContent":["export function isPromiseLike(v: unknown): v is PromiseLike<unknown> {\n return typeof v === \"object\" && v !== null && \"then\" in v && typeof v.then === \"function\";\n}\n"],"mappings":";AAAA,SAAgB,cAAc,GAAuC;AACnE,QAAO,OAAO,MAAM,YAAY,MAAM,QAAQ,UAAU,KAAK,OAAO,EAAE,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-from-file-
|
|
1
|
+
{"version":3,"file":"load-from-file-BhdBOcQT.js","names":[],"sources":["../src/config/load-from-file.ts"],"sourcesContent":["import { pathToFileURL } from \"node:url\";\nimport type { Core } from \"@/core\";\n\n/**\n * - `true`: compile the config before loading.\n * - `false`: import the config directly (without compiling it).\n * - `skip`: assume the config is already compiled.\n */\nexport type CompileMode = boolean | \"skip\";\n\nasync function compileConfig(core: Core) {\n const { build } = await import(\"esbuild\");\n const { configPath, outDir } = core.getOptions();\n\n const transformed = await build({\n entryPoints: [{ in: configPath, out: \"content.config\" }],\n bundle: true,\n outdir: outDir,\n target: \"node22\",\n write: true,\n platform: \"node\",\n format: \"esm\",\n packages: \"external\",\n outExtension: {\n \".js\": \".mjs\",\n },\n allowOverwrite: true,\n });\n\n if (transformed.errors.length > 0) {\n throw new Error(\"failed to compile configuration file\");\n }\n}\n\n/**\n * Load config\n */\nexport async function loadConfig(\n core: Core,\n compileMode: CompileMode,\n): Promise<Record<string, unknown>> {\n if (compileMode === true) await compileConfig(core);\n\n const url =\n compileMode === false\n ? pathToFileURL(core.getOptions().configPath)\n : pathToFileURL(core.getCompiledConfigPath());\n // always return a new config\n url.searchParams.set(\"hash\", Date.now().toString());\n\n return import(url.href);\n}\n"],"mappings":";;;;;AAUA,eAAe,cAAc,MAAY;CACvC,MAAM,EAAE,UAAU,MAAM,OAAO;CAC/B,MAAM,EAAE,YAAY,WAAW,KAAK,YAAY;AAiBhD,MAfoB,MAAM,MAAM;EAC9B,aAAa,CAAC;GAAE,IAAI;GAAY,KAAK;GAAkB,CAAC;EACxD,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,UAAU;EACV,QAAQ;EACR,UAAU;EACV,cAAc,EACZ,OAAO,QACR;EACD,gBAAgB;EACjB,CAAC,EAEc,OAAO,SAAS,EAC9B,OAAM,IAAI,MAAM,uCAAuC;;;;;AAO3D,eAAsB,WACpB,MACA,aACkC;AAClC,KAAI,gBAAgB,KAAM,OAAM,cAAc,KAAK;CAEnD,MAAM,MACJ,gBAAgB,QACZ,cAAc,KAAK,YAAY,CAAC,WAAW,GAC3C,cAAc,KAAK,uBAAuB,CAAC;AAEjD,KAAI,aAAa,IAAI,QAAQ,KAAK,KAAK,CAAC,UAAU,CAAC;AAEnD,QAAO,OAAO,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-from-file-CIYdu-B5.d.ts","names":[],"sources":["../src/config/load-from-file.ts"],"mappings":";AAQA;;;;;AAAA,KAAY,WAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-CjeV3_4I.js";
|
|
2
|
-
import { t as createDataLoader } from "./loader-
|
|
2
|
+
import { t as createDataLoader } from "./loader-UhlX4xbz.js";
|
|
3
3
|
|
|
4
4
|
//#region src/collections/json/loader.ts
|
|
5
5
|
var loader_exports = /* @__PURE__ */ __exportAll({ createJsonLoader: () => createJsonLoader });
|
|
@@ -15,4 +15,4 @@ function createJsonLoader(core, resolveJson = "js") {
|
|
|
15
15
|
|
|
16
16
|
//#endregion
|
|
17
17
|
export { loader_exports as n, createJsonLoader as t };
|
|
18
|
-
//# sourceMappingURL=loader-
|
|
18
|
+
//# sourceMappingURL=loader-BOYLUNfh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-
|
|
1
|
+
{"version":3,"file":"loader-BOYLUNfh.js","names":[],"sources":["../src/collections/json/loader.ts"],"sourcesContent":["import type { Loader } from \"@/plugins/loader\";\nimport type { DynamicCore } from \"@/dynamic\";\nimport { createDataLoader } from \"../data/loader\";\n\nexport function createJsonLoader(core: DynamicCore, resolveJson: \"json\" | \"js\" = \"js\"): Loader {\n return createDataLoader(\n core,\n (filePath, source) => {\n try {\n return JSON.parse(source);\n } catch (e) {\n throw new Error(`invalid data in ${filePath}`, { cause: e });\n }\n },\n resolveJson,\n );\n}\n"],"mappings":";;;;;AAIA,SAAgB,iBAAiB,MAAmB,cAA6B,MAAc;AAC7F,QAAO,iBACL,OACC,UAAU,WAAW;AACpB,MAAI;AACF,UAAO,KAAK,MAAM,OAAO;WAClB,GAAG;AACV,SAAM,IAAI,MAAM,mBAAmB,YAAY,EAAE,OAAO,GAAG,CAAC;;IAGhE,YACD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-CjeV3_4I.js";
|
|
2
2
|
import { MDXCollection } from "./collections/mdx.js";
|
|
3
|
-
import { t as fumaMatter } from "./fuma-matter-
|
|
3
|
+
import { t as fumaMatter } from "./fuma-matter-B4gT09gM.js";
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { z } from "zod";
|
|
@@ -19,7 +19,7 @@ const cacheEntry = z.object({
|
|
|
19
19
|
hash: z.string().optional()
|
|
20
20
|
});
|
|
21
21
|
function createMdxLoader({ getCore }) {
|
|
22
|
-
return { async load({ getSource, development: isDevelopment, query,
|
|
22
|
+
return { async load({ getSource, development: isDevelopment, query, addDependency, filePath }) {
|
|
23
23
|
let core = await getCore();
|
|
24
24
|
const value = await getSource();
|
|
25
25
|
const matter = fumaMatter(value);
|
|
@@ -52,13 +52,17 @@ function createMdxLoader({ getCore }) {
|
|
|
52
52
|
map: null
|
|
53
53
|
};
|
|
54
54
|
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
55
|
-
const { buildMDX } = await import("./build-mdx-
|
|
55
|
+
const { buildMDX } = await import("./build-mdx-DgzggXIL.js").then((n) => n.n);
|
|
56
56
|
const compiled = await buildMDX(core, collection, {
|
|
57
57
|
isDevelopment,
|
|
58
58
|
source: "\n".repeat(lineOffset) + matter.content,
|
|
59
59
|
filePath,
|
|
60
60
|
frontmatter: matter.data,
|
|
61
|
-
|
|
61
|
+
compiler: {
|
|
62
|
+
addDependency,
|
|
63
|
+
collection,
|
|
64
|
+
core
|
|
65
|
+
},
|
|
62
66
|
environment: "bundler"
|
|
63
67
|
});
|
|
64
68
|
const out = {
|
|
@@ -80,4 +84,4 @@ function countLines(s) {
|
|
|
80
84
|
|
|
81
85
|
//#endregion
|
|
82
86
|
export { loader_exports as n, createMdxLoader as t };
|
|
83
|
-
//# sourceMappingURL=loader-
|
|
87
|
+
//# sourceMappingURL=loader-BT4fwLTJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-BT4fwLTJ.js","names":[],"sources":["../src/collections/mdx/loader.ts"],"sourcesContent":["import { fumaMatter } from \"@/collections/mdx/fuma-matter\";\nimport type { SourceMap } from \"rollup\";\nimport { z } from \"zod\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createHash } from \"node:crypto\";\nimport type { Loader } from \"@/plugins/loader\";\nimport type { DynamicCore } from \"@/dynamic\";\nimport { MDXCollection } from \"../mdx\";\n\nconst querySchema = z\n .object({\n only: z.literal([\"frontmatter\", \"all\"]).default(\"all\"),\n collection: z.string().optional(),\n workspace: z.string().optional(),\n })\n .loose();\n\nconst cacheEntry = z.object({\n code: z.string(),\n map: z.any().optional(),\n hash: z.string().optional(),\n});\n\ntype CacheEntry = z.infer<typeof cacheEntry>;\n\nexport function createMdxLoader({ getCore }: DynamicCore): Loader {\n return {\n async load({ getSource, development: isDevelopment, query, addDependency, filePath }) {\n let core = await getCore();\n const value = await getSource();\n const matter = fumaMatter(value);\n const { collection: collectionName, workspace, only } = querySchema.parse(query);\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n let after: (() => Promise<void>) | undefined;\n\n const { experimentalBuildCache = false } = core.getConfig();\n if (!isDevelopment && experimentalBuildCache) {\n const cacheDir = experimentalBuildCache;\n const cacheKey = `${collectionName ?? \"global\"}_${generateCacheHash(filePath)}`;\n\n const cached = await fs\n .readFile(path.join(cacheDir, cacheKey))\n .then((content) => cacheEntry.parse(JSON.parse(content.toString())))\n .catch(() => null);\n\n if (cached && cached.hash === generateCacheHash(value)) return cached;\n after = async () => {\n await fs.mkdir(cacheDir, { recursive: true });\n await fs.writeFile(\n path.join(cacheDir, cacheKey),\n JSON.stringify({\n ...out,\n hash: generateCacheHash(value),\n } satisfies CacheEntry),\n );\n };\n }\n\n let collection = collectionName ? core.getCollection(collectionName) : undefined;\n if (!(collection instanceof MDXCollection)) collection = undefined;\n\n if (collection?.frontmatter) {\n matter.data = await collection.frontmatter.run(matter.data as Record<string, unknown>, {\n collection,\n filePath,\n source: value,\n });\n }\n\n if (only === \"frontmatter\") {\n return {\n code: `export const frontmatter = ${JSON.stringify(matter.data)}`,\n map: null,\n };\n }\n\n // ensure the line number is correct in dev mode\n const lineOffset = isDevelopment ? countLines(matter.matter) : 0;\n\n const { buildMDX } = await import(\"@/collections/mdx/build-mdx\");\n const compiled = await buildMDX(core, collection, {\n isDevelopment,\n source: \"\\n\".repeat(lineOffset) + matter.content,\n filePath,\n frontmatter: matter.data as Record<string, unknown>,\n compiler: {\n addDependency,\n collection,\n core,\n },\n environment: \"bundler\",\n });\n\n const out = {\n code: String(compiled.value),\n map: compiled.map as SourceMap,\n };\n\n await after?.();\n return out;\n },\n };\n}\n\nfunction generateCacheHash(input: string): string {\n return createHash(\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WAAW,MAAM,CAAC;AAC7C,UAAM,GAAG,UACP,KAAK,KAAK,UAAU,SAAS,EAC7B,KAAK,UAAU;KACb,GAAG;KACH,MAAM,kBAAkB,MAAM;KAC/B,CAAsB,CACxB;;;EAIL,IAAI,aAAa,iBAAiB,KAAK,cAAc,eAAe,GAAG;AACvE,MAAI,EAAE,sBAAsB,eAAgB,cAAa;AAEzD,MAAI,YAAY,YACd,QAAO,OAAO,MAAM,WAAW,YAAY,IAAI,OAAO,MAAiC;GACrF;GACA;GACA,QAAQ;GACT,CAAC;AAGJ,MAAI,SAAS,cACX,QAAO;GACL,MAAM,8BAA8B,KAAK,UAAU,OAAO,KAAK;GAC/D,KAAK;GACN;EAIH,MAAM,aAAa,gBAAgB,WAAW,OAAO,OAAO,GAAG;EAE/D,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,WAAW,MAAM,SAAS,MAAM,YAAY;GAChD;GACA,QAAQ,KAAK,OAAO,WAAW,GAAG,OAAO;GACzC;GACA,aAAa,OAAO;GACpB,UAAU;IACR;IACA;IACA;IACD;GACD,aAAa;GACd,CAAC;EAEF,MAAM,MAAM;GACV,MAAM,OAAO,SAAS,MAAM;GAC5B,KAAK,SAAS;GACf;AAED,QAAM,SAAS;AACf,SAAO;IAEV;;AAGH,SAAS,kBAAkB,OAAuB;AAChD,QAAO,WAAW,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGtD,SAAS,WAAW,GAAW;CAC7B,IAAI,MAAM;AAEV,MAAK,MAAM,KAAK,EACd,KAAI,MAAM,KAAM;AAGlB,QAAO"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-CjeV3_4I.js";
|
|
2
|
-
import { t as createDataLoader } from "./loader-
|
|
2
|
+
import { t as createDataLoader } from "./loader-UhlX4xbz.js";
|
|
3
3
|
import { load } from "js-yaml";
|
|
4
4
|
|
|
5
5
|
//#region src/collections/yaml/loader.ts
|
|
@@ -16,4 +16,4 @@ function createYamlLoader(core) {
|
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
export { loader_exports as n, createYamlLoader as t };
|
|
19
|
-
//# sourceMappingURL=loader-
|
|
19
|
+
//# sourceMappingURL=loader-Cb9kSSxT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-
|
|
1
|
+
{"version":3,"file":"loader-Cb9kSSxT.js","names":[],"sources":["../src/collections/yaml/loader.ts"],"sourcesContent":["import type { Loader } from \"@/plugins/loader\";\nimport { load } from \"js-yaml\";\nimport type { DynamicCore } from \"@/dynamic\";\nimport { createDataLoader } from \"../data/loader\";\n\nexport function createYamlLoader(core: DynamicCore): Loader {\n return createDataLoader(core, (filePath, source) => {\n try {\n return load(source) as Record<string, unknown>;\n } catch (e) {\n throw new Error(`invalid data in ${filePath}`, { cause: e });\n }\n });\n}\n"],"mappings":";;;;;;AAKA,SAAgB,iBAAiB,MAA2B;AAC1D,QAAO,iBAAiB,OAAO,UAAU,WAAW;AAClD,MAAI;AACF,UAAO,KAAK,OAAO;WACZ,GAAG;AACV,SAAM,IAAI,MAAM,mBAAmB,YAAY,EAAE,OAAO,GAAG,CAAC;;GAE9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-
|
|
1
|
+
{"version":3,"file":"loader-UhlX4xbz.js","names":[],"sources":["../src/collections/data/loader.ts"],"sourcesContent":["import type { Loader, LoaderInput } from \"@/plugins/loader\";\nimport { z } from \"zod\";\nimport { validate } from \"@/utils/validation\";\nimport { DataCollection, type DataTransformationContext } from \"@/collections/data\";\nimport type { DynamicCore } from \"@/dynamic\";\n\nconst querySchema = z\n .object({\n collection: z.string().optional(),\n workspace: z.string().optional(),\n })\n .loose();\n\n/**\n * load data files, fallback to bundler's built-in plugins when ?collection is unspecified.\n */\nexport function createDataLoader(\n { getCore }: DynamicCore,\n parse: (filePath: string, source: string) => Record<string, unknown>,\n moduleType: \"json\" | \"js\" = \"js\",\n): Loader {\n function getCollectionProcessor({ filePath, query }: LoaderInput) {\n const parsed = querySchema.safeParse(query);\n if (!parsed.success || !parsed.data.collection) return null;\n const { collection: collectionName, workspace } = parsed.data;\n\n return async (source: string): Promise<unknown> => {\n let core = await getCore();\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n let collection = core.getCollection(collectionName);\n let data: unknown = parse(filePath, source);\n if (!collection || !(collection instanceof DataCollection)) return data;\n\n const context: DataTransformationContext = {\n path: filePath,\n source,\n };\n\n if (collection.schema) {\n data = await validate(collection.schema, data, context, `invalid data in ${filePath}`);\n }\n\n return collection.onLoad.run(data, context);\n };\n }\n\n return {\n async load(input) {\n const processor = getCollectionProcessor(input);\n if (processor === null) return null;\n const data = await processor(await input.getSource());\n\n if (moduleType === \"json\") {\n return {\n code: JSON.stringify(data),\n moduleType,\n };\n } else {\n return {\n code: `export default ${JSON.stringify(data)}`,\n };\n }\n },\n bun: {\n load(source, input) {\n const processor = getCollectionProcessor(input);\n if (processor === null)\n return {\n loader: \"object\",\n exports: parse(input.filePath, source),\n };\n\n return processor(source).then((data) => ({\n loader: \"object\",\n exports: { default: data },\n }));\n },\n },\n };\n}\n"],"mappings":";;;;;AAMA,MAAM,cAAc,EACjB,OAAO;CACN,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC,CACD,OAAO;;;;AAKV,SAAgB,iBACd,EAAE,WACF,OACA,aAA4B,MACpB;CACR,SAAS,uBAAuB,EAAE,UAAU,SAAsB;EAChE,MAAM,SAAS,YAAY,UAAU,MAAM;AAC3C,MAAI,CAAC,OAAO,WAAW,CAAC,OAAO,KAAK,WAAY,QAAO;EACvD,MAAM,EAAE,YAAY,gBAAgB,cAAc,OAAO;AAEzD,SAAO,OAAO,WAAqC;GACjD,IAAI,OAAO,MAAM,SAAS;AAC1B,OAAI,UACF,QAAO,KAAK,eAAe,CAAC,IAAI,UAAU,IAAI;GAGhD,IAAI,aAAa,KAAK,cAAc,eAAe;GACnD,IAAI,OAAgB,MAAM,UAAU,OAAO;AAC3C,OAAI,CAAC,cAAc,EAAE,sBAAsB,gBAAiB,QAAO;GAEnE,MAAM,UAAqC;IACzC,MAAM;IACN;IACD;AAED,OAAI,WAAW,OACb,QAAO,MAAM,SAAS,WAAW,QAAQ,MAAM,SAAS,mBAAmB,WAAW;AAGxF,UAAO,WAAW,OAAO,IAAI,MAAM,QAAQ;;;AAI/C,QAAO;EACL,MAAM,KAAK,OAAO;GAChB,MAAM,YAAY,uBAAuB,MAAM;AAC/C,OAAI,cAAc,KAAM,QAAO;GAC/B,MAAM,OAAO,MAAM,UAAU,MAAM,MAAM,WAAW,CAAC;AAErD,OAAI,eAAe,OACjB,QAAO;IACL,MAAM,KAAK,UAAU,KAAK;IAC1B;IACD;OAED,QAAO,EACL,MAAM,kBAAkB,KAAK,UAAU,KAAK,IAC7C;;EAGL,KAAK,EACH,KAAK,QAAQ,OAAO;GAClB,MAAM,YAAY,uBAAuB,MAAM;AAC/C,OAAI,cAAc,KAChB,QAAO;IACL,QAAQ;IACR,SAAS,MAAM,MAAM,UAAU,OAAO;IACvC;AAEH,UAAO,UAAU,OAAO,CAAC,MAAM,UAAU;IACvC,QAAQ;IACR,SAAS,EAAE,SAAS,MAAM;IAC3B,EAAE;KAEN;EACF"}
|
package/dist/next/index.d.ts
CHANGED
package/dist/next/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as Core } from "../core-
|
|
1
|
+
import { t as Core } from "../core-BuUsOElL.js";
|
|
2
2
|
import { loaderPlugin } from "../plugins/loader/index.js";
|
|
3
|
-
import { t as loadConfig } from "../load-from-file-
|
|
3
|
+
import { t as loadConfig } from "../load-from-file-BhdBOcQT.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
6
6
|
//#region src/next/index.ts
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/loader.d.ts
CHANGED
package/dist/node/loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDynamicCore } from "../dynamic.js";
|
|
2
|
-
import { t as Core } from "../core-
|
|
2
|
+
import { t as Core } from "../core-BuUsOElL.js";
|
|
3
3
|
import { t as createCache } from "../async-cache-DRmFaVGm.js";
|
|
4
4
|
import { loaderPlugin } from "../plugins/loader/index.js";
|
|
5
5
|
|
|
@@ -16,7 +16,7 @@ function toNode(loaders) {
|
|
|
16
16
|
return (await fs.readFile(filePath)).toString();
|
|
17
17
|
},
|
|
18
18
|
development: false,
|
|
19
|
-
|
|
19
|
+
addDependency() {}
|
|
20
20
|
});
|
|
21
21
|
if (result) return {
|
|
22
22
|
source: result.code,
|
|
@@ -30,4 +30,4 @@ function toNode(loaders) {
|
|
|
30
30
|
|
|
31
31
|
//#endregion
|
|
32
32
|
export { toNode };
|
|
33
|
-
//# sourceMappingURL=node-
|
|
33
|
+
//# sourceMappingURL=node-Cu5Pqxxo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-Cu5Pqxxo.js","names":[],"sources":["../src/plugins/loader/node.ts"],"sourcesContent":["import type { LoadFnOutput, LoadHook } from \"node:module\";\nimport { fileURLToPath } from \"node:url\";\nimport fs from \"node:fs/promises\";\nimport type { Loader } from \"@/plugins/loader\";\n\nexport function toNode(loaders: { test: RegExp | undefined; loader: Loader }[]): LoadHook {\n return async (url, _context, nextLoad): Promise<LoadFnOutput> => {\n if (!url.startsWith(\"file:///\")) return nextLoad(url);\n\n const config = loaders.find((loader) => !loader.test || loader.test.test(url));\n if (config) {\n const parsedUrl = new URL(url);\n const filePath = fileURLToPath(parsedUrl);\n\n const result = await config.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 addDependency() {},\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"],"mappings":";;;;AAKA,SAAgB,OAAO,SAAmE;AACxF,QAAO,OAAO,KAAK,UAAU,aAAoC;AAC/D,MAAI,CAAC,IAAI,WAAW,WAAW,CAAE,QAAO,SAAS,IAAI;EAErD,MAAM,SAAS,QAAQ,MAAM,WAAW,CAAC,OAAO,QAAQ,OAAO,KAAK,KAAK,IAAI,CAAC;AAC9E,MAAI,QAAQ;GACV,MAAM,YAAY,IAAI,IAAI,IAAI;GAC9B,MAAM,WAAW,cAAc,UAAU;GAEzC,MAAM,SAAS,MAAM,OAAO,OAAO,KAAK;IACtC;IACA,OAAO,OAAO,YAAY,UAAU,aAAa,SAAS,CAAC;IAC3D,MAAM,YAAY;AAChB,aAAQ,MAAM,GAAG,SAAS,SAAS,EAAE,UAAU;;IAEjD,aAAa;IACb,gBAAgB;IACjB,CAAC;AAEF,OAAI,OACF,QAAO;IACL,QAAQ,OAAO;IACf,QAAQ;IACR,cAAc;IACf;;AAIL,SAAO,SAAS,IAAI"}
|
package/dist/plugins/git.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { c as PluginContext, s as Plugin } from "../../core-
|
|
1
|
+
import { c as PluginContext, s as Plugin } from "../../core-FjA_Xoho.js";
|
|
2
2
|
import { CollectionHook } from "../../collections/index.js";
|
|
3
|
-
import "../../load-from-file-
|
|
3
|
+
import "../../load-from-file-CIYdu-B5.js";
|
|
4
4
|
import { WebpackLoaderOptions } from "./webpack.js";
|
|
5
5
|
import { NextConfig } from "next";
|
|
6
6
|
|
|
7
7
|
//#region src/plugins/loader/index.d.ts
|
|
8
8
|
type Awaitable<T> = T | Promise<T>;
|
|
9
|
-
interface CompilerOptions {
|
|
10
|
-
addDependency: (file: string) => void;
|
|
11
|
-
}
|
|
12
9
|
type LoaderEnvironment = "vite" | "bun" | "node";
|
|
13
10
|
interface Loader {
|
|
14
11
|
/**
|
|
@@ -29,10 +26,10 @@ interface Loader {
|
|
|
29
26
|
}
|
|
30
27
|
interface LoaderInput {
|
|
31
28
|
development: boolean;
|
|
32
|
-
compiler: CompilerOptions;
|
|
33
29
|
filePath: string;
|
|
34
30
|
query: Record<string, string | string[] | undefined>;
|
|
35
31
|
getSource: () => string | Promise<string>;
|
|
32
|
+
addDependency: (file: string) => void;
|
|
36
33
|
}
|
|
37
34
|
interface LoaderOutput {
|
|
38
35
|
code: string;
|
|
@@ -71,5 +68,5 @@ interface LoaderHook {
|
|
|
71
68
|
}
|
|
72
69
|
declare const loaderHook: CollectionHook<LoaderHook, undefined>;
|
|
73
70
|
//#endregion
|
|
74
|
-
export {
|
|
71
|
+
export { Loader, LoaderConfig, LoaderHook, LoaderInput, LoaderOutput, loaderHook, loaderPlugin };
|
|
75
72
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugins/loader/index.ts"],"mappings":";;;;;;;KAOK,SAAA,MAAe,CAAA,GAAI,OAAA,CAAQ,CAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugins/loader/index.ts"],"mappings":";;;;;;;KAOK,SAAA,MAAe,CAAA,GAAI,OAAA,CAAQ,CAAA;AAAA,KAE3B,iBAAA;AAAA,UAEY,MAAA;;AAPmC;;;;;;EAelD,IAAA,GAAO,KAAA,EAAO,WAAA,KAAgB,SAAA,CAAU,YAAA;EAExC,GAAA;IAda;;;;IAmBX,IAAA,IAAQ,MAAA,UAAgB,KAAA,EAAO,WAAA,KAAgB,SAAA,CAAU,GAAA,CAAI,YAAA;EAAA;AAAA;AAAA,UAIhD,WAAA;EACf,WAAA;EAEA,QAAA;EACA,KAAA,EAAO,MAAA;EACP,SAAA,iBAA0B,OAAA;EAC1B,aAAA,GAAgB,IAAA;AAAA;AAAA,UAGD,YAAA;EACf,IAAA;EACA,GAAA;EAfiC;;;;;EAsBjC,UAAA;AAAA;AAAA,UAGQ,iBAAA,SAA0B,aAAA;EAClC,gBAAA,QAAwB,oBAAA;AAAA;AAAA,UAGT,YAAA;EA7Bb;EA+BF,EAAA;EA/BiC;;;;;EAsCjC,IAAA,GAAO,MAAA;EAtCoE;AAI7E;;EAuCE,YAAA,GAAe,IAAA,EAAM,aAAA,EAAe,WAAA,EAAa,iBAAA,KAAsB,OAAA,CAAQ,MAAA;EAC/E,aAAA,IAAiB,IAAA,EAAM,iBAAA,EAAmB,IAAA,EAAM,UAAA,KAAe,UAAA;AAAA;;;;iBAYjD,YAAA,CAAA,GAAgB,MAAA;AAAA,UAsFf,UAAA;EACf,OAAA,EAAS,YAAA;AAAA;AAAA,cAGE,UAAA,EAAU,cAAA,CAAA,UAAA"}
|
|
@@ -9,10 +9,11 @@ import path from "node:path";
|
|
|
9
9
|
function loaderPlugin() {
|
|
10
10
|
const cachedLoaders = createCache();
|
|
11
11
|
function initLoaders(ctx, env) {
|
|
12
|
+
const { core } = ctx;
|
|
12
13
|
return cachedLoaders.cached(env, async () => {
|
|
13
14
|
const usedIds = /* @__PURE__ */ new Set();
|
|
14
15
|
const out = [];
|
|
15
|
-
for (const collection of
|
|
16
|
+
for (const collection of core.getCollections()) {
|
|
16
17
|
const hook = collection.getPluginHook(loaderHook);
|
|
17
18
|
if (!hook) continue;
|
|
18
19
|
let nextId = 0;
|
|
@@ -55,15 +56,15 @@ function loaderPlugin() {
|
|
|
55
56
|
return config;
|
|
56
57
|
} },
|
|
57
58
|
bun: { async setup(build) {
|
|
58
|
-
const { toBun } = await import("../../bun-
|
|
59
|
+
const { toBun } = await import("../../bun-Be5pgXW_.js");
|
|
59
60
|
for (const loader of await initLoaders(this, "bun")) toBun(loader.test, loader.loader)(build);
|
|
60
61
|
} },
|
|
61
62
|
node: { async createLoad() {
|
|
62
|
-
const { toNode } = await import("../../node-
|
|
63
|
+
const { toNode } = await import("../../node-Cu5Pqxxo.js");
|
|
63
64
|
return toNode(await initLoaders(this, "node"));
|
|
64
65
|
} },
|
|
65
66
|
vite: { async createPlugin() {
|
|
66
|
-
const { toVite } = await import("../../vite-
|
|
67
|
+
const { toVite } = await import("../../vite-CoJIMNWk.js");
|
|
67
68
|
return (await initLoaders(this, "vite")).map((loader) => {
|
|
68
69
|
return toVite(`fuma-content:${loader.id}`, loader.test, loader.loader);
|
|
69
70
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/plugins/loader/index.ts"],"sourcesContent":["import { defineCollectionHook } from \"@/collections\";\nimport type { Plugin, PluginContext } from \"@/core\";\nimport { createCache } from \"@/utils/async-cache\";\nimport { NextConfig } from \"next\";\nimport { WebpackLoaderOptions } from \"./webpack.js\";\nimport path from \"node:path\";\n\ntype Awaitable<T> = T | Promise<T>;\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/plugins/loader/index.ts"],"sourcesContent":["import { defineCollectionHook } from \"@/collections\";\nimport type { Plugin, PluginContext } from \"@/core\";\nimport { createCache } from \"@/utils/async-cache\";\nimport { NextConfig } from \"next\";\nimport { WebpackLoaderOptions } from \"./webpack.js\";\nimport path from \"node:path\";\n\ntype Awaitable<T> = T | Promise<T>;\n\ntype LoaderEnvironment = \"vite\" | \"bun\" | \"node\";\n\nexport interface Loader {\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 interface LoaderInput {\n development: boolean;\n\n filePath: string;\n query: Record<string, string | string[] | undefined>;\n getSource: () => string | Promise<string>;\n addDependency: (file: string) => void;\n}\n\nexport interface LoaderOutput {\n code: string;\n map?: unknown;\n\n /**\n * only supported on Vite 8 at the moment, specify the output module type.\n *\n * on unsupported environments, it will be ignored.\n */\n moduleType?: \"js\" | \"json\";\n}\n\ninterface NextLoaderContext extends PluginContext {\n getLoaderOptions: () => WebpackLoaderOptions;\n}\n\nexport interface LoaderConfig {\n /** unique ID for loader, used to deduplicate loaders */\n id?: string;\n\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 * @remarks it doesn't configure automatically for Next.js, you have to define the webpack/turbopack config in `configureNext()`.\n */\n createLoader: (this: PluginContext, environment: LoaderEnvironment) => Promise<Loader>;\n configureNext?: (this: NextLoaderContext, next: NextConfig) => NextConfig;\n}\n\ninterface ResolvedLoader {\n id: string;\n test: RegExp | undefined;\n loader: Loader;\n}\n\n/**\n * a light layer for implementing loaders.\n */\nexport function loaderPlugin(): Plugin {\n // env -> loaders\n const cachedLoaders = createCache<ResolvedLoader[]>();\n\n function initLoaders(ctx: PluginContext, env: LoaderEnvironment) {\n const { core } = ctx;\n return cachedLoaders.cached(env, async () => {\n const usedIds = new Set<string>();\n const out: ResolvedLoader[] = [];\n\n for (const collection of core.getCollections()) {\n const hook = collection.getPluginHook(loaderHook);\n if (!hook) continue;\n\n let nextId = 0;\n for (const loader of hook.loaders) {\n if (loader.id && usedIds.has(loader.id)) continue;\n if (loader.id) usedIds.add(loader.id);\n\n out.push({\n id: loader.id ?? `${collection.name}:${nextId++}`,\n test: loader.test,\n loader: await loader.createLoader.call(ctx, env),\n });\n }\n }\n return out;\n });\n }\n\n return {\n name: \"fuma-content:loader\",\n next: {\n config(config) {\n const ctx: NextLoaderContext = {\n ...this,\n getLoaderOptions: () => {\n const { configPath, outDir } = this.core.getOptions();\n return {\n configPath,\n outDir,\n absoluteCompiledConfigPath: path.resolve(this.core.getCompiledConfigPath()),\n isDev: process.env.NODE_ENV === \"development\",\n };\n },\n };\n for (const collection of this.core.getCollections()) {\n const hook = collection.getPluginHook(loaderHook);\n if (!hook) continue;\n\n for (const loader of hook.loaders) {\n if (!loader.configureNext) continue;\n\n config = loader.configureNext.call(ctx, config);\n }\n }\n\n return config;\n },\n },\n bun: {\n async setup(build) {\n const { toBun } = await import(\"./bun\");\n\n for (const loader of await initLoaders(this, \"bun\")) {\n toBun(loader.test, loader.loader)(build);\n }\n },\n },\n node: {\n async createLoad() {\n const { toNode } = await import(\"./node\");\n return toNode(await initLoaders(this, \"node\"));\n },\n },\n vite: {\n async createPlugin() {\n const { toVite } = await import(\"./vite\");\n return (await initLoaders(this, \"vite\")).map((loader) => {\n return toVite(`fuma-content:${loader.id}`, loader.test, loader.loader);\n });\n },\n },\n };\n}\n\nexport interface LoaderHook {\n loaders: LoaderConfig[];\n}\n\nexport const loaderHook = defineCollectionHook<LoaderHook>(() => ({\n loaders: [],\n}));\n"],"mappings":";;;;;;;;AAkFA,SAAgB,eAAuB;CAErC,MAAM,gBAAgB,aAA+B;CAErD,SAAS,YAAY,KAAoB,KAAwB;EAC/D,MAAM,EAAE,SAAS;AACjB,SAAO,cAAc,OAAO,KAAK,YAAY;GAC3C,MAAM,0BAAU,IAAI,KAAa;GACjC,MAAM,MAAwB,EAAE;AAEhC,QAAK,MAAM,cAAc,KAAK,gBAAgB,EAAE;IAC9C,MAAM,OAAO,WAAW,cAAc,WAAW;AACjD,QAAI,CAAC,KAAM;IAEX,IAAI,SAAS;AACb,SAAK,MAAM,UAAU,KAAK,SAAS;AACjC,SAAI,OAAO,MAAM,QAAQ,IAAI,OAAO,GAAG,CAAE;AACzC,SAAI,OAAO,GAAI,SAAQ,IAAI,OAAO,GAAG;AAErC,SAAI,KAAK;MACP,IAAI,OAAO,MAAM,GAAG,WAAW,KAAK,GAAG;MACvC,MAAM,OAAO;MACb,QAAQ,MAAM,OAAO,aAAa,KAAK,KAAK,IAAI;MACjD,CAAC;;;AAGN,UAAO;IACP;;AAGJ,QAAO;EACL,MAAM;EACN,MAAM,EACJ,OAAO,QAAQ;GACb,MAAM,MAAyB;IAC7B,GAAG;IACH,wBAAwB;KACtB,MAAM,EAAE,YAAY,WAAW,KAAK,KAAK,YAAY;AACrD,YAAO;MACL;MACA;MACA,4BAA4B,KAAK,QAAQ,KAAK,KAAK,uBAAuB,CAAC;MAC3E,OAAO,QAAQ,IAAI,aAAa;MACjC;;IAEJ;AACD,QAAK,MAAM,cAAc,KAAK,KAAK,gBAAgB,EAAE;IACnD,MAAM,OAAO,WAAW,cAAc,WAAW;AACjD,QAAI,CAAC,KAAM;AAEX,SAAK,MAAM,UAAU,KAAK,SAAS;AACjC,SAAI,CAAC,OAAO,cAAe;AAE3B,cAAS,OAAO,cAAc,KAAK,KAAK,OAAO;;;AAInD,UAAO;KAEV;EACD,KAAK,EACH,MAAM,MAAM,OAAO;GACjB,MAAM,EAAE,UAAU,MAAM,OAAO;AAE/B,QAAK,MAAM,UAAU,MAAM,YAAY,MAAM,MAAM,CACjD,OAAM,OAAO,MAAM,OAAO,OAAO,CAAC,MAAM;KAG7C;EACD,MAAM,EACJ,MAAM,aAAa;GACjB,MAAM,EAAE,WAAW,MAAM,OAAO;AAChC,UAAO,OAAO,MAAM,YAAY,MAAM,OAAO,CAAC;KAEjD;EACD,MAAM,EACJ,MAAM,eAAe;GACnB,MAAM,EAAE,WAAW,MAAM,OAAO;AAChC,WAAQ,MAAM,YAAY,MAAM,OAAO,EAAE,KAAK,WAAW;AACvD,WAAO,OAAO,gBAAgB,OAAO,MAAM,OAAO,MAAM,OAAO,OAAO;KACtE;KAEL;EACF;;AAOH,MAAa,aAAa,4BAAwC,EAChE,SAAS,EAAE,EACZ,EAAE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../../core-
|
|
2
|
-
import "../../load-from-file-
|
|
1
|
+
import "../../core-FjA_Xoho.js";
|
|
2
|
+
import "../../load-from-file-CIYdu-B5.js";
|
|
3
3
|
import { DynamicCore } from "../../dynamic.js";
|
|
4
4
|
import { Loader } from "./index.js";
|
|
5
5
|
import { LoaderContext } from "webpack";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDynamicCore } from "../../dynamic.js";
|
|
2
|
-
import { t as Core } from "../../core-
|
|
2
|
+
import { t as Core } from "../../core-BuUsOElL.js";
|
|
3
3
|
import { t as ValidationError } from "../../validation-C3kXuveD.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { parse } from "node:querystring";
|
|
@@ -39,7 +39,9 @@ function createWebpackLoader(loaderFactory) {
|
|
|
39
39
|
return source;
|
|
40
40
|
},
|
|
41
41
|
development: this.mode === "development",
|
|
42
|
-
|
|
42
|
+
addDependency: (file) => {
|
|
43
|
+
this.addDependency(file);
|
|
44
|
+
}
|
|
43
45
|
});
|
|
44
46
|
if (result === null) callback(void 0, source);
|
|
45
47
|
else callback(void 0, result.code, result.map);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.js","names":[],"sources":["../../../src/plugins/loader/webpack.ts"],"sourcesContent":["import { parse } from \"node:querystring\";\nimport { ValidationError } from \"@/utils/validation\";\nimport path from \"node:path\";\nimport { Core } from \"@/core\";\nimport { createDynamicCore, type DynamicCore } from \"@/dynamic\";\nimport type { LoaderContext } from \"webpack\";\nimport type { Loader } from \"@/plugins/loader\";\n\nexport interface WebpackLoaderOptions {\n absoluteCompiledConfigPath: string;\n configPath: string;\n outDir: string;\n isDev: boolean;\n}\n\nexport type WebpackLoader = (this: LoaderContext<WebpackLoaderOptions>, source: string) => void;\n\nconst cachedCores = new Map<string, DynamicCore>();\n\nfunction initDynamicCore({ configPath, isDev, outDir }: WebpackLoaderOptions) {\n const key = `${configPath}:${isDev}:${outDir}`;\n let res = cachedCores.get(key);\n if (res) return res;\n\n res = createDynamicCore({\n core: new Core({ configPath, outDir }),\n compileMode: \"skip\",\n mode: isDev ? \"dev\" : \"production\",\n });\n cachedCores.set(key, res);\n return res;\n}\n\n/**\n * Note: need to handle the `test` regex in Webpack config instead.\n */\nexport function createWebpackLoader(loaderFactory: (core: DynamicCore) => Loader): WebpackLoader {\n let loader: Loader | undefined;\n\n async function asyncLoader(\n this: LoaderContext<WebpackLoaderOptions>,\n source: string,\n callback: LoaderContext<WebpackLoaderOptions>[\"callback\"],\n ) {\n const options = this.getOptions();\n this.cacheable(true);\n this.addDependency(options.absoluteCompiledConfigPath);\n\n if (!loader) {\n const core = initDynamicCore(options);\n loader = loaderFactory(core);\n }\n\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
|
|
1
|
+
{"version":3,"file":"webpack.js","names":[],"sources":["../../../src/plugins/loader/webpack.ts"],"sourcesContent":["import { parse } from \"node:querystring\";\nimport { ValidationError } from \"@/utils/validation\";\nimport path from \"node:path\";\nimport { Core } from \"@/core\";\nimport { createDynamicCore, type DynamicCore } from \"@/dynamic\";\nimport type { LoaderContext } from \"webpack\";\nimport type { Loader } from \"@/plugins/loader\";\n\nexport interface WebpackLoaderOptions {\n absoluteCompiledConfigPath: string;\n configPath: string;\n outDir: string;\n isDev: boolean;\n}\n\nexport type WebpackLoader = (this: LoaderContext<WebpackLoaderOptions>, source: string) => void;\n\nconst cachedCores = new Map<string, DynamicCore>();\n\nfunction initDynamicCore({ configPath, isDev, outDir }: WebpackLoaderOptions) {\n const key = `${configPath}:${isDev}:${outDir}`;\n let res = cachedCores.get(key);\n if (res) return res;\n\n res = createDynamicCore({\n core: new Core({ configPath, outDir }),\n compileMode: \"skip\",\n mode: isDev ? \"dev\" : \"production\",\n });\n cachedCores.set(key, res);\n return res;\n}\n\n/**\n * Note: need to handle the `test` regex in Webpack config instead.\n */\nexport function createWebpackLoader(loaderFactory: (core: DynamicCore) => Loader): WebpackLoader {\n let loader: Loader | undefined;\n\n async function asyncLoader(\n this: LoaderContext<WebpackLoaderOptions>,\n source: string,\n callback: LoaderContext<WebpackLoaderOptions>[\"callback\"],\n ) {\n const options = this.getOptions();\n this.cacheable(true);\n this.addDependency(options.absoluteCompiledConfigPath);\n\n if (!loader) {\n const core = initDynamicCore(options);\n loader = loaderFactory(core);\n }\n\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 addDependency: (file) => {\n this.addDependency(file);\n },\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\n const fpath = path.relative(this.context, this.resourcePath);\n error.message = `${fpath}:${error.name}: ${error.message}`;\n callback(error);\n }\n }\n\n return function loader(source) {\n return asyncLoader.call(this, source, this.async());\n };\n}\n"],"mappings":";;;;;;;AAiBA,MAAM,8BAAc,IAAI,KAA0B;AAElD,SAAS,gBAAgB,EAAE,YAAY,OAAO,UAAgC;CAC5E,MAAM,MAAM,GAAG,WAAW,GAAG,MAAM,GAAG;CACtC,IAAI,MAAM,YAAY,IAAI,IAAI;AAC9B,KAAI,IAAK,QAAO;AAEhB,OAAM,kBAAkB;EACtB,MAAM,IAAI,KAAK;GAAE;GAAY;GAAQ,CAAC;EACtC,aAAa;EACb,MAAM,QAAQ,QAAQ;EACvB,CAAC;AACF,aAAY,IAAI,KAAK,IAAI;AACzB,QAAO;;;;;AAMT,SAAgB,oBAAoB,eAA6D;CAC/F,IAAI;CAEJ,eAAe,YAEb,QACA,UACA;EACA,MAAM,UAAU,KAAK,YAAY;AACjC,OAAK,UAAU,KAAK;AACpB,OAAK,cAAc,QAAQ,2BAA2B;AAEtD,MAAI,CAAC,OAEH,UAAS,cADI,gBAAgB,QAAQ,CACT;AAG9B,MAAI;GACF,MAAM,SAAS,MAAM,OAAO,KAAK;IAC/B,UAAU,KAAK;IACf,OAAO,MAAM,KAAK,cAAc,MAAM,EAAE,CAAC;IACzC,YAAY;AACV,YAAO;;IAET,aAAa,KAAK,SAAS;IAC3B,gBAAgB,SAAS;AACvB,UAAK,cAAc,KAAK;;IAE3B,CAAC;AAEF,OAAI,WAAW,KACb,UAAS,QAAW,OAAO;OAE3B,UAAS,QAAW,OAAO,MAAM,OAAO,IAAc;WAEjD,OAAO;AACd,OAAI,iBAAiB,gBACnB,QAAO,SAAS,IAAI,MAAM,MAAM,MAAM,mBAAmB,CAAC,CAAC;AAG7D,OAAI,EAAE,iBAAiB,OAAQ,OAAM;AAGrC,SAAM,UAAU,GADF,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACnC,GAAG,MAAM,KAAK,IAAI,MAAM;AACjD,YAAS,MAAM;;;AAInB,QAAO,SAAS,OAAO,QAAQ;AAC7B,SAAO,YAAY,KAAK,MAAM,QAAQ,KAAK,OAAO,CAAC"}
|
package/dist/vite/index.d.ts
CHANGED
package/dist/vite/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/vite/index.ts"],"mappings":";;;;UAKiB,aAAA,SAAsB,IAAA,CAAK,WAAA;;AAA5C;;;;EAME,KAAA;AAAA;AAAA,iBAG4B,OAAA,CAC5B,MAAA,EAAQ,MAAA,mBACR,aAAA,GAAe,aAAA,GACd,OAAA,CAAQ,YAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/vite/index.ts"],"mappings":";;;;UAKiB,aAAA,SAAsB,IAAA,CAAK,WAAA;;AAA5C;;;;EAME,KAAA;AAAA;AAAA,iBAG4B,OAAA,CAC5B,MAAA,EAAQ,MAAA,mBACR,aAAA,GAAe,aAAA,GACd,OAAA,CAAQ,YAAA;AAAA,iBAkCW,oBAAA,CAAqB,aAAA,GAAe,aAAA,GAAkB,OAAA,CAAA,IAAA"}
|