From c3c77d525ef536d571828d5c58cffac926059284 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Fri, 14 Apr 2023 13:56:43 -0400 Subject: [PATCH] feat(nextjs): remove "--server=..." app generator option (#16312) --- .../packages/next/executors/server.json | 5 -- .../packages/next/generators/application.json | 10 --- .../packages/next/generators/library.json | 6 -- .../src/executors/server/lib/custom-server.ts | 23 ------- .../next/src/executors/server/schema.json | 5 -- .../next/src/executors/server/server.impl.ts | 11 +--- .../src/generators/application/application.ts | 2 - .../generators/application/lib/add-project.ts | 18 +----- .../lib/create-next-server-files.ts | 61 ------------------- .../src/generators/application/schema.d.ts | 2 - .../src/generators/application/schema.json | 10 --- .../next/src/generators/library/library.ts | 3 - .../next/src/generators/library/schema.d.ts | 1 - .../next/src/generators/library/schema.json | 6 -- packages/next/src/utils/types.ts | 4 -- 15 files changed, 4 insertions(+), 163 deletions(-) delete mode 100644 packages/next/src/executors/server/lib/custom-server.ts delete mode 100644 packages/next/src/generators/application/lib/create-next-server-files.ts diff --git a/docs/generated/packages/next/executors/server.json b/docs/generated/packages/next/executors/server.json index 5bfa1f6eff6e5..d269906a9d9c3 100644 --- a/docs/generated/packages/next/executors/server.json +++ b/docs/generated/packages/next/executors/server.json @@ -39,11 +39,6 @@ "type": "string", "description": "Target which builds the custom server." }, - "customServerPath": { - "type": "string", - "description": "Use a custom server script.", - "x-deprecated": "Use `customServerTarget` instead." - }, "hostname": { "type": "string", "description": "Hostname on which the application is served." diff --git a/docs/generated/packages/next/generators/application.json b/docs/generated/packages/next/generators/application.json index 50cd841111739..fa325636748a0 100644 --- a/docs/generated/packages/next/generators/application.json +++ b/docs/generated/packages/next/generators/application.json @@ -61,10 +61,6 @@ ] } }, - "server": { - "description": "The server script path to be used with next.", - "type": "string" - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -104,12 +100,6 @@ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false }, - "standaloneConfig": { - "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`", - "type": "boolean", - "default": true, - "x-deprecated": "Nx only supports standaloneConfig" - }, "swc": { "description": "Enable the Rust-based compiler SWC to compile JS/TS files.", "type": "boolean", diff --git a/docs/generated/packages/next/generators/library.json b/docs/generated/packages/next/generators/library.json index 149c42ec5712a..9ea971eb3a859 100644 --- a/docs/generated/packages/next/generators/library.json +++ b/docs/generated/packages/next/generators/library.json @@ -141,12 +141,6 @@ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false }, - "standaloneConfig": { - "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`", - "type": "boolean", - "default": true, - "x-deprecated": "Nx only supports standaloneConfig" - }, "skipPackageJson": { "type": "boolean", "default": false, diff --git a/packages/next/src/executors/server/lib/custom-server.ts b/packages/next/src/executors/server/lib/custom-server.ts deleted file mode 100644 index 2b516a4857010..0000000000000 --- a/packages/next/src/executors/server/lib/custom-server.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { joinPathFragments } from '@nrwl/devkit'; -import next from 'next'; -import { NextServerOptions, ProxyConfig } from '../../../utils/types'; -import { tsNodeRegister } from './tsnode-register'; - -export function customServer( - settings: NextServerOptions, - proxyConfig?: ProxyConfig -): Promise { - const nextApp = next(settings); - - tsNodeRegister( - joinPathFragments(settings.dir, settings.path), - joinPathFragments(settings.dir, 'tsconfig.json') - ); - - const customServerModule = require(joinPathFragments( - settings.dir, - settings.path - )); - const customServer = customServerModule.default || customServerModule; - return customServer(nextApp, settings, proxyConfig); -} diff --git a/packages/next/src/executors/server/schema.json b/packages/next/src/executors/server/schema.json index 3a5296d7d28f7..b060e03f46c1c 100644 --- a/packages/next/src/executors/server/schema.json +++ b/packages/next/src/executors/server/schema.json @@ -36,11 +36,6 @@ "type": "string", "description": "Target which builds the custom server." }, - "customServerPath": { - "type": "string", - "description": "Use a custom server script.", - "x-deprecated": "Use `customServerTarget` instead." - }, "hostname": { "type": "string", "description": "Hostname on which the application is served." diff --git a/packages/next/src/executors/server/server.impl.ts b/packages/next/src/executors/server/server.impl.ts index 4b069dfcb0510..4d4b73bb98df4 100644 --- a/packages/next/src/executors/server/server.impl.ts +++ b/packages/next/src/executors/server/server.impl.ts @@ -13,11 +13,9 @@ import { join, resolve } from 'path'; import { NextBuildBuilderOptions, NextServeBuilderOptions, - NextServer, NextServerOptions, ProxyConfig, } from '../../utils/types'; -import { customServer } from './lib/custom-server'; import { defaultServer } from './lib/default-server'; export default async function* serveExecutor( @@ -61,15 +59,8 @@ async function* runNextDevServer( port: options.port, customServer: !!options.customServerTarget, hostname: options.hostname || 'localhost', - - // TOOD(jack): Remove in Nx 15 - path: options.customServerPath, }; - const server: NextServer = options.customServerPath - ? customServer - : defaultServer; - // look for the proxy.conf.json let proxyConfig: ProxyConfig; const proxyConfigPath = options.proxyConfig @@ -85,7 +76,7 @@ async function* runNextDevServer( } try { - await server(settings, proxyConfig); + await defaultServer(settings, proxyConfig); logger.info(`[ ${chalk.green('ready')} ] on ${baseUrl}`); yield { diff --git a/packages/next/src/generators/application/application.ts b/packages/next/src/generators/application/application.ts index 08f9137679fb4..61d7a6fa3846d 100644 --- a/packages/next/src/generators/application/application.ts +++ b/packages/next/src/generators/application/application.ts @@ -11,7 +11,6 @@ import { addCypress } from './lib/add-cypress'; import { addJest } from './lib/add-jest'; import { addProject } from './lib/add-project'; import { createApplicationFiles } from './lib/create-application-files'; -import { createNextServerFiles } from './lib/create-next-server-files'; import { setDefaults } from './lib/set-defaults'; import { updateJestConfig } from './lib/update-jest-config'; import { nextInitGenerator } from '../init/init'; @@ -27,7 +26,6 @@ export async function applicationGenerator(host: Tree, schema: Schema) { skipFormat: true, }); createApplicationFiles(host, options); - createNextServerFiles(host, options); addProject(host, options); const cypressTask = await addCypress(host, options); const jestTask = await addJest(host, options); diff --git a/packages/next/src/generators/application/lib/add-project.ts b/packages/next/src/generators/application/lib/add-project.ts index 63f9aceecea8c..65e70cc46b4a8 100644 --- a/packages/next/src/generators/application/lib/add-project.ts +++ b/packages/next/src/generators/application/lib/add-project.ts @@ -44,13 +44,6 @@ export function addProject(host: Tree, options: NormalizedSchema) { }, }; - if (options.server) { - targets.serve.options = { - ...targets.serve.options, - customServerPath: options.server, - }; - } - targets.export = { executor: '@nrwl/next:export', options: { @@ -66,12 +59,7 @@ export function addProject(host: Tree, options: NormalizedSchema) { tags: options.parsedTags, }; - addProjectConfiguration( - host, - options.projectName, - { - ...project, - }, - options.standaloneConfig - ); + addProjectConfiguration(host, options.projectName, { + ...project, + }); } diff --git a/packages/next/src/generators/application/lib/create-next-server-files.ts b/packages/next/src/generators/application/lib/create-next-server-files.ts deleted file mode 100644 index e379f963d2f97..0000000000000 --- a/packages/next/src/generators/application/lib/create-next-server-files.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { NormalizedSchema } from './normalize-options'; -import { getWorkspaceLayout, joinPathFragments, Tree } from '@nrwl/devkit'; -import { dirname } from 'path'; - -let isOldNext: boolean; - -try { - require('next/dist/next-server/server/next-server'); - isOldNext = true; -} catch { - isOldNext = false; -} - -export function createNextServerFiles(host: Tree, options: NormalizedSchema) { - if (options.server) { - const directory = dirname( - joinPathFragments(options.appProjectRoot, options.server) - ); - - host.write( - joinPathFragments(options.appProjectRoot, options.server), - ` - // @ts-check - 'use strict'; - - /** - * @typedef {import('http').Server} Server - * @typedef {import('next/dist/server/next-server').default} DevServer - */ - - const express = require('express'); - - /** - * @param {DevServer} app - * @param {{dev: string; dir: string; staticMarkup: boolean; quiet: boolean; conf: any; port: number;}} options - * @returns {Promise} - */ - module.exports = async function nextServer(app, options) { - const handle = app.getRequestHandler(); - const expressApp = express(); - - await app.prepare(); - - /** - * @returns {Promise} - */ - return new Promise((resolve, reject) => { - - expressApp.all('*', (req, res) => { - return handle(req, res); - }); - - const server = expressApp.listen(options.port, (err) => { - err ? reject(err) : resolve(server); - }); - }); - } - ` - ); - } -} diff --git a/packages/next/src/generators/application/schema.d.ts b/packages/next/src/generators/application/schema.d.ts index 180a02846f7d3..c1032a0df4150 100644 --- a/packages/next/src/generators/application/schema.d.ts +++ b/packages/next/src/generators/application/schema.d.ts @@ -4,7 +4,6 @@ import { SupportedStyles } from '@nrwl/react'; export interface Schema { name: string; style?: SupportedStyles; - server?: string; skipFormat?: boolean; directory?: string; tags?: string; @@ -13,7 +12,6 @@ export interface Schema { linter?: Linter; js?: boolean; setParserOptionsProject?: boolean; - standaloneConfig?: boolean; swc?: boolean; customServer?: boolean; skipPackageJson?: boolean; diff --git a/packages/next/src/generators/application/schema.json b/packages/next/src/generators/application/schema.json index 0279baa455f08..889443d88aa62 100644 --- a/packages/next/src/generators/application/schema.json +++ b/packages/next/src/generators/application/schema.json @@ -64,10 +64,6 @@ ] } }, - "server": { - "description": "The server script path to be used with next.", - "type": "string" - }, "linter": { "description": "The tool to use for running lint checks.", "type": "string", @@ -107,12 +103,6 @@ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false }, - "standaloneConfig": { - "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`", - "type": "boolean", - "default": true, - "x-deprecated": "Nx only supports standaloneConfig" - }, "swc": { "description": "Enable the Rust-based compiler SWC to compile JS/TS files.", "type": "boolean", diff --git a/packages/next/src/generators/library/library.ts b/packages/next/src/generators/library/library.ts index b082d0c7ec56b..7269a9a492d37 100644 --- a/packages/next/src/generators/library/library.ts +++ b/packages/next/src/generators/library/library.ts @@ -2,10 +2,7 @@ import { convertNxGenerator, formatFiles, GeneratorCallback, - getImportPath, - getWorkspaceLayout, joinPathFragments, - names, runTasksInSerial, Tree, updateJson, diff --git a/packages/next/src/generators/library/schema.d.ts b/packages/next/src/generators/library/schema.d.ts index 7b707e50daab9..284c3f0add7dd 100644 --- a/packages/next/src/generators/library/schema.d.ts +++ b/packages/next/src/generators/library/schema.d.ts @@ -21,6 +21,5 @@ export interface Schema { globalCss?: boolean; strict?: boolean; setParserOptionsProject?: boolean; - standaloneConfig?: boolean; skipPackageJson?: boolean; } diff --git a/packages/next/src/generators/library/schema.json b/packages/next/src/generators/library/schema.json index 238fcc5e4676b..769fe8867423a 100644 --- a/packages/next/src/generators/library/schema.json +++ b/packages/next/src/generators/library/schema.json @@ -144,12 +144,6 @@ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false }, - "standaloneConfig": { - "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`", - "type": "boolean", - "default": true, - "x-deprecated": "Nx only supports standaloneConfig" - }, "skipPackageJson": { "type": "boolean", "default": false, diff --git a/packages/next/src/utils/types.ts b/packages/next/src/utils/types.ts index 8d6bb0b7e3282..76fd7b28d3523 100644 --- a/packages/next/src/utils/types.ts +++ b/packages/next/src/utils/types.ts @@ -18,7 +18,6 @@ export interface NextServerOptions { staticMarkup: boolean; quiet: boolean; port: number; - path: string; hostname: string; customServer?: boolean; } @@ -47,9 +46,6 @@ export interface NextServeBuilderOptions { quiet: boolean; buildTarget: string; customServerTarget?: string; - /** @deprecated Use customServerTarget - */ - customServerPath?: string; hostname?: string; proxyConfig?: string; buildLibsFromSource?: boolean;