dependency-cruiser 12.5.0-beta-2 → 12.5.0-beta-4
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/package.json +1 -1
- package/src/cache/cache.js +5 -3
- package/src/cache/content-strategy.js +80 -182
- package/src/cache/find-content-changes.js +104 -0
- package/src/cache/metadata-strategy.js +67 -76
- package/src/cache/utl.js +25 -5
- package/src/main/index.js +7 -3
- package/src/meta.js +1 -1
- package/src/utl/find-all-files.js +37 -5
package/package.json
CHANGED
package/src/cache/cache.js
CHANGED
|
@@ -2,8 +2,8 @@ const { readFileSync, mkdirSync, writeFileSync } = require("fs");
|
|
|
2
2
|
const { join } = require("path");
|
|
3
3
|
const meta = require("../extract/transpile/meta");
|
|
4
4
|
const { optionsAreCompatible } = require("./options-compatible");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const MetadataStrategy = require("./metadata-strategy");
|
|
6
|
+
const ContentStrategy = require("./content-strategy");
|
|
7
7
|
|
|
8
8
|
const CACHE_FILE_NAME = "cache.json";
|
|
9
9
|
|
|
@@ -14,7 +14,9 @@ module.exports = class Cache {
|
|
|
14
14
|
constructor(pCacheStrategy) {
|
|
15
15
|
this.revisionData = null;
|
|
16
16
|
this.cacheStrategy =
|
|
17
|
-
pCacheStrategy === "content"
|
|
17
|
+
pCacheStrategy === "content"
|
|
18
|
+
? new ContentStrategy()
|
|
19
|
+
: new MetadataStrategy();
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -1,176 +1,29 @@
|
|
|
1
|
+
const { join } = require("path").posix;
|
|
1
2
|
const { isDeepStrictEqual } = require("util");
|
|
2
|
-
const
|
|
3
|
-
const { DEBUG } = require("../utl/bus-log-levels");
|
|
4
|
-
const findAllFiles = require("../utl/find-all-files");
|
|
3
|
+
const findContentChanges = require("./find-content-changes");
|
|
5
4
|
const {
|
|
6
5
|
getFileHash,
|
|
7
|
-
excludeFilter,
|
|
8
|
-
includeOnlyFilter,
|
|
9
6
|
isInterestingChangeType,
|
|
10
|
-
hasInterestingExtension,
|
|
11
7
|
addCheckSumToChange,
|
|
8
|
+
moduleIsInterestingForDiff,
|
|
12
9
|
} = require("./utl");
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
|
-
* @param {
|
|
16
|
-
* @
|
|
17
|
-
* @returns {import('../..').IRevisionChange}
|
|
12
|
+
* @param {string} pBaseDirectory
|
|
13
|
+
* @returns {(pModule: import("../..").IModule) => import("../..").IModule}
|
|
18
14
|
*/
|
|
19
|
-
function
|
|
20
|
-
pFileSet,
|
|
21
|
-
pFileHashFunction = getFileHash
|
|
22
|
-
) {
|
|
23
|
-
// eslint-disable-next-line complexity
|
|
15
|
+
function addCheckSumToModule(pBaseDirectory) {
|
|
24
16
|
return (pModule) => {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
) {
|
|
31
|
-
if (!pFileSet.has(pModule.source)) {
|
|
32
|
-
return { name: pModule.source, changeType: "deleted" };
|
|
33
|
-
}
|
|
34
|
-
const lNewCheckSum = pFileHashFunction(pModule.source);
|
|
35
|
-
if (lNewCheckSum !== pModule.checksum) {
|
|
36
|
-
return {
|
|
37
|
-
name: pModule.source,
|
|
38
|
-
changeType: "modified",
|
|
39
|
-
checksum: lNewCheckSum,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
17
|
+
if (moduleIsInterestingForDiff(pModule)) {
|
|
18
|
+
return {
|
|
19
|
+
...pModule,
|
|
20
|
+
checksum: getFileHash(join(pBaseDirectory, pModule.source)),
|
|
21
|
+
};
|
|
42
22
|
}
|
|
43
|
-
return
|
|
44
|
-
name: pModule.source,
|
|
45
|
-
changeType: "unmodified",
|
|
46
|
-
checksum: pModule.checksum,
|
|
47
|
-
};
|
|
23
|
+
return pModule;
|
|
48
24
|
};
|
|
49
25
|
}
|
|
50
26
|
|
|
51
|
-
/**
|
|
52
|
-
We can run into these scenarios:
|
|
53
|
-
- there is no cache yet:
|
|
54
|
-
modules will === []; all files will be marked as 'added'
|
|
55
|
-
- there is a cache and it contains checksums:
|
|
56
|
-
- existing files that are not in the cache => added
|
|
57
|
-
- modules that are in the cache:
|
|
58
|
-
- don't exist anymore => deleted TODO:
|
|
59
|
-
we might wrongly bump into this for files that are gitignored and that don't have an interesting extension
|
|
60
|
-
- cached checksum === current checksum => not a change; left out
|
|
61
|
-
- cached checksum !== current checksum => modified
|
|
62
|
-
- there is a cache, but it doesn't contain checksums => same as before, except
|
|
63
|
-
all files will be marked as 'modified'
|
|
64
|
-
* @param {string} pDirectory
|
|
65
|
-
* @param {import("../..").ICruiseResult} pCachedCruiseResult
|
|
66
|
-
* @param {Object} pOptions
|
|
67
|
-
* @param {Set<string>} pOptions.extensions
|
|
68
|
-
* @param {string} pOptions.baseDir
|
|
69
|
-
* @returns {{source: string; changeType: import("watskeburt").changeTypeType; checksum: string}[]}
|
|
70
|
-
*/
|
|
71
|
-
function findChanges(pDirectory, pCachedCruiseResult, pOptions) {
|
|
72
|
-
bus.emit("progress", "cache: - hauling revision data", { level: DEBUG });
|
|
73
|
-
const lFileSet = new Set(
|
|
74
|
-
findAllFiles(pDirectory, {
|
|
75
|
-
baseDir: pOptions.baseDir,
|
|
76
|
-
})
|
|
77
|
-
.filter(excludeFilter(pOptions.exclude))
|
|
78
|
-
.filter(includeOnlyFilter(pOptions.includeOnly))
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
bus.emit("progress", "cache: - determining cached vs new", { level: DEBUG });
|
|
82
|
-
const lDiffCachedVsNew = pCachedCruiseResult.modules.map(
|
|
83
|
-
diffCachedModuleAgainstFileSet(lFileSet)
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
bus.emit("progress", "cache: - determining new vs cached", { level: DEBUG });
|
|
87
|
-
lDiffCachedVsNew.forEach(({ name }) => lFileSet.delete(name));
|
|
88
|
-
|
|
89
|
-
const lDiffNewVsCached = [];
|
|
90
|
-
for (let lFileName of lFileSet) {
|
|
91
|
-
lDiffNewVsCached.push({
|
|
92
|
-
name: lFileName,
|
|
93
|
-
changeType: "added",
|
|
94
|
-
checksum: getFileHash(lFileName),
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
bus.emit("progress", "cache: - returning revision data", { level: DEBUG });
|
|
99
|
-
return lDiffCachedVsNew
|
|
100
|
-
.concat(lDiffNewVsCached)
|
|
101
|
-
.filter(hasInterestingExtension(pOptions.extensions));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
*
|
|
106
|
-
* @param {string} pDirectory
|
|
107
|
-
* @param {import("../..").ICruiseResult} pCachedCruiseResult
|
|
108
|
-
* @param {import("../../types/strict-options").IStrictCruiseOptions} pCruiseOptions
|
|
109
|
-
* @param {Object} pOptions
|
|
110
|
-
* @param {Set<string>} pOptions.extensions
|
|
111
|
-
* @param {Set<import("watskeburt").changeTypeType>} pOptions.interestingChangeTypes
|
|
112
|
-
* @param {string} pOptions.baseDir
|
|
113
|
-
* @param {(pString:string) => Array<import("watskeburt").IChange>} pOptions.diffListFn
|
|
114
|
-
* @param {(import("watskeburt").IChange) => import("../..").IRevisionChange} pOptions.checksumFn
|
|
115
|
-
* @returns {import("../..").IRevisionData}
|
|
116
|
-
*/
|
|
117
|
-
function getRevisionData(
|
|
118
|
-
pDirectory,
|
|
119
|
-
pCachedCruiseResult,
|
|
120
|
-
pCruiseOptions,
|
|
121
|
-
pOptions
|
|
122
|
-
) {
|
|
123
|
-
const lOptions = {
|
|
124
|
-
diffListFn: findChanges,
|
|
125
|
-
checksumFn: addCheckSumToChange,
|
|
126
|
-
baseDir: process.cwd(),
|
|
127
|
-
...pOptions,
|
|
128
|
-
};
|
|
129
|
-
return {
|
|
130
|
-
SHA1: "unknown-in-content-cache-strategy",
|
|
131
|
-
changes: lOptions
|
|
132
|
-
.diffListFn(pDirectory, pCachedCruiseResult, {
|
|
133
|
-
baseDir: lOptions.baseDir,
|
|
134
|
-
extensions: lOptions.extensions,
|
|
135
|
-
includeOnly: pCruiseOptions.includeOnly,
|
|
136
|
-
exclude: pCruiseOptions.exclude,
|
|
137
|
-
})
|
|
138
|
-
.filter(isInterestingChangeType(lOptions.interestingChangeTypes)),
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @param {import("../..").IRevisionData} pExistingRevisionData
|
|
144
|
-
* @param {import("../..").IRevisionData} pNewRevisionData
|
|
145
|
-
* @returns {boolean}
|
|
146
|
-
*/
|
|
147
|
-
function revisionDataEqual(pExistingRevisionData, pNewRevisionData) {
|
|
148
|
-
return (
|
|
149
|
-
Boolean(pExistingRevisionData) &&
|
|
150
|
-
Boolean(pNewRevisionData) &&
|
|
151
|
-
isDeepStrictEqual(pExistingRevisionData.changes, pNewRevisionData.changes)
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @param {import("../..").IModule} pModule
|
|
157
|
-
* @param {import("../..").IRevisionChange}
|
|
158
|
-
*/
|
|
159
|
-
function addCheckSumToModule(pModule) {
|
|
160
|
-
if (
|
|
161
|
-
!pModule.consolidated &&
|
|
162
|
-
!pModule.coreModule &&
|
|
163
|
-
!pModule.couldNotResolve &&
|
|
164
|
-
!pModule.matchesDoNotFollow
|
|
165
|
-
) {
|
|
166
|
-
return {
|
|
167
|
-
...pModule,
|
|
168
|
-
checksum: getFileHash(pModule.source),
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
return pModule;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
27
|
/**
|
|
175
28
|
* @param {import("../..").IRevisionChange[]} pChanges
|
|
176
29
|
* @param {import("../..").IModule[]} pModules
|
|
@@ -187,29 +40,74 @@ function refreshChanges(pChanges, pModules) {
|
|
|
187
40
|
);
|
|
188
41
|
}
|
|
189
42
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
43
|
+
module.exports = class ContentStrategy {
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} pDirectory
|
|
46
|
+
* @param {import("../..").ICruiseResult} pCachedCruiseResult
|
|
47
|
+
* @param {import("../../types/strict-options").IStrictCruiseOptions} pCruiseOptions
|
|
48
|
+
* @param {Object} pOptions
|
|
49
|
+
* @param {Set<string>} pOptions.extensions
|
|
50
|
+
* @param {Set<import("watskeburt").changeTypeType>} pOptions.interestingChangeTypes
|
|
51
|
+
* @param {string} pOptions.baseDir
|
|
52
|
+
* @param {(pString:string) => Array<import("watskeburt").IChange>} pOptions.diffListFn
|
|
53
|
+
* @param {(import("watskeburt").IChange) => import("../..").IRevisionChange} pOptions.checksumFn
|
|
54
|
+
* @returns {import("../..").IRevisionData}
|
|
55
|
+
*/
|
|
56
|
+
getRevisionData(pDirectory, pCachedCruiseResult, pCruiseOptions, pOptions) {
|
|
57
|
+
const lOptions = {
|
|
58
|
+
diffListFn: findContentChanges,
|
|
59
|
+
checksumFn: addCheckSumToChange,
|
|
60
|
+
baseDir: process.cwd(),
|
|
61
|
+
...pOptions,
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
SHA1: "unknown-in-content-cache-strategy",
|
|
65
|
+
changes: lOptions
|
|
66
|
+
.diffListFn(pDirectory, pCachedCruiseResult, {
|
|
67
|
+
baseDir: lOptions.baseDir,
|
|
68
|
+
extensions: lOptions.extensions,
|
|
69
|
+
includeOnly: pCruiseOptions.includeOnly,
|
|
70
|
+
exclude: pCruiseOptions.exclude,
|
|
71
|
+
})
|
|
72
|
+
.filter(isInterestingChangeType(lOptions.interestingChangeTypes)),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
201
75
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
76
|
+
/**
|
|
77
|
+
* @param {import("../..").IRevisionData} pExistingRevisionData
|
|
78
|
+
* @param {import("../..").IRevisionData} pNewRevisionData
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
revisionDataEqual(pExistingRevisionData, pNewRevisionData) {
|
|
82
|
+
return (
|
|
83
|
+
Boolean(pExistingRevisionData) &&
|
|
84
|
+
Boolean(pNewRevisionData) &&
|
|
85
|
+
// Even though we don't really have a SHA1, it might be the previous version
|
|
86
|
+
// of the cache did, e.g. because it was rendered with the metadata cache
|
|
87
|
+
// strategy. In that case the SHA1 comparison is a reliable, fast bailout.
|
|
88
|
+
pExistingRevisionData.SHA1 === pNewRevisionData.SHA1 &&
|
|
89
|
+
isDeepStrictEqual(pExistingRevisionData.changes, pNewRevisionData.changes)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
210
92
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
93
|
+
/**
|
|
94
|
+
* @param {import("../..").ICruiseResult} pCruiseResult
|
|
95
|
+
* @param {import("../..").IRevisionData} pRevisionData
|
|
96
|
+
* @returns {import("../..").ICruiseResult}
|
|
97
|
+
*/
|
|
98
|
+
prepareRevisionDataForSaving(pCruiseResult, pRevisionData) {
|
|
99
|
+
const lModulesWithCheckSum = pCruiseResult.modules.map(
|
|
100
|
+
addCheckSumToModule(pCruiseResult.summary.optionsUsed.baseDir)
|
|
101
|
+
);
|
|
102
|
+
const lRevisionData = {
|
|
103
|
+
...pRevisionData,
|
|
104
|
+
changes: refreshChanges(pRevisionData.changes, lModulesWithCheckSum),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
...pCruiseResult,
|
|
109
|
+
modules: lModulesWithCheckSum,
|
|
110
|
+
revisionData: lRevisionData,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
215
113
|
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const { join } = require("path").posix;
|
|
2
|
+
const bus = require("../utl/bus");
|
|
3
|
+
const { DEBUG } = require("../utl/bus-log-levels");
|
|
4
|
+
const findAllFiles = require("../utl/find-all-files");
|
|
5
|
+
const {
|
|
6
|
+
getFileHash,
|
|
7
|
+
excludeFilter,
|
|
8
|
+
includeOnlyFilter,
|
|
9
|
+
hasInterestingExtension,
|
|
10
|
+
moduleIsInterestingForDiff,
|
|
11
|
+
} = require("./utl");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {Set<string>} pFileSet
|
|
15
|
+
* @param {typeof getFileHash} pFileHashFunction
|
|
16
|
+
* @returns {(pModule:import("../..").IModule) => import('../..').IRevisionChange}
|
|
17
|
+
*/
|
|
18
|
+
function diffCachedModuleAgainstFileSet(
|
|
19
|
+
pFileSet,
|
|
20
|
+
pBaseDirectory,
|
|
21
|
+
pFileHashFunction = getFileHash
|
|
22
|
+
) {
|
|
23
|
+
return (pModule) => {
|
|
24
|
+
if (!moduleIsInterestingForDiff(pModule)) {
|
|
25
|
+
return { name: pModule.source, changeType: "ignored" };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!pFileSet.has(pModule.source)) {
|
|
29
|
+
return { name: pModule.source, changeType: "deleted" };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const lNewCheckSum = pFileHashFunction(
|
|
33
|
+
join(pBaseDirectory, pModule.source)
|
|
34
|
+
);
|
|
35
|
+
if (lNewCheckSum !== pModule.checksum) {
|
|
36
|
+
return {
|
|
37
|
+
name: pModule.source,
|
|
38
|
+
changeType: "modified",
|
|
39
|
+
checksum: lNewCheckSum,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
name: pModule.source,
|
|
45
|
+
changeType: "unmodified",
|
|
46
|
+
checksum: pModule.checksum,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
We can run into these scenarios:
|
|
53
|
+
- there is no cache yet:
|
|
54
|
+
modules will === []; all files will be marked as 'added'
|
|
55
|
+
- there is a cache and it contains checksums:
|
|
56
|
+
- existing files that are not in the cache => added
|
|
57
|
+
- modules that are in the cache:
|
|
58
|
+
- don't exist anymore => deleted TODO:
|
|
59
|
+
we might wrongly bump into this for files that are gitignored and that don't have an interesting extension
|
|
60
|
+
- cached checksum === current checksum => not a change; left out
|
|
61
|
+
- cached checksum !== current checksum => modified
|
|
62
|
+
- there is a cache, but it doesn't contain checksums => same as before, except
|
|
63
|
+
all files will be marked as 'modified'
|
|
64
|
+
* @param {string} pDirectory
|
|
65
|
+
* @param {import("../..").ICruiseResult} pCachedCruiseResult
|
|
66
|
+
* @param {Object} pOptions
|
|
67
|
+
* @param {Set<string>} pOptions.extensions
|
|
68
|
+
* @param {string} pOptions.baseDir
|
|
69
|
+
* @returns {{source: string; changeType: import("watskeburt").changeTypeType; checksum: string}[]}
|
|
70
|
+
*/
|
|
71
|
+
module.exports = function findContentChanges(
|
|
72
|
+
pDirectory,
|
|
73
|
+
pCachedCruiseResult,
|
|
74
|
+
pOptions
|
|
75
|
+
) {
|
|
76
|
+
bus.emit("progress", "cache: - hauling revision data", { level: DEBUG });
|
|
77
|
+
const lFileSet = new Set(
|
|
78
|
+
findAllFiles(pDirectory, {
|
|
79
|
+
baseDir: pOptions.baseDir,
|
|
80
|
+
excludeFilterFn: excludeFilter(pOptions.exclude),
|
|
81
|
+
includeOnlyFilterFn: includeOnlyFilter(pOptions.includeOnly),
|
|
82
|
+
}).filter(hasInterestingExtension(pOptions.extensions))
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
bus.emit("progress", "cache: - determining cached vs new", { level: DEBUG });
|
|
86
|
+
const lDiffCachedVsNew = pCachedCruiseResult.modules.map(
|
|
87
|
+
diffCachedModuleAgainstFileSet(lFileSet, pOptions.baseDir)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
bus.emit("progress", "cache: - determining new vs cached", { level: DEBUG });
|
|
91
|
+
lDiffCachedVsNew.forEach(({ name }) => lFileSet.delete(name));
|
|
92
|
+
|
|
93
|
+
const lDiffNewVsCached = [];
|
|
94
|
+
for (let lFileName of lFileSet) {
|
|
95
|
+
lDiffNewVsCached.push({
|
|
96
|
+
name: lFileName,
|
|
97
|
+
changeType: "added",
|
|
98
|
+
checksum: getFileHash(join(pOptions.baseDir, lFileName)),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
bus.emit("progress", "cache: - returning revision data", { level: DEBUG });
|
|
103
|
+
return lDiffCachedVsNew.concat(lDiffNewVsCached);
|
|
104
|
+
};
|
|
@@ -5,86 +5,77 @@ const {
|
|
|
5
5
|
addCheckSumToChange,
|
|
6
6
|
excludeFilter,
|
|
7
7
|
includeOnlyFilter,
|
|
8
|
-
|
|
8
|
+
changeHasInterestingExtension,
|
|
9
9
|
} = require("./utl");
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
pDirectory,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
shaRetrievalFn: getSHASync,
|
|
31
|
-
diffListFn: listSync,
|
|
32
|
-
checksumFn: addCheckSumToChange,
|
|
33
|
-
...pOptions,
|
|
34
|
-
};
|
|
35
|
-
try {
|
|
36
|
-
const lSHA = lOptions.shaRetrievalFn();
|
|
37
|
-
return {
|
|
38
|
-
SHA1: lSHA,
|
|
39
|
-
changes: lOptions
|
|
40
|
-
.diffListFn(lSHA)
|
|
41
|
-
.filter(({ name }) => excludeFilter(pCruiseOptions.exclude)(name))
|
|
42
|
-
.filter(({ name }) =>
|
|
43
|
-
includeOnlyFilter(pCruiseOptions.includeOnly)(name)
|
|
44
|
-
)
|
|
45
|
-
.filter(hasInterestingExtension(lOptions.extensions))
|
|
46
|
-
.filter(isInterestingChangeType(lOptions.interestingChangeTypes))
|
|
47
|
-
.map(lOptions.checksumFn),
|
|
11
|
+
module.exports = class MetaDataStrategy {
|
|
12
|
+
/**
|
|
13
|
+
* @param {Set<string>} pExtensions
|
|
14
|
+
* @param {Set<import("watskeburt").changeTypeType>} pInterestingChangeTypes
|
|
15
|
+
* @param {import("../../types/strict-options").IStrictCruiseOptions} pCruiseOptions
|
|
16
|
+
* @param {Object} pOptions
|
|
17
|
+
* @param {Set<string>} pOptions.extensions
|
|
18
|
+
* @param {Set<import("watskeburt").changeTypeType>} pOptions.interestingChangeTypes
|
|
19
|
+
* @param {() => string} pOptions.shaRetrievalFn
|
|
20
|
+
* @param {(pString:string) => Array<import("watskeburt").IChange>} pOptions.diffListFn
|
|
21
|
+
* @param {(import("watskeburt").IChange) => import("../..").IRevisionChange} pOptions.checksumFn
|
|
22
|
+
* @returns {import("../..").IRevisionData}
|
|
23
|
+
*/
|
|
24
|
+
getRevisionData(pDirectory, pCachedCruiseResult, pCruiseOptions, pOptions) {
|
|
25
|
+
const lOptions = {
|
|
26
|
+
shaRetrievalFn: getSHASync,
|
|
27
|
+
diffListFn: listSync,
|
|
28
|
+
checksumFn: addCheckSumToChange,
|
|
29
|
+
...pOptions,
|
|
48
30
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
31
|
+
try {
|
|
32
|
+
const lSHA = lOptions.shaRetrievalFn();
|
|
33
|
+
return {
|
|
34
|
+
SHA1: lSHA,
|
|
35
|
+
changes: lOptions
|
|
36
|
+
.diffListFn(lSHA)
|
|
37
|
+
.filter(({ name }) => excludeFilter(pCruiseOptions.exclude)(name))
|
|
38
|
+
.filter(({ name }) =>
|
|
39
|
+
includeOnlyFilter(pCruiseOptions.includeOnly)(name)
|
|
40
|
+
)
|
|
41
|
+
.filter(changeHasInterestingExtension(lOptions.extensions))
|
|
42
|
+
.filter(isInterestingChangeType(lOptions.interestingChangeTypes))
|
|
43
|
+
.map(lOptions.checksumFn),
|
|
44
|
+
};
|
|
45
|
+
} catch (pError) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"The --cache option works in concert with git - and it seems either the " +
|
|
48
|
+
"current folder isn't version managed or git isn't installed. Error:" +
|
|
49
|
+
`\n\n ${pError}\n`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
55
52
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {import("../..").IRevisionData} pExistingRevisionData
|
|
60
|
-
* @param {import("../..").IRevisionData} pNewRevisionData
|
|
61
|
-
* @returns {boolean}
|
|
62
|
-
*/
|
|
63
|
-
function revisionDataEqual(pExistingRevisionData, pNewRevisionData) {
|
|
64
|
-
return (
|
|
65
|
-
Boolean(pExistingRevisionData) &&
|
|
66
|
-
Boolean(pNewRevisionData) &&
|
|
67
|
-
pExistingRevisionData.SHA1 === pNewRevisionData.SHA1 &&
|
|
68
|
-
isDeepStrictEqual(pExistingRevisionData.changes, pNewRevisionData.changes)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
53
|
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
54
|
+
/**
|
|
55
|
+
* @param {import("../..").IRevisionData} pExistingRevisionData
|
|
56
|
+
* @param {import("../..").IRevisionData} pNewRevisionData
|
|
57
|
+
* @returns {boolean}
|
|
58
|
+
*/
|
|
59
|
+
revisionDataEqual(pExistingRevisionData, pNewRevisionData) {
|
|
60
|
+
return (
|
|
61
|
+
Boolean(pExistingRevisionData) &&
|
|
62
|
+
Boolean(pNewRevisionData) &&
|
|
63
|
+
pExistingRevisionData.SHA1 === pNewRevisionData.SHA1 &&
|
|
64
|
+
isDeepStrictEqual(pExistingRevisionData.changes, pNewRevisionData.changes)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
85
67
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @param {import("../..").ICruiseResult} pCruiseResult
|
|
70
|
+
* @param {import("../..").IRevisionData} pRevisionData
|
|
71
|
+
* @returns {import("../..").ICruiseResult}
|
|
72
|
+
*/
|
|
73
|
+
prepareRevisionDataForSaving(pCruiseResult, pRevisionData) {
|
|
74
|
+
return pRevisionData
|
|
75
|
+
? {
|
|
76
|
+
...pCruiseResult,
|
|
77
|
+
revisionData: pRevisionData,
|
|
78
|
+
}
|
|
79
|
+
: pCruiseResult;
|
|
80
|
+
}
|
|
90
81
|
};
|
package/src/cache/utl.js
CHANGED
|
@@ -63,23 +63,29 @@ function includeOnlyFilter(pIncludeOnlyFilter) {
|
|
|
63
63
|
return true;
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* @param {Set<string>} pExtensions
|
|
68
|
+
* @returns {(pFileName: string) => boolean}
|
|
69
|
+
*/
|
|
70
|
+
function hasInterestingExtension(pExtensions) {
|
|
71
|
+
return (pFileName) => pExtensions.has(path.extname(pFileName));
|
|
72
|
+
}
|
|
66
73
|
|
|
67
74
|
/**
|
|
68
75
|
* @param {Set<string>} pExtensions
|
|
69
76
|
* @returns {(pChange: import("watskeburt").IChange) => boolean}
|
|
70
77
|
*/
|
|
71
|
-
function
|
|
78
|
+
function changeHasInterestingExtension(pExtensions) {
|
|
72
79
|
return (pChange) =>
|
|
73
|
-
pExtensions
|
|
74
|
-
(pChange.oldName && pExtensions
|
|
80
|
+
hasInterestingExtension(pExtensions)(pChange.name) ||
|
|
81
|
+
(pChange.oldName && hasInterestingExtension(pExtensions)(pChange.oldName));
|
|
75
82
|
}
|
|
76
83
|
|
|
77
|
-
// skipping: "pairing broken", "unmodified", "
|
|
84
|
+
// skipping: "pairing broken", "unmodified", "type changed", "ignored"
|
|
78
85
|
const DEFAULT_INTERESTING_CHANGE_TYPES = new Set([
|
|
79
86
|
"added",
|
|
80
87
|
"copied",
|
|
81
88
|
"deleted",
|
|
82
|
-
"ignored",
|
|
83
89
|
"modified",
|
|
84
90
|
"renamed",
|
|
85
91
|
"unmerged",
|
|
@@ -97,11 +103,25 @@ function isInterestingChangeType(pInterestingChangeTypes) {
|
|
|
97
103
|
);
|
|
98
104
|
}
|
|
99
105
|
|
|
106
|
+
/**
|
|
107
|
+
* @param {pModule:import("../..").IModule} pModule
|
|
108
|
+
*/
|
|
109
|
+
function moduleIsInterestingForDiff(pModule) {
|
|
110
|
+
return (
|
|
111
|
+
!pModule.consolidated &&
|
|
112
|
+
!pModule.coreModule &&
|
|
113
|
+
!pModule.couldNotResolve &&
|
|
114
|
+
!pModule.matchesDoNotFollow
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
100
118
|
module.exports = {
|
|
101
119
|
getFileHash,
|
|
102
120
|
excludeFilter,
|
|
103
121
|
includeOnlyFilter,
|
|
104
122
|
hasInterestingExtension,
|
|
123
|
+
changeHasInterestingExtension,
|
|
105
124
|
isInterestingChangeType,
|
|
106
125
|
addCheckSumToChange,
|
|
126
|
+
moduleIsInterestingForDiff,
|
|
107
127
|
};
|
package/src/main/index.js
CHANGED
|
@@ -63,9 +63,13 @@ function futureCruise(
|
|
|
63
63
|
let lCache = null;
|
|
64
64
|
|
|
65
65
|
if (lCruiseOptions.cache) {
|
|
66
|
-
bus.emit(
|
|
66
|
+
bus.emit(
|
|
67
|
+
"progress",
|
|
68
|
+
`cache: check freshness with ${lCruiseOptions.cache.strategy}`,
|
|
69
|
+
c(2)
|
|
70
|
+
);
|
|
67
71
|
|
|
68
|
-
lCache = new Cache(lCruiseOptions
|
|
72
|
+
lCache = new Cache(lCruiseOptions.cache.strategy);
|
|
69
73
|
const lCachedResults = lCache.read(lCruiseOptions.cache.folder);
|
|
70
74
|
|
|
71
75
|
if (lCache.canServeFromCache(lCruiseOptions, lCachedResults)) {
|
|
@@ -108,7 +112,7 @@ function futureCruise(
|
|
|
108
112
|
);
|
|
109
113
|
|
|
110
114
|
if (lCruiseOptions.cache) {
|
|
111
|
-
bus.emit("progress", "cache:
|
|
115
|
+
bus.emit("progress", "cache: save", c(7));
|
|
112
116
|
lCache.write(lCruiseOptions.cache.folder, lCruiseResult);
|
|
113
117
|
}
|
|
114
118
|
|
package/src/meta.js
CHANGED
|
@@ -3,6 +3,10 @@ const { join } = require("path");
|
|
|
3
3
|
const ignore = require("ignore");
|
|
4
4
|
const pathToPosix = require("./path-to-posix");
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {(pString:string, pIndex: number, pArray: string[]) => boolean} FilterFunctionType
|
|
8
|
+
*/
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* @param {string} pFullPathToFile
|
|
8
12
|
* @param {string} pBaseDirectory
|
|
@@ -19,13 +23,18 @@ function fileIsDirectory(pFullPathToFile, pBaseDirectory) {
|
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* @param {string} pDirectoryName
|
|
22
|
-
* @param {{baseDir: string; ignoreFilterFn:
|
|
26
|
+
* @param {{baseDir: string; ignoreFilterFn: FilterFunctionType; excludeFilterFn: FilterFunctionType; includeOnlyFilterFn: FilterFunctionType}} pOptions
|
|
23
27
|
* @returns {string[]}
|
|
24
28
|
*/
|
|
25
|
-
function walk(
|
|
29
|
+
function walk(
|
|
30
|
+
pDirectoryName,
|
|
31
|
+
{ baseDir, ignoreFilterFn, excludeFilterFn, includeOnlyFilterFn }
|
|
32
|
+
) {
|
|
26
33
|
return readdirSync(join(baseDir, pDirectoryName))
|
|
27
34
|
.map((pFileName) => join(pDirectoryName, pFileName))
|
|
28
35
|
.filter(ignoreFilterFn)
|
|
36
|
+
.filter(excludeFilterFn)
|
|
37
|
+
.filter(includeOnlyFilterFn)
|
|
29
38
|
.map((pFullPathToFile) => ({
|
|
30
39
|
fullPathToFile: pFullPathToFile,
|
|
31
40
|
isDirectory: fileIsDirectory(pFullPathToFile, baseDir),
|
|
@@ -38,7 +47,14 @@ function walk(pDirectoryName, { baseDir, ignoreFilterFn }) {
|
|
|
38
47
|
*/
|
|
39
48
|
(pSum, { fullPathToFile, isDirectory }) => {
|
|
40
49
|
if (isDirectory) {
|
|
41
|
-
return pSum.concat(
|
|
50
|
+
return pSum.concat(
|
|
51
|
+
walk(fullPathToFile, {
|
|
52
|
+
baseDir,
|
|
53
|
+
ignoreFilterFn,
|
|
54
|
+
excludeFilterFn,
|
|
55
|
+
includeOnlyFilterFn,
|
|
56
|
+
})
|
|
57
|
+
);
|
|
42
58
|
}
|
|
43
59
|
return pSum.concat(fullPathToFile);
|
|
44
60
|
},
|
|
@@ -55,14 +71,28 @@ function readIgnoreFile(pFileName) {
|
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @type FilterFunctionType
|
|
76
|
+
*/
|
|
77
|
+
// eslint-disable-next-line no-unused-vars
|
|
78
|
+
function identityFilter(_pString, _pIndex, _pArray) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
58
82
|
/**
|
|
59
83
|
* @param {string} pDirectoryName
|
|
60
|
-
* @param {{baseDir: string; ignoreFileContents?: string; additionalIgnorePatterns?: string[]}} pOptions
|
|
84
|
+
* @param {{baseDir: string; ignoreFileContents?: string; additionalIgnorePatterns?: string[]; excludeFilterFn: FilterFunctionType; includeOnlyFilterFn: FilterFunctionType}} pOptions
|
|
61
85
|
* @returns {string[]}
|
|
62
86
|
*/
|
|
63
87
|
module.exports = function findAllFiles(
|
|
64
88
|
pDirectoryName,
|
|
65
|
-
{
|
|
89
|
+
{
|
|
90
|
+
baseDir,
|
|
91
|
+
ignoreFileContents,
|
|
92
|
+
additionalIgnorePatterns,
|
|
93
|
+
excludeFilterFn,
|
|
94
|
+
includeOnlyFilterFn,
|
|
95
|
+
}
|
|
66
96
|
) {
|
|
67
97
|
const lIgnoreFileContents =
|
|
68
98
|
ignoreFileContents ?? readIgnoreFile(join(baseDir, ".gitignore"));
|
|
@@ -75,5 +105,7 @@ module.exports = function findAllFiles(
|
|
|
75
105
|
return walk(pDirectoryName, {
|
|
76
106
|
baseDir,
|
|
77
107
|
ignoreFilterFn: lIgnoreFilterFunction,
|
|
108
|
+
excludeFilterFn: excludeFilterFn ?? identityFilter,
|
|
109
|
+
includeOnlyFilterFn: includeOnlyFilterFn ?? identityFilter,
|
|
78
110
|
});
|
|
79
111
|
};
|