From 775c16a9101331b2ef1cd39aea98f3e3a09e75ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E4=BA=8E=E6=99=8F?= <3146347095@qq.com> Date: Mon, 29 Jun 2026 12:33:38 +0800 Subject: [PATCH] feat: add modern package json fields --- test/package-json-fields.ts | 37 +++++++++++++++++++++++++++++++++++++ types/index.d.ts | 10 ++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/package-json-fields.ts diff --git a/test/package-json-fields.ts b/test/package-json-fields.ts new file mode 100644 index 0000000..26a5342 --- /dev/null +++ b/test/package-json-fields.ts @@ -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() +}) diff --git a/types/index.d.ts b/types/index.d.ts index ac4432d..9afd1fa 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -23,6 +23,12 @@ interface Funding { url: string } +type PackageJSONExports = + | string + | string[] + | Record + | null + // https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides interface Overrides { [moduleName: string]: string | Overrides @@ -125,6 +131,7 @@ export interface PackageJSON { licenses?: DeprecatedLicense | DeprecatedLicense[] main?: string man?: string | string[] + maintainers?: Contact[] name: string optionalDependencies?: Record os?: string[] @@ -137,6 +144,9 @@ export interface PackageJSON { scripts?: Record // https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html#editing-the-packagejson types?: string + type?: 'commonjs' | 'module' + exports?: PackageJSONExports + imports?: Record version: string workspaces?: string[] | Record