From 5d858f5e66443fa517d278d5adca186872776d7a Mon Sep 17 00:00:00 2001 From: Noritaka Kobayashi Date: Mon, 26 May 2025 20:07:56 +0900 Subject: [PATCH 1/2] refactor: remove unnecessary undefined & use optional chain (#11192) --- .../docusaurus-plugin-content-docs/src/sidebars/utils.ts | 2 +- .../src/theme/IdealImageLegacy/components/helpers.js | 5 ++--- packages/docusaurus-theme-common/src/utils/useThemeConfig.ts | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars/utils.ts b/packages/docusaurus-plugin-content-docs/src/sidebars/utils.ts index 2f785a0320..e0d1152113 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars/utils.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars/utils.ts @@ -480,7 +480,7 @@ Available document ids are: export function toDocNavigationLink( doc: DocMetadataBase, - options?: {sidebarItemLabel?: string | undefined}, + options?: {sidebarItemLabel?: string}, ): PropNavigationLink { const { title, diff --git a/packages/docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy/components/helpers.js b/packages/docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy/components/helpers.js index f2c06f1602..5360a02721 100644 --- a/packages/docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy/components/helpers.js +++ b/packages/docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy/components/helpers.js @@ -86,7 +86,7 @@ export const bytesToSize = (bytes) => { const detectWebpSupport = () => { if (ssr) return false; const elem = document.createElement('canvas'); - if (elem.getContext && elem.getContext('2d')) { + if (elem.getContext?.('2d')) { // was able or not to get WebP representation return elem.toDataURL('image/webp').indexOf('data:image/webp') === 0; } else { @@ -97,8 +97,7 @@ const detectWebpSupport = () => { export const supportsWebp = detectWebpSupport(); -const isWebp = (x) => - x.format === 'webp' || (x.src && x.src.match(/\.webp($|\?.*)/i)); +const isWebp = (x) => x.format === 'webp' || x.src?.match(/\.webp($|\?.*)/i); // eslint-disable-next-line no-shadow export const selectSrc = ({srcSet, maxImageWidth, supportsWebp}) => { diff --git a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts index a1d095387e..af9fe2c825 100644 --- a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts +++ b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts @@ -15,7 +15,7 @@ export type DocsVersionPersistence = 'localStorage' | 'none'; // TODO improve types, use unions export type NavbarItem = { - type?: string | undefined; + type?: string; items?: NavbarItem[]; label?: string; position?: 'left' | 'right'; From ba18a8b8b9bd396cbc3b1b78ff0164c15f9faa5b Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 26 May 2025 04:29:23 -0700 Subject: [PATCH 2/2] chore: simplify construction of test paths (#11196) --- .../docusaurus/src/commands/swizzle/__tests__/index.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts b/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts index 013fbab245..a6bc0df605 100644 --- a/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts +++ b/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts @@ -91,13 +91,11 @@ async function createTestSite() { const siteThemePathPosix = posixPath(siteThemePath); expect(tree(siteThemePathPosix)).toMatchSnapshot('theme dir tree'); - const files = (await Globby(siteThemePathPosix)) - .map((file) => path.posix.relative(siteThemePathPosix, file)) - .sort(); + const files = await Globby('**/*', {cwd: siteThemePath}); for (const file of files) { const fileContent = await fs.readFile( - path.posix.join(siteThemePath, file), + path.join(siteThemePath, file), 'utf-8', ); expect(fileContent).toMatchSnapshot(file);