@lage-run/hasher 1.2.1 → 1.3.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 CHANGED
@@ -2,7 +2,22 @@
2
2
  "name": "@lage-run/hasher",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 25 Jun 2024 22:03:26 GMT",
5
+ "date": "Fri, 30 Aug 2024 18:39:54 GMT",
6
+ "version": "1.3.0",
7
+ "tag": "@lage-run/hasher_v1.3.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "kchau@microsoft.com",
12
+ "package": "@lage-run/hasher",
13
+ "commit": "962af15909d64159bbc5fef954e66b6bd4c410d1",
14
+ "comment": "adding the ability to calculate target env globs"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Tue, 25 Jun 2024 22:03:40 GMT",
6
21
  "version": "1.2.1",
7
22
  "tag": "@lage-run/hasher_v1.2.1",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # Change Log - @lage-run/hasher
2
2
 
3
- This log was last generated on Tue, 25 Jun 2024 22:03:26 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 30 Aug 2024 18:39:54 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.3.0
8
+
9
+ Fri, 30 Aug 2024 18:39:54 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - adding the ability to calculate target env globs (kchau@microsoft.com)
14
+
7
15
  ## 1.2.1
8
16
 
9
- Tue, 25 Jun 2024 22:03:26 GMT
17
+ Tue, 25 Jun 2024 22:03:40 GMT
10
18
 
11
19
  ### Patches
12
20
 
@@ -40,6 +40,8 @@ export declare class TargetHasher {
40
40
  lockInfo: ParsedLock | undefined;
41
41
  targetHashes: Record<string, string>;
42
42
  dependencyMap: DependencyMap;
43
+ memoizedEnvGlobResults: Map<string, string[]>;
44
+ getMemorizedEnvGlobResults(envGlob: string[]): Promise<string[]>;
43
45
  getPackageInfos(workspacePackages: WorkspaceInfo): PackageInfos;
44
46
  expandInputPatterns(patterns: string[], target: Target): Record<string, string[]>;
45
47
  constructor(options: TargetHasherOptions);
@@ -38,6 +38,17 @@ function _interop_require_default(obj) {
38
38
  };
39
39
  }
40
40
  class TargetHasher {
41
+ async getMemorizedEnvGlobResults(envGlob) {
42
+ const key = envGlob.join("\0ENV_GLOB\0");
43
+ const { root } = this.options;
44
+ if (!this.memoizedEnvGlobResults.has(key)) {
45
+ const files = await (0, _fastglob.default)(envGlob, {
46
+ cwd: root
47
+ });
48
+ this.memoizedEnvGlobResults.set(key, files);
49
+ }
50
+ return this.memoizedEnvGlobResults.get(key) ?? [];
51
+ }
41
52
  getPackageInfos(workspacePackages) {
42
53
  const { root } = this.options;
43
54
  const packageInfos = {};
@@ -110,9 +121,7 @@ class TargetHasher {
110
121
  return;
111
122
  }
112
123
  this.initializedPromise = Promise.all([
113
- this.fileHasher.readManifest().then(()=>(0, _fastglob.default)(environmentGlob, {
114
- cwd: root
115
- })).then((files)=>this.fileHasher.hash(files)).then((hash)=>this.globalInputsHash = hash),
124
+ this.fileHasher.readManifest().then(()=>this.getMemorizedEnvGlobResults(environmentGlob)).then((files)=>this.fileHasher.hash(files)).then((hash)=>this.globalInputsHash = hash),
116
125
  (0, _workspacetools.getWorkspacesAsync)(root).then((workspaceInfo)=>this.workspaceInfo = workspaceInfo).then(()=>{
117
126
  this.packageInfos = this.getPackageInfos(this.workspaceInfo);
118
127
  this.dependencyMap = (0, _workspacetools.createDependencyMap)(this.packageInfos, {
@@ -181,9 +190,10 @@ class TargetHasher {
181
190
  const fileHashes = this.fileHasher.hash(files) ?? {}; // this list is sorted by file name
182
191
  // get target hashes
183
192
  const targetDepHashes = target.dependencies?.sort().map((targetDep)=>this.targetHashes[targetDep]);
193
+ const envGlobFiles = target.environmentGlob ? await this.getMemorizedEnvGlobResults(target.environmentGlob) : Object.values(this.globalInputsHash ?? {});
184
194
  const combinedHashes = [
185
195
  // Environmental hashes
186
- ...Object.values(this.globalInputsHash ?? {}),
196
+ ...envGlobFiles,
187
197
  `${target.id}|${JSON.stringify(this.options.cliArgs)}`,
188
198
  this.options.cacheKey || "",
189
199
  // File content hashes based on target.inputs
@@ -211,6 +221,7 @@ class TargetHasher {
211
221
  _define_property(this, "lockInfo", void 0);
212
222
  _define_property(this, "targetHashes", void 0);
213
223
  _define_property(this, "dependencyMap", void 0);
224
+ _define_property(this, "memoizedEnvGlobResults", void 0);
214
225
  this.options = options;
215
226
  this.packageInfos = {};
216
227
  this.targetHashes = {};
@@ -218,6 +229,7 @@ class TargetHasher {
218
229
  dependencies: new Map(),
219
230
  dependents: new Map()
220
231
  };
232
+ this.memoizedEnvGlobResults = new Map();
221
233
  const { root , logger } = options;
222
234
  this.logger = logger;
223
235
  this.fileHasher = new _FileHasher.FileHasher({
@@ -0,0 +1 @@
1
+ export const global: boolean;
@@ -0,0 +1 @@
1
+ export const global: boolean;
@@ -125,4 +125,31 @@ describe("The main Hasher class", ()=>{
125
125
  monorepo1.cleanup();
126
126
  monorepo2.cleanup();
127
127
  });
128
+ it("creates different hashes when the target has a different env glob", async ()=>{
129
+ const monorepo1 = await setupFixture("monorepo-with-global-files");
130
+ const hasher = new _index.TargetHasher({
131
+ root: monorepo1.root,
132
+ environmentGlob: []
133
+ });
134
+ const target = createTarget(monorepo1.root, "package-a", "build");
135
+ target.environmentGlob = [
136
+ "some-global*"
137
+ ];
138
+ target.inputs = [
139
+ "**/*",
140
+ "^**/*"
141
+ ];
142
+ const hash = await getHash(hasher, target);
143
+ const target2 = createTarget(monorepo1.root, "package-a", "build");
144
+ target2.environmentGlob = [
145
+ "some-global.*"
146
+ ];
147
+ target2.inputs = [
148
+ "**/*",
149
+ "^**/*"
150
+ ];
151
+ const hash2 = await getHash(hasher, target2);
152
+ expect(hash).not.toEqual(hash2);
153
+ monorepo1.cleanup();
154
+ });
128
155
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lage-run/hasher",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Hasher for Lage Targets",
5
5
  "repository": {
6
6
  "url": "https://github.com/microsoft/lage"