@farming-labs/next 0.2.113 → 0.2.115

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/api.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import { fileURLToPath, pathToFileURL } from "node:url";
3
3
  import { createDocsAPI as createDocsAPI$1, createDocsMCPAPI as createDocsMCPAPI$1 } from "@farming-labs/theme/api";
4
- import { bundledAgentSkills } from "@farming-labs/docs/agent-skills-bundle";
4
+ import { bundledAgentSkills, bundledRootDocuments } from "@farming-labs/docs/agent-skills-bundle";
5
5
  import { createDocsCloudRouteHandler } from "@farming-labs/docs/cloud/server";
6
6
 
7
7
  //#region src/api.ts
@@ -117,7 +117,8 @@ function createDocsAPI(options = {}, cloudIntegration) {
117
117
  const handlers = createDocsAPI$1({
118
118
  ...options,
119
119
  ...rootDir ? { rootDir } : {},
120
- _preloadedAgentSkills: options._preloadedAgentSkills ?? bundledAgentSkills
120
+ _preloadedAgentSkills: options._preloadedAgentSkills ?? bundledAgentSkills,
121
+ _preloadedRootDocuments: options._preloadedRootDocuments ?? bundledRootDocuments
121
122
  });
122
123
  const integration = resolveDocsCloudIntegration(cloudIntegration);
123
124
  if (!integration) return handlers;
@@ -146,7 +147,8 @@ function createDocsMCPAPI(options = {}) {
146
147
  return createDocsMCPAPI$1({
147
148
  ...options,
148
149
  ...rootDir ? { rootDir } : {},
149
- _preloadedAgentSkills: options._preloadedAgentSkills ?? bundledAgentSkills
150
+ _preloadedAgentSkills: options._preloadedAgentSkills ?? bundledAgentSkills,
151
+ _preloadedRootDocuments: options._preloadedRootDocuments ?? bundledRootDocuments
150
152
  });
151
153
  }
152
154
 
package/dist/config.mjs CHANGED
@@ -669,11 +669,33 @@ function readAgentSkillPaths(root, configPath) {
669
669
  if (!configured) throw new Error("withDocs could not statically bundle agent.skills. Use a literal path, a literal path array, or { paths: [...] } so configured skills are included in production.");
670
670
  return configured;
671
671
  }
672
+ const ROOT_DOCUMENT_FILES = [
673
+ "skill.md",
674
+ "AGENTS.md",
675
+ "AGENT.md"
676
+ ];
677
+ /**
678
+ * Snapshot the project-root agent documents into the skills bundle. Tracing
679
+ * them by bare filename is not an option: Turbopack matches such globs at any
680
+ * depth, which drags `node_modules/next/AGENTS.md` into the trace through the
681
+ * pnpm workspace symlink and breaks Vercel output materialization.
682
+ */
683
+ function readRootDocumentsSnapshot(root) {
684
+ const documents = {};
685
+ for (const fileName of ROOT_DOCUMENT_FILES) {
686
+ const filePath = join(root, fileName);
687
+ if (!existsSync(filePath)) continue;
688
+ try {
689
+ documents[fileName] = readFileSync(filePath, "utf8");
690
+ } catch {}
691
+ }
692
+ return Object.keys(documents).length > 0 ? documents : void 0;
693
+ }
672
694
  function writeAgentSkillsBundle(root, configuredSkills) {
673
695
  const bundlePath = join(root, AGENT_SKILLS_BUNDLE_PATH);
674
- const source = `${GENERATED_BANNER}${renderDocsAgentSkillsBundle(resolveConfiguredAgentSkillsSync(configuredSkills, { rootDir: root }))}`;
675
- mkdirSync(dirname(bundlePath), { recursive: true });
676
- if (!existsSync(bundlePath) || readFileSync(bundlePath, "utf8") !== source) writeFileSync(bundlePath, source, "utf8");
696
+ const source = `${GENERATED_BANNER}${renderDocsAgentSkillsBundle(resolveConfiguredAgentSkillsSync(configuredSkills, { rootDir: root }), readRootDocumentsSnapshot(root))}`;
697
+ makeGeneratedDir(dirname(bundlePath));
698
+ if (!existsSync(bundlePath) || readFileSync(bundlePath, "utf8") !== source) writeGeneratedFile(bundlePath, source);
677
699
  return bundlePath;
678
700
  }
679
701
  /** Read the OG endpoint from docs.config.ts[x] (returns undefined if not set). */
@@ -1155,7 +1177,29 @@ function resolveManagedChangelogSourceLayoutPath(root, appDir, entry, changelogC
1155
1177
  return join(contentRoot, "layout.tsx");
1156
1178
  }
1157
1179
  function removeManagedFile(filePath) {
1158
- if (isManagedGeneratedFile(filePath)) rmSync(filePath, { force: true });
1180
+ if (isManagedGeneratedFile(filePath)) withReadOnlyFsGuard(filePath, () => rmSync(filePath, { force: true }));
1181
+ }
1182
+ const READ_ONLY_FS_CODES = new Set([
1183
+ "EROFS",
1184
+ "EACCES",
1185
+ "EPERM"
1186
+ ]);
1187
+ /** Generation must not take down config evaluation on read-only filesystems; the build already shipped these files. */
1188
+ function withReadOnlyFsGuard(target, mutate) {
1189
+ try {
1190
+ return mutate();
1191
+ } catch (error) {
1192
+ const code = error?.code;
1193
+ if (!code || !READ_ONLY_FS_CODES.has(code)) throw error;
1194
+ console.warn(`[docs] Skipped generating ${target} (${code}): filesystem is read-only; using existing files.`);
1195
+ return;
1196
+ }
1197
+ }
1198
+ function makeGeneratedDir(dirPath) {
1199
+ withReadOnlyFsGuard(dirPath, () => mkdirSync(dirPath, { recursive: true }));
1200
+ }
1201
+ function writeGeneratedFile(filePath, content) {
1202
+ withReadOnlyFsGuard(filePath, () => writeFileSync(filePath, content, "utf8"));
1159
1203
  }
1160
1204
  function resolveMcpConfig(mcp) {
1161
1205
  if (mcp === false) return {
@@ -1910,36 +1954,36 @@ function withDocs(nextConfig = {}, docsConfig) {
1910
1954
  const agentSkillsBundlePath = writeAgentSkillsBundle(root, docsConfig === void 0 || !Object.hasOwn(docsConfig, "agent") ? readAgentSkillPaths(root, docsConfigPath) : docsConfig.agent?.skills);
1911
1955
  const agentFeedback = readAgentFeedbackConfig(root);
1912
1956
  const docsConfigRelativeAlias = docsConfigPath.startsWith("./") || docsConfigPath.startsWith("../") ? docsConfigPath : `./${docsConfigPath}`;
1913
- ensureDocsReviewWorkflow({
1957
+ withReadOnlyFsGuard(".github/workflows/docs-review.yml", () => ensureDocsReviewWorkflow({
1914
1958
  rootDir: root,
1915
1959
  configPath: docsConfigPath,
1916
1960
  configContent: existsSync(docsConfigAbsolutePath) ? readFileSync(docsConfigAbsolutePath, "utf-8") : void 0,
1917
1961
  log: process.env.NODE_ENV === "test" ? void 0 : (message) => console.log(message)
1918
- });
1919
- if (!hasFile(root, "mdx-components")) writeFileSync(join(root, "mdx-components.tsx"), MDX_COMPONENTS_TEMPLATE);
1962
+ }));
1963
+ if (!hasFile(root, "mdx-components")) writeGeneratedFile(join(root, "mdx-components.tsx"), MDX_COMPONENTS_TEMPLATE);
1920
1964
  const entry = readDocsEntry(root);
1921
1965
  const docsPath = normalizeDocsPath(readDocsPath(root), entry);
1922
1966
  const configuredContentDir = readDocsContentDir(root);
1923
1967
  const appDir = getNextAppDir(root);
1924
1968
  const docsContentDir = configuredContentDir ?? join(appDir, entry);
1925
1969
  const layoutDir = join(root, appDir, entry);
1926
- if (!existsSync(layoutDir)) mkdirSync(layoutDir, { recursive: true });
1970
+ if (!existsSync(layoutDir)) makeGeneratedDir(layoutDir);
1927
1971
  const docsLayoutPath = join(layoutDir, "layout.tsx");
1928
- if (!hasFile(layoutDir, "layout") || isManagedGeneratedFile(docsLayoutPath)) writeFileSync(join(layoutDir, "layout.tsx"), DOCS_LAYOUT_TEMPLATE);
1972
+ if (!hasFile(layoutDir, "layout") || isManagedGeneratedFile(docsLayoutPath)) writeGeneratedFile(join(layoutDir, "layout.tsx"), DOCS_LAYOUT_TEMPLATE);
1929
1973
  const isStaticExport = nextConfig.output === "export";
1930
1974
  const docsApiRouteDir = join(root, appDir, "api", "docs");
1931
1975
  const existingDocsApiRoutePath = FILE_EXTS.map((ext) => join(docsApiRouteDir, `route.${ext}`)).find((filePath) => existsSync(filePath));
1932
1976
  const docsApiRoutePath = existingDocsApiRoutePath ?? join(docsApiRouteDir, "route.ts");
1933
1977
  if (!isStaticExport && (!existingDocsApiRoutePath || isManagedGeneratedFile(existingDocsApiRoutePath))) {
1934
- mkdirSync(docsApiRouteDir, { recursive: true });
1935
- writeFileSync(docsApiRoutePath, DOCS_API_ROUTE_TEMPLATE);
1978
+ makeGeneratedDir(docsApiRouteDir);
1979
+ writeGeneratedFile(docsApiRoutePath, DOCS_API_ROUTE_TEMPLATE);
1936
1980
  }
1937
1981
  const sitemap = readSitemapConfig(root);
1938
1982
  const robots = readRobotsConfig(root);
1939
1983
  const docsMcpRouteDir = join(root, appDir, "api", "docs", "mcp");
1940
1984
  if (mcp.enabled && mcp.route === DEFAULT_MCP_ROUTE && !isStaticExport && !hasFile(docsMcpRouteDir, "route")) {
1941
- mkdirSync(docsMcpRouteDir, { recursive: true });
1942
- writeFileSync(join(docsMcpRouteDir, "route.ts"), DOCS_MCP_ROUTE_TEMPLATE);
1985
+ makeGeneratedDir(docsMcpRouteDir);
1986
+ writeGeneratedFile(join(docsMcpRouteDir, "route.ts"), DOCS_MCP_ROUTE_TEMPLATE);
1943
1987
  }
1944
1988
  const apiReference = readApiReferenceConfig(root);
1945
1989
  if (apiReference.enabled && !isStaticExport) {
@@ -1954,19 +1998,19 @@ function withDocs(nextConfig = {}, docsConfig) {
1954
1998
  removeManagedFile(apiReferenceRoutePath);
1955
1999
  removeManagedFile(legacyApiReferencePagePath);
1956
2000
  if (!hasFile(apiReferenceBaseDir, "layout") || isManagedGeneratedFile(apiReferenceLayoutPath)) {
1957
- mkdirSync(apiReferenceBaseDir, { recursive: true });
1958
- writeFileSync(apiReferenceLayoutPath, API_REFERENCE_LAYOUT_TEMPLATE);
2001
+ makeGeneratedDir(apiReferenceBaseDir);
2002
+ writeGeneratedFile(apiReferenceLayoutPath, API_REFERENCE_LAYOUT_TEMPLATE);
1959
2003
  }
1960
2004
  if (!hasFile(apiReferencePageDir, "page") || isManagedGeneratedFile(apiReferencePagePath)) {
1961
- mkdirSync(apiReferencePageDir, { recursive: true });
1962
- writeFileSync(apiReferencePagePath, API_REFERENCE_PAGE_TEMPLATE);
2005
+ makeGeneratedDir(apiReferencePageDir);
2006
+ writeGeneratedFile(apiReferencePagePath, API_REFERENCE_PAGE_TEMPLATE);
1963
2007
  }
1964
2008
  } else {
1965
2009
  removeManagedFile(apiReferenceLayoutPath);
1966
2010
  removeManagedFile(apiReferencePagePath);
1967
2011
  if (!hasFile(apiReferenceRouteDir, "route") || isManagedGeneratedFile(apiReferenceRoutePath)) {
1968
- mkdirSync(apiReferenceRouteDir, { recursive: true });
1969
- writeFileSync(apiReferenceRoutePath, API_REFERENCE_ROUTE_TEMPLATE);
2012
+ makeGeneratedDir(apiReferenceRouteDir);
2013
+ writeGeneratedFile(apiReferenceRoutePath, API_REFERENCE_ROUTE_TEMPLATE);
1970
2014
  }
1971
2015
  }
1972
2016
  }
@@ -1987,22 +2031,22 @@ function withDocs(nextConfig = {}, docsConfig) {
1987
2031
  removeManagedFile(join(legacyChangelogBaseDir, "page.tsx"));
1988
2032
  removeManagedFile(join(legacyChangelogBaseDir, "__changelog.generated.tsx"));
1989
2033
  }
1990
- mkdirSync(changelogBaseDir, { recursive: true });
2034
+ makeGeneratedDir(changelogBaseDir);
1991
2035
  removeManagedFile(join(changelogBaseDir, "__changelog.generated.tsx"));
1992
- if (!hasFile(changelogBaseDir, "page") || isManagedGeneratedFile(changelogIndexPath)) writeFileSync(changelogIndexPath, buildChangelogIndexPageSource(root, changelogIndexPath, entry, changelog.path, changelogEntries));
2036
+ if (!hasFile(changelogBaseDir, "page") || isManagedGeneratedFile(changelogIndexPath)) writeGeneratedFile(changelogIndexPath, buildChangelogIndexPageSource(root, changelogIndexPath, entry, changelog.path, changelogEntries));
1993
2037
  if (changelogUsesSourcePagesAsDetails) {
1994
2038
  removeManagedFile(changelogEntryPath);
1995
2039
  if (changelogSourceLayoutPath) removeManagedFile(changelogSourceLayoutPath);
1996
2040
  } else {
1997
2041
  if (!hasFile(changelogEntryDir, "page") || isManagedGeneratedFile(changelogEntryPath)) {
1998
- mkdirSync(changelogEntryDir, { recursive: true });
1999
- writeFileSync(changelogEntryPath, buildChangelogEntryPageSource(root, changelogEntryPath, entry, changelog.path, changelogEntries));
2042
+ makeGeneratedDir(changelogEntryDir);
2043
+ writeGeneratedFile(changelogEntryPath, buildChangelogEntryPageSource(root, changelogEntryPath, entry, changelog.path, changelogEntries));
2000
2044
  }
2001
2045
  if (changelogSourceLayoutPath) {
2002
2046
  const changelogSourceLayoutDir = dirname(changelogSourceLayoutPath);
2003
2047
  if (!hasFile(changelogSourceLayoutDir, "layout") || isManagedGeneratedFile(changelogSourceLayoutPath)) {
2004
- mkdirSync(changelogSourceLayoutDir, { recursive: true });
2005
- writeFileSync(changelogSourceLayoutPath, CHANGELOG_SOURCE_LAYOUT_TEMPLATE);
2048
+ makeGeneratedDir(changelogSourceLayoutDir);
2049
+ writeGeneratedFile(changelogSourceLayoutPath, CHANGELOG_SOURCE_LAYOUT_TEMPLATE);
2006
2050
  }
2007
2051
  }
2008
2052
  }
@@ -2098,9 +2142,6 @@ function withDocs(nextConfig = {}, docsConfig) {
2098
2142
  };
2099
2143
  const existingTracingIncludes = nextConfig.outputFileTracingIncludes ?? {};
2100
2144
  const docsTraceGlob = docsContentDir.replace(/\\/g, "/").replace(/^\.?\//, "") + "/**/*";
2101
- const skillTraceFile = "skill.md";
2102
- const agentsTraceFile = "AGENTS.md";
2103
- const agentTraceFile = "AGENT.md";
2104
2145
  const sitemapManifestTraceFile = DEFAULT_SITEMAP_MANIFEST_PATH;
2105
2146
  const docsContentRoot = isAbsolute(docsContentDir) ? docsContentDir : join(root, docsContentDir);
2106
2147
  if (!isStaticExport) {
@@ -2121,16 +2162,9 @@ function withDocs(nextConfig = {}, docsConfig) {
2121
2162
  "/api/docs": [...new Set([
2122
2163
  ...existingTracingIncludes["/api/docs"] ?? [],
2123
2164
  docsTraceGlob,
2124
- skillTraceFile,
2125
- agentsTraceFile,
2126
- agentTraceFile,
2127
2165
  sitemapManifestTraceFile
2128
2166
  ])],
2129
- [DEFAULT_MCP_ROUTE]: [...new Set([
2130
- ...existingTracingIncludes[DEFAULT_MCP_ROUTE] ?? [],
2131
- docsTraceGlob,
2132
- skillTraceFile
2133
- ])]
2167
+ [DEFAULT_MCP_ROUTE]: [...new Set([...existingTracingIncludes[DEFAULT_MCP_ROUTE] ?? [], docsTraceGlob])]
2134
2168
  };
2135
2169
  return withMDX(nextConfig);
2136
2170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/next",
3
- "version": "0.2.113",
3
+ "version": "0.2.115",
4
4
  "description": "Next.js adapter for @farming-labs/docs — MDX config wrapper",
5
5
  "keywords": [
6
6
  "docs",
@@ -109,8 +109,8 @@
109
109
  "tsdown": "^0.20.3",
110
110
  "typescript": "^5.9.3",
111
111
  "vitest": "^4.1.8",
112
- "@farming-labs/theme": "0.2.113",
113
- "@farming-labs/docs": "0.2.113"
112
+ "@farming-labs/docs": "0.2.115",
113
+ "@farming-labs/theme": "0.2.115"
114
114
  },
115
115
  "peerDependencies": {
116
116
  "@farming-labs/docs": ">=0.2.73",