chore: upgrade Prettier + regenerate lock file (#5611)

* Bump deps

* Run prettier

* Format docs

* Minor refactor

* Collapse objects

* Fix type

* Update lock file
This commit is contained in:
Joshua Chen 2021-09-30 18:54:17 +08:00 committed by GitHub
parent 4dbc458a22
commit 3f1f8255a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 1534 additions and 1517 deletions

View file

@ -563,12 +563,8 @@ describe('versioned site', () => {
options,
});
expect(versionsMetadata.length).toEqual(4);
const [
currentVersion,
version101,
version100,
versionWithSlugs,
] = versionsMetadata;
const [currentVersion, version101, version100, versionWithSlugs] =
versionsMetadata;
const currentVersionTestUtils = createTestUtils({
siteDir,

View file

@ -575,12 +575,8 @@ describe('versioned website', () => {
const {siteDir, plugin, pluginContentDir} = await loadSite();
const content = await plugin.loadContent!();
expect(content.loadedVersions.length).toEqual(4);
const [
currentVersion,
version101,
version100,
versionWithSlugs,
] = content.loadedVersions;
const [currentVersion, version101, version100, versionWithSlugs] =
content.loadedVersions;
// foo/baz.md only exists in version -1.0.0
expect(findDocById(currentVersion, 'foo/baz')).toBeUndefined();
@ -751,13 +747,8 @@ describe('versioned website (community)', () => {
}
test('extendCli - docsVersion', async () => {
const {
siteDir,
routeBasePath,
sidebarPath,
pluginId,
plugin,
} = await loadSite();
const {siteDir, routeBasePath, sidebarPath, pluginId, plugin} =
await loadSite();
const mock = jest
.spyOn(cliDocs, 'cliDocsVersionCommand')
.mockImplementation();
@ -1784,12 +1775,11 @@ describe('site with custom sidebar items generator', () => {
});
test('sidebar is autogenerated according to a custom sidebarItemsGenerator', async () => {
const customSidebarItemsGenerator: SidebarItemsGeneratorOption = async () => {
return [
const customSidebarItemsGenerator: SidebarItemsGeneratorOption =
async () => [
{type: 'doc', id: 'API/api-overview'},
{type: 'doc', id: 'API/api-end'},
];
};
const {content} = await loadSite(customSidebarItemsGenerator);
const version = content.loadedVersions[0];

View file

@ -646,11 +646,8 @@ describe('createSidebarsUtils', () => {
const sidebars: Sidebars = {sidebar1, sidebar2};
const {
getFirstDocIdOfFirstSidebar,
getSidebarNameByDocId,
getDocNavigation,
} = createSidebarsUtils(sidebars);
const {getFirstDocIdOfFirstSidebar, getSidebarNameByDocId, getDocNavigation} =
createSidebarsUtils(sidebars);
test('getSidebarNameByDocId', async () => {
expect(getFirstDocIdOfFirstSidebar()).toEqual('doc1');

View file

@ -324,14 +324,8 @@ describe('versioned site, pluginId=default', () => {
}
test('readVersionsMetadata versioned site', async () => {
const {
defaultOptions,
defaultContext,
vCurrent,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
await loadSite();
const versionsMetadata = readVersionsMetadata({
options: defaultOptions,
@ -342,13 +336,8 @@ describe('versioned site, pluginId=default', () => {
});
test('readVersionsMetadata versioned site with includeCurrentVersion=false', async () => {
const {
defaultOptions,
defaultContext,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, v101, v100, vwithSlugs} =
await loadSite();
const versionsMetadata = readVersionsMetadata({
options: {...defaultOptions, includeCurrentVersion: false},
@ -364,14 +353,8 @@ describe('versioned site, pluginId=default', () => {
});
test('readVersionsMetadata versioned site with version options', async () => {
const {
defaultOptions,
defaultContext,
vCurrent,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
await loadSite();
const versionsMetadata = readVersionsMetadata({
options: {
@ -424,14 +407,8 @@ describe('versioned site, pluginId=default', () => {
});
test('readVersionsMetadata versioned site with editUrl', async () => {
const {
defaultOptions,
defaultContext,
vCurrent,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
await loadSite();
const versionsMetadata = readVersionsMetadata({
options: {
@ -474,14 +451,8 @@ describe('versioned site, pluginId=default', () => {
});
test('readVersionsMetadata versioned site with editUrl and editCurrentVersion=true', async () => {
const {
defaultOptions,
defaultContext,
vCurrent,
v101,
v100,
vwithSlugs,
} = await loadSite();
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
await loadSite();
const versionsMetadata = readVersionsMetadata({
options: {

View file

@ -201,11 +201,8 @@ export default function pluginContentDocs(
// Add sidebar/next/previous to the docs
function addNavData(doc: DocMetadataBase): DocMetadata {
const {
sidebarName,
previousId,
nextId,
} = sidebarsUtils.getDocNavigation(doc.id);
const {sidebarName, previousId, nextId} =
sidebarsUtils.getDocNavigation(doc.id);
const toDocNavLink = (navDocId: string): DocNavLink => {
const {title, permalink, frontMatter} = docsBaseById[navDocId];
return {
@ -239,7 +236,8 @@ export default function pluginContentDocs(
(doc) =>
doc.unversionedId === options.homePageId || doc.slug === '/',
);
const firstDocIdOfFirstSidebar = sidebarsUtils.getFirstDocIdOfFirstSidebar();
const firstDocIdOfFirstSidebar =
sidebarsUtils.getFirstDocIdOfFirstSidebar();
if (versionHomeDoc) {
return versionHomeDoc;
} else if (firstDocIdOfFirstSidebar) {

View file

@ -10,7 +10,8 @@ import {NumberPrefixParser} from './types';
// Best-effort to avoid parsing some patterns as number prefix
const IgnoredPrefixPatterns = (function () {
// ignore common date-like patterns: https://github.com/facebook/docusaurus/issues/4640
const DateLikePrefixRegex = /^((\d{2}|\d{4})[-_.]\d{2}([-_.](\d{2}|\d{4}))?)(.*)$/;
const DateLikePrefixRegex =
/^((\d{2}|\d{4})[-_.]\d{2}([-_.](\d{2}|\d{4}))?)(.*)$/;
// ignore common versioning patterns: https://github.com/facebook/docusaurus/issues/4653
// note: we could try to parse float numbers in filenames but that is probably not worth it
@ -23,7 +24,8 @@ const IgnoredPrefixPatterns = (function () {
);
})();
const NumberPrefixRegex = /^(?<numberPrefix>\d+)(?<separator>\s*[-_.]+\s*)(?<suffix>.*)$/;
const NumberPrefixRegex =
/^(?<numberPrefix>\d+)(?<separator>\s*[-_.]+\s*)(?<suffix>.*)$/;
// 0-myDoc => {filename: myDoc, numberPrefix: 0}
// 003 - myDoc => {filename: myDoc, numberPrefix: 3}

View file

@ -194,8 +194,10 @@ declare module '@theme/hooks/useDocs' {
type GlobalVersion = import('./types').GlobalVersion;
type ActivePlugin = import('./client/docsClientUtils').ActivePlugin;
type ActiveDocContext = import('./client/docsClientUtils').ActiveDocContext;
type DocVersionSuggestions = import('./client/docsClientUtils').DocVersionSuggestions;
type GetActivePluginOptions = import('./client/docsClientUtils').GetActivePluginOptions;
type DocVersionSuggestions =
import('./client/docsClientUtils').DocVersionSuggestions;
type GetActivePluginOptions =
import('./client/docsClientUtils').GetActivePluginOptions;
export type {GlobalPluginData, GlobalVersion};
export const useAllDocsData: () => Record<string, GlobalPluginData>;

View file

@ -93,9 +93,10 @@ async function readCategoryMetadatasFile(
}
// [...parents, tail]
function parseBreadcrumb(
breadcrumb: string[],
): {parents: string[]; tail: string} {
function parseBreadcrumb(breadcrumb: string[]): {
parents: string[];
tail: string;
} {
return {
parents: take(breadcrumb, breadcrumb.length - 1),
tail: last(breadcrumb)!,
@ -103,13 +104,13 @@ function parseBreadcrumb(
}
// Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async function defaultSidebarItemsGenerator({
export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
item,
docs: allDocs,
version,
numberPrefixParser,
options,
}) {
}) => {
// Doc at the root of the autogenerated sidebar dir
function isRootDoc(doc: SidebarItemsGeneratorDoc) {
return doc.sourceDirName === item.dirName;
@ -245,9 +246,8 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async functio
} else {
sidebarItems.push(newCategory);
}
categoriesByBreadcrumb[
breadcrumb.join(BreadcrumbSeparator)
] = newCategory;
categoriesByBreadcrumb[breadcrumb.join(BreadcrumbSeparator)] =
newCategory;
return newCategory;
}
}

View file

@ -457,7 +457,7 @@ export async function processSidebars({
function collectSidebarItemsOfType<
Type extends SidebarItemType,
Item extends SidebarItem & {type: SidebarItemType}
Item extends SidebarItem & {type: SidebarItemType},
>(type: Type, sidebar: Sidebar): Item[] {
function collectRecursive(item: SidebarItem): Item[] {
const currentItemsCollected: Item[] =
@ -508,14 +508,10 @@ export function collectSidebarsDocIds(
});
}
export function createSidebarsUtils(
sidebars: Sidebars,
): {
export function createSidebarsUtils(sidebars: Sidebars): {
getFirstDocIdOfFirstSidebar: () => string | undefined;
getSidebarNameByDocId: (docId: string) => string | undefined;
getDocNavigation: (
docId: string,
) => {
getDocNavigation: (docId: string) => {
sidebarName: string | undefined;
previousId: string | undefined;
nextId: string | undefined;
@ -530,16 +526,14 @@ export function createSidebarsUtils(
function getSidebarNameByDocId(docId: string): string | undefined {
// TODO lookup speed can be optimized
const entry = Object.entries(
sidebarNameToDocIds,
).find(([_sidebarName, docIds]) => docIds.includes(docId));
const entry = Object.entries(sidebarNameToDocIds).find(
([_sidebarName, docIds]) => docIds.includes(docId),
);
return entry?.[0];
}
function getDocNavigation(
docId: string,
): {
function getDocNavigation(docId: string): {
sidebarName: string | undefined;
previousId: string | undefined;
nextId: string | undefined;

View file

@ -131,29 +131,25 @@ function translateSidebar({
sidebarName: string;
sidebarsTranslations: TranslationFileContent;
}): Sidebar {
return transformSidebarItems(
sidebar,
(item: SidebarItem): SidebarItem => {
if (item.type === 'category') {
return {
...item,
label:
sidebarsTranslations[
`sidebar.${sidebarName}.category.${item.label}`
]?.message ?? item.label,
};
}
if (item.type === 'link') {
return {
...item,
label:
sidebarsTranslations[`sidebar.${sidebarName}.link.${item.label}`]
?.message ?? item.label,
};
}
return item;
},
);
return transformSidebarItems(sidebar, (item: SidebarItem): SidebarItem => {
if (item.type === 'category') {
return {
...item,
label:
sidebarsTranslations[`sidebar.${sidebarName}.category.${item.label}`]
?.message ?? item.label,
};
}
if (item.type === 'link') {
return {
...item,
label:
sidebarsTranslations[`sidebar.${sidebarName}.link.${item.label}`]
?.message ?? item.label,
};
}
return item;
});
}
function getSidebarsTranslations(
@ -193,9 +189,8 @@ function getVersionTranslationFiles(version: LoadedVersion): TranslationFiles {
},
};
const sidebarsTranslations: TranslationFileContent = getSidebarsTranslations(
version,
);
const sidebarsTranslations: TranslationFileContent =
getSidebarsTranslations(version);
// const docsTranslations: TranslationFileContent = getDocsTranslations(version);

View file

@ -306,6 +306,7 @@ export type DocsMarkdownOption = {
onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void;
};
export type NumberPrefixParser = (
filename: string,
) => {filename: string; numberPrefix?: number};
export type NumberPrefixParser = (filename: string) => {
filename: string;
numberPrefix?: number;
};

View file

@ -355,15 +355,8 @@ function createVersionMetadata({
| 'editCurrentVersion'
>;
}): VersionMetadata {
const {
sidebarFilePath,
contentPath,
contentPathLocalized,
} = getVersionMetadataPaths({
versionName,
context,
options,
});
const {sidebarFilePath, contentPath, contentPathLocalized} =
getVersionMetadataPaths({versionName, context, options});
const isLast = versionName === lastVersionName;