@lage-run/hasher 1.1.2 → 1.2.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,28 @@
2
2
  "name": "@lage-run/hasher",
3
3
  "entries": [
4
4
  {
5
- "date": "Mon, 10 Jun 2024 23:50:24 GMT",
5
+ "date": "Tue, 25 Jun 2024 18:10:41 GMT",
6
+ "version": "1.2.0",
7
+ "tag": "@lage-run/hasher_v1.2.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "kchau@microsoft.com",
12
+ "package": "@lage-run/hasher",
13
+ "commit": "e294f805313ceb5b66640f8aaff8647bdb588511",
14
+ "comment": "moving back to using globby instead for speed & accuracy reasons"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@lage-run/hasher",
19
+ "comment": "Bump @lage-run/globby to v14.0.2",
20
+ "commit": "not available"
21
+ }
22
+ ]
23
+ }
24
+ },
25
+ {
26
+ "date": "Mon, 10 Jun 2024 23:50:39 GMT",
6
27
  "version": "1.1.2",
7
28
  "tag": "@lage-run/hasher_v1.1.2",
8
29
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @lage-run/hasher
2
2
 
3
- This log was last generated on Mon, 10 Jun 2024 23:50:24 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 25 Jun 2024 18:10:41 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.2.0
8
+
9
+ Tue, 25 Jun 2024 18:10:41 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - moving back to using globby instead for speed & accuracy reasons (kchau@microsoft.com)
14
+ - Bump @lage-run/globby to v14.0.2
15
+
7
16
  ## 1.1.2
8
17
 
9
- Mon, 10 Jun 2024 23:50:24 GMT
18
+ Mon, 10 Jun 2024 23:50:39 GMT
10
19
 
11
20
  ### Patches
12
21
 
@@ -8,9 +8,8 @@ Object.defineProperty(exports, "PackageTree", {
8
8
  return PackageTree;
9
9
  }
10
10
  });
11
- const _execa = /*#__PURE__*/ _interop_require_default(require("execa"));
12
11
  const _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
- const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
+ const _globby = require("@lage-run/globby");
14
13
  function _check_private_redeclaration(obj, privateCollection) {
15
14
  if (privateCollection.has(obj)) {
16
15
  throw new TypeError("Cannot initialize the same private elements twice on an object");
@@ -79,11 +78,9 @@ function _interop_require_default(obj) {
79
78
  default: obj
80
79
  };
81
80
  }
82
- var _tree = /*#__PURE__*/ new WeakMap(), _packageFiles = /*#__PURE__*/ new WeakMap(), _memoizedPackageFiles = /*#__PURE__*/ new WeakMap(), _findFilesFromGitTree = /*#__PURE__*/ new WeakSet();
81
+ var _memoizedPackageFiles = /*#__PURE__*/ new WeakMap(), _findFilesFromGitTree = /*#__PURE__*/ new WeakSet();
83
82
  class PackageTree {
84
83
  reset() {
85
- _class_private_field_set(this, _tree, {});
86
- _class_private_field_set(this, _packageFiles, {});
87
84
  _class_private_field_set(this, _memoizedPackageFiles, {});
88
85
  }
89
86
  async initialize() {
@@ -92,7 +89,7 @@ class PackageTree {
92
89
  async findFilesInPath(packagePath, patterns) {
93
90
  const key = `${packagePath}\0${patterns.join("\0")}`;
94
91
  if (!_class_private_field_get(this, _memoizedPackageFiles)[key]) {
95
- const files = (await _class_private_method_get(this, _findFilesFromGitTree, findFilesFromGitTree).call(this, packagePath, patterns)).map((f)=>_path.default.join(packagePath, f));
92
+ const files = await _class_private_method_get(this, _findFilesFromGitTree, findFilesFromGitTree).call(this, packagePath, patterns);
96
93
  _class_private_field_get(this, _memoizedPackageFiles)[key] = files;
97
94
  }
98
95
  return _class_private_field_get(this, _memoizedPackageFiles)[key];
@@ -101,58 +98,23 @@ class PackageTree {
101
98
  constructor(options){
102
99
  _class_private_method_init(this, _findFilesFromGitTree);
103
100
  _define_property(this, "options", void 0);
104
- _class_private_field_init(this, _tree, {
105
- writable: true,
106
- value: void 0
107
- });
108
- _class_private_field_init(this, _packageFiles, {
109
- writable: true,
110
- value: void 0
111
- });
112
101
  _class_private_field_init(this, _memoizedPackageFiles, {
113
102
  writable: true,
114
103
  value: void 0
115
104
  });
116
105
  this.options = options;
117
- _class_private_field_set(this, _tree, {});
118
- _class_private_field_set(this, _packageFiles, {});
119
106
  _class_private_field_set(this, _memoizedPackageFiles, {});
120
107
  }
121
108
  }
122
109
  async function findFilesFromGitTree(packagePath, patterns) {
123
- const { includeUntracked } = this.options;
124
110
  const cwd = _path.default.isAbsolute(packagePath) ? packagePath : _path.default.join(this.options.root, packagePath);
125
- const trackedPromise = (0, _execa.default)("git", [
126
- "ls-files",
127
- "-z",
128
- ...patterns.filter((p)=>!p.startsWith("!")).map((p)=>`:(glob)${p}`),
129
- ...patterns.filter((p)=>p.startsWith("!")).map((p)=>`:(exclude,glob)${p.slice(1)}`)
130
- ], {
131
- cwd
132
- }).then((lsFilesResults)=>{
133
- if (lsFilesResults.exitCode === 0) {
134
- return lsFilesResults.stdout.split("\0").filter((f)=>Boolean(f) && _fs.default.existsSync(_path.default.join(cwd, f)));
135
- }
136
- return [];
137
- });
138
- const untrackedPromise = includeUntracked ? (0, _execa.default)("git", [
139
- "ls-files",
140
- "-z",
141
- "-o",
142
- "--exclude-standard",
143
- ...patterns.filter((p)=>!p.startsWith("!")).map((p)=>`:(glob)${p}`),
144
- ...patterns.filter((p)=>p.startsWith("!")).map((p)=>`:(exclude,glob)${p.slice(1)}`)
145
- ], {
146
- cwd
147
- }).then((lsOtherResults)=>{
148
- if (lsOtherResults.exitCode === 0) {
149
- return lsOtherResults.stdout.split("\0").filter((f)=>Boolean(f));
150
- }
151
- return [];
152
- }) : Promise.resolve([]);
153
- const [trackedFiles, untrackedFiles] = await Promise.all([
154
- trackedPromise,
155
- untrackedPromise
156
- ]);
157
- return trackedFiles.concat(untrackedFiles);
111
+ return (0, _globby.globby)(patterns, {
112
+ cwd,
113
+ onlyFiles: true,
114
+ ignore: [
115
+ ".git"
116
+ ],
117
+ gitignore: true,
118
+ absolute: true
119
+ }) ?? [];
158
120
  }
@@ -117,7 +117,13 @@ class TargetHasher {
117
117
  const finderInitPromise = this.packageTree.initialize();
118
118
  this.initializedPromise = finderInitPromise.then(()=>{
119
119
  return Promise.all([
120
- this.fileHasher.readManifest().then(()=>environmentGlob.length > 0 ? this.packageTree.findFilesInPath(root, environmentGlob) : []).then((files)=>this.fileHasher.hash(files)).then((hash)=>this.globalInputsHash = hash),
120
+ this.fileHasher.readManifest().then(()=>environmentGlob.length > 0 ? this.packageTree.findFilesInPath(root, environmentGlob) : []).then((files)=>{
121
+ if (this.logger !== undefined) {
122
+ this.logger.verbose(`Environment glob files:`);
123
+ this.logger.silly(" " + files.join("\n "));
124
+ }
125
+ return this.fileHasher.hash(files);
126
+ }).then((hash)=>this.globalInputsHash = hash),
121
127
  (0, _workspacetools.parseLockFile)(root).then((lockInfo)=>this.lockInfo = lockInfo)
122
128
  ]);
123
129
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
1
+ // test out the findFilesInPath method of the PackageTree
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ const _monorepofixture = require("@lage-run/monorepo-fixture");
7
+ const _PackageTree = require("../PackageTree");
8
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
9
+ function _interop_require_default(obj) {
10
+ return obj && obj.__esModule ? obj : {
11
+ default: obj
12
+ };
13
+ }
14
+ // given various patterns that exercises the globby functionality with extgob, etc.
15
+ describe("PackageTree", ()=>{
16
+ async function setupFixture(fixture = "monorepo") {
17
+ const monorepo = new _monorepofixture.Monorepo(fixture);
18
+ await monorepo.init(_path.default.join(fixturesPath, fixture));
19
+ return monorepo;
20
+ }
21
+ const fixturesPath = _path.default.join(__dirname, "../__fixtures__");
22
+ it("should find all files in a package using globby basic pattern", async ()=>{
23
+ const monorepo = await setupFixture("basic");
24
+ const packagePath = monorepo.root;
25
+ const patterns = [
26
+ "**/*"
27
+ ];
28
+ const packageTree = new _PackageTree.PackageTree({
29
+ root: packagePath,
30
+ includeUntracked: true
31
+ });
32
+ await packageTree.initialize();
33
+ const files = await packageTree.findFilesInPath(packagePath, patterns);
34
+ expect(serializeFiles(files, packagePath)).toMatchInlineSnapshot(`
35
+ [
36
+ "node_modules/package-2/package.json",
37
+ "package.json",
38
+ "src/index.ts",
39
+ "yarn.lock",
40
+ ]
41
+ `);
42
+ monorepo.cleanup();
43
+ });
44
+ it("should find all files in a package using globby with extglob", async ()=>{
45
+ const monorepo = await setupFixture("basic");
46
+ const packagePath = monorepo.root;
47
+ const patterns = [
48
+ "**/*.+(json|ts)",
49
+ "!yarn.lock"
50
+ ];
51
+ const packageTree = new _PackageTree.PackageTree({
52
+ root: packagePath,
53
+ includeUntracked: true
54
+ });
55
+ await packageTree.initialize();
56
+ const files = await packageTree.findFilesInPath(packagePath, patterns);
57
+ expect(serializeFiles(files, packagePath)).toMatchInlineSnapshot(`
58
+ [
59
+ "node_modules/package-2/package.json",
60
+ "package.json",
61
+ "src/index.ts",
62
+ ]
63
+ `);
64
+ monorepo.cleanup();
65
+ });
66
+ it("should find all files in a package using globby with extglob of sub-exclusion pattern", async ()=>{
67
+ const monorepo = await setupFixture("monorepo-with-deps");
68
+ const packagePath = monorepo.root;
69
+ const patterns = [
70
+ "**/!(package.json)"
71
+ ];
72
+ const packageTree = new _PackageTree.PackageTree({
73
+ root: packagePath,
74
+ includeUntracked: true
75
+ });
76
+ await packageTree.initialize();
77
+ const files = await packageTree.findFilesInPath(packagePath, patterns);
78
+ expect(serializeFiles(files, packagePath)).toMatchInlineSnapshot(`
79
+ [
80
+ "node_modules/.yarn-integrity",
81
+ "node_modules/package-a/src/index.ts",
82
+ "node_modules/package-b/src/index.ts",
83
+ "packages/package-a/src/index.ts",
84
+ "packages/package-b/src/index.ts",
85
+ "yarn.lock",
86
+ ]
87
+ `);
88
+ monorepo.cleanup();
89
+ });
90
+ function serializeFiles(files, packagePath) {
91
+ return files.map((p)=>_path.default.relative(packagePath, p)).map((p)=>p.replace(/\\/g, "/")).sort();
92
+ }
93
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lage-run/hasher",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Hasher for Lage Targets",
5
5
  "repository": {
6
6
  "url": "https://github.com/microsoft/lage"
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@lage-run/target-graph": "^0.8.9",
19
+ "@lage-run/globby": "^14.0.2",
19
20
  "@lage-run/logger": "^1.3.0",
20
21
  "execa": "5.1.1",
21
22
  "workspace-tools": "0.36.4",