From 3ce29eedf10b2d4c0f6ac6c29aeee932cd40af4a Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Tue, 27 Sep 2022 10:51:05 +0200 Subject: [PATCH] chore!: remove node 12 support (#5089) * chore!: remove node 12 support * chore: update docs Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .github/workflows/main.yml | 6 +- README.md | 25 ++- docs/README.md | 12 +- docs/netlify-dev.md | 180 +++++++++++++----- npm-shrinkwrap.json | 35 ++-- package.json | 3 +- site/package-lock.json | 2 +- site/package.json | 2 +- .../google-analytics/package-lock.json | 2 +- .../javascript/google-analytics/package.json | 2 +- src/utils/command-helpers.js | 4 +- src/utils/proxy.js | 5 +- tools/eslint-rules/package.json | 2 +- 13 files changed, 183 insertions(+), 97 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 066e2c508df..5efce66a8b3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,14 +48,14 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - node-version: [12.x, '*'] + node-version: [14.x, '*'] machine: ['0', '1', '2', '3', '4', '5', '6'] exclude: - os: macOS-latest - node-version: '12.x' + node-version: '14.x' - os: windows-latest - node-version: '12.x' + node-version: '14.x' fail-fast: false steps: # Sets an output parameter if this is a release PR diff --git a/README.md b/README.md index abd9bd1132e..a646e55a335 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ ![Netlify CLI](cli.png) [![Coverage Status](https://codecov.io/gh/netlify/cli/branch/main/graph/badge.svg)](https://codecov.io/gh/netlify/cli) -[![npm version][npm-img]][npm] [![downloads][dl-img]][dl] [![netlify-status][netlify-img]][netlify] [![security][snyk-img]][snyk] +[![npm version][npm-img]][npm] [![downloads][dl-img]][dl] [![netlify-status][netlify-img]][netlify] +[![security][snyk-img]][snyk] Interact with [Netlify](http://netlify.com/) from the comfort of your CLI. -See the [CLI command line reference](https://cli.netlify.com/commands/) to get started and the docs on using [Netlify Dev](https://github.com/netlify/cli/blob/main/docs/netlify-dev.md) to run your site locally. +See the [CLI command line reference](https://cli.netlify.com/commands/) to get started and the docs on using +[Netlify Dev](https://github.com/netlify/cli/blob/main/docs/netlify-dev.md) to run your site locally. ## Table of Contents @@ -46,22 +48,28 @@ See the [CLI command line reference](https://cli.netlify.com/commands/) to get s ## Installation -Netlify CLI requires [Node.js](https://nodejs.org) version 12 or above. To install, run the following command from any directory in your terminal: +Netlify CLI requires [Node.js](https://nodejs.org) version 14 or above. To install, run the following command from any +directory in your terminal: ```bash npm install netlify-cli -g ``` -When using the CLI in a CI environment we recommend installing it locally as a development dependency, instead of globally. -To install locally, run the following command from the root directory of your project: +When using the CLI in a CI environment we recommend installing it locally as a development dependency, instead of +globally. To install locally, run the following command from the root directory of your project: ```bash npm install --save-dev netlify-cli ``` -**Important:** Running `npm install netlify-cli -g` in CI means you're always installing the latest version of the CLI, including **breaking changes**. When you install locally and use a [lock file](https://docs.npmjs.com/cli/v7/commands/npm-ci) you guarantee reproducible builds. To manage CLI updates we recommend using an automated tool like [renovate](https://github.com/renovatebot/renovate) or [dependabot](https://github.com/dependabot). +**Important:** Running `npm install netlify-cli -g` in CI means you're always installing the latest version of the CLI, +including **breaking changes**. When you install locally and use a +[lock file](https://docs.npmjs.com/cli/v7/commands/npm-ci) you guarantee reproducible builds. To manage CLI updates we +recommend using an automated tool like [renovate](https://github.com/renovatebot/renovate) or +[dependabot](https://github.com/dependabot). -Alternatively you may also use Homebrew: `brew install netlify-cli` (thanks [@cglong](https://github.com/netlify/cli/issues/291)). +Alternatively you may also use Homebrew: `brew install netlify-cli` (thanks +[@cglong](https://github.com/netlify/cli/issues/291)). ## Usage @@ -76,7 +84,8 @@ netlify [command] help ## Documentation -To learn how to log in to Netlify and start deploying sites, visit the [documentation on Netlify](https://docs.netlify.com/cli/get-started/). +To learn how to log in to Netlify and start deploying sites, visit the +[documentation on Netlify](https://docs.netlify.com/cli/get-started/). For a full command reference, see the list below, or visit [cli.netlify.com](https://cli.netlify.com/). diff --git a/docs/README.md b/docs/README.md index 5ac86b2770c..8ae49013435 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,12 +5,13 @@ description: All Netlify CLI commands # Netlify CLI Command List -Welcome to the Netlify CLI! This site provides online access to all help strings in the Netlify CLI. For a more in-depth guide, please see our [Getting Started](https://docs.netlify.com/cli/get-started/) guide on our main docs site. +Welcome to the Netlify CLI! This site provides online access to all help strings in the Netlify CLI. For a more in-depth +guide, please see our [Getting Started](https://docs.netlify.com/cli/get-started/) guide on our main docs site. -If you have questions, ideas, or would like to contribute, check out the [repository on GitHub](https://github.com/netlify/cli/). +If you have questions, ideas, or would like to contribute, check out the +[repository on GitHub](https://github.com/netlify/cli/). -**Before you begin** -Make sure you have [Node.js](https://nodejs.org/en/download/) version 12.20.0, 14.14.0, 16.0.0, or later. +**Before you begin** Make sure you have [Node.js](https://nodejs.org/en/download/) version 16.0.0, or later. **Install the CLI** @@ -20,7 +21,8 @@ To install the CLI, pop open your terminal and install with `npm`. npm install netlify-cli -g ``` -**Important:** When using the CLI in a CI environment we recommend installing it locally. See more [here](https://github.com/netlify/cli#installation). +**Important:** When using the CLI in a CI environment we recommend installing it locally. See more +[here](https://github.com/netlify/cli#installation). **Listing commands** diff --git a/docs/netlify-dev.md b/docs/netlify-dev.md index d137db43ec8..905573ed6a6 100644 --- a/docs/netlify-dev.md +++ b/docs/netlify-dev.md @@ -2,12 +2,16 @@

Watch the introduction (24 minutes)

- + link to netlify dev talk
-Netlify Dev brings the power of Netlify's Edge Logic layer, [serverless functions](#netlify-functions) and [add-on ecosystem](#using-add-ons) to your local machine. It runs Netlify's production routing engine in a local dev server to make all redirects, proxy rules, function routes or add-on routes available locally and injects the correct environment variables from your site environment, installed add-ons or your netlify.toml file into your build and function environment. +Netlify Dev brings the power of Netlify's Edge Logic layer, [serverless functions](#netlify-functions) and +[add-on ecosystem](#using-add-ons) to your local machine. It runs Netlify's production routing engine in a local dev +server to make all redirects, proxy rules, function routes or add-on routes available locally and injects the correct +environment variables from your site environment, installed add-ons or your netlify.toml file into your build and +function environment. ``` ┌───────────────┐ @@ -27,13 +31,19 @@ Netlify Dev brings the power of Netlify's Edge Logic layer, [serverless function └──────────┘ ``` -With project detectors, it automatically detects common tools like Gatsby, Hugo, React Static, Eleventy, and more, to give a zero config setup for your local dev server and can help scaffolding new functions as you work on them. Read our blog post for [more on detectors and how you can contribute](https://www.netlify.com/blog/2019/04/24/zero-config-yet-technology-agnostic-how-netlify-dev-detectors-work/)! +With project detectors, it automatically detects common tools like Gatsby, Hugo, React Static, Eleventy, and more, to +give a zero config setup for your local dev server and can help scaffolding new functions as you work on them. Read our +blog post for +[more on detectors and how you can contribute](https://www.netlify.com/blog/2019/04/24/zero-config-yet-technology-agnostic-how-netlify-dev-detectors-work/)! ## Prerequisites - You should have the latest Netlify CLI version. Run `npm install -g netlify-cli` to be sure. - You should be [logged in on Netlify CLI](https://docs.netlify.com/cli/get-started/#authentication) -- Your project should be linked to a `siteID` on Netlify (using [netlify init](https://docs.netlify.com/cli/get-started/#continuous-deployment) or [netlify link](https://docs.netlify.com/cli/get-started/#linking-and-unlinking-sites)). You can confirm this has been done if you have a `.netlify` folder with a `state.json` file containing your `siteID`. +- Your project should be linked to a `siteID` on Netlify (using + [netlify init](https://docs.netlify.com/cli/get-started/#continuous-deployment) or + [netlify link](https://docs.netlify.com/cli/get-started/#linking-and-unlinking-sites)). You can confirm this has been + done if you have a `.netlify` folder with a `state.json` file containing your `siteID`. This is how we pull down your build environment variables and manage your addons on your local machine. @@ -48,7 +58,12 @@ This is how we pull down your build environment variables and manage your addons Pro tip: Aliasing commands -As these commands are expected to be frequently used, it may be helpful to define aliases in your terminal (Mac: [bash](https://jonsuh.com/blog/bash-command-line-shortcuts/), [zsh](https://askubuntu.com/questions/758496/how-to-make-a-permanent-alias-in-oh-my-zsh), Windows: [doskey](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt), [registry](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt)) to your personal preference. For example: +As these commands are expected to be frequently used, it may be helpful to define aliases in your terminal (Mac: +[bash](https://jonsuh.com/blog/bash-command-line-shortcuts/), +[zsh](https://askubuntu.com/questions/758496/how-to-make-a-permanent-alias-in-oh-my-zsh), Windows: +[doskey](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt), +[registry](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt)) to your personal preference. +For example: ```bash ## ~/.zshrc @@ -85,7 +100,8 @@ EXAMPLES $ netlify dev -c "hugo server -w" --targetPort 1313 ``` -The command will automatically open your preferred browser to serve the application. You can customize this behaviour by using the `BROWSER` environment variable: +The command will automatically open your preferred browser to serve the application. You can customize this behaviour by +using the `BROWSER` environment variable: ```bash $ BROWSER=none netlify dev # this will disable the auto opening of the browser @@ -99,11 +115,13 @@ To share your ongoing dev session with a coworker, just run Netlify Dev with a ` netlify dev --live ``` -You will get a URL that looks like `https://clever-cray-2aa156-6639f3.netlify.live/`. This can be accessed by anyone as long as you keep your session open. +You will get a URL that looks like `https://clever-cray-2aa156-6639f3.netlify.live/`. This can be accessed by anyone as +long as you keep your session open. ## netlify.toml [dev] block -Netlify Dev is meant to work with zero config for the majority of users, by using its detector system. However you may wish to assert more control over its behavior, and should make use of the new `[dev]` block in `netlify.toml` to do so: +Netlify Dev is meant to work with zero config for the majority of users, by using its detector system. However you may +wish to assert more control over its behavior, and should make use of the new `[dev]` block in `netlify.toml` to do so: ```toml # sample netlify.toml @@ -130,9 +148,14 @@ Netlify Dev is meant to work with zero config for the majority of users, by usin ## Project detection -Netlify Dev will attempt to detect the site generator or build command that you are using, and run these on your behalf, while adding other development utilities. If you have a JavaScript project, it looks for the best `package.json` script to run for you, using simple heuristics, so you can use the full flexibility of npm scripts. +Netlify Dev will attempt to detect the site generator or build command that you are using, and run these on your behalf, +while adding other development utilities. If you have a JavaScript project, it looks for the best `package.json` script +to run for you, using simple heuristics, so you can use the full flexibility of npm scripts. -**Overriding framework detection**: The number of [frameworks which Netlify Dev can detect](https://github.com/netlify/framework-info/tree/main/src/frameworks) is growing, but if yours is not yet supported (contributions welcome!), you can instruct Netlify Dev to run the project on your behalf by declaring it in a `[dev]` block of your `netlify.toml` file. +**Overriding framework detection**: The number of +[frameworks which Netlify Dev can detect](https://github.com/netlify/framework-info/tree/main/src/frameworks) is +growing, but if yours is not yet supported (contributions welcome!), you can instruct Netlify Dev to run the project on +your behalf by declaring it in a `[dev]` block of your `netlify.toml` file. ```toml # sample dev block in the toml @@ -144,9 +167,8 @@ Netlify Dev will attempt to detect the site generator or build command that you publish = "dist" # If you use a _redirect file, provide the path to your static content folder ``` -If your project is being detected incorrectly or positive by multiple -detectors you can specify `framework` option to test only one detector -against your project. +If your project is being detected incorrectly or positive by multiple detectors you can specify `framework` option to +test only one detector against your project. ```toml [dev] @@ -155,20 +177,27 @@ against your project. Possible values of `framework`: -- `#auto` (default) to check of all [available frameworks](https://github.com/netlify/framework-info/tree/main/src/frameworks). +- `#auto` (default) to check of all + [available frameworks](https://github.com/netlify/framework-info/tree/main/src/frameworks). - One of the framework ids as specified [here](https://github.com/netlify/framework-info/tree/main/src/frameworks). - `#static` for a static file server - `#custom` to use the `command` option to run an app server and `targetPort` option to connect to it ## Explanation of ports in Netlify Dev -There will be a number of ports that you will encounter when using Netlify Dev, especially when running a static site generator like Gatsby which has its own dev server. All the port numbers can be a bit confusing, so here is a brief explainer. +There will be a number of ports that you will encounter when using Netlify Dev, especially when running a static site +generator like Gatsby which has its own dev server. All the port numbers can be a bit confusing, so here is a brief +explainer. -- If your site generator runs on port 8000 for example, Netlify Dev needs to be told to connect to that port, so, it can route the requests successfully to the site generator along with the rest of the local Netlify environment -- If you’re running a project we have a detector for, we hardcode those conventional ports so you don't have to supply it yourself. If we have multiple detectors that match, we'll ask you to choose. -- However, sometimes you’re using some unrecognized site generator or just have a server you want Netlify Dev to connect to. This is when you go to the `netlify.toml` `[dev]` block to specify exactly what port we should listen to. +- If your site generator runs on port 8000 for example, Netlify Dev needs to be told to connect to that port, so, it can + route the requests successfully to the site generator along with the rest of the local Netlify environment +- If you’re running a project we have a detector for, we hardcode those conventional ports so you don't have to supply + it yourself. If we have multiple detectors that match, we'll ask you to choose. +- However, sometimes you’re using some unrecognized site generator or just have a server you want Netlify Dev to connect + to. This is when you go to the `netlify.toml` `[dev]` block to specify exactly what port we should listen to. -As for which port to use while doing local development in Netlify Dev, always search for this box in your console output and use that: +As for which port to use while doing local development in Netlify Dev, always search for this box in your console output +and use that: ```bash ┌──────────────────────────────────────────────────────────────┐ @@ -180,16 +209,20 @@ As for which port to use while doing local development in Netlify Dev, always se **Specifying custom ports for Netlify Dev** -Netlify Dev allows you to specify the following parameters for port as both flags and in config file (`netlify.toml` etc.): +Netlify Dev allows you to specify the following parameters for port as both flags and in config file (`netlify.toml` +etc.): - `targetPort`: The port for your application server, framework or site generator. - `port`: The port for the Netlify Dev server, the one you'll open in the browser. -Netlify Dev tries to acquire these ports but if any of them is not available (already in use by another application), it will throw an error and let you know. +Netlify Dev tries to acquire these ports but if any of them is not available (already in use by another application), it +will throw an error and let you know. ## Redirects -Netlify Dev has the ability emulate the [redirect capability](https://docs.netlify.com/routing/redirects/) Netlify provide on the [ADN](https://netlify.com/features/adn) in your local environment. The same redirect rules which you configure to run on the edge, will also work in your local builds. +Netlify Dev has the ability emulate the [redirect capability](https://docs.netlify.com/routing/redirects/) Netlify +provide on the [ADN](https://netlify.com/features/adn) in your local environment. The same redirect rules which you +configure to run on the edge, will also work in your local builds. Netlify dev supports redirect rules defined in either `_redirects` or `netlify.toml` files. @@ -199,18 +232,26 @@ The order of precedence for applying redirect rules is: 1. `netlify.toml` file (in the project's publish folder) 1. `netlify.toml` file (in the project's root folder) -See the [Redirects Documentation](https://docs.netlify.com/routing/redirects/) for more information on Netlify's redirect and proxying capabilities. +See the [Redirects Documentation](https://docs.netlify.com/routing/redirects/) for more information on Netlify's +redirect and proxying capabilities. ## Environment Variables -If the current project is linked to a Netlify site (`netlify link`), environment variables are pulled down from production and populated in `netlify dev` server. This functionality requires that you’re logged in (`netlify login`) and connected to the internet when running `netlify dev`. +If the current project is linked to a Netlify site (`netlify link`), environment variables are pulled down from +production and populated in `netlify dev` server. This functionality requires that you’re logged in (`netlify login`) +and connected to the internet when running `netlify dev`. -Netlify Dev also supports local environment variables through `.env` files. -Netlify Dev will look in project root directory for `.env` file and will provide those variables to the spawned site generator/server and Netlify Functions. +Netlify Dev also supports local environment variables through `.env` files. Netlify Dev will look in project root +directory for `.env` file and will provide those variables to the spawned site generator/server and Netlify Functions. ## Netlify Functions -Netlify can also create serverless functions for you locally as part of Netlify Functions. The serverless functions can then be run by Netlify Dev in the same way they would be when deployed to the cloud. Once you've configured the [functions directory in your `netlify.toml`](https://docs.netlify.com/configure-builds/file-based-configuration/#sample-file), the functions will be accessible through `netlify dev` server. e.g. at `http://localhost:8888/.netlify/functions/function-name`. Besides interacting with your functions through the browser, you can also use the following commands: +Netlify can also create serverless functions for you locally as part of Netlify Functions. The serverless functions can +then be run by Netlify Dev in the same way they would be when deployed to the cloud. Once you've configured the +[functions directory in your `netlify.toml`](https://docs.netlify.com/configure-builds/file-based-configuration/#sample-file), +the functions will be accessible through `netlify dev` server. e.g. at +`http://localhost:8888/.netlify/functions/function-name`. Besides interacting with your functions through the browser, +you can also use the following commands: ``` ## list of major functionality @@ -219,7 +260,8 @@ netlify functions:create netlify functions:invoke ``` -A number of function templates are available to get you started, and you can add your own utility functions to suit your own project development needs. You can also locally invoke them with test payload data. +A number of function templates are available to get you started, and you can add your own utility functions to suit your +own project development needs. You can also locally invoke them with test payload data. **Create a new function** @@ -227,7 +269,10 @@ A number of function templates are available to get you started, and you can add $ netlify functions:create ``` -Important note: Your functions will likely have `node_modules` in each folder. These are usually gitignored. You can write bash scripts to install them for production, or use the lightweight [`netlify-lambda install`](https://github.com/netlify/netlify-lambda/blob/master/README.md#netlify-lambda-install) CLI to do it for you. +Important note: Your functions will likely have `node_modules` in each folder. These are usually gitignored. You can +write bash scripts to install them for production, or use the lightweight +[`netlify-lambda install`](https://github.com/netlify/netlify-lambda/blob/master/README.md#netlify-lambda-install) CLI +to do it for you.
@@ -250,11 +295,16 @@ $ netlify functions:create hello-world --url https://github.com/netlify-labs/all **Deploying unbundled function folders** -Functions that have `node_modules` inside their own folders require these `node_modules` to be installed when deployed. For the time being, **the Netlify build process does not recursively install dependencies for your function folders yet**. You can write `prebuild` or `postinstall` bash scripts to install them for production, or use the lightweight [`netlify-lambda install`](https://github.com/netlify/netlify-lambda/blob/master/README.md#netlify-lambda-install) CLI to do it for you. +Functions that have `node_modules` inside their own folders require these `node_modules` to be installed when deployed. +For the time being, **the Netlify build process does not recursively install dependencies for your function folders +yet**. You can write `prebuild` or `postinstall` bash scripts to install them for production, or use the lightweight +[`netlify-lambda install`](https://github.com/netlify/netlify-lambda/blob/master/README.md#netlify-lambda-install) CLI +to do it for you. **Writing your own Function Templates** -Function templates can specify `addons` that they rely on as well as execute arbitrary code after installation in an `onComplete` hook, if a special `.netlify-function-template.js` file exists in the directory: +Function templates can specify `addons` that they rely on as well as execute arbitrary code after installation in an +`onComplete` hook, if a special `.netlify-function-template.js` file exists in the directory: ```js // .netlify-function-template.js @@ -271,13 +321,16 @@ module.exports = { } ``` -Instead of using our basic templates, you can use your own by passing it with a --url flag: `netlify functions:create hello-world --url https://github.com/netlify-labs/all-the-functions/tree/master/functions/9-using-middleware`, specifying any addons and postinstall/complete steps as shown above. +Instead of using our basic templates, you can use your own by passing it with a --url flag: +`netlify functions:create hello-world --url https://github.com/netlify-labs/all-the-functions/tree/master/functions/9-using-middleware`, +specifying any addons and postinstall/complete steps as shown above.
### Locally Testing Functions with `netlify functions:invoke` -`netlify functions:invoke` allows you to locally test functions going above and beyond a simple GET request in browser. (we only model POSTs now but could easily expand from here). +`netlify functions:invoke` allows you to locally test functions going above and beyond a simple GET request in browser. +(we only model POSTs now but could easily expand from here). If you have Netlify Dev running your functions, you can then test sending payloads of data, or authentication payloads: @@ -298,33 +351,51 @@ netlify functions:invoke myfunction --querystring "foo=1" netlify functions:invoke myfunction --payload "./pathTo.json" ``` -There are special cases for [event triggered functions](https://docs.netlify.com/functions/trigger-on-events/) (eg `identity-signup`) which will also give you mock data for testing. This makes manual local testing of event triggered functions possible, which drastically improves the development experience. +There are special cases for [event triggered functions](https://docs.netlify.com/functions/trigger-on-events/) (eg +`identity-signup`) which will also give you mock data for testing. This makes manual local testing of event triggered +functions possible, which drastically improves the development experience. This is a new feature; ideas and feedback and issues and PR's welcome! ### Function Builders, Function Builder Detection, and Relationship with `netlify-lambda` -**Existing users of `netlify-lambda` should have no change to their workflow by switching to `netlify dev`.** One immediate benefit is no need for [proxying](https://github.com/netlify/netlify-lambda#proxying-for-local-development) since Netlify Dev does that for you. +**Existing users of `netlify-lambda` should have no change to their workflow by switching to `netlify dev`.** One +immediate benefit is no need for [proxying](https://github.com/netlify/netlify-lambda#proxying-for-local-development) +since Netlify Dev does that for you. **Why Function Builders** -Notice that all the functions created by `netlify functions:create` require no build step. This is intentional: we want to remain agnostic of build tooling and thereby create clear expectations: You give us a folder of functions, and we simply serve it (This is called [`zip-it-and-ship-it`](https://github.com/netlify/zip-it-and-ship-it)). If you want to build that folder from a separate source folder, that is entirely under your control. Use whatever tool you like. +Notice that all the functions created by `netlify functions:create` require no build step. This is intentional: we want +to remain agnostic of build tooling and thereby create clear expectations: You give us a folder of functions, and we +simply serve it (This is called [`zip-it-and-ship-it`](https://github.com/netlify/zip-it-and-ship-it)). If you want to +build that folder from a separate source folder, that is entirely under your control. Use whatever tool you like. -This can be helpful, for example, to use ES modules syntax (e.g. `import`/`export`) via webpack, babel transforms via `babel-cli` or `babel-loader`, or strict type-checking and transpilation with TypeScript's `tsc` or other webpack loaders. +This can be helpful, for example, to use ES modules syntax (e.g. `import`/`export`) via webpack, babel transforms via +`babel-cli` or `babel-loader`, or strict type-checking and transpilation with TypeScript's `tsc` or other webpack +loaders. -We'll call this category of tools **function builders**. In fact, we do maintain an open source function builder dedicated to the task of transforming serverless functions from source to destination via webpack, called [`netlify-lambda`](https://github.com/netlify/netlify-lambda). We maintain [a comparison between Netlify Dev and `netlify-lambda` on its README as well as advice on when to use which or both](https://github.com/netlify/netlify-lambda#netlify-lambda). +We'll call this category of tools **function builders**. In fact, we do maintain an open source function builder +dedicated to the task of transforming serverless functions from source to destination via webpack, called +[`netlify-lambda`](https://github.com/netlify/netlify-lambda). We maintain +[a comparison between Netlify Dev and `netlify-lambda` on its README as well as advice on when to use which or both](https://github.com/netlify/netlify-lambda#netlify-lambda). **Function Builder Detection** -We don't expect everyone to use function builders, but we expect many will, and want to provide helpful defaults that "just work" for this. To do that, we use a similar detection concept to [project detectors](#Project-detection), and look for common function builder setups. +We don't expect everyone to use function builders, but we expect many will, and want to provide helpful defaults that +"just work" for this. To do that, we use a similar detection concept to [project detectors](#Project-detection), and +look for common function builder setups. -With this feature, pre-Netlify Dev projects like https://github.com/netlify/create-react-app-lambda can immediately use the `netlify dev` command with no change to code. Currently, we only offer detection for scripts with `netlify-lambda build $SRCFOLDER`. More ideas are welcome. +With this feature, pre-Netlify Dev projects like https://github.com/netlify/create-react-app-lambda can immediately use +the `netlify dev` command with no change to code. Currently, we only offer detection for scripts with +`netlify-lambda build $SRCFOLDER`. More ideas are welcome. -Netlify Dev will watch `netlify-lambda`'s source folder and rebuild whenever the source file changes, eliminating the need for `netlify-lambda serve` since we don't want a duplicate functions server. +Netlify Dev will watch `netlify-lambda`'s source folder and rebuild whenever the source file changes, eliminating the +need for `netlify-lambda serve` since we don't want a duplicate functions server. **Bring Your Own Function Builder** -We may offer detection for more function builders in future, and also let you specify function build commands in the `netlify.toml` `[dev]` block. Please share your use case with us if you are likely to need this. +We may offer detection for more function builders in future, and also let you specify function build commands in the +`netlify.toml` `[dev]` block. Please share your use case with us if you are likely to need this. ### Using Add-ons @@ -338,18 +409,21 @@ To try out an add-on with Netlify dev, run the `netlify addons:create` command: netlify addons:create fauna ``` -The above command will install the FaunaDB add-on and provision a noSQL database for your site to leverage. The FaunaDB add-on injects environment variables into your site's build process and the serverless functions. +The above command will install the FaunaDB add-on and provision a noSQL database for your site to leverage. The FaunaDB +add-on injects environment variables into your site's build process and the serverless functions. Or install this [one click example](https://github.com/netlify/fauna-one-click). -After you have installed an add-on, it will be visible with the `netlify addons:list` command inside your site's current working directory. You can use `netlify addons:delete $ADDONNAME` to delete your addon instance. +After you have installed an add-on, it will be visible with the `netlify addons:list` command inside your site's current +working directory. You can use `netlify addons:delete $ADDONNAME` to delete your addon instance. -For now, it is important to include instructions to create addons for each member of your team, as there is no way to specify addons inside of `netlify.toml`. We are working on this. +For now, it is important to include instructions to create addons for each member of your team, as there is no way to +specify addons inside of `netlify.toml`. We are working on this. ### Running an https server for local development -By default, `netlify dev` starts an HTTP server. If you require HTTPS, you can configure a certificate and key file for use by `netlify dev`. -Example `netlify.toml`: +By default, `netlify dev` starts an HTTP server. If you require HTTPS, you can configure a certificate and key file for +use by `netlify dev`. Example `netlify.toml`: ```toml [dev] @@ -358,8 +432,9 @@ certFile = "cert.pem" keyFile = "key.pem" ``` -**Important -** If you’re using a self-signed certificate, you might need to configure your browser to accept it when running on `localhost`. -To enable this setting for Chrome, visit `chrome://flags/#allow-insecure-localhost` in your browser. +**Important -** If you’re using a self-signed certificate, you might need to configure your browser to accept it when +running on `localhost`. To enable this setting for Chrome, visit `chrome://flags/#allow-insecure-localhost` in your +browser. ## Contributing/Local Development @@ -369,9 +444,12 @@ Thanks for contributing! You'll need to follow these steps to run Netlify CLI an 2. clone and install deps for https://github.com/netlify/cli 3. `npm link` from inside the `cli` folder -Now you’re both ready to start testing `netlify dev` and to contribute to the project! Note these are untested instructions, please get in touch if you’re unable to follow them clearly and we'll work with you. Or ping [@swyx](https://twitter.com/swyx). +Now you’re both ready to start testing `netlify dev` and to contribute to the project! Note these are untested +instructions, please get in touch if you’re unable to follow them clearly and we'll work with you. Or ping +[@swyx](https://twitter.com/swyx). -Note that code that you may be debugging or investigating may be in some transitive dependencies we have published as separate libraries: +Note that code that you may be debugging or investigating may be in some transitive dependencies we have published as +separate libraries: - https://github.com/netlify/netlify-rules-proxy/ ([npm](https://www.npmjs.com/package/@netlify/rules-proxy)) - https://github.com/netlify/node-redirects-parser ([npm](https://www.npmjs.com/package/netlify-redirect-parser)) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index c68e812d400..72190ff5d1f 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -87,7 +87,6 @@ "node-version-alias": "^1.0.1", "omit.js": "^2.0.2", "ora": "^5.0.0", - "p-event": "^4.2.0", "p-filter": "^2.1.0", "p-map": "^4.0.0", "p-wait-for": "^3.0.0", @@ -150,7 +149,7 @@ "verdaccio": "^5.10.2" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@ampproject/remapping": { @@ -1257,7 +1256,7 @@ "netlify-build": "lib/core/bin.js" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/build/node_modules/@sindresorhus/is": { @@ -1918,7 +1917,7 @@ "readdirp": "^3.4.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/cache-utils/node_modules/globby": { @@ -2056,7 +2055,7 @@ "netlify-config": "lib/bin/main.js" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/config/node_modules/chalk": { @@ -2377,7 +2376,7 @@ "uuid": "^9.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/edge-bundler/node_modules/env-paths": { @@ -3125,7 +3124,7 @@ "semver": "^7.3.4" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/framework-info/node_modules/aggregate-error": { @@ -3354,7 +3353,7 @@ "path-exists": "^5.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/functions-utils/node_modules/path-exists": { @@ -3377,7 +3376,7 @@ "path-exists": "^5.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/git-utils/node_modules/execa": { @@ -3699,7 +3698,7 @@ "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.46.0.tgz", "integrity": "sha512-kUX90Eacqko9ni3cepVZKXFTLmhdwES/HDRlMYxyUh+SmvXWRC+h43b11nA0/6M5PEPolUChQOZN9wZql6oJJw==", "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/run-utils": { @@ -3710,7 +3709,7 @@ "execa": "^6.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/run-utils/node_modules/execa": { @@ -3846,7 +3845,7 @@ "zip-it-and-ship-it": "dist/bin.js" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@netlify/zip-it-and-ship-it/node_modules/@babel/parser": { @@ -9013,7 +9012,7 @@ "typescript": "^4.5.5" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/detective-typescript/node_modules/node-source-walk": { @@ -12065,7 +12064,7 @@ "semver": "^7.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/git-raw-commits": { @@ -16003,7 +16002,7 @@ "qs": "^6.9.6" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/netlify-headers-parser": { @@ -16018,7 +16017,7 @@ "toml": "^3.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/netlify-headers-parser/node_modules/escape-string-regexp": { @@ -16092,7 +16091,7 @@ "toml": "^3.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/netlify-redirect-parser/node_modules/filter-obj": { @@ -18232,7 +18231,7 @@ "precinct": "bin/cli.js" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/precinct/node_modules/node-source-walk": { diff --git a/package.json b/package.json index 8f9b80a9752..4129e769002 100644 --- a/package.json +++ b/package.json @@ -156,7 +156,7 @@ "swyx (https://twitter.com/swyx)" ], "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" }, "files": [ "/bin", @@ -300,7 +300,6 @@ "node-version-alias": "^1.0.1", "omit.js": "^2.0.2", "ora": "^5.0.0", - "p-event": "^4.2.0", "p-filter": "^2.1.0", "p-map": "^4.0.0", "p-wait-for": "^3.0.0", diff --git a/site/package-lock.json b/site/package-lock.json index 94e933fb5f1..eeb5c84ecb3 100644 --- a/site/package-lock.json +++ b/site/package-lock.json @@ -31,7 +31,7 @@ "strip-ansi": "^6.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/@algolia/cache-browser-local-storage": { diff --git a/site/package.json b/site/package.json index d978b648bf6..9f630c74623 100644 --- a/site/package.json +++ b/site/package.json @@ -26,7 +26,7 @@ "clean": "rimraf dist" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" }, "license": "MIT", "dependencies": { diff --git a/src/functions-templates/javascript/google-analytics/package-lock.json b/src/functions-templates/javascript/google-analytics/package-lock.json index 9394daff3c5..c68b04f52ee 100644 --- a/src/functions-templates/javascript/google-analytics/package-lock.json +++ b/src/functions-templates/javascript/google-analytics/package-lock.json @@ -13,7 +13,7 @@ "uuid": "^9.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }, "node_modules/node-fetch": { diff --git a/src/functions-templates/javascript/google-analytics/package.json b/src/functions-templates/javascript/google-analytics/package.json index a522bd8442e..7fd6b6c2794 100644 --- a/src/functions-templates/javascript/google-analytics/package.json +++ b/src/functions-templates/javascript/google-analytics/package.json @@ -7,7 +7,7 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" }, "keywords": [ "netlify", diff --git a/src/utils/command-helpers.js b/src/utils/command-helpers.js index 6bc15869208..9f82cf7d4a7 100644 --- a/src/utils/command-helpers.js +++ b/src/utils/command-helpers.js @@ -1,4 +1,5 @@ // @ts-check +const { once } = require('events') const os = require('os') const process = require('process') const { format, inspect } = require('util') @@ -9,7 +10,6 @@ const decache = require('decache') const WSL = require('is-wsl') const debounce = require('lodash/debounce') const { default: omit } = require('omit.js') -const pEvent = require('p-event') const terminalLink = require('terminal-link') const { name, version } = require('../../package.json') @@ -218,7 +218,7 @@ const DEBOUNCE_WAIT = 100 const watchDebounced = async (target, { depth, onAdd = () => {}, onChange = () => {}, onUnlink = () => {} }) => { const watcher = chokidar.watch(target, { depth, ignored: /node_modules/, ignoreInitial: true }) - await pEvent(watcher, 'ready') + await once(watcher, 'ready') const debouncedOnChange = debounce(onChange, DEBOUNCE_WAIT) const debouncedOnUnlink = debounce(onUnlink, DEBOUNCE_WAIT) diff --git a/src/utils/proxy.js b/src/utils/proxy.js index 122f9b43e6d..c2cfe5ccfe8 100644 --- a/src/utils/proxy.js +++ b/src/utils/proxy.js @@ -1,5 +1,6 @@ // @ts-check const { Buffer } = require('buffer') +const { once } = require('events') const { readFile } = require('fs').promises const http = require('http') const https = require('https') @@ -14,7 +15,6 @@ const { createProxyMiddleware } = require('http-proxy-middleware') const jwtDecode = require('jwt-decode') const locatePath = require('locate-path') const isEmpty = require('lodash/isEmpty') -const pEvent = require('p-event') const pFilter = require('p-filter') const toReadableStream = require('to-readable-stream') @@ -529,8 +529,7 @@ const startProxy = async function ({ }) server.listen({ port: settings.port }) - // TODO: use events.once when we drop support for Node.js < 12 - await pEvent(server, 'listening') + await once(server, 'listening') const scheme = settings.https ? 'https' : 'http' return `${scheme}://localhost:${settings.port}` diff --git a/tools/eslint-rules/package.json b/tools/eslint-rules/package.json index 1daaf4df70f..2433c7dda5d 100644 --- a/tools/eslint-rules/package.json +++ b/tools/eslint-rules/package.json @@ -8,6 +8,6 @@ "ava": "^4.0.0" }, "engines": { - "node": "^12.20.0 || ^14.14.0 || >=16.0.0" + "node": "^14.16.0 || >=16.0.0" } }