From a97f0d3feba1de3fa8dea0aae8d8304ac6abea25 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Mon, 8 May 2023 11:59:56 -0400 Subject: [PATCH] fix(nextjs): withNx works with production build --- packages/next/plugins/with-nx.ts | 10 +++++++++- packages/next/src/utils/config.ts | 9 --------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/next/plugins/with-nx.ts b/packages/next/plugins/with-nx.ts index 482087e305b55..bff1b15255845 100644 --- a/packages/next/plugins/with-nx.ts +++ b/packages/next/plugins/with-nx.ts @@ -5,7 +5,6 @@ import * as path from 'path'; import type { NextConfig } from 'next'; import type { NextConfigFn } from '../src/utils/config'; -import { forNextVersion } from '../src/utils/config'; import type { NextBuildBuilderOptions } from '../src/utils/types'; import type { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils'; import type { ProjectGraph, ProjectGraphProjectNode, Target } from '@nx/devkit'; @@ -465,6 +464,15 @@ export function getAliasForProject( return null; } +// Runs a function if the Next.js version satisfies the range. +export function forNextVersion(range: string, fn: () => void) { + const semver = require('semver'); + const nextJsVersion = require('next/package.json').version; + if (semver.satisfies(nextJsVersion, range)) { + fn(); + } +} + // Support for older generated code: `const withNx = require('@nx/next/plugins/with-nx');` module.exports = withNx; // Support for newer generated code: `const { withNx } = require(...);` diff --git a/packages/next/src/utils/config.ts b/packages/next/src/utils/config.ts index 2586b7d3f0295..b1be952f4d079 100644 --- a/packages/next/src/utils/config.ts +++ b/packages/next/src/utils/config.ts @@ -107,12 +107,3 @@ function isTsRule(r: RuleSetRule): boolean { return r.test.test('a.ts'); } - -// Runs a function if the Next.js version satisfies the range. -export function forNextVersion(range: string, fn: () => void) { - const semver = require('semver'); - const nextJsVersion = require('next/package.json').version; - if (semver.satisfies(nextJsVersion, range)) { - fn(); - } -}