Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 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
f2b3e18
windows fix?
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
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
3 changes: 1 addition & 2 deletions packages/docusaurus-theme-translations/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,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
14 changes: 10 additions & 4 deletions packages/docusaurus-utils/src/globUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<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 +136,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);
}
6 changes: 6 additions & 0 deletions packages/docusaurus/src/commands/swizzle/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export async function eject({
const globPatternPosix = posixPath(globPattern);

const filesToCopy = await Globby(globPatternPosix, {
// Workaround for Tinyglobby bug?
// We glob absolute from the theme root path, not from cwd
// See https://github.com/SuperchupuDev/tinyglobby/issues/186
cwd: themePath,
absolute: true,

ignore: _.compact([
'**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}',
// When ejecting JS components, we want to avoid emitting TS files
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
33 changes: 3 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/snapshotPathNormalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import fs from 'fs';
import _ from 'lodash';
import stripAnsi from 'strip-ansi';
import {version} from '../packages/docusaurus/package.json';
import {posixPath} from '../packages/docusaurus-utils/src';

/*
This weird thing is to normalize paths on our Windows GitHub Actions runners
Expand All @@ -41,8 +42,6 @@ function readPathsForNormalization() {
const cwd = process.cwd();
const cwdEscaped = escapePath(cwd);

console.log({cwd, cwdEscaped});

const tempDir = os.tmpdir();
const homeDir = os.homedir();

Expand Down Expand Up @@ -92,6 +91,7 @@ function normalizeString(value: string): string {
(val) => (val.includes('keepAnsi') ? val : stripAnsi(val)),
// Replace process.cwd with <PROJECT_ROOT>
(val) => val.split(cwd).join('<PROJECT_ROOT>'),
(val) => val.split(posixPath(cwd)).join('<PROJECT_ROOT>'),
// In case the CWD is escaped
(val) => val.split(cwdEscaped).join('<PROJECT_ROOT>'),

Expand Down
1 change: 1 addition & 0 deletions website/_dogfooding/testSwizzleThemeClassic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading