Repository: nuxt/nuxt.js
Pull request #7796 (2020-07-28 11:51:23)

fix(cli): normalize win32 paths for `nuxt generate` cache snapshots
## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [x] Bug fix (a non-breaking change which fixes an issue)
- [ ] 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 -->
Added [upath](https://www.npmjs.com/package/upath) (which is already used in @nuxtjs/builder) for enforce posix patterns to be given to the `nuxt generate` [`snapshot` function](https://github.com/nuxt/nuxt.js/blob/dev/packages/cli/src/utils/generate.js#L142).
<!--- Why is this change required? What problem does it solve? -->
Globby was receiving OS specific paths for it's [ignore option](https://github.com/nuxt/nuxt.js/blob/dev/packages/cli/src/utils/generate.js#L142) while only accepting posix paths resulting to cache failing on win32 platform.
<!--- If it resolves an open issue, please link to the issue here. For example "Resolves: #1337" -->
Resolves: #7792 (all details there)

## 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)
- [x] All new and existing tests are passing. _(see message below)_



lihbr: @pi0 (sorry to ping you ^^) I didn't see any tests for the new `nuxt generate` cache feature 🤔 not sure of how to address that one for now~

Patch:
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 4ce47990e..483f1c075 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -33,6 +33,7 @@
     "pretty-bytes": "^5.3.0",
     "serve-static": "^1.14.1",
     "std-env": "^2.2.1",
+    "upath": "^1.2.0",
     "wrap-ansi": "^6.2.0"
   },
   "publishConfig": {
diff --git a/packages/cli/src/utils/generate.js b/packages/cli/src/utils/generate.js
index 6e881972b..c1c7eed18 100644
--- a/packages/cli/src/utils/generate.js
+++ b/packages/cli/src/utils/generate.js
@@ -1,4 +1,5 @@
 import path, { relative } from 'path'
+import upath from 'upath'
 import fs from 'fs-extra'
 import crc32 from 'crc/lib/crc32'
 import consola from 'consola'
@@ -48,7 +49,7 @@ export async function ensureBuild (cmd) {
   // Take a snapshot of current project
   const snapshotOptions = {
     rootDir: nuxt.options.rootDir,
-    ignore: nuxt.options.generate.cache.ignore,
+    ignore: nuxt.options.generate.cache.ignore.map(upath.normalize),
     globbyOptions: nuxt.options.generate.cache.globbyOptions
   }
 
diff --git a/packages/types/config/build.d.ts b/packages/types/config/build.d.ts
index 3965c10c9..617b5f594 100644
--- a/packages/types/config/build.d.ts
+++ b/packages/types/config/build.d.ts
@@ -137,6 +137,7 @@ export interface NuxtOptionsBuild {
   analyze?: BundleAnalyzerPlugin.Options | boolean
   babel?: NuxtBabelOptions
   cache?: boolean
+  corejs?: 'auto' | 2 | 3
   crossorigin?: string
   cssSourceMap?: boolean
   devMiddleware?: WebpackDevMiddlewareOptions
diff --git a/packages/webpack/src/config/base.js b/packages/webpack/src/config/base.js
index fd092179e..456bd8dee 100644
--- a/packages/webpack/src/config/base.js
+++ b/packages/webpack/src/config/base.js
@@ -120,15 +120,15 @@ export default class WebpackBaseConfig {
     let corejsVersion = corejs
     if (corejsVersion === 'auto') {
       try {
-        corejsVersion = createRequire(rootDir)('core-js/package.json').version.split('.')[0]
+        corejsVersion = Number.parseInt(createRequire(rootDir)('core-js/package.json').version.split('.')[0])
       } catch (_err) {
-        corejsVersion = '2'
+        corejsVersion = 2
       }
     }
 
-    if (corejsVersion !== '2' && corejsVersion !== '3') {
-      consola.warn(`Invalid corejs version ${JSON.stringify(corejsVersion)}! Please set "build.corejs" to either "2" or "3".`)
-      corejsVersion = '2'
+    if (![2, 3].includes(corejsVersion)) {
+      consola.warn(`Invalid corejs version ${corejsVersion}! Please set "build.corejs" to either "auto", 2 or 3.`)
+      corejsVersion = 2
     }
 
     const defaultPreset = [require.resolve('@nuxt/babel-preset-app'), {


Test patch:
diff --git a/packages/cli/test/unit/__snapshots__/webpack.test.js.snap b/packages/cli/test/unit/__snapshots__/webpack.test.js.snap
index 0100e79fc..719860577 100644
--- a/packages/cli/test/unit/__snapshots__/webpack.test.js.snap
+++ b/packages/cli/test/unit/__snapshots__/webpack.test.js.snap
@@ -75,7 +75,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
               \\"<nuxtDir>/packages/babel-preset-app/src/index.js\\",
               Object {
                 \\"corejs\\": Object {
-                  \\"version\\": \\"2\\",
+                  \\"version\\": 2,
                 },
               },
             ],
@@ -654,7 +654,7 @@ exports[`webpack nuxt webpack module.rules test=.jsx 1`] = `
             \\"<nuxtDir>/packages/babel-preset-app/src/index.js\\",
             Object {
               \\"corejs\\": Object {
-                \\"version\\": \\"2\\",
+                \\"version\\": 2,
               },
             },
           ],