Repository: netlify/build
Pull request #3460 (2021-08-13 12:16:53)

fix(deps): update dependency netlify-redirect-parser to v10
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [netlify-redirect-parser](https://togithub.com/netlify/netlify-redirect-parser) | [`^9.1.0` -> `^10.0.0`](https://renovatebot.com/diffs/npm/netlify-redirect-parser/9.1.0/10.0.0) | [![age](https://badges.renovateapi.com/packages/npm/netlify-redirect-parser/10.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/netlify-redirect-parser/10.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/netlify-redirect-parser/10.0.0/compatibility-slim/9.1.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/netlify-redirect-parser/10.0.0/confidence-slim/9.1.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>netlify/netlify-redirect-parser</summary>

### [`v10.0.0`](https://togithub.com/netlify/netlify-redirect-parser/blob/master/CHANGELOG.md#&#8203;1000-httpswwwgithubcomnetlifynetlify-redirect-parsercomparev910v1000-2021-08-13)

[Compare Source](https://togithub.com/netlify/netlify-redirect-parser/compare/v9.1.0...v10.0.0)

##### ⚠ BREAKING CHANGES

-   add lenient parsing

##### Features

-   add lenient parsing ([562eb4d](https://www.github.com/netlify/netlify-redirect-parser/commit/562eb4d4fccc050241f51aee5193c694a1e9d205))

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/netlify/build).

kodiakhq[bot]: 
This PR currently has a merge conflict. Please resolve this and then re-add the `automerge` label.


Patch:
diff --git a/package-lock.json b/package-lock.json
index accef6f93..334d6a85b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14132,9 +14132,9 @@
       }
     },
     "node_modules/netlify-redirect-parser": {
-      "version": "9.1.0",
-      "resolved": "https://registry.npmjs.org/netlify-redirect-parser/-/netlify-redirect-parser-9.1.0.tgz",
-      "integrity": "sha512-YORCj4Qeimv7VixnNHtTt3i0EfyWYG0rYb68EcQpwJ+nG1mRWmybW2WwYcKI5jRIaKTNZeDwsWS+yuGpRfcu0A==",
+      "version": "10.0.0",
+      "resolved": "https://registry.npmjs.org/netlify-redirect-parser/-/netlify-redirect-parser-10.0.0.tgz",
+      "integrity": "sha512-hbl1e/LQ9kChfMatJu3hXL4F6qdNYl1WDu/P3qMgB4g8z4zgW6JDfpPoYNuTANQWqtN0ufcWJ4EHRrIRcawx0Q==",
       "dependencies": {
         "filter-obj": "^2.0.2",
         "is-plain-obj": "^2.1.0",
@@ -20304,7 +20304,7 @@
     },
     "packages/build": {
       "name": "@netlify/build",
-      "version": "18.2.4",
+      "version": "18.2.5",
       "license": "MIT",
       "dependencies": {
         "@bugsnag/js": "^7.0.0",
@@ -20498,7 +20498,7 @@
     },
     "packages/cache-utils": {
       "name": "@netlify/cache-utils",
-      "version": "2.0.0",
+      "version": "2.0.1",
       "license": "MIT",
       "dependencies": {
         "array-flat-polyfill": "^1.0.1",
@@ -20562,7 +20562,7 @@
     },
     "packages/config": {
       "name": "@netlify/config",
-      "version": "15.1.4",
+      "version": "15.1.5",
       "license": "MIT",
       "dependencies": {
         "@ungap/from-entries": "^0.2.1",
@@ -20583,7 +20583,7 @@
         "map-obj": "^4.0.0",
         "netlify": "^8.0.0",
         "netlify-headers-parser": "^2.1.0",
-        "netlify-redirect-parser": "^9.1.0",
+        "netlify-redirect-parser": "^10.0.0",
         "omit.js": "^2.0.2",
         "p-locate": "^4.1.0",
         "path-exists": "^4.0.0",
@@ -23755,7 +23755,7 @@
         "map-obj": "^4.0.0",
         "netlify": "^8.0.0",
         "netlify-headers-parser": "^2.1.0",
-        "netlify-redirect-parser": "^9.1.0",
+        "netlify-redirect-parser": "^10.0.0",
         "omit.js": "^2.0.2",
         "p-locate": "^4.1.0",
         "path-exists": "^4.0.0",
@@ -32140,9 +32140,9 @@
       }
     },
     "netlify-redirect-parser": {
-      "version": "9.1.0",
-      "resolved": "https://registry.npmjs.org/netlify-redirect-parser/-/netlify-redirect-parser-9.1.0.tgz",
-      "integrity": "sha512-YORCj4Qeimv7VixnNHtTt3i0EfyWYG0rYb68EcQpwJ+nG1mRWmybW2WwYcKI5jRIaKTNZeDwsWS+yuGpRfcu0A==",
+      "version": "10.0.0",
+      "resolved": "https://registry.npmjs.org/netlify-redirect-parser/-/netlify-redirect-parser-10.0.0.tgz",
+      "integrity": "sha512-hbl1e/LQ9kChfMatJu3hXL4F6qdNYl1WDu/P3qMgB4g8z4zgW6JDfpPoYNuTANQWqtN0ufcWJ4EHRrIRcawx0Q==",
       "requires": {
         "filter-obj": "^2.0.2",
         "is-plain-obj": "^2.1.0",
diff --git a/packages/config/package.json b/packages/config/package.json
index 1ab5949f1..957192b6e 100644
--- a/packages/config/package.json
+++ b/packages/config/package.json
@@ -67,7 +67,7 @@
     "map-obj": "^4.0.0",
     "netlify": "^8.0.0",
     "netlify-headers-parser": "^2.1.0",
-    "netlify-redirect-parser": "^9.1.0",
+    "netlify-redirect-parser": "^10.0.0",
     "omit.js": "^2.0.2",
     "p-locate": "^4.1.0",
     "path-exists": "^4.0.0",
diff --git a/packages/config/src/log/messages.js b/packages/config/src/log/messages.js
index 5e63b7369..70c8c7123 100644
--- a/packages/config/src/log/messages.js
+++ b/packages/config/src/log/messages.js
@@ -59,15 +59,16 @@ ${errorMessage}`,
   )
 }
 
-const getErrorMessage = function ({ message }) {
-  return message
-}
-
 const warnHeadersException = function (logs, errorMessage) {
   logWarning(logs, `Error while parsing headers: ${errorMessage}`)
 }
 
-const warnRedirectsParsing = function (logs, errorMessage) {
+const warnRedirectsParsing = function (logs, errors) {
+  if (errors.length === 0) {
+    return
+  }
+
+  const errorMessage = errors.map(getErrorMessage).join('\n\n')
   logWarning(
     logs,
     `
@@ -77,6 +78,14 @@ ${errorMessage}`,
   )
 }
 
+const warnRedirectsException = function (logs, errorMessage) {
+  logWarning(logs, `Error while parsing redirects: ${errorMessage}`)
+}
+
+const getErrorMessage = function ({ message }) {
+  return message
+}
+
 module.exports = {
   warnLegacyFunctionsDirectory,
   warnContextPluginConfig,
@@ -84,4 +93,5 @@ module.exports = {
   warnHeadersParsing,
   warnHeadersException,
   warnRedirectsParsing,
+  warnRedirectsException,
 }
diff --git a/packages/config/src/redirects.js b/packages/config/src/redirects.js
index 91758a4aa..492fd62ec 100644
--- a/packages/config/src/redirects.js
+++ b/packages/config/src/redirects.js
@@ -4,7 +4,7 @@ const { resolve } = require('path')
 
 const { parseFileRedirects, mergeRedirects, normalizeRedirects } = require('netlify-redirect-parser')
 
-const { warnRedirectsParsing } = require('./log/messages')
+const { warnRedirectsParsing, warnRedirectsException } = require('./log/messages')
 
 // Add `config.redirects`
 const addRedirects = async function (config, logs) {
@@ -17,24 +17,27 @@ const REDIRECTS_FILENAME = '_redirects'
 
 const addConfigRedirects = async function ({ redirects: configRedirects = [], ...config }, redirectsPath, logs) {
   try {
-    const normalizedConfigRedirects = normalizeAllRedirects(configRedirects)
-    const normalizedFileRedirects = await getFileRedirects(redirectsPath)
-    const redirects = mergeRedirects({
+    const { redirects: normalizedConfigRedirects, errors: configNormalizeErrors } =
+      normalizeAllRedirects(configRedirects)
+    const { normalizedFileRedirects, fileParseErrors, fileNormalizeErrors } = await getFileRedirects(redirectsPath)
+    const { redirects, errors: mergeErrors } = mergeRedirects({
       fileRedirects: normalizedFileRedirects,
       configRedirects: normalizedConfigRedirects,
     })
+    const errors = [...configNormalizeErrors, ...fileParseErrors, ...fileNormalizeErrors, ...mergeErrors]
+    warnRedirectsParsing(logs, errors)
     return { ...config, redirects }
     // @todo remove this failsafe once the code is stable
   } catch (error) {
-    warnRedirectsParsing(logs, error.message)
+    warnRedirectsException(logs, error.message)
     return { ...config, redirects: [] }
   }
 }
 
 const getFileRedirects = async function (redirectsPath) {
-  const fileRedirects = await parseFileRedirects(redirectsPath)
-  const normalizedFileRedirects = normalizeAllRedirects(fileRedirects)
-  return normalizedFileRedirects
+  const { redirects: fileRedirects, errors: fileParseErrors } = await parseFileRedirects(redirectsPath)
+  const { redirects: normalizedFileRedirects, errors: fileNormalizeErrors } = normalizeAllRedirects(fileRedirects)
+  return { normalizedFileRedirects, fileParseErrors, fileNormalizeErrors }
 }
 
 const normalizeAllRedirects = function (redirects) {


Test patch:
diff --git a/packages/config/tests/parse/fixtures/redirects_field_error/netlify.toml b/packages/config/tests/parse/fixtures/redirects_field_error/netlify.toml
index e23b209fc..31af1550e 100644
--- a/packages/config/tests/parse/fixtures/redirects_field_error/netlify.toml
+++ b/packages/config/tests/parse/fixtures/redirects_field_error/netlify.toml
@@ -1,2 +1,9 @@
 [[redirects]]
 from = "/from"
+
+[[redirects]]
+from = "/.netlify/from"
+
+[[redirects]]
+from = "/from"
+to = "/to"
diff --git a/packages/config/tests/parse/fixtures/redirects_file_error/publish/_redirects b/packages/config/tests/parse/fixtures/redirects_file_error/publish/_redirects
index 362d91652..eb2b1b60f 100644
--- a/packages/config/tests/parse/fixtures/redirects_file_error/publish/_redirects
+++ b/packages/config/tests/parse/fixtures/redirects_file_error/publish/_redirects
@@ -1,1 +1,3 @@
 /from
+/.netlify/from
+/from /to
diff --git a/packages/config/tests/parse/snapshots/tests.js.md b/packages/config/tests/parse/snapshots/tests.js.md
index da323b3f7..8432f8f6e 100644
--- a/packages/config/tests/parse/snapshots/tests.js.md
+++ b/packages/config/tests/parse/snapshots/tests.js.md
@@ -522,6 +522,10 @@ Generated by [AVA](https://avajs.dev).
       /external/path␊
     Missing destination path/URL␊
     ␊
+    Could not parse redirect line 2:␊
+      /external/path␊
+    Missing destination path/URL␊
+    ␊
     {␊
       "accounts": [],␊
       "addons": [],␊
@@ -545,7 +549,16 @@ Generated by [AVA](https://avajs.dev).
         },␊
         "headers": [],␊
         "plugins": [],␊
-        "redirects": []␊
+        "redirects": [␊
+          {␊
+            "conditions": {},␊
+            "force": false,␊
+            "from": "/external/path",␊
+            "headers": {},␊
+            "query": {},␊
+            "to": "/external/path"␊
+          }␊
+        ]␊
       },␊
       "configPath": "packages/config/tests/parse/fixtures/redirects_file_error/netlify.toml",␊
       "context": "production",␊
@@ -640,6 +653,10 @@ Generated by [AVA](https://avajs.dev).
       {"from":"/external/path"}␊
     Missing "to" field␊
     ␊
+    Could not parse redirect number 2:␊
+      {"from":"/external/path"}␊
+    Missing "to" field␊
+    ␊
     {␊
       "accounts": [],␊
       "addons": [],␊
@@ -663,7 +680,16 @@ Generated by [AVA](https://avajs.dev).
         },␊
         "headers": [],␊
         "plugins": [],␊
-        "redirects": [],␊
+        "redirects": [␊
+          {␊
+            "conditions": {},␊
+            "force": false,␊
+            "from": "/external/path",␊
+            "headers": {},␊
+            "query": {},␊
+            "to": "/external/path"␊
+          }␊
+        ],␊
         "redirectsOrigin": "config"␊
       },␊
       "configPath": "packages/config/tests/parse/fixtures/redirects_field_error/netlify.toml",␊