@lage-run/cache 0.1.21 → 0.1.23

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 CHANGED
@@ -2,7 +2,37 @@
2
2
  "name": "@lage-run/cache",
3
3
  "entries": [
4
4
  {
5
- "date": "Sun, 23 Oct 2022 04:31:33 GMT",
5
+ "date": "Tue, 25 Oct 2022 00:06:34 GMT",
6
+ "tag": "@lage-run/cache_v0.1.23",
7
+ "version": "0.1.23",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "kchau@microsoft.com",
12
+ "package": "@lage-run/cache",
13
+ "commit": "1f0d69225e193de2c9495d9fe7a6e331ea8a3284",
14
+ "comment": "recover the cache check to not bombard with file reads"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Mon, 24 Oct 2022 21:40:05 GMT",
21
+ "tag": "@lage-run/cache_v0.1.22",
22
+ "version": "0.1.22",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "kchau@microsoft.com",
27
+ "package": "@lage-run/cache",
28
+ "commit": "c91040aa0f9d6e804c300e18a1b41295c242fa4e",
29
+ "comment": "Fixed salt to not have race conditions with env hash calculations"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Sun, 23 Oct 2022 04:31:57 GMT",
6
36
  "tag": "@lage-run/cache_v0.1.21",
7
37
  "version": "0.1.21",
8
38
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,28 @@
1
1
  # Change Log - @lage-run/cache
2
2
 
3
- This log was last generated on Sun, 23 Oct 2022 04:31:33 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 25 Oct 2022 00:06:34 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.1.23
8
+
9
+ Tue, 25 Oct 2022 00:06:34 GMT
10
+
11
+ ### Patches
12
+
13
+ - recover the cache check to not bombard with file reads (kchau@microsoft.com)
14
+
15
+ ## 0.1.22
16
+
17
+ Mon, 24 Oct 2022 21:40:05 GMT
18
+
19
+ ### Patches
20
+
21
+ - Fixed salt to not have race conditions with env hash calculations (kchau@microsoft.com)
22
+
7
23
  ## 0.1.21
8
24
 
9
- Sun, 23 Oct 2022 04:31:33 GMT
25
+ Sun, 23 Oct 2022 04:31:57 GMT
10
26
 
11
27
  ### Patches
12
28
 
package/lib/salt.js CHANGED
@@ -28,33 +28,52 @@ const path = __importStar(require("path"));
28
28
  const crypto = __importStar(require("crypto"));
29
29
  const fg = __importStar(require("fast-glob"));
30
30
  const fs = __importStar(require("fs/promises"));
31
- let envHash = undefined;
31
+ let envHashes = {};
32
+ // A promise to guarantee the getEnvHashes is done one at a time
33
+ let oneAtATime = Promise.resolve();
32
34
  function _testResetEnvHash() {
33
- envHash = undefined;
35
+ envHashes = {};
34
36
  }
35
37
  exports._testResetEnvHash = _testResetEnvHash;
36
38
  async function salt(environmentGlobFiles, command, repoRoot, customKey = "") {
37
- return hashStrings([...(await getEnvHash(environmentGlobFiles, repoRoot)), command, customKey]);
39
+ const envHash = await getEnvHash(environmentGlobFiles, repoRoot);
40
+ return hashStrings([...envHash, command, customKey]);
38
41
  }
39
42
  exports.salt = salt;
43
+ function envHashKey(environmentGlobFiles) {
44
+ return environmentGlobFiles.sort().join("|");
45
+ }
40
46
  async function getEnvHash(environmentGlobFiles, repoRoot) {
41
- if (!envHash) {
42
- envHash = [];
43
- const newline = /\r\n|\r|\n/g;
44
- const LF = "\n";
45
- const files = fg.sync(environmentGlobFiles, {
46
- cwd: repoRoot,
47
- });
48
- files.sort((a, b) => a.localeCompare(b));
49
- for (const file of files) {
50
- const hasher = crypto.createHash("sha1");
51
- hasher.update(file);
52
- const fileBuffer = await fs.readFile(path.join(repoRoot, file), "utf-8");
53
- const data = fileBuffer.replace(newline, LF);
54
- hasher.update(data);
55
- envHash.push(hasher.digest("hex"));
47
+ const key = envHashKey(environmentGlobFiles);
48
+ // We want to make sure that we only call getEnvHashOneAtTime one at a time
49
+ // to avoid having many concurrent calls to read files again and again
50
+ oneAtATime = oneAtATime.then(() => {
51
+ // we may already have it by time we get to here
52
+ if (envHashes[key]) {
53
+ return envHashes[key];
56
54
  }
55
+ return getEnvHashOneAtTime(environmentGlobFiles, repoRoot);
56
+ });
57
+ return oneAtATime;
58
+ }
59
+ async function getEnvHashOneAtTime(environmentGlobFiles, repoRoot) {
60
+ const envHash = [];
61
+ const newline = /\r\n|\r|\n/g;
62
+ const LF = "\n";
63
+ const files = fg.sync(environmentGlobFiles, {
64
+ cwd: repoRoot,
65
+ });
66
+ files.sort((a, b) => a.localeCompare(b));
67
+ for (const file of files) {
68
+ const hasher = crypto.createHash("sha1");
69
+ hasher.update(file);
70
+ const fileBuffer = await fs.readFile(path.join(repoRoot, file), "utf-8");
71
+ const data = fileBuffer.replace(newline, LF);
72
+ hasher.update(data);
73
+ envHash.push(hasher.digest("hex"));
57
74
  }
75
+ const key = envHashKey(environmentGlobFiles);
76
+ envHashes[key] = envHash;
58
77
  return envHash;
59
78
  }
60
79
  function hashStrings(strings) {
package/lib/salt.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"salt.js","sourceRoot":"","sources":["../src/salt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+CAAiC;AACjC,8CAAgC;AAChC,gDAAkC;AAElC,IAAI,OAAO,GAAyB,SAAS,CAAC;AAE9C,SAAgB,iBAAiB;IAC/B,OAAO,GAAG,SAAS,CAAC;AACtB,CAAC;AAFD,8CAEC;AAEM,KAAK,UAAU,IAAI,CAAC,oBAA8B,EAAE,OAAe,EAAE,QAAgB,EAAE,SAAS,GAAG,EAAE;IAC1G,OAAO,WAAW,CAAC,CAAC,GAAG,CAAC,MAAM,UAAU,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;AAClG,CAAC;AAFD,oBAEC;AAED,KA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AC;AAED,SAAS,WAAW,CAAC,OAA0B;IAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAClE,MAAM,QAAQ,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAEtD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lage-run/cache",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "Cache for Lage",
5
5
  "repository": {
6
6
  "url": "https://github.com/microsoft/lage"