Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wizard for Next15 ts config #313

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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