diff --git a/package.json b/package.json index 86aca531..ff44bcdb 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ } }, "dependencies": { - "@package-json/types": "^0.0.12", "@typescript-eslint/types": "^8.56.0", "comment-parser": "^1.4.1", "debug": "^4.4.1", diff --git a/src/rules/no-duplicates.ts b/src/rules/no-duplicates.ts index 473eb477..d8abbb38 100644 --- a/src/rules/no-duplicates.ts +++ b/src/rules/no-duplicates.ts @@ -1,9 +1,8 @@ -import type { PackageJson } from '@package-json/types' import type { TSESLint, TSESTree } from '@typescript-eslint/utils' import * as semver from 'semver' import { cjsRequire } from '../require.js' -import type { RuleContext } from '../types.js' +import type { PackageJson, RuleContext } from '../types.js' import { createRule, lazy, resolve } from '../utils/index.js' // a user might set prefer-inline but not have a supporting TypeScript version. Flow does not support inline types so this should fail in that case as well. diff --git a/src/rules/no-extraneous-dependencies.ts b/src/rules/no-extraneous-dependencies.ts index 87370ed8..269bba47 100644 --- a/src/rules/no-extraneous-dependencies.ts +++ b/src/rules/no-extraneous-dependencies.ts @@ -1,11 +1,10 @@ import fs from 'node:fs' import path from 'node:path' -import type { PackageJson } from '@package-json/types' import type { TSESTree } from '@typescript-eslint/utils' import { minimatch } from 'minimatch' -import type { RuleContext } from '../types.js' +import type { PackageJson, RuleContext } from '../types.js' import { createRule, moduleVisitor, @@ -46,8 +45,7 @@ function extractDepFields(pkg: PackageJson) { devDependencies: pkg.devDependencies || {}, optionalDependencies: pkg.optionalDependencies || {}, peerDependencies: pkg.peerDependencies || {}, - // BundledDeps should be in the form of an array, but object notation is also supported by - // `npm`, so we convert it to an array if it is an object + // bundleDependencies is an array per npm spec; this rule also accepts an object form for backward compatibility, which is not part of the npm spec bundledDependencies: arrayOrKeys( pkg.bundleDependencies || pkg.bundledDependencies || [], ), diff --git a/src/types.ts b/src/types.ts index 51918cec..2b69c45a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -169,3 +169,23 @@ export interface NormalizedCacheSettings extends NonNullable { lifetime: number } + +/** + * Minimal subset of package.json fields used by this plugin. + * Defined inline to avoid a runtime dependency solely for type information. + */ +export interface PackageJson { + name?: string + version?: string + private?: boolean + main?: string + bin?: string | Record + browser?: string | Record + dependencies?: Record + devDependencies?: Record + optionalDependencies?: Record + peerDependencies?: Record + /** Array form per npm spec; object form is non-standard but intentionally supported by this rule */ + bundleDependencies?: string[] | Record + bundledDependencies?: string[] | Record +} diff --git a/src/utils/read-pkg-up.ts b/src/utils/read-pkg-up.ts index 52d5bd68..290966dd 100644 --- a/src/utils/read-pkg-up.ts +++ b/src/utils/read-pkg-up.ts @@ -1,6 +1,6 @@ import fs from 'node:fs' -import type { PackageJson } from '@package-json/types' +import type { PackageJson } from '../types.js' import { pkgUp } from './pkg-up.js' diff --git a/yarn.lock b/yarn.lock index ab290a40..e66f2604 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3224,13 +3224,6 @@ __metadata: languageName: node linkType: hard -"@package-json/types@npm:^0.0.12": - version: 0.0.12 - resolution: "@package-json/types@npm:0.0.12" - checksum: 10c0/d9bba086efe7b9901f02f1cff7a68ab23269aeddfb7ee92a16930e219f705bfc188b9fec2dd47265033dbda45ed1514d8a46f46363f38f1ad56bc993754126da - languageName: node - linkType: hard - "@pkgjs/parseargs@npm:^0.11.0": version: 0.11.0 resolution: "@pkgjs/parseargs@npm:0.11.0" @@ -6073,7 +6066,6 @@ __metadata: "@commitlint/cli": "npm:^19.8.1" "@eslint/import-test-order-redirect-scoped": "link:./test/fixtures/order-redirect-scoped" "@eslint/js": "npm:^9.29.0" - "@package-json/types": "npm:^0.0.12" "@swc-node/jest": "npm:^1.8.13" "@swc/core": "npm:^1.12.7" "@swc/helpers": "npm:^0.5.17"