fix(nextjs): correct inferred outputs for root Next.js projects (#20891)
This commit is contained in:
parent
cb86dcbaeb
commit
029f73d3b7
@ -1,5 +1,101 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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": ".",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
@ -25,10 +25,10 @@ describe('@nx/next/plugin', () => {
|
|||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create nodes', () => {
|
it('should create nodes', async () => {
|
||||||
const nextConfigPath = 'next.config.js';
|
const nextConfigPath = 'next.config.js';
|
||||||
mockNextConfig(nextConfigPath, {});
|
mockNextConfig(nextConfigPath, {});
|
||||||
const nodes = createNodesFunction(
|
const nodes = await createNodesFunction(
|
||||||
nextConfigPath,
|
nextConfigPath,
|
||||||
{
|
{
|
||||||
buildTargetName: 'build',
|
buildTargetName: 'build',
|
||||||
@ -65,9 +65,9 @@ describe('@nx/next/plugin', () => {
|
|||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create nodes', () => {
|
it('should create nodes', async () => {
|
||||||
mockNextConfig('my-app/next.config.js', {});
|
mockNextConfig('my-app/next.config.js', {});
|
||||||
const nodes = createNodesFunction(
|
const nodes = await createNodesFunction(
|
||||||
'my-app/next.config.js',
|
'my-app/next.config.js',
|
||||||
{
|
{
|
||||||
buildTargetName: 'my-build',
|
buildTargetName: 'my-build',
|
||||||
|
|||||||
@ -2,10 +2,10 @@ import {
|
|||||||
CreateDependencies,
|
CreateDependencies,
|
||||||
CreateNodes,
|
CreateNodes,
|
||||||
CreateNodesContext,
|
CreateNodesContext,
|
||||||
NxJsonConfiguration,
|
|
||||||
TargetConfiguration,
|
|
||||||
detectPackageManager,
|
detectPackageManager,
|
||||||
|
NxJsonConfiguration,
|
||||||
readJsonFile,
|
readJsonFile,
|
||||||
|
TargetConfiguration,
|
||||||
writeJsonFile,
|
writeJsonFile,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { dirname, join } from 'path';
|
import { dirname, join } from 'path';
|
||||||
@ -170,8 +170,13 @@ async function getOutputs(projectRoot, nextConfig) {
|
|||||||
// If nextConfig is an object, directly use its 'distDir' property.
|
// If nextConfig is an object, directly use its 'distDir' property.
|
||||||
dir = nextConfig.distDir;
|
dir = nextConfig.distDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (projectRoot === '.') {
|
||||||
|
return `{projectRoot}/${dir}`;
|
||||||
|
} else {
|
||||||
return `{workspaceRoot}/${projectRoot}/${dir}`;
|
return `{workspaceRoot}/${projectRoot}/${dir}`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getNextConfig(
|
function getNextConfig(
|
||||||
configFilePath: string,
|
configFilePath: string,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user