@ranger1/dx 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/dx.js +34 -0
  2. package/package.json +1 -1
package/bin/dx.js CHANGED
@@ -31,6 +31,33 @@ function stripConfigDirArgs(argv) {
31
31
  return out
32
32
  }
33
33
 
34
+ function isVersionInvocation(argv) {
35
+ const raw = Array.isArray(argv) ? argv : []
36
+ const filtered = stripConfigDirArgs(raw)
37
+
38
+ const flags = []
39
+ const positionals = []
40
+ for (const token of filtered) {
41
+ if (token === '--') break
42
+ if (token.startsWith('-')) flags.push(token)
43
+ else positionals.push(token)
44
+ }
45
+
46
+ // Keep current semantics:
47
+ // - -V/--version always prints version and exits.
48
+ // - -v is verbose in commands, but `dx -v` is commonly expected to show version.
49
+ const hasCanonicalVersionFlag = flags.includes('-V') || flags.includes('--version')
50
+ if (hasCanonicalVersionFlag) return true
51
+
52
+ const isBareLowerV = flags.length === 1 && flags[0] === '-v' && positionals.length === 0
53
+ if (isBareLowerV) return true
54
+
55
+ const isVersionCommand = positionals.length === 1 && positionals[0] === 'version'
56
+ if (isVersionCommand) return true
57
+
58
+ return false
59
+ }
60
+
34
61
  function findProjectRootFrom(startDir) {
35
62
  let current = resolve(startDir)
36
63
  while (true) {
@@ -67,6 +94,13 @@ function inferProjectRootFromConfigDir(configDir, startDir) {
67
94
 
68
95
  async function main() {
69
96
  const rawArgs = process.argv.slice(2)
97
+
98
+ if (isVersionInvocation(rawArgs)) {
99
+ const { getPackageVersion } = await import('../lib/version.js')
100
+ console.log(getPackageVersion())
101
+ return
102
+ }
103
+
70
104
  const overrideConfigDir = parseConfigDir(rawArgs)
71
105
  const filteredArgs = stripConfigDirArgs(rawArgs)
72
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {