From 34ceb27dc0af91eacdb0181a22307c2962b52826 Mon Sep 17 00:00:00 2001 From: Wesley Luyten Date: Tue, 29 Oct 2024 15:21:14 -0500 Subject: [PATCH] fix: wizard for Next15 ts config fix #312 --- package-lock.json | 6 +++--- src/cli/lib/next-config.ts | 4 ++-- tests/cli/lib/next-config.test.ts | 12 ++++++++++++ tests/factories/next.config.ts | 7 +++++++ 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 tests/factories/next.config.ts diff --git a/package-lock.json b/package-lock.json index 0e953dd..2137752 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,10 +42,10 @@ "typescript": "^5.5.2" }, "peerDependencies": { - "@types/react": "^17.0.0 || ^18", + "@types/react": "^17.0.0 || ^17.0.0-0 || ^18 || ^18.0.0-0 || ^19 || ^19.0.0-0", "next": ">=12.0.0", - "react": "^17.0.2 || ^18", - "react-dom": "^17.0.2 || ^18" + "react": "^17.0.2 || ^17.0.0-0 || ^18 || ^18.0.0-0 || ^19 || ^19.0.0-0", + "react-dom": "^17.0.2 || ^17.0.2-0 || ^18 || ^18.0.0-0 || ^19 || ^19.0.0-0" }, "peerDependenciesMeta": { "@types/react": { 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