Skip to content

Commit

Permalink
feat: add semver
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 2, 2022
1 parent 71ef024 commit 37b8913
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ yarn add zx-extra
```

## Usage
Inherits zx, so all origin methods are available.

## Extras

### `semver`
Semantic versioning api from [node-semver](https://github.com/npm/node-semver)
```js
import {semver} from 'zx-extra'

semver.gte('1.0.1', '1.0.0')
```

### `$.raw`
Evaluates target cmd as is without `shq`.
Expand Down
11 changes: 11 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"homepage": "https://github.com/qiwi/zx-extra#readme",
"dependencies": {
"@types/node": "^17.0.38",
"zx": "^6.2.0"
"zx": "^6.2.0",
"@types/semver": "^7.3.9"
}
}
3 changes: 3 additions & 0 deletions src/main/js/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import * as semver from 'semver'

export * from 'zx'
export { semver }

interface $ {
raw: $
Expand Down
1 change: 1 addition & 0 deletions src/main/js/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {$, quiet} from 'zx'

export { semver } from './semver.mjs'
export * from 'zx'

$.raw = async (...args) => {
Expand Down
10 changes: 10 additions & 0 deletions src/main/js/semver.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createRequire } from 'node:module'
import { execSync } from 'node:child_process'
import { join } from 'node:path'
const require = createRequire(import.meta.url)

export const semver = require(join(
execSync('npm list -g --depth=0 --parseable npm', {shell: true}).toString().trim(),
'node_modules',
'semver'
))
7 changes: 6 additions & 1 deletion src/test/js/test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {$} from '../../main/js/index.mjs'
import {$, semver} from '../../main/js/index.mjs'

import {strict as assert} from 'node:assert'

Expand All @@ -25,3 +25,8 @@ import {strict as assert} from 'node:assert'
assert(typeof argv === 'object')
console.log(argv)
}

{
assert(semver.gte('1.0.1', '1.0.0'))
assert(!semver.lt('1.0.0', '1.0.0'))
}

0 comments on commit 37b8913

Please sign in to comment.