@pnpm/deps.inspection.outdated 1001.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2026 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @pnpm/outdated
2
+
3
+ > Check for outdated packages
4
+
5
+ <!--@shields('npm')-->
6
+ [![npm version](https://img.shields.io/npm/v/@pnpm/outdated.svg)](https://www.npmjs.com/package/@pnpm/outdated)
7
+ <!--/@-->
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ pnpm add @pnpm/outdated
13
+ ```
14
+
15
+ ## License
16
+
17
+ [MIT](LICENSE)
@@ -0,0 +1,20 @@
1
+ import { type ClientOptions, type ResolveFunction } from '@pnpm/installing.client';
2
+ import type { DependencyManifest, PackageVersionPolicy } from '@pnpm/types';
3
+ interface GetManifestOpts {
4
+ dir: string;
5
+ lockfileDir: string;
6
+ rawConfig: object;
7
+ minimumReleaseAge?: number;
8
+ minimumReleaseAgeExclude?: string[];
9
+ }
10
+ export type ManifestGetterOptions = Omit<ClientOptions, 'authConfig' | 'minimumReleaseAgeExclude' | 'storeIndex'> & GetManifestOpts & {
11
+ fullMetadata: boolean;
12
+ rawConfig: Record<string, string>;
13
+ };
14
+ export declare function createManifestGetter(opts: ManifestGetterOptions): (packageName: string, bareSpecifier: string) => Promise<DependencyManifest | null>;
15
+ export declare function getManifest(opts: GetManifestOpts & {
16
+ resolve: ResolveFunction;
17
+ publishedBy?: Date;
18
+ publishedByExclude?: PackageVersionPolicy;
19
+ }, packageName: string, bareSpecifier: string): Promise<DependencyManifest | null>;
20
+ export {};
@@ -0,0 +1,48 @@
1
+ import { createPackageVersionPolicy } from '@pnpm/config.version-policy';
2
+ import { createResolver, } from '@pnpm/installing.client';
3
+ export function createManifestGetter(opts) {
4
+ const publishedByExclude = opts.minimumReleaseAgeExclude
5
+ ? createPackageVersionPolicy(opts.minimumReleaseAgeExclude)
6
+ : undefined;
7
+ const { resolve } = createResolver({
8
+ ...opts,
9
+ authConfig: opts.rawConfig,
10
+ filterMetadata: false, // We need all the data from metadata for "outdated --long" to work.
11
+ strictPublishedByCheck: Boolean(opts.minimumReleaseAge),
12
+ });
13
+ const publishedBy = opts.minimumReleaseAge
14
+ ? new Date(Date.now() - opts.minimumReleaseAge * 60 * 1000)
15
+ : undefined;
16
+ return getManifest.bind(null, {
17
+ ...opts,
18
+ resolve,
19
+ publishedBy,
20
+ publishedByExclude,
21
+ });
22
+ }
23
+ export async function getManifest(opts, packageName, bareSpecifier) {
24
+ try {
25
+ const resolution = await opts.resolve({ alias: packageName, bareSpecifier }, {
26
+ lockfileDir: opts.lockfileDir,
27
+ preferredVersions: {},
28
+ projectDir: opts.dir,
29
+ publishedBy: opts.publishedBy,
30
+ publishedByExclude: opts.publishedByExclude,
31
+ });
32
+ return resolution?.manifest ?? null;
33
+ }
34
+ catch (err) {
35
+ const code = err.code;
36
+ if (opts.publishedBy && (code === 'ERR_PNPM_NO_MATURE_MATCHING_VERSION' ||
37
+ code === 'ERR_PNPM_NO_MATCHING_VERSION')) {
38
+ // No versions found that meet the minimumReleaseAge requirement.
39
+ // This can happen when all published versions (including the one the
40
+ // "latest" dist-tag points to) are newer than the minimumReleaseAge
41
+ // threshold, causing the resolver to throw NO_MATCHING_VERSION instead
42
+ // of NO_MATURE_MATCHING_VERSION.
43
+ return null;
44
+ }
45
+ throw err;
46
+ }
47
+ }
48
+ //# sourceMappingURL=createManifestGetter.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type { OutdatedPackage } from './outdated.js';
2
+ export { outdatedDepsOfProjects } from './outdatedDepsOfProjects.js';
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { outdatedDepsOfProjects } from './outdatedDepsOfProjects.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,30 @@
1
+ import type { Catalogs } from '@pnpm/catalogs.types';
2
+ import { type LockfileObject } from '@pnpm/lockfile.fs';
3
+ import { type DependenciesField, type IncludedDependencies, type PackageManifest, type ProjectManifest, type Registries } from '@pnpm/types';
4
+ export * from './createManifestGetter.js';
5
+ export type GetLatestManifestFunction = (packageName: string, rangeOrTag: string) => Promise<PackageManifest | null>;
6
+ export interface OutdatedPackage {
7
+ alias: string;
8
+ belongsTo: DependenciesField;
9
+ current?: string;
10
+ latestManifest?: PackageManifest;
11
+ packageName: string;
12
+ wanted: string;
13
+ workspace?: string;
14
+ }
15
+ export declare function outdated(opts: {
16
+ catalogs?: Catalogs;
17
+ compatible?: boolean;
18
+ currentLockfile: LockfileObject | null;
19
+ getLatestManifest: GetLatestManifestFunction;
20
+ ignoreDependencies?: string[];
21
+ include?: IncludedDependencies;
22
+ lockfileDir: string;
23
+ manifest: ProjectManifest;
24
+ match?: (dependencyName: string) => boolean;
25
+ minimumReleaseAge?: number;
26
+ minimumReleaseAgeExclude?: string[];
27
+ prefix: string;
28
+ registries: Registries;
29
+ wantedLockfile: LockfileObject | null;
30
+ }): Promise<OutdatedPackage[]>;
@@ -0,0 +1,135 @@
1
+ import { matchCatalogResolveResult, resolveFromCatalog, } from '@pnpm/catalogs.resolver';
2
+ import { createMatcher } from '@pnpm/config.matcher';
3
+ import { parseOverrides } from '@pnpm/config.parse-overrides';
4
+ import { pickRegistryForPackage } from '@pnpm/config.pick-registry-for-package';
5
+ import { LOCKFILE_VERSION, WANTED_LOCKFILE } from '@pnpm/constants';
6
+ import * as dp from '@pnpm/deps.path';
7
+ import { PnpmError } from '@pnpm/error';
8
+ import { createReadPackageHook } from '@pnpm/hooks.read-package-hook';
9
+ import { getLockfileImporterId, } from '@pnpm/lockfile.fs';
10
+ import { nameVerFromPkgSnapshot } from '@pnpm/lockfile.utils';
11
+ import { getAllDependenciesFromManifest } from '@pnpm/pkg-manifest.utils';
12
+ import { parseBareSpecifier } from '@pnpm/resolving.npm-resolver';
13
+ import { DEPENDENCIES_FIELDS, } from '@pnpm/types';
14
+ import semver from 'semver';
15
+ export * from './createManifestGetter.js';
16
+ export async function outdated(opts) {
17
+ if (packageHasNoDeps(opts.manifest))
18
+ return [];
19
+ if (opts.wantedLockfile == null) {
20
+ throw new PnpmError('OUTDATED_NO_LOCKFILE', `No lockfile in directory "${opts.lockfileDir}". Run \`pnpm install\` to generate one.`);
21
+ }
22
+ async function getOverriddenManifest() {
23
+ const overrides = opts.currentLockfile?.overrides ?? opts.wantedLockfile?.overrides;
24
+ if (overrides) {
25
+ const readPackageHook = createReadPackageHook({
26
+ lockfileDir: opts.lockfileDir,
27
+ overrides: parseOverrides(overrides, opts.catalogs ?? {}),
28
+ });
29
+ const manifest = await readPackageHook?.(opts.manifest, opts.lockfileDir);
30
+ if (manifest)
31
+ return manifest;
32
+ }
33
+ return opts.manifest;
34
+ }
35
+ const allDeps = getAllDependenciesFromManifest(await getOverriddenManifest());
36
+ const importerId = getLockfileImporterId(opts.lockfileDir, opts.prefix);
37
+ const currentLockfile = opts.currentLockfile ?? { lockfileVersion: LOCKFILE_VERSION, importers: { [importerId]: { specifiers: {} } } };
38
+ const outdated = [];
39
+ const ignoreDependenciesMatcher = opts.ignoreDependencies?.length ? createMatcher(opts.ignoreDependencies) : undefined;
40
+ await Promise.all(DEPENDENCIES_FIELDS.map(async (depType) => {
41
+ if (opts.include?.[depType] === false ||
42
+ (opts.wantedLockfile.importers[importerId][depType] == null))
43
+ return;
44
+ let pkgs = Object.keys(opts.wantedLockfile.importers[importerId][depType]);
45
+ if (opts.match != null) {
46
+ pkgs = pkgs.filter((pkgName) => opts.match(pkgName));
47
+ }
48
+ const _replaceCatalogProtocolIfNecessary = replaceCatalogProtocolIfNecessary.bind(null, opts.catalogs ?? {});
49
+ await Promise.all(pkgs.map(async (alias) => {
50
+ if (!allDeps[alias])
51
+ return;
52
+ const ref = opts.wantedLockfile.importers[importerId][depType][alias];
53
+ if (ref.startsWith('file:') || // ignoring linked packages. (For backward compatibility)
54
+ ignoreDependenciesMatcher?.(alias)) {
55
+ return;
56
+ }
57
+ const relativeDepPath = dp.refToRelative(ref, alias);
58
+ // ignoring linked packages
59
+ if (relativeDepPath === null)
60
+ return;
61
+ const pkgSnapshot = opts.wantedLockfile.packages?.[relativeDepPath];
62
+ if (pkgSnapshot == null) {
63
+ throw new Error(`Invalid ${WANTED_LOCKFILE} file. ${relativeDepPath} not found in packages field`);
64
+ }
65
+ const currentRef = currentLockfile.importers[importerId]?.[depType]?.[alias];
66
+ const currentRelative = currentRef && dp.refToRelative(currentRef, alias);
67
+ const current = (currentRelative && dp.parse(currentRelative).version) ?? currentRef;
68
+ const wanted = dp.parse(relativeDepPath).version ?? ref;
69
+ const { name: packageName } = nameVerFromPkgSnapshot(relativeDepPath, pkgSnapshot);
70
+ const name = dp.parse(relativeDepPath).name ?? packageName;
71
+ const bareSpecifier = _replaceCatalogProtocolIfNecessary({ alias, bareSpecifier: allDeps[alias] });
72
+ // If the npm resolve parser cannot parse the spec of the dependency,
73
+ // it means that the package is not from a npm-compatible registry.
74
+ // In that case, we can't check whether the package is up-to-date
75
+ if (parseBareSpecifier(bareSpecifier, alias, 'latest', pickRegistryForPackage(opts.registries, name)) == null) {
76
+ if (current !== wanted) {
77
+ outdated.push({
78
+ alias,
79
+ belongsTo: depType,
80
+ current,
81
+ latestManifest: undefined,
82
+ packageName,
83
+ wanted,
84
+ workspace: opts.manifest.name,
85
+ });
86
+ }
87
+ return;
88
+ }
89
+ const latestManifest = await opts.getLatestManifest(name, opts.compatible ? (bareSpecifier ?? 'latest') : 'latest');
90
+ if (latestManifest == null)
91
+ return;
92
+ if (!current) {
93
+ outdated.push({
94
+ alias,
95
+ belongsTo: depType,
96
+ latestManifest,
97
+ packageName,
98
+ wanted,
99
+ workspace: opts.manifest.name,
100
+ });
101
+ return;
102
+ }
103
+ if (current !== wanted || semver.lt(current, latestManifest.version) || latestManifest.deprecated) {
104
+ outdated.push({
105
+ alias,
106
+ belongsTo: depType,
107
+ current,
108
+ latestManifest,
109
+ packageName,
110
+ wanted,
111
+ workspace: opts.manifest.name,
112
+ });
113
+ }
114
+ }));
115
+ }));
116
+ return outdated.sort((pkg1, pkg2) => pkg1.packageName.localeCompare(pkg2.packageName));
117
+ }
118
+ function packageHasNoDeps(manifest) {
119
+ return ((manifest.dependencies == null) || isEmpty(manifest.dependencies)) &&
120
+ ((manifest.devDependencies == null) || isEmpty(manifest.devDependencies)) &&
121
+ ((manifest.optionalDependencies == null) || isEmpty(manifest.optionalDependencies));
122
+ }
123
+ function isEmpty(obj) {
124
+ return Object.keys(obj).length === 0;
125
+ }
126
+ function replaceCatalogProtocolIfNecessary(catalogs, wantedDependency) {
127
+ return matchCatalogResolveResult(resolveFromCatalog(catalogs, wantedDependency), {
128
+ unused: () => wantedDependency.bareSpecifier,
129
+ found: (found) => found.resolution.specifier,
130
+ misconfiguration: (misconfiguration) => {
131
+ throw misconfiguration.error;
132
+ },
133
+ });
134
+ }
135
+ //# sourceMappingURL=outdated.js.map
@@ -0,0 +1,15 @@
1
+ import type { Catalogs } from '@pnpm/catalogs.types';
2
+ import type { IncludedDependencies, ProjectManifest, ProjectRootDir } from '@pnpm/types';
3
+ import { type ManifestGetterOptions } from './createManifestGetter.js';
4
+ import { type OutdatedPackage } from './outdated.js';
5
+ export declare function outdatedDepsOfProjects(pkgs: Array<{
6
+ rootDir: ProjectRootDir;
7
+ manifest: ProjectManifest;
8
+ }>, args: string[], opts: Omit<ManifestGetterOptions, 'fullMetadata' | 'lockfileDir'> & {
9
+ catalogs?: Catalogs;
10
+ compatible?: boolean;
11
+ ignoreDependencies?: string[];
12
+ include: IncludedDependencies;
13
+ minimumReleaseAge?: number;
14
+ minimumReleaseAgeExclude?: string[];
15
+ } & Partial<Pick<ManifestGetterOptions, 'fullMetadata' | 'lockfileDir'>>): Promise<OutdatedPackage[][]>;
@@ -0,0 +1,42 @@
1
+ import path from 'node:path';
2
+ import { createMatcher } from '@pnpm/config.matcher';
3
+ import { readCurrentLockfile, readWantedLockfile, } from '@pnpm/lockfile.fs';
4
+ import { unnest } from 'ramda';
5
+ import { createManifestGetter } from './createManifestGetter.js';
6
+ import { outdated } from './outdated.js';
7
+ export async function outdatedDepsOfProjects(pkgs, args, opts) {
8
+ if (!opts.lockfileDir) {
9
+ return unnest(await Promise.all(pkgs.map(async (pkg) => outdatedDepsOfProjects([pkg], args, { ...opts, lockfileDir: pkg.rootDir }))));
10
+ }
11
+ const lockfileDir = opts.lockfileDir ?? opts.dir;
12
+ const internalPnpmDir = path.join(path.join(lockfileDir, 'node_modules/.pnpm'));
13
+ const currentLockfile = await readCurrentLockfile(internalPnpmDir, { ignoreIncompatible: false });
14
+ const wantedLockfile = await readWantedLockfile(lockfileDir, { ignoreIncompatible: false }) ?? currentLockfile;
15
+ const getLatestManifest = createManifestGetter({
16
+ ...opts,
17
+ fullMetadata: opts.fullMetadata === true || Boolean(opts.minimumReleaseAge),
18
+ lockfileDir,
19
+ minimumReleaseAge: opts.minimumReleaseAge,
20
+ minimumReleaseAgeExclude: opts.minimumReleaseAgeExclude,
21
+ });
22
+ return Promise.all(pkgs.map(async ({ rootDir, manifest }) => {
23
+ const match = (args.length > 0) && createMatcher(args) || undefined;
24
+ return outdated({
25
+ catalogs: opts.catalogs,
26
+ compatible: opts.compatible,
27
+ currentLockfile,
28
+ getLatestManifest,
29
+ ignoreDependencies: opts.ignoreDependencies,
30
+ include: opts.include,
31
+ lockfileDir,
32
+ manifest,
33
+ match,
34
+ minimumReleaseAge: opts.minimumReleaseAge,
35
+ minimumReleaseAgeExclude: opts.minimumReleaseAgeExclude,
36
+ prefix: rootDir,
37
+ registries: opts.registries,
38
+ wantedLockfile,
39
+ });
40
+ }));
41
+ }
42
+ //# sourceMappingURL=outdatedDepsOfProjects.js.map
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@pnpm/deps.inspection.outdated",
3
+ "version": "1001.1.1",
4
+ "description": "Check for outdated packages",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11",
8
+ "outdated"
9
+ ],
10
+ "license": "MIT",
11
+ "funding": "https://opencollective.com/pnpm",
12
+ "repository": "https://github.com/pnpm/pnpm/tree/main/deps/inspection/outdated",
13
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/deps/inspection/outdated#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/pnpm/pnpm/issues"
16
+ },
17
+ "type": "module",
18
+ "main": "lib/index.js",
19
+ "types": "lib/index.d.ts",
20
+ "exports": {
21
+ ".": "./lib/index.js"
22
+ },
23
+ "files": [
24
+ "lib",
25
+ "!*.map"
26
+ ],
27
+ "dependencies": {
28
+ "ramda": "npm:@pnpm/ramda@0.28.1",
29
+ "semver": "^7.7.2",
30
+ "@pnpm/config.parse-overrides": "1001.0.3",
31
+ "@pnpm/catalogs.types": "1000.0.0",
32
+ "@pnpm/config.pick-registry-for-package": "1000.0.11",
33
+ "@pnpm/config.matcher": "1000.1.0",
34
+ "@pnpm/config.version-policy": "1000.0.0",
35
+ "@pnpm/constants": "1001.3.1",
36
+ "@pnpm/deps.path": "1001.1.3",
37
+ "@pnpm/error": "1000.0.5",
38
+ "@pnpm/catalogs.resolver": "1000.0.5",
39
+ "@pnpm/installing.client": "1001.1.4",
40
+ "@pnpm/hooks.read-package-hook": "1000.0.15",
41
+ "@pnpm/lockfile.fs": "1001.1.21",
42
+ "@pnpm/lockfile.utils": "1003.0.3",
43
+ "@pnpm/resolving.npm-resolver": "1004.4.1",
44
+ "@pnpm/types": "1000.9.0",
45
+ "@pnpm/pkg-manifest.utils": "1001.0.6"
46
+ },
47
+ "peerDependencies": {
48
+ "@pnpm/logger": ">=1001.0.0 <1002.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@jest/globals": "30.0.5",
52
+ "@types/ramda": "0.29.12",
53
+ "@types/semver": "7.7.1",
54
+ "@pnpm/logger": "1001.0.1",
55
+ "@pnpm/resolving.resolver-base": "1005.1.0",
56
+ "@pnpm/deps.inspection.outdated": "1001.1.1"
57
+ },
58
+ "engines": {
59
+ "node": ">=22.13"
60
+ },
61
+ "jest": {
62
+ "preset": "@pnpm/jest-config/with-registry"
63
+ },
64
+ "scripts": {
65
+ "test": "pnpm run compile && pnpm run _test",
66
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
67
+ "_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
68
+ "compile": "tsgo --build && pnpm run lint --fix"
69
+ }
70
+ }