Skip to content

Commit

Permalink
fix(nextjs): Add debug ability when verbose is passed to build (#16545)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham authored Apr 26, 2023
1 parent 7229750 commit d24862d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/next/executors/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
"description": "Generate a lockfile (e.g. yarn.lock) that matches the workspace lockfile to ensure package versions match.",
"default": false,
"x-priority": "internal"
},
"debug": {
"type": "boolean",
"description": "Enable Next.js debug build logging",
"default": false
}
},
"required": ["root", "outputPath"],
Expand Down
17 changes: 15 additions & 2 deletions packages/next/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createLockFile, createPackageJson, getLockFileName } from '@nx/js';
import build from 'next/dist/build';
import { join, resolve } from 'path';
import { copySync, existsSync, mkdir, writeFileSync } from 'fs-extra';
import { gte } from 'semver';
import { lt, gte } from 'semver';
import { directoryExists } from '@nx/workspace/src/utilities/fileutils';
import { checkAndCleanWithSemver } from '@nx/devkit/src/utils/semver';

Expand Down Expand Up @@ -45,7 +45,20 @@ export default async function buildExecutor(
(process.env as any).__NEXT_REACT_ROOT ||= 'true';
}

await build(root);
// Get the installed Next.js version (will be removed after Nx 16 and Next.js update)
const nextVersion = require('next/package.json').version;

const debug = !!process.env.NX_VERBOSE_LOGGING || options.debug;

// Check the major and minor version numbers
if (lt(nextVersion, '13.2.0')) {
// If the version is lower than 13.2.0, use the second parameter as the config object
await build(root, null, false, debug);
} else {
// Otherwise, use the third parameter as a boolean flag for verbose logging
// @ts-ignore
await build(root, false, debug);
}

if (!directoryExists(options.outputPath)) {
mkdir(options.outputPath);
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/executors/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
"description": "Generate a lockfile (e.g. yarn.lock) that matches the workspace lockfile to ensure package versions match.",
"default": false,
"x-priority": "internal"
},
"debug": {
"type": "boolean",
"description": "Enable Next.js debug build logging",
"default": false
}
},
"required": ["root", "outputPath"]
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface NextBuildBuilderOptions {
includeDevDependenciesInPackageJson?: boolean;
generateLockfile?: boolean;
watch?: boolean;
debug?: boolean;
}

export interface NextServeBuilderOptions {
Expand Down

1 comment on commit d24862d

@vercel
Copy link

@vercel vercel bot commented on d24862d Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx.dev
nx-dev-nrwl.vercel.app

Please sign in to comment.