Skip to content

Commit

Permalink
fix(nextjs): withNx works with production build
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed May 8, 2023
1 parent a081233 commit a97f0d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 9 additions & 1 deletion packages/next/plugins/with-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(...);`
Expand Down
9 changes: 0 additions & 9 deletions packages/next/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit a97f0d3

Please sign in to comment.