chore: don't show stable version number when running from git/source (#4756)

This commit is contained in:
Pim 2019-01-16 18:53:14 +01:00 committed by Pooya Parsa
parent 9c9d519576
commit 0c64410c6d
4 changed files with 39 additions and 6 deletions

View File

@ -90,7 +90,7 @@ export function showBanner(nuxt) {
const lines = [] const lines = []
// Name and version // Name and version
lines.push(`${chalk.green.bold('Nuxt.js')} v${nuxt.constructor.version}`) lines.push(`${chalk.green.bold('Nuxt.js')} ${nuxt.constructor.version}`)
// Running mode // Running mode
lines.push(`Running in ${nuxt.options.dev ? chalk.bold.blue('development') : chalk.bold.green('production')} mode (${chalk.bold(nuxt.options.mode)})`) lines.push(`Running in ${nuxt.options.dev ? chalk.bold.blue('development') : chalk.bold.green('production')} mode (${chalk.bold(nuxt.options.mode)})`)

View File

@ -45,7 +45,7 @@ export default class Nuxt extends Hookable {
} }
static get version() { static get version() {
return version return (global.__NUXT && global.__NUXT.version) || `v${version}`
} }
async ready() { async ready() {

View File

@ -5,9 +5,9 @@ import consola from 'consola'
import Package from './package.js' import Package from './package.js'
const useCjs = new Set([ const useCjs = [
'@nuxt/cli' '@nuxt/cli'
]) ]
const stub = { const stub = {
es: `export * from '../src/index'`, es: `export * from '../src/index'`,
@ -22,6 +22,37 @@ const _require = esm(module, {
} }
}) })
const execa = require('execa')
global.__NUXT = new Proxy({}, {
get(target, propertyKey, receiver) {
if (propertyKey === 'version') {
try {
const { stdout } = execa.sync('git', ['status', '-s', '-b', '--porcelain=2'])
const status = { dirty: false }
for (const line of stdout.split('\\n')) {
if (line[0] === '#') {
const match = line.match(/branch\.([^\\s]+) (.*)\$/)
if (match && match.length) {
status[match[1]] = match[2]
}
} else {
status.dirty = true
break
}
}
return \`git<\${status.head}\${status.dirty ? '~' : '-'}\${(status.oid && status.oid.substr(0, 7)) || ''}> (\${status.ab})\`
} catch (err) {
return 'source'
}
}
return target[propertyKey]
}
})
module.exports = _require('../src/index') module.exports = _require('../src/index')
` } ` }
@ -38,7 +69,7 @@ async function main() {
consola.info(pkg.pkg.main) consola.info(pkg.pkg.main)
const distMain = pkg.resolvePath(pkg.pkg.main) const distMain = pkg.resolvePath(pkg.pkg.main)
await fs.mkdirp(path.dirname(distMain)) await fs.mkdirp(path.dirname(distMain))
await fs.writeFile(distMain, useCjs.has(pkg.pkg.name) ? stub.cjs : stub.es) await fs.writeFile(distMain, useCjs.includes(pkg.pkg.name) ? stub.cjs : stub.es)
} }
} }

View File

@ -2,14 +2,16 @@
import path from 'path' import path from 'path'
import fs from 'fs' import fs from 'fs'
import { defaultsDeep } from 'lodash' import { defaultsDeep } from 'lodash'
import { version as coreVersion } from '../../packages/core/package.json'
export { version } from '../../packages/core/package.json'
export { Nuxt } from '../../packages/core/src/index' export { Nuxt } from '../../packages/core/src/index'
export { Builder } from '../../packages/builder/src/index' export { Builder } from '../../packages/builder/src/index'
export { Generator } from '../../packages/generator/src/index' export { Generator } from '../../packages/generator/src/index'
export { BundleBuilder } from '../../packages/webpack/src/index' export { BundleBuilder } from '../../packages/webpack/src/index'
export * from '../../packages/utils/src/index' export * from '../../packages/utils/src/index'
export const version = `v${coreVersion}`
export const loadFixture = async function (fixture, overrides) { export const loadFixture = async function (fixture, overrides) {
const rootDir = path.resolve(__dirname, '..', 'fixtures', fixture) const rootDir = path.resolve(__dirname, '..', 'fixtures', fixture)
const configFile = path.resolve(rootDir, `nuxt.config${process.env.NUXT_TS === 'true' ? '.ts' : '.js'}`) const configFile = path.resolve(rootDir, `nuxt.config${process.env.NUXT_TS === 'true' ? '.ts' : '.js'}`)