7a1c9eb17e
This PR introduces an improved developer experience when `next lint` is run for the first time. ### Current behavior `eslint-config-next` is a required package that must be installed before proceeding with `next lint` or `next build`: ![image](https://user-images.githubusercontent.com/12476932/123468791-43088100-d5c0-11eb-9ad0-5beb80b6c968.png) Although this has helped many developers start using the new ESLint config, this has also resulted in a few issues: - Users are required to install the full config (`eslint-config-next`) even if they do not use it or use the Next.js plugin directly (`eslint-plugin-next`). - #26348 - There's some confusion on why `eslint-config-next` needs to be installed or how it should be used instead of `eslint-plugin-next`. - #26574 - #26475 - #26438 ### New behavior Instead of enforcing `eslint-config-next` as a required package, this PR prompts the user by asking what config they would like to start. This happens when `next lint` is run for the first time **and** if no ESLint configuration is detected in the application. <img src="https://user-images.githubusercontent.com/12476932/124331177-e1668a80-db5c-11eb-8915-38d3dc20f5d4.gif" width="800" /> - The CLI will take care of installing `eslint` or `eslint-config-next` if either is not already installed - Users now have the option to choose between a strict configuration (`next/core-web-vitals`) or just the base configuration (`next`) - For users that decide to create their own ESLint configuration, or already have an existing one, **installing `eslint-config-next` will not be a requirement for `next lint` or `next build` to run**. A warning message will just show if the Next.js ESLint plugin is not detected in an ESLint config. <img width="682" alt="Screen Shot 2021-06-25 at 3 02 12 PM" src="https://user-images.githubusercontent.com/12476932/123473329-6cc4a680-d5c6-11eb-9a57-d5c0b89a2732.png"> --- In addition, this PR also: - Fixes #26348 - Updates documentation to make it more clear what approach to take for new and existing ESLint configurations
79 lines
3.1 KiB
TypeScript
79 lines
3.1 KiB
TypeScript
import { join } from 'path'
|
|
export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..')
|
|
export const NEXT_PROJECT_ROOT_DIST = join(NEXT_PROJECT_ROOT, 'dist')
|
|
export const NEXT_PROJECT_ROOT_NODE_MODULES = join(
|
|
NEXT_PROJECT_ROOT,
|
|
'node_modules'
|
|
)
|
|
export const NEXT_PROJECT_ROOT_DIST_CLIENT = join(
|
|
NEXT_PROJECT_ROOT_DIST,
|
|
'client'
|
|
)
|
|
export const NEXT_PROJECT_ROOT_DIST_SERVER = join(
|
|
NEXT_PROJECT_ROOT_DIST,
|
|
'server'
|
|
)
|
|
|
|
// Regex for API routes
|
|
export const API_ROUTE = /^\/api(?:\/|$)/
|
|
|
|
// Because on Windows absolute paths in the generated code can break because of numbers, eg 1 in the path,
|
|
// we have to use a private alias
|
|
export const PAGES_DIR_ALIAS = 'private-next-pages'
|
|
export const DOT_NEXT_ALIAS = 'private-dot-next'
|
|
|
|
export const PUBLIC_DIR_MIDDLEWARE_CONFLICT = `You can not have a '_next' folder inside of your public folder. This conflicts with the internal '/_next' route. https://nextjs.org/docs/messages/public-next-folder-conflict`
|
|
|
|
export const SSG_GET_INITIAL_PROPS_CONFLICT = `You can not use getInitialProps with getStaticProps. To use SSG, please remove your getInitialProps`
|
|
|
|
export const SERVER_PROPS_GET_INIT_PROPS_CONFLICT = `You can not use getInitialProps with getServerSideProps. Please remove getInitialProps.`
|
|
|
|
export const SERVER_PROPS_SSG_CONFLICT = `You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps`
|
|
|
|
export const STATIC_STATUS_PAGE_GET_INITIAL_PROPS_ERROR = `can not have getInitialProps/getServerSideProps, https://nextjs.org/docs/messages/404-get-initial-props`
|
|
|
|
export const SERVER_PROPS_EXPORT_ERROR = `pages with \`getServerSideProps\` can not be exported. See more info here: https://nextjs.org/docs/messages/gssp-export`
|
|
|
|
export const GSP_NO_RETURNED_VALUE =
|
|
'Your `getStaticProps` function did not return an object. Did you forget to add a `return`?'
|
|
export const GSSP_NO_RETURNED_VALUE =
|
|
'Your `getServerSideProps` function did not return an object. Did you forget to add a `return`?'
|
|
|
|
export const UNSTABLE_REVALIDATE_RENAME_ERROR =
|
|
'The `unstable_revalidate` property is available for general use.\n' +
|
|
'Please use `revalidate` instead.'
|
|
|
|
export const GSSP_COMPONENT_MEMBER_ERROR = `can not be attached to a page's component and must be exported from the page. See more info here: https://nextjs.org/docs/messages/gssp-component-member`
|
|
|
|
export const NON_STANDARD_NODE_ENV = `You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://nextjs.org/docs/messages/non-standard-node-env`
|
|
|
|
export const SSG_FALLBACK_EXPORT_ERROR = `Pages with \`fallback\` enabled in \`getStaticPaths\` can not be exported. See more info here: https://nextjs.org/docs/messages/ssg-fallback-true-export`
|
|
|
|
export const ESLINT_DEFAULT_DIRS = [
|
|
'pages',
|
|
'components',
|
|
'lib',
|
|
'src/pages',
|
|
'src/components',
|
|
'src/lib',
|
|
]
|
|
|
|
export const ESLINT_PROMPT_VALUES = [
|
|
{
|
|
title: 'Strict',
|
|
recommended: true,
|
|
config: {
|
|
extends: 'next/core-web-vitals',
|
|
},
|
|
},
|
|
{
|
|
title: 'Base',
|
|
config: {
|
|
extends: 'next',
|
|
},
|
|
},
|
|
{
|
|
title: 'Cancel',
|
|
config: null,
|
|
},
|
|
]
|