From 92803b23d99857af512dd7d0170d1258eb73b626 Mon Sep 17 00:00:00 2001 From: Pim Date: Mon, 4 Feb 2019 22:20:09 +0100 Subject: [PATCH] fix: improve nuxt version number when running from git (#4946) --- package.json | 2 +- scripts/{dev => dev.js} | 41 ++++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 22 deletions(-) rename scripts/{dev => dev.js} (59%) diff --git a/package.json b/package.json index 64092399ab..7fd389469c 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "clean:build": "rimraf distributions/*/dist packages/*/dist", "clean:examples": "rimraf examples/*/dist examples/*/.nuxt", "clean:test": "rimraf test/fixtures/*/dist test/fixtures/*/.nuxt*", - "dev": "node -r esm ./scripts/dev", + "dev": "node -r esm ./scripts/dev.js", "coverage": "codecov", "lint": "eslint --ext .js,.mjs,.vue .", "lint:app": "eslint-multiplexer eslint --ignore-path packages/vue-app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b", diff --git a/scripts/dev b/scripts/dev.js similarity index 59% rename from scripts/dev rename to scripts/dev.js index 2e70b3c6ab..387fe414e6 100755 --- a/scripts/dev +++ b/scripts/dev.js @@ -24,32 +24,31 @@ 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']) +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 + 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] + return \`git<\${status.head}\${status.dirty ? '~' : '-'}\${(status.oid && status.oid.substr(0, 7)) || ''}>\` + + (status.ab ? \` (\${status.ab})\` : '') + } catch (err) { + return 'source' + } } })