@timber-js/app 0.2.0-alpha.191 → 0.2.0-alpha.192
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/config-types.d.ts +24 -6
- package/dist/config-types.d.ts.map +1 -1
- package/dist/index.js +31 -28
- package/dist/index.js.map +1 -1
- package/dist/plugins/mdx.d.ts +17 -4
- package/dist/plugins/mdx.d.ts.map +1 -1
- package/dist/plugins/server-bundle.d.ts.map +1 -1
- package/docs/api/34-api-config.mdx +9 -8
- package/docs/more/04b-mdx.mdx +38 -18
- package/package.json +7 -3
- package/src/config-types.ts +27 -7
- package/src/plugins/mdx.ts +69 -35
- package/src/plugins/server-bundle.ts +2 -1
package/dist/config-types.d.ts
CHANGED
|
@@ -157,12 +157,30 @@ export interface TimberUserConfig {
|
|
|
157
157
|
* to use a custom location.
|
|
158
158
|
*/
|
|
159
159
|
appDir?: string;
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
/**
|
|
161
|
+
* MDX/Markdown compilation options passed to vite-plugin-satteri.
|
|
162
|
+
*
|
|
163
|
+
* Satteri's plugin API is visitor-based (`defineMdastPlugin` /
|
|
164
|
+
* `defineHastPlugin` from the `satteri` package) — unified
|
|
165
|
+
* remark/rehype plugins are not supported.
|
|
166
|
+
*
|
|
167
|
+
* Set to `false` to disable timber's MDX support entirely — even when a
|
|
168
|
+
* `content/` directory exists. Use this when registering your own MDX
|
|
169
|
+
* compiler (e.g. `@mdx-js/rollup` for the unified pipeline) directly in
|
|
170
|
+
* `vite.config.ts`.
|
|
171
|
+
*
|
|
172
|
+
* See design/20-content-collections.md.
|
|
173
|
+
*/
|
|
174
|
+
mdx?: false | {
|
|
175
|
+
/** MDAST-stage plugins (created with satteri's `defineMdastPlugin`). */
|
|
176
|
+
mdastPlugins?: unknown[];
|
|
177
|
+
/** HAST-stage plugins (created with satteri's `defineHastPlugin`). */
|
|
178
|
+
hastPlugins?: unknown[];
|
|
179
|
+
/**
|
|
180
|
+
* Parser feature toggles. Defaults: `gfm: true`, `frontmatter: true`,
|
|
181
|
+
* everything else (math, directive, wikilinks, …) off.
|
|
182
|
+
*/
|
|
183
|
+
features?: Record<string, unknown>;
|
|
166
184
|
};
|
|
167
185
|
/**
|
|
168
186
|
* Server action bound args encryption configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-types.d.ts","sourceRoot":"","sources":["../src/config-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uDAAuD;AACvD,MAAM,WAAW,sBAAsB;IACrC,yEAAyE;IACzE,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC7B;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAC;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE;QACP,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,KAAK,CAAC,EAAE;QACN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA6BG;QACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAAC;KACpD,CAAC;IACF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;;;;;OAWG;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OAaG;IACH,OAAO,CAAC,EAAE;QACR,2EAA2E;QAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,oGAAoG;QACpG,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,wDAAwD;QACxD,sBAAsB,CAAC,EAAE,MAAM,CAAC;QAChC,gEAAgE;QAChE,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,+DAA+D;QAC/D,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,CAAC;IACF;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,CAAC,EAAE;QACV,wDAAwD;QACxD,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,qCAAqC;QACrC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,wCAAwC;QACxC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,qDAAqD;QACrD,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,kFAAkF;QAClF,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,kCAAkC;QAClC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH"}
|
package/dist/index.js
CHANGED
|
@@ -2094,6 +2094,7 @@ function findMdxComponents(root) {
|
|
|
2094
2094
|
* Determine if MDX should be activated based on config and project structure.
|
|
2095
2095
|
*/
|
|
2096
2096
|
function shouldActivate(ctx) {
|
|
2097
|
+
if (ctx.config.mdx === false) return false;
|
|
2097
2098
|
const exts = ctx.config.pageExtensions;
|
|
2098
2099
|
if (exts && exts.some((ext) => MDX_EXTENSIONS.includes(ext))) return true;
|
|
2099
2100
|
if (existsSync(join(ctx.root, "content"))) return true;
|
|
@@ -2105,13 +2106,11 @@ function shouldActivate(ctx) {
|
|
|
2105
2106
|
*
|
|
2106
2107
|
* Why this matters: pnpm only hoists declared (peer) dependencies into a
|
|
2107
2108
|
* package's resolution scope. The MDX integration's optional companions
|
|
2108
|
-
* — `
|
|
2109
|
-
*
|
|
2110
|
-
*
|
|
2111
|
-
*
|
|
2112
|
-
*
|
|
2113
|
-
* `undefined` and skipped frontmatter parsing entirely — leaving MDX to
|
|
2114
|
-
* choke on YAML as JS expressions (TIM-840).
|
|
2109
|
+
* — `vite-plugin-satteri` and `satteri` — are installed as direct deps of
|
|
2110
|
+
* the consumer (e.g. `packages/website`), not `@timber-js/app`. A bare
|
|
2111
|
+
* `import('vite-plugin-satteri')` from inside this file resolves against
|
|
2112
|
+
* `packages/timber-app/node_modules` and silently fails with
|
|
2113
|
+
* `ERR_MODULE_NOT_FOUND` (TIM-840).
|
|
2115
2114
|
*
|
|
2116
2115
|
* Resolving relative to `projectRoot` (via `createRequire`) makes the
|
|
2117
2116
|
* lookup walk the consumer's `node_modules` tree first, which is where
|
|
@@ -2138,39 +2137,41 @@ async function tryImport(name, projectRoot) {
|
|
|
2138
2137
|
* Create the timber-mdx Vite plugin.
|
|
2139
2138
|
*
|
|
2140
2139
|
* Uses the transform and resolveId hooks to delegate MDX compilation
|
|
2141
|
-
* to
|
|
2140
|
+
* to vite-plugin-satteri. The inner plugin is loaded lazily on first
|
|
2141
|
+
* activation.
|
|
2142
2142
|
*
|
|
2143
|
-
* Hooks: buildStart (loads
|
|
2143
|
+
* Hooks: buildStart (loads vite-plugin-satteri), resolveId, load, transform
|
|
2144
2144
|
*/
|
|
2145
2145
|
function timberMdx(ctx) {
|
|
2146
2146
|
let innerPlugin = null;
|
|
2147
2147
|
async function activate() {
|
|
2148
2148
|
if (innerPlugin !== null || !shouldActivate(ctx)) return;
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
"
|
|
2149
|
+
if (ctx.config.pageExtensions?.includes("md")) throw new Error([
|
|
2150
|
+
"[timber] pageExtensions includes 'md', but .md route pages are not supported:",
|
|
2151
|
+
"Markdown files compile to HTML strings, not components.",
|
|
2152
|
+
"",
|
|
2153
|
+
"Use .mdx for pages (pageExtensions: ['tsx', 'ts', 'mdx']).",
|
|
2154
|
+
".md files can still be imported as HTML strings — no pageExtensions entry needed."
|
|
2155
|
+
].join("\n"));
|
|
2156
|
+
const createSatteriPlugin = await tryImport("vite-plugin-satteri", ctx.root);
|
|
2157
|
+
if (!createSatteriPlugin) throw new Error([
|
|
2158
|
+
"[timber] MDX is enabled but vite-plugin-satteri is not installed.",
|
|
2152
2159
|
"",
|
|
2153
2160
|
"Install it:",
|
|
2154
|
-
" pnpm add -D
|
|
2161
|
+
" pnpm add -D vite-plugin-satteri satteri",
|
|
2155
2162
|
"",
|
|
2156
2163
|
"MDX is activated because pageExtensions includes \"mdx\"/\"md\" or a content/ directory exists."
|
|
2157
2164
|
].join("\n"));
|
|
2158
|
-
const mdxConfig = ctx.config.mdx
|
|
2159
|
-
const
|
|
2160
|
-
const remarkFrontmatter = await tryImport("remark-frontmatter", ctx.root);
|
|
2161
|
-
const remarkMdxFrontmatter = await tryImport("remark-mdx-frontmatter", ctx.root);
|
|
2162
|
-
if (remarkFrontmatter) remarkPlugins.push(remarkFrontmatter);
|
|
2163
|
-
if (remarkMdxFrontmatter) remarkPlugins.push(remarkMdxFrontmatter);
|
|
2164
|
-
if (mdxConfig.remarkPlugins) remarkPlugins.push(...mdxConfig.remarkPlugins);
|
|
2165
|
-
const mdxOptions = {
|
|
2166
|
-
remarkPlugins,
|
|
2167
|
-
rehypePlugins: mdxConfig.rehypePlugins ?? [],
|
|
2168
|
-
recmaPlugins: mdxConfig.recmaPlugins ?? [],
|
|
2169
|
-
remarkRehypeOptions: mdxConfig.remarkRehypeOptions
|
|
2170
|
-
};
|
|
2165
|
+
const mdxConfig = ctx.config.mdx || {};
|
|
2166
|
+
const mdxOptions = { development: ctx.dev };
|
|
2171
2167
|
const mdxComponentsPath = findMdxComponents(ctx.root);
|
|
2172
2168
|
if (mdxComponentsPath) mdxOptions.providerImportSource = mdxComponentsPath;
|
|
2173
|
-
innerPlugin =
|
|
2169
|
+
innerPlugin = createSatteriPlugin({
|
|
2170
|
+
mdx: mdxOptions,
|
|
2171
|
+
...mdxConfig.mdastPlugins ? { mdastPlugins: mdxConfig.mdastPlugins } : {},
|
|
2172
|
+
...mdxConfig.hastPlugins ? { hastPlugins: mdxConfig.hastPlugins } : {},
|
|
2173
|
+
...mdxConfig.features ? { features: mdxConfig.features } : {}
|
|
2174
|
+
});
|
|
2174
2175
|
}
|
|
2175
2176
|
return {
|
|
2176
2177
|
name: "timber-mdx",
|
|
@@ -2198,6 +2199,7 @@ function timberMdx(ctx) {
|
|
|
2198
2199
|
},
|
|
2199
2200
|
async transform(code, id) {
|
|
2200
2201
|
if (!innerPlugin) return null;
|
|
2202
|
+
if (id.includes("?")) return null;
|
|
2201
2203
|
const envName = this.environment?.name;
|
|
2202
2204
|
if (envName && envName !== "rsc") return null;
|
|
2203
2205
|
if (typeof innerPlugin.transform === "function") return innerPlugin.transform.call(this, code, id);
|
|
@@ -7426,7 +7428,8 @@ var BUILD_ONLY_EXTERNALS = [
|
|
|
7426
7428
|
"vite",
|
|
7427
7429
|
"nitro",
|
|
7428
7430
|
"rollup",
|
|
7429
|
-
"
|
|
7431
|
+
"vite-plugin-satteri",
|
|
7432
|
+
"satteri",
|
|
7430
7433
|
"fsevents",
|
|
7431
7434
|
"chokidar"
|
|
7432
7435
|
];
|