fix(nextjs): correct inferred outputs for root Next.js projects (#20891)

This commit is contained in:
Jack Hsu 2023-12-21 11:16:55 -05:00 committed by GitHub
parent cb86dcbaeb
commit 029f73d3b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 110 additions and 9 deletions

View File

@ -1,5 +1,101 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`@nx/next/plugin integrated projects should create nodes 1`] = `Promise {}`;
exports[`@nx/next/plugin integrated projects should create nodes 1`] = `
{
"projects": {
"my-app": {
"root": "my-app",
"targets": {
"my-build": {
"cache": true,
"command": "next build",
"dependsOn": [
"^build",
],
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"next",
],
},
],
"options": {
"cwd": "my-app",
},
"outputs": [
"{workspaceRoot}/my-app/.next",
"{workspaceRoot}/my-app/.next/!(cache)",
],
},
"my-serve": {
"command": "next dev",
"options": {
"cwd": "my-app",
},
},
"my-start": {
"command": "next start",
"dependsOn": [
"my-build",
],
"options": {
"cwd": "my-app",
},
},
},
},
},
}
`;
exports[`@nx/next/plugin root projects should create nodes 1`] = `Promise {}`;
exports[`@nx/next/plugin root projects should create nodes 1`] = `
{
"projects": {
".": {
"root": ".",
"targets": {
"build": {
"cache": true,
"command": "next build",
"dependsOn": [
"^build",
],
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"next",
],
},
],
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/.next",
"{projectRoot}/.next/!(cache)",
],
},
"dev": {
"command": "next dev",
"options": {
"cwd": ".",
},
},
"start": {
"command": "next start",
"dependsOn": [
"build",
],
"options": {
"cwd": ".",
},
},
},
},
},
}
`;

View File

@ -25,10 +25,10 @@ describe('@nx/next/plugin', () => {
jest.resetModules();
});
it('should create nodes', () => {
it('should create nodes', async () => {
const nextConfigPath = 'next.config.js';
mockNextConfig(nextConfigPath, {});
const nodes = createNodesFunction(
const nodes = await createNodesFunction(
nextConfigPath,
{
buildTargetName: 'build',
@ -65,9 +65,9 @@ describe('@nx/next/plugin', () => {
jest.resetModules();
});
it('should create nodes', () => {
it('should create nodes', async () => {
mockNextConfig('my-app/next.config.js', {});
const nodes = createNodesFunction(
const nodes = await createNodesFunction(
'my-app/next.config.js',
{
buildTargetName: 'my-build',

View File

@ -2,10 +2,10 @@ import {
CreateDependencies,
CreateNodes,
CreateNodesContext,
NxJsonConfiguration,
TargetConfiguration,
detectPackageManager,
NxJsonConfiguration,
readJsonFile,
TargetConfiguration,
writeJsonFile,
} from '@nx/devkit';
import { dirname, join } from 'path';
@ -170,7 +170,12 @@ async function getOutputs(projectRoot, nextConfig) {
// If nextConfig is an object, directly use its 'distDir' property.
dir = nextConfig.distDir;
}
return `{workspaceRoot}/${projectRoot}/${dir}`;
if (projectRoot === '.') {
return `{projectRoot}/${dir}`;
} else {
return `{workspaceRoot}/${projectRoot}/${dir}`;
}
}
function getNextConfig(