Skip to content

Commit

Permalink
refactor(resolutions): handle missing ignore-resolutions-until
Browse files Browse the repository at this point in the history
  • Loading branch information
padamczewski committed May 4, 2024
1 parent 62bbb95 commit 18f473f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
15 changes: 9 additions & 6 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18102,11 +18102,14 @@ var dependencySatisfiesAllowedTags = (packageName, version, allowedTags) => {
// src/rules/resolutions.ts
var core5 = __toESM(require_core(), 1);
var validateResolutions = (packageJson) => {
const ignoreUntilDate = new Date(core5.getInput("ignore-resolutions-until"));
const now = new Date;
if (packageJson.resolutions && ignoreUntilDate > now) {
core5.info(`Ignoring resolutions until ${ignoreUntilDate.toISOString()}`);
return;
const ignoreResolutionsUntil = core5.getInput("ignore-resolutions-until");
if (packageJson.resolutions && ignoreResolutionsUntil) {
const ignoreUntilDate = new Date(ignoreResolutionsUntil);
const now = new Date;
if (ignoreUntilDate > now) {
core5.info(`Ignoring resolutions until ${ignoreUntilDate.toISOString()}`);
return;
}
}
const ignoredResolutions = core5.getMultilineInput("ignore-resolutions");
if (packageJson.resolutions && !ignoredResolutions.length) {
Expand Down Expand Up @@ -18209,4 +18212,4 @@ export {
RULES_MAP
};

//# debugId=B3BC6D9C6519319864756e2164756e21
//# debugId=653C660A130B963164756e2164756e21
6 changes: 3 additions & 3 deletions dist/main.js.map

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/rules/resolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ import * as core from '@actions/core';
import { PackageJson } from 'type-fest';

export const validateResolutions = (packageJson: PackageJson) => {
const ignoreUntilDate = new Date(core.getInput('ignore-resolutions-until'));
const now = new Date();
if (packageJson.resolutions && ignoreUntilDate > now) {
core.info(`Ignoring resolutions until ${ignoreUntilDate.toISOString()}`);
return;
const ignoreResolutionsUntil = core.getInput('ignore-resolutions-until');

if (packageJson.resolutions && ignoreResolutionsUntil) {
const ignoreUntilDate = new Date(ignoreResolutionsUntil);
const now = new Date();

if (ignoreUntilDate > now) {
core.info(`Ignoring resolutions until ${ignoreUntilDate.toISOString()}`);
return;
}
}

const ignoredResolutions = core.getMultilineInput('ignore-resolutions');
Expand Down
23 changes: 23 additions & 0 deletions test/rules/resolutions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ describe("ignore-resolutions-until", () => {
expect(core.info).not.toHaveBeenCalledWith();
});

it('should fail when some resolutions are provided and ignore-resolutions-until is not set', () => {
// 1. Arrange
jest.setSystemTime(new Date("2021-01-31"));
(core.getInput as jest.Mock).mockImplementation(input => input === 'ignore-resolutions-until' ? "" : "");

// 2. Act
const packageJson: PackageJson = {
dependencies: {},
resolutions: {
"@test/package-foo": 'resolution',
"@test/package-bar": 'resolution'
}
};
validateResolutions(packageJson);

// 3. Assert
expect(core.getInput).toHaveBeenCalledWith("ignore-resolutions-until");
expect(core.getMultilineInput).toHaveBeenCalledWith("ignore-resolutions");

expect(core.setFailed).toHaveBeenCalledWith('Resolutions may not be set. Please investigate the root cause of your dependency issues!');
expect(core.info).not.toHaveBeenCalledWith();
});

it('should not fail when matching resolution is present in package.json and ignore list, while ignore-resolutions-until is provided with date in the past', () => {
// 1. Arrange
jest.setSystemTime(new Date("2021-01-31"));
Expand Down

0 comments on commit 18f473f

Please sign in to comment.