From b9db4934eadd622c7a1b10085c654dab28f7f3d1 Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Tue, 9 Jul 2024 18:13:02 -0400 Subject: [PATCH] fix: (regression) parseDocsConfiguration accidentally calls loadAllPages with absolutePathToDocsConfig (#4026) * fix: (regression) parseDocsConfiguration accidentally calls loadAllPages with absolutePathToDocsConfig * update tests --- .pnp.cjs | 1 + .../configuration/src/docs-yml/getAllPages.ts | 30 ++++++++++++------- .../src/docs-yml/parseDocsConfiguration.ts | 10 +++---- packages/cli/ete-tests/package.json | 1 + .../src/tests/docs-dev/docsDev.test.ts | 20 ++++++++++++- yarn.lock | 1 + 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/.pnp.cjs b/.pnp.cjs index 4fd857319c8..8dbb5c04442 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -6746,6 +6746,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "packageDependencies": [\ ["@fern-api/ete-tests", "workspace:packages/cli/ete-tests"],\ ["@fern-api/configuration", "workspace:packages/cli/configuration"],\ + ["@fern-api/fdr-sdk", "npm:0.98.10-04e9d1412"],\ ["@fern-api/fs-utils", "workspace:packages/commons/fs-utils"],\ ["@fern-api/logging-execa", "workspace:packages/commons/logging-execa"],\ ["@fern-typescript/fetcher", "workspace:generators/typescript/utils/core-utilities/fetcher"],\ diff --git a/packages/cli/configuration/src/docs-yml/getAllPages.ts b/packages/cli/configuration/src/docs-yml/getAllPages.ts index 477eef3f16e..adcf0ca58c2 100644 --- a/packages/cli/configuration/src/docs-yml/getAllPages.ts +++ b/packages/cli/configuration/src/docs-yml/getAllPages.ts @@ -10,10 +10,15 @@ import { const BATCH_SIZE = 100; // Define a reasonable batch size -async function loadBatch( - files: AbsoluteFilePath[], - absolutePathToFernFolder: AbsoluteFilePath -): Promise> { +interface LoadPagesOptions { + files: AbsoluteFilePath[]; + absolutePathToFernFolder: AbsoluteFilePath; +} + +async function loadBatch({ + files, + absolutePathToFernFolder +}: LoadPagesOptions): Promise> { const pairs = await Promise.all( files.map(async (file) => { const content = await readFile(file, "utf-8"); @@ -23,16 +28,21 @@ async function loadBatch( return Object.fromEntries(pairs); } -export async function loadAllPages( - filesPromise: Promise, - absolutePathToFernFolder: AbsoluteFilePath -): Promise> { - const files = await filesPromise; +export async function loadAllPages({ + files, + absolutePathToFernFolder +}: { + files: AbsoluteFilePath[]; + absolutePathToFernFolder: AbsoluteFilePath; +}): Promise> { const result: Record = {}; for (let i = 0; i < files.length; i += BATCH_SIZE) { const batch = files.slice(i, i + BATCH_SIZE); - const batchResult = await loadBatch(batch, absolutePathToFernFolder); + const batchResult = await loadBatch({ + files: batch, + absolutePathToFernFolder + }); Object.assign(result, batchResult); } diff --git a/packages/cli/configuration/src/docs-yml/parseDocsConfiguration.ts b/packages/cli/configuration/src/docs-yml/parseDocsConfiguration.ts index 03d691ff49b..50ac70fe0c9 100644 --- a/packages/cli/configuration/src/docs-yml/parseDocsConfiguration.ts +++ b/packages/cli/configuration/src/docs-yml/parseDocsConfiguration.ts @@ -80,11 +80,11 @@ export async function parseDocsConfiguration({ context }); - const pagesPromise = loadAllPages( - convertedNavigationPromise.then((convertedNavigation) => - getAllPages({ navigation: convertedNavigation, landingPage }) - ), - absoluteFilepathToDocsConfig + const pagesPromise = convertedNavigationPromise.then((convertedNavigation) => + loadAllPages({ + files: getAllPages({ navigation: convertedNavigation, landingPage }), + absolutePathToFernFolder + }) ); const logo = convertLogoReference(rawLogo, absoluteFilepathToDocsConfig); diff --git a/packages/cli/ete-tests/package.json b/packages/cli/ete-tests/package.json index c6c1855168a..f55a409a201 100644 --- a/packages/cli/ete-tests/package.json +++ b/packages/cli/ete-tests/package.json @@ -28,6 +28,7 @@ }, "dependencies": { "@fern-api/configuration": "workspace:*", + "@fern-api/fdr-sdk": "0.98.10-04e9d1412", "@fern-api/fs-utils": "workspace:*", "@fern-api/logging-execa": "workspace:*", "@fern-typescript/fetcher": "workspace:*", diff --git a/packages/cli/ete-tests/src/tests/docs-dev/docsDev.test.ts b/packages/cli/ete-tests/src/tests/docs-dev/docsDev.test.ts index 068cfe6ff92..34f66639826 100644 --- a/packages/cli/ete-tests/src/tests/docs-dev/docsDev.test.ts +++ b/packages/cli/ete-tests/src/tests/docs-dev/docsDev.test.ts @@ -1,3 +1,4 @@ +import { DocsV2Read, FernNavigation } from "@fern-api/fdr-sdk"; import { AbsoluteFilePath, join, RelativeFilePath } from "@fern-api/fs-utils"; import fetch from "node-fetch"; import { runFernCli } from "../../utils/runFernCli"; @@ -26,10 +27,27 @@ describe("fern docs dev", () => { const responseText = await response.text(); expect(responseText.includes("[object Promise]")).toBeFalsy(); - const responseBody = JSON.parse(responseText); + const responseBody = JSON.parse(responseText) as DocsV2Read.LoadDocsForUrlResponse; expect(typeof responseBody === "object").toEqual(true); // eslint-disable-next-line @typescript-eslint/no-explicit-any expect(Object.keys(responseBody as any)).toEqual(["baseUrl", "definition", "lightModeEnabled"]); + + const root = FernNavigation.utils.convertLoadDocsForUrlResponse(responseBody); + const pageIds = new Set(Object.keys(responseBody.definition.pages)); + const pageIdsVisited = new Set(); + + FernNavigation.utils.traverseNavigation(root, (node) => { + if (FernNavigation.hasMarkdown(node)) { + const pageId = FernNavigation.utils.getPageId(node); + if (pageId != null) { + pageIdsVisited.add(pageId); + } + } + }); + expect(pageIdsVisited.size).toBeGreaterThan(0); + + const overlap = new Set([...pageIds].filter((x) => pageIdsVisited.has(x))); + expect(overlap.size).toEqual(pageIdsVisited.size); }, 30_000); }); diff --git a/yarn.lock b/yarn.lock index 09c6aed423f..0647061838f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3684,6 +3684,7 @@ __metadata: resolution: "@fern-api/ete-tests@workspace:packages/cli/ete-tests" dependencies: "@fern-api/configuration": "workspace:*" + "@fern-api/fdr-sdk": 0.98.10-04e9d1412 "@fern-api/fs-utils": "workspace:*" "@fern-api/logging-execa": "workspace:*" "@fern-typescript/fetcher": "workspace:*"