@lage-run/cache 0.5.4 → 1.1.1
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 +22 -1
- package/CHANGELOG.md +11 -2
- package/lib/backfillWrapper.js +13 -9
- package/lib/chunkPromise.js +3 -1
- package/lib/getCacheDirectory.js +11 -5
- package/lib/index.d.ts +0 -1
- package/lib/index.js +18 -10
- package/lib/providers/BackfillCacheProvider.js +33 -14
- package/lib/providers/RemoteFallbackCacheProvider.js +19 -3
- package/package.json +3 -5
- package/lib/TargetHasher.d.ts +0 -18
- package/lib/TargetHasher.js +0 -49
- package/lib/hashStrings.d.ts +0 -1
- package/lib/hashStrings.js +0 -26
- package/lib/salt.d.ts +0 -2
- package/lib/salt.js +0 -67
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,28 @@
|
|
|
2
2
|
"name": "@lage-run/cache",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Mon, 08 May 2023 22:26:52 GMT",
|
|
6
|
+
"tag": "@lage-run/cache_v1.1.1",
|
|
7
|
+
"version": "1.1.1",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "kchau@microsoft.com",
|
|
12
|
+
"package": "@lage-run/cache",
|
|
13
|
+
"commit": "5a132808f166179bc316a279c9e11a13d3a39103",
|
|
14
|
+
"comment": "Moved the TargetHasher into @lage-run/hasher package"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "beachball",
|
|
18
|
+
"package": "@lage-run/cache",
|
|
19
|
+
"comment": "Bump @lage-run/target-graph to v0.8.6",
|
|
20
|
+
"commit": "5a132808f166179bc316a279c9e11a13d3a39103"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"date": "Tue, 25 Apr 2023 02:51:19 GMT",
|
|
6
27
|
"tag": "@lage-run/cache_v0.5.4",
|
|
7
28
|
"version": "0.5.4",
|
|
8
29
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# Change Log - @lage-run/cache
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 08 May 2023 22:26:52 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.1.1
|
|
8
|
+
|
|
9
|
+
Mon, 08 May 2023 22:26:52 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Moved the TargetHasher into @lage-run/hasher package (kchau@microsoft.com)
|
|
14
|
+
- Bump @lage-run/target-graph to v0.8.6
|
|
15
|
+
|
|
7
16
|
## 0.5.4
|
|
8
17
|
|
|
9
|
-
Tue, 25 Apr 2023 02:
|
|
18
|
+
Tue, 25 Apr 2023 02:51:19 GMT
|
|
10
19
|
|
|
11
20
|
### Patches
|
|
12
21
|
|
package/lib/backfillWrapper.js
CHANGED
|
@@ -11,12 +11,16 @@ function _export(target, all) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
_export(exports, {
|
|
14
|
-
createBackfillLogger: ()
|
|
15
|
-
|
|
14
|
+
createBackfillLogger: function() {
|
|
15
|
+
return createBackfillLogger;
|
|
16
|
+
},
|
|
17
|
+
createBackfillCacheConfig: function() {
|
|
18
|
+
return createBackfillCacheConfig;
|
|
19
|
+
}
|
|
16
20
|
});
|
|
17
|
-
const _os = /*#__PURE__*/
|
|
18
|
-
const
|
|
19
|
-
const
|
|
21
|
+
const _os = /*#__PURE__*/ _interop_require_wildcard(require("os"));
|
|
22
|
+
const _backfillconfig = require("backfill-config");
|
|
23
|
+
const _backfilllogger = require("backfill-logger");
|
|
20
24
|
function _getRequireWildcardCache(nodeInterop) {
|
|
21
25
|
if (typeof WeakMap !== "function") return null;
|
|
22
26
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -25,7 +29,7 @@ function _getRequireWildcardCache(nodeInterop) {
|
|
|
25
29
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
26
30
|
})(nodeInterop);
|
|
27
31
|
}
|
|
28
|
-
function
|
|
32
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
29
33
|
if (!nodeInterop && obj && obj.__esModule) {
|
|
30
34
|
return obj;
|
|
31
35
|
}
|
|
@@ -59,7 +63,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
59
63
|
function createBackfillLogger() {
|
|
60
64
|
const stdout = process.stdout;
|
|
61
65
|
const stderr = process.stderr;
|
|
62
|
-
return (0,
|
|
66
|
+
return (0, _backfilllogger.makeLogger)("error", {
|
|
63
67
|
console: {
|
|
64
68
|
info (...args) {
|
|
65
69
|
stdout.write(args.join(" ") + _os.EOL);
|
|
@@ -74,9 +78,9 @@ function createBackfillLogger() {
|
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
80
|
function createBackfillCacheConfig(cwd, cacheOptions = {}, backfillLogger) {
|
|
77
|
-
const envConfig = (0,
|
|
81
|
+
const envConfig = (0, _backfillconfig.getEnvConfig)(backfillLogger);
|
|
78
82
|
return {
|
|
79
|
-
...(0,
|
|
83
|
+
...(0, _backfillconfig.createDefaultConfig)(cwd),
|
|
80
84
|
...cacheOptions,
|
|
81
85
|
...envConfig
|
|
82
86
|
};
|
package/lib/chunkPromise.js
CHANGED
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "chunkPromise", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return chunkPromise;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
11
|
async function chunkPromise(promises, limit = 5) {
|
|
10
12
|
for(let i = 0; i < promises.length; i += limit){
|
package/lib/getCacheDirectory.js
CHANGED
|
@@ -9,12 +9,18 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
getCacheDirectoryRoot: ()
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
getCacheDirectoryRoot: function() {
|
|
13
|
+
return getCacheDirectoryRoot;
|
|
14
|
+
},
|
|
15
|
+
getCacheDirectory: function() {
|
|
16
|
+
return getCacheDirectory;
|
|
17
|
+
},
|
|
18
|
+
getLogsCacheDirectory: function() {
|
|
19
|
+
return getLogsCacheDirectory;
|
|
20
|
+
}
|
|
15
21
|
});
|
|
16
|
-
const _path = /*#__PURE__*/
|
|
17
|
-
function
|
|
22
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
23
|
+
function _interop_require_default(obj) {
|
|
18
24
|
return obj && obj.__esModule ? obj : {
|
|
19
25
|
default: obj
|
|
20
26
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { BackfillCacheProvider } from "./providers/BackfillCacheProvider.js";
|
|
2
2
|
export { RemoteFallbackCacheProvider } from "./providers/RemoteFallbackCacheProvider.js";
|
|
3
|
-
export { TargetHasher } from "./TargetHasher.js";
|
|
4
3
|
export type { CacheOptions } from "./types/CacheOptions.js";
|
|
5
4
|
export type { CacheProvider } from "./types/CacheProvider.js";
|
|
6
5
|
export { getCacheDirectory, getLogsCacheDirectory, getCacheDirectoryRoot } from "./getCacheDirectory.js";
|
package/lib/index.js
CHANGED
|
@@ -9,14 +9,22 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
BackfillCacheProvider: ()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
BackfillCacheProvider: function() {
|
|
13
|
+
return _BackfillCacheProvider.BackfillCacheProvider;
|
|
14
|
+
},
|
|
15
|
+
RemoteFallbackCacheProvider: function() {
|
|
16
|
+
return _RemoteFallbackCacheProvider.RemoteFallbackCacheProvider;
|
|
17
|
+
},
|
|
18
|
+
getCacheDirectory: function() {
|
|
19
|
+
return _getCacheDirectory.getCacheDirectory;
|
|
20
|
+
},
|
|
21
|
+
getLogsCacheDirectory: function() {
|
|
22
|
+
return _getCacheDirectory.getLogsCacheDirectory;
|
|
23
|
+
},
|
|
24
|
+
getCacheDirectoryRoot: function() {
|
|
25
|
+
return _getCacheDirectory.getCacheDirectoryRoot;
|
|
26
|
+
}
|
|
18
27
|
});
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const _getCacheDirectoryJs = require("./getCacheDirectory.js");
|
|
28
|
+
const _BackfillCacheProvider = require("./providers/BackfillCacheProvider.js");
|
|
29
|
+
const _RemoteFallbackCacheProvider = require("./providers/RemoteFallbackCacheProvider.js");
|
|
30
|
+
const _getCacheDirectory = require("./getCacheDirectory.js");
|
|
@@ -4,15 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "BackfillCacheProvider", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return BackfillCacheProvider;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
+
const _backfillWrapper = require("../backfillWrapper.js");
|
|
12
|
+
const _backfillcache = require("backfill-cache");
|
|
11
13
|
const _util = require("util");
|
|
12
|
-
const _fs = /*#__PURE__*/
|
|
13
|
-
const _path = /*#__PURE__*/
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const _fs = /*#__PURE__*/ _interop_require_wildcard(require("fs"));
|
|
15
|
+
const _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
|
16
|
+
const _getCacheDirectory = require("../getCacheDirectory.js");
|
|
17
|
+
const _chunkPromise = require("../chunkPromise.js");
|
|
18
|
+
function _define_property(obj, key, value) {
|
|
19
|
+
if (key in obj) {
|
|
20
|
+
Object.defineProperty(obj, key, {
|
|
21
|
+
value: value,
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
obj[key] = value;
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
16
31
|
function _getRequireWildcardCache(nodeInterop) {
|
|
17
32
|
if (typeof WeakMap !== "function") return null;
|
|
18
33
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -21,7 +36,7 @@ function _getRequireWildcardCache(nodeInterop) {
|
|
|
21
36
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
22
37
|
})(nodeInterop);
|
|
23
38
|
}
|
|
24
|
-
function
|
|
39
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
25
40
|
if (!nodeInterop && obj && obj.__esModule) {
|
|
26
41
|
return obj;
|
|
27
42
|
}
|
|
@@ -59,9 +74,9 @@ const MS_IN_A_DAY = 1000 * 60 * 60 * 24;
|
|
|
59
74
|
class BackfillCacheProvider {
|
|
60
75
|
getTargetCacheStorageProvider(cwd, hash) {
|
|
61
76
|
const { cacheOptions } = this.options;
|
|
62
|
-
const { cacheStorageConfig , incrementalCaching } = (0,
|
|
77
|
+
const { cacheStorageConfig , incrementalCaching } = (0, _backfillWrapper.createBackfillCacheConfig)(cwd, cacheOptions, this.backfillLogger);
|
|
63
78
|
const cachePath = this.getCachePath(cwd, hash);
|
|
64
|
-
return (0,
|
|
79
|
+
return (0, _backfillcache.getCacheStorageProvider)(cacheStorageConfig ?? {
|
|
65
80
|
provider: "local"
|
|
66
81
|
}, cachePath, this.backfillLogger, cwd, incrementalCaching);
|
|
67
82
|
}
|
|
@@ -117,7 +132,7 @@ class BackfillCacheProvider {
|
|
|
117
132
|
];
|
|
118
133
|
const entries = [];
|
|
119
134
|
for (const cacheType of cacheTypes){
|
|
120
|
-
const cacheTypeDirectory = _path.join((0,
|
|
135
|
+
const cacheTypeDirectory = _path.join((0, _getCacheDirectory.getCacheDirectoryRoot)(this.options.root), cacheType);
|
|
121
136
|
if (_fs.existsSync(cacheTypeDirectory)) {
|
|
122
137
|
const hashPrefixes = await readdir(cacheTypeDirectory);
|
|
123
138
|
for (const prefix of hashPrefixes){
|
|
@@ -126,7 +141,7 @@ class BackfillCacheProvider {
|
|
|
126
141
|
}
|
|
127
142
|
}
|
|
128
143
|
}
|
|
129
|
-
await (0,
|
|
144
|
+
await (0, _chunkPromise.chunkPromise)(entries.map((entry)=>{
|
|
130
145
|
return async ()=>{
|
|
131
146
|
const entryPath = entry;
|
|
132
147
|
const entryStat = await stat(entryPath);
|
|
@@ -137,11 +152,15 @@ class BackfillCacheProvider {
|
|
|
137
152
|
}), concurrency);
|
|
138
153
|
}
|
|
139
154
|
getCachePath(packagePath, hash) {
|
|
140
|
-
return _path.relative(packagePath, (0,
|
|
155
|
+
return _path.relative(packagePath, (0, _getCacheDirectory.getCacheDirectory)(this.options.root, hash));
|
|
141
156
|
}
|
|
142
157
|
constructor(options){
|
|
158
|
+
_define_property(this, "options", void 0);
|
|
159
|
+
/**
|
|
160
|
+
* logger for backfill
|
|
161
|
+
*/ _define_property(this, "backfillLogger", void 0);
|
|
143
162
|
this.options = options;
|
|
144
|
-
this.backfillLogger = (0,
|
|
163
|
+
this.backfillLogger = (0, _backfillWrapper.createBackfillLogger)();
|
|
145
164
|
}
|
|
146
165
|
}
|
|
147
166
|
async function removeCache(cachePath, entryStat) {
|
|
@@ -4,8 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
Object.defineProperty(exports, "RemoteFallbackCacheProvider", {
|
|
6
6
|
enumerable: true,
|
|
7
|
-
get: ()
|
|
7
|
+
get: function() {
|
|
8
|
+
return RemoteFallbackCacheProvider;
|
|
9
|
+
}
|
|
8
10
|
});
|
|
11
|
+
function _define_property(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value: value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
9
24
|
class RemoteFallbackCacheProvider {
|
|
10
25
|
async fetch(hash, target) {
|
|
11
26
|
const { logger , remoteCacheProvider , localCacheProvider } = this.options;
|
|
@@ -62,8 +77,9 @@ class RemoteFallbackCacheProvider {
|
|
|
62
77
|
}
|
|
63
78
|
}
|
|
64
79
|
constructor(options){
|
|
80
|
+
_define_property(this, "options", void 0);
|
|
65
81
|
this.options = options;
|
|
66
82
|
}
|
|
67
83
|
}
|
|
68
|
-
RemoteFallbackCacheProvider
|
|
69
|
-
RemoteFallbackCacheProvider
|
|
84
|
+
_define_property(RemoteFallbackCacheProvider, "localHits", {});
|
|
85
|
+
_define_property(RemoteFallbackCacheProvider, "remoteHits", {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lage-run/cache",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Cache for Lage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,14 +17,12 @@
|
|
|
17
17
|
"lint": "monorepo-scripts lint"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@lage-run/
|
|
21
|
-
"@lage-run/target-graph": "^0.8.4",
|
|
20
|
+
"@lage-run/target-graph": "^0.8.6",
|
|
22
21
|
"@lage-run/logger": "^1.3.0",
|
|
23
22
|
"backfill-config": "^6.3.1",
|
|
24
23
|
"backfill-cache": "^5.6.4",
|
|
25
24
|
"backfill-logger": "^5.1.3",
|
|
26
|
-
"glob-hasher": "1.
|
|
27
|
-
"fast-glob": "3.2.12"
|
|
25
|
+
"glob-hasher": "^1.3.0"
|
|
28
26
|
},
|
|
29
27
|
"devDependencies": {
|
|
30
28
|
"@lage-run/monorepo-fixture": "*",
|
package/lib/TargetHasher.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Target } from "@lage-run/target-graph";
|
|
2
|
-
export interface TargetHasherOptions {
|
|
3
|
-
root: string;
|
|
4
|
-
environmentGlob: string[];
|
|
5
|
-
cacheKey?: string;
|
|
6
|
-
cliArgs?: string[];
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* TargetHasher is a class that can be used to generate a hash of a target.
|
|
10
|
-
*
|
|
11
|
-
* Currently, it encapsulates the use of `backfill-hasher` to generate a hash.
|
|
12
|
-
*/
|
|
13
|
-
export declare class TargetHasher {
|
|
14
|
-
private options;
|
|
15
|
-
private repoInfo?;
|
|
16
|
-
constructor(options: TargetHasherOptions);
|
|
17
|
-
hash(target: Target): Promise<string>;
|
|
18
|
-
}
|
package/lib/TargetHasher.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "TargetHasher", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>TargetHasher
|
|
8
|
-
});
|
|
9
|
-
const _hasher = require("@lage-run/hasher");
|
|
10
|
-
const _saltJs = require("./salt.js");
|
|
11
|
-
const _globHasher = require("glob-hasher");
|
|
12
|
-
const _fastGlob = /*#__PURE__*/ _interopRequireDefault(require("fast-glob"));
|
|
13
|
-
const _hashStringsJs = require("./hashStrings.js");
|
|
14
|
-
function _interopRequireDefault(obj) {
|
|
15
|
-
return obj && obj.__esModule ? obj : {
|
|
16
|
-
default: obj
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
class TargetHasher {
|
|
20
|
-
async hash(target) {
|
|
21
|
-
const { root } = this.options;
|
|
22
|
-
const hashKey = await (0, _saltJs.salt)(target.environmentGlob ?? this.options.environmentGlob ?? [
|
|
23
|
-
"lage.config.js"
|
|
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 files = await (0, _fastGlob.default)(target.inputs, {
|
|
30
|
-
cwd: root
|
|
31
|
-
});
|
|
32
|
-
const fileFashes = (0, _globHasher.hash)(files, {
|
|
33
|
-
cwd: root
|
|
34
|
-
}) ?? {};
|
|
35
|
-
const hashes = Object.values(fileFashes);
|
|
36
|
-
hashes.push(hashKey);
|
|
37
|
-
return (0, _hashStringsJs.hashStrings)(hashes);
|
|
38
|
-
}
|
|
39
|
-
if (!this.repoInfo) {
|
|
40
|
-
this.repoInfo = await (0, _hasher.getRepoInfo)(root);
|
|
41
|
-
}
|
|
42
|
-
const hasher = new _hasher.Hasher(target.cwd, this.repoInfo);
|
|
43
|
-
const hashString = hasher.createPackageHash(hashKey);
|
|
44
|
-
return hashString;
|
|
45
|
-
}
|
|
46
|
-
constructor(options){
|
|
47
|
-
this.options = options;
|
|
48
|
-
}
|
|
49
|
-
}
|
package/lib/hashStrings.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function hashStrings(strings: string | string[]): string;
|
package/lib/hashStrings.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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.d.ts
DELETED
package/lib/salt.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
"_testResetEnvHash": ()=>_testResetEnvHash,
|
|
13
|
-
salt: ()=>salt
|
|
14
|
-
});
|
|
15
|
-
const _globHasher = require("glob-hasher");
|
|
16
|
-
const _hashStringsJs = require("./hashStrings.js");
|
|
17
|
-
const _fastGlob = /*#__PURE__*/ _interopRequireDefault(require("fast-glob"));
|
|
18
|
-
function _interopRequireDefault(obj) {
|
|
19
|
-
return obj && obj.__esModule ? obj : {
|
|
20
|
-
default: obj
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
let envHashes = {};
|
|
24
|
-
// A promise to guarantee the getEnvHashes is done one at a time
|
|
25
|
-
let oneAtATime = Promise.resolve();
|
|
26
|
-
function _testResetEnvHash() {
|
|
27
|
-
envHashes = {};
|
|
28
|
-
}
|
|
29
|
-
async function salt(environmentGlobFiles, command, repoRoot, customKey = "") {
|
|
30
|
-
const envHash = await getEnvHash(environmentGlobFiles, repoRoot);
|
|
31
|
-
return (0, _hashStringsJs.hashStrings)([
|
|
32
|
-
...envHash,
|
|
33
|
-
command,
|
|
34
|
-
customKey
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
function envHashKey(environmentGlobFiles) {
|
|
38
|
-
return environmentGlobFiles.sort().join("|");
|
|
39
|
-
}
|
|
40
|
-
async function getEnvHash(environmentGlobFiles, repoRoot) {
|
|
41
|
-
const key = envHashKey(environmentGlobFiles);
|
|
42
|
-
// We want to make sure that we only call getEnvHashOneAtTime one at a time
|
|
43
|
-
// to avoid having many concurrent calls to read files again and again
|
|
44
|
-
oneAtATime = oneAtATime.then(async ()=>{
|
|
45
|
-
// we may already have it by time we get to here
|
|
46
|
-
if (envHashes[key]) {
|
|
47
|
-
return envHashes[key];
|
|
48
|
-
}
|
|
49
|
-
return getEnvHashOneAtTime(environmentGlobFiles, repoRoot);
|
|
50
|
-
});
|
|
51
|
-
return oneAtATime;
|
|
52
|
-
}
|
|
53
|
-
async function getEnvHashOneAtTime(environmentGlobFiles, root) {
|
|
54
|
-
const key = envHashKey(environmentGlobFiles);
|
|
55
|
-
if (environmentGlobFiles.length === 0) {
|
|
56
|
-
envHashes[key] = [];
|
|
57
|
-
return envHashes[key];
|
|
58
|
-
}
|
|
59
|
-
const files = await (0, _fastGlob.default)(environmentGlobFiles, {
|
|
60
|
-
cwd: root
|
|
61
|
-
});
|
|
62
|
-
const fileFashes = (0, _globHasher.hash)(files, {
|
|
63
|
-
cwd: root
|
|
64
|
-
}) ?? {};
|
|
65
|
-
envHashes[key] = Object.values(fileFashes);
|
|
66
|
-
return envHashes[key];
|
|
67
|
-
}
|