Skip to content

Commit 9641d6d

Browse files
authored
fix: fix support for Node.js v8 and deprecate it (#5827)
Fixes #5800
1 parent 9706cd1 commit 9641d6d

File tree

3 files changed

+70
-18
lines changed

3 files changed

+70
-18
lines changed

Diff for: packages/@vue/cli/bin/vue.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ function checkNodeVersion (wanted, id) {
1919

2020
checkNodeVersion(requiredVersion, '@vue/cli')
2121

22-
if (semver.satisfies(process.version, '9.x')) {
23-
console.log(chalk.red(
24-
`You are using Node ${process.version}.\n` +
25-
`Node.js 9.x has already reached end-of-life and will not be supported in future major releases.\n` +
26-
`It's strongly recommended to use an active LTS version instead.`
27-
))
22+
const EOL_NODE_MAJORS = ['8.x', '9.x', '11.x', '13.x']
23+
for (const major of EOL_NODE_MAJORS) {
24+
if (semver.satisfies(process.version, major)) {
25+
console.log(chalk.red(
26+
`You are using Node ${process.version}.\n` +
27+
`Node.js ${major} has already reached end-of-life and will not be supported in future major releases.\n` +
28+
`It's strongly recommended to use an active LTS version instead.`
29+
))
30+
}
2831
}
2932

3033
const fs = require('fs')

Diff for: packages/@vue/cli/lib/Creator.js

+23-12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const {
2828
const {
2929
chalk,
3030
execa,
31+
semver,
3132

3233
log,
3334
warn,
@@ -132,9 +133,10 @@ module.exports = class Creator extends EventEmitter {
132133
(hasYarn() ? 'yarn' : null) ||
133134
(hasPnpm3OrLater() ? 'pnpm' : 'npm')
134135
)
135-
const pm = new PackageManager({ context, forcePackageManager: packageManager })
136136

137137
await clearConsole()
138+
const pm = new PackageManager({ context, forcePackageManager: packageManager })
139+
138140
log(`✨ Creating project in ${chalk.yellow(context)}.`)
139141
this.emit('creation', { event: 'creating' })
140142

@@ -173,6 +175,26 @@ module.exports = class Creator extends EventEmitter {
173175
'package.json': JSON.stringify(pkg, null, 2)
174176
})
175177

178+
// generate a .npmrc file for pnpm, to persist the `shamefully-flatten` flag
179+
if (packageManager === 'pnpm') {
180+
const pnpmConfig = hasPnpmVersionOrLater('4.0.0')
181+
? 'shamefully-hoist=true\n'
182+
: 'shamefully-flatten=true\n'
183+
184+
await writeFileTree(context, {
185+
'.npmrc': pnpmConfig
186+
})
187+
}
188+
189+
if (packageManager === 'yarn' && semver.satisfies(process.version, '8.x')) {
190+
// Vue CLI 4.x should support Node 8.x,
191+
// but some dependenices already bumped `engines` field to Node 10
192+
// and Yarn treats `engines` field too strictly
193+
await writeFileTree(context, {
194+
'.yarnrc': '# Hotfix for Node 8.x\n--install.ignore-engines true\n'
195+
})
196+
}
197+
176198
// intilaize git repository before installing deps
177199
// so that vue-cli-service can setup git hooks.
178200
const shouldInitGit = this.shouldInitGit(cliOptions)
@@ -235,17 +257,6 @@ module.exports = class Creator extends EventEmitter {
235257
})
236258
}
237259

238-
// generate a .npmrc file for pnpm, to persist the `shamefully-flatten` flag
239-
if (packageManager === 'pnpm') {
240-
const pnpmConfig = hasPnpmVersionOrLater('4.0.0')
241-
? 'shamefully-hoist=true\n'
242-
: 'shamefully-flatten=true\n'
243-
244-
await writeFileTree(context, {
245-
'.npmrc': pnpmConfig
246-
})
247-
}
248-
249260
// commit initial state
250261
let gitCommitFailed = false
251262
let gpgSign = false

Diff for: packages/@vue/cli/lib/util/ProjectPackageManager.js

+38
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ class PackageManager {
106106
this.bin = loadOptions().packageManager || (hasYarn() ? 'yarn' : hasPnpm3OrLater() ? 'pnpm' : 'npm')
107107
}
108108

109+
if (this.bin === 'npm') {
110+
// npm doesn't support package aliases until v6.9
111+
const MIN_SUPPORTED_NPM_VERSION = '6.9.0'
112+
const npmVersion = stripAnsi(execa.sync('npm', ['--version']).stdout)
113+
114+
if (semver.lt(npmVersion, MIN_SUPPORTED_NPM_VERSION)) {
115+
warn(
116+
'You are using an outdated version of NPM.\n' +
117+
'there may be unexpected errors during installation.\n' +
118+
'Please upgrade your NPM version.'
119+
)
120+
121+
this.needsNpmInstallFix = true
122+
}
123+
}
124+
109125
if (!SUPPORTED_PACKAGE_MANAGERS.includes(this.bin)) {
110126
log()
111127
warn(
@@ -313,6 +329,28 @@ class PackageManager {
313329
}
314330
}
315331

332+
if (this.needsNpmInstallFix) {
333+
// if npm 5, split into several `npm add` calls
334+
// see https://github.com/vuejs/vue-cli/issues/5800#issuecomment-675199729
335+
const pkg = resolvePkg(this.context)
336+
if (pkg.dependencies) {
337+
const deps = Object.entries(pkg.dependencies).map(([dep, range]) => `${dep}@${range}`)
338+
await this.runCommand('install', deps)
339+
}
340+
341+
if (pkg.devDependencies) {
342+
const devDeps = Object.entries(pkg.devDependencies).map(([dep, range]) => `${dep}@${range}`)
343+
await this.runCommand('install', [...devDeps, '--save-dev'])
344+
}
345+
346+
if (pkg.optionalDependencies) {
347+
const devDeps = Object.entries(pkg.devDependencies).map(([dep, range]) => `${dep}@${range}`)
348+
await this.runCommand('install', [...devDeps, '--save-optional'])
349+
}
350+
351+
return
352+
}
353+
316354
return await this.runCommand('install')
317355
}
318356

0 commit comments

Comments
 (0)