This commit is contained in:
Ben McCann 2025-12-23 16:29:21 +01:00 committed by GitHub
commit 9eb934de83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 56 additions and 45 deletions

View File

@ -66,6 +66,9 @@ function normalizePaths<T>(value: T): T {
const cwd = process.cwd();
const cwdReal = getRealPath(cwd);
console.log('CWD:', cwd);
console.log('CWD Real:', cwdReal);
const tempDir = os.tmpdir();
const tempDirReal = getRealPath(tempDir);
const homeDir = os.homedir();

View File

@ -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/,
);
});

View File

@ -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},
);
}
}

View File

@ -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 <Translate id="my-id" description="my-description">text</Translate>.
File: packages/docusaurus-theme-translations/src/__tests__/__fixtures__/theme/index.js at line 4
Full code: <Translate>{index}</Translate>
"
`);
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: <PROJECT_ROOT>/packages/docusaurus-theme-translations/src/__tests__/__fixtures__/theme/index.js at line 4
Full code: <Translate>{index}</Translate>
"
`);
});
});

View File

@ -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",

View File

@ -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<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)
@ -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);
}

View File

@ -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

View File

@ -47,12 +47,11 @@ export async function writeHeadingIds(
): Promise<void> {
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)),

View File

@ -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;
}

View File

@ -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),

View File

@ -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"