How to use the package-json.VersionNotFoundError function in package-json

To help you get started, we’ve selected a few package-json examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terascope / teraslice / packages / scripts / src / helpers / packages.ts View on Github external
export async function getRemotePackageVersion(pkgInfo: i.PackageInfo): Promise {
    if (pkgInfo.private) return pkgInfo.version;

    const registryUrl: string|undefined = get(pkgInfo, 'publishConfig.registry');
    const tag = getPublishTag(pkgInfo.version);

    try {
        const { version } = await packageJson(pkgInfo.name, {
            version: tag,
            registryUrl
        });
        return version as string;
    } catch (err) {
        if (err instanceof packageJson.VersionNotFoundError) {
            return pkgInfo.version;
        }
        if (err instanceof packageJson.PackageNotFoundError) {
            return '0.1.0';
        }
        throw err;
    }
}

package-json

Get metadata of a package from the npm registry

MIT
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis