mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
feat(cli): warn if incompatible node/package versions detected (#8792)
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
parent
346a57eb34
commit
e5d202badb
@ -31,6 +31,7 @@
|
|||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
"opener": "1.5.2",
|
"opener": "1.5.2",
|
||||||
"pretty-bytes": "^5.5.0",
|
"pretty-bytes": "^5.5.0",
|
||||||
|
"semver": "^7.3.4",
|
||||||
"serve-static": "^1.14.1",
|
"serve-static": "^1.14.1",
|
||||||
"std-env": "^2.2.1",
|
"std-env": "^2.2.1",
|
||||||
"upath": "^2.0.1",
|
"upath": "^2.0.1",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import exit from 'exit'
|
import exit from 'exit'
|
||||||
|
import { checkDependencies } from './utils/dependencies'
|
||||||
import { fatalBox } from './utils/formatting'
|
import { fatalBox } from './utils/formatting'
|
||||||
|
|
||||||
let _setup = false
|
let _setup = false
|
||||||
@ -15,6 +16,8 @@ export default function setup ({ dev }) {
|
|||||||
}
|
}
|
||||||
_setup = true
|
_setup = true
|
||||||
|
|
||||||
|
checkDependencies()
|
||||||
|
|
||||||
// Global error handler
|
// Global error handler
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
process.on('unhandledRejection', (err) => {
|
process.on('unhandledRejection', (err) => {
|
||||||
|
35
packages/cli/src/utils/dependencies.js
Normal file
35
packages/cli/src/utils/dependencies.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import consola from 'consola'
|
||||||
|
import { satisfies } from 'semver'
|
||||||
|
import { getPKG } from '@nuxt/utils'
|
||||||
|
|
||||||
|
const dependencies = {
|
||||||
|
postcss: '^7.0.32',
|
||||||
|
webpack: '^4.46.0',
|
||||||
|
'sass-loader': '^10.1.1'
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodeVersion = '>=12.0.0'
|
||||||
|
|
||||||
|
function getInstalledVersion (name) {
|
||||||
|
try {
|
||||||
|
return getPKG(name).version
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkDependencies () {
|
||||||
|
for (const name in dependencies) {
|
||||||
|
const installedVersion = getInstalledVersion(name)
|
||||||
|
if (!installedVersion) {
|
||||||
|
return // Ignore to avoid false-positive warnings
|
||||||
|
}
|
||||||
|
const expectedRange = dependencies[name]
|
||||||
|
if (!satisfies(installedVersion, expectedRange)) {
|
||||||
|
consola.warn(`${name}@${installedVersion} is installed but ${expectedRange} is expected`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check Node versions
|
||||||
|
if (!satisfies(process.version, nodeVersion)) {
|
||||||
|
consola.warn(`You are using an unsupported version of Node.js (${process.version}). It is recommended to use the latest LTS version (https://nodejs.org/en/about/releases)`)
|
||||||
|
}
|
||||||
|
}
|
25
packages/cli/test/unit/dependencies.test.js
Normal file
25
packages/cli/test/unit/dependencies.test.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { consola } from '../utils'
|
||||||
|
import { checkDependencies } from '../../src/utils/dependencies'
|
||||||
|
|
||||||
|
jest.mock('webpack/package.json', () => ({
|
||||||
|
version: '5.0.0'
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe('cli/utils', () => {
|
||||||
|
afterEach(() => jest.resetAllMocks())
|
||||||
|
|
||||||
|
test('checkDependencies', () => {
|
||||||
|
checkDependencies()
|
||||||
|
expect(consola.warn).toHaveBeenCalledWith(
|
||||||
|
expect.stringMatching(
|
||||||
|
/webpack@.+ is installed but .+ is expected/
|
||||||
|
)
|
||||||
|
)
|
||||||
|
expect(consola.warn).toHaveBeenCalledTimes(1)
|
||||||
|
if (process.version.startsWith('v10')) {
|
||||||
|
expect(consola.warn).toHaveBeenCalledTimes(2)
|
||||||
|
} else {
|
||||||
|
expect(consola.warn).toHaveBeenCalledTimes(1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user