Skip to content

Commit

Permalink
fix: wizard for Next15 ts config
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Oct 29, 2024
1 parent 6755df7 commit c77995b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cli/lib/next-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -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]);
Expand Down
12 changes: 12 additions & 0 deletions tests/cli/lib/next-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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'));
});
});
7 changes: 7 additions & 0 deletions tests/factories/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
/* config options here */
}

export default nextConfig

0 comments on commit c77995b

Please sign in to comment.