@lage-run/hasher
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -5,3 +5,18 @@ { | ||
{ | ||
"date": "Tue, 25 Jun 2024 22:03:26 GMT", | ||
"date": "Fri, 30 Aug 2024 18:39:54 GMT", | ||
"version": "1.3.0", | ||
"tag": "@lage-run/hasher_v1.3.0", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"author": "kchau@microsoft.com", | ||
"package": "@lage-run/hasher", | ||
"commit": "962af15909d64159bbc5fef954e66b6bd4c410d1", | ||
"comment": "adding the ability to calculate target env globs" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Tue, 25 Jun 2024 22:03:40 GMT", | ||
"version": "1.2.1", | ||
@@ -8,0 +23,0 @@ "tag": "@lage-run/hasher_v1.2.1", |
# Change Log - @lage-run/hasher | ||
This log was last generated on Tue, 25 Jun 2024 22:03:26 GMT and should not be manually modified. | ||
This log was last generated on Fri, 30 Aug 2024 18:39:54 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## 1.3.0 | ||
Fri, 30 Aug 2024 18:39:54 GMT | ||
### Minor changes | ||
- adding the ability to calculate target env globs (kchau@microsoft.com) | ||
## 1.2.1 | ||
Tue, 25 Jun 2024 22:03:26 GMT | ||
Tue, 25 Jun 2024 22:03:40 GMT | ||
@@ -11,0 +19,0 @@ ### Patches |
@@ -128,2 +128,29 @@ "use strict"; | ||
}); | ||
it("creates different hashes when the target has a different env glob", async ()=>{ | ||
const monorepo1 = await setupFixture("monorepo-with-global-files"); | ||
const hasher = new _index.TargetHasher({ | ||
root: monorepo1.root, | ||
environmentGlob: [] | ||
}); | ||
const target = createTarget(monorepo1.root, "package-a", "build"); | ||
target.environmentGlob = [ | ||
"some-global*" | ||
]; | ||
target.inputs = [ | ||
"**/*", | ||
"^**/*" | ||
]; | ||
const hash = await getHash(hasher, target); | ||
const target2 = createTarget(monorepo1.root, "package-a", "build"); | ||
target2.environmentGlob = [ | ||
"some-global.*" | ||
]; | ||
target2.inputs = [ | ||
"**/*", | ||
"^**/*" | ||
]; | ||
const hash2 = await getHash(hasher, target2); | ||
expect(hash).not.toEqual(hash2); | ||
monorepo1.cleanup(); | ||
}); | ||
}); |
@@ -43,2 +43,4 @@ import type { Target } from "@lage-run/target-graph"; | ||
dependencyMap: DependencyMap; | ||
memoizedEnvGlobResults: Map<string, string[]>; | ||
getMemorizedEnvGlobResults(envGlob: string[]): Promise<string[]>; | ||
getPackageInfos(workspacePackages: WorkspaceInfo): PackageInfos; | ||
@@ -45,0 +47,0 @@ expandInputPatterns(patterns: string[], target: Target): Record<string, string[]>; |
@@ -41,2 +41,13 @@ "use strict"; | ||
class TargetHasher { | ||
async getMemorizedEnvGlobResults(envGlob) { | ||
const key = envGlob.join("\0ENV_GLOB\0"); | ||
const { root } = this.options; | ||
if (!this.memoizedEnvGlobResults.has(key)) { | ||
const files = await (0, _fastglob.default)(envGlob, { | ||
cwd: root | ||
}); | ||
this.memoizedEnvGlobResults.set(key, files); | ||
} | ||
return this.memoizedEnvGlobResults.get(key) ?? []; | ||
} | ||
getPackageInfos(workspacePackages) { | ||
@@ -114,5 +125,3 @@ const { root } = this.options; | ||
this.initializedPromise = Promise.all([ | ||
this.fileHasher.readManifest().then(()=>(0, _fastglob.default)(environmentGlob, { | ||
cwd: root | ||
})).then((files)=>this.fileHasher.hash(files)).then((hash)=>this.globalInputsHash = hash), | ||
this.fileHasher.readManifest().then(()=>this.getMemorizedEnvGlobResults(environmentGlob)).then((files)=>this.fileHasher.hash(files)).then((hash)=>this.globalInputsHash = hash), | ||
(0, _workspacetools.getWorkspacesAsync)(root).then((workspaceInfo)=>this.workspaceInfo = workspaceInfo).then(()=>{ | ||
@@ -186,5 +195,6 @@ this.packageInfos = this.getPackageInfos(this.workspaceInfo); | ||
const targetDepHashes = target.dependencies?.sort().map((targetDep)=>this.targetHashes[targetDep]); | ||
const envGlobFiles = target.environmentGlob ? await this.getMemorizedEnvGlobResults(target.environmentGlob) : Object.values(this.globalInputsHash ?? {}); | ||
const combinedHashes = [ | ||
// Environmental hashes | ||
...Object.values(this.globalInputsHash ?? {}), | ||
...envGlobFiles, | ||
`${target.id}|${JSON.stringify(this.options.cliArgs)}`, | ||
@@ -217,2 +227,3 @@ this.options.cacheKey || "", | ||
_define_property(this, "dependencyMap", void 0); | ||
_define_property(this, "memoizedEnvGlobResults", void 0); | ||
this.options = options; | ||
@@ -225,2 +236,3 @@ this.packageInfos = {}; | ||
}; | ||
this.memoizedEnvGlobResults = new Map(); | ||
const { root , logger } = options; | ||
@@ -227,0 +239,0 @@ this.logger = logger; |
{ | ||
"name": "@lage-run/hasher", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Hasher for Lage Targets", | ||
@@ -5,0 +5,0 @@ "repository": { |
96183
39
2306