fix(nextjs): Remove deprecated export executor (#28702)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Nicholas Cunningham 2024-10-30 18:10:47 -06:00 committed by GitHub
parent 51bed0e456
commit faf448379d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 4 additions and 231 deletions

View File

@ -8747,14 +8747,6 @@
"children": [],
"isExternal": false,
"disableCollapsible": false
},
{
"id": "export",
"path": "/nx-api/next/executors/export",
"name": "export",
"children": [],
"isExternal": false,
"disableCollapsible": false
}
],
"isExternal": false,

View File

@ -1531,15 +1531,6 @@
"originalFilePath": "/packages/next/src/executors/server/schema.json",
"path": "/nx-api/next/executors/server",
"type": "executor"
},
"/nx-api/next/executors/export": {
"description": "Export a Next.js application. The exported application is located at `dist/$outputPath/exported`.",
"file": "generated/packages/next/executors/export.json",
"hidden": false,
"name": "export",
"originalFilePath": "/packages/next/src/executors/export/schema.json",
"path": "/nx-api/next/executors/export",
"type": "executor"
}
},
"generators": {

View File

@ -1511,15 +1511,6 @@
"originalFilePath": "/packages/next/src/executors/server/schema.json",
"path": "next/executors/server",
"type": "executor"
},
{
"description": "Export a Next.js application. The exported application is located at `dist/$outputPath/exported`.",
"file": "generated/packages/next/executors/export.json",
"hidden": false,
"name": "export",
"originalFilePath": "/packages/next/src/executors/export/schema.json",
"path": "next/executors/export",
"type": "executor"
}
],
"generators": [

View File

@ -1,41 +0,0 @@
{
"name": "export",
"implementation": "/packages/next/src/executors/export/export.impl.ts",
"schema": {
"version": 2,
"outputCapture": "pipe",
"cli": "nx",
"title": "Next Export",
"description": "Export a Next.js application. The exported application is located at `dist/$outputPath/exported`.",
"type": "object",
"properties": {
"buildTarget": {
"type": "string",
"description": "Target which builds the application",
"x-priority": "important"
},
"silent": {
"type": "boolean",
"description": "Hide progress or not (default is `false`)",
"default": false
},
"threads": {
"type": "number",
"description": "Number of worker threads to utilize (defaults to the number of CPUs)"
},
"buildLibsFromSource": {
"type": "boolean",
"description": "Read buildable libraries from source instead of building them separately.",
"default": true
}
},
"required": [],
"presets": []
},
"description": "Export a Next.js application. The exported application is located at `dist/$outputPath/exported`.",
"x-deprecated": "Use static exports in next.config.js instead. See: https://nextjs.org/docs/pages/building-your-application/deploying/static-exports.",
"aliases": [],
"hidden": false,
"path": "/packages/next/src/executors/export/schema.json",
"type": "executor"
}

View File

@ -529,7 +529,6 @@
- [executors](/nx-api/next/executors)
- [build](/nx-api/next/executors/build)
- [server](/nx-api/next/executors/server)
- [export](/nx-api/next/executors/export)
- [generators](/nx-api/next/generators)
- [init](/nx-api/next/generators/init)
- [application](/nx-api/next/generators/application)

View File

@ -235,7 +235,6 @@ describe('@nx/next (legacy)', () => {
checkUnitTest: true,
checkLint: true,
checkE2E: isNotWindows(),
checkExport: false,
appsDir: 'packages',
});

View File

@ -39,7 +39,6 @@ describe('Next.js Styles', () => {
checkUnitTest: false,
checkLint: false,
checkE2E: false,
checkExport: false,
});
const scApp = uniq('app');
@ -52,7 +51,6 @@ describe('Next.js Styles', () => {
checkUnitTest: true,
checkLint: false,
checkE2E: false,
checkExport: false,
});
const scAppWithAppRouter = uniq('app');
@ -65,7 +63,6 @@ describe('Next.js Styles', () => {
checkUnitTest: false, // No unit tests for app router
checkLint: false,
checkE2E: false,
checkExport: false,
});
const emotionApp = uniq('app');
@ -78,7 +75,6 @@ describe('Next.js Styles', () => {
checkUnitTest: true,
checkLint: false,
checkE2E: false,
checkExport: false,
});
}, 600_000);
@ -94,7 +90,6 @@ describe('Next.js Styles', () => {
checkUnitTest: true,
checkLint: false,
checkE2E: false,
checkExport: false,
});
checkFilesExist(`${tailwindApp}/tailwind.config.js`);
@ -119,7 +114,6 @@ describe('Next.js Styles', () => {
checkUnitTest: true,
checkLint: false,
checkE2E: false,
checkExport: false,
});
checkFilesExist(`${tailwindApp}/tailwind.config.js`);

View File

@ -91,7 +91,6 @@ describe('Next.js Applications', () => {
checkUnitTest: true,
checkLint: true,
checkE2E: false,
checkExport: false,
});
// Consume a JS lib
@ -128,7 +127,6 @@ describe('Next.js Applications', () => {
checkUnitTest: true,
checkLint: true,
checkE2E: false,
checkExport: false,
});
}, 300_000);
@ -144,7 +142,6 @@ describe('Next.js Applications', () => {
checkUnitTest: false,
checkLint: false,
checkE2E: false,
checkExport: false,
});
}, 300_000);

View File

@ -14,7 +14,6 @@ export async function checkApp(
checkUnitTest: boolean;
checkLint: boolean;
checkE2E: boolean;
checkExport: boolean;
appsDir?: string;
}
) {

View File

@ -231,7 +231,7 @@ const pages: Array<{ title: string; path: string }> = [
{ title: '@nx/next:library', path: '/packages/next/generators/library' },
{ title: '@nx/next:build', path: '/packages/next/executors/build' },
{ title: '@nx/next:server', path: '/packages/next/executors/server' },
{ title: '@nx/next:export', path: '/packages/next/executors/export' },
{ title: '@nx/node', path: '/packages/node' },
{ title: '@nx/node:init', path: '/packages/node/generators/init' },
{

View File

@ -9,12 +9,6 @@
"implementation": "./src/executors/server/server.impl",
"schema": "./src/executors/server/schema.json",
"description": "Serve a Next.js application."
},
"export": {
"implementation": "./src/executors/export/export.impl",
"schema": "./src/executors/export/schema.json",
"description": "Export a Next.js application. The exported application is located at `dist/$outputPath/exported`.",
"x-deprecated": "Use static exports in next.config.js instead. See: https://nextjs.org/docs/pages/building-your-application/deploying/static-exports."
}
}
}

View File

@ -41,7 +41,6 @@
"copy-webpack-plugin": "^10.2.4",
"file-loader": "^6.2.0",
"ignore": "^5.0.4",
"picocolors": "^1.1.0",
"semver": "^7.5.3",
"tslib": "^2.3.0",
"webpack-merge": "^5.8.0",

View File

@ -92,7 +92,7 @@ function getNxContext(
parseTargetString(targetOptions.devServerTarget, partialExecutorContext)
);
} else if (targetOptions.buildTarget) {
// Executors such as @nx/next:server or @nx/next:export define the buildTarget option.
// Executors such as @nx/next:server define the buildTarget option.
return getNxContext(
graph,
parseTargetString(targetOptions.buildTarget, partialExecutorContext)

View File

@ -1,84 +0,0 @@
import {
ExecutorContext,
parseTargetString,
readTargetOptions,
targetToTargetString,
} from '@nx/devkit';
import exportApp from 'next/dist/export';
import {
NextBuildBuilderOptions,
NextExportBuilderOptions,
} from '../../utils/types';
import nextTrace = require('next/dist/trace');
import { platform } from 'os';
import { execFileSync } from 'child_process';
import * as pc from 'picocolors';
import { satisfies } from 'semver';
// platform specific command name
const pmCmd = platform() === 'win32' ? `npx.cmd` : 'npx';
/**
* @deprecated use output inside of your next.config.js
* Example
* const nextConfig = {
nx: {
svgr: false,
},
output: 'export'
};
* Read https://nextjs.org/docs/pages/building-your-application/deploying/static-exports
**/
export default async function exportExecutor(
options: NextExportBuilderOptions,
context: ExecutorContext
) {
const nextJsVersion = require('next/package.json').version;
if (satisfies(nextJsVersion, '>=14.0.0')) {
throw new Error(
'The export command has been removed in Next.js 14. Please update your Next config to use the output property. Read more: https://nextjs.org/docs/pages/building-your-application/deploying/static-exports'
);
}
// Returns { project: ProjectGraphNode; target: string; configuration?: string;}
const buildTarget = parseTargetString(options.buildTarget, context);
try {
const buildTargetName = targetToTargetString(buildTarget);
const args = getBuildTargetCommand(buildTargetName);
execFileSync(pmCmd, args, {
stdio: [0, 1, 2],
});
} catch {
throw new Error(`Build target failed: ${pc.bold(options.buildTarget)}`);
}
const buildOptions = readTargetOptions<NextBuildBuilderOptions>(
buildTarget,
context
);
const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
// Taken from:
// https://github.com/vercel/next.js/blob/ead56eaab68409e96c19f7d9139747bac1197aa9/packages/next/cli/next-export.ts#L13
const nextExportCliSpan = nextTrace.trace('next-export-cli');
await exportApp(
projectRoot,
{
statusMessage: 'Exporting',
silent: options.silent,
threads: options.threads,
outdir: `${buildOptions.outputPath}/exported`,
} as any,
nextExportCliSpan
);
return { success: true };
}
function getBuildTargetCommand(buildTarget: string) {
const cmd = ['nx', 'run', buildTarget];
return cmd;
}

View File

@ -1,30 +0,0 @@
{
"version": 2,
"outputCapture": "pipe",
"cli": "nx",
"title": "Next Export",
"description": "Export a Next.js application. The exported application is located at `dist/$outputPath/exported`.",
"type": "object",
"properties": {
"buildTarget": {
"type": "string",
"description": "Target which builds the application",
"x-priority": "important"
},
"silent": {
"type": "boolean",
"description": "Hide progress or not (default is `false`)",
"default": false
},
"threads": {
"type": "number",
"description": "Number of worker threads to utilize (defaults to the number of CPUs)"
},
"buildLibsFromSource": {
"type": "boolean",
"description": "Read buildable libraries from source instead of building them separately.",
"default": true
}
},
"required": []
}

View File

@ -821,7 +821,7 @@ describe('app (legacy)', () => {
}
});
it('should generate build serve and export targets', async () => {
it('should generate build and serve targets', async () => {
const name = uniq();
await applicationGenerator(tree, {
@ -832,7 +832,6 @@ describe('app (legacy)', () => {
const projectConfiguration = readProjectConfiguration(tree, name);
expect(projectConfiguration.targets.build).toBeDefined();
expect(projectConfiguration.targets.serve).toBeDefined();
expect(projectConfiguration.targets.export).toBeDefined();
});
});

View File

@ -56,13 +56,6 @@ export function addProject(host: Tree, options: NormalizedSchema) {
},
},
};
targets.export = {
executor: '@nx/next:export',
options: {
buildTarget: `${options.projectName}:build:production`,
},
};
}
const project: ProjectConfiguration = {

View File

@ -379,10 +379,7 @@
}
}
},
"export": {
"executor": "@nx/next:export",
"options": { "buildTarget": "nextapp:build:production" }
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],

View File

@ -33,10 +33,6 @@
}
}
},
"export": {
"executor": "@nx/next:export",
"options": { "buildTarget": "nextapp:build:production" }
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
@ -108,10 +104,6 @@
}
}
},
"export": {
"executor": "@nx/next:export",
"options": { "buildTarget": "nextapp-ts:build:production" }
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],

View File

@ -33,10 +33,6 @@
}
}
},
"export": {
"executor": "@nx/next:export",
"options": { "buildTarget": "nextapp:build:production" }
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
@ -108,10 +104,6 @@
}
}
},
"export": {
"executor": "@nx/next:export",
"options": { "buildTarget": "nextapp-ts:build:production" }
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],