mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-13 01:08:09 +02:00
refactor: ensure all types are using index signature instead of Record (#6995)
* refactor: ensure all types are using index signature instead of Record * kick CI
This commit is contained in:
parent
e8800b9d49
commit
87592bca03
99 changed files with 339 additions and 307 deletions
.eslintrc.js
admin/new.docusaurus.io/functionUtils
jest
packages
create-docusaurus/src
docusaurus-mdx-loader/src
docusaurus-migrate/src
docusaurus-module-type-aliases/src
docusaurus-plugin-client-redirects/src
docusaurus-plugin-content-blog/src
docusaurus-plugin-content-docs/src
__tests__
categoryGeneratedIndex.tsclient
deps.d.tsdocs.tsfrontMatter.tsglobalData.tsindex.tsplugin-content-docs.d.tssidebars
translations.tstypes.tsdocusaurus-plugin-content-pages/src
docusaurus-plugin-debug/src/theme/DebugContent
docusaurus-plugin-google-gtag/src
docusaurus-plugin-ideal-image/src
docusaurus-remark-plugin-npm2yarn/src/__tests__
docusaurus-theme-classic/src
docusaurus-theme-common/src
docusaurus-theme-search-algolia/src
docusaurus-theme-translations
docusaurus-types/src
docusaurus-utils-validation/src
docusaurus-utils/src
docusaurus/src
choosePort.ts
client
commands
deps.d.tsserver
webpack
lqip-loader/src
website
docs
src
versioned_docs
|
@ -269,6 +269,10 @@ module.exports = {
|
||||||
ERROR,
|
ERROR,
|
||||||
{'ts-expect-error': 'allow-with-description'},
|
{'ts-expect-error': 'allow-with-description'},
|
||||||
],
|
],
|
||||||
|
'@typescript-eslint/consistent-indexed-object-style': [
|
||||||
|
WARNING,
|
||||||
|
'index-signature',
|
||||||
|
],
|
||||||
'@typescript-eslint/consistent-type-imports': [
|
'@typescript-eslint/consistent-type-imports': [
|
||||||
WARNING,
|
WARNING,
|
||||||
{disallowTypeAnnotations: false},
|
{disallowTypeAnnotations: false},
|
||||||
|
|
|
@ -26,9 +26,11 @@ const PlaygroundDocumentationUrl = 'https://docusaurus.io/docs/playground';
|
||||||
export type PlaygroundName = keyof typeof PlaygroundConfigs;
|
export type PlaygroundName = keyof typeof PlaygroundConfigs;
|
||||||
|
|
||||||
function isValidPlaygroundName(
|
function isValidPlaygroundName(
|
||||||
playgroundName: string,
|
playgroundName: string | undefined,
|
||||||
): playgroundName is PlaygroundName {
|
): playgroundName is PlaygroundName {
|
||||||
return Object.keys(PlaygroundConfigs).includes(playgroundName);
|
return (
|
||||||
|
!!playgroundName && Object.keys(PlaygroundConfigs).includes(playgroundName)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPlaygroundDocumentationResponse(): HandlerResponse {
|
export function createPlaygroundDocumentationResponse(): HandlerResponse {
|
||||||
|
@ -54,10 +56,10 @@ export function createPlaygroundResponse(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inspired by https://stackoverflow.com/a/3409200/82609
|
// Inspired by https://stackoverflow.com/a/3409200/82609
|
||||||
function parseCookieString(cookieString: string): Record<string, string> {
|
function parseCookieString(cookieString: string): {[key: string]: string} {
|
||||||
const result: Record<string, string> = {};
|
const result: {[key: string]: string} = {};
|
||||||
cookieString.split(';').forEach((cookie) => {
|
cookieString.split(';').forEach((cookie) => {
|
||||||
const [name, value] = cookie.split('=');
|
const [name, value] = cookie.split('=') as [string, string];
|
||||||
result[name.trim()] = decodeURI(value);
|
result[name.trim()] = decodeURI(value);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
@ -66,7 +68,7 @@ function parseCookieString(cookieString: string): Record<string, string> {
|
||||||
export function readPlaygroundName(
|
export function readPlaygroundName(
|
||||||
event: HandlerEvent,
|
event: HandlerEvent,
|
||||||
): PlaygroundName | undefined {
|
): PlaygroundName | undefined {
|
||||||
const parsedCookie: Record<string, string> = event.headers.cookie
|
const parsedCookie: {[key: string]: string} = event.headers.cookie
|
||||||
? parseCookieString(event.headers.cookie)
|
? parseCookieString(event.headers.cookie)
|
||||||
: {};
|
: {};
|
||||||
const playgroundName: string | undefined = parsedCookie[CookieName];
|
const playgroundName: string | undefined = parsedCookie[CookieName];
|
||||||
|
|
4
jest/snapshotPathNormalizer.ts
vendored
4
jest/snapshotPathNormalizer.ts
vendored
|
@ -31,7 +31,7 @@ export function print(
|
||||||
});
|
});
|
||||||
return serialize(error);
|
return serialize(error);
|
||||||
} else if (val && typeof val === 'object') {
|
} else if (val && typeof val === 'object') {
|
||||||
const normalizedValue = _.cloneDeep(val) as Record<string, unknown>;
|
const normalizedValue = _.cloneDeep(val) as {[key: string]: unknown};
|
||||||
|
|
||||||
Object.keys(normalizedValue).forEach((key) => {
|
Object.keys(normalizedValue).forEach((key) => {
|
||||||
normalizedValue[key] = normalizePaths(normalizedValue[key]);
|
normalizedValue[key] = normalizePaths(normalizedValue[key]);
|
||||||
|
@ -46,7 +46,7 @@ export function test(val: unknown): boolean {
|
||||||
(typeof val === 'object' &&
|
(typeof val === 'object' &&
|
||||||
val &&
|
val &&
|
||||||
Object.keys(val).some((key) =>
|
Object.keys(val).some((key) =>
|
||||||
shouldUpdate((val as Record<string, unknown>)[key]),
|
shouldUpdate((val as {[key: string]: unknown})[key]),
|
||||||
)) ||
|
)) ||
|
||||||
// val.message is non-enumerable in an error
|
// val.message is non-enumerable in an error
|
||||||
(val instanceof Error && shouldUpdate(val.message)) ||
|
(val instanceof Error && shouldUpdate(val.message)) ||
|
||||||
|
|
|
@ -102,7 +102,7 @@ function isValidGitRepoUrl(gitRepoUrl: string) {
|
||||||
return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
|
return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updatePkg(pkgPath: string, obj: Record<string, unknown>) {
|
async function updatePkg(pkgPath: string, obj: {[key: string]: unknown}) {
|
||||||
const content = await fs.readFile(pkgPath, 'utf-8');
|
const content = await fs.readFile(pkgPath, 'utf-8');
|
||||||
const pkg = JSON.parse(content);
|
const pkg = JSON.parse(content);
|
||||||
const newPkg = Object.assign(pkg, obj);
|
const newPkg = Object.assign(pkg, obj);
|
||||||
|
|
|
@ -43,9 +43,9 @@ type Options = RemarkAndRehypePluginOptions & {
|
||||||
removeContentTitle?: boolean;
|
removeContentTitle?: boolean;
|
||||||
metadataPath?: string | ((filePath: string) => string);
|
metadataPath?: string | ((filePath: string) => string);
|
||||||
createAssets?: (metadata: {
|
createAssets?: (metadata: {
|
||||||
frontMatter: Record<string, unknown>;
|
frontMatter: {[key: string]: unknown};
|
||||||
metadata: Record<string, unknown>;
|
metadata: {[key: string]: unknown};
|
||||||
}) => Record<string, unknown>;
|
}) => {[key: string]: unknown};
|
||||||
filepath: string;
|
filepath: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ async function readMetadataPath(metadataPath: string) {
|
||||||
*
|
*
|
||||||
* `{image: "./myImage.png"}` => `{image: require("./myImage.png")}`
|
* `{image: "./myImage.png"}` => `{image: require("./myImage.png")}`
|
||||||
*/
|
*/
|
||||||
function createAssetsExportCode(assets: Record<string, unknown>) {
|
function createAssetsExportCode(assets: {[key: string]: unknown}) {
|
||||||
if (Object.keys(assets).length === 0) {
|
if (Object.keys(assets).length === 0) {
|
||||||
return 'undefined';
|
return 'undefined';
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import type {Plugin} from 'unified';
|
||||||
|
|
||||||
export type RemarkOrRehypePlugin =
|
export type RemarkOrRehypePlugin =
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
[Plugin<any[]>, Record<string, unknown>] | Plugin<any[]>;
|
[Plugin<any[]>, any] | Plugin<any[]>;
|
||||||
export type RemarkAndRehypePluginOptions = {
|
export type RemarkAndRehypePluginOptions = {
|
||||||
remarkPlugins: RemarkOrRehypePlugin[];
|
remarkPlugins: RemarkOrRehypePlugin[];
|
||||||
rehypePlugins: RemarkOrRehypePlugin[];
|
rehypePlugins: RemarkOrRehypePlugin[];
|
||||||
|
|
|
@ -67,7 +67,7 @@ ${
|
||||||
type MigrationContext = {
|
type MigrationContext = {
|
||||||
siteDir: string;
|
siteDir: string;
|
||||||
newDir: string;
|
newDir: string;
|
||||||
deps: Record<string, string>;
|
deps: {[key: string]: string};
|
||||||
shouldMigrateMdFiles: boolean;
|
shouldMigrateMdFiles: boolean;
|
||||||
shouldMigratePages: boolean;
|
shouldMigratePages: boolean;
|
||||||
v1Config: VersionOneConfig;
|
v1Config: VersionOneConfig;
|
||||||
|
@ -83,7 +83,7 @@ export async function migrateDocusaurusProject(
|
||||||
async function createMigrationContext(): Promise<MigrationContext> {
|
async function createMigrationContext(): Promise<MigrationContext> {
|
||||||
const v1Config = importFresh(`${siteDir}/siteConfig`) as VersionOneConfig;
|
const v1Config = importFresh(`${siteDir}/siteConfig`) as VersionOneConfig;
|
||||||
logger.info('Starting migration from v1 to v2...');
|
logger.info('Starting migration from v1 to v2...');
|
||||||
const deps: Record<string, string> = {
|
const deps = {
|
||||||
'@docusaurus/core': DOCUSAURUS_VERSION,
|
'@docusaurus/core': DOCUSAURUS_VERSION,
|
||||||
'@docusaurus/preset-classic': DOCUSAURUS_VERSION,
|
'@docusaurus/preset-classic': DOCUSAURUS_VERSION,
|
||||||
clsx: '^1.1.1',
|
clsx: '^1.1.1',
|
||||||
|
@ -206,7 +206,7 @@ export function createConfigFile({
|
||||||
'v1Config' | 'siteDir' | 'newDir'
|
'v1Config' | 'siteDir' | 'newDir'
|
||||||
>): VersionTwoConfig {
|
>): VersionTwoConfig {
|
||||||
const siteConfig = v1Config;
|
const siteConfig = v1Config;
|
||||||
const customConfigFields: Record<string, unknown> = {};
|
const customConfigFields: {[key: string]: unknown} = {};
|
||||||
// add fields that are unknown to v2 to customConfigFields
|
// add fields that are unknown to v2 to customConfigFields
|
||||||
Object.keys(siteConfig).forEach((key) => {
|
Object.keys(siteConfig).forEach((key) => {
|
||||||
const knownFields = [
|
const knownFields = [
|
||||||
|
@ -564,7 +564,7 @@ async function migrateVersionedSidebar(
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, Array<string | Record<string, unknown>>>);
|
}, {} as {[key: string]: Array<string | {[key: string]: unknown}>});
|
||||||
return topLevel;
|
return topLevel;
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
|
@ -702,9 +702,9 @@ async function migrateLatestDocs(context: MigrationContext) {
|
||||||
async function migratePackageFile(context: MigrationContext): Promise<void> {
|
async function migratePackageFile(context: MigrationContext): Promise<void> {
|
||||||
const {deps, siteDir, newDir} = context;
|
const {deps, siteDir, newDir} = context;
|
||||||
const packageFile = importFresh(`${siteDir}/package.json`) as {
|
const packageFile = importFresh(`${siteDir}/package.json`) as {
|
||||||
scripts?: Record<string, string>;
|
scripts?: {[key: string]: string};
|
||||||
dependencies?: Record<string, string>;
|
dependencies?: {[key: string]: string};
|
||||||
devDependencies?: Record<string, string>;
|
devDependencies?: {[key: string]: string};
|
||||||
[otherKey: string]: unknown;
|
[otherKey: string]: unknown;
|
||||||
};
|
};
|
||||||
packageFile.scripts = {
|
packageFile.scripts = {
|
||||||
|
|
|
@ -33,8 +33,8 @@ export type SidebarEntry =
|
||||||
|
|
||||||
export type SidebarEntries = {
|
export type SidebarEntries = {
|
||||||
[key: string]:
|
[key: string]:
|
||||||
| Record<string, unknown>
|
| {[key: string]: unknown}
|
||||||
| Array<Record<string, unknown> | string>;
|
| Array<{[key: string]: unknown} | string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface VersionTwoConfig {
|
export interface VersionTwoConfig {
|
||||||
|
@ -58,7 +58,7 @@ export interface VersionTwoConfig {
|
||||||
logo?: {
|
logo?: {
|
||||||
src?: string;
|
src?: string;
|
||||||
};
|
};
|
||||||
items: Array<Record<string, unknown> | null>;
|
items: Array<{[key: string]: unknown} | null>;
|
||||||
};
|
};
|
||||||
image?: string;
|
image?: string;
|
||||||
footer: {
|
footer: {
|
||||||
|
@ -74,7 +74,7 @@ export interface VersionTwoConfig {
|
||||||
src?: string;
|
src?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
algolia?: Record<string, unknown>;
|
algolia?: {[key: string]: unknown};
|
||||||
};
|
};
|
||||||
customFields: {
|
customFields: {
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
|
@ -111,16 +111,16 @@ export type VersionOneConfig = {
|
||||||
copyright?: string;
|
copyright?: string;
|
||||||
editUrl?: string;
|
editUrl?: string;
|
||||||
customDocsPath?: string;
|
customDocsPath?: string;
|
||||||
users?: Array<Record<string, unknown>>;
|
users?: Array<{[key: string]: unknown}>;
|
||||||
disableHeaderTitle?: string;
|
disableHeaderTitle?: string;
|
||||||
disableTitleTagline?: string;
|
disableTitleTagline?: string;
|
||||||
separateCss?: Array<Record<string, unknown>>;
|
separateCss?: Array<{[key: string]: unknown}>;
|
||||||
footerIcon?: string;
|
footerIcon?: string;
|
||||||
translationRecruitingLink?: string;
|
translationRecruitingLink?: string;
|
||||||
algolia?: Record<string, unknown>;
|
algolia?: {[key: string]: unknown};
|
||||||
gaTrackingId?: string;
|
gaTrackingId?: string;
|
||||||
gaGtag?: boolean;
|
gaGtag?: boolean;
|
||||||
highlight?: Record<string, unknown>;
|
highlight?: {[key: string]: unknown};
|
||||||
markdownPlugins?: Array<() => void>;
|
markdownPlugins?: Array<() => void>;
|
||||||
scripts?: Array<{src: string; [key: string]: unknown} | string>;
|
scripts?: Array<{src: string; [key: string]: unknown} | string>;
|
||||||
stylesheets?: Array<{href: string; [key: string]: unknown} | string>;
|
stylesheets?: Array<{href: string; [key: string]: unknown} | string>;
|
||||||
|
@ -133,5 +133,5 @@ export type VersionOneConfig = {
|
||||||
ogImage?: string;
|
ogImage?: string;
|
||||||
cleanUrl?: boolean;
|
cleanUrl?: boolean;
|
||||||
scrollToTop?: boolean;
|
scrollToTop?: boolean;
|
||||||
scrollToTopOptions?: Record<string, unknown>;
|
scrollToTopOptions?: {[key: string]: unknown};
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,13 +44,14 @@ declare module '@generated/routes' {
|
||||||
declare module '@generated/routesChunkNames' {
|
declare module '@generated/routesChunkNames' {
|
||||||
import type {RouteChunksTree} from '@docusaurus/types';
|
import type {RouteChunksTree} from '@docusaurus/types';
|
||||||
|
|
||||||
const routesChunkNames: Record<string, RouteChunksTree>;
|
const routesChunkNames: {[route: string]: RouteChunksTree};
|
||||||
export = routesChunkNames;
|
export = routesChunkNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@generated/globalData' {
|
declare module '@generated/globalData' {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
import type {GlobalData} from '@docusaurus/types';
|
||||||
const globalData: Record<string, any>;
|
|
||||||
|
const globalData: GlobalData;
|
||||||
export = globalData;
|
export = globalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,20 +60,19 @@ declare module '@generated/i18n' {
|
||||||
defaultLocale: string;
|
defaultLocale: string;
|
||||||
locales: [string, ...string[]];
|
locales: [string, ...string[]];
|
||||||
currentLocale: string;
|
currentLocale: string;
|
||||||
localeConfigs: Record<
|
localeConfigs: {
|
||||||
string,
|
[localeName: string]: {
|
||||||
{
|
|
||||||
label: string;
|
label: string;
|
||||||
direction: string;
|
direction: string;
|
||||||
htmlLang: string;
|
htmlLang: string;
|
||||||
}
|
};
|
||||||
>;
|
};
|
||||||
};
|
};
|
||||||
export = i18n;
|
export = i18n;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@generated/codeTranslations' {
|
declare module '@generated/codeTranslations' {
|
||||||
const codeTranslations: Record<string, string>;
|
const codeTranslations: {[msgId: string]: string};
|
||||||
export = codeTranslations;
|
export = codeTranslations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,10 +172,9 @@ declare module '@docusaurus/Interpolate' {
|
||||||
? Key | ExtractInterpolatePlaceholders<Rest>
|
? Key | ExtractInterpolatePlaceholders<Rest>
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
export type InterpolateValues<
|
export type InterpolateValues<Str extends string, Value extends ReactNode> = {
|
||||||
Str extends string,
|
[key in ExtractInterpolatePlaceholders<Str>]: Value;
|
||||||
Value extends ReactNode,
|
};
|
||||||
> = Record<ExtractInterpolatePlaceholders<Str>, Value>;
|
|
||||||
|
|
||||||
// If all the values are plain strings, interpolate returns a simple string
|
// If all the values are plain strings, interpolate returns a simple string
|
||||||
export function interpolate<Str extends string>(
|
export function interpolate<Str extends string>(
|
||||||
|
@ -320,17 +319,18 @@ declare module '@docusaurus/renderRoutes' {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@docusaurus/useGlobalData' {
|
declare module '@docusaurus/useGlobalData' {
|
||||||
export function useAllPluginInstancesData<T = unknown>(
|
import type {GlobalData} from '@docusaurus/types';
|
||||||
pluginName: string,
|
|
||||||
): Record<string, T>;
|
|
||||||
|
|
||||||
export function usePluginData<T = unknown>(
|
export function useAllPluginInstancesData(
|
||||||
|
pluginName: string,
|
||||||
|
): GlobalData[string];
|
||||||
|
|
||||||
|
export function usePluginData(
|
||||||
pluginName: string,
|
pluginName: string,
|
||||||
pluginId?: string,
|
pluginId?: string,
|
||||||
): T;
|
): GlobalData[string][string];
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
export default function useGlobalData(): GlobalData;
|
||||||
export default function useGlobalData(): Record<string, any>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '*.svg' {
|
declare module '*.svg' {
|
||||||
|
|
|
@ -13,7 +13,7 @@ const getCompiledRedirectPageTemplate = _.memoize(() =>
|
||||||
eta.compile(redirectPageTemplate.trim()),
|
eta.compile(redirectPageTemplate.trim()),
|
||||||
);
|
);
|
||||||
|
|
||||||
function renderRedirectPageTemplate(data: Record<string, unknown>) {
|
function renderRedirectPageTemplate(data: {toUrl: string}) {
|
||||||
const compiled = getCompiledRedirectPageTemplate();
|
const compiled = getCompiledRedirectPageTemplate();
|
||||||
return compiled(data, eta.defaultConfig);
|
return compiled(data, eta.defaultConfig);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,11 @@ function testField(params: {
|
||||||
fieldName: keyof BlogPostFrontMatter;
|
fieldName: keyof BlogPostFrontMatter;
|
||||||
validFrontMatters: BlogPostFrontMatter[];
|
validFrontMatters: BlogPostFrontMatter[];
|
||||||
convertibleFrontMatter?: [
|
convertibleFrontMatter?: [
|
||||||
ConvertibleFrontMatter: Record<string, unknown>,
|
ConvertibleFrontMatter: {[key: string]: unknown},
|
||||||
ConvertedFrontMatter: BlogPostFrontMatter,
|
ConvertedFrontMatter: BlogPostFrontMatter,
|
||||||
][];
|
][];
|
||||||
invalidFrontMatters?: [
|
invalidFrontMatters?: [
|
||||||
InvalidFrontMatter: Record<string, unknown>,
|
InvalidFrontMatter: {[key: string]: unknown},
|
||||||
ErrorMessage: string,
|
ErrorMessage: string,
|
||||||
][];
|
][];
|
||||||
}) {
|
}) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ import type {
|
||||||
BlogPostFrontMatterAuthors,
|
BlogPostFrontMatterAuthors,
|
||||||
} from '@docusaurus/plugin-content-blog';
|
} from '@docusaurus/plugin-content-blog';
|
||||||
|
|
||||||
export type AuthorsMap = Record<string, Author>;
|
export type AuthorsMap = {[authorKey: string]: Author};
|
||||||
|
|
||||||
const AuthorsMapSchema = Joi.object<AuthorsMap>()
|
const AuthorsMapSchema = Joi.object<AuthorsMap>()
|
||||||
.pattern(
|
.pattern(
|
||||||
|
|
|
@ -43,9 +43,9 @@ export function truncate(fileString: string, truncateMarker: RegExp): string {
|
||||||
return fileString.split(truncateMarker, 1).shift()!;
|
return fileString.split(truncateMarker, 1).shift()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSourceToPermalink(
|
export function getSourceToPermalink(blogPosts: BlogPost[]): {
|
||||||
blogPosts: BlogPost[],
|
[aliasedPath: string]: string;
|
||||||
): Record<string, string> {
|
} {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
blogPosts.map(({metadata: {source, permalink}}) => [source, permalink]),
|
blogPosts.map(({metadata: {source, permalink}}) => [source, permalink]),
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare module 'remark-admonitions' {
|
declare module 'remark-admonitions' {
|
||||||
type Options = Record<string, unknown>;
|
type Options = {[key: string]: unknown};
|
||||||
|
|
||||||
const plugin: (options?: Options) => void;
|
const plugin: (options?: Options) => void;
|
||||||
export = plugin;
|
export = plugin;
|
||||||
|
|
|
@ -74,8 +74,8 @@ const BlogFrontMatterSchema = Joi.object<BlogPostFrontMatter>({
|
||||||
'{#label} blog frontMatter field is deprecated. Please use {#alternative} instead.',
|
'{#label} blog frontMatter field is deprecated. Please use {#alternative} instead.',
|
||||||
});
|
});
|
||||||
|
|
||||||
export function validateBlogPostFrontMatter(
|
export function validateBlogPostFrontMatter(frontMatter: {
|
||||||
frontMatter: Record<string, unknown>,
|
[key: string]: unknown;
|
||||||
): BlogPostFrontMatter {
|
}): BlogPostFrontMatter {
|
||||||
return validateFrontMatter(frontMatter, BlogFrontMatterSchema);
|
return validateFrontMatter(frontMatter, BlogFrontMatterSchema);
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ export default async function pluginContentBlog(
|
||||||
blogTagsListPath,
|
blogTagsListPath,
|
||||||
} = blogContents;
|
} = blogContents;
|
||||||
|
|
||||||
const blogItemsToMetadata: Record<string, BlogPostMetadata> = {};
|
const blogItemsToMetadata: {[postId: string]: BlogPostMetadata} = {};
|
||||||
|
|
||||||
const sidebarBlogPosts =
|
const sidebarBlogPosts =
|
||||||
options.blogSidebarCount === 'ALL'
|
options.blogSidebarCount === 'ALL'
|
||||||
|
@ -316,7 +316,7 @@ export default async function pluginContentBlog(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagsModule: Record<string, TagModule> = Object.fromEntries(
|
const tagsModule: {[tagName: string]: TagModule} = Object.fromEntries(
|
||||||
Object.entries(blogTags).map(([, tag]) => {
|
Object.entries(blogTags).map(([, tag]) => {
|
||||||
const tagModule: TagModule = {
|
const tagModule: TagModule = {
|
||||||
allTagsPath: blogTagsListPath,
|
allTagsPath: blogTagsListPath,
|
||||||
|
|
|
@ -232,7 +232,7 @@ declare module '@docusaurus/plugin-content-blog' {
|
||||||
/**
|
/**
|
||||||
* Front matter, as-is.
|
* Front matter, as-is.
|
||||||
*/
|
*/
|
||||||
readonly frontMatter: BlogPostFrontMatter & Record<string, unknown>;
|
readonly frontMatter: BlogPostFrontMatter & {[key: string]: unknown};
|
||||||
/**
|
/**
|
||||||
* Tags, normalized.
|
* Tags, normalized.
|
||||||
*/
|
*/
|
||||||
|
@ -301,7 +301,7 @@ declare module '@docusaurus/plugin-content-blog' {
|
||||||
/** Markdown content. */
|
/** Markdown content. */
|
||||||
content: string;
|
content: string;
|
||||||
/** Front matter. */
|
/** Front matter. */
|
||||||
frontMatter?: BlogPostFrontMatter & Record<string, unknown>;
|
frontMatter?: BlogPostFrontMatter & {[key: string]: unknown};
|
||||||
/** Options accepted by ngryman/reading-time. */
|
/** Options accepted by ngryman/reading-time. */
|
||||||
options?: ReadingTimeOptions;
|
options?: ReadingTimeOptions;
|
||||||
}) => number;
|
}) => number;
|
||||||
|
@ -402,7 +402,7 @@ declare module '@docusaurus/plugin-content-blog' {
|
||||||
* unlocalized file. Ignored when `editUrl` is a function.
|
* unlocalized file. Ignored when `editUrl` is a function.
|
||||||
*/
|
*/
|
||||||
editLocalizedFiles?: boolean;
|
editLocalizedFiles?: boolean;
|
||||||
admonitions: Record<string, unknown>;
|
admonitions: {[key: string]: unknown};
|
||||||
/** Path to the authors map file, relative to the blog content directory. */
|
/** Path to the authors map file, relative to the blog content directory. */
|
||||||
authorsMapPath: string;
|
authorsMapPath: string;
|
||||||
/** A callback to customize the reading time number displayed. */
|
/** A callback to customize the reading time number displayed. */
|
||||||
|
@ -545,7 +545,7 @@ declare module '@theme/BlogTagsListPage' {
|
||||||
/** Blog sidebar. */
|
/** Blog sidebar. */
|
||||||
readonly sidebar: BlogSidebar;
|
readonly sidebar: BlogSidebar;
|
||||||
/** A map from tag names to the full tag module. */
|
/** A map from tag names to the full tag module. */
|
||||||
readonly tags: Readonly<Record<string, TagModule>>;
|
readonly tags: Readonly<{[tagName: string]: TagModule}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function BlogTagsListPage(props: Props): JSX.Element;
|
export default function BlogTagsListPage(props: Props): JSX.Element;
|
||||||
|
|
|
@ -50,6 +50,6 @@ export type BlogMarkdownLoaderOptions = {
|
||||||
siteDir: string;
|
siteDir: string;
|
||||||
contentPaths: BlogContentPaths;
|
contentPaths: BlogContentPaths;
|
||||||
truncateMarker: RegExp;
|
truncateMarker: RegExp;
|
||||||
sourceToPermalink: Record<string, string>;
|
sourceToPermalink: {[aliasedPath: string]: string};
|
||||||
onBrokenMarkdownLink: (brokenMarkdownLink: BlogBrokenMarkdownLink) => void;
|
onBrokenMarkdownLink: (brokenMarkdownLink: BlogBrokenMarkdownLink) => void;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1535,10 +1535,6 @@ exports[`site with custom sidebar items generator sidebarItemsGenerator is calle
|
||||||
"type": "autogenerated",
|
"type": "autogenerated",
|
||||||
},
|
},
|
||||||
"numberPrefixParser": [Function],
|
"numberPrefixParser": [Function],
|
||||||
"options": {
|
|
||||||
"sidebarCollapsed": true,
|
|
||||||
"sidebarCollapsible": true,
|
|
||||||
},
|
|
||||||
"version": {
|
"version": {
|
||||||
"contentPath": "docs",
|
"contentPath": "docs",
|
||||||
"versionName": "current",
|
"versionName": "current",
|
||||||
|
|
|
@ -43,7 +43,7 @@ const createFakeDocFile = ({
|
||||||
markdown = 'some markdown content',
|
markdown = 'some markdown content',
|
||||||
}: {
|
}: {
|
||||||
source: string;
|
source: string;
|
||||||
frontMatter?: Record<string, string>;
|
frontMatter?: {[key: string]: string};
|
||||||
markdown?: string;
|
markdown?: string;
|
||||||
}): DocFile => {
|
}): DocFile => {
|
||||||
const content = `---
|
const content = `---
|
||||||
|
|
|
@ -13,11 +13,11 @@ function testField(params: {
|
||||||
prefix: string;
|
prefix: string;
|
||||||
validFrontMatters: DocFrontMatter[];
|
validFrontMatters: DocFrontMatter[];
|
||||||
convertibleFrontMatter?: [
|
convertibleFrontMatter?: [
|
||||||
ConvertibleFrontMatter: Record<string, unknown>,
|
ConvertibleFrontMatter: {[key: string]: unknown},
|
||||||
ConvertedFrontMatter: DocFrontMatter,
|
ConvertedFrontMatter: DocFrontMatter,
|
||||||
][];
|
][];
|
||||||
invalidFrontMatters?: [
|
invalidFrontMatters?: [
|
||||||
InvalidFrontMatter: Record<string, unknown>,
|
InvalidFrontMatter: {[key: string]: unknown},
|
||||||
ErrorMessage: string,
|
ErrorMessage: string,
|
||||||
][];
|
][];
|
||||||
}) {
|
}) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ Available ids are:\n- ${version.docs.map((d) => d.unversionedId).join('\n- ')}`,
|
||||||
|
|
||||||
const createFakeActions = (contentDir: string) => {
|
const createFakeActions = (contentDir: string) => {
|
||||||
const routeConfigs: RouteConfig[] = [];
|
const routeConfigs: RouteConfig[] = [];
|
||||||
const dataContainer: Record<string, unknown> = {};
|
const dataContainer: {[key: string]: unknown} = {};
|
||||||
const globalDataContainer: {pluginName?: {pluginId: unknown}} = {};
|
const globalDataContainer: {pluginName?: {pluginId: unknown}} = {};
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
|
|
|
@ -17,7 +17,7 @@ function getCategoryGeneratedIndexMetadata({
|
||||||
}: {
|
}: {
|
||||||
category: SidebarItemCategoryWithGeneratedIndex;
|
category: SidebarItemCategoryWithGeneratedIndex;
|
||||||
sidebarsUtils: SidebarsUtils;
|
sidebarsUtils: SidebarsUtils;
|
||||||
docsById: Record<string, DocMetadataBase>;
|
docsById: {[docId: string]: DocMetadataBase};
|
||||||
}): CategoryGeneratedIndexMetadata {
|
}): CategoryGeneratedIndexMetadata {
|
||||||
const {sidebarName, previous, next} =
|
const {sidebarName, previous, next} =
|
||||||
sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import _ from 'lodash';
|
||||||
|
|
||||||
describe('docsClientUtils', () => {
|
describe('docsClientUtils', () => {
|
||||||
it('getActivePlugin', () => {
|
it('getActivePlugin', () => {
|
||||||
const data: Record<string, GlobalPluginData> = {
|
const data: {[key: string]: GlobalPluginData} = {
|
||||||
pluginIosId: {
|
pluginIosId: {
|
||||||
path: '/ios',
|
path: '/ios',
|
||||||
versions: [],
|
versions: [],
|
||||||
|
|
|
@ -23,11 +23,11 @@ import type {
|
||||||
// ie the docs of that plugin are currently browsed
|
// ie the docs of that plugin are currently browsed
|
||||||
// it is useful to support multiple docs plugin instances
|
// it is useful to support multiple docs plugin instances
|
||||||
export function getActivePlugin(
|
export function getActivePlugin(
|
||||||
allPluginDatas: Record<string, GlobalPluginData>,
|
allPluginData: {[pluginId: string]: GlobalPluginData},
|
||||||
pathname: string,
|
pathname: string,
|
||||||
options: GetActivePluginOptions = {},
|
options: GetActivePluginOptions = {},
|
||||||
): ActivePlugin | undefined {
|
): ActivePlugin | undefined {
|
||||||
const activeEntry = Object.entries(allPluginDatas)
|
const activeEntry = Object.entries(allPluginData)
|
||||||
// Route sorting: '/android/foo' should match '/android' instead of '/'
|
// Route sorting: '/android/foo' should match '/android' instead of '/'
|
||||||
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
.sort((a, b) => b[1].path.localeCompare(a[1].path))
|
||||||
.find(
|
.find(
|
||||||
|
@ -46,7 +46,7 @@ export function getActivePlugin(
|
||||||
if (!activePlugin && options.failfast) {
|
if (!activePlugin && options.failfast) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Can't find active docs plugin for "${pathname}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(
|
`Can't find active docs plugin for "${pathname}" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: ${Object.values(
|
||||||
allPluginDatas,
|
allPluginData,
|
||||||
)
|
)
|
||||||
.map((plugin) => plugin.path)
|
.map((plugin) => plugin.path)
|
||||||
.join(', ')}`,
|
.join(', ')}`,
|
||||||
|
|
|
@ -31,7 +31,7 @@ const StableEmptyObject = {};
|
||||||
// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks
|
// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks
|
||||||
// are still used by the theme. We need a fail-safe fallback when the docs
|
// are still used by the theme. We need a fail-safe fallback when the docs
|
||||||
// plugin is not in use
|
// plugin is not in use
|
||||||
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
export const useAllDocsData = (): {[pluginId: string]: GlobalPluginData} =>
|
||||||
useGlobalData()['docusaurus-plugin-content-docs'] ?? StableEmptyObject;
|
useGlobalData()['docusaurus-plugin-content-docs'] ?? StableEmptyObject;
|
||||||
|
|
||||||
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare module 'remark-admonitions' {
|
declare module 'remark-admonitions' {
|
||||||
type Options = Record<string, unknown>;
|
type Options = {[key: string]: unknown};
|
||||||
|
|
||||||
const plugin: (options?: Options) => void;
|
const plugin: (options?: Options) => void;
|
||||||
export = plugin;
|
export = plugin;
|
||||||
|
|
|
@ -424,7 +424,7 @@ export function getDocIds(doc: DocMetadataBase): [string, string] {
|
||||||
// to "id")
|
// to "id")
|
||||||
export function createDocsByIdIndex<
|
export function createDocsByIdIndex<
|
||||||
Doc extends {id: string; unversionedId: string},
|
Doc extends {id: string; unversionedId: string},
|
||||||
>(docs: Doc[]): Record<string, Doc> {
|
>(docs: Doc[]): {[docId: string]: Doc} {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
docs.flatMap((doc) => [
|
docs.flatMap((doc) => [
|
||||||
[doc.unversionedId, doc],
|
[doc.unversionedId, doc],
|
||||||
|
|
|
@ -41,8 +41,8 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
|
||||||
...FrontMatterTOCHeadingLevels,
|
...FrontMatterTOCHeadingLevels,
|
||||||
}).unknown();
|
}).unknown();
|
||||||
|
|
||||||
export function validateDocFrontMatter(
|
export function validateDocFrontMatter(frontMatter: {
|
||||||
frontMatter: Record<string, unknown>,
|
[key: string]: unknown;
|
||||||
): DocFrontMatter {
|
}): DocFrontMatter {
|
||||||
return validateFrontMatter(frontMatter, DocFrontMatterSchema);
|
return validateFrontMatter(frontMatter, DocFrontMatterSchema);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ function toGlobalDataGeneratedIndex(
|
||||||
function toGlobalSidebars(
|
function toGlobalSidebars(
|
||||||
sidebars: Sidebars,
|
sidebars: Sidebars,
|
||||||
version: LoadedVersion,
|
version: LoadedVersion,
|
||||||
): Record<string, GlobalSidebar> {
|
): {[sidebarId: string]: GlobalSidebar} {
|
||||||
const {getFirstLink} = createSidebarsUtils(sidebars);
|
const {getFirstLink} = createSidebarsUtils(sidebars);
|
||||||
return _.mapValues(sidebars, (sidebar, sidebarId) => {
|
return _.mapValues(sidebars, (sidebar, sidebarId) => {
|
||||||
const firstLink = getFirstLink(sidebarId);
|
const firstLink = getFirstLink(sidebarId);
|
||||||
|
|
|
@ -56,7 +56,6 @@ import type {
|
||||||
PropTagsListPage,
|
PropTagsListPage,
|
||||||
PluginOptions,
|
PluginOptions,
|
||||||
} from '@docusaurus/plugin-content-docs';
|
} from '@docusaurus/plugin-content-docs';
|
||||||
import type {GlobalPluginData} from '@docusaurus/plugin-content-docs/client';
|
|
||||||
import {createSidebarsUtils} from './sidebars/utils';
|
import {createSidebarsUtils} from './sidebars/utils';
|
||||||
import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
|
import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
|
||||||
|
|
||||||
|
@ -293,7 +292,7 @@ export default async function pluginContentDocs(
|
||||||
// TODO tags should be a sub route of the version route
|
// TODO tags should be a sub route of the version route
|
||||||
await Promise.all(loadedVersions.map(createVersionTagsRoutes));
|
await Promise.all(loadedVersions.map(createVersionTagsRoutes));
|
||||||
|
|
||||||
setGlobalData<GlobalPluginData>({
|
setGlobalData({
|
||||||
path: normalizeUrl([baseUrl, options.routeBasePath]),
|
path: normalizeUrl([baseUrl, options.routeBasePath]),
|
||||||
versions: loadedVersions.map(toGlobalDataVersion),
|
versions: loadedVersions.map(toGlobalDataVersion),
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
|
|
|
@ -68,7 +68,7 @@ declare module '@docusaurus/plugin-content-docs' {
|
||||||
};
|
};
|
||||||
export type VersionsOptions = {
|
export type VersionsOptions = {
|
||||||
lastVersion?: string;
|
lastVersion?: string;
|
||||||
versions: Record<string, VersionOptions>;
|
versions: {[versionName: string]: VersionOptions};
|
||||||
onlyIncludeVersions?: string[];
|
onlyIncludeVersions?: string[];
|
||||||
};
|
};
|
||||||
export type SidebarOptions = {
|
export type SidebarOptions = {
|
||||||
|
@ -89,7 +89,7 @@ declare module '@docusaurus/plugin-content-docs' {
|
||||||
docTagDocListComponent: string;
|
docTagDocListComponent: string;
|
||||||
docTagsListComponent: string;
|
docTagsListComponent: string;
|
||||||
docCategoryGeneratedIndexComponent: string;
|
docCategoryGeneratedIndexComponent: string;
|
||||||
admonitions: Record<string, unknown>;
|
admonitions: {[key: string]: unknown};
|
||||||
disableVersioning: boolean;
|
disableVersioning: boolean;
|
||||||
includeCurrentVersion: boolean;
|
includeCurrentVersion: boolean;
|
||||||
sidebarItemsGenerator: import('./sidebars/types').SidebarItemsGeneratorOption;
|
sidebarItemsGenerator: import('./sidebars/types').SidebarItemsGeneratorOption;
|
||||||
|
@ -282,7 +282,7 @@ declare module '@docusaurus/plugin-content-docs/client' {
|
||||||
export type ActiveDocContext = {
|
export type ActiveDocContext = {
|
||||||
activeVersion?: GlobalVersion;
|
activeVersion?: GlobalVersion;
|
||||||
activeDoc?: GlobalDoc;
|
activeDoc?: GlobalDoc;
|
||||||
alternateDocVersions: Record<string, GlobalDoc>;
|
alternateDocVersions: {[versionName: string]: GlobalDoc};
|
||||||
};
|
};
|
||||||
export type GlobalDoc = {
|
export type GlobalDoc = {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -297,7 +297,7 @@ declare module '@docusaurus/plugin-content-docs/client' {
|
||||||
path: string;
|
path: string;
|
||||||
mainDocId: string; // home doc (if docs homepage configured), or first doc
|
mainDocId: string; // home doc (if docs homepage configured), or first doc
|
||||||
docs: GlobalDoc[];
|
docs: GlobalDoc[];
|
||||||
sidebars?: Record<string, GlobalSidebar>;
|
sidebars?: {[sidebarId: string]: GlobalSidebar};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GlobalSidebarLink = {
|
export type GlobalSidebarLink = {
|
||||||
|
@ -322,7 +322,7 @@ declare module '@docusaurus/plugin-content-docs/client' {
|
||||||
};
|
};
|
||||||
export type GetActivePluginOptions = {failfast?: boolean}; // use fail-fast option if you know for sure one plugin instance is active
|
export type GetActivePluginOptions = {failfast?: boolean}; // use fail-fast option if you know for sure one plugin instance is active
|
||||||
|
|
||||||
export const useAllDocsData: () => Record<string, GlobalPluginData>;
|
export const useAllDocsData: () => {[pluginId: string]: GlobalPluginData};
|
||||||
export const useDocsData: (pluginId?: string) => GlobalPluginData;
|
export const useDocsData: (pluginId?: string) => GlobalPluginData;
|
||||||
export const useActivePlugin: (
|
export const useActivePlugin: (
|
||||||
options?: GetActivePluginOptions,
|
options?: GetActivePluginOptions,
|
||||||
|
|
|
@ -57,7 +57,7 @@ describe('processSidebars', () => {
|
||||||
|
|
||||||
async function testProcessSidebars(
|
async function testProcessSidebars(
|
||||||
unprocessedSidebars: NormalizedSidebars,
|
unprocessedSidebars: NormalizedSidebars,
|
||||||
categoriesMetadata: Record<string, CategoryMetadataFile> = {},
|
categoriesMetadata: {[filePath: string]: CategoryMetadataFile} = {},
|
||||||
paramsOverrides: Partial<SidebarProcessorParams> = {},
|
paramsOverrides: Partial<SidebarProcessorParams> = {},
|
||||||
) {
|
) {
|
||||||
return processSidebars(unprocessedSidebars, categoriesMetadata, {
|
return processSidebars(unprocessedSidebars, categoriesMetadata, {
|
||||||
|
@ -142,7 +142,6 @@ describe('processSidebars', () => {
|
||||||
},
|
},
|
||||||
numberPrefixParser: DefaultNumberPrefixParser,
|
numberPrefixParser: DefaultNumberPrefixParser,
|
||||||
isCategoryIndex,
|
isCategoryIndex,
|
||||||
options: params.sidebarOptions,
|
|
||||||
});
|
});
|
||||||
expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
|
expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
|
||||||
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
||||||
|
@ -154,7 +153,6 @@ describe('processSidebars', () => {
|
||||||
},
|
},
|
||||||
numberPrefixParser: DefaultNumberPrefixParser,
|
numberPrefixParser: DefaultNumberPrefixParser,
|
||||||
isCategoryIndex,
|
isCategoryIndex,
|
||||||
options: params.sidebarOptions,
|
|
||||||
});
|
});
|
||||||
expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
|
expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
|
||||||
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
||||||
|
@ -166,7 +164,6 @@ describe('processSidebars', () => {
|
||||||
},
|
},
|
||||||
numberPrefixParser: DefaultNumberPrefixParser,
|
numberPrefixParser: DefaultNumberPrefixParser,
|
||||||
isCategoryIndex,
|
isCategoryIndex,
|
||||||
options: params.sidebarOptions,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(processedSidebar).toEqual({
|
expect(processedSidebar).toEqual({
|
||||||
|
|
|
@ -680,7 +680,7 @@ describe('toNavigationLink', () => {
|
||||||
return {...data, frontMatter: {}} as DocMetadataBase;
|
return {...data, frontMatter: {}} as DocMetadataBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
const docsById: Record<string, DocMetadataBase> = {
|
const docsById: {[docId: string]: DocMetadataBase} = {
|
||||||
doc1: testDoc({
|
doc1: testDoc({
|
||||||
title: 'Doc 1',
|
title: 'Doc 1',
|
||||||
permalink: '/doc1',
|
permalink: '/doc1',
|
||||||
|
|
|
@ -48,16 +48,10 @@ function toSidebarItemsGeneratorVersion(
|
||||||
// post-processing checks
|
// post-processing checks
|
||||||
async function processSidebar(
|
async function processSidebar(
|
||||||
unprocessedSidebar: NormalizedSidebar,
|
unprocessedSidebar: NormalizedSidebar,
|
||||||
categoriesMetadata: Record<string, CategoryMetadataFile>,
|
categoriesMetadata: {[filePath: string]: CategoryMetadataFile},
|
||||||
params: SidebarProcessorParams,
|
params: SidebarProcessorParams,
|
||||||
): Promise<ProcessedSidebar> {
|
): Promise<ProcessedSidebar> {
|
||||||
const {
|
const {sidebarItemsGenerator, numberPrefixParser, docs, version} = params;
|
||||||
sidebarItemsGenerator,
|
|
||||||
numberPrefixParser,
|
|
||||||
docs,
|
|
||||||
version,
|
|
||||||
sidebarOptions,
|
|
||||||
} = params;
|
|
||||||
|
|
||||||
// Just a minor lazy transformation optimization
|
// Just a minor lazy transformation optimization
|
||||||
const getSidebarItemsGeneratorDocsAndVersion = _.memoize(() => ({
|
const getSidebarItemsGeneratorDocsAndVersion = _.memoize(() => ({
|
||||||
|
@ -74,7 +68,6 @@ async function processSidebar(
|
||||||
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
||||||
isCategoryIndex,
|
isCategoryIndex,
|
||||||
...getSidebarItemsGeneratorDocsAndVersion(),
|
...getSidebarItemsGeneratorDocsAndVersion(),
|
||||||
options: sidebarOptions,
|
|
||||||
categoriesMetadata,
|
categoriesMetadata,
|
||||||
});
|
});
|
||||||
// Process again... weird but sidebar item generated might generate some
|
// Process again... weird but sidebar item generated might generate some
|
||||||
|
@ -113,7 +106,7 @@ async function processSidebar(
|
||||||
|
|
||||||
export async function processSidebars(
|
export async function processSidebars(
|
||||||
unprocessedSidebars: NormalizedSidebars,
|
unprocessedSidebars: NormalizedSidebars,
|
||||||
categoriesMetadata: Record<string, CategoryMetadataFile>,
|
categoriesMetadata: {[filePath: string]: CategoryMetadataFile},
|
||||||
params: SidebarProcessorParams,
|
params: SidebarProcessorParams,
|
||||||
): Promise<ProcessedSidebars> {
|
): Promise<ProcessedSidebars> {
|
||||||
const processedSidebars = await combinePromises(
|
const processedSidebars = await combinePromises(
|
||||||
|
|
|
@ -15,11 +15,11 @@ import type {
|
||||||
import type {Slugger} from '@docusaurus/utils';
|
import type {Slugger} from '@docusaurus/utils';
|
||||||
|
|
||||||
// Makes all properties visible when hovering over the type
|
// Makes all properties visible when hovering over the type
|
||||||
type Expand<T extends Record<string, unknown>> = {[P in keyof T]: T[P]};
|
type Expand<T extends {[x: string]: unknown}> = {[P in keyof T]: T[P]};
|
||||||
|
|
||||||
export type SidebarItemBase = {
|
export type SidebarItemBase = {
|
||||||
className?: string;
|
className?: string;
|
||||||
customProps?: Record<string, unknown>;
|
customProps?: {[key: string]: unknown};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SidebarItemDoc = SidebarItemBase & {
|
export type SidebarItemDoc = SidebarItemBase & {
|
||||||
|
@ -216,7 +216,7 @@ export type CategoryMetadataFile = {
|
||||||
collapsible?: boolean;
|
collapsible?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
link?: SidebarItemCategoryLinkConfig | null;
|
link?: SidebarItemCategoryLinkConfig | null;
|
||||||
customProps?: Record<string, unknown>;
|
customProps?: {[key: string]: unknown};
|
||||||
|
|
||||||
// TODO should we allow "items" here? how would this work? would an
|
// TODO should we allow "items" here? how would this work? would an
|
||||||
// "autogenerated" type be allowed?
|
// "autogenerated" type be allowed?
|
||||||
|
@ -247,8 +247,7 @@ export type SidebarItemsGeneratorArgs = {
|
||||||
docs: SidebarItemsGeneratorDoc[];
|
docs: SidebarItemsGeneratorDoc[];
|
||||||
numberPrefixParser: NumberPrefixParser;
|
numberPrefixParser: NumberPrefixParser;
|
||||||
isCategoryIndex: CategoryIndexMatcher;
|
isCategoryIndex: CategoryIndexMatcher;
|
||||||
categoriesMetadata: Record<string, CategoryMetadataFile>;
|
categoriesMetadata: {[filePath: string]: CategoryMetadataFile};
|
||||||
options: SidebarOptions;
|
|
||||||
};
|
};
|
||||||
export type SidebarItemsGenerator = (
|
export type SidebarItemsGenerator = (
|
||||||
generatorArgs: SidebarItemsGeneratorArgs,
|
generatorArgs: SidebarItemsGeneratorArgs,
|
||||||
|
|
|
@ -107,15 +107,15 @@ export function collectSidebarNavigation(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collectSidebarsDocIds(
|
export function collectSidebarsDocIds(sidebars: Sidebars): {
|
||||||
sidebars: Sidebars,
|
[sidebarId: string]: string[];
|
||||||
): Record<string, string[]> {
|
} {
|
||||||
return _.mapValues(sidebars, collectSidebarDocIds);
|
return _.mapValues(sidebars, collectSidebarDocIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collectSidebarsNavigations(
|
export function collectSidebarsNavigations(sidebars: Sidebars): {
|
||||||
sidebars: Sidebars,
|
[sidebarId: string]: SidebarNavigationItem[];
|
||||||
): Record<string, SidebarNavigationItem[]> {
|
} {
|
||||||
return _.mapValues(sidebars, collectSidebarNavigation);
|
return _.mapValues(sidebars, collectSidebarNavigation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ export function toDocNavigationLink(doc: DocMetadataBase): DocNavLink {
|
||||||
|
|
||||||
export function toNavigationLink(
|
export function toNavigationLink(
|
||||||
navigationItem: SidebarNavigationItem | undefined,
|
navigationItem: SidebarNavigationItem | undefined,
|
||||||
docsById: Record<string, DocMetadataBase>,
|
docsById: {[docId: string]: DocMetadataBase},
|
||||||
): DocNavLink | undefined {
|
): DocNavLink | undefined {
|
||||||
function getDocById(docId: string) {
|
function getDocById(docId: string) {
|
||||||
const doc = docsById[docId];
|
const doc = docsById[docId];
|
||||||
|
|
|
@ -149,9 +149,9 @@ function validateSidebarItem(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateSidebars(
|
export function validateSidebars(sidebars: {
|
||||||
sidebars: Record<string, unknown>,
|
[sidebarId: string]: unknown;
|
||||||
): asserts sidebars is NormalizedSidebars {
|
}): asserts sidebars is NormalizedSidebars {
|
||||||
Object.values(sidebars as NormalizedSidebars).forEach((sidebar) => {
|
Object.values(sidebars as NormalizedSidebars).forEach((sidebar) => {
|
||||||
sidebar.forEach(validateSidebarItem);
|
sidebar.forEach(validateSidebarItem);
|
||||||
});
|
});
|
||||||
|
|
|
@ -269,7 +269,7 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
|
||||||
}
|
}
|
||||||
function translateVersion(
|
function translateVersion(
|
||||||
version: LoadedVersion,
|
version: LoadedVersion,
|
||||||
translationFiles: Record<string, TranslationFile>,
|
translationFiles: {[fileName: string]: TranslationFile},
|
||||||
): LoadedVersion {
|
): LoadedVersion {
|
||||||
const versionTranslations =
|
const versionTranslations =
|
||||||
translationFiles[getVersionFileName(version.versionName)]!.content;
|
translationFiles[getVersionFileName(version.versionName)]!.content;
|
||||||
|
@ -289,7 +289,7 @@ function getVersionsTranslationFiles(
|
||||||
}
|
}
|
||||||
function translateVersions(
|
function translateVersions(
|
||||||
versions: LoadedVersion[],
|
versions: LoadedVersion[],
|
||||||
translationFiles: Record<string, TranslationFile>,
|
translationFiles: {[fileName: string]: TranslationFile},
|
||||||
): LoadedVersion[] {
|
): LoadedVersion[] {
|
||||||
return versions.map((version) => translateVersion(version, translationFiles));
|
return versions.map((version) => translateVersion(version, translationFiles));
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ export function translateLoadedContent(
|
||||||
loadedContent: LoadedContent,
|
loadedContent: LoadedContent,
|
||||||
translationFiles: TranslationFile[],
|
translationFiles: TranslationFile[],
|
||||||
): LoadedContent {
|
): LoadedContent {
|
||||||
const translationFilesMap: Record<string, TranslationFile> = _.keyBy(
|
const translationFilesMap: {[fileName: string]: TranslationFile} = _.keyBy(
|
||||||
translationFiles,
|
translationFiles,
|
||||||
(f) => f.path,
|
(f) => f.path,
|
||||||
);
|
);
|
||||||
|
|
|
@ -59,7 +59,7 @@ export type DocFrontMatter = {
|
||||||
sidebar_label?: string;
|
sidebar_label?: string;
|
||||||
sidebar_position?: number;
|
sidebar_position?: number;
|
||||||
sidebar_class_name?: string;
|
sidebar_class_name?: string;
|
||||||
sidebar_custom_props?: Record<string, unknown>;
|
sidebar_custom_props?: {[key: string]: unknown};
|
||||||
displayed_sidebar?: string | null;
|
displayed_sidebar?: string | null;
|
||||||
pagination_label?: string;
|
pagination_label?: string;
|
||||||
custom_edit_url?: string | null;
|
custom_edit_url?: string | null;
|
||||||
|
@ -83,7 +83,7 @@ export type DocMetadataBase = LastUpdateData & {
|
||||||
sidebarPosition?: number;
|
sidebarPosition?: number;
|
||||||
editUrl?: string | null;
|
editUrl?: string | null;
|
||||||
tags: Tag[];
|
tags: Tag[];
|
||||||
frontMatter: DocFrontMatter & Record<string, unknown>;
|
frontMatter: DocFrontMatter & {[key: string]: unknown};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DocNavLink = {
|
export type DocNavLink = {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare module 'remark-admonitions' {
|
declare module 'remark-admonitions' {
|
||||||
type Options = Record<string, unknown>;
|
type Options = {[key: string]: unknown};
|
||||||
|
|
||||||
const plugin: (options?: Options) => void;
|
const plugin: (options?: Options) => void;
|
||||||
export = plugin;
|
export = plugin;
|
||||||
|
|
|
@ -20,8 +20,8 @@ const PageFrontMatterSchema = Joi.object<FrontMatter>({
|
||||||
...FrontMatterTOCHeadingLevels,
|
...FrontMatterTOCHeadingLevels,
|
||||||
});
|
});
|
||||||
|
|
||||||
export function validatePageFrontMatter(
|
export function validatePageFrontMatter(frontMatter: {
|
||||||
frontMatter: Record<string, unknown>,
|
[key: string]: unknown;
|
||||||
): FrontMatter {
|
}): FrontMatter {
|
||||||
return validateFrontMatter(frontMatter, PageFrontMatterSchema);
|
return validateFrontMatter(frontMatter, PageFrontMatterSchema);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ declare module '@docusaurus/plugin-content-pages' {
|
||||||
include: string[];
|
include: string[];
|
||||||
exclude: string[];
|
exclude: string[];
|
||||||
mdxPageComponent: string;
|
mdxPageComponent: string;
|
||||||
admonitions: Record<string, unknown>;
|
admonitions: {[key: string]: unknown};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Options = Partial<PluginOptions>;
|
export type Options = Partial<PluginOptions>;
|
||||||
|
@ -39,7 +39,7 @@ declare module '@docusaurus/plugin-content-pages' {
|
||||||
type: 'mdx';
|
type: 'mdx';
|
||||||
permalink: string;
|
permalink: string;
|
||||||
source: string;
|
source: string;
|
||||||
frontMatter: FrontMatter & Record<string, unknown>;
|
frontMatter: FrontMatter & {[key: string]: unknown};
|
||||||
title?: string;
|
title?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ function PluginContent({
|
||||||
pluginContent,
|
pluginContent,
|
||||||
}: {
|
}: {
|
||||||
pluginName: string;
|
pluginName: string;
|
||||||
pluginContent: Record<string, unknown>;
|
pluginContent: {[pluginId: string]: unknown};
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<section style={{marginBottom: 60}}>
|
<section style={{marginBottom: 60}}>
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default (function gtagModule() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {trackingID} = globalData['docusaurus-plugin-google-gtag']
|
const {trackingID} = globalData['docusaurus-plugin-google-gtag']!
|
||||||
.default as PluginOptions;
|
.default as PluginOptions;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -68,7 +68,7 @@ declare module '@endiliey/react-ideal-image' {
|
||||||
* from material design, Implemented as React components with the SVG
|
* from material design, Implemented as React components with the SVG
|
||||||
* element. You can customize icons
|
* element. You can customize icons
|
||||||
*/
|
*/
|
||||||
icons?: Partial<Record<IconKey, ComponentType>>;
|
icons?: Partial<{[icon in IconKey]: ComponentType}>;
|
||||||
/**
|
/**
|
||||||
* This prop takes one of the 2 options, xhr and image.
|
* This prop takes one of the 2 options, xhr and image.
|
||||||
* Read more about it:
|
* Read more about it:
|
||||||
|
@ -102,7 +102,7 @@ declare module '@endiliey/react-ideal-image' {
|
||||||
* inline styles, but it is also possible to use CSS modules and override
|
* inline styles, but it is also possible to use CSS modules and override
|
||||||
* all styles.
|
* all styles.
|
||||||
*/
|
*/
|
||||||
theme?: Partial<Record<ThemeKey, string | CSSProperties>>;
|
theme?: Partial<{[key in ThemeKey]: string | CSSProperties}>;
|
||||||
/**
|
/**
|
||||||
* Tells how much to wait in milliseconds until consider the download to be
|
* Tells how much to wait in milliseconds until consider the download to be
|
||||||
* slow.
|
* slow.
|
||||||
|
|
11
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/__fixtures__/sync.md
generated
Normal file
11
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/__fixtures__/sync.md
generated
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
```bash npm2yarn
|
||||||
|
npm install --global docusaurus
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash npm2yarn
|
||||||
|
npm install --save docusaurus-plugin-name
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash npm2yarn
|
||||||
|
npm run build
|
||||||
|
```
|
|
@ -48,6 +48,21 @@ import TabItem from '@theme/TabItem';
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`npm2yarn plugin does not work when language is not set 1`] = `
|
||||||
|
"\`\`\`npm2yarn
|
||||||
|
npm install --save docusaurus-plugin-name
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
\`\`\`bash
|
||||||
|
npm install --save docusaurus-plugin-name
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
\`\`\`shell
|
||||||
|
npm install --save docusaurus-plugin-name
|
||||||
|
\`\`\`
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`npm2yarn plugin works on installation file 1`] = `
|
exports[`npm2yarn plugin works on installation file 1`] = `
|
||||||
"import Tabs from '@theme/Tabs';
|
"import Tabs from '@theme/Tabs';
|
||||||
import TabItem from '@theme/TabItem';
|
import TabItem from '@theme/TabItem';
|
||||||
|
@ -98,17 +113,29 @@ yarn add docusaurus-plugin-name
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`npm2yarn plugin works when language is not set 1`] = `
|
exports[`npm2yarn plugin works with sync option 1`] = `
|
||||||
"\`\`\`npm2yarn
|
"import Tabs from '@theme/Tabs';
|
||||||
npm install --save docusaurus-plugin-name
|
import TabItem from '@theme/TabItem';
|
||||||
\`\`\`
|
|
||||||
|
## Installing a plugin
|
||||||
|
|
||||||
|
A plugin is usually a npm package, so you install them like other npm packages using npm.
|
||||||
|
|
||||||
|
<Tabs groupId=\\"npm2yarn\\">
|
||||||
|
<TabItem value=\\"npm\\">
|
||||||
|
|
||||||
\`\`\`bash
|
\`\`\`bash
|
||||||
npm install --save docusaurus-plugin-name
|
npm install --save docusaurus-plugin-name
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
\`\`\`shell
|
</TabItem>
|
||||||
npm install --save docusaurus-plugin-name
|
<TabItem value=\\"yarn\\" label=\\"Yarn\\">
|
||||||
|
|
||||||
|
\`\`\`bash
|
||||||
|
yarn add docusaurus-plugin-name
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -16,10 +16,7 @@ import mdx from 'remark-mdx';
|
||||||
const processFixture = async (name: string, options?: {sync?: boolean}) => {
|
const processFixture = async (name: string, options?: {sync?: boolean}) => {
|
||||||
const filePath = path.join(__dirname, '__fixtures__', `${name}.md`);
|
const filePath = path.join(__dirname, '__fixtures__', `${name}.md`);
|
||||||
const file = await vfile.read(filePath);
|
const file = await vfile.read(filePath);
|
||||||
const result = await remark()
|
const result = await remark().use(mdx).use(npm2yarn, options).process(file);
|
||||||
.use(mdx)
|
|
||||||
.use(npm2yarn, {...options, filePath})
|
|
||||||
.process(file);
|
|
||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
};
|
};
|
||||||
|
@ -37,7 +34,13 @@ describe('npm2yarn plugin', () => {
|
||||||
expect(result).toMatchSnapshot();
|
expect(result).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works when language is not set', async () => {
|
it('works with sync option', async () => {
|
||||||
|
const result = await processFixture('plugin', {sync: true});
|
||||||
|
|
||||||
|
expect(result).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not work when language is not set', async () => {
|
||||||
const result = await processFixture('syntax-not-properly-set');
|
const result = await processFixture('syntax-not-properly-set');
|
||||||
|
|
||||||
expect(result).toMatchSnapshot();
|
expect(result).toMatchSnapshot();
|
||||||
|
|
|
@ -12,14 +12,14 @@ import {normalizeThemeConfig} from '@docusaurus/utils-validation';
|
||||||
import theme from 'prism-react-renderer/themes/github';
|
import theme from 'prism-react-renderer/themes/github';
|
||||||
import darkTheme from 'prism-react-renderer/themes/dracula';
|
import darkTheme from 'prism-react-renderer/themes/dracula';
|
||||||
|
|
||||||
function testValidateThemeConfig(partialThemeConfig: Record<string, unknown>) {
|
function testValidateThemeConfig(partialThemeConfig: {[key: string]: unknown}) {
|
||||||
return normalizeThemeConfig(ThemeConfigSchema, {
|
return normalizeThemeConfig(ThemeConfigSchema, {
|
||||||
...DEFAULT_CONFIG,
|
...DEFAULT_CONFIG,
|
||||||
...partialThemeConfig,
|
...partialThemeConfig,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function testOk(partialThemeConfig: Record<string, unknown>) {
|
function testOk(partialThemeConfig: {[key: string]: unknown}) {
|
||||||
expect(
|
expect(
|
||||||
testValidateThemeConfig({...DEFAULT_CONFIG, ...partialThemeConfig}),
|
testValidateThemeConfig({...DEFAULT_CONFIG, ...partialThemeConfig}),
|
||||||
).toEqual({
|
).toEqual({
|
||||||
|
|
|
@ -507,7 +507,7 @@ declare module '@theme/MDXComponents' {
|
||||||
readonly h4: (props: ComponentProps<'h4'>) => JSX.Element;
|
readonly h4: (props: ComponentProps<'h4'>) => JSX.Element;
|
||||||
readonly h5: (props: ComponentProps<'h5'>) => JSX.Element;
|
readonly h5: (props: ComponentProps<'h5'>) => JSX.Element;
|
||||||
readonly h6: (props: ComponentProps<'h6'>) => JSX.Element;
|
readonly h6: (props: ComponentProps<'h6'>) => JSX.Element;
|
||||||
} & Record<string, ComponentType<unknown>>;
|
} & {[tagName: string]: ComponentType<unknown>};
|
||||||
|
|
||||||
const MDXComponents: MDXComponentsObject;
|
const MDXComponents: MDXComponentsObject;
|
||||||
export default MDXComponents;
|
export default MDXComponents;
|
||||||
|
@ -768,7 +768,7 @@ declare module '@theme/TabItem' {
|
||||||
readonly label?: string;
|
readonly label?: string;
|
||||||
readonly hidden?: boolean;
|
readonly hidden?: boolean;
|
||||||
readonly className?: string;
|
readonly className?: string;
|
||||||
readonly attributes?: Record<string, unknown>;
|
readonly attributes?: {[key: string]: unknown};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TabItem(props: Props): JSX.Element;
|
export default function TabItem(props: Props): JSX.Element;
|
||||||
|
@ -786,7 +786,7 @@ declare module '@theme/Tabs' {
|
||||||
readonly values?: readonly {
|
readonly values?: readonly {
|
||||||
value: string;
|
value: string;
|
||||||
label?: string;
|
label?: string;
|
||||||
attributes?: Record<string, unknown>;
|
attributes?: {[key: string]: unknown};
|
||||||
}[];
|
}[];
|
||||||
readonly groupId?: string;
|
readonly groupId?: string;
|
||||||
readonly className?: string;
|
readonly className?: string;
|
||||||
|
|
|
@ -70,10 +70,9 @@ function UnmaintainedVersionLabel({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const BannerLabelComponents: Record<
|
const BannerLabelComponents: {
|
||||||
VersionBanner,
|
[banner in VersionBanner]: ComponentType<BannerLabelComponentProps>;
|
||||||
ComponentType<BannerLabelComponentProps>
|
} = {
|
||||||
> = {
|
|
||||||
unreleased: UnreleasedVersionLabel,
|
unreleased: UnreleasedVersionLabel,
|
||||||
unmaintained: UnmaintainedVersionLabel,
|
unmaintained: UnmaintainedVersionLabel,
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
|
|
||||||
import React, {isValidElement} from 'react';
|
import React, {isValidElement} from 'react';
|
||||||
import CodeBlock from '@theme/CodeBlock';
|
import CodeBlock from '@theme/CodeBlock';
|
||||||
|
import type {Props} from '@theme/MDXComponents/Pre';
|
||||||
|
|
||||||
export default function MDXPre(props: any) {
|
export default function MDXPre(props: Props): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<CodeBlock
|
<CodeBlock
|
||||||
// If this pre is created by a ``` fenced codeblock, unwrap the children
|
// If this pre is created by a ``` fenced codeblock, unwrap the children
|
||||||
|
|
|
@ -14,12 +14,11 @@ import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem
|
||||||
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
||||||
import type {Types, Props} from '@theme/NavbarItem';
|
import type {Types, Props} from '@theme/NavbarItem';
|
||||||
|
|
||||||
const NavbarItemComponents: Record<
|
const NavbarItemComponents: {
|
||||||
Exclude<Types, undefined>,
|
|
||||||
// Not really worth typing, as we pass all props down immediately
|
// Not really worth typing, as we pass all props down immediately
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
() => (props: any) => JSX.Element
|
[type in Exclude<Types, undefined>]: () => (props: any) => JSX.Element;
|
||||||
> = {
|
} = {
|
||||||
default: () => DefaultNavbarItem,
|
default: () => DefaultNavbarItem,
|
||||||
localeDropdown: () => LocaleDropdownNavbarItem,
|
localeDropdown: () => LocaleDropdownNavbarItem,
|
||||||
search: () => SearchNavbarItem,
|
search: () => SearchNavbarItem,
|
||||||
|
|
|
@ -184,7 +184,7 @@ export function translateThemeConfig({
|
||||||
themeConfig: ThemeConfig;
|
themeConfig: ThemeConfig;
|
||||||
translationFiles: TranslationFile[];
|
translationFiles: TranslationFile[];
|
||||||
}): ThemeConfig {
|
}): ThemeConfig {
|
||||||
const translationFilesMap: Record<string, TranslationFile> = _.keyBy(
|
const translationFilesMap: {[fileName: string]: TranslationFile} = _.keyBy(
|
||||||
translationFiles,
|
translationFiles,
|
||||||
(f) => f.path,
|
(f) => f.path,
|
||||||
);
|
);
|
||||||
|
|
|
@ -84,7 +84,7 @@ function readStorageState({
|
||||||
}: {
|
}: {
|
||||||
pluginIds: string[];
|
pluginIds: string[];
|
||||||
versionPersistence: DocsVersionPersistence;
|
versionPersistence: DocsVersionPersistence;
|
||||||
allDocsData: Record<string, GlobalPluginData>;
|
allDocsData: {[pluginId: string]: GlobalPluginData};
|
||||||
}): DocsPreferredVersionState {
|
}): DocsPreferredVersionState {
|
||||||
/**
|
/**
|
||||||
* The storage value we read might be stale, and belong to a version that does
|
* The storage value we read might be stale, and belong to a version that does
|
||||||
|
@ -227,10 +227,9 @@ export function useDocsPreferredVersion(
|
||||||
return {preferredVersion, savePreferredVersionName};
|
return {preferredVersion, savePreferredVersionName};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useDocsPreferredVersionByPluginId(): Record<
|
export function useDocsPreferredVersionByPluginId(): {
|
||||||
string,
|
[pluginId: string]: GlobalVersion | null;
|
||||||
GlobalVersion | null
|
} {
|
||||||
> {
|
|
||||||
const allDocsData = useAllDocsData();
|
const allDocsData = useAllDocsData();
|
||||||
const [state] = useDocsPreferredVersionContext();
|
const [state] = useDocsPreferredVersionContext();
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ function useContextValue(): ContextValue {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
try {
|
try {
|
||||||
const localStorageChoices: Record<string, string> = {};
|
const localStorageChoices: {[groupId: string]: string} = {};
|
||||||
listStorageKeys().forEach((storageKey) => {
|
listStorageKeys().forEach((storageKey) => {
|
||||||
if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
|
if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
|
||||||
const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
|
const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
|
||||||
|
|
|
@ -33,11 +33,11 @@ function getTagLetter(tag: string): string {
|
||||||
export function listTagsByLetters(
|
export function listTagsByLetters(
|
||||||
tags: readonly TagsListItem[],
|
tags: readonly TagsListItem[],
|
||||||
): TagLetterEntry[] {
|
): TagLetterEntry[] {
|
||||||
const groups: Record<string, TagsListItem[]> = {};
|
const groups: {[initial: string]: TagsListItem[]} = {};
|
||||||
Object.values(tags).forEach((tag) => {
|
Object.values(tags).forEach((tag) => {
|
||||||
const letter = getTagLetter(tag.name);
|
const initial = getTagLetter(tag.name);
|
||||||
groups[letter] ??= [];
|
groups[initial] ??= [];
|
||||||
groups[letter]!.push(tag);
|
groups[initial]!.push(tag);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -17,7 +17,7 @@ export type NavbarItem = {
|
||||||
items?: NavbarItem[];
|
items?: NavbarItem[];
|
||||||
label?: string;
|
label?: string;
|
||||||
position?: 'left' | 'right';
|
position?: 'left' | 'right';
|
||||||
} & Record<string, unknown>;
|
} & {[key: string]: unknown};
|
||||||
|
|
||||||
export type NavbarLogo = {
|
export type NavbarLogo = {
|
||||||
src: string;
|
src: string;
|
||||||
|
@ -65,7 +65,7 @@ export type FooterLinkItem = {
|
||||||
href?: string;
|
href?: string;
|
||||||
html?: string;
|
html?: string;
|
||||||
prependBaseUrlToHref?: string;
|
prependBaseUrlToHref?: string;
|
||||||
} & Record<string, unknown>;
|
} & {[key: string]: unknown};
|
||||||
|
|
||||||
export type FooterLogo = {
|
export type FooterLogo = {
|
||||||
alt?: string;
|
alt?: string;
|
||||||
|
@ -119,7 +119,7 @@ export type ThemeConfig = {
|
||||||
hideableSidebar: boolean;
|
hideableSidebar: boolean;
|
||||||
autoCollapseSidebarCategories: boolean;
|
autoCollapseSidebarCategories: boolean;
|
||||||
image?: string;
|
image?: string;
|
||||||
metadata: Array<Record<string, string>>;
|
metadata: Array<{[key: string]: string}>;
|
||||||
sidebarCollapsible: boolean;
|
sidebarCollapsible: boolean;
|
||||||
tableOfContents: TableOfContents;
|
tableOfContents: TableOfContents;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
import type {Joi} from '@docusaurus/utils-validation';
|
import type {Joi} from '@docusaurus/utils-validation';
|
||||||
import {validateThemeConfig, DEFAULT_CONFIG} from '../validateThemeConfig';
|
import {validateThemeConfig, DEFAULT_CONFIG} from '../validateThemeConfig';
|
||||||
|
|
||||||
function testValidateThemeConfig(themeConfig: Record<string, unknown>) {
|
function testValidateThemeConfig(themeConfig: {[key: string]: unknown}) {
|
||||||
function validate(schema: Joi.Schema, cfg: Record<string, unknown>) {
|
function validate(schema: Joi.Schema, cfg: {[key: string]: unknown}) {
|
||||||
const {value, error} = schema.validate(cfg, {
|
const {value, error} = schema.validate(cfg, {
|
||||||
convert: false,
|
convert: false,
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,7 @@ declare module '@docusaurus/theme-search-algolia' {
|
||||||
appId: string;
|
appId: string;
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
indexName: string;
|
indexName: string;
|
||||||
searchParameters: Record<string, unknown>;
|
searchParameters: {[key: string]: unknown};
|
||||||
searchPagePath: string | false | null;
|
searchPagePath: string | false | null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,15 +54,16 @@ function useDocsSearchVersionsHelpers() {
|
||||||
|
|
||||||
// State of the version select menus / algolia facet filters
|
// State of the version select menus / algolia facet filters
|
||||||
// docsPluginId -> versionName map
|
// docsPluginId -> versionName map
|
||||||
const [searchVersions, setSearchVersions] = useState<Record<string, string>>(
|
const [searchVersions, setSearchVersions] = useState<{
|
||||||
() =>
|
[pluginId: string]: string;
|
||||||
Object.entries(allDocsData).reduce(
|
}>(() =>
|
||||||
(acc, [pluginId, pluginData]) => ({
|
Object.entries(allDocsData).reduce(
|
||||||
...acc,
|
(acc, [pluginId, pluginData]) => ({
|
||||||
[pluginId]: pluginData.versions[0]!.name,
|
...acc,
|
||||||
}),
|
[pluginId]: pluginData.versions[0]!.name,
|
||||||
{},
|
}),
|
||||||
),
|
{},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set the value of a single select menu
|
// Set the value of a single select menu
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe('theme translations', () => {
|
||||||
(await fs.readJSON(
|
(await fs.readJSON(
|
||||||
path.join(baseMessagesDirPath, baseMessagesFile),
|
path.join(baseMessagesDirPath, baseMessagesFile),
|
||||||
'utf-8',
|
'utf-8',
|
||||||
)) as Record<string, string>,
|
)) as {[key: string]: string},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
).then((translations) =>
|
).then((translations) =>
|
||||||
|
|
|
@ -39,7 +39,7 @@ export async function readDefaultCodeTranslationMessages({
|
||||||
dirPath?: string;
|
dirPath?: string;
|
||||||
locale: string;
|
locale: string;
|
||||||
name: string;
|
name: string;
|
||||||
}): Promise<Record<string, string>> {
|
}): Promise<{[msgId: string]: string}> {
|
||||||
const localesToTry = codeTranslationLocalesToTry(locale);
|
const localesToTry = codeTranslationLocalesToTry(locale);
|
||||||
|
|
||||||
// Return the content of the first file that match
|
// Return the content of the first file that match
|
||||||
|
|
43
packages/docusaurus-types/src/index.d.ts
vendored
43
packages/docusaurus-types/src/index.d.ts
vendored
|
@ -91,7 +91,7 @@ export type Config = Overwrite<
|
||||||
* package.json.
|
* package.json.
|
||||||
* - `type: 'synthetic'`, docusaurus generated internal plugin.
|
* - `type: 'synthetic'`, docusaurus generated internal plugin.
|
||||||
*/
|
*/
|
||||||
export type DocusaurusPluginVersionInformation =
|
export type PluginVersionInformation =
|
||||||
| {
|
| {
|
||||||
readonly type: 'package';
|
readonly type: 'package';
|
||||||
readonly name?: string;
|
readonly name?: string;
|
||||||
|
@ -104,7 +104,7 @@ export type DocusaurusPluginVersionInformation =
|
||||||
export interface DocusaurusSiteMetadata {
|
export interface DocusaurusSiteMetadata {
|
||||||
readonly docusaurusVersion: string;
|
readonly docusaurusVersion: string;
|
||||||
readonly siteVersion?: string;
|
readonly siteVersion?: string;
|
||||||
readonly pluginVersions: Record<string, DocusaurusPluginVersionInformation>;
|
readonly pluginVersions: {[pluginName: string]: PluginVersionInformation};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inspired by Chrome JSON, because it's a widely supported i18n format
|
// Inspired by Chrome JSON, because it's a widely supported i18n format
|
||||||
|
@ -114,7 +114,7 @@ export interface DocusaurusSiteMetadata {
|
||||||
// https://docs.transifex.com/formats/chrome-json
|
// https://docs.transifex.com/formats/chrome-json
|
||||||
// https://help.phrase.com/help/chrome-json-messages
|
// https://help.phrase.com/help/chrome-json-messages
|
||||||
export type TranslationMessage = {message: string; description?: string};
|
export type TranslationMessage = {message: string; description?: string};
|
||||||
export type TranslationFileContent = Record<string, TranslationMessage>;
|
export type TranslationFileContent = {[key: string]: TranslationMessage};
|
||||||
export type TranslationFile = {path: string; content: TranslationFileContent};
|
export type TranslationFile = {path: string; content: TranslationFileContent};
|
||||||
export type TranslationFiles = TranslationFile[];
|
export type TranslationFiles = TranslationFile[];
|
||||||
|
|
||||||
|
@ -127,22 +127,24 @@ export type I18nLocaleConfig = {
|
||||||
export type I18nConfig = {
|
export type I18nConfig = {
|
||||||
defaultLocale: string;
|
defaultLocale: string;
|
||||||
locales: [string, ...string[]];
|
locales: [string, ...string[]];
|
||||||
localeConfigs: Record<string, Partial<I18nLocaleConfig>>;
|
localeConfigs: {[locale: string]: Partial<I18nLocaleConfig>};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type I18n = {
|
export type I18n = {
|
||||||
defaultLocale: string;
|
defaultLocale: string;
|
||||||
locales: [string, ...string[]];
|
locales: [string, ...string[]];
|
||||||
currentLocale: string;
|
currentLocale: string;
|
||||||
localeConfigs: Record<string, I18nLocaleConfig>;
|
localeConfigs: {[locale: string]: I18nLocaleConfig};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type GlobalData = {[pluginName: string]: {[pluginId: string]: unknown}};
|
||||||
|
|
||||||
export interface DocusaurusContext {
|
export interface DocusaurusContext {
|
||||||
siteConfig: DocusaurusConfig;
|
siteConfig: DocusaurusConfig;
|
||||||
siteMetadata: DocusaurusSiteMetadata;
|
siteMetadata: DocusaurusSiteMetadata;
|
||||||
globalData: Record<string, unknown>;
|
globalData: GlobalData;
|
||||||
i18n: I18n;
|
i18n: I18n;
|
||||||
codeTranslations: Record<string, string>;
|
codeTranslations: {[msgId: string]: string};
|
||||||
|
|
||||||
// Don't put mutable values here, to avoid triggering re-renders
|
// Don't put mutable values here, to avoid triggering re-renders
|
||||||
// We could reconsider that choice if context selectors are implemented
|
// We could reconsider that choice if context selectors are implemented
|
||||||
|
@ -162,7 +164,7 @@ export type ImportedPresetModule = PresetModule & {
|
||||||
default?: PresetModule;
|
default?: PresetModule;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PresetConfig = string | [string, Record<string, unknown>];
|
export type PresetConfig = string | [string, {[key: string]: unknown}];
|
||||||
|
|
||||||
export type HostPortCLIOptions = {
|
export type HostPortCLIOptions = {
|
||||||
host?: string;
|
host?: string;
|
||||||
|
@ -207,7 +209,7 @@ export interface LoadContext {
|
||||||
baseUrl: string; // TODO to remove: useless, there's already siteConfig.baseUrl!
|
baseUrl: string; // TODO to remove: useless, there's already siteConfig.baseUrl!
|
||||||
i18n: I18n;
|
i18n: I18n;
|
||||||
ssrTemplate: string;
|
ssrTemplate: string;
|
||||||
codeTranslations: Record<string, string>;
|
codeTranslations: {[msgId: string]: string};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InjectedHtmlTags {
|
export interface InjectedHtmlTags {
|
||||||
|
@ -228,7 +230,7 @@ export interface Props extends LoadContext, InjectedHtmlTags {
|
||||||
export interface PluginContentLoadedActions {
|
export interface PluginContentLoadedActions {
|
||||||
addRoute: (config: RouteConfig) => void;
|
addRoute: (config: RouteConfig) => void;
|
||||||
createData: (name: string, data: string) => Promise<string>;
|
createData: (name: string, data: string) => Promise<string>;
|
||||||
setGlobalData: <T = unknown>(data: T) => void;
|
setGlobalData: (data: unknown) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AllContent = {
|
export type AllContent = {
|
||||||
|
@ -238,7 +240,7 @@ export type AllContent = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO improve type (not exposed by postcss-loader)
|
// TODO improve type (not exposed by postcss-loader)
|
||||||
export type PostCssOptions = Record<string, unknown> & {plugins: unknown[]};
|
export type PostCssOptions = {[key: string]: unknown} & {plugins: unknown[]};
|
||||||
|
|
||||||
export interface Plugin<Content = unknown> {
|
export interface Plugin<Content = unknown> {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -290,7 +292,7 @@ export interface Plugin<Content = unknown> {
|
||||||
|
|
||||||
export type InitializedPlugin<Content = unknown> = Plugin<Content> & {
|
export type InitializedPlugin<Content = unknown> = Plugin<Content> & {
|
||||||
readonly options: Required<PluginOptions>;
|
readonly options: Required<PluginOptions>;
|
||||||
readonly version: DocusaurusPluginVersionInformation;
|
readonly version: PluginVersionInformation;
|
||||||
/**
|
/**
|
||||||
* The absolute path to the folder containing the entry point file.
|
* The absolute path to the folder containing the entry point file.
|
||||||
*/
|
*/
|
||||||
|
@ -305,12 +307,12 @@ export type SwizzleAction = 'eject' | 'wrap';
|
||||||
export type SwizzleActionStatus = 'safe' | 'unsafe' | 'forbidden';
|
export type SwizzleActionStatus = 'safe' | 'unsafe' | 'forbidden';
|
||||||
|
|
||||||
export type SwizzleComponentConfig = {
|
export type SwizzleComponentConfig = {
|
||||||
actions: Record<SwizzleAction, SwizzleActionStatus>;
|
actions: {[action in SwizzleAction]: SwizzleActionStatus};
|
||||||
description?: string;
|
description?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SwizzleConfig = {
|
export type SwizzleConfig = {
|
||||||
components: Record<string, SwizzleComponentConfig>;
|
components: {[componentName: string]: SwizzleComponentConfig};
|
||||||
// Other settings could be added here,
|
// Other settings could be added here,
|
||||||
// For example: the ability to declare the config as exhaustive
|
// For example: the ability to declare the config as exhaustive
|
||||||
// so that we can emit errors
|
// so that we can emit errors
|
||||||
|
@ -332,13 +334,12 @@ export type ImportedPluginModule = PluginModule & {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ConfigureWebpackFn = Plugin<unknown>['configureWebpack'];
|
export type ConfigureWebpackFn = Plugin<unknown>['configureWebpack'];
|
||||||
export type ConfigureWebpackFnMergeStrategy = Record<
|
export type ConfigureWebpackFnMergeStrategy = {
|
||||||
string,
|
[key: string]: CustomizeRuleString;
|
||||||
CustomizeRuleString
|
};
|
||||||
>;
|
|
||||||
export type ConfigurePostCssFn = Plugin<unknown>['configurePostCss'];
|
export type ConfigurePostCssFn = Plugin<unknown>['configurePostCss'];
|
||||||
|
|
||||||
export type PluginOptions = {id?: string} & Record<string, unknown>;
|
export type PluginOptions = {id?: string} & {[key: string]: unknown};
|
||||||
|
|
||||||
export type PluginConfig =
|
export type PluginConfig =
|
||||||
| string
|
| string
|
||||||
|
@ -416,7 +417,7 @@ export interface ConfigureWebpackUtils {
|
||||||
) => RuleSetRule[];
|
) => RuleSetRule[];
|
||||||
getJSLoader: (options: {
|
getJSLoader: (options: {
|
||||||
isServer: boolean;
|
isServer: boolean;
|
||||||
babelOptions?: Record<string, unknown>;
|
babelOptions?: {[key: string]: unknown};
|
||||||
}) => RuleSetRule;
|
}) => RuleSetRule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,7 +426,7 @@ interface HtmlTagObject {
|
||||||
* Attributes of the html tag
|
* Attributes of the html tag
|
||||||
* E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
|
* E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}`
|
||||||
*/
|
*/
|
||||||
attributes?: Partial<Record<string, string | boolean>>;
|
attributes?: Partial<{[key: string]: string | boolean}>;
|
||||||
/**
|
/**
|
||||||
* The tag name e.g. `div`, `script`, `link`, `meta`
|
* The tag name e.g. `div`, `script`, `link`, `meta`
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -77,7 +77,7 @@ export function normalizeThemeConfig<T>(
|
||||||
* Validate front matter with better error message
|
* Validate front matter with better error message
|
||||||
*/
|
*/
|
||||||
export function validateFrontMatter<T>(
|
export function validateFrontMatter<T>(
|
||||||
frontMatter: Record<string, unknown>,
|
frontMatter: {[key: string]: unknown},
|
||||||
schema: Joi.ObjectSchema<T>,
|
schema: Joi.ObjectSchema<T>,
|
||||||
): T {
|
): T {
|
||||||
const {value, error, warning} = schema.validate(frontMatter, {
|
const {value, error, warning} = schema.validate(frontMatter, {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import fs from 'fs-extra';
|
||||||
|
|
||||||
describe('genChunkName', () => {
|
describe('genChunkName', () => {
|
||||||
it('works', () => {
|
it('works', () => {
|
||||||
const firstAssert: Record<string, string> = {
|
const firstAssert: {[key: string]: string} = {
|
||||||
'/docs/adding-blog': 'docs-adding-blog-062',
|
'/docs/adding-blog': 'docs-adding-blog-062',
|
||||||
'/docs/versioning': 'docs-versioning-8a8',
|
'/docs/versioning': 'docs-versioning-8a8',
|
||||||
'/': 'index',
|
'/': 'index',
|
||||||
|
@ -34,7 +34,7 @@ describe('genChunkName', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits different chunk names for different paths even with same preferred name', () => {
|
it('emits different chunk names for different paths even with same preferred name', () => {
|
||||||
const secondAssert: Record<string, string> = {
|
const secondAssert: {[key: string]: string} = {
|
||||||
'/blog/1': 'blog-85-f-089',
|
'/blog/1': 'blog-85-f-089',
|
||||||
'/blog/2': 'blog-353-489',
|
'/blog/2': 'blog-353-489',
|
||||||
};
|
};
|
||||||
|
@ -44,7 +44,7 @@ describe('genChunkName', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only generates short unique IDs', () => {
|
it('only generates short unique IDs', () => {
|
||||||
const thirdAssert: Record<string, string> = {
|
const thirdAssert: {[key: string]: string} = {
|
||||||
a: '0cc175b9',
|
a: '0cc175b9',
|
||||||
b: '92eb5ffe',
|
b: '92eb5ffe',
|
||||||
c: '4a8a08f0',
|
c: '4a8a08f0',
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {simpleHash, docuHash} from '../hashUtils';
|
||||||
|
|
||||||
describe('hashUtils', () => {
|
describe('hashUtils', () => {
|
||||||
it('simpleHash', () => {
|
it('simpleHash', () => {
|
||||||
const asserts: Record<string, string> = {
|
const asserts: {[key: string]: string} = {
|
||||||
'': 'd41',
|
'': 'd41',
|
||||||
'/foo-bar': '096',
|
'/foo-bar': '096',
|
||||||
'/foo/bar': '1df',
|
'/foo/bar': '1df',
|
||||||
|
@ -30,7 +30,7 @@ describe('hashUtils', () => {
|
||||||
|
|
||||||
describe('docuHash', () => {
|
describe('docuHash', () => {
|
||||||
it('docuHash works', () => {
|
it('docuHash works', () => {
|
||||||
const asserts: Record<string, string> = {
|
const asserts: {[key: string]: string} = {
|
||||||
'': '-d41',
|
'': '-d41',
|
||||||
'/': 'index',
|
'/': 'index',
|
||||||
'/foo-bar': 'foo-bar-096',
|
'/foo-bar': 'foo-bar-096',
|
||||||
|
|
|
@ -45,15 +45,15 @@ describe('mapAsyncSequential', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it('maps sequentially', async () => {
|
it('maps sequentially', async () => {
|
||||||
const itemToTimeout: Record<string, number> = {
|
const itemToTimeout: {[key: string]: number} = {
|
||||||
'1': 200,
|
'1': 200,
|
||||||
'2': 600,
|
'2': 600,
|
||||||
'3': 400,
|
'3': 400,
|
||||||
};
|
};
|
||||||
const items = Object.keys(itemToTimeout);
|
const items = Object.keys(itemToTimeout);
|
||||||
|
|
||||||
const itemMapStartsAt: Record<string, number> = {};
|
const itemMapStartsAt: {[key: string]: number} = {};
|
||||||
const itemMapEndsAt: Record<string, number> = {};
|
const itemMapEndsAt: {[key: string]: number} = {};
|
||||||
|
|
||||||
const timeBefore = Date.now();
|
const timeBefore = Date.now();
|
||||||
await expect(
|
await expect(
|
||||||
|
|
|
@ -131,7 +131,7 @@ describe('toMessageRelativeFilePath', () => {
|
||||||
|
|
||||||
describe('escapePath', () => {
|
describe('escapePath', () => {
|
||||||
it('works', () => {
|
it('works', () => {
|
||||||
const asserts: Record<string, string> = {
|
const asserts: {[key: string]: string} = {
|
||||||
'c:/aaaa\\bbbb': 'c:/aaaa\\\\bbbb',
|
'c:/aaaa\\bbbb': 'c:/aaaa\\\\bbbb',
|
||||||
'c:\\aaaa\\bbbb\\★': 'c:\\\\aaaa\\\\bbbb\\\\★',
|
'c:\\aaaa\\bbbb\\★': 'c:\\\\aaaa\\\\bbbb\\\\★',
|
||||||
'\\\\?\\c:\\aaaa\\bbbb': '\\\\\\\\?\\\\c:\\\\aaaa\\\\bbbb',
|
'\\\\?\\c:\\aaaa\\bbbb': '\\\\\\\\?\\\\c:\\\\aaaa\\\\bbbb',
|
||||||
|
@ -148,7 +148,7 @@ describe('escapePath', () => {
|
||||||
|
|
||||||
describe('posixPath', () => {
|
describe('posixPath', () => {
|
||||||
it('works', () => {
|
it('works', () => {
|
||||||
const asserts: Record<string, string> = {
|
const asserts: {[key: string]: string} = {
|
||||||
'c:/aaaa\\bbbb': 'c:/aaaa/bbbb',
|
'c:/aaaa\\bbbb': 'c:/aaaa/bbbb',
|
||||||
'c:\\aaaa\\bbbb\\★': 'c:\\aaaa\\bbbb\\★',
|
'c:\\aaaa\\bbbb\\★': 'c:\\aaaa\\bbbb\\★',
|
||||||
'\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb',
|
'\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb',
|
||||||
|
@ -165,7 +165,7 @@ describe('posixPath', () => {
|
||||||
|
|
||||||
describe('aliasedSitePath', () => {
|
describe('aliasedSitePath', () => {
|
||||||
it('works', () => {
|
it('works', () => {
|
||||||
const asserts: Record<string, string> = {
|
const asserts: {[key: string]: string} = {
|
||||||
'user/website/docs/asd.md': '@site/docs/asd.md',
|
'user/website/docs/asd.md': '@site/docs/asd.md',
|
||||||
'user/website/versioned_docs/foo/bar.md':
|
'user/website/versioned_docs/foo/bar.md':
|
||||||
'@site/versioned_docs/foo/bar.md',
|
'@site/versioned_docs/foo/bar.md',
|
||||||
|
|
|
@ -170,7 +170,7 @@ describe('getEditUrl', () => {
|
||||||
|
|
||||||
describe('fileToPath', () => {
|
describe('fileToPath', () => {
|
||||||
it('works', () => {
|
it('works', () => {
|
||||||
const asserts: Record<string, string> = {
|
const asserts: {[key: string]: string} = {
|
||||||
'index.md': '/',
|
'index.md': '/',
|
||||||
'hello/index.md': '/hello/',
|
'hello/index.md': '/hello/',
|
||||||
'foo.md': '/foo',
|
'foo.md': '/foo',
|
||||||
|
|
|
@ -69,7 +69,7 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
|
||||||
/**
|
/**
|
||||||
* A map from source paths to their URLs. Source paths are `@site` aliased.
|
* A map from source paths to their URLs. Source paths are `@site` aliased.
|
||||||
*/
|
*/
|
||||||
sourceToPermalink: Record<string, string>;
|
sourceToPermalink: {[aliasedPath: string]: string};
|
||||||
}): {
|
}): {
|
||||||
/**
|
/**
|
||||||
* The content with all Markdown file references replaced with their URLs.
|
* The content with all Markdown file references replaced with their URLs.
|
||||||
|
|
|
@ -143,7 +143,7 @@ export function createExcerpt(fileString: string): string | undefined {
|
||||||
*/
|
*/
|
||||||
export function parseFrontMatter(markdownFileContent: string): {
|
export function parseFrontMatter(markdownFileContent: string): {
|
||||||
/** Front matter as parsed by gray-matter. */
|
/** Front matter as parsed by gray-matter. */
|
||||||
frontMatter: Record<string, unknown>;
|
frontMatter: {[key: string]: unknown};
|
||||||
/** The remaining content, trimmed. */
|
/** The remaining content, trimmed. */
|
||||||
content: string;
|
content: string;
|
||||||
} {
|
} {
|
||||||
|
@ -244,7 +244,7 @@ export function parseMarkdownString(
|
||||||
options?: ParseMarkdownContentTitleOptions,
|
options?: ParseMarkdownContentTitleOptions,
|
||||||
): {
|
): {
|
||||||
/** @see {@link parseFrontMatter} */
|
/** @see {@link parseFrontMatter} */
|
||||||
frontMatter: Record<string, unknown>;
|
frontMatter: {[key: string]: unknown};
|
||||||
/** @see {@link parseMarkdownContentTitle} */
|
/** @see {@link parseMarkdownContentTitle} */
|
||||||
contentTitle: string | undefined;
|
contentTitle: string | undefined;
|
||||||
/** @see {@link createExcerpt} */
|
/** @see {@link createExcerpt} */
|
||||||
|
|
|
@ -18,12 +18,12 @@ import prompts from 'prompts';
|
||||||
|
|
||||||
const isInteractive = process.stdout.isTTY;
|
const isInteractive = process.stdout.isTTY;
|
||||||
|
|
||||||
const execOptions: Record<string, unknown> = {
|
const execOptions = {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8' as const,
|
||||||
stdio: [
|
stdio: [
|
||||||
'pipe', // stdin (default)
|
'pipe' as const, // stdin (default)
|
||||||
'pipe', // stdout (default)
|
'pipe' as const, // stdout (default)
|
||||||
'ignore', // stderr
|
'ignore' as const, // stderr
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,19 +37,18 @@ function clearConsole(): void {
|
||||||
// Gets process id of what is on port
|
// Gets process id of what is on port
|
||||||
function getProcessIdOnPort(port: number): string {
|
function getProcessIdOnPort(port: number): string {
|
||||||
return execSync(`lsof -i:${port} -P -t -sTCP:LISTEN`, execOptions)
|
return execSync(`lsof -i:${port} -P -t -sTCP:LISTEN`, execOptions)
|
||||||
.toString()
|
|
||||||
.split('\n')[0]!
|
.split('\n')[0]!
|
||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets process command
|
// Gets process command
|
||||||
function getProcessCommand(processId: string): string {
|
function getProcessCommand(processId: string): string {
|
||||||
const command: Buffer = execSync(
|
const command = execSync(
|
||||||
`ps -o command -p ${processId} | sed -n 2p`,
|
`ps -o command -p ${processId} | sed -n 2p`,
|
||||||
execOptions,
|
execOptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
return command.toString().replace(/\n$/, '');
|
return command.replace(/\n$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets directory of a process from its process id
|
// Gets directory of a process from its process id
|
||||||
|
@ -57,9 +56,7 @@ function getDirectoryOfProcessById(processId: string): string {
|
||||||
return execSync(
|
return execSync(
|
||||||
`lsof -p ${processId} | awk '$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}'`,
|
`lsof -p ${processId} | awk '$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}'`,
|
||||||
execOptions,
|
execOptions,
|
||||||
)
|
).trim();
|
||||||
.toString()
|
|
||||||
.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets process on port
|
// Gets process on port
|
||||||
|
|
|
@ -12,8 +12,8 @@ import prefetchHelper from './prefetch';
|
||||||
import preloadHelper from './preload';
|
import preloadHelper from './preload';
|
||||||
import flat from './flat';
|
import flat from './flat';
|
||||||
|
|
||||||
const fetched: Record<string, boolean> = {};
|
const fetched: {[key: string]: boolean} = {};
|
||||||
const loaded: Record<string, boolean> = {};
|
const loaded: {[key: string]: boolean} = {};
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// eslint-disable-next-line camelcase, no-underscore-dangle
|
// eslint-disable-next-line camelcase, no-underscore-dangle
|
||||||
|
|
|
@ -13,8 +13,6 @@ import registry from '@generated/registry';
|
||||||
import flat from '../flat';
|
import flat from '../flat';
|
||||||
import {RouteContextProvider} from '../routeContext';
|
import {RouteContextProvider} from '../routeContext';
|
||||||
|
|
||||||
type OptsLoader = Record<string, typeof registry[keyof typeof registry][0]>;
|
|
||||||
|
|
||||||
export default function ComponentCreator(
|
export default function ComponentCreator(
|
||||||
path: string,
|
path: string,
|
||||||
hash: string,
|
hash: string,
|
||||||
|
@ -40,7 +38,8 @@ export default function ComponentCreator(
|
||||||
const chunkNames = routesChunkNames[chunkNamesKey]!;
|
const chunkNames = routesChunkNames[chunkNamesKey]!;
|
||||||
const optsModules: string[] = [];
|
const optsModules: string[] = [];
|
||||||
const optsWebpack: string[] = [];
|
const optsWebpack: string[] = [];
|
||||||
const optsLoader: OptsLoader = {};
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const optsLoader: {[key: string]: () => Promise<any>} = {};
|
||||||
|
|
||||||
/* Prepare opts data that react-loadable needs
|
/* Prepare opts data that react-loadable needs
|
||||||
https://github.com/jamiebuilds/react-loadable#declaring-which-modules-are-being-loaded
|
https://github.com/jamiebuilds/react-loadable#declaring-which-modules-are-being-loaded
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
|
|
||||||
import useDocusaurusContext from './useDocusaurusContext';
|
import useDocusaurusContext from './useDocusaurusContext';
|
||||||
import {DEFAULT_PLUGIN_ID} from './constants';
|
import {DEFAULT_PLUGIN_ID} from './constants';
|
||||||
|
import type {GlobalData} from '@docusaurus/types';
|
||||||
|
|
||||||
export default function useGlobalData(): Record<string, unknown> {
|
export default function useGlobalData(): GlobalData {
|
||||||
const {globalData} = useDocusaurusContext();
|
const {globalData} = useDocusaurusContext();
|
||||||
if (!globalData) {
|
if (!globalData) {
|
||||||
throw new Error('Docusaurus global data not found.');
|
throw new Error('Docusaurus global data not found.');
|
||||||
|
@ -16,9 +17,9 @@ export default function useGlobalData(): Record<string, unknown> {
|
||||||
return globalData;
|
return globalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAllPluginInstancesData<T = unknown>(
|
export function useAllPluginInstancesData(
|
||||||
pluginName: string,
|
pluginName: string,
|
||||||
): Record<string, T> {
|
): GlobalData[string] {
|
||||||
const globalData = useGlobalData();
|
const globalData = useGlobalData();
|
||||||
const pluginGlobalData = globalData[pluginName];
|
const pluginGlobalData = globalData[pluginName];
|
||||||
if (!pluginGlobalData) {
|
if (!pluginGlobalData) {
|
||||||
|
@ -26,13 +27,13 @@ export function useAllPluginInstancesData<T = unknown>(
|
||||||
`Docusaurus plugin global data not found for "${pluginName}" plugin.`,
|
`Docusaurus plugin global data not found for "${pluginName}" plugin.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return pluginGlobalData as Record<string, T>;
|
return pluginGlobalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePluginData<T = unknown>(
|
export function usePluginData(
|
||||||
pluginName: string,
|
pluginName: string,
|
||||||
pluginId: string = DEFAULT_PLUGIN_ID,
|
pluginId: string = DEFAULT_PLUGIN_ID,
|
||||||
): T {
|
): GlobalData[string][string] {
|
||||||
const pluginGlobalData = useAllPluginInstancesData(pluginName);
|
const pluginGlobalData = useAllPluginInstancesData(pluginName);
|
||||||
const pluginInstanceGlobalData = pluginGlobalData[pluginId];
|
const pluginInstanceGlobalData = pluginGlobalData[pluginId];
|
||||||
if (!pluginInstanceGlobalData) {
|
if (!pluginInstanceGlobalData) {
|
||||||
|
@ -40,5 +41,5 @@ export function usePluginData<T = unknown>(
|
||||||
`Docusaurus plugin global data not found for "${pluginName}" plugin with id "${pluginId}".`,
|
`Docusaurus plugin global data not found for "${pluginName}" plugin with id "${pluginId}".`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return pluginInstanceGlobalData as T;
|
return pluginInstanceGlobalData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,11 @@ import type {RouteChunksTree} from '@docusaurus/types';
|
||||||
const isTree = (x: string | RouteChunksTree): x is RouteChunksTree =>
|
const isTree = (x: string | RouteChunksTree): x is RouteChunksTree =>
|
||||||
typeof x === 'object' && !!x && Object.keys(x).length > 0;
|
typeof x === 'object' && !!x && Object.keys(x).length > 0;
|
||||||
|
|
||||||
export default function flat(target: RouteChunksTree): Record<string, string> {
|
export default function flat(target: RouteChunksTree): {
|
||||||
|
[keyPath: string]: string;
|
||||||
|
} {
|
||||||
const delimiter = '.';
|
const delimiter = '.';
|
||||||
const output: Record<string, string> = {};
|
const output: {[keyPath: string]: string} = {};
|
||||||
|
|
||||||
function step(object: RouteChunksTree, prefix?: string | number) {
|
function step(object: RouteChunksTree, prefix?: string | number) {
|
||||||
Object.entries(object).forEach(([key, value]) => {
|
Object.entries(object).forEach(([key, value]) => {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import type {Location} from 'history';
|
import type {Location} from 'history';
|
||||||
|
|
||||||
// Memoize previously normalized pathnames.
|
// Memoize previously normalized pathnames.
|
||||||
const pathnames: Record<string, string> = {};
|
const pathnames: {[rawPathname: string]: string} = {};
|
||||||
|
|
||||||
export default function normalizeLocation<T extends Location>(location: T): T {
|
export default function normalizeLocation<T extends Location>(location: T): T {
|
||||||
if (pathnames[location.pathname]) {
|
if (pathnames[location.pathname]) {
|
||||||
|
|
|
@ -65,7 +65,7 @@ const supportedPrefetchStrategy = support('prefetch')
|
||||||
? linkPrefetchStrategy
|
? linkPrefetchStrategy
|
||||||
: xhrPrefetchStrategy;
|
: xhrPrefetchStrategy;
|
||||||
|
|
||||||
const preFetched: Record<string, boolean> = {};
|
const preFetched: {[url: string]: boolean} = {};
|
||||||
|
|
||||||
export default function prefetch(url: string): Promise<void> {
|
export default function prefetch(url: string): Promise<void> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
|
@ -146,7 +146,7 @@ async function buildLocale({
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const allCollectedLinks: Record<string, string[]> = {};
|
const allCollectedLinks: {[location: string]: string[]} = {};
|
||||||
|
|
||||||
let serverConfig: Configuration = await createServerConfig({
|
let serverConfig: Configuration = await createServerConfig({
|
||||||
props,
|
props,
|
||||||
|
|
|
@ -29,10 +29,9 @@ export function actionStatusLabel(status: SwizzleActionStatus): string {
|
||||||
return _.capitalize(status);
|
return _.capitalize(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
const SwizzleActionStatusColors: Record<
|
const SwizzleActionStatusColors: {
|
||||||
SwizzleActionStatus,
|
[status in SwizzleActionStatus]: (str: string) => string;
|
||||||
(str: string) => string
|
} = {
|
||||||
> = {
|
|
||||||
safe: logger.green,
|
safe: logger.green,
|
||||||
unsafe: logger.yellow,
|
unsafe: logger.yellow,
|
||||||
forbidden: logger.red,
|
forbidden: logger.red,
|
||||||
|
|
8
packages/docusaurus/src/deps.d.ts
vendored
8
packages/docusaurus/src/deps.d.ts
vendored
|
@ -17,8 +17,8 @@ declare module 'react-loadable-ssr-addon-v5-slorber' {
|
||||||
|
|
||||||
export type Manifest = {
|
export type Manifest = {
|
||||||
entrypoints: string[];
|
entrypoints: string[];
|
||||||
origins: Record<string, number[]>;
|
origins: {[key: string]: number[]};
|
||||||
assets: Array<Record<string, Asset[]>>;
|
assets: Array<{[key: string]: Asset[]}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getBundles(
|
export function getBundles(
|
||||||
|
@ -36,7 +36,7 @@ declare module 'react-loadable-ssr-addon-v5-slorber' {
|
||||||
|
|
||||||
declare module '@slorber/static-site-generator-webpack-plugin' {
|
declare module '@slorber/static-site-generator-webpack-plugin' {
|
||||||
export type Locals = {
|
export type Locals = {
|
||||||
routesLocation: Record<string, string>;
|
routesLocation: {[filePath: string]: string};
|
||||||
generatedFilesDir: string;
|
generatedFilesDir: string;
|
||||||
headTags: string;
|
headTags: string;
|
||||||
preBodyTags: string;
|
preBodyTags: string;
|
||||||
|
@ -53,7 +53,7 @@ declare module '@slorber/static-site-generator-webpack-plugin' {
|
||||||
locals: Locals;
|
locals: Locals;
|
||||||
paths: string[];
|
paths: string[];
|
||||||
preferFoldersOutput?: boolean;
|
preferFoldersOutput?: boolean;
|
||||||
globals: Record<string, unknown>;
|
globals: {[key: string]: unknown};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,9 @@ function getAllBrokenLinks({
|
||||||
allCollectedLinks,
|
allCollectedLinks,
|
||||||
routes,
|
routes,
|
||||||
}: {
|
}: {
|
||||||
allCollectedLinks: Record<string, string[]>;
|
allCollectedLinks: {[location: string]: string[]};
|
||||||
routes: RouteConfig[];
|
routes: RouteConfig[];
|
||||||
}): Record<string, BrokenLink[]> {
|
}): {[location: string]: BrokenLink[]} {
|
||||||
const filteredRoutes = filterIntermediateRoutes(routes);
|
const filteredRoutes = filterIntermediateRoutes(routes);
|
||||||
|
|
||||||
const allBrokenLinks = _.mapValues(allCollectedLinks, (pageLinks, pagePath) =>
|
const allBrokenLinks = _.mapValues(allCollectedLinks, (pageLinks, pagePath) =>
|
||||||
|
@ -88,9 +88,9 @@ function getAllBrokenLinks({
|
||||||
return _.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
return _.pickBy(allBrokenLinks, (brokenLinks) => brokenLinks.length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBrokenLinksErrorMessage(
|
function getBrokenLinksErrorMessage(allBrokenLinks: {
|
||||||
allBrokenLinks: Record<string, BrokenLink[]>,
|
[location: string]: BrokenLink[];
|
||||||
): string | undefined {
|
}): string | undefined {
|
||||||
if (Object.keys(allBrokenLinks).length === 0) {
|
if (Object.keys(allBrokenLinks).length === 0) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -177,8 +177,8 @@ async function filterExistingFileLinks({
|
||||||
}: {
|
}: {
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
outDir: string;
|
outDir: string;
|
||||||
allCollectedLinks: Record<string, string[]>;
|
allCollectedLinks: {[location: string]: string[]};
|
||||||
}): Promise<Record<string, string[]>> {
|
}): Promise<{[location: string]: string[]}> {
|
||||||
async function linkFileExists(link: string) {
|
async function linkFileExists(link: string) {
|
||||||
// /baseUrl/javadoc/ -> /outDir/javadoc
|
// /baseUrl/javadoc/ -> /outDir/javadoc
|
||||||
const baseFilePath = onlyPathname(
|
const baseFilePath = onlyPathname(
|
||||||
|
@ -222,7 +222,7 @@ export async function handleBrokenLinks({
|
||||||
baseUrl,
|
baseUrl,
|
||||||
outDir,
|
outDir,
|
||||||
}: {
|
}: {
|
||||||
allCollectedLinks: Record<string, string[]>;
|
allCollectedLinks: {[location: string]: string[]};
|
||||||
onBrokenLinks: ReportingSeverity;
|
onBrokenLinks: ReportingSeverity;
|
||||||
routes: RouteConfig[];
|
routes: RouteConfig[];
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
|
|
|
@ -404,7 +404,7 @@ ${Object.entries(registry)
|
||||||
JSON.stringify(i18n, null, 2),
|
JSON.stringify(i18n, null, 2),
|
||||||
);
|
);
|
||||||
|
|
||||||
const codeTranslationsWithFallbacks: Record<string, string> = {
|
const codeTranslationsWithFallbacks: {[msgId: string]: string} = {
|
||||||
...(await getPluginsDefaultCodeTranslationMessages(plugins)),
|
...(await getPluginsDefaultCodeTranslationMessages(plugins)),
|
||||||
...codeTranslations,
|
...codeTranslations,
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,6 +14,7 @@ import type {
|
||||||
PluginContentLoadedActions,
|
PluginContentLoadedActions,
|
||||||
RouteConfig,
|
RouteConfig,
|
||||||
AllContent,
|
AllContent,
|
||||||
|
GlobalData,
|
||||||
TranslationFiles,
|
TranslationFiles,
|
||||||
ThemeConfig,
|
ThemeConfig,
|
||||||
LoadedPlugin,
|
LoadedPlugin,
|
||||||
|
@ -75,7 +76,7 @@ export async function loadPlugins({
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
plugins: LoadedPlugin[];
|
plugins: LoadedPlugin[];
|
||||||
pluginsRouteConfigs: RouteConfig[];
|
pluginsRouteConfigs: RouteConfig[];
|
||||||
globalData: unknown;
|
globalData: GlobalData;
|
||||||
themeConfigTranslated: ThemeConfig;
|
themeConfigTranslated: ThemeConfig;
|
||||||
}> {
|
}> {
|
||||||
// 1. Plugin Lifecycle - Initialization/Constructor.
|
// 1. Plugin Lifecycle - Initialization/Constructor.
|
||||||
|
@ -135,7 +136,7 @@ export async function loadPlugins({
|
||||||
// 3. Plugin Lifecycle - contentLoaded.
|
// 3. Plugin Lifecycle - contentLoaded.
|
||||||
const pluginsRouteConfigs: RouteConfig[] = [];
|
const pluginsRouteConfigs: RouteConfig[] = [];
|
||||||
|
|
||||||
const globalData: Record<string, Record<string, unknown>> = {};
|
const globalData: GlobalData = {};
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
contentLoadedTranslatedPlugins.map(
|
contentLoadedTranslatedPlugins.map(
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {createRequire} from 'module';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import importFresh from 'import-fresh';
|
import importFresh from 'import-fresh';
|
||||||
import type {
|
import type {
|
||||||
DocusaurusPluginVersionInformation,
|
PluginVersionInformation,
|
||||||
ImportedPluginModule,
|
ImportedPluginModule,
|
||||||
LoadContext,
|
LoadContext,
|
||||||
PluginModule,
|
PluginModule,
|
||||||
|
@ -151,7 +151,7 @@ export default async function initPlugins({
|
||||||
|
|
||||||
async function doGetPluginVersion(
|
async function doGetPluginVersion(
|
||||||
normalizedPluginConfig: NormalizedPluginConfig,
|
normalizedPluginConfig: NormalizedPluginConfig,
|
||||||
): Promise<DocusaurusPluginVersionInformation> {
|
): Promise<PluginVersionInformation> {
|
||||||
// get plugin version
|
// get plugin version
|
||||||
if (normalizedPluginConfig.pluginModule?.path) {
|
if (normalizedPluginConfig.pluginModule?.path) {
|
||||||
const pluginPath = pluginRequire.resolve(
|
const pluginPath = pluginRequire.resolve(
|
||||||
|
@ -198,8 +198,9 @@ export default async function initPlugins({
|
||||||
async function initializePlugin(
|
async function initializePlugin(
|
||||||
normalizedPluginConfig: NormalizedPluginConfig,
|
normalizedPluginConfig: NormalizedPluginConfig,
|
||||||
): Promise<InitializedPlugin> {
|
): Promise<InitializedPlugin> {
|
||||||
const pluginVersion: DocusaurusPluginVersionInformation =
|
const pluginVersion: PluginVersionInformation = await doGetPluginVersion(
|
||||||
await doGetPluginVersion(normalizedPluginConfig);
|
normalizedPluginConfig,
|
||||||
|
);
|
||||||
const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
|
const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
|
||||||
|
|
||||||
// Side-effect: merge the normalized theme config in the original one
|
// Side-effect: merge the normalized theme config in the original one
|
||||||
|
|
|
@ -103,8 +103,8 @@ function isModule(value: unknown): value is Module {
|
||||||
if (
|
if (
|
||||||
typeof value === 'object' &&
|
typeof value === 'object' &&
|
||||||
// eslint-disable-next-line no-underscore-dangle
|
// eslint-disable-next-line no-underscore-dangle
|
||||||
(value as Record<string, unknown>)?.__import &&
|
(value as {[key: string]: unknown})?.__import &&
|
||||||
(value as Record<string, unknown>)?.path
|
(value as {[key: string]: unknown})?.path
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,7 +265,7 @@ export async function localizePluginTranslationFile({
|
||||||
|
|
||||||
export async function getPluginsDefaultCodeTranslationMessages(
|
export async function getPluginsDefaultCodeTranslationMessages(
|
||||||
plugins: InitializedPlugin[],
|
plugins: InitializedPlugin[],
|
||||||
): Promise<Record<string, string>> {
|
): Promise<{[msgId: string]: string}> {
|
||||||
const pluginsMessages = await Promise.all(
|
const pluginsMessages = await Promise.all(
|
||||||
plugins.map((plugin) => plugin.getDefaultCodeTranslationMessages?.() ?? {}),
|
plugins.map((plugin) => plugin.getDefaultCodeTranslationMessages?.() ?? {}),
|
||||||
);
|
);
|
||||||
|
@ -280,9 +280,9 @@ export function applyDefaultCodeTranslations({
|
||||||
extractedCodeTranslations,
|
extractedCodeTranslations,
|
||||||
defaultCodeMessages,
|
defaultCodeMessages,
|
||||||
}: {
|
}: {
|
||||||
extractedCodeTranslations: Record<string, TranslationMessage>;
|
extractedCodeTranslations: {[msgId: string]: TranslationMessage};
|
||||||
defaultCodeMessages: Record<string, string>;
|
defaultCodeMessages: {[msgId: string]: string};
|
||||||
}): Record<string, TranslationMessage> {
|
}): {[msgId: string]: TranslationMessage} {
|
||||||
const unusedDefaultCodeMessages = _.difference(
|
const unusedDefaultCodeMessages = _.difference(
|
||||||
Object.keys(defaultCodeMessages),
|
Object.keys(defaultCodeMessages),
|
||||||
Object.keys(extractedCodeTranslations),
|
Object.keys(extractedCodeTranslations),
|
||||||
|
|
|
@ -130,7 +130,7 @@ function logSourceCodeFileTranslationsWarnings(
|
||||||
|
|
||||||
type SourceCodeFileTranslations = {
|
type SourceCodeFileTranslations = {
|
||||||
sourceCodeFilePath: string;
|
sourceCodeFilePath: string;
|
||||||
translations: Record<string, TranslationMessage>;
|
translations: {[msgId: string]: TranslationMessage};
|
||||||
warnings: string[];
|
warnings: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ function extractSourceCodeAstTranslations(
|
||||||
Full code: ${generate(node).code}`;
|
Full code: ${generate(node).code}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const translations: Record<string, TranslationMessage> = {};
|
const translations: {[msgId: string]: TranslationMessage} = {};
|
||||||
const warnings: string[] = [];
|
const warnings: string[] = [];
|
||||||
let translateComponentName: string | undefined;
|
let translateComponentName: string | undefined;
|
||||||
let translateFunctionName: string | undefined;
|
let translateFunctionName: string | undefined;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {DocusaurusPluginVersionInformation} from '@docusaurus/types';
|
import type {PluginVersionInformation} from '@docusaurus/types';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ async function getPackageJsonName(
|
||||||
export async function getPluginVersion(
|
export async function getPluginVersion(
|
||||||
pluginPath: string,
|
pluginPath: string,
|
||||||
siteDir: string,
|
siteDir: string,
|
||||||
): Promise<DocusaurusPluginVersionInformation> {
|
): Promise<PluginVersionInformation> {
|
||||||
let potentialPluginPackageJsonDirectory = path.dirname(pluginPath);
|
let potentialPluginPackageJsonDirectory = path.dirname(pluginPath);
|
||||||
while (potentialPluginPackageJsonDirectory !== '/') {
|
while (potentialPluginPackageJsonDirectory !== '/') {
|
||||||
const packageJsonPath = path.join(
|
const packageJsonPath = path.join(
|
||||||
|
|
|
@ -44,11 +44,13 @@ export function excludeJS(modulePath: string): boolean {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getDocusaurusAliases(): Promise<Record<string, string>> {
|
export async function getDocusaurusAliases(): Promise<{
|
||||||
|
[aliasName: string]: string;
|
||||||
|
}> {
|
||||||
const dirPath = path.resolve(__dirname, '../client/exports');
|
const dirPath = path.resolve(__dirname, '../client/exports');
|
||||||
const extensions = ['.js', '.ts', '.tsx'];
|
const extensions = ['.js', '.ts', '.tsx'];
|
||||||
|
|
||||||
const aliases: Record<string, string> = {};
|
const aliases: {[key: string]: string} = {};
|
||||||
|
|
||||||
(await fs.readdir(dirPath))
|
(await fs.readdir(dirPath))
|
||||||
.filter((fileName) => extensions.includes(path.extname(fileName)))
|
.filter((fileName) => extensions.includes(path.extname(fileName)))
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default async function createServerConfig({
|
||||||
} = props;
|
} = props;
|
||||||
const config = await createBaseConfig(props, true);
|
const config = await createBaseConfig(props, true);
|
||||||
|
|
||||||
const routesLocation: Record<string, string> = {};
|
const routesLocation: {[filePath: string]: string} = {};
|
||||||
// Array of paths to be rendered. Relative to output directory
|
// Array of paths to be rendered. Relative to output directory
|
||||||
const ssgPaths = routesPaths.map((str) => {
|
const ssgPaths = routesPaths.map((str) => {
|
||||||
const ssgPath =
|
const ssgPath =
|
||||||
|
|
|
@ -14,7 +14,7 @@ const {version} = require('../package.json');
|
||||||
|
|
||||||
const ERROR_EXT = `Error: Input file is missing or uses unsupported image format, lqip v${version}`;
|
const ERROR_EXT = `Error: Input file is missing or uses unsupported image format, lqip v${version}`;
|
||||||
|
|
||||||
const SUPPORTED_MIMES: Record<string, string> = {
|
const SUPPORTED_MIMES: {[ext: string]: string} = {
|
||||||
jpeg: 'image/jpeg',
|
jpeg: 'image/jpeg',
|
||||||
jpg: 'image/jpeg',
|
jpg: 'image/jpeg',
|
||||||
png: 'image/png',
|
png: 'image/png',
|
||||||
|
|
|
@ -335,7 +335,7 @@ You can even omit the children prop and specify a translation string in your `co
|
||||||
React hook to access Docusaurus Context. The context contains the `siteConfig` object from [docusaurus.config.js](api/docusaurus.config.js.md) and some additional site metadata.
|
React hook to access Docusaurus Context. The context contains the `siteConfig` object from [docusaurus.config.js](api/docusaurus.config.js.md) and some additional site metadata.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
type DocusaurusPluginVersionInformation =
|
type PluginVersionInformation =
|
||||||
| {readonly type: 'package'; readonly version?: string}
|
| {readonly type: 'package'; readonly version?: string}
|
||||||
| {readonly type: 'project'}
|
| {readonly type: 'project'}
|
||||||
| {readonly type: 'local'}
|
| {readonly type: 'local'}
|
||||||
|
@ -344,7 +344,7 @@ type DocusaurusPluginVersionInformation =
|
||||||
interface DocusaurusSiteMetadata {
|
interface DocusaurusSiteMetadata {
|
||||||
readonly docusaurusVersion: string;
|
readonly docusaurusVersion: string;
|
||||||
readonly siteVersion?: string;
|
readonly siteVersion?: string;
|
||||||
readonly pluginVersions: Record<string, DocusaurusPluginVersionInformation>;
|
readonly pluginVersions: Record<string, PluginVersionInformation>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface I18nLocaleConfig {
|
interface I18nLocaleConfig {
|
||||||
|
|
|
@ -74,7 +74,7 @@ export type User = {
|
||||||
// Available tags to assign to your site
|
// Available tags to assign to your site
|
||||||
// Please choose all tags that you think might apply.
|
// Please choose all tags that you think might apply.
|
||||||
// We'll remove inappropriate tags, but it's less likely that we add tags.
|
// We'll remove inappropriate tags, but it's less likely that we add tags.
|
||||||
export const Tags: Record<TagType, Tag> = {
|
export const Tags: {[type in TagType]: Tag} = {
|
||||||
// DO NOT USE THIS TAG: we choose sites to add to favorites
|
// DO NOT USE THIS TAG: we choose sites to add to favorites
|
||||||
favorite: {
|
favorite: {
|
||||||
label: 'Favorite',
|
label: 'Favorite',
|
||||||
|
|
|
@ -19,15 +19,14 @@ export type ColorState = {
|
||||||
shades: Shades;
|
shades: Shades;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Shades = Record<
|
export type Shades = {
|
||||||
string,
|
[cssVar: string]: {
|
||||||
{
|
|
||||||
adjustment: number;
|
adjustment: number;
|
||||||
adjustmentInput: string;
|
adjustmentInput: string;
|
||||||
displayOrder: number;
|
displayOrder: number;
|
||||||
codeOrder: number;
|
codeOrder: number;
|
||||||
}
|
};
|
||||||
>;
|
};
|
||||||
export const COLOR_SHADES: Shades = {
|
export const COLOR_SHADES: Shades = {
|
||||||
'--ifm-color-primary': {
|
'--ifm-color-primary': {
|
||||||
adjustment: 0,
|
adjustment: 0,
|
||||||
|
|
|
@ -335,7 +335,7 @@ You can even omit the children prop and specify a translation string in your `co
|
||||||
React hook to access Docusaurus Context. The context contains the `siteConfig` object from [docusaurus.config.js](api/docusaurus.config.js.md) and some additional site metadata.
|
React hook to access Docusaurus Context. The context contains the `siteConfig` object from [docusaurus.config.js](api/docusaurus.config.js.md) and some additional site metadata.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
type DocusaurusPluginVersionInformation =
|
type PluginVersionInformation =
|
||||||
| {readonly type: 'package'; readonly version?: string}
|
| {readonly type: 'package'; readonly version?: string}
|
||||||
| {readonly type: 'project'}
|
| {readonly type: 'project'}
|
||||||
| {readonly type: 'local'}
|
| {readonly type: 'local'}
|
||||||
|
@ -344,7 +344,7 @@ type DocusaurusPluginVersionInformation =
|
||||||
interface DocusaurusSiteMetadata {
|
interface DocusaurusSiteMetadata {
|
||||||
readonly docusaurusVersion: string;
|
readonly docusaurusVersion: string;
|
||||||
readonly siteVersion?: string;
|
readonly siteVersion?: string;
|
||||||
readonly pluginVersions: Record<string, DocusaurusPluginVersionInformation>;
|
readonly pluginVersions: Record<string, PluginVersionInformation>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface I18nLocaleConfig {
|
interface I18nLocaleConfig {
|
||||||
|
|
|
@ -335,7 +335,7 @@ You can even omit the children prop and specify a translation string in your `co
|
||||||
React hook to access Docusaurus Context. The context contains the `siteConfig` object from [docusaurus.config.js](api/docusaurus.config.js.md) and some additional site metadata.
|
React hook to access Docusaurus Context. The context contains the `siteConfig` object from [docusaurus.config.js](api/docusaurus.config.js.md) and some additional site metadata.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
type DocusaurusPluginVersionInformation =
|
type PluginVersionInformation =
|
||||||
| {readonly type: 'package'; readonly version?: string}
|
| {readonly type: 'package'; readonly version?: string}
|
||||||
| {readonly type: 'project'}
|
| {readonly type: 'project'}
|
||||||
| {readonly type: 'local'}
|
| {readonly type: 'local'}
|
||||||
|
@ -344,7 +344,7 @@ type DocusaurusPluginVersionInformation =
|
||||||
interface DocusaurusSiteMetadata {
|
interface DocusaurusSiteMetadata {
|
||||||
readonly docusaurusVersion: string;
|
readonly docusaurusVersion: string;
|
||||||
readonly siteVersion?: string;
|
readonly siteVersion?: string;
|
||||||
readonly pluginVersions: Record<string, DocusaurusPluginVersionInformation>;
|
readonly pluginVersions: Record<string, PluginVersionInformation>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface I18nLocaleConfig {
|
interface I18nLocaleConfig {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue