feat(nextjs): remove "--server=..." app generator option (#16312)
This commit is contained in:
parent
330fe741aa
commit
c3c77d525e
@ -39,11 +39,6 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Target which builds the custom server."
|
"description": "Target which builds the custom server."
|
||||||
},
|
},
|
||||||
"customServerPath": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Use a custom server script.",
|
|
||||||
"x-deprecated": "Use `customServerTarget` instead."
|
|
||||||
},
|
|
||||||
"hostname": {
|
"hostname": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Hostname on which the application is served."
|
"description": "Hostname on which the application is served."
|
||||||
|
|||||||
@ -61,10 +61,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"server": {
|
|
||||||
"description": "The server script path to be used with next.",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"linter": {
|
"linter": {
|
||||||
"description": "The tool to use for running lint checks.",
|
"description": "The tool to use for running lint checks.",
|
||||||
"type": "string",
|
"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.",
|
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
||||||
"default": false
|
"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": {
|
"swc": {
|
||||||
"description": "Enable the Rust-based compiler SWC to compile JS/TS files.",
|
"description": "Enable the Rust-based compiler SWC to compile JS/TS files.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|||||||
@ -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.",
|
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
||||||
"default": false
|
"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": {
|
"skipPackageJson": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
@ -36,11 +36,6 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Target which builds the custom server."
|
"description": "Target which builds the custom server."
|
||||||
},
|
},
|
||||||
"customServerPath": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Use a custom server script.",
|
|
||||||
"x-deprecated": "Use `customServerTarget` instead."
|
|
||||||
},
|
|
||||||
"hostname": {
|
"hostname": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Hostname on which the application is served."
|
"description": "Hostname on which the application is served."
|
||||||
|
|||||||
@ -13,11 +13,9 @@ import { join, resolve } from 'path';
|
|||||||
import {
|
import {
|
||||||
NextBuildBuilderOptions,
|
NextBuildBuilderOptions,
|
||||||
NextServeBuilderOptions,
|
NextServeBuilderOptions,
|
||||||
NextServer,
|
|
||||||
NextServerOptions,
|
NextServerOptions,
|
||||||
ProxyConfig,
|
ProxyConfig,
|
||||||
} from '../../utils/types';
|
} from '../../utils/types';
|
||||||
import { customServer } from './lib/custom-server';
|
|
||||||
import { defaultServer } from './lib/default-server';
|
import { defaultServer } from './lib/default-server';
|
||||||
|
|
||||||
export default async function* serveExecutor(
|
export default async function* serveExecutor(
|
||||||
@ -61,15 +59,8 @@ async function* runNextDevServer(
|
|||||||
port: options.port,
|
port: options.port,
|
||||||
customServer: !!options.customServerTarget,
|
customServer: !!options.customServerTarget,
|
||||||
hostname: options.hostname || 'localhost',
|
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
|
// look for the proxy.conf.json
|
||||||
let proxyConfig: ProxyConfig;
|
let proxyConfig: ProxyConfig;
|
||||||
const proxyConfigPath = options.proxyConfig
|
const proxyConfigPath = options.proxyConfig
|
||||||
@ -85,7 +76,7 @@ async function* runNextDevServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await server(settings, proxyConfig);
|
await defaultServer(settings, proxyConfig);
|
||||||
logger.info(`[ ${chalk.green('ready')} ] on ${baseUrl}`);
|
logger.info(`[ ${chalk.green('ready')} ] on ${baseUrl}`);
|
||||||
|
|
||||||
yield {
|
yield {
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import { addCypress } from './lib/add-cypress';
|
|||||||
import { addJest } from './lib/add-jest';
|
import { addJest } from './lib/add-jest';
|
||||||
import { addProject } from './lib/add-project';
|
import { addProject } from './lib/add-project';
|
||||||
import { createApplicationFiles } from './lib/create-application-files';
|
import { createApplicationFiles } from './lib/create-application-files';
|
||||||
import { createNextServerFiles } from './lib/create-next-server-files';
|
|
||||||
import { setDefaults } from './lib/set-defaults';
|
import { setDefaults } from './lib/set-defaults';
|
||||||
import { updateJestConfig } from './lib/update-jest-config';
|
import { updateJestConfig } from './lib/update-jest-config';
|
||||||
import { nextInitGenerator } from '../init/init';
|
import { nextInitGenerator } from '../init/init';
|
||||||
@ -27,7 +26,6 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
|
|||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
});
|
});
|
||||||
createApplicationFiles(host, options);
|
createApplicationFiles(host, options);
|
||||||
createNextServerFiles(host, options);
|
|
||||||
addProject(host, options);
|
addProject(host, options);
|
||||||
const cypressTask = await addCypress(host, options);
|
const cypressTask = await addCypress(host, options);
|
||||||
const jestTask = await addJest(host, options);
|
const jestTask = await addJest(host, options);
|
||||||
|
|||||||
@ -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 = {
|
targets.export = {
|
||||||
executor: '@nrwl/next:export',
|
executor: '@nrwl/next:export',
|
||||||
options: {
|
options: {
|
||||||
@ -66,12 +59,7 @@ export function addProject(host: Tree, options: NormalizedSchema) {
|
|||||||
tags: options.parsedTags,
|
tags: options.parsedTags,
|
||||||
};
|
};
|
||||||
|
|
||||||
addProjectConfiguration(
|
addProjectConfiguration(host, options.projectName, {
|
||||||
host,
|
|
||||||
options.projectName,
|
|
||||||
{
|
|
||||||
...project,
|
...project,
|
||||||
},
|
});
|
||||||
options.standaloneConfig
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -4,7 +4,6 @@ import { SupportedStyles } from '@nrwl/react';
|
|||||||
export interface Schema {
|
export interface Schema {
|
||||||
name: string;
|
name: string;
|
||||||
style?: SupportedStyles;
|
style?: SupportedStyles;
|
||||||
server?: string;
|
|
||||||
skipFormat?: boolean;
|
skipFormat?: boolean;
|
||||||
directory?: string;
|
directory?: string;
|
||||||
tags?: string;
|
tags?: string;
|
||||||
@ -13,7 +12,6 @@ export interface Schema {
|
|||||||
linter?: Linter;
|
linter?: Linter;
|
||||||
js?: boolean;
|
js?: boolean;
|
||||||
setParserOptionsProject?: boolean;
|
setParserOptionsProject?: boolean;
|
||||||
standaloneConfig?: boolean;
|
|
||||||
swc?: boolean;
|
swc?: boolean;
|
||||||
customServer?: boolean;
|
customServer?: boolean;
|
||||||
skipPackageJson?: boolean;
|
skipPackageJson?: boolean;
|
||||||
|
|||||||
@ -64,10 +64,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"server": {
|
|
||||||
"description": "The server script path to be used with next.",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"linter": {
|
"linter": {
|
||||||
"description": "The tool to use for running lint checks.",
|
"description": "The tool to use for running lint checks.",
|
||||||
"type": "string",
|
"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.",
|
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
||||||
"default": false
|
"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": {
|
"swc": {
|
||||||
"description": "Enable the Rust-based compiler SWC to compile JS/TS files.",
|
"description": "Enable the Rust-based compiler SWC to compile JS/TS files.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|||||||
@ -2,10 +2,7 @@ import {
|
|||||||
convertNxGenerator,
|
convertNxGenerator,
|
||||||
formatFiles,
|
formatFiles,
|
||||||
GeneratorCallback,
|
GeneratorCallback,
|
||||||
getImportPath,
|
|
||||||
getWorkspaceLayout,
|
|
||||||
joinPathFragments,
|
joinPathFragments,
|
||||||
names,
|
|
||||||
runTasksInSerial,
|
runTasksInSerial,
|
||||||
Tree,
|
Tree,
|
||||||
updateJson,
|
updateJson,
|
||||||
|
|||||||
@ -21,6 +21,5 @@ export interface Schema {
|
|||||||
globalCss?: boolean;
|
globalCss?: boolean;
|
||||||
strict?: boolean;
|
strict?: boolean;
|
||||||
setParserOptionsProject?: boolean;
|
setParserOptionsProject?: boolean;
|
||||||
standaloneConfig?: boolean;
|
|
||||||
skipPackageJson?: boolean;
|
skipPackageJson?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.",
|
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
||||||
"default": false
|
"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": {
|
"skipPackageJson": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
|||||||
@ -18,7 +18,6 @@ export interface NextServerOptions {
|
|||||||
staticMarkup: boolean;
|
staticMarkup: boolean;
|
||||||
quiet: boolean;
|
quiet: boolean;
|
||||||
port: number;
|
port: number;
|
||||||
path: string;
|
|
||||||
hostname: string;
|
hostname: string;
|
||||||
customServer?: boolean;
|
customServer?: boolean;
|
||||||
}
|
}
|
||||||
@ -47,9 +46,6 @@ export interface NextServeBuilderOptions {
|
|||||||
quiet: boolean;
|
quiet: boolean;
|
||||||
buildTarget: string;
|
buildTarget: string;
|
||||||
customServerTarget?: string;
|
customServerTarget?: string;
|
||||||
/** @deprecated Use customServerTarget
|
|
||||||
*/
|
|
||||||
customServerPath?: string;
|
|
||||||
hostname?: string;
|
hostname?: string;
|
||||||
proxyConfig?: string;
|
proxyConfig?: string;
|
||||||
buildLibsFromSource?: boolean;
|
buildLibsFromSource?: boolean;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user