Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): Add debug ability when verbose is passed to build #16545

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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