Skip to content

Commit

Permalink
chore(cache): migrates to watskeburt 4 (#914)
Browse files Browse the repository at this point in the history
## Description

- migrates to watskeburt@4
- as the largest breaking change in watskeburt@4 is that
`IChange.changeType` => `IChange.type` and we use the IChange interface
for our cache, this means the cache format version needs to be bumped as
well to prevent backwards compatibility issues.

## Motivation and Context

Life cycle management
## How Has This Been Tested?

- [x] green ci

## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [ ] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
  • Loading branch information
sverweij committed Feb 24, 2024
1 parent 1dcb73d commit 24aec38
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 99 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -222,7 +222,7 @@
"semver-try-require": "6.2.3",
"teamcity-service-messages": "0.1.14",
"tsconfig-paths-webpack-plugin": "4.1.0",
"watskeburt": "3.0.0",
"watskeburt": "4.0.0",
"wrap-ansi": "9.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/cache/cache.mjs
Expand Up @@ -44,7 +44,7 @@ const EMPTY_CACHE = {
// in patch releases. If worst case scenario it _is_ necessary we could
// add the patch version divided by 1000_000 e.g.:
// version 3.14.16 => 3.14 + 16/1000_000 = 3.140016
const CACHE_FORMAT_VERSION = 16;
const CACHE_FORMAT_VERSION = 16.2;

export default class Cache {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/cache/content-strategy.mjs
Expand Up @@ -56,7 +56,7 @@ export default class ContentStrategy {
* @param {IStrictCruiseOptions} pCruiseOptions
* @param {Object} pOptions
* @param {Set<string>} pOptions.extensions
* @param {Set<import("watskeburt").changeTypeType>=} pOptions.interestingChangeTypes?
* @param {Set<import("watskeburt").changeType>=} pOptions.interestingChangeTypes?
* @param {string=} pOptions.baseDir
* @param {typeof findContentChanges=} pOptions.diffListFn
* @param {typeof import('watskeburt').getSHA=} pOptions.checksumFn
Expand Down
10 changes: 5 additions & 5 deletions src/cache/find-content-changes.mjs
Expand Up @@ -25,11 +25,11 @@ function diffCachedModuleAgainstFileSet(
) {
return (pModule) => {
if (!moduleIsInterestingForDiff(pModule)) {
return { name: pModule.source, changeType: "ignored" };
return { name: pModule.source, type: "ignored" };
}

if (!pFileSet.has(pModule.source)) {
return { name: pModule.source, changeType: "deleted" };
return { name: pModule.source, type: "deleted" };
}

const lNewCheckSum = pFileHashFunction(
Expand All @@ -38,14 +38,14 @@ function diffCachedModuleAgainstFileSet(
if (lNewCheckSum !== pModule.checksum) {
return {
name: pModule.source,
changeType: "modified",
type: "modified",
checksum: lNewCheckSum,
};
}

return {
name: pModule.source,
changeType: "unmodified",
type: "unmodified",
checksum: pModule.checksum,
};
};
Expand Down Expand Up @@ -99,7 +99,7 @@ export default function findContentChanges(
for (let lFileName of lFileSet) {
lDiffNewVsCached.push({
name: lFileName,
changeType: /** @type import('watskeburt').changeTypeType */ ("added"),
type: /** @type import('watskeburt').changeType */ ("added"),
checksum: getFileHashSync(join(pOptions.baseDir, lFileName)),
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/cache/helpers.mjs
Expand Up @@ -107,13 +107,13 @@ const DEFAULT_INTERESTING_CHANGE_TYPES = new Set([
]);

/**
* @param {Set<import("watskeburt").changeTypeType>=} pInterestingChangeTypes
* @param {Set<import("watskeburt").changeType>=} pInterestingChangeTypes
* @returns {(pChange: import("watskeburt").IChange) => boolean}
*/
export function isInterestingChangeType(pInterestingChangeTypes) {
return (pChange) =>
(pInterestingChangeTypes ?? DEFAULT_INTERESTING_CHANGE_TYPES).has(
pChange.changeType,
pChange.type,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cache/metadata-strategy.mjs
Expand Up @@ -26,7 +26,7 @@ export default class MetaDataStrategy {
* @param {import("../../types/cruise-result.mjs").ICruiseResult} _pCachedCruiseResult
* @param {Object} pOptions
* @param {Set<string>} pOptions.extensions
* @param {Set<import("watskeburt").changeTypeType>=} pOptions.interestingChangeTypes
* @param {Set<import("watskeburt").changeType>=} pOptions.interestingChangeTypes
* @param {typeof getSHA=} pOptions.shaRetrievalFn
* @param {typeof list=} pOptions.diffListFn
* @param {typeof addCheckSumToChangeSync=} pOptions.checksumFn
Expand Down
4 changes: 2 additions & 2 deletions src/schema/cruise-result.schema.json

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

2 changes: 1 addition & 1 deletion src/schema/cruise-result.schema.mjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/cache/cache.spec.mjs
Expand Up @@ -114,7 +114,7 @@ describe("[I] cache/cache - canServeFromCache", () => {
args: "src test tools",
},
},
revisionData: { cacheFormatVersion: 16, SHA1: "dummy-sha", changes: [] },
revisionData: { cacheFormatVersion: 16.2, SHA1: "dummy-sha", changes: [] },
};

/** @type import("../..").ICruiseResult */
Expand Down Expand Up @@ -230,7 +230,7 @@ describe("[I] cache/cache - canServeFromCache", () => {
SHA1: "dummy-sha",
changes: [
{
changeType: "added",
type: "added",
name: "some-new-file.aap",
checksum: "dummy-checksum",
},
Expand Down
40 changes: 20 additions & 20 deletions test/cache/content-strategy.spec.mjs
Expand Up @@ -23,15 +23,15 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
/** @type {import('watskeburt').IChange[]} */
const lInputChanges = [
{
changeType: "modified",
type: "modified",
name: "test/cache/__mocks__/calculate-shasum-of-this.aap",
},
];
const lExpected = {
SHA1: DUMMY_SHA,
changes: [
{
changeType: "modified",
type: "modified",
name: "test/cache/__mocks__/calculate-shasum-of-this.aap",
},
],
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
SHA1: DUMMY_SHA,
changes: [
{
changeType: "added",
type: "added",
name: "noot-extension-hence-returned.noot",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
Expand All @@ -105,28 +105,28 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
/** @type {import('watskeburt').IChange[]} */
const lInputChanges = [
{
changeType: "added",
type: "added",
name: "added-hence-returned.aap",
},
{
changeType: "added",
type: "added",
name: "added-hence-returned.noot",
},
{
changeType: "ignored",
type: "ignored",
name: "ignored-hence-ignored.aap",
},
{
changeType: "renamed",
type: "renamed",
name: "renamed-hence-returned.mies",
oldName: "old-name.wim",
},
{
changeType: "deleted",
type: "deleted",
name: "deleted-hence-ignored.aap",
},
{
changeType: "deleted",
type: "deleted",
name: "untracked-hence-ignored.aap",
},
];
Expand All @@ -147,15 +147,15 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
SHA1: DUMMY_SHA,
changes: [
{
changeType: "added",
type: "added",
name: "added-hence-returned.aap",
},
{
changeType: "added",
type: "added",
name: "added-hence-returned.noot",
},
{
changeType: "renamed",
type: "renamed",
name: "renamed-hence-returned.mies",
oldName: "old-name.wim",
},
Expand All @@ -168,17 +168,17 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
describe("[U] cache/content-strategy - revisionDataEqual", () => {
const lChanges = [
{
changeType: "added",
type: "added",
name: "added-hence-returned.aap",
checksum: "dummy-checksum",
},
{
changeType: "added",
type: "added",
name: "added-hence-returned.noot",
checksum: "dummy-checksum",
},
{
changeType: "renamed",
type: "renamed",
name: "renamed-hence-returned.mies",
oldName: "old-name.wim",
checksum: "dummy-checksum",
Expand Down Expand Up @@ -369,17 +369,17 @@ describe("[U] cache/content-strategy - prepareRevisionDataForSaving", () => {
SHA1: "shwoop",
changes: [
{
changeType: "modified",
type: "modified",
name: "foo.js",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
{
changeType: "added",
type: "added",
name: "added.js",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
{
changeType: "modified",
type: "modified",
name: "baz.js",
checksum: "differentchecksumfromthing/=",
},
Expand Down Expand Up @@ -409,12 +409,12 @@ describe("[U] cache/content-strategy - prepareRevisionDataForSaving", () => {
SHA1: "shwoop",
changes: [
{
changeType: "added",
type: "added",
name: "added.js",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
{
changeType: "modified",
type: "modified",
name: "baz.js",
checksum: "differentchecksumfromthing/=",
},
Expand Down
28 changes: 14 additions & 14 deletions test/cache/find-content-changes.spec.mjs
Expand Up @@ -36,19 +36,19 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
[
{
name: "consolidated",
changeType: "ignored",
type: "ignored",
},
{
name: "path",
changeType: "ignored",
type: "ignored",
},
{
name: "could-not-resolve.js",
changeType: "ignored",
type: "ignored",
},
{
name: "node_modules/matches-do-not/follow.js",
changeType: "ignored",
type: "ignored",
},
],
);
Expand All @@ -69,7 +69,7 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
[
{
name: "only-in-cache-ends-up-as-deleted.js",
changeType: "deleted",
type: "deleted",
},
],
);
Expand Down Expand Up @@ -98,7 +98,7 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
[
{
name: "not-in-content-changes-as-extension.weird",
changeType: "ignored",
type: "ignored",
},
],
);
Expand Down Expand Up @@ -129,12 +129,12 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
[
{
name: "in-folder-as-well-different-checksum.js",
changeType: "modified",
type: "modified",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
{
name: "in-folder-as-well-no-checksum.js",
changeType: "modified",
type: "modified",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
],
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
[
{
name: "in-folder-as-well-unmodified.js",
changeType: "unmodified",
type: "unmodified",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
],
Expand Down Expand Up @@ -203,7 +203,7 @@ describe("[U] cache/find-content-changes - new vs cached", () => {
[
{
name: "interesting-extension.js",
changeType: "added",
type: "added",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
],
Expand All @@ -224,7 +224,7 @@ describe("[U] cache/find-content-changes - new vs cached", () => {
[
{
name: "interesting-extension.js",
changeType: "added",
type: "added",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
],
Expand All @@ -246,7 +246,7 @@ describe("[U] cache/find-content-changes - new vs cached", () => {
[
{
name: "interesting-extension.js",
changeType: "added",
type: "added",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
],
Expand All @@ -269,12 +269,12 @@ describe("[U] cache/find-content-changes - new vs cached", () => {
[
{
name: "interesting-as-well.js",
changeType: "added",
type: "added",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
{
name: "interesting-extension.js",
changeType: "added",
type: "added",
checksum: "2jmj7l5rSw0yVb/vlWAYkK/YBwk=",
},
],
Expand Down

0 comments on commit 24aec38

Please sign in to comment.