Repository: nuxt/nuxt.js
Pull request #7144 (2020-03-27 15:16:55)

feat(babel-preset-app): add `bugfixes` option
<!--- Provide a general summary of your changes in the title above -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (a non-breaking change which fixes an issue)
- [x] New feature (a non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)


## Description
<!--- Describe your changes in detail -->
<!--- Why is this change required? What problem does it solve? -->
<!--- If it resolves an open issue, please link to the issue here. For example "Resolves: #1337" -->

Related to https://github.com/nuxt/nuxt.js/issues/6784#issuecomment-605042333

Add new option `bugfixes` which is introduced from babel-preeset-env 7.9.0.

Options can be set by:


```js
export default {
  build: {
    babel: {
      presets: ['@nuxt/babel-preset-app', { bugfixes: true }]
  }
}
```

## Checklist:
<!--- Put an `x` in all the boxes that apply. -->
<!--- If your change requires a documentation PR, please link it appropriately -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly. (PR: #)
- [ ] I have added tests to cover my changes (if not applicable, please state why)
- [ ] All new and existing tests are passing.




Patch:
diff --git a/packages/babel-preset-app/README.md b/packages/babel-preset-app/README.md
index d03d7ea0d..260f6dcd5 100644
--- a/packages/babel-preset-app/README.md
+++ b/packages/babel-preset-app/README.md
@@ -45,6 +45,7 @@ Below is a list of all available `options` parameters:
 
 ### Options
 
+* **bugfixes** - [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env#bugfixes)
 * **configPath** - [`@babel/preset-env` parameter](https://babeljs.io/docs/en/babel-preset-env#configpath)
 * **forceAllTransforms** - '[@babel/preset-env](https://babeljs.io/docs/en/babel-preset-env#forcealltransforms)' parameter
 * **debug**, default  `false` - '[@babel/preset-env](https://babeljs.io/docs/en/babel-preset-env#debug)' parameter
diff --git a/packages/babel-preset-app/src/index.js b/packages/babel-preset-app/src/index.js
index ab3a3cc70..5d6da53e2 100644
--- a/packages/babel-preset-app/src/index.js
+++ b/packages/babel-preset-app/src/index.js
@@ -55,6 +55,7 @@ module.exports = (api, options = {}) => {
   const envName = api.env()
 
   const {
+    bugfixes,
     polyfills: userPolyfills,
     loose = false,
     debug = false,
@@ -111,6 +112,7 @@ module.exports = (api, options = {}) => {
   // Pass options along to babel-preset-env
   presets.push([
     require('@babel/preset-env'), {
+      bugfixes,
       spec,
       loose,
       debug,
diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js
index 6b4c90fb0..b40b6f93f 100644
--- a/packages/builder/src/builder.js
+++ b/packages/builder/src/builder.js
@@ -742,7 +742,7 @@ export default class Builder {
           }
 
           // Log
-          consola.info(`[HMR] ${chalk.cyan(newItem.route)} (${chalk.grey(fileName)})`)
+          consola.info(`[HMR] ${chalk.cyan(newItem.route || '/')} (${chalk.grey(fileName)})`)
         }
         // Tree may be changed so recreate watcher
         this.serverMiddlewareHMR()
diff --git a/packages/server/src/server.js b/packages/server/src/server.js
index 06afdccfb..cd5cebfc3 100644
--- a/packages/server/src/server.js
+++ b/packages/server/src/server.js
@@ -260,6 +260,11 @@ export default class Server {
       (typeof middleware.route === 'string' ? middleware.route : '')
     ).replace(/\/\//g, '/')
 
+    // Strip trailing slash
+    if (middleware.route.endsWith('/')) {
+      middleware.route = middleware.route.slice(0, -1)
+    }
+
     // Assign _middleware to handle to make accessable from app.stack
     middleware.handle._middleware = middleware
 
@@ -294,11 +299,7 @@ export default class Server {
     serverStackItem.handle = handle
 
     // Error State
-    if (route.includes('#error')) {
-      serverStackItem.route = serverStackItem.route || '/'
-    } else {
-      serverStackItem.route = route
-    }
+    serverStackItem.route = route
 
     // Return updated item
     return serverStackItem


Test patch:
diff --git a/packages/server/test/server.test.js b/packages/server/test/server.test.js
index 18f10ae1c..798e23f20 100644
--- a/packages/server/test/server.test.js
+++ b/packages/server/test/server.test.js
@@ -333,7 +333,7 @@ describe('server: server', () => {
 
   test('should use object middleware', () => {
     const nuxt = createNuxt()
-    nuxt.options.router = { base: '/' }
+    nuxt.options.router = { base: '' }
     const server = new Server(nuxt)
     const handler = jest.fn()
 
@@ -348,7 +348,7 @@ describe('server: server', () => {
 
   test('should use function module middleware', () => {
     const nuxt = createNuxt()
-    nuxt.options.router = { base: '/' }
+    nuxt.options.router = { base: '' }
     const server = new Server(nuxt)
     const handler = jest.fn()
     nuxt.resolver.requireModule.mockReturnValueOnce(handler)