diff --git a/packages/docusaurus-babel/src/__tests__/babelTranslationsExtractor.test.ts b/packages/docusaurus-babel/src/__tests__/babelTranslationsExtractor.test.ts index b3b08839339f..0f9e3dd6cfb4 100644 --- a/packages/docusaurus-babel/src/__tests__/babelTranslationsExtractor.test.ts +++ b/packages/docusaurus-babel/src/__tests__/babelTranslationsExtractor.test.ts @@ -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'; @@ -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/, ); }); diff --git a/packages/docusaurus-babel/src/babelTranslationsExtractor.ts b/packages/docusaurus-babel/src/babelTranslationsExtractor.ts index 744f1aaa2161..e53d21ce1a81 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}, + ); } } diff --git a/packages/docusaurus-theme-translations/src/__tests__/utils.test.ts b/packages/docusaurus-theme-translations/src/__tests__/utils.test.ts index 775a83f5804e..08ccf37e999c 100644 --- a/packages/docusaurus-theme-translations/src/__tests__/utils.test.ts +++ b/packages/docusaurus-theme-translations/src/__tests__/utils.test.ts @@ -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 text. - File: packages/docusaurus-theme-translations/src/__tests__/__fixtures__/theme/index.js at line 5 + File: /packages/docusaurus-theme-translations/src/__tests__/__fixtures__/theme/index.js at line 5 Full code: {index} ] `); diff --git a/packages/docusaurus-theme-translations/src/utils.ts b/packages/docusaurus-theme-translations/src/utils.ts index 9b3d313ff798..6eda4f98919a 100644 --- a/packages/docusaurus-theme-translations/src/utils.ts +++ b/packages/docusaurus-theme-translations/src/utils.ts @@ -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')} diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json index 6013310d1e3a..e80ebf9152cf 100644 --- a/packages/docusaurus-utils/package.json +++ b/packages/docusaurus-utils/package.json @@ -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", @@ -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", diff --git a/packages/docusaurus-utils/src/globUtils.ts b/packages/docusaurus-utils/src/globUtils.ts index ba6b5589751f..c26e84ab65d7 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 d5074697ecc0..f0b9d51bcb0e 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 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 diff --git a/packages/docusaurus/src/commands/writeHeadingIds.ts b/packages/docusaurus/src/commands/writeHeadingIds.ts index ae1033f68793..c5d6cf50e46f 100644 --- a/packages/docusaurus/src/commands/writeHeadingIds.ts +++ b/packages/docusaurus/src/commands/writeHeadingIds.ts @@ -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}`; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 482cfebbe6f7..c17cde0dc4c0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1928,9 +1928,6 @@ importers: github-slugger: specifier: ^2.0.0 version: 2.0.0 - globby: - specifier: ^11.1.0 - version: 11.1.0 gray-matter: specifier: ^4.0.3 version: 4.0.3 @@ -1955,6 +1952,9 @@ importers: resolve-pathname: specifier: ^3.0.0 version: 3.0.0 + tinyglobby: + specifier: ^0.2.15 + version: 0.2.16 tslib: specifier: ^2.6.0 version: 2.8.1 @@ -6483,10 +6483,6 @@ packages: array-timsort@1.0.3: resolution: {integrity: sha512-/+3GRL7dDAGEfM6TseQk/U+mi18TU2Ms9I3UlLdUMhz2hbvGNTKdj9xniwXfUqgYhHxRx0+8UnKkvlNwVU+cWQ==} - array-union@2.1.0: - resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} - engines: {node: '>=8'} - array.prototype.findlast@1.2.5: resolution: {integrity: sha512-CVvd6FHg1Z3POpBLxO6E6zr+rSKEQ9L6rZHAaY7lLfhKsWYUBBOuMs0e9o24oopj6H+geRCX0YJ+TJLBK2eHyQ==} engines: {node: '>= 0.4'} @@ -7811,10 +7807,6 @@ packages: devlop@1.1.0: resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==} - dir-glob@3.0.1: - resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} - engines: {node: '>=8'} - dns-packet@5.6.1: resolution: {integrity: sha512-l4gcSouhcgIKRvyy99RNVOgxXiicE+2jZoNmaNmZ6JXiGajBOJAesk1OBlJuM5k2c+eudGdLxDqXuPCKIj6kpw==} engines: {node: '>=6'} @@ -8655,10 +8647,6 @@ packages: resolution: {integrity: sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ==} engines: {node: '>= 0.4'} - globby@11.1.0: - resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==} - engines: {node: '>=10'} - globby@16.2.0: resolution: {integrity: sha512-QrJia2qDf5BB/V6HYlDTs0I0lBahyjLzpGQg3KT7FnCdTonAyPy2RtY802m2k4ALx6Dp752f82WsOczEVr3l6Q==} engines: {node: '>=20'} @@ -18170,8 +18158,6 @@ snapshots: array-timsort@1.0.3: {} - array-union@2.1.0: {} - array.prototype.findlast@1.2.5: dependencies: call-bind: 1.0.9 @@ -19634,10 +19620,6 @@ snapshots: dependencies: dequal: 2.0.3 - dir-glob@3.0.1: - dependencies: - path-type: 4.0.0 - dns-packet@5.6.1: dependencies: '@leichtgewicht/ip-codec': 2.0.5 @@ -20666,15 +20648,6 @@ snapshots: define-properties: 1.2.1 gopd: 1.2.0 - globby@11.1.0: - dependencies: - array-union: 2.1.0 - dir-glob: 3.0.1 - fast-glob: 3.3.3 - ignore: 5.3.2 - merge2: 1.4.1 - slash: 3.0.0 - globby@16.2.0: dependencies: '@sindresorhus/merge-streams': 4.0.0 diff --git a/test/snapshotPathNormalizer.ts b/test/snapshotPathNormalizer.ts index 43f863c46f15..0c5e254a8549 100644 --- a/test/snapshotPathNormalizer.ts +++ b/test/snapshotPathNormalizer.ts @@ -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 @@ -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(); @@ -92,6 +91,7 @@ function normalizeString(value: string): string { (val) => (val.includes('keepAnsi') ? val : stripAnsi(val)), // Replace process.cwd with (val) => val.split(cwd).join(''), + (val) => val.split(posixPath(cwd)).join(''), // In case the CWD is escaped (val) => val.split(cwdEscaped).join(''), diff --git a/website/_dogfooding/testSwizzleThemeClassic.mjs b/website/_dogfooding/testSwizzleThemeClassic.mjs index 364958b4ec74..c294fc198397 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),