Skip to content

Commit

Permalink
merge from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohin Bhargava authored and Rohin Bhargava committed Jul 29, 2024
2 parents 14f82ee + dc629cf commit ee41049
Show file tree
Hide file tree
Showing 87 changed files with 939 additions and 450 deletions.
4 changes: 2 additions & 2 deletions .github/actions/install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ runs:

steps:
- name: ⎔ Setup pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8
version: 9.4.0

- name: ⎔ Setup Node.js
uses: actions/setup-node@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8
version: 9.4.0

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8
version: 9.4.0

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/production-dashboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8
version: 9.4.0

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
run: npm install --global vercel@latest

- name: Setup pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8
version: 9.4.0

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/publish-fdr-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Publish FDR SDKs

on:
workflow_call:
workflow_dispatch:

env:
PACKAGE_NAME: "@fern-platform/fdr"
Expand All @@ -18,6 +19,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || "main" }}

- name: 📥 Install
uses: ./.github/actions/install
Expand All @@ -26,19 +28,19 @@ jobs:
run: npm install -g fern-api

- name: Publish Fiddle FDR SDK
env:
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
git_version="$(scripts/fdr-version.sh)"
fern generate --api fdr --group fiddle --version $git_version
publish_sdk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || "main" }}

- name: 📥 Install
uses: ./.github/actions/install
Expand All @@ -47,7 +49,7 @@ jobs:
run: pnpm turbo codegen build test --filter=${{ env.PACKAGE_NAME }}

- name: Publish FDR SDK
env:
env:
NPM_TOKEN: ${{ secrets.FERN_NPM_TOKEN }}
run: |
git_version="$(scripts/fdr-version.sh)"
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"name": "Debug with Chrome",
"type": "node-terminal",
"request": "launch",
"command": "pnpm docs:dev",
"command": "pnpm dev:fern-prod",
"cwd": "${workspaceFolder}/packages/ui/docs-bundle",
"serverReadyAction": {
"pattern": "- Local:.+(https?://.+)",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"postcss": "8.4.31",
"esbuild": "0.20.2"
},
"packageManager": "[email protected]",
"dependenciesMeta": {
"[email protected]": {
"unplugged": true
Expand All @@ -101,5 +100,6 @@
"dependencies": {
"@radix-ui/colors": "^3.0.0",
"fern-api": "^0.21.0"
}
},
"packageManager": "[email protected]"
}
23 changes: 0 additions & 23 deletions packages/commons/fdr-utils/src/getUnversionedSlug.ts

This file was deleted.

29 changes: 17 additions & 12 deletions packages/fdr-sdk/src/navigation/NodeCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const NodeCollectorInstances = new WeakMap<NavigationNode, NodeCollector>();
export class NodeCollector {
private static readonly EMPTY = new NodeCollector(undefined);
private idToNode = new Map<FernNavigation.NodeId, NavigationNode>();
private slugToNode: Record<FernNavigation.Slug, NavigationNodeWithMetadataAndParents> = {};
private idToNodeParents = new Map<FernNavigation.NodeId, NavigationNode[]>();
private slugToNode = new Map<FernNavigation.Slug, NavigationNodeWithMetadataAndParents>();
private orphanedNodes: NavigationNodeWithMetadata[] = [];

public static collect(rootNode: NavigationNode | undefined): NodeCollector {
Expand All @@ -45,7 +46,7 @@ export class NodeCollector {
#lastNeighboringNode: NavigationNodeNeighbor | undefined;
#setNode(slug: FernNavigation.Slug, node: NavigationNodeWithMetadata, parents: NavigationNode[]) {
const toSet = { node, parents, prev: this.#lastNeighboringNode, next: undefined };
this.slugToNode[slug] = toSet;
this.slugToNode.set(slug, toSet);

if (isNeighbor(node) && !node.hidden) {
this.#lastNeighboringNode = node;
Expand All @@ -63,7 +64,9 @@ export class NodeCollector {
}
traverseNavigation(rootNode, (node, _index, parents) => {
this.idToNode.set(node.id, node);
this.idToNodeParents.set(node.id, parents);

// if the node is the default version, make a copy of it and "prune" the version slug from all children nodes
const parent = parents[parents.length - 1];
if (
node.type === "version" &&
Expand Down Expand Up @@ -94,7 +97,7 @@ export class NodeCollector {
return;
}

const existing = this.slugToNode[node.slug];
const existing = this.slugToNode.get(node.slug);
if (existing == null) {
this.#setNode(node.slug, node, parents);
} else if (!node.hidden && isPage(node) && (existing.node.hidden || !isPage(existing.node))) {
Expand All @@ -118,7 +121,7 @@ export class NodeCollector {
});

private getSlugMap = once((): Map<string, NavigationNodeWithMetadata> => {
return new Map(Object.entries(this.slugToNode).map(([slug, { node }]) => [slug, node]));
return new Map([...this.slugToNode.entries()].map(([slug, { node }]) => [slug, node]));
});

get slugMap(): Map<string, NavigationNodeWithMetadata> {
Expand All @@ -133,21 +136,23 @@ export class NodeCollector {
return this.idToNode.get(id);
}

public getSlugMapWithParents = once((): Map<string, NavigationNodeWithMetadataAndParents> => {
return new Map(Object.entries(this.slugToNode));
});
public getParents(id: FernNavigation.NodeId): NavigationNode[] {
return this.idToNodeParents.get(id) ?? [];
}

public getSlugMapWithParents = (): ReadonlyMap<FernNavigation.Slug, NavigationNodeWithMetadataAndParents> => {
return this.slugToNode;
};

public getSlugs = once((): string[] => {
return Object.keys(this.slugToNode);
return [...this.slugToNode.keys()];
});

/**
* Returns a list of slugs for all pages in the navigation tree. This includes hidden pages.
*/
public getPageSlugs = once((): string[] => {
return Object.values(this.slugToNode)
.filter(({ node }) => isPage(node))
.map(({ node }) => urljoin(node.slug));
return [...this.slugToNode.values()].filter(({ node }) => isPage(node)).map(({ node }) => urljoin(node.slug));
});

/**
Expand All @@ -156,7 +161,7 @@ export class NodeCollector {
* This excludes hidden pages and noindex pages.
*/
public getIndexablePageSlugs = once((): string[] => {
return Object.values(this.slugToNode)
return [...this.slugToNode.values()]
.filter(({ node }) => isPage(node) && node.hidden !== true)
.filter(({ node }) => (hasMarkdown(node) ? node.noindex !== true : true))
.map(({ node }) => urljoin(node.slug));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ApiReferenceNavigationConverter {
idgen?: NodeIdGenerator,
lexicographic?: boolean,
disableEndpointPairs?: boolean,
disableLongScrolling?: boolean,
) {
return new ApiReferenceNavigationConverter(
apiSection,
Expand All @@ -30,6 +31,7 @@ export class ApiReferenceNavigationConverter {
idgen ?? new NodeIdGenerator(),
lexicographic,
disableEndpointPairs,
disableLongScrolling,
).convert();
}

Expand All @@ -48,6 +50,7 @@ export class ApiReferenceNavigationConverter {
idgen: NodeIdGenerator,
private lexicographic: boolean = false,
private disableEndpointPairs: boolean = false,
private disableLongScrolling: boolean | undefined,
) {
this.apiDefinitionId = FernNavigation.ApiDefinitionId(api.id);
this.#holder = ApiDefinitionHolder.create(api);
Expand Down Expand Up @@ -81,7 +84,8 @@ export class ApiReferenceNavigationConverter {
apiDefinitionId: FernNavigation.ApiDefinitionId(this.apiSection.api),
overviewPageId,
noindex,
disableLongScrolling: this.apiSection.longScrolling === false ? true : undefined,
disableLongScrolling:
this.disableLongScrolling ?? (this.apiSection.longScrolling === false ? true : undefined),
slug: slug.get(),
icon: this.apiSection.icon,
hidden: this.apiSection.hidden,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class NavigationConfigConverter {
private basePath: string | undefined,
private lexicographic?: boolean,
private disableEndpointPairs?: boolean,
private disableLongScrolling?: boolean,
) {}

public static convert(
Expand All @@ -29,6 +30,7 @@ export class NavigationConfigConverter {
basePath: string | undefined,
lexicographic?: boolean,
disableEndpointPairs?: boolean,
disableLongScrolling?: boolean,
): FernNavigation.RootNode {
return new NavigationConfigConverter(
title,
Expand All @@ -38,6 +40,7 @@ export class NavigationConfigConverter {
basePath,
lexicographic,
disableEndpointPairs,
disableLongScrolling,
).convert();
}

Expand Down Expand Up @@ -289,12 +292,19 @@ export class NavigationConfigConverter {
this.#idgen,
this.lexicographic,
this.disableEndpointPairs,
this.disableLongScrolling,
);
},
changelog: (changelog) =>
ChangelogNavigationConverter.convert(changelog, this.noindexMap, parentSlug, this.#idgen),
// Note: apiSection.node is imported from `navigation`, and is guaranteed to be a FernNavigation.ApiReferenceNode
apiV2: (apiSection) => apiSection.node as unknown as FernNavigation.ApiReferenceNode,
apiV2: (apiSection) => {
const node = apiSection.node as unknown as FernNavigation.ApiReferenceNode;
if (this.disableLongScrolling) {
node.disableLongScrolling = true;
}
return node;
},
changelogV3: (changelog) => changelog.node as unknown as FernNavigation.ChangelogNode,
_other: (value) => assertNever(value as never),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { FernNavigation } from "../../generated";
import { toDefaultSlug } from "../pruneVersionNode";

describe("toDefaultSlug", () => {
it("should return the default slug", () => {
expect(
toDefaultSlug(
FernNavigation.Slug("basepath/version/page"),
FernNavigation.Slug("basepath"),
FernNavigation.Slug("basepath/version"),
),
).toEqual(FernNavigation.Slug("basepath/page"));
});

it("should be noop if the slug doesn't start with the version slug", () => {
expect(
toDefaultSlug(
FernNavigation.Slug("basepath/page"),
FernNavigation.Slug("basepath"),
FernNavigation.Slug("basepath/version"),
),
).toEqual(FernNavigation.Slug("basepath/page"));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getNoIndexFromFrontmatter } from "./getNoIndexFromFrontmatter";
export function convertLoadDocsForUrlResponse(
response: DocsV2Read.LoadDocsForUrlResponse,
disableEndpointPairs: boolean = false,
disableLongScrolling?: boolean,
): FernNavigation.RootNode {
const noindexMap: Record<FernNavigation.PageId, boolean> = {};
Object.entries(response.definition.pages).forEach(([pageId, page]) => {
Expand All @@ -23,6 +24,7 @@ export function convertLoadDocsForUrlResponse(
response.baseUrl.basePath,
isLexicographicSortEnabled(response.baseUrl.domain),
disableEndpointPairs,
disableLongScrolling,
);
}

Expand Down
Loading

0 comments on commit ee41049

Please sign in to comment.