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-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index a30480b84025..d3bdae46ce5b 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -399,7 +399,7 @@ export async function generateBlogPosts( const blogSourceFiles = await Globby(include, { cwd: contentPaths.contentPath, - ignore: exclude, + exclude, }); async function doProcessBlogSourceFile(blogSourceFile: string) { diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 06704fbff1dd..c74bccec662b 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -68,7 +68,7 @@ export async function readVersionDocs( ): Promise { const sources = await Globby(options.include, { cwd: versionMetadata.contentPath, - ignore: options.exclude, + exclude: options.exclude, }); return Promise.all( sources.map((source) => readDocFile(versionMetadata, source)), diff --git a/packages/docusaurus-plugin-content-pages/src/__tests__/__snapshots__/index.test.ts.snap b/packages/docusaurus-plugin-content-pages/src/__tests__/__snapshots__/index.test.ts.snap index c6c95b5c6f84..f571e6696324 100644 --- a/packages/docusaurus-plugin-content-pages/src/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/docusaurus-plugin-content-pages/src/__tests__/__snapshots__/index.test.ts.snap @@ -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, @@ -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, @@ -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", @@ -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, @@ -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", @@ -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", + }, ] `; diff --git a/packages/docusaurus-plugin-content-pages/src/content.ts b/packages/docusaurus-plugin-content-pages/src/content.ts index 1ddc6eeb5616..65fa6af26205 100644 --- a/packages/docusaurus-plugin-content-pages/src/content.ts +++ b/packages/docusaurus-plugin-content-pages/src/content.ts @@ -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) { 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..4f605029af68 100644 --- a/packages/docusaurus-theme-translations/src/utils.ts +++ b/packages/docusaurus-theme-translations/src/utils.ts @@ -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)), ); @@ -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')} 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..f632e309bae4 100644 --- a/packages/docusaurus-utils/src/globUtils.ts +++ b/packages/docusaurus-utils/src/globUtils.ts @@ -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 { + 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. @@ -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 { // 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 +165,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..023709fc6ce7 100644 --- a/packages/docusaurus/src/commands/swizzle/actions.ts +++ b/packages/docusaurus/src/commands/swizzle/actions.ts @@ -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 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/packages/docusaurus/src/server/translations/translationsExtractor.ts b/packages/docusaurus/src/server/translations/translationsExtractor.ts index f3a778286e13..bb17ae54beb1 100644 --- a/packages/docusaurus/src/server/translations/translationsExtractor.ts +++ b/packages/docusaurus/src/server/translations/translationsExtractor.ts @@ -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)); @@ -42,7 +42,9 @@ async function getSourceCodeFilePaths( siteDir: string, plugins: InitializedPlugin[], ): Promise { - 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 diff --git a/packages/docusaurus/src/webpack/aliases/index.ts b/packages/docusaurus/src/webpack/aliases/index.ts index 03e14426b04d..3dee22efda9a 100644 --- a/packages/docusaurus/src/webpack/aliases/index.ts +++ b/packages/docusaurus/src/webpack/aliases/index.ts @@ -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}', 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/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), diff --git a/website/src/plugins/changelog/index.ts b/website/src/plugins/changelog/index.ts index da009a7c2caf..248460e4103c 100644 --- a/website/src/plugins/changelog/index.ts +++ b/website/src/plugins/changelog/index.ts @@ -20,10 +20,14 @@ export {validateOptions} from '@docusaurus/plugin-content-blog'; const MonorepoRoot = path.resolve(path.join(__dirname, '../../../..')); -const ChangelogFilePattern = 'CHANGELOG(-v[0-9]*)?.md'; +const ChangelogFileNames = [ + 'CHANGELOG.md', + 'CHANGELOG-v2.md', + 'CHANGELOG-v3.md', +]; async function getChangelogFiles() { - const files = await safeGlobby([ChangelogFilePattern], { + const files = await safeGlobby(ChangelogFileNames, { cwd: MonorepoRoot, }); // As of today, there are 2 changelog files @@ -110,7 +114,7 @@ const ChangelogPlugin: typeof pluginContentBlog = }, getPathsToWatch() { - return [path.join(MonorepoRoot, ChangelogFilePattern)]; + return ChangelogFileNames.map((name) => path.join(MonorepoRoot, name)); }, }; };