rsnext/packages/next/compiled/cli-select/index.js
Houssein Djirdeh 7a1c9eb17e
[ESLint] Introduce a new setup process when next lint is run for the first time (#26584)
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
2021-08-04 21:53:15 +00:00

1 line
No EOL
6.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module.exports=(()=>{"use strict";var e={610:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.withPromise=t.withCallback=void 0;const r=(e,t,r)=>{e.open();e.onSelect((e,s)=>r(t(e,s)))};t.withCallback=r;const s=(e,t)=>{return new Promise((r,s)=>{e.open();e.onSelect((e,i)=>{if(e===null){s()}else{r(t(e,i))}})})};t.withPromise=s},960:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var s=_interopRequireDefault(r(213));var i=_interopRequireDefault(r(88));var n=r(610);var u=r(797);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};var s=Object.keys(r);if(typeof Object.getOwnPropertySymbols==="function"){s=s.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))}s.forEach(function(t){_defineProperty(e,t,r[t])})}return e}function _defineProperty(e,t,r){if(t in e){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true})}else{e[t]=r}return e}const o={outputStream:process.stdout,inputStream:process.stdin,values:[],defaultValue:0,selected:"(x)",unselected:"( )",indentation:0,cleanup:true,valueRenderer:e=>e};const a=(e,t)=>{e=_objectSpread({},o,e);const r=new i.default(e,e.outputStream);const a=new s.default(e.inputStream);a.setDefaultValue(e.defaultValue);a.attachRenderer(r);let l;if(Array.isArray(e.values)){l=(0,u.withArrayValues)(e)}else{l=(0,u.withObjectValues)(e)}e.values=l.input;a.setValues(e.values);if(typeof t==="function"){return(0,n.withCallback)(a,l.output,t)}else{return(0,n.withPromise)(a,l.output)}};t=e.exports=a;Object.defineProperty(t,"__esModule",{value:true});var l=a;t.default=l},213:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var s=_interopRequireDefault(r(58));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}class Input{constructor(e=process.stdin){this.stream=e;this.values=[];this.selectedValue=0;this.onSelectListener=(()=>{});this.onKeyPress=this.onKeyPress.bind(this)}setValues(e){this.values=e;if(this.renderer){this.renderer.setValues(e)}}setDefaultValue(e){this.selectedValue=e}attachRenderer(e){this.renderer=e;this.renderer.setValues(this.values)}onSelect(e){this.onSelectListener=e}open(){s.default.emitKeypressEvents(this.stream);this.stream.on("keypress",this.onKeyPress);if(this.renderer){this.renderer.render(this.selectedValue)}this.stream.setRawMode(true);this.stream.resume()}close(e=false){this.stream.setRawMode(false);this.stream.pause();if(this.renderer){this.renderer.cleanup()}if(e){this.onSelectListener(null)}else{this.onSelectListener(this.selectedValue,this.values[this.selectedValue])}this.stream.removeListener("keypress",this.onKeyPress)}render(){if(!this.renderer){return}this.renderer.render(this.selectedValue)}onKeyPress(e,t){if(t){if(t.name==="up"&&this.selectedValue>0){this.selectedValue--;this.render()}else if(t.name==="down"&&this.selectedValue+1<this.values.length){this.selectedValue++;this.render()}else if(t.name==="return"){this.close()}else if(t.name==="escape"||t.name==="c"&&t.ctrl){this.close(true)}}}}t.default=Input},88:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.default=void 0;var s=_interopRequireDefault(r(58));var i=r(211);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}class Renderer{constructor(e,t=process.stdout){this.options=e;this.stream=t;this.values=[];this.initialRender=true}setValues(e){this.values=e}render(e=0){if(this.initialRender){this.initialRender=false;this.stream.write(i.cursorHide)}else{this.stream.write((0,i.eraseLines)(this.values.length))}this.values.forEach((t,r)=>{const s=e===r?this.options.selected:this.options.unselected;const i=" ".repeat(this.options.indentation);const n=this.options.valueRenderer(t,e===r);const u=r!==this.values.length-1?"\n":"";this.stream.write(i+s+" "+n+u)})}cleanup(){this.stream.write((0,i.eraseLines)(this.values.length));this.stream.write(i.cursorShow)}}t.default=Renderer},797:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.withObjectValues=t.withArrayValues=void 0;const r=e=>{return{input:e.values,output:(e,t)=>{return{id:e,value:t}}}};t.withArrayValues=r;const s=e=>{const t=e.values;return{input:Object.values(t),output:(e,r)=>{return{id:Object.keys(t)[e],value:r}}}};t.withObjectValues=s},211:e=>{const t=e.exports;const r="[";const s="]";const i="";const n=";";const u=process.env.TERM_PROGRAM==="Apple_Terminal";t.cursorTo=((e,t)=>{if(typeof e!=="number"){throw new TypeError("The `x` argument is required")}if(typeof t!=="number"){return r+(e+1)+"G"}return r+(t+1)+";"+(e+1)+"H"});t.cursorMove=((e,t)=>{if(typeof e!=="number"){throw new TypeError("The `x` argument is required")}let s="";if(e<0){s+=r+-e+"D"}else if(e>0){s+=r+e+"C"}if(t<0){s+=r+-t+"A"}else if(t>0){s+=r+t+"B"}return s});t.cursorUp=(e=>r+(typeof e==="number"?e:1)+"A");t.cursorDown=(e=>r+(typeof e==="number"?e:1)+"B");t.cursorForward=(e=>r+(typeof e==="number"?e:1)+"C");t.cursorBackward=(e=>r+(typeof e==="number"?e:1)+"D");t.cursorLeft=r+"G";t.cursorSavePosition=r+(u?"7":"s");t.cursorRestorePosition=r+(u?"8":"u");t.cursorGetPosition=r+"6n";t.cursorNextLine=r+"E";t.cursorPrevLine=r+"F";t.cursorHide=r+"?25l";t.cursorShow=r+"?25h";t.eraseLines=(e=>{let r="";for(let s=0;s<e;s++){r+=t.eraseLine+(s<e-1?t.cursorUp():"")}if(e){r+=t.cursorLeft}return r});t.eraseEndLine=r+"K";t.eraseStartLine=r+"1K";t.eraseLine=r+"2K";t.eraseDown=r+"J";t.eraseUp=r+"1J";t.eraseScreen=r+"2J";t.scrollUp=r+"S";t.scrollDown=r+"T";t.clearScreen="c";t.clearTerminal=process.platform==="win32"?`${t.eraseScreen}${r}0f`:`${t.eraseScreen}${r}3J${r}H`;t.beep=i;t.link=((e,t)=>{return[s,"8",n,n,t,i,e,s,"8",n,n,i].join("")});t.image=((e,t)=>{t=t||{};let r=s+"1337;File=inline=1";if(t.width){r+=`;width=${t.width}`}if(t.height){r+=`;height=${t.height}`}if(t.preserveAspectRatio===false){r+=";preserveAspectRatio=0"}return r+":"+e.toString("base64")+i});t.iTerm={};t.iTerm.setCwd=(e=>s+"50;CurrentDir="+(e||process.cwd())+i)},58:e=>{e.exports=require("readline")}};var t={};function __nccwpck_require__(r){if(t[r]){return t[r].exports}var s=t[r]={exports:{}};var i=true;try{e[r](s,s.exports,__nccwpck_require__);i=false}finally{if(i)delete t[r]}return s.exports}__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(960)})();