From dcbf92abf49a28b249df0c58c9252e0310022596 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Mon, 27 Apr 2020 16:24:33 +0200 Subject: [PATCH] Run Prettier --- .github/ISSUE_TEMPLATE.md | 5 +- CHANGELOG.md | 20 +-- README.md | 92 ++++++------ docs/README.md | 62 ++++---- docs/commands/addons.md | 27 ++-- docs/commands/api.md | 7 +- docs/commands/deploy.md | 38 ++--- docs/commands/dev.md | 25 ++-- docs/commands/functions.md | 35 ++--- docs/commands/index.md | 62 ++++---- docs/commands/init.md | 10 +- docs/commands/link.md | 8 +- docs/commands/login.md | 5 +- docs/commands/logout.md | 2 + docs/commands/open.md | 16 +- docs/commands/sites.md | 32 ++-- docs/commands/status.md | 11 +- docs/commands/unlink.md | 2 +- docs/commands/watch.md | 2 +- docs/netlify-dev.md | 16 +- renovate.json | 2 +- site/sync.js | 18 +-- src/commands/deploy.js | 6 +- src/commands/dev/index.js | 64 ++++---- src/commands/init.js | 2 +- src/commands/link.js | 2 +- src/commands/sites/delete.js | 2 +- src/detectors/eleventy.js | 10 +- .../netlify-lambda.js | 3 +- src/hooks/init.js | 7 +- src/tests/addons.test.js | 2 +- src/tests/dev.test.js | 14 +- src/tests/dummy-site/functions/env/env.js | 8 +- .../override-process-env.js | 8 +- src/tests/dummy-site/functions/timeout.js | 7 +- src/tests/utils/exec.js | 2 +- src/utils/detect-server.js | 56 ++++--- src/utils/get-repo-data.js | 4 +- src/utils/headers.js | 137 +++++++++--------- src/utils/headers.test.js | 108 +++++--------- src/utils/logo.js | 10 +- src/utils/rules-proxy.js | 17 ++- src/utils/serve-functions.js | 10 +- 43 files changed, 472 insertions(+), 504 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index d597fc784a1..f0bd85e9dd7 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -18,15 +18,12 @@ You do NOT have to include this information if this is a FEATURE REQUEST **- Do you want to request a _feature_ or report a _bug_?** - **- What is the current behavior?** - **- If the current behavior is a bug, please provide the steps to reproduce.** - **- What is the expected behavior?** - **- Local Environment Information** + diff --git a/CHANGELOG.md b/CHANGELOG.md index 37365e9203d..02f4d8117b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -118,7 +118,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Make sure to respect port flags and configuration [`#755`](https://github.com/netlify/cli/pull/755) - Add support for getting/tailing deploy logs [`#762`](https://github.com/netlify/cli/pull/762) - Deploy: Add flag to trigger build [`#760`](https://github.com/netlify/cli/pull/760) -- Add support for _headers files [`#754`](https://github.com/netlify/cli/pull/754) +- Add support for \_headers files [`#754`](https://github.com/netlify/cli/pull/754) - Upgrade `@netlify/build` [`#761`](https://github.com/netlify/cli/pull/761) ## [v2.40.0](https://github.com/netlify/cli/compare/v2.39.0...v2.40.0) - 2020-03-16 @@ -537,7 +537,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). ### Commits -- RulesProxy: Make sure _redirects works with dev [`27f92f2`](https://github.com/netlify/cli/commit/27f92f23148f7250e63a1586744d155a54751cd5) +- RulesProxy: Make sure \_redirects works with dev [`27f92f2`](https://github.com/netlify/cli/commit/27f92f23148f7250e63a1586744d155a54751cd5) - update logo [`3984bbb`](https://github.com/netlify/cli/commit/3984bbb1c4177fb410f9100d83baac7875ea0025) - Dev: Make stdio more maintainable [`4cbdb02`](https://github.com/netlify/cli/commit/4cbdb02ca85c7680b9c469aad5ce725e3975f86f) @@ -549,11 +549,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Dev: Make functions port configureable [`#525`](https://github.com/netlify/cli/pull/525) - Fix port for proxy redirects [`#520`](https://github.com/netlify/cli/pull/520) - Rules Proxy: Pass on query parameters [`#519`](https://github.com/netlify/cli/pull/519) -- Import rules-proxy and and redirect-parser [`#518`](https://github.com/netlify/cli/pull/518) +- Import rules-proxy and and redirect-parser [`#518`](https://github.com/netlify/cli/pull/518) - Consider sites from different team in Netlify link [`#500`](https://github.com/netlify/cli/pull/500) - Improve prompts for `link` command [`#502`](https://github.com/netlify/cli/pull/502) - Add Parcel detector [`#505`](https://github.com/netlify/cli/pull/505) -- rename deploy path [`#508`](https://github.com/netlify/cli/pull/508) +- rename deploy path [`#508`](https://github.com/netlify/cli/pull/508) - Improve analytics [`#513`](https://github.com/netlify/cli/pull/513) - Update ISSUE_TEMPLATE.md [`#504`](https://github.com/netlify/cli/pull/504) - Neltify -> Netlify [`#512`](https://github.com/netlify/cli/pull/512) @@ -903,7 +903,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - update netlify dev plugin [`514d759`](https://github.com/netlify/cli/commit/514d7591609fbd645c1de87f47200099e6919abe) - Add a test for raw parsing [`deb4cb9`](https://github.com/netlify/cli/commit/deb4cb97cf0ef12efba83b07c719064e9e16342e) -- Use conventional file casing [`60ad9d0`](https://github.com/netlify/cli/commit/60ad9d07c5a43ea24e78b63d70955e1a11dacc13) +- Use conventional file casing [`60ad9d0`](https://github.com/netlify/cli/commit/60ad9d07c5a43ea24e78b63d70955e1a11dacc13) ## [v2.11.7](https://github.com/netlify/cli/compare/v2.11.6...v2.11.7) - 2019-04-10 @@ -1117,7 +1117,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). ### Commits - Run `npm up` [`29f16fa`](https://github.com/netlify/cli/commit/29f16fa376a55093b09d0c14a67e6ab68a5718f7) -- Update js-client providing zip-n-ship capabilities [`f9774a2`](https://github.com/netlify/cli/commit/f9774a29781c37d10875563c6221c2b92d2d7800) +- Update js-client providing zip-n-ship capabilities [`f9774a2`](https://github.com/netlify/cli/commit/f9774a29781c37d10875563c6221c2b92d2d7800) - Update deps [`985e8da`](https://github.com/netlify/cli/commit/985e8da37e162fefabfd27ac5bf6e567ba7ea790) ## [v2.6.6](https://github.com/netlify/cli/compare/v2.6.5...v2.6.6) - 2019-01-31 @@ -1128,7 +1128,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). ### Commits -- Run prune before shrink-wrap [`761fcc5`](https://github.com/netlify/cli/commit/761fcc5660c8ac2a293afde661a129a0c8fbee84) +- Run prune before shrink-wrap [`761fcc5`](https://github.com/netlify/cli/commit/761fcc5660c8ac2a293afde661a129a0c8fbee84) ## [v2.6.5](https://github.com/netlify/cli/compare/v2.6.4...v2.6.5) - 2019-01-31 @@ -1165,7 +1165,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). ### Commits -- Update js-client to fix rate limit handling [`32590eb`](https://github.com/netlify/cli/commit/32590ebf2aa9788733908afee3aefd87f21e9bb8) +- Update js-client to fix rate limit handling [`32590eb`](https://github.com/netlify/cli/commit/32590ebf2aa9788733908afee3aefd87f21e9bb8) ## [v2.6.2](https://github.com/netlify/cli/compare/v2.6.1...v2.6.2) - 2019-01-19 @@ -1255,7 +1255,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). ### Commits -- Fix missing dependencies [`4dd06ad`](https://github.com/netlify/cli/commit/4dd06ad5bf53d62355e2f126bcc641786dba4139) +- Fix missing dependencies [`4dd06ad`](https://github.com/netlify/cli/commit/4dd06ad5bf53d62355e2f126bcc641786dba4139) ## [v2.2.2](https://github.com/netlify/cli/compare/v2.2.1...v2.2.2) - 2018-11-26 @@ -1379,7 +1379,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). ### Commits - add root to this.netlify.site [`9104cf2`](https://github.com/netlify/cli/commit/9104cf2df283e19b4565daeb7f9c7a695a5bc419) -- Use dirname, not base name [`73b594c`](https://github.com/netlify/cli/commit/73b594c1bb8dc024ecca8d1a1c9a42ab0b953317) +- Use dirname, not base name [`73b594c`](https://github.com/netlify/cli/commit/73b594c1bb8dc024ecca8d1a1c9a42ab0b953317) ## [v2.0.0-beta.8](https://github.com/netlify/cli/compare/v2.0.0-beta.7...v2.0.0-beta.8) - 2018-10-09 diff --git a/README.md b/README.md index 46bf1e59b67..7590e23736c 100644 --- a/README.md +++ b/README.md @@ -16,21 +16,21 @@ See the [CLI command line reference](https://cli.netlify.com/commands/) to get s - [Usage](#usage) - [Documentation](#documentation) - [Commands](#commands) - * [addons](#addons) - * [api](#api) - * [build](#build) - * [deploy](#deploy) - * [dev](#dev) - * [functions](#functions) - * [init](#init) - * [link](#link) - * [login](#login) - * [open](#open) - * [sites](#sites) - * [status](#status) - * [switch](#switch) - * [unlink](#unlink) - * [watch](#watch) + - [addons](#addons) + - [api](#api) + - [build](#build) + - [deploy](#deploy) + - [dev](#dev) + - [functions](#functions) + - [init](#init) + - [link](#link) + - [login](#login) + - [open](#open) + - [sites](#sites) + - [status](#status) + - [switch](#switch) + - [unlink](#unlink) + - [watch](#watch) - [Contributing](#contributing) - [Development](#development) - [License](#license) @@ -68,18 +68,18 @@ For a full command reference, see the list below, or visit [cli.netlify.com](htt ## Commands + ### [addons](/docs/commands/addons.md) (Beta) Manage Netlify Add-ons -| Subcommand | description | -|:--------------------------- |:-----| -| [`addons:auth`](/docs/commands/addons.md#addonsauth) | Login to add-on provider | -| [`addons:config`](/docs/commands/addons.md#addonsconfig) | Configure add-on settings | -| [`addons:create`](/docs/commands/addons.md#addonscreate) | Add an add-on extension to your site | -| [`addons:delete`](/docs/commands/addons.md#addonsdelete) | Remove an add-on extension to your site | -| [`addons:list`](/docs/commands/addons.md#addonslist) | List currently installed add-ons for site | - +| Subcommand | description | +| :------------------------------------------------------- | :---------------------------------------- | +| [`addons:auth`](/docs/commands/addons.md#addonsauth) | Login to add-on provider | +| [`addons:config`](/docs/commands/addons.md#addonsconfig) | Configure add-on settings | +| [`addons:create`](/docs/commands/addons.md#addonscreate) | Add an add-on extension to your site | +| [`addons:delete`](/docs/commands/addons.md#addonsdelete) | Remove an add-on extension to your site | +| [`addons:list`](/docs/commands/addons.md#addonslist) | List currently installed add-ons for site | ### [api](/docs/commands/api.md) @@ -97,21 +97,19 @@ Create a new deploy from the contents of a folder Local dev server -| Subcommand | description | -|:--------------------------- |:-----| -| [`dev:exec`](/docs/commands/dev.md#devexec) | Exec command | - +| Subcommand | description | +| :------------------------------------------ | :----------- | +| [`dev:exec`](/docs/commands/dev.md#devexec) | Exec command | ### [functions](/docs/commands/functions.md) Manage netlify functions -| Subcommand | description | -|:--------------------------- |:-----| -| [`functions:build`](/docs/commands/functions.md#functionsbuild) | Build functions locally | -| [`functions:create`](/docs/commands/functions.md#functionscreate) | Create a new function locally | -| [`functions:invoke`](/docs/commands/functions.md#functionsinvoke) | Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions | - +| Subcommand | description | +| :---------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------- | +| [`functions:build`](/docs/commands/functions.md#functionsbuild) | Build functions locally | +| [`functions:create`](/docs/commands/functions.md#functionscreate) | Create a new function locally | +| [`functions:invoke`](/docs/commands/functions.md#functionsinvoke) | Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions | ### [init](/docs/commands/init.md) @@ -129,31 +127,28 @@ Login to your Netlify account Open settings for the site linked to the current folder -| Subcommand | description | -|:--------------------------- |:-----| -| [`open:admin`](/docs/commands/open.md#openadmin) | Opens current site admin UI in Netlify | -| [`open:site`](/docs/commands/open.md#opensite) | Opens current site url in browser | - +| Subcommand | description | +| :----------------------------------------------- | :------------------------------------- | +| [`open:admin`](/docs/commands/open.md#openadmin) | Opens current site admin UI in Netlify | +| [`open:site`](/docs/commands/open.md#opensite) | Opens current site url in browser | ### [sites](/docs/commands/sites.md) Handle various site operations -| Subcommand | description | -|:--------------------------- |:-----| -| [`sites:create`](/docs/commands/sites.md#sitescreate) | Create an empty site (advanced) | -| [`sites:delete`](/docs/commands/sites.md#sitesdelete) | Delete a site | -| [`sites:list`](/docs/commands/sites.md#siteslist) | List all sites you have access to | - +| Subcommand | description | +| :---------------------------------------------------- | :-------------------------------- | +| [`sites:create`](/docs/commands/sites.md#sitescreate) | Create an empty site (advanced) | +| [`sites:delete`](/docs/commands/sites.md#sitesdelete) | Delete a site | +| [`sites:list`](/docs/commands/sites.md#siteslist) | List all sites you have access to | ### [status](/docs/commands/status.md) Print status information -| Subcommand | description | -|:--------------------------- |:-----| -| [`status:hooks`](/docs/commands/status.md#statushooks) | Print hook information of the linked site | - +| Subcommand | description | +| :----------------------------------------------------- | :---------------------------------------- | +| [`status:hooks`](/docs/commands/status.md#statushooks) | Print hook information of the linked site | ### [switch](/docs/commands/switch.md) @@ -167,7 +162,6 @@ Unlink a local folder from a Netlify site Watch for site deploy to finish - ## Contributing diff --git a/docs/README.md b/docs/README.md index 71a1e1c09dc..f55ca1c0c5e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -34,18 +34,18 @@ netlify [command] help ## Commands + ### [addons](/docs/commands/addons.md) (Beta) Manage Netlify Add-ons -| Subcommand | description | -|:--------------------------- |:-----| -| [`addons:auth`](/docs/commands/addons.md#addonsauth) | Login to add-on provider | -| [`addons:config`](/docs/commands/addons.md#addonsconfig) | Configure add-on settings | -| [`addons:create`](/docs/commands/addons.md#addonscreate) | Add an add-on extension to your site | -| [`addons:delete`](/docs/commands/addons.md#addonsdelete) | Remove an add-on extension to your site | -| [`addons:list`](/docs/commands/addons.md#addonslist) | List currently installed add-ons for site | - +| Subcommand | description | +| :------------------------------------------------------- | :---------------------------------------- | +| [`addons:auth`](/docs/commands/addons.md#addonsauth) | Login to add-on provider | +| [`addons:config`](/docs/commands/addons.md#addonsconfig) | Configure add-on settings | +| [`addons:create`](/docs/commands/addons.md#addonscreate) | Add an add-on extension to your site | +| [`addons:delete`](/docs/commands/addons.md#addonsdelete) | Remove an add-on extension to your site | +| [`addons:list`](/docs/commands/addons.md#addonslist) | List currently installed add-ons for site | ### [api](/docs/commands/api.md) @@ -63,21 +63,19 @@ Create a new deploy from the contents of a folder Local dev server -| Subcommand | description | -|:--------------------------- |:-----| -| [`dev:exec`](/docs/commands/dev.md#devexec) | Exec command | - +| Subcommand | description | +| :------------------------------------------ | :----------- | +| [`dev:exec`](/docs/commands/dev.md#devexec) | Exec command | ### [functions](/docs/commands/functions.md) Manage netlify functions -| Subcommand | description | -|:--------------------------- |:-----| -| [`functions:build`](/docs/commands/functions.md#functionsbuild) | Build functions locally | -| [`functions:create`](/docs/commands/functions.md#functionscreate) | Create a new function locally | -| [`functions:invoke`](/docs/commands/functions.md#functionsinvoke) | Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions | - +| Subcommand | description | +| :---------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------- | +| [`functions:build`](/docs/commands/functions.md#functionsbuild) | Build functions locally | +| [`functions:create`](/docs/commands/functions.md#functionscreate) | Create a new function locally | +| [`functions:invoke`](/docs/commands/functions.md#functionsinvoke) | Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions | ### [init](/docs/commands/init.md) @@ -95,31 +93,28 @@ Login to your Netlify account Open settings for the site linked to the current folder -| Subcommand | description | -|:--------------------------- |:-----| -| [`open:admin`](/docs/commands/open.md#openadmin) | Opens current site admin UI in Netlify | -| [`open:site`](/docs/commands/open.md#opensite) | Opens current site url in browser | - +| Subcommand | description | +| :----------------------------------------------- | :------------------------------------- | +| [`open:admin`](/docs/commands/open.md#openadmin) | Opens current site admin UI in Netlify | +| [`open:site`](/docs/commands/open.md#opensite) | Opens current site url in browser | ### [sites](/docs/commands/sites.md) Handle various site operations -| Subcommand | description | -|:--------------------------- |:-----| -| [`sites:create`](/docs/commands/sites.md#sitescreate) | Create an empty site (advanced) | -| [`sites:delete`](/docs/commands/sites.md#sitesdelete) | Delete a site | -| [`sites:list`](/docs/commands/sites.md#siteslist) | List all sites you have access to | - +| Subcommand | description | +| :---------------------------------------------------- | :-------------------------------- | +| [`sites:create`](/docs/commands/sites.md#sitescreate) | Create an empty site (advanced) | +| [`sites:delete`](/docs/commands/sites.md#sitesdelete) | Delete a site | +| [`sites:list`](/docs/commands/sites.md#siteslist) | List all sites you have access to | ### [status](/docs/commands/status.md) Print status information -| Subcommand | description | -|:--------------------------- |:-----| -| [`status:hooks`](/docs/commands/status.md#statushooks) | Print hook information of the linked site | - +| Subcommand | description | +| :----------------------------------------------------- | :---------------------------------------- | +| [`status:hooks`](/docs/commands/status.md#statushooks) | Print hook information of the linked site | ### [switch](/docs/commands/switch.md) @@ -133,5 +128,4 @@ Unlink a local folder from a Netlify site Watch for site deploy to finish - diff --git a/docs/commands/addons.md b/docs/commands/addons.md index 276e6987bb4..01a3668742d 100644 --- a/docs/commands/addons.md +++ b/docs/commands/addons.md @@ -11,6 +11,7 @@ For more information on add-ons see our [Netlify partner add-ons docs](https://w ## About + (Beta) Manage Netlify Add-ons **Usage** @@ -19,14 +20,13 @@ For more information on add-ons see our [Netlify partner add-ons docs](https://w netlify addons ``` -| Subcommand | description | -|:--------------------------- |:-----| -| [`addons:auth`](/docs/commands/addons.md#addonsauth) | Login to add-on provider | -| [`addons:config`](/docs/commands/addons.md#addonsconfig) | Configure add-on settings | -| [`addons:create`](/docs/commands/addons.md#addonscreate) | Add an add-on extension to your site | -| [`addons:delete`](/docs/commands/addons.md#addonsdelete) | Remove an add-on extension to your site | -| [`addons:list`](/docs/commands/addons.md#addonslist) | List currently installed add-ons for site | - +| Subcommand | description | +| :------------------------------------------------------- | :---------------------------------------- | +| [`addons:auth`](/docs/commands/addons.md#addonsauth) | Login to add-on provider | +| [`addons:config`](/docs/commands/addons.md#addonsconfig) | Configure add-on settings | +| [`addons:create`](/docs/commands/addons.md#addonscreate) | Add an add-on extension to your site | +| [`addons:delete`](/docs/commands/addons.md#addonsdelete) | Remove an add-on extension to your site | +| [`addons:list`](/docs/commands/addons.md#addonslist) | List currently installed add-ons for site | **Examples** @@ -39,6 +39,7 @@ netlify addons:auth addon-xyz ``` --- + ## `addons:auth` Login to add-on provider @@ -54,6 +55,7 @@ netlify addons:auth - name - Add-on slug --- + ## `addons:config` Configure add-on settings @@ -69,13 +71,13 @@ netlify addons:config - name - Add-on namespace --- + ## `addons:create` Add an add-on extension to your site ... Add-ons are a way to extend the functionality of your Netlify site - **Usage** ```bash @@ -87,13 +89,13 @@ netlify addons:create - name - Add-on namespace --- + ## `addons:delete` Remove an add-on extension to your site ... Add-ons are a way to extend the functionality of your Netlify site - **Usage** ```bash @@ -106,9 +108,10 @@ netlify addons:delete **Flags** -- `force` (*boolean*) - delete without prompting (useful for CI) +- `force` (_boolean_) - delete without prompting (useful for CI) --- + ## `addons:list` List currently installed add-ons for site @@ -121,7 +124,7 @@ netlify addons:list **Flags** -- `json` (*boolean*) - Output add-on data as JSON +- `json` (_boolean_) - Output add-on data as JSON --- diff --git a/docs/commands/api.md b/docs/commands/api.md index dcd6bcb69b3..740a84e8c45 100644 --- a/docs/commands/api.md +++ b/docs/commands/api.md @@ -7,11 +7,11 @@ title: Netlify CLI api command The `api` command will let you call any [Netlify open API methods](https://open-api.netlify.com/) + Run any Netlify API method For more information on available methods checkout https://open-api.netlify.com/ or run "netlify api --list" - **Usage** ```bash @@ -24,8 +24,8 @@ netlify api **Flags** -- `data` (*option*) - Data to use -- `list` (*boolean*) - List out available API methods +- `data` (_option_) - Data to use +- `list` (_boolean_) - List out available API methods **Examples** @@ -34,5 +34,4 @@ netlify api --list netlify api getSite --data '{ "site_id": "123456"}' ``` - diff --git a/docs/commands/deploy.md b/docs/commands/deploy.md index f97382e74a6..560cbe60074 100644 --- a/docs/commands/deploy.md +++ b/docs/commands/deploy.md @@ -5,6 +5,7 @@ title: Netlify CLI deploy command # `deploy` + Create a new deploy from the contents of a folder Deploys from the build settings found in the netlify.toml file, or settings from the API. @@ -16,9 +17,7 @@ The following environment variables can be used to override configuration file l Lambda functions in the function folder can be in the following configurations for deployment: - -Built Go binaries: ------------------- +## Built Go binaries: ``` functions/ @@ -27,9 +26,7 @@ functions/ Build binaries of your Go language functions into the functions folder as part of your build process. - -Single file Node.js functions: ------------------------------ +## Single file Node.js functions: Build dependency bundled Node.js lambda functions with tools like netlify-lambda, webpack or browserify into the function folder as part of your build process. @@ -38,8 +35,7 @@ functions/ └── nameOfBundledNodeJSFunction.js ``` -Unbundled Node.js functions that have dependencies outside or inside of the functions folder: ---------------------------------------------------------------------------------------------- +## Unbundled Node.js functions that have dependencies outside or inside of the functions folder: You can ship unbundled Node.js functions with the CLI, utilizing top level project dependencies, or a nested package.json. If you use nested dependencies, be sure to populate the nested node_modules as part of your build process before deploying using npm or yarn. @@ -59,9 +55,7 @@ project/ Any mix of these configurations works as well. - -Node.js function entry points ------------------------------ +## Node.js function entry points Function entry points are determined by the file name and name of the folder they are in: @@ -75,7 +69,6 @@ functions/ Support for package.json's main field, and intrinsic index.js entrypoints are coming soon. - **Usage** ```bash @@ -84,16 +77,16 @@ netlify deploy **Flags** -- `dir` (*option*) - Specify a folder to deploy -- `functions` (*option*) - Specify a functions folder to deploy -- `prod` (*boolean*) - Deploy to production -- `open` (*boolean*) - Open site after deploy -- `message` (*option*) - A short message to include in the deploy log -- `auth` (*option*) - Netlify auth token to deploy with -- `site` (*option*) - A site ID to deploy to -- `json` (*boolean*) - Output deployment data as JSON -- `timeout` (*option*) - Timeout to wait for deployment to finish -- `trigger` (*boolean*) - Trigger a new build of your site on Netlify without uploading local files +- `dir` (_option_) - Specify a folder to deploy +- `functions` (_option_) - Specify a functions folder to deploy +- `prod` (_boolean_) - Deploy to production +- `open` (_boolean_) - Open site after deploy +- `message` (_option_) - A short message to include in the deploy log +- `auth` (_option_) - Netlify auth token to deploy with +- `site` (_option_) - A site ID to deploy to +- `json` (_boolean_) - Output deployment data as JSON +- `timeout` (_option_) - Timeout to wait for deployment to finish +- `trigger` (_boolean_) - Trigger a new build of your site on Netlify without uploading local files **Examples** @@ -106,5 +99,4 @@ netlify deploy --auth $NETLIFY_AUTH_TOKEN netlify deploy --trigger ``` - diff --git a/docs/commands/dev.md b/docs/commands/dev.md index f6b73ffea9a..c042ab62d89 100644 --- a/docs/commands/dev.md +++ b/docs/commands/dev.md @@ -6,10 +6,10 @@ description: Run netlify dev locally # `dev` + Local dev server The dev command will run a local dev server with Netlify's proxy and redirect rules - **Usage** ```bash @@ -18,18 +18,17 @@ netlify dev **Flags** -- `command` (*option*) - command to run -- `port` (*option*) - port of netlify dev -- `targetPort` (*option*) - port of target app server -- `dir` (*option*) - dir with static files -- `functions` (*option*) - Specify a functions folder to serve -- `offline` (*boolean*) - disables any features that require network access -- `live` (*boolean*) - Start a public live session - -| Subcommand | description | -|:--------------------------- |:-----| -| [`dev:exec`](/docs/commands/dev.md#devexec) | Exec command | +- `command` (_option_) - command to run +- `port` (_option_) - port of netlify dev +- `targetPort` (_option_) - port of target app server +- `dir` (_option_) - dir with static files +- `functions` (_option_) - Specify a functions folder to serve +- `offline` (_boolean_) - disables any features that require network access +- `live` (_boolean_) - Start a public live session +| Subcommand | description | +| :------------------------------------------ | :----------- | +| [`dev:exec`](/docs/commands/dev.md#devexec) | Exec command | **Examples** @@ -40,12 +39,12 @@ $ netlify dev -c hugo ``` --- + ## `dev:exec` Exec command Runs a command within the netlify dev environment, e.g. with env variables from any installed addons - **Usage** ```bash diff --git a/docs/commands/functions.md b/docs/commands/functions.md index 6aeff33414c..536802f350c 100644 --- a/docs/commands/functions.md +++ b/docs/commands/functions.md @@ -6,22 +6,21 @@ description: Run netlify dev locally # `functions` + Manage netlify functions The `functions` command will help you manage the functions in this site - **Usage** ```bash netlify functions ``` -| Subcommand | description | -|:--------------------------- |:-----| -| [`functions:build`](/docs/commands/functions.md#functionsbuild) | Build functions locally | -| [`functions:create`](/docs/commands/functions.md#functionscreate) | Create a new function locally | -| [`functions:invoke`](/docs/commands/functions.md#functionsinvoke) | Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions | - +| Subcommand | description | +| :---------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------- | +| [`functions:build`](/docs/commands/functions.md#functionsbuild) | Build functions locally | +| [`functions:create`](/docs/commands/functions.md#functionscreate) | Create a new function locally | +| [`functions:invoke`](/docs/commands/functions.md#functionsinvoke) | Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions | **Examples** @@ -31,11 +30,11 @@ netlify functions:build --name function-abc --timeout 30s ``` --- + ## `functions:build` Build functions locally - **Usage** ```bash @@ -44,10 +43,11 @@ netlify functions:build **Flags** -- `functions` (*option*) - Specify a functions folder to build to -- `src` (*option*) - Specify the source folder for the functions +- `functions` (_option_) - Specify a functions folder to build to +- `src` (_option_) - Specify the source folder for the functions --- + ## `functions:create` Create a new function locally @@ -64,8 +64,8 @@ netlify functions:create **Flags** -- `name` (*option*) - function name -- `url` (*option*) - pull template from URL +- `name` (_option_) - function name +- `url` (_option_) - pull template from URL **Examples** @@ -76,6 +76,7 @@ netlify functions:create --name hello-world ``` --- + ## `functions:invoke` Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions @@ -92,11 +93,11 @@ netlify functions:invoke **Flags** -- `name` (*option*) - function name to invoke -- `functions` (*option*) - Specify a functions folder to parse, overriding netlify.toml -- `querystring` (*option*) - Querystring to add to your function invocation -- `payload` (*option*) - Supply POST payload in stringified json, or a path to a json file -- `identity` (*boolean*) - simulate Netlify Identity authentication JWT. pass --no-identity to affirm unauthenticated request +- `name` (_option_) - function name to invoke +- `functions` (_option_) - Specify a functions folder to parse, overriding netlify.toml +- `querystring` (_option_) - Querystring to add to your function invocation +- `payload` (_option_) - Supply POST payload in stringified json, or a path to a json file +- `identity` (_boolean_) - simulate Netlify Identity authentication JWT. pass --no-identity to affirm unauthenticated request **Examples** diff --git a/docs/commands/index.md b/docs/commands/index.md index 363c25f9bed..c4630c65298 100644 --- a/docs/commands/index.md +++ b/docs/commands/index.md @@ -20,18 +20,18 @@ netlify [command] help ## Commands + ### [addons](/docs/commands/addons.md) (Beta) Manage Netlify Add-ons -| Subcommand | description | -|:--------------------------- |:-----| -| [`addons:auth`](/docs/commands/addons.md#addonsauth) | Login to add-on provider | -| [`addons:config`](/docs/commands/addons.md#addonsconfig) | Configure add-on settings | -| [`addons:create`](/docs/commands/addons.md#addonscreate) | Add an add-on extension to your site | -| [`addons:delete`](/docs/commands/addons.md#addonsdelete) | Remove an add-on extension to your site | -| [`addons:list`](/docs/commands/addons.md#addonslist) | List currently installed add-ons for site | - +| Subcommand | description | +| :------------------------------------------------------- | :---------------------------------------- | +| [`addons:auth`](/docs/commands/addons.md#addonsauth) | Login to add-on provider | +| [`addons:config`](/docs/commands/addons.md#addonsconfig) | Configure add-on settings | +| [`addons:create`](/docs/commands/addons.md#addonscreate) | Add an add-on extension to your site | +| [`addons:delete`](/docs/commands/addons.md#addonsdelete) | Remove an add-on extension to your site | +| [`addons:list`](/docs/commands/addons.md#addonslist) | List currently installed add-ons for site | ### [api](/docs/commands/api.md) @@ -49,21 +49,19 @@ Create a new deploy from the contents of a folder Local dev server -| Subcommand | description | -|:--------------------------- |:-----| -| [`dev:exec`](/docs/commands/dev.md#devexec) | Exec command | - +| Subcommand | description | +| :------------------------------------------ | :----------- | +| [`dev:exec`](/docs/commands/dev.md#devexec) | Exec command | ### [functions](/docs/commands/functions.md) Manage netlify functions -| Subcommand | description | -|:--------------------------- |:-----| -| [`functions:build`](/docs/commands/functions.md#functionsbuild) | Build functions locally | -| [`functions:create`](/docs/commands/functions.md#functionscreate) | Create a new function locally | -| [`functions:invoke`](/docs/commands/functions.md#functionsinvoke) | Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions | - +| Subcommand | description | +| :---------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------- | +| [`functions:build`](/docs/commands/functions.md#functionsbuild) | Build functions locally | +| [`functions:create`](/docs/commands/functions.md#functionscreate) | Create a new function locally | +| [`functions:invoke`](/docs/commands/functions.md#functionsinvoke) | Trigger a function while in netlify dev with simulated data, good for testing function calls including Netlify's Event Triggered Functions | ### [init](/docs/commands/init.md) @@ -81,31 +79,28 @@ Login to your Netlify account Open settings for the site linked to the current folder -| Subcommand | description | -|:--------------------------- |:-----| -| [`open:admin`](/docs/commands/open.md#openadmin) | Opens current site admin UI in Netlify | -| [`open:site`](/docs/commands/open.md#opensite) | Opens current site url in browser | - +| Subcommand | description | +| :----------------------------------------------- | :------------------------------------- | +| [`open:admin`](/docs/commands/open.md#openadmin) | Opens current site admin UI in Netlify | +| [`open:site`](/docs/commands/open.md#opensite) | Opens current site url in browser | ### [sites](/docs/commands/sites.md) Handle various site operations -| Subcommand | description | -|:--------------------------- |:-----| -| [`sites:create`](/docs/commands/sites.md#sitescreate) | Create an empty site (advanced) | -| [`sites:delete`](/docs/commands/sites.md#sitesdelete) | Delete a site | -| [`sites:list`](/docs/commands/sites.md#siteslist) | List all sites you have access to | - +| Subcommand | description | +| :---------------------------------------------------- | :-------------------------------- | +| [`sites:create`](/docs/commands/sites.md#sitescreate) | Create an empty site (advanced) | +| [`sites:delete`](/docs/commands/sites.md#sitesdelete) | Delete a site | +| [`sites:list`](/docs/commands/sites.md#siteslist) | List all sites you have access to | ### [status](/docs/commands/status.md) Print status information -| Subcommand | description | -|:--------------------------- |:-----| -| [`status:hooks`](/docs/commands/status.md#statushooks) | Print hook information of the linked site | - +| Subcommand | description | +| :----------------------------------------------------- | :---------------------------------------- | +| [`status:hooks`](/docs/commands/status.md#statushooks) | Print hook information of the linked site | ### [switch](/docs/commands/switch.md) @@ -119,5 +114,4 @@ Unlink a local folder from a Netlify site Watch for site deploy to finish - diff --git a/docs/commands/init.md b/docs/commands/init.md index 583fff8e3c9..7f9b833f8c8 100644 --- a/docs/commands/init.md +++ b/docs/commands/init.md @@ -6,6 +6,7 @@ description: Initialize a new site locally # `init` + Configure continuous deployment for a new or existing site **Usage** @@ -16,10 +17,9 @@ netlify init **Flags** -- `manual` (*boolean*) - Manually configure a git remote for CI -- `watch` (*boolean*) - Make the CLI wait for the first deploy to complete after setting up CI -- `force` (*boolean*) - Reinitialize CI hooks if the linked site is already configured to use CI -- `gitRemoteName` (*option*) - Name of Git remote to use. e.g. "origin" - +- `manual` (_boolean_) - Manually configure a git remote for CI +- `watch` (_boolean_) - Make the CLI wait for the first deploy to complete after setting up CI +- `force` (_boolean_) - Reinitialize CI hooks if the linked site is already configured to use CI +- `gitRemoteName` (_option_) - Name of Git remote to use. e.g. "origin" diff --git a/docs/commands/link.md b/docs/commands/link.md index 6d624386842..66ed48b605e 100644 --- a/docs/commands/link.md +++ b/docs/commands/link.md @@ -6,6 +6,7 @@ description: Link an existing site to a local site directory # `link` + Link a local repo or project folder to an existing site on Netlify **Usage** @@ -16,9 +17,9 @@ netlify link **Flags** -- `id` (*option*) - ID of site to link to -- `name` (*option*) - Name of site to link to -- `gitRemoteName` (*option*) - Name of Git remote to use. e.g. "origin" +- `id` (_option_) - ID of site to link to +- `name` (_option_) - Name of site to link to +- `gitRemoteName` (_option_) - Name of Git remote to use. e.g. "origin" **Examples** @@ -28,5 +29,4 @@ netlify link --id 123-123-123-123 netlify link --name my-site-name ``` - diff --git a/docs/commands/login.md b/docs/commands/login.md index e1e37a8cd0b..93b7922c058 100644 --- a/docs/commands/login.md +++ b/docs/commands/login.md @@ -6,11 +6,11 @@ description: Login to your Netlify account # `login` + Login to your Netlify account Opens a web browser to acquire an OAuth token. - **Usage** ```bash @@ -19,7 +19,6 @@ netlify login **Flags** -- `new` (*boolean*) - Login to new Netlify account - +- `new` (_boolean_) - Login to new Netlify account diff --git a/docs/commands/logout.md b/docs/commands/logout.md index 582f650b4d3..a8e2eecbd5d 100644 --- a/docs/commands/logout.md +++ b/docs/commands/logout.md @@ -7,6 +7,7 @@ hidden: true # `logout` + Logout of your Netlify account **Usage** @@ -14,4 +15,5 @@ Logout of your Netlify account ```bash netlify logout ``` + diff --git a/docs/commands/open.md b/docs/commands/open.md index 0217326801f..e0e2f7cb763 100644 --- a/docs/commands/open.md +++ b/docs/commands/open.md @@ -5,6 +5,7 @@ title: Netlify CLI open command # `open` + Open settings for the site linked to the current folder **Usage** @@ -15,14 +16,13 @@ netlify open **Flags** -- `site` (*boolean*) - Open site -- `admin` (*boolean*) - Open Netlify site - -| Subcommand | description | -|:--------------------------- |:-----| -| [`open:admin`](/docs/commands/open.md#openadmin) | Opens current site admin UI in Netlify | -| [`open:site`](/docs/commands/open.md#opensite) | Opens current site url in browser | +- `site` (_boolean_) - Open site +- `admin` (_boolean_) - Open Netlify site +| Subcommand | description | +| :----------------------------------------------- | :------------------------------------- | +| [`open:admin`](/docs/commands/open.md#openadmin) | Opens current site admin UI in Netlify | +| [`open:site`](/docs/commands/open.md#opensite) | Opens current site url in browser | **Examples** @@ -34,6 +34,7 @@ netlify open:site ``` --- + ## `open:admin` Opens current site admin UI in Netlify @@ -51,6 +52,7 @@ netlify open:admin ``` --- + ## `open:site` Opens current site url in browser diff --git a/docs/commands/sites.md b/docs/commands/sites.md index c855e7ce635..0c7dde6e023 100644 --- a/docs/commands/sites.md +++ b/docs/commands/sites.md @@ -6,22 +6,21 @@ description: Manage Netlify sites via the command line # `sites` + Handle various site operations The sites command will help you manage all your sites - **Usage** ```bash netlify sites ``` -| Subcommand | description | -|:--------------------------- |:-----| -| [`sites:create`](/docs/commands/sites.md#sitescreate) | Create an empty site (advanced) | -| [`sites:delete`](/docs/commands/sites.md#sitesdelete) | Delete a site | -| [`sites:list`](/docs/commands/sites.md#siteslist) | List all sites you have access to | - +| Subcommand | description | +| :---------------------------------------------------- | :-------------------------------- | +| [`sites:create`](/docs/commands/sites.md#sitescreate) | Create an empty site (advanced) | +| [`sites:delete`](/docs/commands/sites.md#sitesdelete) | Delete a site | +| [`sites:list`](/docs/commands/sites.md#siteslist) | List all sites you have access to | **Examples** @@ -31,12 +30,12 @@ netlify sites:list ``` --- + ## `sites:create` Create an empty site (advanced) -Create a blank site that isn't associated with any git remote. Does not link to the current working directory. - +Create a blank site that isn't associated with any git remote. Does not link to the current working directory. **Usage** @@ -46,19 +45,19 @@ netlify sites:create **Flags** -- `name` (*option*) - name of site -- `account-slug` (*option*) - account slug to create the site under -- `with-ci` (*boolean*) - initialize CI hooks during site creation -- `manual` (*boolean*) - Force manual CI setup. Used --with-ci flag +- `name` (_option_) - name of site +- `account-slug` (_option_) - account slug to create the site under +- `with-ci` (_boolean_) - initialize CI hooks during site creation +- `manual` (_boolean_) - Force manual CI setup. Used --with-ci flag --- + ## `sites:delete` Delete a site This command will permanently delete the site on Netlify. Use with caution. - **Usage** ```bash @@ -71,7 +70,7 @@ netlify sites:delete {site-id} **Flags** -- `force` (*boolean*) - delete without prompting (useful for CI) +- `force` (_boolean_) - delete without prompting (useful for CI) **Examples** @@ -80,6 +79,7 @@ netlify site:delete 1234-3262-1211 ``` --- + ## `sites:list` List all sites you have access to @@ -92,7 +92,7 @@ netlify sites:list **Flags** -- `json` (*boolean*) - Output site data as JSON +- `json` (_boolean_) - Output site data as JSON --- diff --git a/docs/commands/status.md b/docs/commands/status.md index e3aa724fcd9..6c6a6144f0f 100644 --- a/docs/commands/status.md +++ b/docs/commands/status.md @@ -6,6 +6,7 @@ description: Get the current context of the netlify CLI # `status` + Print status information **Usage** @@ -16,14 +17,14 @@ netlify status **Flags** -- `verbose` (*boolean*) - Output system info - -| Subcommand | description | -|:--------------------------- |:-----| -| [`status:hooks`](/docs/commands/status.md#statushooks) | Print hook information of the linked site | +- `verbose` (_boolean_) - Output system info +| Subcommand | description | +| :----------------------------------------------------- | :---------------------------------------- | +| [`status:hooks`](/docs/commands/status.md#statushooks) | Print hook information of the linked site | --- + ## `status:hooks` Print hook information of the linked site diff --git a/docs/commands/unlink.md b/docs/commands/unlink.md index ee7a2818907..0777512686c 100644 --- a/docs/commands/unlink.md +++ b/docs/commands/unlink.md @@ -6,6 +6,7 @@ description: Link an existing site to a local site directory # `unlink` + Unlink a local folder from a Netlify site **Usage** @@ -14,5 +15,4 @@ Unlink a local folder from a Netlify site netlify unlink ``` - diff --git a/docs/commands/watch.md b/docs/commands/watch.md index 2a6bbaa544b..014dedb4c4e 100644 --- a/docs/commands/watch.md +++ b/docs/commands/watch.md @@ -6,6 +6,7 @@ hidden: true # `watch` + Watch for site deploy to finish **Usage** @@ -21,5 +22,4 @@ netlify watch git push && netlify watch ``` - diff --git a/docs/netlify-dev.md b/docs/netlify-dev.md index 1b5c73f96c1..2097038d687 100644 --- a/docs/netlify-dev.md +++ b/docs/netlify-dev.md @@ -134,15 +134,16 @@ Netlify Dev will attempt to detect the SSG or build command that you are using, publish = "dist" # If you use a _redirect file, provide the path to your static content folder ``` - Or you 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. +against your project. + ```toml [dev] framework = "create-react-app" # or "#static" to force a static server -``` - The `framework` option should be one of the available +``` + +The `framework` option should be one of the available [project types which Netlify Dev can detect](https://github.com/netlify/cli/tree/master/src/detectors) or `#auto` (default) to test all available detectors or `#staic` for a static file server. @@ -168,9 +169,10 @@ As for which port to use while doing local development in Netlify Dev, always lo **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.): -* `port`: The port for the main Netlify Dev server, the one you'll open in browser. -* `targetPort`: The port for your application server or site generator. -* `functionsPort`: The port for Netlify Functions server. This server is accessed internally within Netlify Dev, you shouldn't need to access it directly. And thus shouldn't need to change this port. You can access your functions at Netlify Dev main server port like so: `http://localhost:/.netlify/functions/`. + +- `port`: The port for the main Netlify Dev server, the one you'll open in browser. +- `targetPort`: The port for your application server or site generator. +- `functionsPort`: The port for Netlify Functions server. This server is accessed internally within Netlify Dev, you shouldn't need to access it directly. And thus shouldn't need to change this port. You can access your functions at Netlify Dev main server port like so: `http://localhost:/.netlify/functions/`. Netlify Dev tries to acquire these ports but if any of them is not available (already in use by another application), it assigns a random port instead of that. diff --git a/renovate.json b/renovate.json index f39f8c97ac2..a2b42ee3bc4 100644 --- a/renovate.json +++ b/renovate.json @@ -1,3 +1,3 @@ { "extends": ["github>netlify/renovate-config"] -} \ No newline at end of file +} diff --git a/site/sync.js b/site/sync.js index c05739dcc54..f4ce8781144 100644 --- a/site/sync.js +++ b/site/sync.js @@ -11,11 +11,7 @@ const deleteFile = promisify(fs.unlink) async function readDir(dir, allFiles = []) { const files = (await readdirP(dir)).map(f => path.join(dir, f)) allFiles.push(...files) - await Promise.all( - files.map( - async f => (await statP(f)).isDirectory() && readDir(f, allFiles) - ) - ) + await Promise.all(files.map(async f => (await statP(f)).isDirectory() && readDir(f, allFiles))) return allFiles } @@ -27,11 +23,13 @@ async function syncLocalContent() { console.log(`Docs synced to ${destination}`) const files = await readDir(destination) - const mdFiles = files.filter((file) => { - return file.endsWith('.md') - }).map((path) => { - return removeMarkDownLinks(path) - }) + const mdFiles = files + .filter(file => { + return file.endsWith('.md') + }) + .map(path => { + return removeMarkDownLinks(path) + }) await Promise.all(mdFiles) } diff --git a/src/commands/deploy.js b/src/commands/deploy.js index 616e661900f..112833531df 100644 --- a/src/commands/deploy.js +++ b/src/commands/deploy.js @@ -68,7 +68,7 @@ class DeployCommand extends Command { } catch (e) { // TODO specifically handle known cases (e.g. no account access) if (e.status === 404) { - this.error("Site not found") + this.error('Site not found') } else { this.error(e.message) } @@ -78,7 +78,9 @@ class DeployCommand extends Command { if (flags.trigger) { try { const siteBuild = await api.createSiteBuild({ siteId: siteId }) - this.log(`${NETLIFYDEV} A new deployment was triggered successfully. Visit https://app.netlify.com/sites/${siteData.name}/deploys/${siteBuild.deploy_id} to see the logs.`) + this.log( + `${NETLIFYDEV} A new deployment was triggered successfully. Visit https://app.netlify.com/sites/${siteData.name}/deploys/${siteBuild.deploy_id} to see the logs.` + ) return } catch (err) { if (err.status === 404) { diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index 6d3cb58e0fe..e4caca8ff7d 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -23,12 +23,7 @@ const chalk = require('chalk') const jwtDecode = require('jwt-decode') const open = require('open') const dotenv = require('dotenv') -const { - NETLIFYDEV, - NETLIFYDEVLOG, - NETLIFYDEVWARN, - NETLIFYDEVERR -} = require('../../utils/logo') +const { NETLIFYDEV, NETLIFYDEVLOG, NETLIFYDEVWARN, NETLIFYDEVERR } = require('../../utils/logo') const boxen = require('boxen') const { createTunnel, connectTunnel } = require('../../utils/live-tunnel') const createRewriter = require('../../utils/rules-proxy') @@ -57,7 +52,7 @@ async function isStatic(pathname, publicFolder) { try { const pathStats = await stat(p) if (pathStats.isFile()) return true - } catch(err) { + } catch (err) { // Ignore } } @@ -69,7 +64,7 @@ function isExternal(match) { } function isRedirect(match) { - return match.status && (match.status >= 300 && match.status <= 400) + return match.status && match.status >= 300 && match.status <= 400 } function render404(publicFolder) { @@ -110,14 +105,14 @@ function initializeProxy(port, distDir, projectDir) { } }) - const headersFiles = Array.from(new Set([ - path.resolve(projectDir, '_headers'), - path.resolve(distDir, '_headers'), - ])) + const headersFiles = Array.from(new Set([path.resolve(projectDir, '_headers'), path.resolve(distDir, '_headers')])) let headerRules = headersFiles.reduce((prev, curr) => Object.assign(prev, parseHeadersFile(curr)), {}) onChanges(headersFiles, () => { - console.log(`${NETLIFYDEVLOG} Reloading headers files`, headersFiles.filter(fs.existsSync).map(p => path.relative(projectDir, p))) + console.log( + `${NETLIFYDEVLOG} Reloading headers files`, + headersFiles.filter(fs.existsSync).map(p => path.relative(projectDir, p)) + ) headerRules = headersFiles.reduce((prev, curr) => Object.assign(prev, parseHeadersFile(curr)), {}) }) @@ -163,7 +158,7 @@ function initializeProxy(port, distDir, projectDir) { async function startProxy(settings, addonUrls, configPath, projectDir, functionsDir) { try { await waitPort({ port: settings.proxyPort }) - } catch(err) { + } catch (err) { console.error(NETLIFYDEVERR, `Netlify Dev doesn't know what port your site is running on.`) console.error(NETLIFYDEVERR, `Please set --targetPort.`) this.exit(1) @@ -180,7 +175,7 @@ async function startProxy(settings, addonUrls, configPath, projectDir, functions distDir: settings.dist, jwtRole: settings.jwtRolePath, configPath, - projectDir, + projectDir }) const server = http.createServer(function(req, res) { @@ -201,7 +196,7 @@ async function startProxy(settings, addonUrls, configPath, projectDir, functions functionsServer, functionsPort: settings.functionsPort, jwtRolePath: settings.jwtRolePath, - framework: settings.framework, + framework: settings.framework } if (match) return serveRedirect(req, res, proxy, match, options) @@ -287,7 +282,10 @@ async function serveRedirect(req, res, proxy, match, options) { return render404(options.publicFolder) } - if (match.force || ((!(await isStatic(reqUrl.pathname, options.publicFolder)) || options.framework) && match.status !== 404)) { + if ( + match.force || + ((!(await isStatic(reqUrl.pathname, options.publicFolder)) || options.framework) && match.status !== 404) + ) { const dest = new url.URL(match.to, `${reqUrl.protocol}//${reqUrl.host}`) if (isRedirect(match)) { res.writeHead(match.status, { @@ -328,7 +326,7 @@ async function serveRedirect(req, res, proxy, match, options) { return proxy.web(req, res, { target: urlForAddons }) } - return proxy.web(req, res, { ...options, status, }) + return proxy.web(req, res, { ...options, status }) } return proxy.web(req, res, options) @@ -356,13 +354,15 @@ async function startDevServer(settings, log) { log(`${NETLIFYDEVLOG} Starting Netlify Dev with ${settings.framework || 'custom config'}`) const commandBin = await which(settings.command).catch(err => { if (err.code === 'ENOENT') { - throw new Error(`"${settings.command}" could not be found in your PATH. Please make sure that "${settings.command}" is installed and available in your PATH`) + throw new Error( + `"${settings.command}" could not be found in your PATH. Please make sure that "${settings.command}" is installed and available in your PATH` + ) } throw err }) const ps = child_process.spawn(commandBin, settings.args, { env: { ...settings.env, FORCE_COLOR: 'true' }, - stdio: 'pipe', + stdio: 'pipe' }) ps.stdout.pipe(stripAnsiCc()).pipe(process.stdout) @@ -371,16 +371,18 @@ async function startDevServer(settings, log) { process.stdin.pipe(process.stdin) ps.on('close', code => process.exit(code)) ps.on('SIGINT', process.exit) - ps.on('SIGTERM', process.exit); + ps.on('SIGTERM', process.exit) - ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP', 'exit'].forEach(signal => process.on(signal, () => { + ;['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP', 'exit'].forEach(signal => + process.on(signal, () => { try { process.kill(-ps.pid) } catch (err) { // Ignore } process.exit() - })) + }) + ) return ps } @@ -392,7 +394,12 @@ class DevCommand extends Command { const { api, site, config } = this.netlify config.dev = { ...config.dev } config.build = { ...config.build } - const devConfig = { framework: '#auto', ...(config.build.functions && { functions: config.build.functions }), ...config.dev, ...flags } + const devConfig = { + framework: '#auto', + ...(config.build.functions && { functions: config.build.functions }), + ...config.dev, + ...flags + } let addonUrls = {} let accessToken = api.accessToken @@ -406,8 +413,11 @@ class DevCommand extends Command { const envFile = path.resolve(site.root, '.env') if (fs.existsSync(envFile)) { const vars = dotenv.parse(fs.readFileSync(envFile)) || {} - console.log(`${NETLIFYDEVLOG} Overriding the following env variables with ${chalk.blue('.env')} file:`, chalk.yellow(Object.keys(vars))) - Object.entries(vars).forEach(([key, val]) => process.env[key] = val) + console.log( + `${NETLIFYDEVLOG} Overriding the following env variables with ${chalk.blue('.env')} file:`, + chalk.yellow(Object.keys(vars)) + ) + Object.entries(vars).forEach(([key, val]) => (process.env[key] = val)) } let settings = await serverSettings(devConfig, flags, this.log) @@ -528,7 +538,7 @@ DevCommand.flags = { live: flags.boolean({ char: 'l', description: 'Start a public live session' - }), + }) } module.exports = DevCommand diff --git a/src/commands/init.js b/src/commands/init.js index d1b11662c75..0be326c413a 100644 --- a/src/commands/init.js +++ b/src/commands/init.js @@ -263,7 +263,7 @@ InitCommand.flags = { }), gitRemoteName: flags.string({ description: 'Name of Git remote to use. e.g. "origin"' - }), + }) } module.exports = InitCommand diff --git a/src/commands/link.js b/src/commands/link.js index c85ed2f8d38..45eafe2b3d6 100644 --- a/src/commands/link.js +++ b/src/commands/link.js @@ -121,7 +121,7 @@ LinkCommand.flags = { }), gitRemoteName: flags.string({ description: 'Name of Git remote to use. e.g. "origin"' - }), + }) } module.exports = LinkCommand diff --git a/src/commands/sites/delete.js b/src/commands/sites/delete.js index 9514f9d69b5..56996bb0fc1 100644 --- a/src/commands/sites/delete.js +++ b/src/commands/sites/delete.js @@ -59,7 +59,7 @@ class SitesDeleteCommand extends Command { } /* Validation logic if siteId passed in does not match current site ID */ - if (noForce && (cwdSiteId && cwdSiteId !== siteId)) { + if (noForce && cwdSiteId && cwdSiteId !== siteId) { this.log(`${chalk.redBright('Warning')}: The siteId supplied does not match the current working directory siteId`) this.log() this.log(`Supplied: "${siteId}"`) diff --git a/src/detectors/eleventy.js b/src/detectors/eleventy.js index 40c0ce9a5e3..36429e47bff 100644 --- a/src/detectors/eleventy.js +++ b/src/detectors/eleventy.js @@ -1,14 +1,12 @@ -const { - hasRequiredDeps, - hasRequiredFiles -} = require('./utils/jsdetect') +const { hasRequiredDeps, hasRequiredFiles } = require('./utils/jsdetect') module.exports = function() { // REQUIRED FILES if ( !hasRequiredFiles(['package.json', '.eleventy.js']) && - !(hasRequiredFiles(['package.json']) && hasRequiredDeps(["@11ty/eleventy"])) - ) return false + !(hasRequiredFiles(['package.json']) && hasRequiredDeps(['@11ty/eleventy'])) + ) + return false return { framework: 'eleventy', diff --git a/src/function-builder-detectors/netlify-lambda.js b/src/function-builder-detectors/netlify-lambda.js index 81914d9754b..284297b8608 100644 --- a/src/function-builder-detectors/netlify-lambda.js +++ b/src/function-builder-detectors/netlify-lambda.js @@ -32,7 +32,8 @@ module.exports = function() { } if (settings.npmScript) { - settings.build = () => execa(yarnExists ? 'yarn' : 'npm', ['run', settings.npmScript], { env: { ...process.env, ...envConfig } }) + settings.build = () => + execa(yarnExists ? 'yarn' : 'npm', ['run', settings.npmScript], { env: { ...process.env, ...envConfig } }) settings.builderName = 'netlify-lambda' return settings } diff --git a/src/hooks/init.js b/src/hooks/init.js index 3782f354d16..9f9465c1356 100644 --- a/src/hooks/init.js +++ b/src/hooks/init.js @@ -21,8 +21,11 @@ module.exports = async context => { process.exit() // eslint-disable-line } - if (process.argv.length > 3 && - ['-v', '--version', 'version'].includes(process.argv[2]) && process.argv[3] === '--verbose') { + if ( + process.argv.length > 3 && + ['-v', '--version', 'version'].includes(process.argv[2]) && + process.argv[3] === '--verbose' + ) { console.log(`────────────────────┐ Environment Info │ ────────────────────┘`) diff --git a/src/tests/addons.test.js b/src/tests/addons.test.js index 6393624e2e7..f6e7a2794f0 100644 --- a/src/tests/addons.test.js +++ b/src/tests/addons.test.js @@ -9,7 +9,7 @@ const execOptions = { cwd: sitePath, env: { ...process.env }, windowsHide: true, - windowsVerbatimArguments: true, + windowsVerbatimArguments: true } const siteName = diff --git a/src/tests/dev.test.js b/src/tests/dev.test.js index 2c046d66964..75aacda9d9a 100644 --- a/src/tests/dev.test.js +++ b/src/tests/dev.test.js @@ -10,14 +10,13 @@ let ps, host, port test.before(async t => { console.log('Running Netlify Dev server') ps = await spawn(cliPath, ['dev'], { - cwd: sitePath, - env: { ...process.env, DUMMY_VAR: "true" }, - stdio: 'pipe', - shell: true, - } - ) + cwd: sitePath, + env: { ...process.env, DUMMY_VAR: 'true' }, + stdio: 'pipe', + shell: true + }) return new Promise((resolve, reject) => { - ps.stdout.on('data', (data) => { + ps.stdout.on('data', data => { data = data.toString() if (data.includes('Server now ready on')) { const matches = data.match(/http:\/\/(.+):(\d+)/) @@ -45,7 +44,6 @@ test('netlify dev env file', async t => { t.is(response, 'true') }) - test('netlify dev env file overriding prod var', async t => { const response = await fetch(`http://${host}:${port}/.netlify/functions/override-process-env`).then(r => r.text()) diff --git a/src/tests/dummy-site/functions/env/env.js b/src/tests/dummy-site/functions/env/env.js index 1a3587be738..eb88db3327f 100644 --- a/src/tests/dummy-site/functions/env/env.js +++ b/src/tests/dummy-site/functions/env/env.js @@ -1,6 +1,6 @@ exports.handler = async (event, context) => { - return { - statusCode: 200, - body: `${process.env.EASY_VAR}`, - } + return { + statusCode: 200, + body: `${process.env.EASY_VAR}` + } } diff --git a/src/tests/dummy-site/functions/override-process-env/override-process-env.js b/src/tests/dummy-site/functions/override-process-env/override-process-env.js index bb031bbc6bd..0524bcf512d 100644 --- a/src/tests/dummy-site/functions/override-process-env/override-process-env.js +++ b/src/tests/dummy-site/functions/override-process-env/override-process-env.js @@ -1,6 +1,6 @@ exports.handler = async (event, context) => { - return { - statusCode: 200, - body: `${process.env.DUMMY_VAR}`, - } + return { + statusCode: 200, + body: `${process.env.DUMMY_VAR}` + } } diff --git a/src/tests/dummy-site/functions/timeout.js b/src/tests/dummy-site/functions/timeout.js index a6b11512e8a..c22cd53eec9 100644 --- a/src/tests/dummy-site/functions/timeout.js +++ b/src/tests/dummy-site/functions/timeout.js @@ -4,7 +4,6 @@ exports.handler = async (event, context) => { await new Promise((resolve, reject) => setTimeout(resolve, 4000)) return { statusCode: 200, - body: JSON.stringify('ping'), - }; -}; - + body: JSON.stringify('ping') + } +} diff --git a/src/tests/utils/exec.js b/src/tests/utils/exec.js index 0d244909010..0e57d6e0f6b 100644 --- a/src/tests/utils/exec.js +++ b/src/tests/utils/exec.js @@ -1,5 +1,5 @@ const { promisify } = require('util') -const { execFile : execSyncOriginal } = require('child_process') +const { execFile: execSyncOriginal } = require('child_process') const execFile = promisify(execSyncOriginal) diff --git a/src/utils/detect-server.js b/src/utils/detect-server.js index 37bba2771fb..2b26caeef41 100644 --- a/src/utils/detect-server.js +++ b/src/utils/detect-server.js @@ -8,9 +8,7 @@ const fs = require('fs') module.exports.serverSettings = async (devConfig, flags, log) => { let settings = { env: { ...process.env } } - const detectorsFiles = fs - .readdirSync(path.join(__dirname, '..', 'detectors')) - .filter(x => x.endsWith('.js')) // only accept .js detector files + const detectorsFiles = fs.readdirSync(path.join(__dirname, '..', 'detectors')).filter(x => x.endsWith('.js')) // only accept .js detector files if (typeof devConfig.framework !== 'string') throw new Error('Invalid "framework" option provided in config') @@ -50,7 +48,9 @@ module.exports.serverSettings = async (devConfig, flags, log) => { }) settings = chosenSetting // finally! we have a selected option - console.log(`Add \`framework = "${chosenSetting.framework}"\` to [dev] section of your netlify.toml to avoid this selection prompt next time`) + console.log( + `Add \`framework = "${chosenSetting.framework}"\` to [dev] section of your netlify.toml to avoid this selection prompt next time` + ) } } else if (devConfig.framework === '#static') { settings.framework = devConfig.framework @@ -60,7 +60,10 @@ module.exports.serverSettings = async (devConfig, flags, log) => { const detector = loadDetector(detectorName) const detectorResult = detector() - if (!detectorResult) throw new Error(`Specified "framework" detector "${devConfig.framework}" did not pass requirements for your project`) + if (!detectorResult) + throw new Error( + `Specified "framework" detector "${devConfig.framework}" did not pass requirements for your project` + ) settings.args = chooseDefaultArgs(detectorResult.possibleArgsArrs) } @@ -84,12 +87,8 @@ module.exports.serverSettings = async (devConfig, flags, log) => { if (!dist) { log(`${NETLIFYDEVLOG} Using current working directory`) log(`${NETLIFYDEVWARN} Unable to determine public folder to serve files from.`) - log( - `${NETLIFYDEVWARN} Setup a netlify.toml file with a [dev] section to specify your dev server settings.` - ) - log( - `${NETLIFYDEVWARN} See docs at: https://cli.netlify.com/netlify-dev#project-detection` - ) + log(`${NETLIFYDEVWARN} Setup a netlify.toml file with a [dev] section to specify your dev server settings.`) + log(`${NETLIFYDEVWARN} See docs at: https://cli.netlify.com/netlify-dev#project-detection`) log(`${NETLIFYDEVWARN} Using current working directory for now...`) dist = process.cwd() } @@ -98,19 +97,23 @@ module.exports.serverSettings = async (devConfig, flags, log) => { port: 8888, proxyPort: await getPort({ port: 3999 }), dist, - ...(settings.command ? { command: settings.command, args: settings.args } : { noCmd: true }), + ...(settings.command ? { command: settings.command, args: settings.args } : { noCmd: true }) } } settings.port = devConfig.port || settings.port if (devConfig.targetPort) { if (devConfig.targetPort === devConfig.port) { - throw new Error('"port" and "targetPort" options cannot have same values. Please consult the documentation for more details: https://cli.netlify.com/netlify-dev#netlifytoml-dev-block') + throw new Error( + '"port" and "targetPort" options cannot have same values. Please consult the documentation for more details: https://cli.netlify.com/netlify-dev#netlifytoml-dev-block' + ) } settings.proxyPort = devConfig.targetPort settings.urlRegexp = devConfig.urlRegexp || new RegExp(`(http://)([^:]+:)${devConfig.targetPort}(/)?`, 'g') } else if (devConfig.port && devConfig.port === settings.proxyPort) { - throw new Error('The "port" option you specified conflicts with the port of your application. Please use a different value for "port"') + throw new Error( + 'The "port" option you specified conflicts with the port of your application. Please use a different value for "port"' + ) } const port = await getPort({ port: settings.port }) @@ -127,17 +130,21 @@ module.exports.serverSettings = async (devConfig, flags, log) => { } const tellUser = settingsField => dV => - // eslint-disable-next-line no-console - console.log( - `${NETLIFYDEVLOG} Overriding ${chalk.yellow(settingsField)} with setting derived from netlify.toml [dev] block: `, - dV - ) + // eslint-disable-next-line no-console + console.log( + `${NETLIFYDEVLOG} Overriding ${chalk.yellow(settingsField)} with setting derived from netlify.toml [dev] block: `, + dV + ) function loadDetector(detectorName) { try { return require(path.join(__dirname, '..', 'detectors', detectorName)) } catch (err) { - throw new Error(`Failed to load detector: ${chalk.yellow(detectorName)}, this is likely a bug in the detector, please file an issue in netlify-cli\n ${err}`) + throw new Error( + `Failed to load detector: ${chalk.yellow( + detectorName + )}, this is likely a bug in the detector, please file an issue in netlify-cli\n ${err}` + ) } } module.exports.loadDetector = loadDetector @@ -147,7 +154,9 @@ function chooseDefaultArgs(possibleArgsArrs) { const args = possibleArgsArrs[0] // just pick the first one if (!args) { const { scripts } = JSON.parse(fs.readFileSync('package.json', { encoding: 'utf8' })) - const err = new Error('Empty args assigned, this is an internal Netlify Dev bug, please report your settings and scripts so we can improve') + const err = new Error( + 'Empty args assigned, this is an internal Netlify Dev bug, please report your settings and scripts so we can improve' + ) err.scripts = scripts err.possibleArgsArrs = possibleArgsArrs throw err @@ -159,7 +168,10 @@ module.exports.chooseDefaultArgs = chooseDefaultArgs /** utilities for the inquirer section above */ function filterSettings(scriptInquirerOptions, input) { - const filteredSettings = fuzzy.filter(input, scriptInquirerOptions.map(x => x.name)) + const filteredSettings = fuzzy.filter( + input, + scriptInquirerOptions.map(x => x.name) + ) const filteredSettingNames = filteredSettings.map(x => (input ? x.string : x)) return scriptInquirerOptions.filter(t => filteredSettingNames.includes(t.name)) } diff --git a/src/utils/get-repo-data.js b/src/utils/get-repo-data.js index b971bbc4b4f..2894ff44eb8 100644 --- a/src/utils/get-repo-data.js +++ b/src/utils/get-repo-data.js @@ -29,7 +29,9 @@ async function getRepoData(remote) { } if (!gitConfig.remote.hasOwnProperty(remote) || isEmpty(gitConfig.remote[remote])) { - throw new Error(`The specified remote "${remote}" is not defined in Git repo. Please use --gitRemoteName flag to specify a remote.`) + throw new Error( + `The specified remote "${remote}" is not defined in Git repo. Please use --gitRemoteName flag to specify a remote.` + ) } const remoteData = parseGitRemote(gitConfig.remote[remote].url) diff --git a/src/utils/headers.js b/src/utils/headers.js index d09db55f265..7521593d73d 100644 --- a/src/utils/headers.js +++ b/src/utils/headers.js @@ -1,94 +1,97 @@ const fs = require('fs') -const TOKEN_COMMENT = "#" -const TOKEN_PATH = "/" +const TOKEN_COMMENT = '#' +const TOKEN_PATH = '/' function matchPaths(rulePath, targetPath) { - const rulePathParts = rulePath.split('/').filter(Boolean) - const targetPathParts = targetPath.split('/').filter(Boolean) - - if (rulePathParts.length < 1 && targetPathParts.length < 1) { - return true - } - - for (let i = 0; i < rulePathParts.length; i++) { - if (i >= targetPathParts.length) return false - - const rulePart = rulePathParts[i] - const target = targetPathParts[i] - - if (rulePart === '*') return true - - if (rulePart.startsWith(':')) { - if (i === rulePathParts.length - 1) { - return i === targetPathParts.length - 1 - } - if (i === targetPathParts.length - 1) { - return false - } - } else { - return rulePart === target - } + const rulePathParts = rulePath.split('/').filter(Boolean) + const targetPathParts = targetPath.split('/').filter(Boolean) + + if (rulePathParts.length < 1 && targetPathParts.length < 1) { + return true + } + + for (let i = 0; i < rulePathParts.length; i++) { + if (i >= targetPathParts.length) return false + + const rulePart = rulePathParts[i] + const target = targetPathParts[i] + + if (rulePart === '*') return true + + if (rulePart.startsWith(':')) { + if (i === rulePathParts.length - 1) { + return i === targetPathParts.length - 1 + } + if (i === targetPathParts.length - 1) { + return false + } + } else { + return rulePart === target } + } - return false + return false } function objectForPath(rules, pathname) { - return Object.entries(rules).reduce((prev, [rulePath, pathHeaders]) => Object.assign({}, prev, matchPaths(rulePath, pathname) && pathHeaders), {}) + return Object.entries(rules).reduce( + (prev, [rulePath, pathHeaders]) => Object.assign({}, prev, matchPaths(rulePath, pathname) && pathHeaders), + {} + ) } function parseHeadersFile(filePath) { - const rules = {} - if (!fs.existsSync(filePath)) return rules - if (fs.statSync(filePath).isDirectory()) { - console.warn('expected _headers file but found a directory at:', filePath) - return rules - } + const rules = {} + if (!fs.existsSync(filePath)) return rules + if (fs.statSync(filePath).isDirectory()) { + console.warn('expected _headers file but found a directory at:', filePath) + return rules + } - const lines = fs.readFileSync(filePath, { encoding: 'utf8' }).split('\n') - if (lines.length < 1) return rules + const lines = fs.readFileSync(filePath, { encoding: 'utf8' }).split('\n') + if (lines.length < 1) return rules - let path - for (let i = 0; i <= lines.length; i++) { - if (!lines[i]) continue + let path + for (let i = 0; i <= lines.length; i++) { + if (!lines[i]) continue - const line = lines[i].trim() + const line = lines[i].trim() - if (line.startsWith(TOKEN_COMMENT) || line.length < 1) continue - if (line.startsWith(TOKEN_PATH)) { - if (line.includes('*') && line.indexOf('*') !== line.length - 1) { - throw new Error(`invalid rule (A path rule cannot contain anything after * token) at line: ${i}\n${lines[i]}\n`) - } - path = line - continue - } + if (line.startsWith(TOKEN_COMMENT) || line.length < 1) continue + if (line.startsWith(TOKEN_PATH)) { + if (line.includes('*') && line.indexOf('*') !== line.length - 1) { + throw new Error(`invalid rule (A path rule cannot contain anything after * token) at line: ${i}\n${lines[i]}\n`) + } + path = line + continue + } - if (!path) throw new Error('path should come before headers') + if (!path) throw new Error('path should come before headers') - if (line.includes(':')) { - const sepIndex = line.indexOf(':') - if (sepIndex < 1) throw new Error(`invalid header at line: ${i}\n${lines[i]}\n`) + if (line.includes(':')) { + const sepIndex = line.indexOf(':') + if (sepIndex < 1) throw new Error(`invalid header at line: ${i}\n${lines[i]}\n`) - const key = line.substr(0, sepIndex).trim() - const value = line.substr(sepIndex + 1).trim() + const key = line.substr(0, sepIndex).trim() + const value = line.substr(sepIndex + 1).trim() - if (rules.hasOwnProperty(path)) { - if (rules[path].hasOwnProperty(key)) { - rules[path][key].push(value) - } else { - rules[path][key] = [value] - } - } else { - rules[path] = {[key]: [value]} - } + if (rules.hasOwnProperty(path)) { + if (rules[path].hasOwnProperty(key)) { + rules[path][key].push(value) + } else { + rules[path][key] = [value] } + } else { + rules[path] = { [key]: [value] } + } } + } - return rules + return rules } module.exports = { - objectForPath, - parseHeadersFile, + objectForPath, + parseHeadersFile } diff --git a/src/utils/headers.test.js b/src/utils/headers.test.js index db05845479b..a4e1405bfcf 100644 --- a/src/utils/headers.test.js +++ b/src/utils/headers.test.js @@ -1,80 +1,46 @@ const test = require('ava') const path = require('path') -const { parseHeadersFile, objectForPath } = require('./headers.js') +const { parseHeadersFile, objectForPath } = require('./headers.js') test('_headers: validate correct parsing', t => { - const sitePath = path.join(__dirname, '../tests/dummy-site') - const rules = parseHeadersFile(path.resolve(sitePath, '_headers')) + const sitePath = path.join(__dirname, '../tests/dummy-site') + const rules = parseHeadersFile(path.resolve(sitePath, '_headers')) - t.deepEqual(rules, { - "/":{ - "X-Frame-Options":[ - "SAMEORIGIN" - ] - }, - "/*":{ - "X-Frame-Thing":[ - "SAMEORIGIN" - ] - }, - "/something/*":{ - "X-Frame-Options":[ - "DENY" - ], - "X-XSS-Protection":[ - "1; mode=block" - ], - "cache-control":[ - "max-age=0", - "no-cache", - "no-store", - "must-revalidate" - ] - }, - "/:ding/index.html":{ - "X-Frame-Options":[ - "SAMEORIGIN" - ] - } - }) + t.deepEqual(rules, { + '/': { + 'X-Frame-Options': ['SAMEORIGIN'] + }, + '/*': { + 'X-Frame-Thing': ['SAMEORIGIN'] + }, + '/something/*': { + 'X-Frame-Options': ['DENY'], + 'X-XSS-Protection': ['1; mode=block'], + 'cache-control': ['max-age=0', 'no-cache', 'no-store', 'must-revalidate'] + }, + '/:ding/index.html': { + 'X-Frame-Options': ['SAMEORIGIN'] + } + }) }) test('_headers: rulesForPath testing', t => { - const sitePath = path.join(__dirname, '../tests/dummy-site') - const rules = parseHeadersFile(path.resolve(sitePath, '_headers')) - t.deepEqual(objectForPath(rules, '/'), { - "X-Frame-Options":[ - "SAMEORIGIN" - ] - }) - t.deepEqual(objectForPath(rules, '/ding'), { - "X-Frame-Thing":[ - "SAMEORIGIN" - ] - }) - t.deepEqual(objectForPath(rules, '/something/ding'), { - "X-Frame-Thing":[ - "SAMEORIGIN" - ], - "X-Frame-Options":[ - "DENY" - ], - "X-XSS-Protection":[ - "1; mode=block" - ], - "cache-control":[ - "max-age=0", - "no-cache", - "no-store", - "must-revalidate" - ] - }) - t.deepEqual(objectForPath(rules, '/ding/index.html'), { - "X-Frame-Options":[ - "SAMEORIGIN" - ], - "X-Frame-Thing":[ - "SAMEORIGIN" - ] - }) + const sitePath = path.join(__dirname, '../tests/dummy-site') + const rules = parseHeadersFile(path.resolve(sitePath, '_headers')) + t.deepEqual(objectForPath(rules, '/'), { + 'X-Frame-Options': ['SAMEORIGIN'] + }) + t.deepEqual(objectForPath(rules, '/ding'), { + 'X-Frame-Thing': ['SAMEORIGIN'] + }) + t.deepEqual(objectForPath(rules, '/something/ding'), { + 'X-Frame-Thing': ['SAMEORIGIN'], + 'X-Frame-Options': ['DENY'], + 'X-XSS-Protection': ['1; mode=block'], + 'cache-control': ['max-age=0', 'no-cache', 'no-store', 'must-revalidate'] + }) + t.deepEqual(objectForPath(rules, '/ding/index.html'), { + 'X-Frame-Options': ['SAMEORIGIN'], + 'X-Frame-Thing': ['SAMEORIGIN'] + }) }) diff --git a/src/utils/logo.js b/src/utils/logo.js index b12ddc9e308..dd06231c0b2 100644 --- a/src/utils/logo.js +++ b/src/utils/logo.js @@ -1,8 +1,8 @@ -const chalk = require("chalk") +const chalk = require('chalk') module.exports = { - NETLIFYDEV: `${chalk.greenBright("◈")} ${chalk.rgb(40, 180, 170)("Netlify Dev")} ${chalk.greenBright("◈")}`, - NETLIFYDEVLOG: `${chalk.greenBright("◈")}`, - NETLIFYDEVWARN: `${chalk.yellowBright("◈")}`, - NETLIFYDEVERR: `${chalk.redBright("◈")}` + NETLIFYDEV: `${chalk.greenBright('◈')} ${chalk.rgb(40, 180, 170)('Netlify Dev')} ${chalk.greenBright('◈')}`, + NETLIFYDEVLOG: `${chalk.greenBright('◈')}`, + NETLIFYDEVWARN: `${chalk.yellowBright('◈')}`, + NETLIFYDEVERR: `${chalk.redBright('◈')}` } diff --git a/src/utils/rules-proxy.js b/src/utils/rules-proxy.js index b40330a1fbb..2e2c3605350 100644 --- a/src/utils/rules-proxy.js +++ b/src/utils/rules-proxy.js @@ -58,17 +58,18 @@ module.exports = async function createRewriter({ distDir, projectDir, jwtSecret, let matcher = null const configFiles = Array.from( new Set( - [ - path.resolve(distDir, '_redirects'), - path.resolve(projectDir, '_redirects'), - ] - .concat(configPath ? path.resolve(configPath) : []) + [path.resolve(distDir, '_redirects'), path.resolve(projectDir, '_redirects')].concat( + configPath ? path.resolve(configPath) : [] + ) ) ).filter(f => f !== projectDir) let rules = await parseRules(configFiles) onChanges(configFiles, async () => { - console.log(`${NETLIFYDEVLOG} Reloading redirect rules from`, configFiles.filter(fs.existsSync).map(p => path.relative(projectDir, p))) + console.log( + `${NETLIFYDEVLOG} Reloading redirect rules from`, + configFiles.filter(fs.existsSync).map(p => path.relative(projectDir, p)) + ) rules = await parseRules(configFiles) matcher = null }) @@ -77,10 +78,10 @@ module.exports = async function createRewriter({ distDir, projectDir, jwtSecret, if (matcher) return matcher if (rules.length) { - return matcher = await redirector.parseJSON(JSON.stringify(rules), { + return (matcher = await redirector.parseJSON(JSON.stringify(rules), { jwtSecret: jwtSecret || 'secret', jwtRole: jwtRole || 'app_metadata.authorization.roles' - }) + })) } return { match() { diff --git a/src/utils/serve-functions.js b/src/utils/serve-functions.js index e26ffbeeeea..faf5b12cb40 100644 --- a/src/utils/serve-functions.js +++ b/src/utils/serve-functions.js @@ -57,9 +57,7 @@ function createCallback(response) { const items = lambdaResponse.multiValueHeaders[key] response.setHeader(key, items) } - response.write( - lambdaResponse.isBase64Encoded ? Buffer.from(lambdaResponse.body, 'base64') : lambdaResponse.body - ) + response.write(lambdaResponse.isBase64Encoded ? Buffer.from(lambdaResponse.body, 'base64') : lambdaResponse.body) response.end() } } @@ -105,9 +103,7 @@ function createHandler(dir) { const logger = winston.createLogger({ levels: winston.config.npm.levels, - transports: [ - new winston.transports.Console( { level: 'warn' }), - ] + transports: [new winston.transports.Console({ level: 'warn' })] }) lambdaLocal.setLogger(logger) @@ -158,7 +154,7 @@ function createHandler(dir) { clientContext: JSON.stringify(buildClientContext(request.headers) || {}), callback: callback, verboseLevel: 3, - timeoutMs: 10 * 1000, + timeoutMs: 10 * 1000 }) } }