@lage-run/hasher 1.2.1 → 1.3.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 CHANGED
@@ -2,7 +2,37 @@
2
2
  "name": "@lage-run/hasher",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 25 Jun 2024 22:03:26 GMT",
5
+ "date": "Wed, 04 Sep 2024 23:24:50 GMT",
6
+ "version": "1.3.1",
7
+ "tag": "@lage-run/hasher_v1.3.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "kchau@microsoft.com",
12
+ "package": "@lage-run/hasher",
13
+ "commit": "cbfd60ade539086a6a797c0674e06f26cfc06af3",
14
+ "comment": "Use file hashes instead of just the file names for env glob for targets\\"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Fri, 30 Aug 2024 18:40:09 GMT",
21
+ "version": "1.3.0",
22
+ "tag": "@lage-run/hasher_v1.3.0",
23
+ "comments": {
24
+ "minor": [
25
+ {
26
+ "author": "kchau@microsoft.com",
27
+ "package": "@lage-run/hasher",
28
+ "commit": "962af15909d64159bbc5fef954e66b6bd4c410d1",
29
+ "comment": "adding the ability to calculate target env globs"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Tue, 25 Jun 2024 22:03:40 GMT",
6
36
  "version": "1.2.1",
7
37
  "tag": "@lage-run/hasher_v1.2.1",
8
38
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,28 @@
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 Wed, 04 Sep 2024 23:24:50 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.3.1
8
+
9
+ Wed, 04 Sep 2024 23:24:50 GMT
10
+
11
+ ### Patches
12
+
13
+ - Use file hashes instead of just the file names for env glob for targets\ (kchau@microsoft.com)
14
+
15
+ ## 1.3.0
16
+
17
+ Fri, 30 Aug 2024 18:40:09 GMT
18
+
19
+ ### Minor changes
20
+
21
+ - adding the ability to calculate target env globs (kchau@microsoft.com)
22
+
7
23
  ## 1.2.1
8
24
 
9
- Tue, 25 Jun 2024 22:03:26 GMT
25
+ Tue, 25 Jun 2024 22:03:40 GMT
10
26
 
11
27
  ### Patches
12
28
 
@@ -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 = Object.values(target.environmentGlob ? this.fileHasher.hash(await this.getMemorizedEnvGlobResults(target.environmentGlob)) : 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 global2: boolean;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  const _path = /*#__PURE__*/ _interop_require_default(require("path"));
6
6
  const _index = require("../index");
7
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
7
8
  const _monorepofixture = require("@lage-run/monorepo-fixture");
8
9
  function _interop_require_default(obj) {
9
10
  return obj && obj.__esModule ? obj : {
@@ -125,4 +126,69 @@ describe("The main Hasher class", ()=>{
125
126
  monorepo1.cleanup();
126
127
  monorepo2.cleanup();
127
128
  });
129
+ it("creates different hashes when the target has a different env glob", async ()=>{
130
+ const monorepo1 = await setupFixture("monorepo-with-global-files");
131
+ const hasher = new _index.TargetHasher({
132
+ root: monorepo1.root,
133
+ environmentGlob: []
134
+ });
135
+ const target = createTarget(monorepo1.root, "package-a", "build");
136
+ target.environmentGlob = [
137
+ "some-global*"
138
+ ];
139
+ target.inputs = [
140
+ "**/*",
141
+ "^**/*"
142
+ ];
143
+ const hash = await getHash(hasher, target);
144
+ const target2 = createTarget(monorepo1.root, "package-a", "build");
145
+ target2.environmentGlob = [
146
+ "some-global.*"
147
+ ];
148
+ target2.inputs = [
149
+ "**/*",
150
+ "^**/*"
151
+ ];
152
+ const hash2 = await getHash(hasher, target2);
153
+ expect(hash).not.toEqual(hash2);
154
+ monorepo1.cleanup();
155
+ });
156
+ it("creates different hashes when the target has a different env glob for different task types", async ()=>{
157
+ const monorepo1 = await setupFixture("monorepo-with-global-files-different-tasks");
158
+ const hasher = new _index.TargetHasher({
159
+ root: monorepo1.root,
160
+ environmentGlob: []
161
+ });
162
+ const target = createTarget(monorepo1.root, "package-a", "test");
163
+ target.environmentGlob = [
164
+ "some-global*"
165
+ ];
166
+ target.inputs = [
167
+ "**/*",
168
+ "^**/*"
169
+ ];
170
+ const hash = await getHash(hasher, target);
171
+ const target2 = createTarget(monorepo1.root, "package-a", "lint");
172
+ target2.environmentGlob = [
173
+ ".eslintrc.js"
174
+ ];
175
+ target2.inputs = [
176
+ "**/*",
177
+ "^**/*"
178
+ ];
179
+ const hash2 = await getHash(hasher, target2);
180
+ const target3 = createTarget(monorepo1.root, "package-a", "lint");
181
+ _fs.default.writeFileSync(_path.default.join(monorepo1.root, ".eslintrc.js"), "module.exports = {/*somethingdifferent*/};");
182
+ target3.environmentGlob = [
183
+ ".eslintrc.js"
184
+ ];
185
+ target3.inputs = [
186
+ "**/*",
187
+ "^**/*"
188
+ ];
189
+ const hash3 = await getHash(hasher, target3);
190
+ expect(hash).not.toEqual(hash2);
191
+ expect(hash2).not.toEqual(hash3);
192
+ monorepo1.cleanup();
193
+ });
128
194
  });
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.1",
4
4
  "description": "Hasher for Lage Targets",
5
5
  "repository": {
6
6
  "url": "https://github.com/microsoft/lage"