diff --git a/packages/docusaurus-babel/src/__tests__/babelTranslationsExtractor.test.ts b/packages/docusaurus-babel/src/__tests__/babelTranslationsExtractor.test.ts
index f221bd2350..f38d5650bf 100644
--- a/packages/docusaurus-babel/src/__tests__/babelTranslationsExtractor.test.ts
+++ b/packages/docusaurus-babel/src/__tests__/babelTranslationsExtractor.test.ts
@@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
-import {jest} from '@jest/globals';
import fs from 'fs-extra';
import tmp from 'tmp-promise';
import {getBabelOptions} from '../utils';
@@ -45,16 +44,10 @@ const default => {
`,
});
- const errorMock = jest.spyOn(console, 'error').mockImplementation(() => {});
-
await expect(
extractSourceCodeFileTranslations(sourceCodeFilePath, TestBabelOptions),
- ).rejects.toThrow();
-
- expect(errorMock).toHaveBeenCalledWith(
- expect.stringMatching(
- /Error while attempting to extract Docusaurus translations from source code file at/,
- ),
+ ).rejects.toThrow(
+ /Error while attempting to extract Docusaurus translations from source code file at/,
);
});
diff --git a/packages/docusaurus-babel/src/babelTranslationsExtractor.ts b/packages/docusaurus-babel/src/babelTranslationsExtractor.ts
index 744f1aaa21..9675d1176f 100644
--- a/packages/docusaurus-babel/src/babelTranslationsExtractor.ts
+++ b/packages/docusaurus-babel/src/babelTranslationsExtractor.ts
@@ -6,7 +6,6 @@
*/
import fs from 'fs-extra';
-import logger from '@docusaurus/logger';
import traverse, {type Node} from '@babel/traverse';
import generate from '@babel/generator';
import {
@@ -15,6 +14,7 @@ import {
type NodePath,
type TransformOptions,
} from '@babel/core';
+import {logger} from '@docusaurus/logger';
import type {TranslationFileContent} from '@docusaurus/types';
export type SourceCodeFileTranslations = {
@@ -56,8 +56,10 @@ export async function extractSourceCodeFileTranslations(
);
return translations;
} catch (err) {
- logger.error`Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}.`;
- throw err;
+ throw new Error(
+ logger.interpolate`Error while attempting to extract Docusaurus translations from source code file at path=${sourceCodeFilePath}.`,
+ {cause: err as Error},
+ );
}
}
diff --git a/packages/docusaurus-theme-translations/src/__tests__/utils.test.ts b/packages/docusaurus-theme-translations/src/__tests__/utils.test.ts
index 2f8949b55f..3b86d354ad 100644
--- a/packages/docusaurus-theme-translations/src/__tests__/utils.test.ts
+++ b/packages/docusaurus-theme-translations/src/__tests__/utils.test.ts
@@ -13,14 +13,14 @@ describe('extractThemeCodeMessages', () => {
await expect(() =>
extractThemeCodeMessages([path.join(__dirname, '__fixtures__/theme')]),
).rejects.toThrowErrorMatchingInlineSnapshot(`
- "
- Please make sure all theme translations are static!
- Some warnings were found!
+ "
+ Please make sure all theme translations are static!
+ Some warnings were found!
- Translate content could not be extracted. It has to be a static string and use optional but static props, like text.
- File: packages/docusaurus-theme-translations/src/__tests__/__fixtures__/theme/index.js at line 4
- Full code: {index}
- "
- `);
+ Translate content could not be extracted. It has to be a static string and use optional but static props, like text.
+ File: /packages/docusaurus-theme-translations/src/__tests__/__fixtures__/theme/index.js at line 4
+ Full code: {index}
+ "
+ `);
});
});
diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json
index 7e775a0117..c0a2884f83 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",
@@ -35,6 +34,7 @@
"p-queue": "^6.6.2",
"prompts": "^2.4.2",
"resolve-pathname": "^3.0.0",
+ "tinyglobby": "^0.2.15",
"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 ba6b558975..c26e84ab65 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 'globby';
+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.GlobbyOptions,
+ 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)
@@ -132,6 +136,8 @@ export const isTranslatableSourceFile: (filePath: string) => boolean = (() => {
export async function globTranslatableSourceFiles(
patterns: string[],
): Promise {
- const filePaths = await safeGlobby(patterns);
+ const filePaths = await safeGlobby(patterns, {
+ absolute: true,
+ });
return filePaths.filter(isTranslatableSourceFile);
}
diff --git a/packages/docusaurus/src/commands/swizzle/actions.ts b/packages/docusaurus/src/commands/swizzle/actions.ts
index d5074697ec..32f90cbf21 100644
--- a/packages/docusaurus/src/commands/swizzle/actions.ts
+++ b/packages/docusaurus/src/commands/swizzle/actions.ts
@@ -62,6 +62,12 @@ export async function eject({
const globPatternPosix = posixPath(globPattern);
const filesToCopy = await Globby(globPatternPosix, {
+ // Workaround for Tinyglobby bug?
+ // We glob from the repo root, not from the website dir
+ // See https://github.com/SuperchupuDev/tinyglobby/issues/186
+ cwd: path.join(process.cwd(), '..'),
+ absolute: true,
+
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/server/translations/__tests__/translationsExtractor.test.ts b/packages/docusaurus/src/server/translations/__tests__/translationsExtractor.test.ts
index 69c9ec4683..f626494214 100644
--- a/packages/docusaurus/src/server/translations/__tests__/translationsExtractor.test.ts
+++ b/packages/docusaurus/src/server/translations/__tests__/translationsExtractor.test.ts
@@ -17,6 +17,7 @@ async function createTmpDir() {
const {path: siteDirPath} = await tmp.dir({
prefix: 'jest-createTmpSiteDir',
});
+ console.log(`Created temporary directory at ${siteDirPath}`);
return siteDirPath;
}
diff --git a/website/_dogfooding/testSwizzleThemeClassic.mjs b/website/_dogfooding/testSwizzleThemeClassic.mjs
index 364958b4ec..c294fc1983 100644
--- a/website/_dogfooding/testSwizzleThemeClassic.mjs
+++ b/website/_dogfooding/testSwizzleThemeClassic.mjs
@@ -80,6 +80,7 @@ async function getAllComponentNames() {
}
const componentNames = await getAllComponentNames();
+console.log('componentNames', componentNames);
const componentsNotFound = Object.keys(swizzleConfig.components).filter(
(componentName) => !componentNames.includes(componentName),
diff --git a/yarn.lock b/yarn.lock
index deea90e6bc..5d69849ae2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -8994,10 +8994,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.5.0:
+ version "6.5.0"
+ resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.5.0.tgz#ed2ab967a331ade62f18d077dae192684d50d350"
+ integrity sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==
feed@^4.2.2:
version "4.2.2"
@@ -14531,10 +14531,10 @@ picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.2, picomatch@^2.2.3, picomatc
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
-picomatch@^4.0.2:
- version "4.0.2"
- resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-4.0.2.tgz#77c742931e8f3b8820946c76cd0c1f13730d1dab"
- integrity sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==
+picomatch@^4.0.2, picomatch@^4.0.3:
+ version "4.0.3"
+ resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-4.0.3.tgz#796c76136d1eead715db1e7bad785dedd695a042"
+ integrity sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==
pidtree@^0.3.0:
version "0.3.1"
@@ -17713,13 +17713,13 @@ 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.15:
+ version "0.2.15"
+ resolved "https://registry.yarnpkg.com/tinyglobby/-/tinyglobby-0.2.15.tgz#e228dd1e638cea993d2fdb4fcd2d4602a79951c2"
+ integrity sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==
dependencies:
- fdir "^6.4.3"
- picomatch "^4.0.2"
+ fdir "^6.5.0"
+ picomatch "^4.0.3"
tinypool@^1.0.2:
version "1.0.2"