Socket
Socket
Sign inDemoInstall

package-json

Package Overview
Dependencies
29
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.0 to 8.0.0

296

index.d.ts

@@ -1,5 +0,9 @@

import {Agent as HttpAgent} from 'http';
import {Agent as HttpsAgent} from 'https';
import {Agent as HttpAgent} from 'node:http';
import {Agent as HttpsAgent} from 'node:https';
import {Agents} from 'got';
declare class VersionNotFoundErrorClass extends Error {
/**
The error thrown when the given package version cannot be found.
*/
export class VersionNotFoundError extends Error {
readonly name: 'VersionNotFoundError';

@@ -10,3 +14,6 @@

declare class PackageNotFoundErrorClass extends Error {
/**
The error thrown when the given package name cannot be found.
*/
export class PackageNotFoundError extends Error {
readonly name: 'PackageNotFoundError';

@@ -17,178 +24,151 @@

declare namespace packageJson {
interface Agents {
http?: HttpAgent;
https?: HttpsAgent;
}
export type Options = {
/**
Package version such as `1.0.0` or a [dist tag](https://docs.npmjs.com/cli/dist-tag) such as `latest`.
interface Options {
/**
Package version such as `1.0.0` or a [dist tag](https://docs.npmjs.com/cli/dist-tag) such as `latest`.
The version can also be in any format supported by the [semver](https://github.com/npm/node-semver) module. For example:
- `1` - Get the latest `1.x.x`
- `1.2` - Get the latest `1.2.x`
- `^1.2.3` - Get the latest `1.x.x` but at least `1.2.3`
- `~1.2.3` - Get the latest `1.2.x` but at least `1.2.3`
The version can also be in any format supported by the [semver](https://github.com/npm/node-semver) module. For example:
- `1` - Get the latest `1.x.x`
- `1.2` - Get the latest `1.2.x`
- `^1.2.3` - Get the latest `1.x.x` but at least `1.2.3`
- `~1.2.3` - Get the latest `1.2.x` but at least `1.2.3`
@default 'latest'
*/
readonly version?: string;
@default 'latest'
*/
readonly version?: string;
/**
By default, only an abbreviated metadata object is returned for performance reasons. [Read more.](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md)
/**
By default, only an abbreviated metadata object is returned for performance reasons. [Read more.](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md)
@default false
*/
readonly fullMetadata?: boolean;
@default false
*/
readonly fullMetadata?: boolean;
/**
Return the [main entry](https://registry.npmjs.org/ava) containing all versions.
/**
Return the [main entry](https://registry.npmjs.org/ava) containing all versions.
@default false
*/
readonly allVersions?: boolean;
@default false
*/
readonly allVersions?: boolean;
/**
The registry URL is by default inferred from the npm defaults and `.npmrc`. This is beneficial as `package-json` and any project using it will work just like npm. This option is*only** intended for internal tools. You should __not__ use this option in reusable packages. Prefer just using `.npmrc` whenever possible.
*/
readonly registryUrl?: string;
/**
The registry URL is by default inferred from the npm defaults and `.npmrc`. This is beneficial as `package-json` and any project using it will work just like npm. This option is*only** intended for internal tools. You should*not** use this option in reusable packages. Prefer just using `.npmrc` whenever possible.
*/
readonly registryUrl?: string;
/**
Overwrite the `agent` option that is passed down to [`got`](https://github.com/sindresorhus/got#agent). This might be useful to add [proxy support](https://github.com/sindresorhus/got#proxies).
*/
readonly agent?: Agents;
};
/**
Overwrite the `agent` option that is passed down to [`got`](https://github.com/sindresorhus/got#agent). This might be useful to add [proxy support](https://github.com/sindresorhus/got#proxies).
*/
readonly agent?: HttpAgent | HttpsAgent | Agents | false;
}
export type FullMetadataOptions = {
/**
By default, only an abbreviated metadata object is returned for performance reasons. [Read more.](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md)
interface FullMetadataOptions extends Options {
/**
By default, only an abbreviated metadata object is returned for performance reasons. [Read more.](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md)
@default false
*/
readonly fullMetadata: true;
} & Options;
@default false
*/
readonly fullMetadata: true;
}
interface DistTags {
readonly [tagName: string]: string;
readonly latest: string;
}
interface DistTags {
readonly [tagName: string]: string;
readonly latest: string;
}
interface AbbreviatedVersion {
readonly [key: string]: unknown;
readonly name: string;
readonly version: string;
readonly dist: {
readonly shasum: string;
readonly tarball: string;
readonly integrity?: string;
};
readonly deprecated?: string;
readonly dependencies?: Readonly<Record<string, string>>;
readonly optionalDependencies?: Readonly<Record<string, string>>;
readonly devDependencies?: Readonly<Record<string, string>>;
readonly bundleDependencies?: Readonly<Record<string, string>>;
readonly peerDependencies?: Readonly<Record<string, string>>;
readonly bin?: Readonly<Record<string, string>>;
readonly directories?: readonly string[];
readonly engines?: Readonly<Record<string, string>>;
readonly _hasShrinkwrap?: boolean;
}
interface AbbreviatedMetadata {
readonly [key: string]: unknown;
readonly 'dist-tags': DistTags;
readonly modified: string;
readonly name: string;
readonly versions: Readonly<Record<string, AbbreviatedVersion>>;
}
interface Person {
readonly name?: string;
readonly email?: string;
readonly url?: string;
}
interface AbbreviatedVersion {
readonly [key: string]: unknown;
readonly name: string;
readonly version: string;
readonly dist: {
readonly shasum: string;
readonly tarball: string;
readonly integrity?: string;
};
readonly deprecated?: string;
readonly dependencies?: Readonly<Record<string, string>>;
readonly optionalDependencies?: Readonly<Record<string, string>>;
readonly devDependencies?: Readonly<Record<string, string>>;
readonly bundleDependencies?: Readonly<Record<string, string>>;
readonly peerDependencies?: Readonly<Record<string, string>>;
readonly bin?: Readonly<Record<string, string>>;
readonly directories?: readonly string[];
readonly engines?: Readonly<Record<string, string>>;
readonly _hasShrinkwrap?: boolean;
}
interface HoistedData {
readonly author?: Person;
readonly bugs?:
| {readonly url: string; readonly email?: string}
| {readonly url?: string; readonly email: string};
readonly contributors?: readonly Person[];
readonly description?: string;
readonly homepage?: string;
readonly keywords?: readonly string[];
readonly license?: string;
readonly maintainers?: readonly Person[];
readonly readme?: string;
readonly readmeFilename?: string;
readonly repository?: {readonly type: string; readonly url: string};
}
interface Person {
readonly name?: string;
readonly email?: string;
readonly url?: string;
}
interface FullVersion extends AbbreviatedVersion, HoistedData {
readonly [key: string]: unknown;
readonly _id: string;
readonly _nodeVersion: string;
readonly _npmUser: string;
readonly _npmVersion: string;
readonly main?: string;
readonly files?: readonly string[];
readonly man?: readonly string[];
readonly scripts?: Readonly<Record<string, string>>;
readonly gitHead?: string;
readonly types?: string;
readonly typings?: string;
}
interface HoistedData {
readonly author?: Person;
readonly bugs?:
| {readonly url: string; readonly email?: string}
| {readonly url?: string; readonly email: string};
readonly contributors?: readonly Person[];
readonly description?: string;
readonly homepage?: string;
readonly keywords?: readonly string[];
readonly license?: string;
readonly maintainers?: readonly Person[];
readonly readme?: string;
readonly readmeFilename?: string;
readonly repository?: {readonly type: string; readonly url: string};
}
export interface FullMetadata extends AbbreviatedMetadata, HoistedData {
readonly [key: string]: unknown;
readonly _id: string;
readonly _rev: string;
readonly time: {
readonly [version: string]: string;
readonly created: string;
readonly modified: string;
};
readonly users?: Readonly<Record<string, boolean>>;
readonly versions: Readonly<Record<string, FullVersion>>;
}
interface FullMetadata extends AbbreviatedMetadata, HoistedData {
readonly [key: string]: unknown;
readonly _id: string;
readonly _rev: string;
readonly time: {
readonly [version: string]: string;
readonly created: string;
readonly modified: string;
};
readonly users?: Readonly<Record<string, boolean>>;
readonly versions: Readonly<Record<string, FullVersion>>;
}
interface FullVersion extends AbbreviatedVersion, HoistedData {
readonly [key: string]: unknown;
readonly _id: string;
readonly _nodeVersion: string;
readonly _npmUser: string;
readonly _npmVersion: string;
readonly main?: string;
readonly files?: readonly string[];
readonly man?: readonly string[];
readonly scripts?: Readonly<Record<string, string>>;
readonly gitHead?: string;
readonly types?: string;
readonly typings?: string;
}
type VersionNotFoundError = VersionNotFoundErrorClass;
type PackageNotFoundError = PackageNotFoundErrorClass;
export interface AbbreviatedMetadata {
readonly [key: string]: unknown;
readonly 'dist-tags': DistTags;
readonly modified: string;
readonly name: string;
readonly versions: Readonly<Record<string, AbbreviatedVersion>>;
}
declare const packageJson: { // eslint-disable-line no-redeclare
/**
Get metadata of a package from the npm registry.
/**
Get metadata of a package from the npm registry.
@param packageName - Name of the package.
@param packageName - Name of the package.
@example
```
import packageJson = require('package-json');
@example
```
import packageJson from 'package-json';
console.log(await packageJson('ava'));
//=> {name: 'ava', ...}
console.log(await packageJson('ava'));
//=> {name: 'ava', …}
// Also works with scoped packages
console.log(await packageJson('@sindresorhus/df'));
```
*/
(packageName: string, options: packageJson.FullMetadataOptions): Promise<packageJson.FullMetadata>;
(packageName: string, options?: packageJson.Options): Promise<packageJson.AbbreviatedMetadata>;
/**
The error thrown when the given package version cannot be found.
*/
VersionNotFoundError: typeof VersionNotFoundErrorClass;
/**
The error thrown when the given package name cannot be found.
*/
PackageNotFoundError: typeof PackageNotFoundErrorClass;
// TODO: remove this in the next major version
default: typeof packageJson;
};
export = packageJson;
// Also works with scoped packages
console.log(await packageJson('@sindresorhus/df'));
```
*/
export default function packageJson(packageName: string, options: FullMetadataOptions): Promise<FullMetadata>;
export default function packageJson(packageName: string, options?: Options): Promise<AbbreviatedMetadata>;

@@ -1,8 +0,7 @@

'use strict';
const {Agent: HttpAgent} = require('http');
const {Agent: HttpsAgent} = require('https');
const got = require('got');
const registryUrl = require('registry-url');
const registryAuthToken = require('registry-auth-token');
const semver = require('semver');
import {Agent as HttpAgent} from 'node:http';
import {Agent as HttpsAgent} from 'node:https';
import got from 'got';
import registryUrl from 'registry-url';
import registryAuthToken from 'registry-auth-token';
import semver from 'semver';

@@ -13,8 +12,9 @@ // These agent options are chosen to match the npm client defaults and help with performance

keepAlive: true,
maxSockets: 50
maxSockets: 50,
};
const httpAgent = new HttpAgent(agentOptions);
const httpsAgent = new HttpsAgent(agentOptions);
class PackageNotFoundError extends Error {
export class PackageNotFoundError extends Error {
constructor(packageName) {

@@ -26,3 +26,3 @@ super(`Package \`${packageName}\` could not be found`);

class VersionNotFoundError extends Error {
export class VersionNotFoundError extends Error {
constructor(packageName, version) {

@@ -34,6 +34,6 @@ super(`Version \`${version}\` for package \`${packageName}\` could not be found`);

const packageJson = async (packageName, options) => {
export default async function packageJson(packageName, options) {
options = {
version: 'latest',
...options
...options,
};

@@ -47,3 +47,3 @@

const headers = {
accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
};

@@ -63,4 +63,4 @@

http: httpAgent,
https: httpsAgent
}
https: httpsAgent,
},
};

@@ -110,8 +110,2 @@

return data;
};
module.exports = packageJson;
// TODO: remove this in the next major version
module.exports.default = packageJson;
module.exports.PackageNotFoundError = PackageNotFoundError;
module.exports.VersionNotFoundError = VersionNotFoundError;
}
{
"name": "package-json",
"version": "7.0.0",
"version": "8.0.0",
"description": "Get metadata of a package from the npm registry",

@@ -13,4 +13,7 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"types": "./index.d.ts",
"engines": {
"node": ">=12"
"node": ">=14.16"
},

@@ -36,14 +39,14 @@ "scripts": {

"dependencies": {
"got": "^11.8.2",
"registry-auth-token": "^4.0.0",
"registry-url": "^5.0.0",
"semver": "^7.3.5"
"got": "^12.1.0",
"registry-auth-token": "^4.2.1",
"registry-url": "^6.0.0",
"semver": "^7.3.7"
},
"devDependencies": {
"@types/node": "^15.12.4",
"ava": "^2.4.0",
"@types/node": "^17.0.40",
"ava": "^4.3.0",
"mock-private-registry": "^1.1.2",
"tsd": "^0.17.0",
"xo": "^0.39.0"
"tsd": "^0.20.0",
"xo": "^0.49.0"
}
}

@@ -7,5 +7,5 @@ # package-json

```sh
npm install package-json
```
$ npm install package-json
```

@@ -15,11 +15,9 @@ ## Usage

```js
const packageJson = require('package-json');
import packageJson from 'package-json';
(async () => {
console.log(await packageJson('ava'));
//=> {name: 'ava', ...}
console.log(await packageJson('ava'));
//=> {name: 'ava', …}
// Also works with scoped packages
console.log(await packageJson('@sindresorhus/df'));
})();
// Also works with scoped packages
console.log(await packageJson('@sindresorhus/df'));
```

@@ -78,11 +76,11 @@

Type: `http.Agent | https.Agent | object | false`
Type: `object`
Overwrite the `agent` option that is passed down to [`got`](https://github.com/sindresorhus/got#agent). This might be useful to add [proxy support](https://github.com/sindresorhus/got#proxies).
### packageJson.PackageNotFoundError
### PackageNotFoundError
The error thrown when the given package name cannot be found.
### packageJson.VersionNotFoundError
### VersionNotFoundError

@@ -89,0 +87,0 @@ The error thrown when the given package version cannot be found.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc