diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-19 05:33:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-19 05:33:17 +0800 |
commit | 8c83f4ba3b72660c1a7a0b0829e8800a2a8687fe (patch) | |
tree | c73dc3abd7e94510b8f2d6476cff53e021746a4f /packages/monorepo-scripts/src/utils/npm_utils.ts | |
parent | 3f02631b98368503718a1c1977e7f83220c284a2 (diff) | |
parent | 25b6d1a232835b76decbb1c66878da1285afe404 (diff) | |
download | dexon-sol-tools-8c83f4ba3b72660c1a7a0b0829e8800a2a8687fe.tar.gz dexon-sol-tools-8c83f4ba3b72660c1a7a0b0829e8800a2a8687fe.tar.zst dexon-sol-tools-8c83f4ba3b72660c1a7a0b0829e8800a2a8687fe.zip |
Merge pull request #722 from 0xProject/improvement/publishing-v2
Improvements to pre-publishing checks
Diffstat (limited to 'packages/monorepo-scripts/src/utils/npm_utils.ts')
-rw-r--r-- | packages/monorepo-scripts/src/utils/npm_utils.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/monorepo-scripts/src/utils/npm_utils.ts b/packages/monorepo-scripts/src/utils/npm_utils.ts new file mode 100644 index 000000000..cc1e046e7 --- /dev/null +++ b/packages/monorepo-scripts/src/utils/npm_utils.ts @@ -0,0 +1,28 @@ +import 'isomorphic-fetch'; +import * as _ from 'lodash'; + +import { PackageRegistryJson } from '../types'; + +const NPM_REGISTRY_BASE_URL = 'https://registry.npmjs.org'; +const SUCCESS_STATUS = 200; +const NOT_FOUND_STATUS = 404; + +export const npmUtils = { + async getPackageRegistryJsonIfExistsAsync(packageName: string): Promise<PackageRegistryJson | undefined> { + const url = `${NPM_REGISTRY_BASE_URL}/${packageName}`; + const response = await fetch(url); + + if (response.status === NOT_FOUND_STATUS) { + return undefined; + } else if (response.status !== SUCCESS_STATUS) { + throw new Error(`Request to ${url} failed. Check your internet connection and that npmjs.org is up.`); + } + const packageRegistryJson = await response.json(); + return packageRegistryJson; + }, + getPreviouslyPublishedVersions(packageRegistryJson: PackageRegistryJson): string[] { + const timeWithOnlyVersions = _.omit(packageRegistryJson.time, ['modified', 'created']); + const versions = _.keys(timeWithOnlyVersions); + return versions; + }, +}; |