diff --git a/README.md b/README.md index 04ecc80..f542f6c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/main/js/goods.mjs b/src/main/js/goods.mjs index 7443893..a30b887 100644 --- a/src/main/js/goods.mjs +++ b/src/main/js/goods.mjs @@ -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' diff --git a/src/main/js/index.mjs b/src/main/js/index.mjs index cc7b7a9..dc92262 100644 --- a/src/main/js/index.mjs +++ b/src/main/js/index.mjs @@ -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' diff --git a/src/main/js/semver.mjs b/src/main/js/reexport.mjs similarity index 68% rename from src/main/js/semver.mjs rename to src/main/js/reexport.mjs index 1f4f12f..ee720c9 100644 --- a/src/main/js/semver.mjs +++ b/src/main/js/reexport.mjs @@ -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') diff --git a/src/test/js/test.mjs b/src/test/js/test.mjs index 1c3de93..e2dd67a 100644 --- a/src/test/js/test.mjs +++ b/src/test/js/test.mjs @@ -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 { @@ -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})