Skip to content

Commit

Permalink
fix: (regression) parseDocsConfiguration accidentally calls loadAllPa…
Browse files Browse the repository at this point in the history
…ges with absolutePathToDocsConfig (#4026)

* fix: (regression) parseDocsConfiguration accidentally calls loadAllPages with absolutePathToDocsConfig

* update tests
  • Loading branch information
abvthecity authored Jul 9, 2024
1 parent 84c482a commit b9db493
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
1 change: 1 addition & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 20 additions & 10 deletions packages/cli/configuration/src/docs-yml/getAllPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import {

const BATCH_SIZE = 100; // Define a reasonable batch size

async function loadBatch(
files: AbsoluteFilePath[],
absolutePathToFernFolder: AbsoluteFilePath
): Promise<Record<RelativeFilePath, string>> {
interface LoadPagesOptions {
files: AbsoluteFilePath[];
absolutePathToFernFolder: AbsoluteFilePath;
}

async function loadBatch({
files,
absolutePathToFernFolder
}: LoadPagesOptions): Promise<Record<RelativeFilePath, string>> {
const pairs = await Promise.all(
files.map(async (file) => {
const content = await readFile(file, "utf-8");
Expand All @@ -23,16 +28,21 @@ async function loadBatch(
return Object.fromEntries(pairs);
}

export async function loadAllPages(
filesPromise: Promise<AbsoluteFilePath[]>,
absolutePathToFernFolder: AbsoluteFilePath
): Promise<Record<RelativeFilePath, string>> {
const files = await filesPromise;
export async function loadAllPages({
files,
absolutePathToFernFolder
}: {
files: AbsoluteFilePath[];
absolutePathToFernFolder: AbsoluteFilePath;
}): Promise<Record<RelativeFilePath, string>> {
const result: Record<RelativeFilePath, string> = {};

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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/ete-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
20 changes: 19 additions & 1 deletion packages/cli/ete-tests/src/tests/docs-dev/docsDev.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<string>();

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);
});

Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:*"
Expand Down

0 comments on commit b9db493

Please sign in to comment.