@lage-run/cache 0.3.0 → 0.4.0
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/CHANGELOG.json +28 -1
- package/CHANGELOG.md +12 -2
- package/lib/TargetHasher.js +22 -0
- package/lib/hashStrings.d.ts +1 -0
- package/lib/hashStrings.js +26 -0
- package/lib/salt.js +21 -74
- package/package.json +5 -7
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,34 @@
|
|
|
2
2
|
"name": "@lage-run/cache",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Wed, 08 Mar 2023 00:05:07 GMT",
|
|
6
|
+
"tag": "@lage-run/cache_v0.4.0",
|
|
7
|
+
"version": "0.4.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "kchau@microsoft.com",
|
|
12
|
+
"package": "@lage-run/cache",
|
|
13
|
+
"commit": "e2eb2c00d1b23e2c65943e9c64134c14e04f985f",
|
|
14
|
+
"comment": "allows global script cache"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "beachball",
|
|
18
|
+
"package": "@lage-run/cache",
|
|
19
|
+
"comment": "Bump @lage-run/hasher to v0.2.0",
|
|
20
|
+
"commit": "e2eb2c00d1b23e2c65943e9c64134c14e04f985f"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"author": "beachball",
|
|
24
|
+
"package": "@lage-run/cache",
|
|
25
|
+
"comment": "Bump @lage-run/target-graph to v0.7.0",
|
|
26
|
+
"commit": "e2eb2c00d1b23e2c65943e9c64134c14e04f985f"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"date": "Tue, 21 Feb 2023 21:30:37 GMT",
|
|
6
33
|
"tag": "@lage-run/cache_v0.3.0",
|
|
7
34
|
"version": "0.3.0",
|
|
8
35
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
# Change Log - @lage-run/cache
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 08 Mar 2023 00:05:07 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.4.0
|
|
8
|
+
|
|
9
|
+
Wed, 08 Mar 2023 00:05:07 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- allows global script cache (kchau@microsoft.com)
|
|
14
|
+
- Bump @lage-run/hasher to v0.2.0
|
|
15
|
+
- Bump @lage-run/target-graph to v0.7.0
|
|
16
|
+
|
|
7
17
|
## 0.3.0
|
|
8
18
|
|
|
9
|
-
Tue, 21 Feb 2023 21:30:
|
|
19
|
+
Tue, 21 Feb 2023 21:30:37 GMT
|
|
10
20
|
|
|
11
21
|
### Minor changes
|
|
12
22
|
|
package/lib/TargetHasher.js
CHANGED
|
@@ -8,11 +8,33 @@ Object.defineProperty(exports, "TargetHasher", {
|
|
|
8
8
|
});
|
|
9
9
|
const _hasher = require("@lage-run/hasher");
|
|
10
10
|
const _saltJs = require("./salt.js");
|
|
11
|
+
const _globHasher = require("glob-hasher");
|
|
12
|
+
const _hashStringsJs = require("./hashStrings.js");
|
|
13
|
+
function sortObject(unordered) {
|
|
14
|
+
return Object.keys(unordered).sort((a, b)=>a.localeCompare(b)).reduce((obj, key)=>{
|
|
15
|
+
obj[key] = unordered[key];
|
|
16
|
+
return obj;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
11
19
|
class TargetHasher {
|
|
12
20
|
async hash(target) {
|
|
21
|
+
const { root } = this.options;
|
|
13
22
|
const hashKey = await (0, _saltJs.salt)(target.environmentGlob ?? this.options.environmentGlob ?? [
|
|
14
23
|
"lage.config.js"
|
|
15
24
|
], `${target.id}|${JSON.stringify(this.options.cliArgs)}`, this.options.root, this.options.cacheKey || "");
|
|
25
|
+
if (target.cwd === root && target.cache) {
|
|
26
|
+
if (!target.inputs) {
|
|
27
|
+
throw new Error("Root-level targets must have `inputs` defined if it has cache enabled.");
|
|
28
|
+
}
|
|
29
|
+
const hashes = (0, _globHasher.hashGlobGit)(target.inputs, {
|
|
30
|
+
cwd: root,
|
|
31
|
+
gitignore: false
|
|
32
|
+
}) ?? {};
|
|
33
|
+
const sortedHashMap = sortObject(hashes);
|
|
34
|
+
const sortedHashes = Object.values(sortedHashMap);
|
|
35
|
+
sortedHashes.push(hashKey);
|
|
36
|
+
return (0, _hashStringsJs.hashStrings)(sortedHashes);
|
|
37
|
+
}
|
|
16
38
|
const hasher = new _hasher.Hasher(target.cwd);
|
|
17
39
|
return hasher.createPackageHash(hashKey);
|
|
18
40
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hashStrings(strings: string | string[]): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "hashStrings", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>hashStrings
|
|
8
|
+
});
|
|
9
|
+
const _crypto = /*#__PURE__*/ _interopRequireDefault(require("crypto"));
|
|
10
|
+
function _interopRequireDefault(obj) {
|
|
11
|
+
return obj && obj.__esModule ? obj : {
|
|
12
|
+
default: obj
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function hashStrings(strings) {
|
|
16
|
+
const hasher = _crypto.default.createHash("sha1");
|
|
17
|
+
const anArray = typeof strings === "string" ? [
|
|
18
|
+
strings
|
|
19
|
+
] : strings;
|
|
20
|
+
const elements = [
|
|
21
|
+
...anArray
|
|
22
|
+
];
|
|
23
|
+
elements.sort((a, b)=>a.localeCompare(b));
|
|
24
|
+
elements.forEach((element)=>hasher.update(element));
|
|
25
|
+
return hasher.digest("hex");
|
|
26
|
+
}
|
package/lib/salt.js
CHANGED
|
@@ -12,49 +12,8 @@ _export(exports, {
|
|
|
12
12
|
"_testResetEnvHash": ()=>_testResetEnvHash,
|
|
13
13
|
salt: ()=>salt
|
|
14
14
|
});
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const _fastGlob = /*#__PURE__*/ _interopRequireWildcard(require("fast-glob"));
|
|
18
|
-
const _promises = /*#__PURE__*/ _interopRequireWildcard(require("fs/promises"));
|
|
19
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
20
|
-
if (typeof WeakMap !== "function") return null;
|
|
21
|
-
var cacheBabelInterop = new WeakMap();
|
|
22
|
-
var cacheNodeInterop = new WeakMap();
|
|
23
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
24
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
25
|
-
})(nodeInterop);
|
|
26
|
-
}
|
|
27
|
-
function _interopRequireWildcard(obj, nodeInterop) {
|
|
28
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
32
|
-
return {
|
|
33
|
-
default: obj
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
37
|
-
if (cache && cache.has(obj)) {
|
|
38
|
-
return cache.get(obj);
|
|
39
|
-
}
|
|
40
|
-
var newObj = {};
|
|
41
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
42
|
-
for(var key in obj){
|
|
43
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
44
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
45
|
-
if (desc && (desc.get || desc.set)) {
|
|
46
|
-
Object.defineProperty(newObj, key, desc);
|
|
47
|
-
} else {
|
|
48
|
-
newObj[key] = obj[key];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
newObj.default = obj;
|
|
53
|
-
if (cache) {
|
|
54
|
-
cache.set(obj, newObj);
|
|
55
|
-
}
|
|
56
|
-
return newObj;
|
|
57
|
-
}
|
|
15
|
+
const _globHasher = require("glob-hasher");
|
|
16
|
+
const _hashStringsJs = require("./hashStrings.js");
|
|
58
17
|
let envHashes = {};
|
|
59
18
|
// A promise to guarantee the getEnvHashes is done one at a time
|
|
60
19
|
let oneAtATime = Promise.resolve();
|
|
@@ -63,7 +22,7 @@ function _testResetEnvHash() {
|
|
|
63
22
|
}
|
|
64
23
|
async function salt(environmentGlobFiles, command, repoRoot, customKey = "") {
|
|
65
24
|
const envHash = await getEnvHash(environmentGlobFiles, repoRoot);
|
|
66
|
-
return hashStrings([
|
|
25
|
+
return (0, _hashStringsJs.hashStrings)([
|
|
67
26
|
...envHash,
|
|
68
27
|
command,
|
|
69
28
|
customKey
|
|
@@ -72,6 +31,12 @@ async function salt(environmentGlobFiles, command, repoRoot, customKey = "") {
|
|
|
72
31
|
function envHashKey(environmentGlobFiles) {
|
|
73
32
|
return environmentGlobFiles.sort().join("|");
|
|
74
33
|
}
|
|
34
|
+
function sortObject(unordered) {
|
|
35
|
+
return Object.keys(unordered).sort((a, b)=>a.localeCompare(b)).reduce((obj, key)=>{
|
|
36
|
+
obj[key] = unordered[key];
|
|
37
|
+
return obj;
|
|
38
|
+
}, {});
|
|
39
|
+
}
|
|
75
40
|
async function getEnvHash(environmentGlobFiles, repoRoot) {
|
|
76
41
|
const key = envHashKey(environmentGlobFiles);
|
|
77
42
|
// We want to make sure that we only call getEnvHashOneAtTime one at a time
|
|
@@ -85,35 +50,17 @@ async function getEnvHash(environmentGlobFiles, repoRoot) {
|
|
|
85
50
|
});
|
|
86
51
|
return oneAtATime;
|
|
87
52
|
}
|
|
88
|
-
|
|
89
|
-
const envHash = [];
|
|
90
|
-
const newline = /\r\n|\r|\n/g;
|
|
91
|
-
const LF = "\n";
|
|
92
|
-
const files = _fastGlob.sync(environmentGlobFiles, {
|
|
93
|
-
cwd: repoRoot
|
|
94
|
-
});
|
|
95
|
-
files.sort((a, b)=>a.localeCompare(b));
|
|
96
|
-
for (const file of files){
|
|
97
|
-
const hasher = _crypto.createHash("sha1");
|
|
98
|
-
hasher.update(file);
|
|
99
|
-
const fileBuffer = await _promises.readFile(_path.join(repoRoot, file), "utf-8");
|
|
100
|
-
const data = fileBuffer.replace(newline, LF);
|
|
101
|
-
hasher.update(data);
|
|
102
|
-
envHash.push(hasher.digest("hex"));
|
|
103
|
-
}
|
|
53
|
+
function getEnvHashOneAtTime(environmentGlobFiles, repoRoot) {
|
|
104
54
|
const key = envHashKey(environmentGlobFiles);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
];
|
|
116
|
-
elements.sort((a, b)=>a.localeCompare(b));
|
|
117
|
-
elements.forEach((element)=>hasher.update(element));
|
|
118
|
-
return hasher.digest("hex");
|
|
55
|
+
if (environmentGlobFiles.length === 0) {
|
|
56
|
+
envHashes[key] = [];
|
|
57
|
+
return envHashes[key];
|
|
58
|
+
}
|
|
59
|
+
const hashes = (0, _globHasher.hashGlobGit)(environmentGlobFiles, {
|
|
60
|
+
cwd: repoRoot,
|
|
61
|
+
gitignore: false
|
|
62
|
+
});
|
|
63
|
+
const sortedHashes = sortObject(hashes);
|
|
64
|
+
envHashes[key] = Object.values(sortedHashes);
|
|
65
|
+
return envHashes[key];
|
|
119
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lage-run/cache",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Cache for Lage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/microsoft/lage"
|
|
@@ -15,19 +15,17 @@
|
|
|
15
15
|
"lint": "monorepo-scripts lint"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lage-run/hasher": "^0.
|
|
19
|
-
"@lage-run/target-graph": "^0.
|
|
18
|
+
"@lage-run/hasher": "^0.2.0",
|
|
19
|
+
"@lage-run/target-graph": "^0.7.0",
|
|
20
20
|
"@lage-run/logger": "^1.2.2",
|
|
21
21
|
"backfill-config": "^6.3.0",
|
|
22
22
|
"backfill-cache": "^5.6.1",
|
|
23
23
|
"backfill-logger": "^5.1.3",
|
|
24
|
-
"
|
|
24
|
+
"glob-hasher": "1.1.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@lage-run/monorepo-fixture": "*",
|
|
28
|
-
"
|
|
29
|
-
"monorepo-scripts": "*",
|
|
30
|
-
"mock-fs": "5.2.0"
|
|
28
|
+
"monorepo-scripts": "*"
|
|
31
29
|
},
|
|
32
30
|
"publishConfig": {
|
|
33
31
|
"access": "public"
|