Skip to content

Commit

Permalink
refactor: replace next-mdx-remote with mdx-bundler (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Jul 9, 2024
1 parent 0d669df commit 04e9d14
Show file tree
Hide file tree
Showing 64 changed files with 829 additions and 453 deletions.
2 changes: 1 addition & 1 deletion clis/generator-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/yargs": "^17.0.32",
"@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.15",
"depcheck": "^1.4.3",
"esbuild": "^0.15.7",
"esbuild": "0.20.2",
"eslint": "^8.56.0",
"execa": "^5.1.1",
"lodash-es": "^4.17.12",
Expand Down
5 changes: 5 additions & 0 deletions fern/apis/fdr/definition/docs/v1/db/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ types:
referencedApis: set<rootCommons.ApiDefinitionId>
files: map<commons.FileId, DbFileInfoV2>
config: DocsDbConfig
jsFiles:
type: optional<map<string, string>>
docs: |
A map of file names to their contents.
The key is the absolute path file name and the value is the file contents.
DocsDbConfig:
properties:
Expand Down
5 changes: 5 additions & 0 deletions fern/apis/fdr/definition/docs/v1/read/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ types:
apis: map<rootCommons.ApiDefinitionId, apiReadV1.ApiDefinition>
files: map<commons.FileId, commons.Url>
filesV2: map<commons.FileId, File>
jsFiles:
type: optional<map<string, string>>
docs: |
A map of file names to their contents.
The key is the absolute path file name and the value is the file contents.
id: optional<rootCommons.DocsConfigId>
config: DocsConfig
search: algolia.SearchInfo
Expand Down
5 changes: 5 additions & 0 deletions fern/apis/fdr/definition/docs/v1/write/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ types:
properties:
pages: map<commons.PageId, PageContent>
config: DocsConfig
jsFiles:
type: optional<map<string, string>>
docs: |
A map of file names to their contents.
The key is the absolute path file name and the value is the file contents.
PageContent:
properties:
Expand Down

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

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

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

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

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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function convertDocsDefinitionToDb({
integrations: writeShape.config.integrations,
},
pages: writeShape.pages,
jsFiles: writeShape.jsFiles,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DocsV1Db } from "../../../client";
import { isPlainObject } from "../../../utils";
import { WithoutQuestionMarks } from "../../utils/WithoutQuestionMarks";
import { upgradeV1ToV2 } from "./upgradeV1ToV2";
import { upgradeV2ToV3 } from "./upgradeV2ToV3";

export function migrateDocsDbDefinition(buffer: unknown): DocsV1Db.DocsDefinitionDb.V3 {
export function migrateDocsDbDefinition(buffer: unknown): WithoutQuestionMarks<DocsV1Db.DocsDefinitionDb.V3> {
if (!isPlainObject(buffer)) {
throw new Error("Invalid buffer");
}
Expand All @@ -20,5 +21,5 @@ export function migrateDocsDbDefinition(buffer: unknown): DocsV1Db.DocsDefinitio
return upgradeV2ToV3(dbValue);
}

return dbValue as DocsV1Db.DocsDefinitionDb.V3;
return dbValue as WithoutQuestionMarks<DocsV1Db.DocsDefinitionDb.V3>;
}
4 changes: 3 additions & 1 deletion packages/fdr-sdk/src/converters/db/upgrade/upgradeV2ToV3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { DocsV1Db } from "../../../client";
import { mapValues } from "../../../utils";
import { WithoutQuestionMarks } from "../../utils/WithoutQuestionMarks";

export function upgradeV2ToV3(v2: DocsV1Db.DocsDefinitionDb.V2): DocsV1Db.DocsDefinitionDb.V3 {
export function upgradeV2ToV3(v2: DocsV1Db.DocsDefinitionDb.V2): WithoutQuestionMarks<DocsV1Db.DocsDefinitionDb.V3> {
return {
type: "v3",
pages: v2.pages,
Expand All @@ -14,5 +15,6 @@ export function upgradeV2ToV3(v2: DocsV1Db.DocsDefinitionDb.V2): DocsV1Db.DocsDe
}),
),
config: v2.config,
jsFiles: undefined,
};
}
3 changes: 1 addition & 2 deletions packages/healthchecks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
"@fern-ui/core-utils": "workspace:*",
"@types/jest": "^29.5.11",
"@types/node": "^18.7.18",
"@types/node-emoji": "^2.1.0",
"@types/yargs": "^17.0.32",
"@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.15",
"depcheck": "^1.4.3",
"esbuild": "^0.15.7",
"esbuild": "0.20.2",
"eslint": "^8.56.0",
"organize-imports-cli": "^0.10.0",
"prettier": "^3.3.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/app/.depcheckrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"@storybook/addon-onboarding",
"@storybook/blocks",
"@storybook/test",
"@emotion/is-prop-valid"
"@emotion/is-prop-valid",
"mdx"
],
"ignore-patterns": ["dist"]
}
12 changes: 12 additions & 0 deletions packages/ui/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
"source": "src/index.ts",
"module": "src/index.ts",
"main": "src/index.ts",
"exports": {
".": {
"default": "./src/index.ts"
},
"./bundlers": {
"default": "./src/mdx/bundlers/index.ts"
}
},
"sideEffects": [
"*.css",
"*.scss"
Expand Down Expand Up @@ -65,6 +73,7 @@
"bezier-easing": "^2.1.0",
"clsx": "^2.1.0",
"colorjs.io": "^0.5.0",
"esbuild": "0.20.2",
"estree-util-visit": "^2.0.0",
"fastdom": "^1.0.12",
"framer-motion": "^11.2.4",
Expand All @@ -86,6 +95,7 @@
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-mdx-jsx": "^3.1.0",
"mdast-util-to-hast": "^13.1.0",
"mdx-bundler": "^10.0.2",
"moment": "^2.30.1",
"next": "^14.2.3",
"next-mdx-remote": "^5.0.0",
Expand Down Expand Up @@ -122,6 +132,7 @@
"devDependencies": {
"@chromatic-com/storybook": "^1.3.5",
"@fern-platform/configs": "workspace:*",
"@mdx-js/esbuild": "^3.0.1",
"@storybook/addon-essentials": "8.1.0-alpha.6",
"@storybook/addon-interactions": "8.1.0-alpha.6",
"@storybook/addon-links": "8.1.0-alpha.6",
Expand All @@ -141,6 +152,7 @@
"@types/jsonpath": "^0.2.4",
"@types/lodash-es": "^4.17.12",
"@types/mdast": "^4.0.3",
"@types/mdx": "^2.0.13",
"@types/node": "^18.7.18",
"@types/numeral": "^2.0.5",
"@types/react": "^18.0.20",
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/app/src/api-page/ApiPageDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cn from "clsx";
import dynamic from "next/dynamic";
import { SerializedMdxContent } from "../mdx/mdx";
import type { BundledMDX } from "../mdx/types";

const Markdown = dynamic(() => import("../mdx/Markdown").then(({ Markdown }) => Markdown), {
ssr: true,
Expand All @@ -9,7 +9,7 @@ const Markdown = dynamic(() => import("../mdx/Markdown").then(({ Markdown }) =>
export declare namespace ApiPageDescription {
export interface Props {
className?: string;
description: string | SerializedMdxContent | undefined;
description: BundledMDX | undefined;
isMarkdown: boolean;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/app/src/api-page/endpoints/EndpointParameter.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { APIV1Read } from "@fern-api/fdr-sdk";
import cn from "clsx";
import type { MDXRemoteSerializeResult } from "next-mdx-remote";
import { FC, PropsWithChildren, ReactNode, memo, useRef, useState } from "react";
import { AbsolutelyPositionedAnchor } from "../../commons/AbsolutelyPositionedAnchor";
import { useRouteListener } from "../../contexts/useRouteListener";
import type { BundledMDX } from "../../mdx/types";
import { ResolvedTypeDefinition, ResolvedTypeShape } from "../../resolver/types";
import { getAnchorId } from "../../util/anchor";
import { ApiPageDescription } from "../ApiPageDescription";
Expand All @@ -14,7 +14,7 @@ import { EndpointAvailabilityTag } from "./EndpointAvailabilityTag";
export declare namespace EndpointParameter {
export interface Props {
name: string;
description: MDXRemoteSerializeResult | string | undefined;
description: BundledMDX | undefined;
shape: ResolvedTypeShape;
anchorIdParts: readonly string[];
route: string;
Expand All @@ -24,7 +24,7 @@ export declare namespace EndpointParameter {

export interface ContentProps {
name: string;
description: MDXRemoteSerializeResult | string | undefined;
description: BundledMDX | undefined;
typeShorthand: ReactNode;
anchorIdParts: readonly string[];
route: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { APIV1Read } from "@fern-api/fdr-sdk";
import { visitDiscriminatedUnion } from "@fern-ui/core-utils";
import cn from "clsx";
import { MDXRemoteSerializeResult } from "next-mdx-remote";
import { Fragment, ReactNode } from "react";
import type { BundledMDX } from "../../mdx/types";
import {
ResolvedFormDataRequestProperty,
ResolvedRequestBody,
Expand Down Expand Up @@ -128,7 +128,7 @@ export const EndpointRequestSection: React.FC<EndpointRequestSection.Props> = ({
function getDescription(
bodyProperty: ResolvedFormDataRequestProperty.BodyProperty,
types: Record<string, ResolvedTypeDefinition>,
): string | MDXRemoteSerializeResult | undefined {
): BundledMDX | undefined {
if (bodyProperty.description != null) {
return bodyProperty.description;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/app/src/api-page/endpoints/EndpointSection.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FernButton, FernButtonGroup } from "@fern-ui/components";
import { MinusIcon, PlusIcon } from "@radix-ui/react-icons";
import type { MDXRemoteSerializeResult } from "next-mdx-remote";
import dynamic from "next/dynamic";
import { ReactNode, createElement, useRef } from "react";
import { AbsolutelyPositionedAnchor } from "../../commons/AbsolutelyPositionedAnchor";
import { FernErrorBoundary } from "../../components/FernErrorBoundary";
import type { BundledMDX } from "../../mdx/types";
import { getAnchorId } from "../../util/anchor";

const Markdown = dynamic(() => import("../../mdx/Markdown").then(({ Markdown }) => Markdown), {
Expand All @@ -15,7 +15,7 @@ export declare namespace EndpointSection {
export type Props = React.PropsWithChildren<{
headerType?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
title: ReactNode;
description?: MDXRemoteSerializeResult | string | undefined;
description?: BundledMDX | undefined;
anchorIdParts: readonly string[];
route: string;
expandAll?: () => void;
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/app/src/atoms/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface FeatureFlags {
useJavaScriptAsTypeScript: boolean;
alwaysEnableJavaScriptFetch: boolean;
scrollInContainerEnabled: boolean;
useMdxBundler: boolean;
}

export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
Expand All @@ -33,6 +34,7 @@ export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
useJavaScriptAsTypeScript: false,
alwaysEnableJavaScriptFetch: false,
scrollInContainerEnabled: false,
useMdxBundler: false,
};

export const FEATURE_FLAGS_ATOM = atom(DEFAULT_FEATURE_FLAGS);
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/app/src/atoms/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const RESOLVED_PATH_ATOM = atomWithReducer<ResolvedPath, ResolvedPath>(
type: "custom-markdown-page",
fullSlug: "",
title: "",
serializedMdxContent: "",
mdx: "",
neighbors: { prev: null, next: null },
apis: {},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/app/src/atoms/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export const SIDEBAR_DISMISSABLE_ATOM = atom((get) => {
}

const resolvedPath = get(RESOLVED_PATH_ATOM);
if (resolvedPath.type === "custom-markdown-page" && typeof resolvedPath.serializedMdxContent !== "string") {
const layout = resolvedPath.serializedMdxContent.frontmatter.layout;
if (resolvedPath.type === "custom-markdown-page" && typeof resolvedPath.mdx !== "string") {
const layout = resolvedPath.mdx.frontmatter.layout;

if (layout === "page" || layout === "custom") {
return true;
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/app/src/components/Chip.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FernTooltip } from "@fern-ui/components";
import { useCopyToClipboard } from "@fern-ui/react-commons";
import cn from "clsx";
import type { MDXRemoteSerializeResult } from "next-mdx-remote";
import { ReactElement } from "react";
import { Markdown } from "../mdx/Markdown";
import type { BundledMDX } from "../mdx/types";

type ChipProps = {
name: string;
description?: MDXRemoteSerializeResult | string | undefined;
description?: BundledMDX | undefined;
small?: boolean;
};

Expand Down
Loading

0 comments on commit 04e9d14

Please sign in to comment.