Skip to content

Commit

Permalink
feat: expose ssri API
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jul 6, 2022
1 parent ea0ec55 commit f12141a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ await copy({
})
```

### `SSRI`
Exposes [SSRI API](https://github.com/npm/ssri#readme)
```js
import {SSRI} from 'zx-extra'

const integrity = 'sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==?foo'
// Parsing and serializing
const parsed = SSRI.parse(integrity)
SSRI.stringify(parsed) // === integrity (works on non-Integrity objects)
parsed.toString() // === integrity
```

### `ctx`
[async_hooks](https://nodejs.org/api/async_hooks.html)-driven scope isolator.
Creates a separate zx-context for the specified function.
Expand Down
2 changes: 1 addition & 1 deletion src/main/js/goods.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * as tempy from 'tempy'
export { default as ip } from 'ip'
export { semver } from './semver.mjs'
export { semver, SSRI } from './reexport.mjs'
export { default as tcping } from 'is-reachable'
export { copy } from 'globby-cp'
2 changes: 1 addition & 1 deletion src/main/js/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {$ as _$, quiet, ProcessPromise, within, argv} from 'zx'
import {$ as _$, quiet, ProcessPromise, within} from 'zx'
import {isTemplateSignature, randomId} from './util.mjs'
import {npmRunPath} from 'npm-run-path'
import {DeepProxy} from '@qiwi/deep-proxy'
Expand Down
7 changes: 5 additions & 2 deletions src/main/js/semver.mjs → src/main/js/reexport.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { execSync } from 'node:child_process'
import { join } from 'node:path'
const require = createRequire(import.meta.url)

export const semver = require(join(
const reexport = (name) => require(join(
execSync('npm list -g --depth=0 --parseable npm', {shell: true}).toString().trim(),
'node_modules',
'semver'
name
))

export const semver = reexport('semver')
export const SSRI = reexport('ssri')
10 changes: 9 additions & 1 deletion src/test/js/test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {strict as assert} from 'node:assert'
import {$, semver, createHook, ip, tempy, tcping, ctx, copy, fs, path} from '../../main/js/index.mjs'
import {$, semver, createHook, ip, tempy, tcping, ctx, copy, fs, path, SSRI} from '../../main/js/index.mjs'

// $.verbose
{
Expand Down Expand Up @@ -36,6 +36,14 @@ import {$, semver, createHook, ip, tempy, tcping, ctx, copy, fs, path} from '../
assert(!semver.lt('1.0.0', '1.0.0'))
}

// SSRI
{
const integrity = 'sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==?foo'
const parsed = SSRI.parse(integrity)
assert.equal(SSRI.stringify(parsed), integrity)
assert.equal(parsed.toString(), integrity)
}

// opt
{
const nothrow = $.opt({nothrow: true})
Expand Down

0 comments on commit f12141a

Please sign in to comment.