Skip to content

Commit c1823ff

Browse files
committed
fix write-translation bug
1 parent a982482 commit c1823ff

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

packages/docusaurus-utils/src/__tests__/globUtils.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
1428
describe('createMatcher', () => {
1529
it('match default exclude MD/MDX partials correctly', () => {
1630
const matcher = createMatcher(GlobExcludeDefault);

packages/docusaurus-utils/src/globUtils.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)