diff --git a/src/cli/lib/next-config.ts b/src/cli/lib/next-config.ts index e75a36f..589b963 100644 --- a/src/cli/lib/next-config.ts +++ b/src/cli/lib/next-config.ts @@ -8,7 +8,7 @@ import { videoConfigDefault } from '../../config.js'; import type { VideoConfig } from '../../config.js'; function extensionToType(filePath: string) { - if (filePath.endsWith('.mjs')) { + if (filePath.endsWith('.mjs') || filePath.endsWith('.ts')) { return 'module'; } @@ -20,7 +20,7 @@ export default async function updateNextConfigFile(parentDir: string = './', vid let configPath: string | undefined = undefined; let configContents: string = ''; - const pathsToCheck = ['next.config.js', 'next.config.mjs']; + const pathsToCheck = ['next.config.js', 'next.config.mjs', 'next.config.ts']; for (let i = 0; i < pathsToCheck.length; i++) { const filePath = path.join(parentDir, pathsToCheck[i]); diff --git a/tests/cli/lib/next-config.test.ts b/tests/cli/lib/next-config.test.ts index 846370b..b8a6f94 100644 --- a/tests/cli/lib/next-config.test.ts +++ b/tests/cli/lib/next-config.test.ts @@ -10,6 +10,10 @@ function outputConfigName(configName: string) { return 'next.config.mjs'; } + if (configName.endsWith('.ts')) { + return 'next.config.ts'; + } + // We have to return cjs files so we can import them async in a test. return 'next.config.js'; } @@ -49,4 +53,12 @@ describe('updateNextConfig', () => { const updatedContents = await fs.readFile(path.join(dirPath, 'next.config.mjs'), 'utf-8'); assert(updatedContents.includes('next-video')); }); + + it('should add next-video to the next.config.ts file', async () => { + const dirPath = await createTempDirWithConfig('next.config.ts'); + await updateNextConfigFile(dirPath); + + const updatedContents = await fs.readFile(path.join(dirPath, 'next.config.ts'), 'utf-8'); + assert(updatedContents.includes('next-video')); + }); }); diff --git a/tests/factories/next.config.ts b/tests/factories/next.config.ts new file mode 100644 index 0000000..2c7a945 --- /dev/null +++ b/tests/factories/next.config.ts @@ -0,0 +1,7 @@ +import type { NextConfig } from 'next' + +const nextConfig: NextConfig = { + /* config options here */ +} + +export default nextConfig