File tree 3 files changed +13
-6
lines changed
3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ 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
30
import { randomId } from './util.js'
@@ -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 ) {
@@ -294,10 +295,6 @@ export function transformMarkdown(buf: Buffer): string {
294
295
return output . join ( '\n' )
295
296
}
296
297
297
- export function getVersion ( ) : string {
298
- return createRequire ( import . meta. url ) ( '../package.json' ) . version
299
- }
300
-
301
298
export function isMain (
302
299
metaurl : string = import . meta. url ,
303
300
scriptpath : string = process . argv [ 1 ]
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,6 +28,11 @@ 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
38
quote ,
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 ( $ )
You can’t perform that action at this time.
0 commit comments