File tree Expand file tree Collapse file tree 5 files changed +14
-16
lines changed Expand file tree Collapse file tree 5 files changed +14
-16
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,10 @@ import {
24
24
minimist ,
25
25
fs ,
26
26
path ,
27
+ VERSION ,
27
28
} from './index.js'
28
29
import { installDeps , parseDeps } from './deps.js'
29
- import { randomId , getVersion } from './util.js'
30
+ import { randomId } from './util.js'
30
31
import { createRequire } from './vendor.js'
31
32
32
33
const EXT = '.mjs'
@@ -44,7 +45,7 @@ isMain() &&
44
45
export function printUsage ( ) {
45
46
// language=txt
46
47
console . log ( `
47
- ${ chalk . bold ( 'zx ' + getVersion ( ) ) }
48
+ ${ chalk . bold ( 'zx ' + VERSION ) }
48
49
A tool for writing better scripts
49
50
50
51
${ chalk . bold ( 'Usage' ) }
@@ -95,7 +96,7 @@ export async function main() {
95
96
if ( argv . prefix ) $ . prefix = argv . prefix
96
97
if ( argv . postfix ) $ . postfix = argv . postfix
97
98
if ( argv . version ) {
98
- console . log ( getVersion ( ) )
99
+ console . log ( VERSION )
99
100
return
100
101
}
101
102
if ( argv . help ) {
Original file line number Diff line number Diff line change 13
13
// limitations under the License.
14
14
15
15
import { ProcessPromise } from './core.js'
16
+ import { fs } from './vendor.js'
16
17
17
18
export * from './core.js'
18
19
export * from './goods.js'
@@ -27,9 +28,13 @@ export {
27
28
glob as globby ,
28
29
} from './vendor.js'
29
30
31
+ export const VERSION = fs . readJsonSync (
32
+ new URL ( '../package.json' , import . meta. url )
33
+ ) . version
34
+ export const version = VERSION
35
+
30
36
export {
31
37
type Duration ,
32
- getVersion ,
33
38
quote ,
34
39
quotePowerShell ,
35
40
tempdir ,
Original file line number Diff line number Diff line change 15
15
import os from 'node:os'
16
16
import path from 'node:path'
17
17
import fs from 'node:fs'
18
- import { createRequire } from './vendor.js'
19
18
import { chalk } from './vendor-core.js'
20
19
21
20
export { isStringLiteral } from './vendor-core.js'
@@ -464,10 +463,6 @@ export const proxyOverride = <T extends object>(
464
463
} ,
465
464
} ) as T
466
465
467
- export function getVersion ( ) : string {
468
- return createRequire ( import . meta. url ) ( '../package.json' ) . version
469
- }
470
-
471
466
// https://stackoverflow.com/a/7888303
472
467
export const camelToSnake = ( str : string ) =>
473
468
str
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ import { describe, test } from 'node:test'
17
17
import {
18
18
nothrow ,
19
19
quiet ,
20
+ version ,
21
+ VERSION ,
20
22
$ ,
21
23
log ,
22
24
cd ,
@@ -62,6 +64,8 @@ describe('index', () => {
62
64
// index
63
65
assert ( nothrow )
64
66
assert ( quiet )
67
+ assert ( version )
68
+ assert . equal ( version , VERSION )
65
69
66
70
// core
67
71
assert ( $ )
Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ import {
28
28
randomId ,
29
29
// normalizeMultilinePieces,
30
30
getCallerLocationFromString ,
31
- getVersion ,
32
31
tempdir ,
33
32
tempfile ,
34
33
preferLocalBin ,
@@ -195,12 +194,6 @@ test('preferLocalBin()', () => {
195
194
)
196
195
} )
197
196
198
- test ( 'getVersion return version from package.json' , ( ) => {
199
- const packageJsonContent = fs . readFileSync ( './package.json' , 'utf8' )
200
- const packageInfo = JSON . parse ( packageJsonContent )
201
-
202
- assert . equal ( getVersion ( ) , packageInfo . version )
203
-
204
197
test ( 'camelToSnake()' , ( ) => {
205
198
assert . equal ( camelToSnake ( 'verbose' ) , 'VERBOSE' )
206
199
assert . equal ( camelToSnake ( 'nothrow' ) , 'NOTHROW' )
You can’t perform that action at this time.
0 commit comments