Skip to content
Closed
2 changes: 2 additions & 0 deletions knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ const config: KnipConfig = ({
ignoreDependencies: [/.*/],
},
'packages/docusaurus-plugin-content-blog': {
// Webpack loader, resolved with path.resolve(__dirname, ...)
entry: ['src/markdownLoader.ts!'],
// Knip doesn't detect imports in "declare module" blocks
ignoreDependencies: ['utility-types'],
},
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"main": "lib/index.js",
"types": "src/plugin-content-blog.d.ts",
"exports": {
"./lib/*": "./lib/*",
"./src/*": "./src/*",
"./client": {
"type": "./lib/client/index.d.ts",
"default": "./lib/client/index.js"
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"main": "lib/index.js",
"sideEffects": false,
"exports": {
"./lib/*": "./lib/*",
"./src/*": "./src/*",
"./client": {
"type": "./lib/client/index.d.ts",
"default": "./lib/client/index.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function findSidebarCategory(
* Best effort to assign a link to a sidebar category. If the category doesn't
* have a link itself, we link to the first sub item with a link.
*/
export function findFirstSidebarItemCategoryLink(
function findFirstSidebarItemCategoryLink(
item: PropSidebarItemCategory,
): string | undefined {
if (item.href && !item.linkUnlisted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ declare module '@docusaurus/plugin-content-docs' {
>
>;
export type SidebarsConfig = import('./sidebars/types').SidebarsConfig;
export type SidebarItemConfig = import('./sidebars/types').SidebarItemConfig;
export type SidebarItemCategoryConfig =
import('./sidebars/types').SidebarItemCategoryConfig;

export type VersionMetadata = ContentPaths & {
/** A name like `1.0.0`. Acquired from `versions.json`. */
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ type BuildAllRoutesParam = Omit<CreateAllRoutesParam, 'actions'> & {

// TODO we want this buildAllRoutes function to be easily testable
// Ideally, we should avoid side effects here (ie not injecting actions)
export async function buildAllRoutes(
async function buildAllRoutes(
param: BuildAllRoutesParam,
): Promise<RouteConfig[]> {
const subRoutes = await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function getLocalDocId(docId: string): string {
return _.last(docId.split('/'))!;
}

export const CategoryMetadataFilenameBase = '_category_';
export const CategoryMetadataFilenamePattern = '_category_.{json,yml,yaml}';

type WithPosition<T> = T & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {postProcessSidebars} from './postProcessor';
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
import type {SidebarsConfig, Sidebars, SidebarProcessorParams} from './types';

export const DefaultSidebars: SidebarsConfig = {
const DefaultSidebars: SidebarsConfig = {
defaultSidebar: [
{
type: 'autogenerated',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ function normalizeCategoriesShorthand(
* Normalizes recursively item and all its children. Ensures that at the end
* each item will be an object with the corresponding type.
*/
export function normalizeItem(
item: SidebarItemConfig,
): NormalizedSidebarItem[] {
function normalizeItem(item: SidebarItemConfig): NormalizedSidebarItem[] {
if (typeof item === 'string') {
return [{type: 'doc', id: item}];
}
Expand Down
17 changes: 14 additions & 3 deletions packages/docusaurus-plugin-content-docs/src/sidebars/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type SidebarItemCategoryBase = SidebarItemBase & {

export type SidebarItemCategoryLinkDoc = {type: 'doc'; id: string};

export type SidebarItemCategoryLinkGeneratedIndexConfig = {
type SidebarItemCategoryLinkGeneratedIndexConfig = {
type: 'generated-index';
slug?: string;
title?: string;
Expand Down Expand Up @@ -160,7 +160,7 @@ export type SidebarItemCategory = Expand<
}
>;

export type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;
type SidebarItemCategoryWithLink = Required<SidebarItemCategory, 'link'>;

export type SidebarItemCategoryWithGeneratedIndex =
SidebarItemCategoryWithLink & {link: SidebarItemCategoryLinkGeneratedIndex};
Expand All @@ -182,7 +182,12 @@ export type Sidebars = {
[sidebarId: string]: Sidebar;
};

// The Prop* types are public API: plugin-content-docs.d.ts re-exports them
// with import() types in a "declare module" block, which Knip doesn't follow.
// The @public tags prevent Knip from reporting them as unused exports.

// Doc links have been resolved to URLs, ready to be passed to the theme
/** @public */
export type PropSidebarItemCategory = Expand<
SidebarItemCategoryBase & {
items: PropSidebarItem[];
Expand All @@ -196,22 +201,28 @@ export type PropSidebarItemCategory = Expand<
}
>;

/** @public */
export type PropSidebarItemLink = SidebarItemLink & {
docId?: string;
unlisted?: boolean;
};

/** @public */
export type PropSidebarItemHtml = SidebarItemHtml;

/** @public */
export type PropSidebarItem =
| PropSidebarItemLink
| PropSidebarItemCategory
| PropSidebarItemHtml;
/** @public */
export type PropSidebar = PropSidebarItem[];
/** @public */
export type PropSidebars = {
[sidebarId: string]: PropSidebar;
};

/** @public */
export type PropSidebarBreadcrumbsItem =
| PropSidebarItemLink
| PropSidebarItemCategory;
Expand Down Expand Up @@ -250,7 +261,7 @@ export type SidebarItemsGeneratorVersion = Pick<
'versionName' | 'contentPath'
>;

export type SidebarItemsGeneratorArgs = {
type SidebarItemsGeneratorArgs = {
/** The sidebar item with type "autogenerated" to be transformed. */
item: SidebarItemAutogenerated;
/** Useful metadata for the version this sidebar belongs to. */
Expand Down
10 changes: 4 additions & 6 deletions packages/docusaurus-plugin-content-docs/src/sidebars/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function collectSidebarRefs(sidebar: Sidebar): SidebarItemDoc[] {
}

// /!\ docId order matters for navigation!
export function collectSidebarDocIds(sidebar: Sidebar): string[] {
function collectSidebarDocIds(sidebar: Sidebar): string[] {
return flattenSidebarItems(sidebar).flatMap((item) => {
if (item.type === 'category') {
return item.link?.type === 'doc' ? [item.link.id] : [];
Expand All @@ -98,9 +98,7 @@ export function collectSidebarDocIds(sidebar: Sidebar): string[] {
});
}

export function collectSidebarNavigation(
sidebar: Sidebar,
): SidebarNavigationItem[] {
function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[] {
return flattenSidebarItems(sidebar).flatMap((item) => {
if (item.type === 'category' && item.link) {
return [item as SidebarNavigationItem];
Expand All @@ -118,13 +116,13 @@ export function collectSidebarsDocIds(sidebars: Sidebars): {
return _.mapValues(sidebars, collectSidebarDocIds);
}

export function collectSidebarsNavigations(sidebars: Sidebars): {
function collectSidebarsNavigations(sidebars: Sidebars): {
[sidebarId: string]: SidebarNavigationItem[];
} {
return _.mapValues(sidebars, collectSidebarNavigation);
}

export type SidebarNavigation = {
type SidebarNavigation = {
sidebarName: string | undefined;
previous: SidebarNavigationItem | undefined;
next: SidebarNavigationItem | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function getVersionBadge({
return options.versions[versionName]?.badge ?? defaultVersionBadge;
}

export function getVersionNoIndex({
function getVersionNoIndex({
versionName,
options,
}: VersionContext): VersionMetadata['noIndex'] {
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-theme-live-codeblock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"lib/theme/Playground/*"
],
"exports": {
"./lib/*": "./lib/*",
"./src/*": "./src/*",
"./client": {
"type": "./lib/client/index.d.ts",
"default": "./lib/client/index.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const DEFAULT_CONFIG = {
playgroundPosition: 'bottom',
};

export const Schema = Joi.object<ThemeConfig>({
const Schema = Joi.object<ThemeConfig>({
liveCodeBlock: Joi.object({
playgroundPosition: Joi.string()
.equal('top', 'bottom')
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-theme-mermaid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"types": "src/theme-mermaid.d.ts",
"sideEffects": false,
"exports": {
"./lib/*": "./lib/*",
"./src/*": "./src/*",
"./client": {
"type": "./lib/client/index.d.ts",
"default": "./lib/client/index.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const DEFAULT_THEME_CONFIG: ThemeConfig = {
},
};

export const Schema = Joi.object<ThemeConfig>({
const Schema = Joi.object<ThemeConfig>({
mermaid: Joi.object({
theme: Joi.object({
dark: Joi.string().default(DEFAULT_THEME_CONFIG.mermaid.theme.dark),
Expand Down
4 changes: 2 additions & 2 deletions website/_dogfooding/docs-tests-sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

/**
* @typedef {import('@docusaurus/plugin-content-docs').SidebarsConfig} SidebarsConfig
* @typedef {import('@docusaurus/plugin-content-docs/lib/sidebars/types').SidebarItemConfig} SidebarItemConfig
* @typedef {import('@docusaurus/plugin-content-docs/lib/sidebars/types').SidebarItemCategoryConfig} SidebarItemCategoryConfig
* @typedef {import('@docusaurus/plugin-content-docs').SidebarItemConfig} SidebarItemConfig
* @typedef {import('@docusaurus/plugin-content-docs').SidebarItemCategoryConfig} SidebarItemCategoryConfig
*/

/** @type {SidebarsConfig} */
Expand Down
Loading