Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: extract common declarations #16

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 50 additions & 40 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface PackageJson {
* these help npm searches find your project
*/
keywords?: string[];
homepage?: string;
bugs?: {url: string};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

homepage and bugs were only declared on the top-level of Packument before. Now they're declared on PackageJson and Packument uses Pick<PackumentVersion, "homepage" | "bugs">.

/**
* "name <email> (website)" string or Maintainer object
*/
Expand All @@ -23,6 +25,7 @@ export interface PackageJson {
peerDependencies?: Dependencies;
bundleDependencies?: Dependencies;
bundledDependencies?: Dependencies;
optionalDependencies?: ObjectOfStrings;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optionalDependencies was only declared on ManifestVersion before. Now it's declared on PackageJson and ManifestVersion uses Pick<PackumentVersion, "optionalDependencies">.

engines?: ObjectOfStrings;
files?: string[];
bin?: {[key: string]: string};
Expand All @@ -40,27 +43,34 @@ export interface PackageJson {
* npm config values for publish time. like setting an alternate registry
*/
publishConfig?:ObjectOfStrings;
[field: string]: unknown;
}

// this is what you get from the npm api.
export interface Packument {
name: string;
readme?: string;
description?: string;
export type Packument = {
_id: string;
_rev: string;
'dist-tags': {latest?: string}&ObjectOfStrings;
versions: {[key: string]: PackumentVersion};
maintainers: Maintainer[];
time: {modified: string, created: string, [key: string]: string};
homepage?: string;
keywords?: string[];
repository?: Repository;
author?: Maintainer;
bugs?: {url: string};
license: string;
// left out users (stars) deprecated, and attachments (does nothing)
readmeFilename?: string;
}

// The following fields are hoisted to the top-level of the packument from the latest version published.
} & Pick<
PackumentVersion,
| 'author'
| 'bugs'
| 'contributors'
| 'description'
| 'homepage'
| 'keywords'
| 'license'
| 'maintainers'
| 'name'
| 'readme'
| 'readmeFilename'
| 'repository'
>;

// https://docs.npmjs.com/files/package-lock.json
export interface PackageLock {
name: string;
Expand Down Expand Up @@ -92,14 +102,16 @@ export interface PackumentVersion extends PackageJson {
/**
* packagename@versionstring
*/
id: string;
npmVersion: string;
nodeVersion: string;
npmUser: Maintainer;
_id: string;
_npmVersion: string;
_nodeVersion: string;
_npmUser: Maintainer;
maintainers: Maintainer[];
dist: Dist;
readme?: string;
readmeFilename?: string;
Copy link
Contributor Author

@jablko jablko May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readme and readmeFilename were only declared on the top-level of Packument before. Now they're declared on PackumentVersion and Packument uses Pick<PackumentVersion, "homepage" | "bugs">.

_hasShrinkwrap?: boolean;
types?: string;
deprecated?: string;
}

/**
Expand All @@ -109,29 +121,27 @@ export interface PackumentVersion extends PackageJson {
* returned from registry requests with accept header values conianing
* `application/vnd.npm.install-v1+json`
*/
export interface Manifest{
name:string;
export type Manifest = {
modified:string;
'dist-tags':ObjectOfStrings;
versions:{[version:string]:ManifestVersion}
}

export interface ManifestVersion{
name:string;
version:string;
dependencies?:ObjectOfStrings;
optionalDependencies?:ObjectOfStrings;
devDependencies?:ObjectOfStrings;
bundleDependencies?:ObjectOfStrings;
bundledDependencies?:ObjectOfStrings;
peerDependencies?:ObjectOfStrings;
bin?:ObjectOfStrings;
_hasShrinkwrap?:boolean;
directories?:Directories;
dist:Dist;
engines:ObjectOfStrings;
deprecated?:string;
}
} & Pick<Packument, 'name' | 'dist-tags'>;

export type ManifestVersion = Pick<
PackumentVersion,
| 'name'
| 'version'
| 'bin'
| 'directories'
| 'dependencies'
| 'devDependencies'
| 'peerDependencies'
| 'bundledDependencies'
| 'optionalDependencies'
| 'engines'
| 'dist'
| '_hasShrinkwrap'
| 'deprecated'
>;

/**
* Dists are properties of Packument.versions
Expand Down
Loading