-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: transform javascript provider with files (#2073)
- Loading branch information
1 parent
c2d9a2b
commit d3cd611
Showing
6 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { DocsV1Read } from "@fern-api/fdr-sdk"; | ||
import type { JsConfig } from "@fern-docs/ui"; | ||
import { isEqual } from "es-toolkit/predicate"; | ||
import { selectAtom } from "jotai/utils"; | ||
import { DOCS_ATOM } from "./docs"; | ||
|
||
export const JS_ATOM = selectAtom(DOCS_ATOM, (docs) => docs.js, isEqual); | ||
|
||
export function withCustomJavascript( | ||
readShapeJsConfig: DocsV1Read.JsConfig | undefined, | ||
resolveFileSrc: (fileId: string) => { src: string } | undefined | ||
): JsConfig | undefined { | ||
const remote = [ | ||
...(readShapeJsConfig?.remote ?? []), | ||
...(readShapeJsConfig?.files ?? []).map((file) => ({ | ||
url: resolveFileSrc(file.fileId)?.src, | ||
strategy: file.strategy, | ||
})), | ||
].filter(isRemote); | ||
|
||
const toRet = { | ||
inline: readShapeJsConfig?.inline, | ||
remote: remote.length > 0 ? remote : undefined, | ||
}; | ||
|
||
if (!toRet.inline && !toRet.remote) { | ||
return undefined; | ||
} | ||
|
||
return toRet; | ||
} | ||
|
||
type RemoteJs = NonNullable<JsConfig["remote"]>[number]; | ||
|
||
function isRemote(remote: { | ||
url: string | undefined; // potentially undefined if the file is not found | ||
strategy: RemoteJs["strategy"]; | ||
}): remote is RemoteJs { | ||
return remote.url != null; | ||
} |
10 changes: 6 additions & 4 deletions
10
packages/fern-docs/ui/src/components/JavascriptProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters