fix(core): Treat .mts files as TypeScript modules instead of video files (#5492)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
parent
a0990380b5
commit
8b1d5a2e3c
|
@ -196,9 +196,13 @@ describe('fileUtils', () => {
|
||||||
vi.restoreAllMocks(); // Restore spies on actualNodeFs
|
vi.restoreAllMocks(); // Restore spies on actualNodeFs
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should detect typescript type by extension (ts)', async () => {
|
it('should detect typescript type by extension (ts, mts, cts, tsx)', async () => {
|
||||||
expect(await detectFileType('file.ts')).toBe('text');
|
expect(await detectFileType('file.ts')).toBe('text');
|
||||||
expect(await detectFileType('file.test.ts')).toBe('text');
|
expect(await detectFileType('file.test.ts')).toBe('text');
|
||||||
|
expect(await detectFileType('file.mts')).toBe('text');
|
||||||
|
expect(await detectFileType('vite.config.mts')).toBe('text');
|
||||||
|
expect(await detectFileType('file.cts')).toBe('text');
|
||||||
|
expect(await detectFileType('component.tsx')).toBe('text');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should detect image type by extension (png)', async () => {
|
it('should detect image type by extension (png)', async () => {
|
||||||
|
|
|
@ -122,9 +122,10 @@ export async function detectFileType(
|
||||||
): Promise<'text' | 'image' | 'pdf' | 'audio' | 'video' | 'binary' | 'svg'> {
|
): Promise<'text' | 'image' | 'pdf' | 'audio' | 'video' | 'binary' | 'svg'> {
|
||||||
const ext = path.extname(filePath).toLowerCase();
|
const ext = path.extname(filePath).toLowerCase();
|
||||||
|
|
||||||
// The mimetype for "ts" is MPEG transport stream (a video format) but we want
|
// The mimetype for various TypeScript extensions (ts, mts, cts, tsx) can be
|
||||||
// to assume these are typescript files instead.
|
// MPEG transport stream (a video format), but we want to assume these are
|
||||||
if (ext === '.ts') {
|
// TypeScript files instead.
|
||||||
|
if (['.ts', '.mts', '.cts'].includes(ext)) {
|
||||||
return 'text';
|
return 'text';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue