chore: fix dev version

fixes components version check during nuxt development
This commit is contained in:
pooya parsa 2020-06-24 10:23:29 +02:00
parent e1de5e8667
commit 12d6702eba
3 changed files with 3 additions and 43 deletions

View File

@ -56,7 +56,7 @@ export default class Nuxt extends Hookable {
}
static get version () {
return (global.__NUXT && global.__NUXT.version) || `v${version}`
return `v${version}` + (global.__NUXT_DEV__ ? '-development' : '')
}
ready () {

View File

@ -80,16 +80,6 @@ describe('core: nuxt', () => {
expect(Nuxt.version).toEqual(`v${version}`)
})
test('should return nuxt version from global.__NUXT', () => {
global.__NUXT = {
version: 'latest'
}
expect(Nuxt.version).toEqual('latest')
delete global.__NUXT
})
test('should call module/server ready in nuxt.ready', async () => {
const nuxt = new Nuxt()

View File

@ -12,38 +12,8 @@ const useCjs = [
const stub = {
es: 'export * from \'../src/index\'',
cjs: `const _require = typeof jest === 'undefined' ? require('esm')(module) : require
const execa = require('execa')
global.__NUXT = {}
Object.defineProperty(global.__NUXT, 'version', {
enumerable: true,
get() {
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 ? \` (\${status.ab})\` : '')
} catch (err) {
return 'source'
}
}
})
module.exports = _require('../src/index')
global.__NUXT_DEV__ = true
module.exports = _require('../src/index')
`
}