Skip to content

Commit

Permalink
feat: auto fallback to legacy build for node@6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Jun 1, 2018
1 parent 35ee689 commit 412ffd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 1 addition & 10 deletions bin/nuxt
@@ -1,8 +1,7 @@
#!/usr/bin/env node
const { join } = require('path')
const semver = require('semver')

const consola = require('consola')
const { name, engines } = require('../package.json')

// Global error handler
process.on('unhandledRejection', _error => {
Expand All @@ -19,14 +18,6 @@ consola.add({
}
})

if (!semver.satisfies(process.version, engines.node)) {
consola.fatal(
`The engine "node" is incompatible with ${name}. Expected version "${
engines.node
}".`
)
}

const defaultCommand = 'dev'
const commands = new Set([defaultCommand, 'init', 'build', 'start', 'generate'])

Expand Down
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -7,9 +7,17 @@

const fs = require('fs')
const path = require('path')
const semver = require('semver')

if (fs.existsSync(path.resolve(__dirname, '.babelrc'))) {
const { engines } = require('./package.json')

if (!semver.satisfies(process.version, engines.node)) {
// Auto fallback to legacy build on older node versions
module.exports = require('./dist/nuxt-legacy.js')
} else if (fs.existsSync(path.resolve(__dirname, '.babelrc'))) {
// Use esm version when using linked repository to prevent builds
module.exports = require('./lib/index.js')
} else {
// Use production bundle by default
module.exports = require('./dist/nuxt.js')
}
4 changes: 4 additions & 0 deletions lib/nuxt-legacy.js
@@ -1,7 +1,11 @@
import 'babel-polyfill'

import consola from 'consola'

import core from './core'
import builder from './builder'
import * as Utils from './common/utils'

consola.warn('You are using legacy build of Nuxt. Please consider upgrading your Node.js version to 8.x or later.')

export default Object.assign({ Utils }, core, builder)

1 comment on commit 412ffd4

@webcore-it
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES! Thanks a lot for adding this version check (and the legacy version). Will test the use of Nuxt 2 on Google Firebase Functions which only supports node v6.14.0

Please sign in to comment.