Skip to content
Open
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
37 changes: 37 additions & 0 deletions test/package-json-fields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import t from 'tap'
import type { PackageJSON } from '../types/index.d.ts'

t.test('PackageJSON includes modern package metadata fields', (t) => {
const pkg: PackageJSON = {
name: 'modern-package-fields',
version: '1.0.0',
type: 'module',
exports: {
'.': {
import: './dist/index.mjs',
require: './dist/index.cjs',
default: './dist/index.mjs',
},
'./feature': './dist/feature.mjs',
'./legacy': null,
},
imports: {
'#internal': {
node: './src/internal-node.js',
default: './src/internal.js',
},
},
maintainers: [
{
name: 'npm maintainer',
email: 'maintainer@example.com',
},
],
}

t.equal(pkg.type, 'module')
t.match(pkg.exports, { './feature': './dist/feature.mjs' })
t.match(pkg.imports, { '#internal': { default: './src/internal.js' } })
t.match(pkg.maintainers, [{ name: 'npm maintainer' }])
t.end()
})
10 changes: 10 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ interface Funding {
url: string
}

type PackageJSONExports =
| string
| string[]
| Record<string, string | string[] | PackageJSONExports>
| null

// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides
interface Overrides {
[moduleName: string]: string | Overrides
Expand Down Expand Up @@ -125,6 +131,7 @@ export interface PackageJSON {
licenses?: DeprecatedLicense | DeprecatedLicense[]
main?: string
man?: string | string[]
maintainers?: Contact[]
name: string
optionalDependencies?: Record<string, string>
os?: string[]
Expand All @@ -137,6 +144,9 @@ export interface PackageJSON {
scripts?: Record<string, string>
// https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html#editing-the-packagejson
types?: string
type?: 'commonjs' | 'module'
exports?: PackageJSONExports
imports?: Record<string, PackageJSONExports>
version: string
workspaces?: string[] | Record<string, string>

Expand Down