File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed
packages/docusaurus-utils/src Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,22 @@ import {
99 GlobExcludeDefault ,
1010 createMatcher ,
1111 createAbsoluteFilePathMatcher ,
12+ isTranslatableSourceFile ,
1213} from '../globUtils' ;
1314
15+ describe ( 'isTranslatableSourceFile' , ( ) => {
16+ it ( 'works' , ( ) => {
17+ expect ( isTranslatableSourceFile ( './xyz.ts' ) ) . toBe ( true ) ;
18+ expect ( isTranslatableSourceFile ( './xyz.tsx' ) ) . toBe ( true ) ;
19+ expect ( isTranslatableSourceFile ( './xyz.js' ) ) . toBe ( true ) ;
20+ expect ( isTranslatableSourceFile ( './xyz.jsx' ) ) . toBe ( true ) ;
21+
22+ expect ( isTranslatableSourceFile ( './xyz.md' ) ) . toBe ( false ) ;
23+ expect ( isTranslatableSourceFile ( './xyz.mdx' ) ) . toBe ( false ) ;
24+ expect ( isTranslatableSourceFile ( './xyz.d.ts' ) ) . toBe ( false ) ;
25+ } ) ;
26+ } ) ;
27+
1428describe ( 'createMatcher' , ( ) => {
1529 it ( 'match default exclude MD/MDX partials correctly' , ( ) => {
1630 const matcher = createMatcher ( GlobExcludeDefault ) ;
Original file line number Diff line number Diff line change @@ -104,11 +104,8 @@ export async function safeGlobby(
104104 return Globby ( globPaths , options ) ;
105105}
106106
107- // A bit weird to put this here, but it's used by core + theme-translations
108- export async function globTranslatableSourceFiles (
109- patterns : string [ ] ,
110- ) : Promise < string [ ] > {
111- // We only support extracting source code translations from these kind of files
107+ export const isTranslatableSourceFile : ( filePath : string ) => boolean = ( ( ) => {
108+ // We only support extracting source code translations from these extensions
112109 const extensionsAllowed = new Set ( [
113110 '.js' ,
114111 '.jsx' ,
@@ -125,9 +122,16 @@ export async function globTranslatableSourceFiles(
125122 return filePath . endsWith ( '.d.ts' ) ;
126123 } ;
127124
128- const filePaths = await safeGlobby ( patterns ) ;
129- return filePaths . filter ( ( filePath ) => {
125+ return ( filePath ) : boolean => {
130126 const ext = path . extname ( filePath ) ;
131127 return extensionsAllowed . has ( ext ) && ! isBlacklistedFilePath ( filePath ) ;
132- } ) ;
128+ } ;
129+ } ) ( ) ;
130+
131+ // A bit weird to put this here, but it's used by core + theme-translations
132+ export async function globTranslatableSourceFiles (
133+ patterns : string [ ] ,
134+ ) : Promise < string [ ] > {
135+ const filePaths = await safeGlobby ( patterns ) ;
136+ return filePaths . filter ( isTranslatableSourceFile ) ;
133137}
You can’t perform that action at this time.
0 commit comments