From 784b443cfe82d9c39f15fa799fe1d5b9d33af07b Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 28 Mar 2025 10:30:42 -0700 Subject: [PATCH 1/9] chore: switch to tinyglobby --- packages/docusaurus-utils/package.json | 2 +- packages/docusaurus-utils/src/globUtils.ts | 6 +++--- .../docusaurus/src/commands/swizzle/actions.ts | 2 +- .../docusaurus/src/commands/writeHeadingIds.ts | 11 +++++------ .../docusaurus/src/webpack/aliases/index.ts | 2 +- yarn.lock | 18 +++++++++--------- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json index 7dde60ae3a..f1ee86dfb9 100644 --- a/packages/docusaurus-utils/package.json +++ b/packages/docusaurus-utils/package.json @@ -26,7 +26,6 @@ "file-loader": "^6.2.0", "fs-extra": "^11.1.1", "github-slugger": "^1.5.0", - "globby": "^11.1.0", "gray-matter": "^4.0.3", "jiti": "^1.20.0", "js-yaml": "^4.1.0", @@ -34,6 +33,7 @@ "micromatch": "^4.0.5", "prompts": "^2.4.2", "resolve-pathname": "^3.0.0", + "tinyglobby": "^0.2.12", "tslib": "^2.6.0", "url-loader": "^4.1.1", "utility-types": "^3.10.0", diff --git a/packages/docusaurus-utils/src/globUtils.ts b/packages/docusaurus-utils/src/globUtils.ts index c7e2cab134..0f1b14e244 100644 --- a/packages/docusaurus-utils/src/globUtils.ts +++ b/packages/docusaurus-utils/src/globUtils.ts @@ -10,7 +10,7 @@ import path from 'path'; import Micromatch from 'micromatch'; // Note: Micromatch is used by Globby import {addSuffix} from '@docusaurus/utils-common'; -import Globby from 'globby'; +import Globby from 'tinyglobby'; import {posixPath} from './pathUtils'; /** A re-export of the globby instance. */ @@ -93,7 +93,7 @@ export function createAbsoluteFilePathMatcher( // See https://github.com/facebook/docusaurus/pull/4222#issuecomment-795517329 export async function safeGlobby( patterns: string[], - options?: Globby.GlobbyOptions, + options?: Globby.GlobOptions, ): Promise { // Required for Windows support, as paths using \ should not be used by globby // (also using the windows hard drive prefix like c: is not a good idea) @@ -101,7 +101,7 @@ export async function safeGlobby( posixPath(path.relative(process.cwd(), dirPath)), ); - return Globby(globPaths, options); + return Globby.glob(globPaths, options); } // A bit weird to put this here, but it's used by core + theme-translations diff --git a/packages/docusaurus/src/commands/swizzle/actions.ts b/packages/docusaurus/src/commands/swizzle/actions.ts index d5074697ec..597d4abc90 100644 --- a/packages/docusaurus/src/commands/swizzle/actions.ts +++ b/packages/docusaurus/src/commands/swizzle/actions.ts @@ -61,7 +61,7 @@ export async function eject({ const globPatternPosix = posixPath(globPattern); - const filesToCopy = await Globby(globPatternPosix, { + const filesToCopy = await Globby.glob(globPatternPosix, { ignore: _.compact([ '**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}', // When ejecting JS components, we want to avoid emitting TS files diff --git a/packages/docusaurus/src/commands/writeHeadingIds.ts b/packages/docusaurus/src/commands/writeHeadingIds.ts index 3963270dc5..7cbda95206 100644 --- a/packages/docusaurus/src/commands/writeHeadingIds.ts +++ b/packages/docusaurus/src/commands/writeHeadingIds.ts @@ -47,12 +47,11 @@ export async function writeHeadingIds( ): Promise { const siteDir = await fs.realpath(siteDirParam); - const markdownFiles = await safeGlobby( - files ?? (await getPathsToWatch(siteDir)), - { - expandDirectories: ['**/*.{md,mdx}'], - }, - ); + const markdownFiles = ( + await safeGlobby(files ?? (await getPathsToWatch(siteDir)), { + expandDirectories: true, + }) + ).filter((file) => file.endsWith('.md') || file.endsWith('.mdx')); const result = await Promise.all( markdownFiles.map((p) => transformMarkdownFile(p, options)), diff --git a/packages/docusaurus/src/webpack/aliases/index.ts b/packages/docusaurus/src/webpack/aliases/index.ts index dbade3a77e..7fc59ee6b2 100644 --- a/packages/docusaurus/src/webpack/aliases/index.ts +++ b/packages/docusaurus/src/webpack/aliases/index.ts @@ -51,7 +51,7 @@ export async function createAliasesForTheme( return {}; } - const themeComponentFiles = await Globby(['**/*.{js,jsx,ts,tsx}'], { + const themeComponentFiles = await Globby.glob(['**/*.{js,jsx,ts,tsx}'], { cwd: themePath, }); diff --git a/yarn.lock b/yarn.lock index f90d6cc687..b40d2606a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8556,10 +8556,10 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" -fdir@^6.4.0: - version "6.4.2" - resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.2.tgz#ddaa7ce1831b161bc3657bb99cb36e1622702689" - integrity sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ== +fdir@^6.4.0, fdir@^6.4.3: + version "6.4.3" + resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.3.tgz#011cdacf837eca9b811c89dbb902df714273db72" + integrity sha512-PMXmW2y1hDDfTSRc9gaXIuCCRpuoz3Kaz8cUelp3smouvfT632ozg2vrT6lJsHKKOF59YLbOGfAWGUcKEfRMQw== feed@^4.2.2: version "4.2.2" @@ -17231,12 +17231,12 @@ tinyexec@^0.3.0: resolved "https://registry.yarnpkg.com/tinyexec/-/tinyexec-0.3.0.tgz#ed60cfce19c17799d4a241e06b31b0ec2bee69e6" integrity sha512-tVGE0mVJPGb0chKhqmsoosjsS+qUnJVGJpZgsHYQcGoPlG3B51R3PouqTgEGH2Dc9jjFyOqOpix6ZHNMXp1FZg== -tinyglobby@^0.2.9: - version "0.2.9" - resolved "https://registry.yarnpkg.com/tinyglobby/-/tinyglobby-0.2.9.tgz#6baddd1b0fe416403efb0dd40442c7d7c03c1c66" - integrity sha512-8or1+BGEdk1Zkkw2ii16qSS7uVrQJPre5A9o/XkWPATkk23FZh/15BKFxPnlTy6vkljZxLqYCzzBMj30ZrSvjw== +tinyglobby@^0.2.12, tinyglobby@^0.2.9: + version "0.2.12" + resolved "https://registry.yarnpkg.com/tinyglobby/-/tinyglobby-0.2.12.tgz#ac941a42e0c5773bd0b5d08f32de82e74a1a61b5" + integrity sha512-qkf4trmKSIiMTs/E63cxH+ojC2unam7rJ0WrauAzpT3ECNTxGRMlaXxVbfxMUC/w0LaYk6jQ4y/nGR9uBO3tww== dependencies: - fdir "^6.4.0" + fdir "^6.4.3" picomatch "^4.0.2" tinypool@^1.0.2: From b1ddd480069a3da6991e53aaf60328a513ffcf2e Mon Sep 17 00:00:00 2001 From: sebastien Date: Tue, 8 Apr 2025 14:37:09 +0200 Subject: [PATCH 2/9] fix tinyglobby integration --- packages/docusaurus-utils/src/globUtils.ts | 12 ++++++++---- packages/docusaurus/src/commands/swizzle/actions.ts | 2 +- packages/docusaurus/src/webpack/aliases/index.ts | 2 +- yarn.lock | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/docusaurus-utils/src/globUtils.ts b/packages/docusaurus-utils/src/globUtils.ts index 0f1b14e244..561ea6649f 100644 --- a/packages/docusaurus-utils/src/globUtils.ts +++ b/packages/docusaurus-utils/src/globUtils.ts @@ -10,11 +10,15 @@ import path from 'path'; import Micromatch from 'micromatch'; // Note: Micromatch is used by Globby import {addSuffix} from '@docusaurus/utils-common'; -import Globby from 'tinyglobby'; +import * as Tinyglobby from 'tinyglobby'; import {posixPath} from './pathUtils'; +type GlobOptions = Tinyglobby.GlobOptions; + +// TODO Docusaurus v4 refactor, hide lib behind home-made abstraction +// See https://github.com/facebook/docusaurus/pull/11042 /** A re-export of the globby instance. */ -export {Globby}; +export const Globby = Tinyglobby.glob; /** * The default glob patterns we ignore when sourcing content. @@ -93,7 +97,7 @@ export function createAbsoluteFilePathMatcher( // See https://github.com/facebook/docusaurus/pull/4222#issuecomment-795517329 export async function safeGlobby( patterns: string[], - options?: Globby.GlobOptions, + options?: GlobOptions, ): Promise { // Required for Windows support, as paths using \ should not be used by globby // (also using the windows hard drive prefix like c: is not a good idea) @@ -101,7 +105,7 @@ export async function safeGlobby( posixPath(path.relative(process.cwd(), dirPath)), ); - return Globby.glob(globPaths, options); + return Globby(globPaths, options); } // A bit weird to put this here, but it's used by core + theme-translations diff --git a/packages/docusaurus/src/commands/swizzle/actions.ts b/packages/docusaurus/src/commands/swizzle/actions.ts index 597d4abc90..d5074697ec 100644 --- a/packages/docusaurus/src/commands/swizzle/actions.ts +++ b/packages/docusaurus/src/commands/swizzle/actions.ts @@ -61,7 +61,7 @@ export async function eject({ const globPatternPosix = posixPath(globPattern); - const filesToCopy = await Globby.glob(globPatternPosix, { + const filesToCopy = await Globby(globPatternPosix, { ignore: _.compact([ '**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}', // When ejecting JS components, we want to avoid emitting TS files diff --git a/packages/docusaurus/src/webpack/aliases/index.ts b/packages/docusaurus/src/webpack/aliases/index.ts index 7fc59ee6b2..dbade3a77e 100644 --- a/packages/docusaurus/src/webpack/aliases/index.ts +++ b/packages/docusaurus/src/webpack/aliases/index.ts @@ -51,7 +51,7 @@ export async function createAliasesForTheme( return {}; } - const themeComponentFiles = await Globby.glob(['**/*.{js,jsx,ts,tsx}'], { + const themeComponentFiles = await Globby(['**/*.{js,jsx,ts,tsx}'], { cwd: themePath, }); diff --git a/yarn.lock b/yarn.lock index b40d2606a1..8824d75bd2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8556,7 +8556,7 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" -fdir@^6.4.0, fdir@^6.4.3: +fdir@^6.4.3: version "6.4.3" resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.3.tgz#011cdacf837eca9b811c89dbb902df714273db72" integrity sha512-PMXmW2y1hDDfTSRc9gaXIuCCRpuoz3Kaz8cUelp3smouvfT632ozg2vrT6lJsHKKOF59YLbOGfAWGUcKEfRMQw== From 32c5be420f088801a535da28e075a97ad08a8415 Mon Sep 17 00:00:00 2001 From: sebastien Date: Tue, 8 Apr 2025 16:20:04 +0200 Subject: [PATCH 3/9] spelling --- project-words.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project-words.txt b/project-words.txt index 1e3d534595..3bd183e242 100644 --- a/project-words.txt +++ b/project-words.txt @@ -331,6 +331,8 @@ Tagkey Teik Therox thisweekinreact +Tinyglobby +tinyglobby toplevel Transifex transpiles From 3a7fc225b5a2e990cf151af4718fb8eeba9f3386 Mon Sep 17 00:00:00 2001 From: sebastien Date: Tue, 8 Apr 2025 16:20:48 +0200 Subject: [PATCH 4/9] empty From e0d3696f649dc65ded792a4fc16c92921b89db0a Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 19 Apr 2025 11:47:26 -0700 Subject: [PATCH 5/9] upgrade tinyglobby --- packages/docusaurus-utils/package.json | 2 +- yarn.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json index f1ee86dfb9..4951bc15fe 100644 --- a/packages/docusaurus-utils/package.json +++ b/packages/docusaurus-utils/package.json @@ -33,7 +33,7 @@ "micromatch": "^4.0.5", "prompts": "^2.4.2", "resolve-pathname": "^3.0.0", - "tinyglobby": "^0.2.12", + "tinyglobby": "^0.2.13", "tslib": "^2.6.0", "url-loader": "^4.1.1", "utility-types": "^3.10.0", diff --git a/yarn.lock b/yarn.lock index 4f67ec4371..16f1c4d275 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8813,10 +8813,10 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" -fdir@^6.4.3: - version "6.4.3" - resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.3.tgz#011cdacf837eca9b811c89dbb902df714273db72" - integrity sha512-PMXmW2y1hDDfTSRc9gaXIuCCRpuoz3Kaz8cUelp3smouvfT632ozg2vrT6lJsHKKOF59YLbOGfAWGUcKEfRMQw== +fdir@^6.4.3, fdir@^6.4.4: + version "6.4.4" + resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.4.tgz#1cfcf86f875a883e19a8fab53622cfe992e8d2f9" + integrity sha512-1NZP+GK4GfuAv3PqKvxQRDMjdSRZjnkq7KfhlNrCNNlZ0ygQFpebfrnfnq/W7fpUnAv9aGWmY1zKx7FYL3gwhg== feed@^4.2.2: version "4.2.2" @@ -17482,12 +17482,12 @@ tinyexec@^0.3.2: resolved "https://registry.yarnpkg.com/tinyexec/-/tinyexec-0.3.2.tgz#941794e657a85e496577995c6eef66f53f42b3d2" integrity sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA== -tinyglobby@^0.2.12: - version "0.2.12" - resolved "https://registry.yarnpkg.com/tinyglobby/-/tinyglobby-0.2.12.tgz#ac941a42e0c5773bd0b5d08f32de82e74a1a61b5" - integrity sha512-qkf4trmKSIiMTs/E63cxH+ojC2unam7rJ0WrauAzpT3ECNTxGRMlaXxVbfxMUC/w0LaYk6jQ4y/nGR9uBO3tww== +tinyglobby@^0.2.12, tinyglobby@^0.2.13: + version "0.2.13" + resolved "https://registry.yarnpkg.com/tinyglobby/-/tinyglobby-0.2.13.tgz#a0e46515ce6cbcd65331537e57484af5a7b2ff7e" + integrity sha512-mEwzpUgrLySlveBwEVDMKk5B57bhLPYovRfPAXD5gA/98Opn0rCDj3GtLwFvCvH5RK9uPCExUROW5NjDwvqkxw== dependencies: - fdir "^6.4.3" + fdir "^6.4.4" picomatch "^4.0.2" tinypool@^1.0.2: From 1207ebef324f9a412548efe35fdc9b4fdf1b9599 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 19 Apr 2025 14:01:04 -0700 Subject: [PATCH 6/9] update lockfile --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 16f1c4d275..0bca0e0b3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8813,7 +8813,7 @@ fb-watchman@^2.0.0: dependencies: bser "2.1.1" -fdir@^6.4.3, fdir@^6.4.4: +fdir@^6.4.4: version "6.4.4" resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.4.tgz#1cfcf86f875a883e19a8fab53622cfe992e8d2f9" integrity sha512-1NZP+GK4GfuAv3PqKvxQRDMjdSRZjnkq7KfhlNrCNNlZ0ygQFpebfrnfnq/W7fpUnAv9aGWmY1zKx7FYL3gwhg== From cac8d4881d4512986d4c1162bceda3777ef90074 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 25 May 2025 11:47:30 -0700 Subject: [PATCH 7/9] upgrade tinyglobby --- packages/docusaurus-utils/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json index 4951bc15fe..dd9c0d61b8 100644 --- a/packages/docusaurus-utils/package.json +++ b/packages/docusaurus-utils/package.json @@ -33,7 +33,7 @@ "micromatch": "^4.0.5", "prompts": "^2.4.2", "resolve-pathname": "^3.0.0", - "tinyglobby": "^0.2.13", + "tinyglobby": "^0.2.14", "tslib": "^2.6.0", "url-loader": "^4.1.1", "utility-types": "^3.10.0", diff --git a/yarn.lock b/yarn.lock index 0bca0e0b3d..dc7d0e5936 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17482,10 +17482,10 @@ tinyexec@^0.3.2: resolved "https://registry.yarnpkg.com/tinyexec/-/tinyexec-0.3.2.tgz#941794e657a85e496577995c6eef66f53f42b3d2" integrity sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA== -tinyglobby@^0.2.12, tinyglobby@^0.2.13: - version "0.2.13" - resolved "https://registry.yarnpkg.com/tinyglobby/-/tinyglobby-0.2.13.tgz#a0e46515ce6cbcd65331537e57484af5a7b2ff7e" - integrity sha512-mEwzpUgrLySlveBwEVDMKk5B57bhLPYovRfPAXD5gA/98Opn0rCDj3GtLwFvCvH5RK9uPCExUROW5NjDwvqkxw== +tinyglobby@^0.2.12, tinyglobby@^0.2.14: + version "0.2.14" + resolved "https://registry.yarnpkg.com/tinyglobby/-/tinyglobby-0.2.14.tgz#5280b0cf3f972b050e74ae88406c0a6a58f4079d" + integrity sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ== dependencies: fdir "^6.4.4" picomatch "^4.0.2" From 346a349836ee647dc6f63c9bea18fbccde52084a Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 25 May 2025 14:50:43 -0700 Subject: [PATCH 8/9] simplify --- .../src/commands/swizzle/__tests__/index.test.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 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..4fb86c366d 100644 --- a/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts +++ b/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts @@ -91,15 +91,10 @@ 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(siteThemePathPosix, {absolute: true})).sort(); for (const file of files) { - const fileContent = await fs.readFile( - path.posix.join(siteThemePath, file), - 'utf-8', - ); + const fileContent = await fs.readFile(file, 'utf-8'); expect(fileContent).toMatchSnapshot(file); } } From ca54f5dcdc1d7b92967288153f0fcbcf5dc9e9f4 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 25 May 2025 18:14:24 -0700 Subject: [PATCH 9/9] Revert "simplify" This reverts commit 346a349836ee647dc6f63c9bea18fbccde52084a. --- .../src/commands/swizzle/__tests__/index.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts b/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts index 4fb86c366d..013fbab245 100644 --- a/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts +++ b/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts @@ -91,10 +91,15 @@ async function createTestSite() { const siteThemePathPosix = posixPath(siteThemePath); expect(tree(siteThemePathPosix)).toMatchSnapshot('theme dir tree'); - const files = (await Globby(siteThemePathPosix, {absolute: true})).sort(); + const files = (await Globby(siteThemePathPosix)) + .map((file) => path.posix.relative(siteThemePathPosix, file)) + .sort(); for (const file of files) { - const fileContent = await fs.readFile(file, 'utf-8'); + const fileContent = await fs.readFile( + path.posix.join(siteThemePath, file), + 'utf-8', + ); expect(fileContent).toMatchSnapshot(file); } }