Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync #1220

Merged
merged 12 commits into from
Jan 4, 2025
Merged

Sync #1220

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ content/docs/openapi/**/*.mdx

content/docs/ui/(integrations)/typescript.mdx
public/registry
!next-env.d.ts
22 changes: 0 additions & 22 deletions apps/docs/content/docs/headless/source-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,6 @@ const entries = source.getLanguages();
As mentioned, Source API doesn't rely on real file systems.
During the process, your input source files will be parsed and form a virtual storage to avoid inconsistent behaviour between different OS.

### Root Directory

Filter the input files by its parent directory.

```ts
import { loader } from 'fumadocs-core/source';

loader({
rootDir: 'test',
});
```

Content sources only provide **a virtual file path** to the loader (like `test/index.mdx`).
Relative paths such as `./` and `../` are not supported.

<Callout type='warn' title='Be Careful'>

This is not equivalent to your content directory configured on content source (e.g. Fumadocs MDX `dir` option).
Please use relevant options on your source instead.

</Callout>

### Transformer

To perform virtual file-system operations before processing, you can add a transformer.
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const source = loader({

export const blog = loader({
baseUrl: '/blog',
source: createMDXSource(blogPosts, []),
source: createMDXSource(blogPosts),
});

export const openapi = createOpenAPI({
Expand Down
22 changes: 11 additions & 11 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@radix-ui/react-popover": "^1.1.4",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.6",
"@shikijs/rehype": "^1.24.3",
"@shikijs/rehype": "^1.26.1",
"@theguild/remark-mermaid": "^0.2.0",
"babel-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
"class-variance-authority": "^0.7.1",
Expand All @@ -31,10 +31,10 @@
"fumadocs-ui": "workspace:*",
"geist": "^1.3.1",
"hast-util-to-jsx-runtime": "^2.3.2",
"katex": "^0.16.18",
"katex": "^0.16.19",
"lucide-react": "^0.469.0",
"next": "15.1.2",
"oxc-transform": "^0.43.0",
"next": "15.1.3",
"oxc-transform": "^0.44.0",
"phenomenon": "^1.6.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand All @@ -46,18 +46,18 @@
"remark-rehype": "^11.1.1",
"remark-stringify": "^11.0.0",
"scroll-into-view-if-needed": "^3.1.0",
"shiki": "^1.24.3",
"tailwind-merge": "^2.5.5",
"shiki": "^1.26.1",
"tailwind-merge": "^2.6.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@fumadocs/cli": "workspace:*",
"@next/bundle-analyzer": "15.1.2",
"@next/env": "15.1.2",
"@next/eslint-plugin-next": "15.1.2",
"@next/bundle-analyzer": "15.1.3",
"@next/env": "15.1.3",
"@next/eslint-plugin-next": "15.1.3",
"@types/hast": "^3.0.4",
"@types/mdx": "^2.0.13",
"@types/node": "22.10.2",
"@types/node": "22.10.5",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"autoprefixer": "^10.4.20",
Expand All @@ -68,7 +68,7 @@
"postcss": "^8.4.49",
"tailwindcss": "^3.4.17",
"tailwindcss-animate": "^1.0.7",
"ts-morph": "^24.0.0",
"ts-morph": "^25.0.0",
"tsconfig": "workspace:*",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/content-collections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@fumadocs/content-collections": "workspace:*",
"fumadocs-core": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^15.1.2",
"next": "^15.1.3",
"react": "19.0.0",
"react-dom": "19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "15.1.2",
"next": "15.1.3",
"react": "19.0.0",
"react-dom": "19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/next-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "15.1.2",
"next": "15.1.3",
"react": "19.0.0",
"react-dom": "19.0.0"
},
Expand Down
32 changes: 31 additions & 1 deletion examples/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@
"requestBody": {
"required": true,
"content": {
"application/json": {
"application/xml": {
"schema": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1235,6 +1235,36 @@
"trialEnds": "2023-06-16T17:16:37.161Z"
}
},
"parameters": {
"type": "object",
"required": ["media_input"],
"properties": {
"media_input": {
"oneOf": [
{
"title": "Image Media",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "image"
},
"url": {
"type": "string"
}
},
"required": ["type", "url"],
"examples": [
{
"type": "image",
"url": "https://example.com/image.png"
}
]
}
]
}
}
},
"roles": {
"type": "array",
"items": {
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"fumadocs-mdx": "workspace:*",
"fumadocs-openapi": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "15.1.2",
"next": "15.1.3",
"postcss": "^8.4.49",
"react": "19.0.0",
"react-dom": "19.0.0",
"shiki": "^1.24.3",
"shiki": "^1.26.1",
"tailwindcss": "^3.4.17",
"zod": "^3.24.1"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/remote-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@fumadocs/mdx-remote": "workspace:*",
"fumadocs-core": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "15.1.2",
"next": "15.1.3",
"react": "19.0.0",
"react-dom": "19.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
"@changesets/cli": "^2.27.11",
"@eslint/js": "^9.17.0",
"@types/eslint__js": "^8.42.3",
"concurrently": "^9.1.0",
"concurrently": "^9.1.2",
"eslint": "^9.17.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react": "^7.37.3",
"eslint-plugin-react-hooks": "5.1.0",
"eslint-plugin-tailwindcss": "^3.17.5",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"tsup": "8.3.5",
"turbo": "2.3.3",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.1",
"typescript-eslint": "^8.19.0",
"vitest": "^2.1.8"
},
"packageManager": "[email protected]",
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
},
"dependencies": {
"@clack/prompts": "^0.9.0",
"commander": "^12.1.0",
"commander": "^13.0.0",
"execa": "^9.5.2",
"package-manager-detector": "^0.2.8",
"picocolors": "^1.1.1",
"ts-morph": "^24.0.0"
"ts-morph": "^25.0.0"
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/node": "22.10.2",
"@types/node": "22.10.5",
"@types/react": "^19.0.2",
"eslint-config-custom": "workspace:*",
"fast-glob": "^3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/content-collections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"devDependencies": {
"@content-collections/core": "^0.8.0",
"@content-collections/mdx": "^0.2.0",
"@types/node": "22.10.2",
"@types/node": "22.10.5",
"eslint-config-custom": "workspace:*",
"fumadocs-core": "workspace:*",
"tsconfig": "workspace:*",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# next-docs-zeta

## 14.7.0

### Minor Changes

- 97ed36c: Remove defaults from `loader` and deprecate `rootDir` options

## 14.6.8

## 14.6.7
Expand Down
14 changes: 7 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fumadocs-core",
"version": "14.6.8",
"version": "14.7.0",
"description": "The library for building a documentation website in Next.js",
"keywords": [
"NextJs",
Expand Down Expand Up @@ -84,19 +84,19 @@
"types:check": "tsc --noEmit"
},
"dependencies": {
"@formatjs/intl-localematcher": "^0.5.9",
"@formatjs/intl-localematcher": "^0.5.10",
"@orama/orama": "^2.1.1",
"@shikijs/rehype": "^1.24.3",
"@shikijs/rehype": "^1.26.1",
"github-slugger": "^2.0.0",
"hast-util-to-estree": "^3.1.0",
"hast-util-to-jsx-runtime": "^2.3.2",
"image-size": "^1.1.1",
"image-size": "^1.2.0",
"negotiator": "^1.0.0",
"react-remove-scroll": "^2.6.2",
"remark": "^15.0.0",
"remark-gfm": "^4.0.0",
"scroll-into-view-if-needed": "^3.1.0",
"shiki": "^1.24.3",
"shiki": "^1.26.1",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
Expand All @@ -107,14 +107,14 @@
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.3",
"@types/negotiator": "^0.6.3",
"@types/node": "22.10.2",
"@types/node": "22.10.5",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"algoliasearch": "4.24.0",
"eslint-config-custom": "workspace:*",
"mdast-util-mdx-jsx": "^3.1.3",
"mdast-util-mdxjs-esm": "^2.0.1",
"next": "^15.1.2",
"next": "^15.1.3",
"remark-mdx": "^3.1.0",
"remark-rehype": "^11.1.1",
"shiki-transformers": "^1.0.1",
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/source/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ export interface SourceConfig {

export interface LoaderOptions {
/**
* @deprecated It is now recommended to filter files on `source` level
* @defaultValue `''`
*/
rootDir?: string;
/**
* @defaultValue `'/'`
*/
baseUrl?: string;

baseUrl: string;

icon?: NonNullable<BuildPageTreeOptions['resolveIcon']>;
slugs?: LoadOptions['getSlugs'];
Expand Down Expand Up @@ -216,13 +215,14 @@ export function loader<Options extends LoaderOptions>(
}

function createOutput(options: LoaderOptions): LoaderOutput<LoaderConfig> {
const {
source,
rootDir = '',
baseUrl = '/',
slugs: slugsFn = getSlugs,
url: getUrl = createGetUrl(baseUrl, options.i18n),
} = options;
if (!options.url && !options.baseUrl) {
console.warn('`loader()` now requires a `baseUrl` option to be defined.');
}

const { source, rootDir = '', slugs: slugsFn = getSlugs } = options;
const getUrl =
options.url ?? createGetUrl(options.baseUrl ?? '/', options.i18n);

const storage = loadFiles(
typeof source.files === 'function' ? source.files(rootDir) : source.files,
{
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/utils/merge-refs.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type * as React from 'react';

export function mergeRefs<T>(
...refs: (React.MutableRefObject<T> | React.LegacyRef<T>)[]
): React.RefCallback<T> {
export function mergeRefs<T>(...refs: React.Ref<T>[]): React.RefCallback<T> {
return (value) => {
refs.forEach((ref) => {
if (typeof ref === 'function') {
ref(value);
} else if (ref !== null) {
(ref as React.MutableRefObject<T | null>).current = value;
ref.current = value;
}
});
};
Expand Down
4 changes: 4 additions & 0 deletions packages/core/test/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ test('Get URL: Base', () => {

test('Loader: Simple', () => {
const result = loader({
baseUrl: '/',
pageTree: {
noRef: true,
},
Expand Down Expand Up @@ -91,6 +92,7 @@ test('Loader: Simple', () => {

test('Nested Directories', async () => {
const result = loader({
baseUrl: '/',
icon: (v) => v as unknown as ReactElement,
pageTree: {
noRef: true,
Expand Down Expand Up @@ -254,6 +256,7 @@ const i18nSource: Source<SourceConfig> = {

test('Internationalized Routing', () => {
const result = loader({
baseUrl: '/',
i18n: {
languages: ['cn', 'en'],
defaultLanguage: 'en',
Expand Down Expand Up @@ -344,6 +347,7 @@ test('Internationalized Routing', () => {

test('Internationalized Routing: Hide Prefix', () => {
const result = loader({
baseUrl: '/',
i18n: {
languages: ['cn', 'en'],
defaultLanguage: 'en',
Expand Down
Loading
Loading