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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
| `pack-size-threshold` | Threshold (in bytes) for warning about significant increase in total pack size. Set to `-1` to always report size changes. | No | `50000` |
| `detect-replacements` | Detect modules which have community suggested alternatives | No | `true` |
| `detect-license-changes` | Detect when a dependency changes its license between versions | No | `true` |
| `detect-engine-changes` | Detect when an upgraded dependency tightens its Node.js engine requirement | No | `true` |
| `detect-install-scripts` | Detect when a newly added or upgraded dependency introduces install scripts | No | `true` |
| `exclude-dev-dependencies` | Exclude devDependencies and their exclusive transitive dependencies from analysis | No | `false` |
| `exclude-packages` | Comma-separated package names or wildcard patterns (e.g., `"@types/*, eslint-*"`) to exclude with their dependency trees | No | None |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ inputs:
description: 'Detect when a dependency changes its license between versions'
required: false
default: true
detect-engine-changes:
description: 'Detect when an upgraded dependency tightens its Node.js engine requirement'
required: false
default: true
detect-install-scripts:
description: 'Detect when a newly added or upgraded dependency introduces install scripts'
required: false
Expand Down
468 changes: 465 additions & 3 deletions build/main.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@
"typescript": "npm:@typescript/typescript6@^6.0.2",
"typescript-eslint": "^8.73.0",
"vitest": "^5.1.1"
},
"dependencies": {
"verkit": "^0.5.0"
}
}
70 changes: 70 additions & 0 deletions src/checks/engines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as core from '@actions/core';
import {normalizeRange, isRangeSubset} from 'verkit';
import {getNodeEnginesForPackageVersions} from '../npm.js';

export async function scanForEngineChanges(
messages: string[],
currentDeps: Map<string, Set<string>>,
baseDeps: Map<string, Set<string>>
): Promise<void> {
const engineRows: string[] = [];

for (const [packageName, currentVersionSet] of currentDeps) {
const baseVersionSet = baseDeps.get(packageName);
if (!baseVersionSet || currentVersionSet.isSubsetOf(baseVersionSet)) {
continue;
}

try {
const baseEngines = await getNodeEnginesForPackageVersions(
packageName,
baseVersionSet
);
const currentEngines = await getNodeEnginesForPackageVersions(
packageName,
currentVersionSet
);

for (const [version, currentRange] of currentEngines) {
if (baseVersionSet.has(version) || !currentRange) {
continue;
}

const normalizedCurrentRange = normalizeRange(currentRange);
if (!normalizedCurrentRange) {
continue;
}

const tighterThan = Array.from(baseEngines)
.filter(([baseVersion]) => baseVersionSet.has(baseVersion))
.map(([, baseRange]) => baseRange ?? '*')
.find((baseRange) => {
const normalizedBaseRange = normalizeRange(baseRange);
return (
normalizedBaseRange !== null &&
isRangeSubset(normalizedCurrentRange, normalizedBaseRange) &&
!isRangeSubset(normalizedBaseRange, normalizedCurrentRange)
);
});

if (tighterThan !== undefined) {
engineRows.push(
`| ${packageName}@${version} | ${tighterThan} | ${currentRange} |`
);
}
}
} catch (err) {
core.info(`Failed to check Node.js engine for ${packageName}: ${err}`);
}
}

if (engineRows.length > 0) {
messages.push(
`## ⚠️ Node.js Engine Changes

| 📦 Package | Previous Node.js Engine | New Node.js Engine |
| --- | --- | --- |
${engineRows.join('\n')}`
);
}
}
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {scanForDependencyCount} from './checks/dependency-count.js';
import {scanForDependencySize} from './checks/dependency-size.js';
import {scanForProvenance} from './checks/provenance.js';
import {scanForLicenses} from './checks/license.js';
import {scanForEngineChanges} from './checks/engines.js';
import {scanForInstallScripts} from './checks/install-scripts.js';
import {scanForBundleSize} from './checks/bundle-size.js';
import {formatBytes, parseCommaList} from './common.js';
Expand Down Expand Up @@ -74,6 +75,7 @@ async function analyzeAndComment(): Promise<void> {
const prNumber = parseInt(core.getInput('pr-number', {required: true}), 10);
const detectReplacements = core.getBooleanInput('detect-replacements');
const detectLicenseChanges = core.getBooleanInput('detect-license-changes');
const detectEngineChanges = core.getBooleanInput('detect-engine-changes');
const detectInstallScripts = core.getBooleanInput('detect-install-scripts');
const excludeDevDependencies = core.getBooleanInput(
'exclude-dev-dependencies'
Expand Down Expand Up @@ -220,6 +222,10 @@ async function analyzeAndComment(): Promise<void> {
await scanForLicenses(messages, currentDeps, baseDeps);
}

if (detectEngineChanges) {
await scanForEngineChanges(messages, currentDeps, baseDeps);
}

const basePackagesPattern = core.getInput('base-packages');
const sourcePackagesPattern = core.getInput('source-packages');

Expand Down
15 changes: 15 additions & 0 deletions src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface PackageMetadata {
name: string;
version: string;
license?: string;
engines?: {node?: string};
scripts?: Record<string, string>;
os?: string[];
cpu?: string[];
Expand Down Expand Up @@ -265,6 +266,20 @@ export function isSupportedArchitecture(
return osMatches && cpuMatches && libcMatches;
}

export async function getNodeEnginesForPackageVersions(
packageName: string,
versions: Set<string>
): Promise<Map<string, string | null>> {
const result = new Map<string, string | null>();
for (const version of versions) {
const metadata = await fetchPackageMetadata(packageName, version);
if (metadata) {
result.set(version, metadata.engines?.node?.trim() || null);
}
}
return result;
}

export async function getLicensesForPackageVersions(
packageName: string,
versions: Set<string>
Expand Down
92 changes: 92 additions & 0 deletions test/checks/engines_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {describe, expect, it} from 'vitest';
import {scanForEngineChanges} from '../../src/checks/engines.js';
import {metaCache, type PackageMetadata} from '../../src/npm.js';

function createMeta(
name: string,
version: string,
node?: string
): PackageMetadata {
return {
name,
version,
engines: node ? {node} : undefined,
_npmUser: {name: 'test', email: 'test@example.com'}
};
}

describe('scanForEngineChanges', () => {
it('reports when an upgraded dependency tightens its Node.js requirement', async () => {
metaCache.set(
'pkg-engine@1.0.0',
createMeta('pkg-engine', '1.0.0', '>=16')
);
metaCache.set(
'pkg-engine@2.0.0',
createMeta('pkg-engine', '2.0.0', '>=18')
);

const messages: string[] = [];
const baseDeps = new Map([['pkg-engine', new Set(['1.0.0'])]]);
const currentDeps = new Map([['pkg-engine', new Set(['2.0.0'])]]);

await scanForEngineChanges(messages, currentDeps, baseDeps);

expect(messages).toHaveLength(1);
expect(messages[0]).toContain('## ⚠️ Node.js Engine Changes');
expect(messages[0]).toContain('| pkg-engine@2.0.0 | >=16 | >=18 |');
});

it('reports a newly added Node.js requirement when the prior version had none', async () => {
metaCache.set(
'pkg-engine-none@1.0.0',
createMeta('pkg-engine-none', '1.0.0')
);
metaCache.set(
'pkg-engine-none@2.0.0',
createMeta('pkg-engine-none', '2.0.0', '>=18')
);

const messages: string[] = [];
const baseDeps = new Map([['pkg-engine-none', new Set(['1.0.0'])]]);
const currentDeps = new Map([['pkg-engine-none', new Set(['2.0.0'])]]);

await scanForEngineChanges(messages, currentDeps, baseDeps);

expect(messages[0]).toContain('| pkg-engine-none@2.0.0 | * | >=18 |');
});

it('does not report an unchanged or relaxed Node.js requirement', async () => {
metaCache.set(
'pkg-engine-same@1.0.0',
createMeta('pkg-engine-same', '1.0.0', '>=18')
);
metaCache.set(
'pkg-engine-same@2.0.0',
createMeta('pkg-engine-same', '2.0.0', '>=16')
);

const messages: string[] = [];
const baseDeps = new Map([['pkg-engine-same', new Set(['1.0.0'])]]);
const currentDeps = new Map([['pkg-engine-same', new Set(['2.0.0'])]]);

await scanForEngineChanges(messages, currentDeps, baseDeps);

expect(messages).toHaveLength(0);
});

it('does not report a newly added dependency', async () => {
metaCache.set(
'pkg-engine-new@1.0.0',
createMeta('pkg-engine-new', '1.0.0', '>=18')
);

const messages: string[] = [];
const baseDeps = new Map<string, Set<string>>();
const currentDeps = new Map([['pkg-engine-new', new Set(['1.0.0'])]]);

await scanForEngineChanges(messages, currentDeps, baseDeps);

expect(messages).toHaveLength(0);
});
});