Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
784b443
chore: switch to tinyglobby
benmccann Mar 28, 2025
b1ddd48
fix tinyglobby integration
slorber Apr 8, 2025
bbce79b
Merge branch 'main' into tinyglobby
slorber Apr 8, 2025
51d9a1b
Merge branch 'main' into tinyglobby
slorber Apr 8, 2025
32c5be4
spelling
slorber Apr 8, 2025
3a7fc22
empty
slorber Apr 8, 2025
c32f548
merge main
benmccann Apr 9, 2025
e0d3696
upgrade tinyglobby
benmccann Apr 19, 2025
86303b3
Merge branch 'main' into tinyglobby
benmccann Apr 19, 2025
1207ebe
update lockfile
benmccann Apr 19, 2025
cac8d48
upgrade tinyglobby
benmccann May 25, 2025
175cfbf
Merge branch 'main' into tinyglobby
benmccann May 25, 2025
346a349
simplify
benmccann May 25, 2025
ca54f5d
Revert "simplify"
benmccann May 26, 2025
d98d5b9
Merge branch 'main' into tinyglobby
benmccann May 26, 2025
ac90682
try upgrade
slorber Dec 5, 2025
18b4031
Merge branch 'main' into tinyglobby
slorber Dec 5, 2025
dd0ee05
lockfile
slorber Dec 5, 2025
d168d18
log component names to swizzle
slorber Dec 5, 2025
e3e5fe6
try to ignore tests on windows?
slorber Dec 5, 2025
a61d775
try to ignore tests on windows?
slorber Dec 5, 2025
3b687a5
Merge branch 'main' into tinyglobby
slorber Dec 23, 2025
feebe31
try to fix tinyglobby swizzle CI bug?
slorber Dec 23, 2025
4593f3a
remove useless log
slorber Dec 23, 2025
267a800
test log
slorber Dec 23, 2025
1c13e46
try to fix tinyglobby error on windows
slorber Dec 23, 2025
f2edb91
try to fix tinyglobby
slorber Dec 23, 2025
fafe9f5
test windows
slorber Dec 23, 2025
787ed3c
remove logs
slorber Dec 31, 2025
7920f5b
Merge branch 'main' into tinyglobby
slorber Dec 31, 2025
c57db48
try to normalize windows paths
slorber Dec 31, 2025
8dcf233
remove log
slorber Jan 1, 2026
5389e3a
remove absolute glob translations
slorber Jan 1, 2026
736aaa5
remove absolute glob translations
slorber Jan 1, 2026
2b1dcce
improve eject glob workaround
slorber Jan 1, 2026
77da395
fix windows globbing issue again?
slorber Jan 1, 2026
f0f37b3
Merge branch 'main' into tinyglobby
slorber Jun 12, 2026
22e5fe5
fix snapshot
slorber Jun 12, 2026
8af4f01
fix extractSourceCodeFileTranslations
slorber Jun 12, 2026
f85bb9d
try migrate globUtils
slorber Jun 12, 2026
3cdacd8
try migrate globUtils
slorber Jun 12, 2026
141f3b5
migrate glob options
slorber Jun 12, 2026
3ceeea9
poc migration of glob native failures
slorber Jun 12, 2026
414d340
update snapshot
slorber Jun 12, 2026
f6a18df
fix changelog plugin
slorber Jun 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {describe, expect, it, vi} from 'vitest';
import {describe, expect, it} from 'vitest';
import fs from 'fs-extra';
import {mkdtempDisposable, realpath} from 'node:fs/promises';
import {tmpdir} from 'node:os';
Expand Down Expand Up @@ -53,16 +53,10 @@ const default => {
`,
});

using error = vi.spyOn(console, 'error');

await expect(
extractSourceCodeFileTranslations(sourceCodeFile.path, TestBabelOptions),
).rejects.toThrow();

expect(error).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/,
);
});

Expand Down
8 changes: 5 additions & 3 deletions packages/docusaurus-babel/src/babelTranslationsExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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},
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export async function generateBlogPosts(

const blogSourceFiles = await Globby(include, {
cwd: contentPaths.contentPath,
ignore: exclude,
exclude,
});

async function doProcessBlogSourceFile(blogSourceFile: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function readVersionDocs(
): Promise<DocFile[]> {
const sources = await Globby(options.include, {
cwd: versionMetadata.contentPath,
ignore: options.exclude,
exclude: options.exclude,
});
return Promise.all(
sources.map((source) => readDocFile(versionMetadata, source)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

exports[`docusaurus-plugin-content-pages > loads simple pages 1`] = `
[
{
"permalink": "/",
"source": "@site/src/pages/index.js",
"type": "jsx",
},
{
"permalink": "/typescript",
"source": "@site/src/pages/typescript.tsx",
"type": "jsx",
},
{
"description": "Markdown index page",
"editUrl": undefined,
Expand Down Expand Up @@ -67,21 +57,21 @@ exports[`docusaurus-plugin-content-pages > loads simple pages 1`] = `
"source": "@site/src/pages/hello/world.js",
"type": "jsx",
},
]
`;

exports[`docusaurus-plugin-content-pages > loads simple pages with french translations (translate: false) 1`] = `
[
{
"permalink": "/fr/",
"permalink": "/",
"source": "@site/src/pages/index.js",
"type": "jsx",
},
{
"permalink": "/fr/typescript",
"permalink": "/typescript",
"source": "@site/src/pages/typescript.tsx",
"type": "jsx",
},
]
`;

exports[`docusaurus-plugin-content-pages > loads simple pages with french translations (translate: false) 1`] = `
[
{
"description": "Markdown index page",
"editUrl": undefined,
Expand Down Expand Up @@ -137,11 +127,6 @@ exports[`docusaurus-plugin-content-pages > loads simple pages with french transl
"source": "@site/src/pages/hello/world.js",
"type": "jsx",
},
]
`;

exports[`docusaurus-plugin-content-pages > loads simple pages with french translations 1`] = `
[
{
"permalink": "/fr/",
"source": "@site/src/pages/index.js",
Expand All @@ -152,6 +137,11 @@ exports[`docusaurus-plugin-content-pages > loads simple pages with french transl
"source": "@site/src/pages/typescript.tsx",
"type": "jsx",
},
]
`;

exports[`docusaurus-plugin-content-pages > loads simple pages with french translations 1`] = `
[
{
"description": "Markdown index page",
"editUrl": undefined,
Expand Down Expand Up @@ -207,21 +197,21 @@ exports[`docusaurus-plugin-content-pages > loads simple pages with french transl
"source": "@site/src/pages/hello/world.js",
"type": "jsx",
},
]
`;

exports[`docusaurus-plugin-content-pages > loads simple pages with last update 1`] = `
[
{
"permalink": "/",
"permalink": "/fr/",
"source": "@site/src/pages/index.js",
"type": "jsx",
},
{
"permalink": "/typescript",
"permalink": "/fr/typescript",
"source": "@site/src/pages/typescript.tsx",
"type": "jsx",
},
]
`;

exports[`docusaurus-plugin-content-pages > loads simple pages with last update 1`] = `
[
{
"description": "Markdown index page",
"editUrl": "url placeholder",
Expand Down Expand Up @@ -277,5 +267,15 @@ exports[`docusaurus-plugin-content-pages > loads simple pages with last update 1
"source": "@site/src/pages/hello/world.js",
"type": "jsx",
},
{
"permalink": "/",
"source": "@site/src/pages/index.js",
"type": "jsx",
},
{
"permalink": "/typescript",
"source": "@site/src/pages/typescript.tsx",
"type": "jsx",
},
]
`;
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-pages/src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function loadPagesContent(

const pagesFiles = await Globby(params.options.include, {
cwd: params.contentPaths.contentPath,
ignore: options.exclude,
exclude: options.exclude,
});

async function doProcessPageSourceFile(relativeSource: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ describe('extractThemeCodeMessages', () => {
await expect(() =>
extractThemeCodeMessages([path.join(__dirname, '__fixtures__/theme')]),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[Error:
Please make sure all theme translations are static!
[Error: 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 <Translate id="my-id" description="my-description">text</Translate>.
File: packages/docusaurus-theme-translations/src/__tests__/__fixtures__/theme/index.js at line 5
File: <PROJECT_ROOT>/packages/docusaurus-theme-translations/src/__tests__/__fixtures__/theme/index.js at line 5
Full code: <Translate>{index}</Translate>
]
`);
Expand Down
7 changes: 4 additions & 3 deletions packages/docusaurus-theme-translations/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export async function extractThemeCodeMessages(
// eslint-disable-next-line no-param-reassign
targetDirs ??= (await getThemes()).flatMap((theme) => theme.src);

const filePaths = (await globTranslatableSourceFiles(targetDirs)).filter(
const patterns = targetDirs.map((dir) => path.join(dir, '**/*'));

const filePaths = (await globTranslatableSourceFiles(patterns)).filter(
(filePath) => ['.js', '.jsx'].includes(path.extname(filePath)),
);

Expand All @@ -72,8 +74,7 @@ export async function extractThemeCodeMessages(

filesExtractedTranslations.forEach((fileExtractedTranslations) => {
if (fileExtractedTranslations.warnings.length > 0) {
throw new Error(`
Please make sure all theme translations are static!
throw new Error(`Please make sure all theme translations are static!
Some warnings were found!

${fileExtractedTranslations.warnings.join('\n\n')}
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"file-loader": "^6.2.0",
"fs-extra": "^11.2.0",
"github-slugger": "^2.0.0",
"globby": "^11.1.0",
"gray-matter": "^4.0.3",
"jiti": "^2.7.0",
"js-yaml": "^4.1.0",
Expand All @@ -34,6 +33,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",
Expand Down
45 changes: 40 additions & 5 deletions packages/docusaurus-utils/src/globUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,46 @@
// Globby/Micromatch are the 2 libs we use in Docusaurus consistently

import path from 'path';
import {glob} from 'node:fs/promises';
import Micromatch from 'micromatch'; // Note: Micromatch is used by Globby
import {addSuffix} from '@docusaurus/utils-common';
import Globby from 'globby';
import {posixPath} from './pathUtils';

/** A re-export of the globby instance. */
export {Globby};
type GlobOptions = {
cwd?: string;
absolute?: boolean;
exclude?: ((fileName: string) => boolean) | readonly string[];
expandDirectories?: boolean;
};

export async function Globby(
patterns: string | readonly string[],
options: GlobOptions = {},
): Promise<string[]> {
const {absolute, cwd, exclude, expandDirectories} = options;

console.log({patterns, expandDirectories}); // TODO wire expandDirectories ?

const files = await Array.fromAsync(
glob(patterns, {patterns, cwd, exclude, withFileTypes: true} as any),
);

const filePaths = files
.filter((d) => d.isFile())
.map((d) => {
const absolutePath = path.join(d.parentPath, d.name);
if (absolute) {
return absolutePath;
} else {
return path.relative(cwd ?? process.cwd(), absolutePath);
}
});

console.log({filePaths});
filePaths.sort();

return filePaths;
}

/**
* The default glob patterns we ignore when sourcing content.
Expand Down Expand Up @@ -93,7 +126,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<string[]> {
// 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)
Expand Down Expand Up @@ -132,6 +165,8 @@ export const isTranslatableSourceFile: (filePath: string) => boolean = (() => {
export async function globTranslatableSourceFiles(
patterns: string[],
): Promise<string[]> {
const filePaths = await safeGlobby(patterns);
const filePaths = await safeGlobby(patterns, {
absolute: true,
});
return filePaths.filter(isTranslatableSourceFile);
}
4 changes: 3 additions & 1 deletion packages/docusaurus/src/commands/swizzle/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export async function eject({
const globPatternPosix = posixPath(globPattern);

const filesToCopy = await Globby(globPatternPosix, {
ignore: _.compact([
cwd: themePath,
absolute: true,
exclude: _.compact([
'**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}',
// When ejecting JS components, we want to avoid emitting TS files
// In particular the .d.ts files that theme build output contains
Expand Down
8 changes: 5 additions & 3 deletions packages/docusaurus/src/commands/writeHeadingIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ export async function writeHeadingIds(

const patterns = files.length ? files : await getPathsToWatch(siteDir);

const markdownFiles = await safeGlobby(patterns, {
expandDirectories: ['**/*.{md,mdx}'],
});
const markdownFiles = (
await safeGlobby(patterns, {
expandDirectories: true,
})
).filter((file) => file.endsWith('.md') || file.endsWith('.mdx'));

if (markdownFiles.length === 0) {
logger.warn`No markdown files found in siteDir path=${siteDir} for patterns: ${patterns}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getPluginSourceCodeFilePaths(plugin: InitializedPlugin): string[] {
// We also include theme code
const themePath = plugin.getThemePath?.();
if (themePath) {
codePaths.push(themePath);
codePaths.push(nodePath.join(themePath, '**/*'));
}

return codePaths.map((p) => nodePath.resolve(plugin.path, p));
Expand All @@ -42,7 +42,9 @@ async function getSourceCodeFilePaths(
siteDir: string,
plugins: InitializedPlugin[],
): Promise<string[]> {
const sitePaths = getSiteSourceCodeFilePaths(siteDir);
const sitePaths = getSiteSourceCodeFilePaths(siteDir).map((p) =>
nodePath.join(p, '**/*'),
);

// The getPathsToWatch() generally returns the js/jsx/ts/tsx/md/mdx file paths
// We can use this method as well to know which folders we should try to
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/webpack/aliases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function createAliasesForTheme(

const themeComponentFiles = await Globby(['**/*.{js,jsx,ts,tsx}'], {
cwd: themePath,
ignore: [
exclude: [
// Ignore co-located test files
'**/__tests__/**',
'**/*.test.{js,jsx,ts,tsx}',
Expand Down
Loading
Loading