From 51bed0e456ad07a4299b11cf6d2b945461854fbb Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Wed, 30 Oct 2024 14:15:48 -0600 Subject: [PATCH] feat(nextjs): add support for typescript Next.js config file (#28709) ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes #28572 --- docs/generated/packages/next/documents/overview.md | 1 + docs/shared/packages/next/plugin-overview.md | 1 + packages/devkit/src/utils/add-plugin.spec.ts | 4 ++-- .../src/executors/build/lib/create-next-config-file.ts | 7 ++++++- packages/next/src/plugins/plugin.ts | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/generated/packages/next/documents/overview.md b/docs/generated/packages/next/documents/overview.md index 69f38b5cc2c70..0c8517c460010 100644 --- a/docs/generated/packages/next/documents/overview.md +++ b/docs/generated/packages/next/documents/overview.md @@ -60,6 +60,7 @@ The `@nx/next` plugin will create tasks for any project that has a Next.js confi - `next.config.js` - `next.config.cjs` - `next.config.mjs` +- `next.config.ts` ### View Inferred Tasks diff --git a/docs/shared/packages/next/plugin-overview.md b/docs/shared/packages/next/plugin-overview.md index 69f38b5cc2c70..0c8517c460010 100644 --- a/docs/shared/packages/next/plugin-overview.md +++ b/docs/shared/packages/next/plugin-overview.md @@ -60,6 +60,7 @@ The `@nx/next` plugin will create tasks for any project that has a Next.js confi - `next.config.js` - `next.config.cjs` - `next.config.mjs` +- `next.config.ts` ### View Inferred Tasks diff --git a/packages/devkit/src/utils/add-plugin.spec.ts b/packages/devkit/src/utils/add-plugin.spec.ts index 45b93c4cba02a..12d214b0a86d9 100644 --- a/packages/devkit/src/utils/add-plugin.spec.ts +++ b/packages/devkit/src/utils/add-plugin.spec.ts @@ -54,7 +54,7 @@ describe('addPlugin', () => { }, }; createNodes = [ - '**/next.config.{js,cjs,mjs}', + '**/next.config.{ts,js,cjs,mjs}', (_, { targetName }) => [ [ 'app1/next.config.js', @@ -300,7 +300,7 @@ describe('addPlugin', () => { }); createNodes = [ - '**/next.config.{js,cjs,mjs}', + '**/next.config.{ts,js,cjs,mjs}', () => [ [ 'app1/next.config.js', diff --git a/packages/next/src/executors/build/lib/create-next-config-file.ts b/packages/next/src/executors/build/lib/create-next-config-file.ts index eb8a6c39661a9..beeaf0cd15f1b 100644 --- a/packages/next/src/executors/build/lib/create-next-config-file.ts +++ b/packages/next/src/executors/build/lib/create-next-config-file.ts @@ -155,7 +155,12 @@ export function findNextConfigPath( ); } - const candidates = ['next.config.js', 'next.config.cjs', 'next.config.mjs']; + const candidates = [ + 'next.config.js', + 'next.config.cjs', + 'next.config.mjs', + 'next.config.ts', + ]; for (const candidate of candidates) { if (existsSync(join(dirname, candidate))) return candidate; } diff --git a/packages/next/src/plugins/plugin.ts b/packages/next/src/plugins/plugin.ts index aa61b29d5e037..2621e37a6fbdf 100644 --- a/packages/next/src/plugins/plugin.ts +++ b/packages/next/src/plugins/plugin.ts @@ -29,7 +29,7 @@ export interface NextPluginOptions { serveStaticTargetName?: string; } -const nextConfigBlob = '**/next.config.{js,cjs,mjs}'; +const nextConfigBlob = '**/next.config.{ts,js,cjs,mjs}'; function readTargetsCache( cachePath: string