feat(nextjs): remove "--server=..." app generator option (#16312)

This commit is contained in:
Jack Hsu 2023-04-14 13:56:43 -04:00 committed by GitHub
parent 330fe741aa
commit c3c77d525e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 4 additions and 163 deletions

View File

@ -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."

View File

@ -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 `<projectRoot>/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",

View File

@ -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 `<projectRoot>/project.json` rather than including it inside `workspace.json`",
"type": "boolean",
"default": true,
"x-deprecated": "Nx only supports standaloneConfig"
},
"skipPackageJson": {
"type": "boolean",
"default": false,

View File

@ -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<void> {
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);
}

View File

@ -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."

View File

@ -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 {

View File

@ -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);

View File

@ -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,
});
}

View File

@ -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<Server>}
*/
module.exports = async function nextServer(app, options) {
const handle = app.getRequestHandler();
const expressApp = express();
await app.prepare();
/**
* @returns {Promise<Server>}
*/
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);
});
});
}
`
);
}
}

View File

@ -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;

View File

@ -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 `<projectRoot>/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",

View File

@ -2,10 +2,7 @@ import {
convertNxGenerator,
formatFiles,
GeneratorCallback,
getImportPath,
getWorkspaceLayout,
joinPathFragments,
names,
runTasksInSerial,
Tree,
updateJson,

View File

@ -21,6 +21,5 @@ export interface Schema {
globalCss?: boolean;
strict?: boolean;
setParserOptionsProject?: boolean;
standaloneConfig?: boolean;
skipPackageJson?: boolean;
}

View File

@ -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 `<projectRoot>/project.json` rather than including it inside `workspace.json`",
"type": "boolean",
"default": true,
"x-deprecated": "Nx only supports standaloneConfig"
},
"skipPackageJson": {
"type": "boolean",
"default": false,

View File

@ -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;