From 55b85edb6e7c9c0436660a1d74b21b6f79d8ef4c Mon Sep 17 00:00:00 2001 From: Willem-Jaap Date: Sat, 22 Apr 2023 12:07:14 +0200 Subject: [PATCH 1/4] fix(cli): add all available options to cli commands, format them consistently --- errors/invalid-i18n-config.md | 2 +- packages/next/src/cli/next-build.ts | 10 ++++++---- packages/next/src/cli/next-export.ts | 16 +++++++++++----- packages/next/src/cli/next-info.ts | 3 +++ packages/next/src/cli/next-start.ts | 6 +++--- packages/next/src/cli/next-telemetry.ts | 7 ++++++- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/errors/invalid-i18n-config.md b/errors/invalid-i18n-config.md index b840d14a61f98..07511dd957322 100644 --- a/errors/invalid-i18n-config.md +++ b/errors/invalid-i18n-config.md @@ -1,6 +1,6 @@ # Invalid i18n config -#### Why This Error +#### Why This Error Occurred In your `next.config.js` file you provided an invalid config for the `i18n` field. This could mean the limit for 100 locale items was exceeded. diff --git a/packages/next/src/cli/next-build.ts b/packages/next/src/cli/next-build.ts index 689c1347ede73..81af2c44a8479 100755 --- a/packages/next/src/cli/next-build.ts +++ b/packages/next/src/cli/next-build.ts @@ -45,10 +45,12 @@ const nextBuild: CliCommand = (argv) => { If no directory is provided, the current directory will be used. Options - --profile Can be used to enable React Production Profiling - --no-lint Disable linting - --no-mangling Disable mangling - --experimental-app-only Only build 'app' routes + --profile Can be used to enable React Production Profiling + --no-lint Disable linting + --no-mangling Disable mangling + --experimental-app-only Only build 'app' routes + --experimental-turbo Enable experimental turbo mode + --help, -h Displays this message `, 0 ) diff --git a/packages/next/src/cli/next-export.ts b/packages/next/src/cli/next-export.ts index bfbca1817b22e..e10e02161a818 100755 --- a/packages/next/src/cli/next-export.ts +++ b/packages/next/src/cli/next-export.ts @@ -2,6 +2,7 @@ import { resolve, join } from 'path' import { existsSync } from 'fs' import arg from 'next/dist/compiled/arg/index.js' +import chalk from 'next/dist/compiled/chalk' import exportApp, { ExportError } from '../export' import * as Log from '../build/output/log' import { printAndExit } from '../server/lib/utils' @@ -21,8 +22,8 @@ const nextExport: CliCommand = (argv) => { // Aliases '-h': '--help', - '-s': '--silent', '-o': '--outdir', + '-s': '--silent', } let args: arg.Result try { @@ -36,7 +37,7 @@ const nextExport: CliCommand = (argv) => { if (args['--help']) { console.log(` Description - Exports the application for production deployment + Exports a static version of the application for production deployment Usage $ next export [options] @@ -45,9 +46,14 @@ const nextExport: CliCommand = (argv) => { If no directory is provided, the current directory will be used. Options - -h - list this help - -o - set the output dir (defaults to 'out') - -s - do not print any messages to console + --outdir, -o Set the output dir (defaults to 'out') + --silent, -s Do not print any messages to console + --threads Max number of threads to use + --help, -h List this help + + Learn more: ${chalk.cyan( + 'https://nextjs.org/docs/advanced-features/static-html-export' + )} `) process.exit(0) } diff --git a/packages/next/src/cli/next-info.ts b/packages/next/src/cli/next-info.ts index ef34dd4f34aa2..45442fd0f4218 100755 --- a/packages/next/src/cli/next-info.ts +++ b/packages/next/src/cli/next-info.ts @@ -54,6 +54,9 @@ const nextInfo: CliCommand = async (argv) => { Usage $ next info + Options + --help, -h Displays this message + Learn more: ${chalk.cyan( 'https://nextjs.org/docs/api-reference/cli#info' )}` diff --git a/packages/next/src/cli/next-start.ts b/packages/next/src/cli/next-start.ts index a4c5e56649edb..3fa4eaf7c66c2 100755 --- a/packages/next/src/cli/next-start.ts +++ b/packages/next/src/cli/next-start.ts @@ -45,10 +45,10 @@ const nextStart: CliCommand = async (argv) => { If no directory is provided, the current directory will be used. Options - --port, -p A port number on which to start the application - --hostname, -H Hostname on which to start the application (default: 0.0.0.0) + --port, -p A port number on which to start the application + --hostname, -H Hostname on which to start the application (default: 0.0.0.0) --keepAliveTimeout Max milliseconds to wait before closing inactive connections - --help, -h Displays this message + --help, -h Displays this message `) process.exit(0) } diff --git a/packages/next/src/cli/next-telemetry.ts b/packages/next/src/cli/next-telemetry.ts index 70f4fa482e00a..e83b7b1dd4517 100755 --- a/packages/next/src/cli/next-telemetry.ts +++ b/packages/next/src/cli/next-telemetry.ts @@ -9,9 +9,9 @@ import isError from '../lib/is-error' const nextTelemetry: CliCommand = (argv) => { const validArgs: arg.Spec = { // Types - '--help': Boolean, '--enable': Boolean, '--disable': Boolean, + '--help': Boolean, // Aliases '-h': '--help', } @@ -36,6 +36,11 @@ const nextTelemetry: CliCommand = (argv) => { You may pass the 'enable' or 'disable' argument to turn Next.js' telemetry collection on or off. + Options + --enable Enables Next.js' telemetry collection + --disable Disables Next.js' telemetry collection + --help, -h Displays this message + Learn more: ${chalk.cyan('https://nextjs.org/telemetry')} ` ) From a5af78cf455dd15f5fa448c1603cbcf3bccfe4d5 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 24 Apr 2023 16:47:55 -0400 Subject: [PATCH 2/4] Apply suggestions from code review Mention the "next export" command is deprecated in favor of "output: export" in next.config.js --- packages/next/src/cli/next-export.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/src/cli/next-export.ts b/packages/next/src/cli/next-export.ts index e10e02161a818..df9fc82704632 100755 --- a/packages/next/src/cli/next-export.ts +++ b/packages/next/src/cli/next-export.ts @@ -37,7 +37,7 @@ const nextExport: CliCommand = (argv) => { if (args['--help']) { console.log(` Description - Exports a static version of the application for production deployment + [DEPRECATED] Exports a static version of the application for production deployment Usage $ next export [options] @@ -51,6 +51,7 @@ const nextExport: CliCommand = (argv) => { --threads Max number of threads to use --help, -h List this help + The "next export" command is deprecated in favor of "output: export" in next.config.js Learn more: ${chalk.cyan( 'https://nextjs.org/docs/advanced-features/static-html-export' )} From a486c382798fbe7da290b66e8c4e65b506968d2d Mon Sep 17 00:00:00 2001 From: Willem-Jaap Date: Sun, 7 May 2023 11:33:30 +0200 Subject: [PATCH 3/4] test(cli): update test to match next export content --- test/integration/cli/test/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/cli/test/index.test.js b/test/integration/cli/test/index.test.js index bf539a9e289d9..61ded2719cceb 100644 --- a/test/integration/cli/test/index.test.js +++ b/test/integration/cli/test/index.test.js @@ -580,14 +580,14 @@ describe('CLI Usage', () => { const help = await runNextCommand(['export', '--help'], { stdout: true, }) - expect(help.stdout).toMatch(/Exports the application/) + expect(help.stdout).toMatch(/Exports a static version of the application/) }) test('-h', async () => { const help = await runNextCommand(['export', '-h'], { stdout: true, }) - expect(help.stdout).toMatch(/Exports the application/) + expect(help.stdout).toMatch(/Exports a static version of the application/) }) test('should warn when unknown argument provided', async () => { From 5bb87ccbc4bb1d3fd9dd92d3507a737ee9e96389 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 13 Jun 2023 19:18:05 -0700 Subject: [PATCH 4/4] extra changes --- .../webpack/packages/lazy-compilation-node.js | 80 +++++------ .../webpack/packages/lazy-compilation-web.js | 136 +++++++++--------- 2 files changed, 108 insertions(+), 108 deletions(-) diff --git a/packages/next/src/bundles/webpack/packages/lazy-compilation-node.js b/packages/next/src/bundles/webpack/packages/lazy-compilation-node.js index 855415506e5b9..da4058583b11e 100644 --- a/packages/next/src/bundles/webpack/packages/lazy-compilation-node.js +++ b/packages/next/src/bundles/webpack/packages/lazy-compilation-node.js @@ -1,50 +1,50 @@ /* global __resourceQuery */ -'use strict' +"use strict"; -var urlBase = decodeURIComponent(__resourceQuery.slice(1)) +var urlBase = decodeURIComponent(__resourceQuery.slice(1)); /** * @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options * @returns {() => void} function to destroy response */ exports.keepAlive = function (options) { - var data = options.data - var onError = options.onError - var active = options.active - var module = options.module - /** @type {import("http").IncomingMessage} */ - var response - var request = ( - urlBase.startsWith('https') ? require('https') : require('http') - ).request( - urlBase + data, - { - agent: false, - headers: { accept: 'text/event-stream' }, - }, - function (res) { - response = res - response.on('error', errorHandler) - if (!active && !module.hot) { - console.log( - 'Hot Module Replacement is not enabled. Waiting for process restart...' - ) - } - } - ) + var data = options.data; + var onError = options.onError; + var active = options.active; + var module = options.module; + /** @type {import("http").IncomingMessage} */ + var response; + var request = ( + urlBase.startsWith("https") ? require("https") : require("http") + ).request( + urlBase + data, + { + agent: false, + headers: { accept: "text/event-stream" } + }, + function (res) { + response = res; + response.on("error", errorHandler); + if (!active && !module.hot) { + console.log( + "Hot Module Replacement is not enabled. Waiting for process restart..." + ); + } + } + ); - /** - * @param {Error} err error - */ - function errorHandler(err) { - err.message = - 'Problem communicating active modules to the server: ' + err.message - onError(err) - } - request.on('error', errorHandler) - request.end() - return function () { - response.destroy() - } -} + /** + * @param {Error} err error + */ + function errorHandler(err) { + err.message = + "Problem communicating active modules to the server: " + err.message; + onError(err); + } + request.on("error", errorHandler); + request.end(); + return function () { + response.destroy(); + }; +}; diff --git a/packages/next/src/bundles/webpack/packages/lazy-compilation-web.js b/packages/next/src/bundles/webpack/packages/lazy-compilation-web.js index 5d0006c8a374b..ec8253f0a3cac 100644 --- a/packages/next/src/bundles/webpack/packages/lazy-compilation-web.js +++ b/packages/next/src/bundles/webpack/packages/lazy-compilation-web.js @@ -1,83 +1,83 @@ /* global __resourceQuery */ -'use strict' +"use strict"; -if (typeof EventSource !== 'function') { - throw new Error( - "Environment doesn't support lazy compilation (requires EventSource)" - ) +if (typeof EventSource !== "function") { + throw new Error( + "Environment doesn't support lazy compilation (requires EventSource)" + ); } -var urlBase = decodeURIComponent(__resourceQuery.slice(1)) +var urlBase = decodeURIComponent(__resourceQuery.slice(1)); /** @type {EventSource | undefined} */ -var activeEventSource -var activeKeys = new Map() -var errorHandlers = new Set() +var activeEventSource; +var activeKeys = new Map(); +var errorHandlers = new Set(); var updateEventSource = function updateEventSource() { - if (activeEventSource) activeEventSource.close() - if (activeKeys.size) { - activeEventSource = new EventSource( - urlBase + Array.from(activeKeys.keys()).join('@') - ) - /** - * @this {EventSource} - * @param {Event & { message?: string, filename?: string, lineno?: number, colno?: number, error?: Error }} event event - */ - activeEventSource.onerror = function (event) { - errorHandlers.forEach(function (onError) { - onError( - new Error( - 'Problem communicating active modules to the server: ' + - event.message + - ' ' + - event.filename + - ':' + - event.lineno + - ':' + - event.colno + - ' ' + - event.error - ) - ) - }) - } - } else { - activeEventSource = undefined - } -} + if (activeEventSource) activeEventSource.close(); + if (activeKeys.size) { + activeEventSource = new EventSource( + urlBase + Array.from(activeKeys.keys()).join("@") + ); + /** + * @this {EventSource} + * @param {Event & { message?: string, filename?: string, lineno?: number, colno?: number, error?: Error }} event event + */ + activeEventSource.onerror = function (event) { + errorHandlers.forEach(function (onError) { + onError( + new Error( + "Problem communicating active modules to the server: " + + event.message + + " " + + event.filename + + ":" + + event.lineno + + ":" + + event.colno + + " " + + event.error + ) + ); + }); + }; + } else { + activeEventSource = undefined; + } +}; /** * @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options * @returns {() => void} function to destroy response */ exports.keepAlive = function (options) { - var data = options.data - var onError = options.onError - var active = options.active - var module = options.module - errorHandlers.add(onError) - var value = activeKeys.get(data) || 0 - activeKeys.set(data, value + 1) - if (value === 0) { - updateEventSource() - } - if (!active && !module.hot) { - console.log( - 'Hot Module Replacement is not enabled. Waiting for process restart...' - ) - } + var data = options.data; + var onError = options.onError; + var active = options.active; + var module = options.module; + errorHandlers.add(onError); + var value = activeKeys.get(data) || 0; + activeKeys.set(data, value + 1); + if (value === 0) { + updateEventSource(); + } + if (!active && !module.hot) { + console.log( + "Hot Module Replacement is not enabled. Waiting for process restart..." + ); + } - return function () { - errorHandlers.delete(onError) - setTimeout(function () { - var value = activeKeys.get(data) - if (value === 1) { - activeKeys.delete(data) - updateEventSource() - } else { - activeKeys.set(data, value - 1) - } - }, 1000) - } -} + return function () { + errorHandlers.delete(onError); + setTimeout(function () { + var value = activeKeys.get(data); + if (value === 1) { + activeKeys.delete(data); + updateEventSource(); + } else { + activeKeys.set(data, value - 1); + } + }, 1000); + }; +};