@lage-run/hasher 0.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.
Files changed (73) hide show
  1. package/.eslintignore +2 -0
  2. package/CHANGELOG.json +20 -0
  3. package/CHANGELOG.md +13 -0
  4. package/README.md +2 -0
  5. package/jest.config.js +1 -0
  6. package/lib/__fixtures__/config/backfill.config.d.ts +1 -0
  7. package/lib/__fixtures__/config/backfill.config.js +5 -0
  8. package/lib/__fixtures__/config/backfill.config.js.map +1 -0
  9. package/lib/__fixtures__/config/packages/package-1/backfill.config.d.ts +0 -0
  10. package/lib/__fixtures__/config/packages/package-1/backfill.config.js +2 -0
  11. package/lib/__fixtures__/config/packages/package-1/backfill.config.js.map +1 -0
  12. package/lib/__tests__/createPackageHashes.test.d.ts +1 -0
  13. package/lib/__tests__/createPackageHashes.test.js +43 -0
  14. package/lib/__tests__/createPackageHashes.test.js.map +1 -0
  15. package/lib/__tests__/getPackageDeps.test.d.ts +1 -0
  16. package/lib/__tests__/getPackageDeps.test.js +287 -0
  17. package/lib/__tests__/getPackageDeps.test.js.map +1 -0
  18. package/lib/__tests__/getRepoDeps.test.d.ts +1 -0
  19. package/lib/__tests__/getRepoDeps.test.js +238 -0
  20. package/lib/__tests__/getRepoDeps.test.js.map +1 -0
  21. package/lib/__tests__/getRepoState.test.d.ts +1 -0
  22. package/lib/__tests__/getRepoState.test.js +67 -0
  23. package/lib/__tests__/getRepoState.test.js.map +1 -0
  24. package/lib/__tests__/hashOfFiles.test.d.ts +1 -0
  25. package/lib/__tests__/hashOfFiles.test.js +100 -0
  26. package/lib/__tests__/hashOfFiles.test.js.map +1 -0
  27. package/lib/__tests__/helpers.test.d.ts +1 -0
  28. package/lib/__tests__/helpers.test.js +27 -0
  29. package/lib/__tests__/helpers.test.js.map +1 -0
  30. package/lib/__tests__/index.test.d.ts +1 -0
  31. package/lib/__tests__/index.test.js +87 -0
  32. package/lib/__tests__/index.test.js.map +1 -0
  33. package/lib/__tests__/resolveDependenciesHelper.d.ts +3 -0
  34. package/lib/__tests__/resolveDependenciesHelper.js +41 -0
  35. package/lib/__tests__/resolveDependenciesHelper.js.map +1 -0
  36. package/lib/__tests__/resolveExternalDependencies.test.d.ts +1 -0
  37. package/lib/__tests__/resolveExternalDependencies.test.js +108 -0
  38. package/lib/__tests__/resolveExternalDependencies.test.js.map +1 -0
  39. package/lib/__tests__/resolveInternalDependencies.test.d.ts +1 -0
  40. package/lib/__tests__/resolveInternalDependencies.test.js +100 -0
  41. package/lib/__tests__/resolveInternalDependencies.test.js.map +1 -0
  42. package/lib/createPackageHashes.d.ts +4 -0
  43. package/lib/createPackageHashes.js +41 -0
  44. package/lib/createPackageHashes.js.map +1 -0
  45. package/lib/getPackageDeps.d.ts +45 -0
  46. package/lib/getPackageDeps.js +254 -0
  47. package/lib/getPackageDeps.js.map +1 -0
  48. package/lib/getRepoState.d.ts +76 -0
  49. package/lib/getRepoState.js +271 -0
  50. package/lib/getRepoState.js.map +1 -0
  51. package/lib/hashOfFiles.d.ts +14 -0
  52. package/lib/hashOfFiles.js +65 -0
  53. package/lib/hashOfFiles.js.map +1 -0
  54. package/lib/hashOfPackage.d.ts +9 -0
  55. package/lib/hashOfPackage.js +52 -0
  56. package/lib/hashOfPackage.js.map +1 -0
  57. package/lib/helpers.d.ts +3 -0
  58. package/lib/helpers.js +31 -0
  59. package/lib/helpers.js.map +1 -0
  60. package/lib/index.d.ts +13 -0
  61. package/lib/index.js +66 -0
  62. package/lib/index.js.map +1 -0
  63. package/lib/repoInfo.d.ts +26 -0
  64. package/lib/repoInfo.js +68 -0
  65. package/lib/repoInfo.js.map +1 -0
  66. package/lib/resolveExternalDependencies.d.ts +11 -0
  67. package/lib/resolveExternalDependencies.js +59 -0
  68. package/lib/resolveExternalDependencies.js.map +1 -0
  69. package/lib/resolveInternalDependencies.d.ts +6 -0
  70. package/lib/resolveInternalDependencies.js +15 -0
  71. package/lib/resolveInternalDependencies.js.map +1 -0
  72. package/package.json +30 -0
  73. package/tsconfig.json +7 -0
@@ -0,0 +1,76 @@
1
+ export interface IGitVersion {
2
+ major: number;
3
+ minor: number;
4
+ patch: number;
5
+ }
6
+ /**
7
+ * Parses the output of the "git ls-tree -r -z" command
8
+ * @internal
9
+ */
10
+ export declare function parseGitLsTree(output: string): Map<string, string>;
11
+ /**
12
+ * Information about the changes to a file.
13
+ * @beta
14
+ */
15
+ export interface IFileDiffStatus {
16
+ mode: string;
17
+ oldhash: string;
18
+ newhash: string;
19
+ status: "A" | "D" | "M";
20
+ }
21
+ /**
22
+ * Parses the output of `git diff-index --color=never --no-renames --no-commit-id -z <REVISION> --
23
+ * Returns a map of file path to diff
24
+ * @internal
25
+ */
26
+ export declare function parseGitDiffIndex(output: string): Map<string, IFileDiffStatus>;
27
+ /**
28
+ * Parses the output of `git status -z -u` to extract the set of files that have changed since HEAD.
29
+ *
30
+ * @param output - The raw output from Git
31
+ * @returns a map of file path to if it exists
32
+ * @internal
33
+ */
34
+ export declare function parseGitStatus(output: string): Map<string, boolean>;
35
+ /**
36
+ * Finds the root of the current Git repository
37
+ *
38
+ * @param cwd - The working directory for which to locate the repository
39
+ * @param gitPath - The path to the Git executable
40
+ *
41
+ * @returns The full path to the root directory of the Git repository
42
+ * @beta
43
+ */
44
+ export declare function getRepoRoot(cwd: string, gitPath?: string): string;
45
+ /**
46
+ * Augments the state value with modifications that are not in the index.
47
+ * @param rootDirectory - The root directory of the Git repository
48
+ * @param state - The current map of git path -> object hash. Will be mutated.
49
+ * @param gitPath - The path to the Git executable
50
+ * @internal
51
+ */
52
+ export declare function applyWorkingTreeState(rootDirectory: string, state: Map<string, string>, gitPath?: string): void;
53
+ /**
54
+ * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.
55
+ * @param cwd - The working directory. Only used to find the repository root.
56
+ * @param gitPath - The path to the Git executable
57
+ * @beta
58
+ */
59
+ export declare function getRepoState(cwd: string, gitPath?: string): Map<string, string>;
60
+ /**
61
+ * Find all changed files tracked by Git, their current hashes, and the nature of the change. Only useful if all changes are staged or committed.
62
+ * @param cwd - The working directory. Only used to find the repository root.
63
+ * @param revision - The Git revision specifier to detect changes relative to. Defaults to HEAD (i.e. will compare staged vs. committed)
64
+ * If comparing against a different branch, call `git merge-base` first to find the target commit.
65
+ * @param gitPath - The path to the Git executable
66
+ * @returns A map from the Git file path to the corresponding file change metadata
67
+ * @beta
68
+ */
69
+ export declare function getRepoChanges(cwd: string, revision?: string, gitPath?: string): Map<string, IFileDiffStatus>;
70
+ /**
71
+ * Checks the git version and throws an error if it is less than the minimum required version.
72
+ *
73
+ * @public
74
+ */
75
+ export declare function ensureGitMinimumVersion(gitPath?: string): void;
76
+ export declare function parseGitVersion(gitVersionOutput: string): IGitVersion;
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseGitVersion = exports.ensureGitMinimumVersion = exports.getRepoChanges = exports.getRepoState = exports.applyWorkingTreeState = exports.getRepoRoot = exports.parseGitStatus = exports.parseGitDiffIndex = exports.parseGitLsTree = void 0;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const MINIMUM_GIT_VERSION = {
9
+ major: 2,
10
+ minor: 20,
11
+ patch: 0,
12
+ };
13
+ /**
14
+ * Parses the output of the "git ls-tree -r -z" command
15
+ * @internal
16
+ */
17
+ function parseGitLsTree(output) {
18
+ const result = new Map();
19
+ // Parse the output
20
+ // With the -z modifier, paths are delimited by nulls
21
+ // A line looks like:
22
+ // <mode> <type> <newhash>\t<path>\0
23
+ // 100644 blob a300ccb0b36bd2c85ef18e3c619a2c747f95959e\ttools/prettier-git/prettier-git.js\0
24
+ let last = 0;
25
+ let index = output.indexOf("\0", last);
26
+ while (index >= 0) {
27
+ const item = output.slice(last, index);
28
+ const tabIndex = item.indexOf("\t");
29
+ const filePath = item.slice(tabIndex + 1);
30
+ // The newHash will be all zeros if the file is deleted, or a hash if it exists
31
+ const hash = item.slice(tabIndex - 40, tabIndex);
32
+ result.set(filePath, hash);
33
+ last = index + 1;
34
+ index = output.indexOf("\0", last);
35
+ }
36
+ return result;
37
+ }
38
+ exports.parseGitLsTree = parseGitLsTree;
39
+ /**
40
+ * Parses the output of `git diff-index --color=never --no-renames --no-commit-id -z <REVISION> --
41
+ * Returns a map of file path to diff
42
+ * @internal
43
+ */
44
+ function parseGitDiffIndex(output) {
45
+ const result = new Map();
46
+ // Parse the output
47
+ // With the -z modifier, paths are delimited by nulls
48
+ // A line looks like:
49
+ // :<oldmode> <newmode> <oldhash> <newhash> <status>\0<path>\0
50
+ // :100644 100644 a300ccb0b36bd2c85ef18e3c619a2c747f95959e 0000000000000000000000000000000000000000 M\0tools/prettier-git/prettier-git.js\0
51
+ let last = 0;
52
+ let index = output.indexOf("\0", last);
53
+ while (index >= 0) {
54
+ const header = output.slice(last, index);
55
+ const status = header.slice(-1);
56
+ last = index + 1;
57
+ index = output.indexOf("\0", last);
58
+ const filePath = output.slice(last, index);
59
+ // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.
60
+ // The newHash will be all zeros if the file is deleted, or a hash if it exists
61
+ const mode = header.slice(8, 14);
62
+ const oldhash = header.slice(-83, -43);
63
+ const newhash = header.slice(-42, -2);
64
+ result.set(filePath, {
65
+ mode,
66
+ oldhash,
67
+ newhash,
68
+ status,
69
+ });
70
+ last = index + 1;
71
+ index = output.indexOf("\0", last);
72
+ }
73
+ return result;
74
+ }
75
+ exports.parseGitDiffIndex = parseGitDiffIndex;
76
+ /**
77
+ * Parses the output of `git status -z -u` to extract the set of files that have changed since HEAD.
78
+ *
79
+ * @param output - The raw output from Git
80
+ * @returns a map of file path to if it exists
81
+ * @internal
82
+ */
83
+ function parseGitStatus(output) {
84
+ const result = new Map();
85
+ // Parse the output
86
+ // With the -z modifier, paths are delimited by nulls
87
+ // A line looks like:
88
+ // XY <path>\0
89
+ // M tools/prettier-git/prettier-git.js\0
90
+ let startOfLine = 0;
91
+ let eolIndex = output.indexOf("\0", startOfLine);
92
+ while (eolIndex >= 0) {
93
+ // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.
94
+ // charAt(startOfLine) is the index status, charAt(startOfLine + 1) is the working tree status
95
+ const workingTreeStatus = output.charAt(startOfLine + 1);
96
+ // Deleted in working tree, or not modified in working tree and deleted in index
97
+ const deleted = workingTreeStatus === "D" || (workingTreeStatus === " " && output.charAt(startOfLine) === "D");
98
+ const filePath = output.slice(startOfLine + 3, eolIndex);
99
+ result.set(filePath, !deleted);
100
+ startOfLine = eolIndex + 1;
101
+ eolIndex = output.indexOf("\0", startOfLine);
102
+ }
103
+ return result;
104
+ }
105
+ exports.parseGitStatus = parseGitStatus;
106
+ const repoRootCache = new Map();
107
+ /**
108
+ * Finds the root of the current Git repository
109
+ *
110
+ * @param cwd - The working directory for which to locate the repository
111
+ * @param gitPath - The path to the Git executable
112
+ *
113
+ * @returns The full path to the root directory of the Git repository
114
+ * @beta
115
+ */
116
+ function getRepoRoot(cwd, gitPath) {
117
+ let cachedResult = repoRootCache.get(cwd);
118
+ if (!cachedResult) {
119
+ const result = execa_1.default.sync(gitPath || "git", ["--no-optional-locks", "rev-parse", "--show-toplevel"], {
120
+ cwd,
121
+ });
122
+ if (result.exitCode !== 0) {
123
+ ensureGitMinimumVersion(gitPath);
124
+ throw new Error(`git rev-parse exited with status ${result.exitCode}: ${result.stderr}`);
125
+ }
126
+ repoRootCache.set(cwd, (cachedResult = result.stdout.trim()));
127
+ }
128
+ return cachedResult;
129
+ }
130
+ exports.getRepoRoot = getRepoRoot;
131
+ /**
132
+ * Augments the state value with modifications that are not in the index.
133
+ * @param rootDirectory - The root directory of the Git repository
134
+ * @param state - The current map of git path -> object hash. Will be mutated.
135
+ * @param gitPath - The path to the Git executable
136
+ * @internal
137
+ */
138
+ function applyWorkingTreeState(rootDirectory, state, gitPath) {
139
+ const statusResult = execa_1.default.sync(gitPath || "git", ["--no-optional-locks", "status", "-z", "-u", "--no-renames", "--"], {
140
+ cwd: rootDirectory,
141
+ });
142
+ if (statusResult.exitCode !== 0) {
143
+ ensureGitMinimumVersion(gitPath);
144
+ throw new Error(`git status exited with status ${statusResult.exitCode}: ${statusResult.stderr}`);
145
+ }
146
+ const locallyModified = parseGitStatus(statusResult.stdout);
147
+ const filesToHash = [];
148
+ for (const [filePath, exists] of locallyModified) {
149
+ if (exists) {
150
+ filesToHash.push(filePath);
151
+ }
152
+ else {
153
+ state.delete(filePath);
154
+ }
155
+ }
156
+ if (filesToHash.length) {
157
+ // Use --stdin-paths arg to pass the list of files to git in order to avoid issues with
158
+ // command length
159
+ const hashObjectResult = execa_1.default.sync(gitPath || "git", ["hash-object", "--stdin-paths"], {
160
+ cwd: rootDirectory,
161
+ input: filesToHash.join("\n"),
162
+ });
163
+ if (hashObjectResult.exitCode !== 0) {
164
+ ensureGitMinimumVersion(gitPath);
165
+ throw new Error(`git hash-object exited with status ${hashObjectResult.exitCode}: ${hashObjectResult.stderr}`);
166
+ }
167
+ const hashStdout = hashObjectResult.stdout.trim();
168
+ // The result of "git hash-object" will be a list of file hashes delimited by newlines
169
+ const hashes = hashStdout.split("\n");
170
+ if (hashes.length !== filesToHash.length) {
171
+ throw new Error(`Passed ${filesToHash.length} file paths to Git to hash, but received ${hashes.length} hashes.`);
172
+ }
173
+ const len = hashes.length;
174
+ for (let i = 0; i < len; i++) {
175
+ const hash = hashes[i];
176
+ const filePath = filesToHash[i];
177
+ state.set(filePath, hash);
178
+ }
179
+ }
180
+ }
181
+ exports.applyWorkingTreeState = applyWorkingTreeState;
182
+ /**
183
+ * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.
184
+ * @param cwd - The working directory. Only used to find the repository root.
185
+ * @param gitPath - The path to the Git executable
186
+ * @beta
187
+ */
188
+ function getRepoState(cwd, gitPath) {
189
+ const rootDirectory = getRepoRoot(cwd, gitPath);
190
+ const lsTreeResult = execa_1.default.sync(gitPath || "git", ["--no-optional-locks", "ls-tree", "-r", "-z", "--full-name", "HEAD", "--"], {
191
+ cwd: rootDirectory,
192
+ });
193
+ if (lsTreeResult.exitCode !== 0) {
194
+ ensureGitMinimumVersion(gitPath);
195
+ throw new Error(`git ls-tree exited with status ${lsTreeResult.exitCode}: ${lsTreeResult.stderr}`);
196
+ }
197
+ const state = parseGitLsTree(lsTreeResult.stdout);
198
+ applyWorkingTreeState(rootDirectory, state, gitPath);
199
+ return state;
200
+ }
201
+ exports.getRepoState = getRepoState;
202
+ /**
203
+ * Find all changed files tracked by Git, their current hashes, and the nature of the change. Only useful if all changes are staged or committed.
204
+ * @param cwd - The working directory. Only used to find the repository root.
205
+ * @param revision - The Git revision specifier to detect changes relative to. Defaults to HEAD (i.e. will compare staged vs. committed)
206
+ * If comparing against a different branch, call `git merge-base` first to find the target commit.
207
+ * @param gitPath - The path to the Git executable
208
+ * @returns A map from the Git file path to the corresponding file change metadata
209
+ * @beta
210
+ */
211
+ function getRepoChanges(cwd, revision = "HEAD", gitPath) {
212
+ const rootDirectory = getRepoRoot(cwd, gitPath);
213
+ const result = execa_1.default.sync(gitPath || "git", ["--no-optional-locks", "diff-index", "--color=never", "--no-renames", "--no-commit-id", "--cached", "-z", revision, "--"], {
214
+ cwd: rootDirectory,
215
+ });
216
+ if (result.exitCode !== 0) {
217
+ ensureGitMinimumVersion(gitPath);
218
+ throw new Error(`git diff-index exited with status ${result.exitCode}: ${result.stderr}`);
219
+ }
220
+ const changes = parseGitDiffIndex(result.stdout);
221
+ return changes;
222
+ }
223
+ exports.getRepoChanges = getRepoChanges;
224
+ /**
225
+ * Checks the git version and throws an error if it is less than the minimum required version.
226
+ *
227
+ * @public
228
+ */
229
+ function ensureGitMinimumVersion(gitPath) {
230
+ const gitVersion = getGitVersion(gitPath);
231
+ if (gitVersion.major < MINIMUM_GIT_VERSION.major ||
232
+ (gitVersion.major === MINIMUM_GIT_VERSION.major && gitVersion.minor < MINIMUM_GIT_VERSION.minor) ||
233
+ (gitVersion.major === MINIMUM_GIT_VERSION.major &&
234
+ gitVersion.minor === MINIMUM_GIT_VERSION.minor &&
235
+ gitVersion.patch < MINIMUM_GIT_VERSION.patch)) {
236
+ throw new Error(`The minimum Git version required is ` +
237
+ `${MINIMUM_GIT_VERSION.major}.${MINIMUM_GIT_VERSION.minor}.${MINIMUM_GIT_VERSION.patch}. ` +
238
+ `Your version is ${gitVersion.major}.${gitVersion.minor}.${gitVersion.patch}.`);
239
+ }
240
+ }
241
+ exports.ensureGitMinimumVersion = ensureGitMinimumVersion;
242
+ function getGitVersion(gitPath) {
243
+ const result = execa_1.default.sync(gitPath || "git", ["version"]);
244
+ if (result.exitCode !== 0) {
245
+ throw new Error(`While validating the Git installation, the "git version" command failed with ` + `status ${result.exitCode}: ${result.stderr}`);
246
+ }
247
+ return parseGitVersion(result.stdout);
248
+ }
249
+ function parseGitVersion(gitVersionOutput) {
250
+ // This regexp matches output of "git version" that looks like `git version <number>.<number>.<number>(+whatever)`
251
+ // Examples:
252
+ // - git version 1.2.3
253
+ // - git version 1.2.3.4.5
254
+ // - git version 1.2.3windows.1
255
+ // - git version 1.2.3.windows.1
256
+ const versionRegex = /^git version (\d+)\.(\d+)\.(\d+)/;
257
+ const match = versionRegex.exec(gitVersionOutput);
258
+ if (!match) {
259
+ throw new Error(`While validating the Git installation, the "git version" command produced ` + `unexpected output: "${gitVersionOutput}"`);
260
+ }
261
+ const major = parseInt(match[1], 10);
262
+ const minor = parseInt(match[2], 10);
263
+ const patch = parseInt(match[3], 10);
264
+ return {
265
+ major,
266
+ minor,
267
+ patch,
268
+ };
269
+ }
270
+ exports.parseGitVersion = parseGitVersion;
271
+ //# sourceMappingURL=getRepoState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRepoState.js","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAQ1B,MAAM,mBAAmB,GAAgB;IACvC,KAAK,EAAE,CAAC;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QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE7C,OAAO;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACN,CAAC;AACJ,CAAC;AAxBD,0CAwBC"}
@@ -0,0 +1,14 @@
1
+ import type { RepoInfo } from "./repoInfo.js";
2
+ /**
3
+ * Generates a hash string based on files in a package
4
+ *
5
+ * This implementation relies on `git hash-object` to quickly calculate all files
6
+ * in the repo, caching this result so repeated calls to this function will be
7
+ * a simple lookup.
8
+ *
9
+ * Note: We have to force the types because globby types are wrong
10
+ *
11
+ * @param packageRoot The root of the package
12
+ * @param repoInfo The repoInfo that carries information about repo-wide hashes
13
+ */
14
+ export declare function generateHashOfFiles(packageRoot: string, repoInfo: RepoInfo): Promise<string>;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateHashOfFiles = void 0;
27
+ const path_1 = __importStar(require("path"));
28
+ const helpers_js_1 = require("./helpers.js");
29
+ /**
30
+ * Generates a hash string based on files in a package
31
+ *
32
+ * This implementation relies on `git hash-object` to quickly calculate all files
33
+ * in the repo, caching this result so repeated calls to this function will be
34
+ * a simple lookup.
35
+ *
36
+ * Note: We have to force the types because globby types are wrong
37
+ *
38
+ * @param packageRoot The root of the package
39
+ * @param repoInfo The repoInfo that carries information about repo-wide hashes
40
+ */
41
+ async function generateHashOfFiles(packageRoot, repoInfo) {
42
+ const { repoHashes, root, packageHashes } = repoInfo;
43
+ const hashes = [];
44
+ const packageRelativeRoot = path_1.default.relative(root, packageRoot).replace(/\\/g, "/");
45
+ if (packageHashes[packageRelativeRoot]) {
46
+ // Fast path: if files are clearly inside a package as per the packageHashes cache
47
+ for (const hash of packageHashes[packageRelativeRoot]) {
48
+ hashes.push(hash[0], hash[1]);
49
+ }
50
+ return (0, helpers_js_1.hashStrings)(hashes);
51
+ }
52
+ else {
53
+ // Slow old path: if files are not clearly inside a package (mostly the case for malformed monorepos, like tests)
54
+ const normalized = path_1.default.normalize(packageRoot) + path_1.sep;
55
+ const files = Object.keys(repoHashes).filter((f) => path_1.default.join(root, f).includes(normalized));
56
+ files.sort((a, b) => a.localeCompare(b));
57
+ const hashes = [];
58
+ for (const file of files) {
59
+ hashes.push(file, repoHashes[file]);
60
+ }
61
+ return (0, helpers_js_1.hashStrings)(hashes);
62
+ }
63
+ }
64
+ exports.generateHashOfFiles = generateHashOfFiles;
65
+ //# sourceMappingURL=hashOfFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashOfFiles.js","sourceRoot":"","sources":["../src/hashOfFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;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AW,EAAC,MAAM,CAAC,CAAC;KAC5B;AACH,CAAC;AA5BD,kDA4BC"}
@@ -0,0 +1,9 @@
1
+ import type { RepoInfo } from "./repoInfo.js";
2
+ export declare type PackageHashInfo = {
3
+ name: string;
4
+ filesHash: string;
5
+ dependenciesHash: string;
6
+ internalDependencies: string[];
7
+ };
8
+ export declare function generateHashOfInternalPackages(internalPackages: PackageHashInfo[]): string;
9
+ export declare function getPackageHash(packageRoot: string, repoInfo: RepoInfo): Promise<PackageHashInfo>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getPackageHash = exports.generateHashOfInternalPackages = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const resolveInternalDependencies_js_1 = require("./resolveInternalDependencies.js");
11
+ const resolveExternalDependencies_js_1 = require("./resolveExternalDependencies.js");
12
+ const hashOfFiles_js_1 = require("./hashOfFiles.js");
13
+ const helpers_js_1 = require("./helpers.js");
14
+ function generateHashOfInternalPackages(internalPackages) {
15
+ internalPackages.sort((a, b) => a.name.localeCompare(b.name));
16
+ const hasher = crypto_1.default.createHash("sha1");
17
+ internalPackages.forEach((pkg) => {
18
+ hasher.update(pkg.name);
19
+ hasher.update(pkg.filesHash);
20
+ hasher.update(pkg.dependenciesHash);
21
+ });
22
+ return hasher.digest("hex");
23
+ }
24
+ exports.generateHashOfInternalPackages = generateHashOfInternalPackages;
25
+ const memoization = {};
26
+ async function getPackageHash(packageRoot, repoInfo) {
27
+ const { workspaceInfo, parsedLock } = repoInfo;
28
+ const memoizationKey = path_1.default.resolve(packageRoot);
29
+ if (memoization[memoizationKey]) {
30
+ return memoization[memoizationKey];
31
+ }
32
+ const { name, dependencies, devDependencies } = JSON.parse(fs_1.default.readFileSync(path_1.default.join(packageRoot, "package.json"), "utf-8"));
33
+ const allDependencies = {
34
+ ...dependencies,
35
+ ...devDependencies,
36
+ };
37
+ const internalDependencies = (0, resolveInternalDependencies_js_1.resolveInternalDependencies)(allDependencies, workspaceInfo);
38
+ const externalDeoendencies = (0, resolveExternalDependencies_js_1.resolveExternalDependencies)(allDependencies, workspaceInfo, parsedLock);
39
+ const resolvedDependencies = [...internalDependencies, ...externalDeoendencies];
40
+ const filesHash = await (0, hashOfFiles_js_1.generateHashOfFiles)(packageRoot, repoInfo);
41
+ const dependenciesHash = (0, helpers_js_1.hashStrings)(resolvedDependencies);
42
+ const packageHash = {
43
+ name,
44
+ filesHash,
45
+ dependenciesHash,
46
+ internalDependencies,
47
+ };
48
+ memoization[memoizationKey] = packageHash;
49
+ return packageHash;
50
+ }
51
+ exports.getPackageHash = getPackageHash;
52
+ //# sourceMappingURL=hashOfPackage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashOfPackage.js","sourceRoot":"","sources":["../src/hashOfPackage.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,gDAAwB;AACxB,4CAAoB;AACpB,qFAA+E;AAC/E,qFAA+E;AAE/E,qDAAuD;AACvD,6CAA2C;AAU3C,SAAgB,8BAA8B,CAAC,gBAAmC;IAChF,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAE9D,MAAM,MAAM,GAAG,gBAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACzC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC/B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7B,MAAM,CAAC,MAAM,CAA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AW,CAAC;IAE1C,OAAO,WAAW,CAAC;AACrB,CAAC;AAnCD,wCAmCC"}
@@ -0,0 +1,3 @@
1
+ export declare function hashStrings(strings: string | string[]): string;
2
+ export declare function getPackageRoot(cwd: string): Promise<string>;
3
+ export declare function nameAtVersion(name: string, version: string): string;
package/lib/helpers.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.nameAtVersion = exports.getPackageRoot = exports.hashStrings = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const find_up_1 = __importDefault(require("find-up"));
10
+ function hashStrings(strings) {
11
+ const hasher = crypto_1.default.createHash("sha1");
12
+ const anArray = typeof strings === "string" ? [strings] : strings;
13
+ const elements = [...anArray];
14
+ elements.sort((a, b) => a.localeCompare(b));
15
+ elements.forEach((element) => hasher.update(element));
16
+ return hasher.digest("hex");
17
+ }
18
+ exports.hashStrings = hashStrings;
19
+ async function getPackageRoot(cwd) {
20
+ const packageRoot = await (0, find_up_1.default)("package.json", { cwd });
21
+ if (!packageRoot) {
22
+ throw new Error(`Could not find package.json inside ${cwd}.`);
23
+ }
24
+ return path_1.default.dirname(packageRoot);
25
+ }
26
+ exports.getPackageRoot = getPackageRoot;
27
+ function nameAtVersion(name, version) {
28
+ return `${name}@${version}`;
29
+ }
30
+ exports.nameAtVersion = nameAtVersion;
31
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAA4B;AAC5B,sDAA6B;AAE7B,SAAgB,WAAW,CAAC,OAA0B;IACpD,MAAM,MAAM,GAAG,gBAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAEzC,MAAM,OAAO,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAClE,MAAM,QAAQ,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAEtD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AATD,kCASC;AAEM,KAAK,UAAU,cAAc,CAAC,GAAW;IAC9C,MAAM,WAAW,GAAG,MAAM,IAAA,iBAAM,EAAC,cAAc,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IAE1D,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,GAAG,CAAC,CAAC;KAC/D;IAED,OAAO,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AARD,wCAQC;AAED,SAAgB,aAAa,CAAC,IAAY,EAAE,OAAe;IACzD,OAAO,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC;AAC9B,CAAC;AAFD,sCAEC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { WorkspaceInfo } from "workspace-tools";
2
+ import type { PackageHashInfo } from "./hashOfPackage.js";
3
+ export interface IHasher {
4
+ createPackageHash: (salt: string) => Promise<string>;
5
+ }
6
+ export declare function addToQueue(dependencyNames: string[], queue: string[], done: PackageHashInfo[], workspaces: WorkspaceInfo): void;
7
+ export declare class Hasher implements IHasher {
8
+ private packageRoot;
9
+ private repoInfo?;
10
+ constructor(packageRoot: string);
11
+ createPackageHash(salt: string): Promise<string>;
12
+ }
13
+ export * from "./repoInfo.js";
package/lib/index.js ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Hasher = exports.addToQueue = void 0;
18
+ const workspace_tools_1 = require("workspace-tools");
19
+ const hashOfPackage_js_1 = require("./hashOfPackage.js");
20
+ const helpers_js_1 = require("./helpers.js");
21
+ const repoInfo_js_1 = require("./repoInfo.js");
22
+ function isDone(done, packageName) {
23
+ return Boolean(done.find(({ name }) => name === packageName));
24
+ }
25
+ function isInQueue(queue, packagePath) {
26
+ return queue.indexOf(packagePath) >= 0;
27
+ }
28
+ function addToQueue(dependencyNames, queue, done, workspaces) {
29
+ dependencyNames.forEach((name) => {
30
+ const dependencyPath = (0, workspace_tools_1.findWorkspacePath)(workspaces, name);
31
+ if (dependencyPath) {
32
+ if (!isDone(done, name) && !isInQueue(queue, dependencyPath)) {
33
+ queue.push(dependencyPath);
34
+ }
35
+ }
36
+ });
37
+ }
38
+ exports.addToQueue = addToQueue;
39
+ class Hasher {
40
+ constructor(packageRoot) {
41
+ this.packageRoot = packageRoot;
42
+ }
43
+ async createPackageHash(salt) {
44
+ const packageRoot = await (0, helpers_js_1.getPackageRoot)(this.packageRoot);
45
+ this.repoInfo = await (0, repoInfo_js_1.getRepoInfo)(packageRoot);
46
+ const { workspaceInfo } = this.repoInfo;
47
+ const queue = [packageRoot];
48
+ const done = [];
49
+ while (queue.length > 0) {
50
+ const packageRoot = queue.shift();
51
+ if (!packageRoot) {
52
+ continue;
53
+ }
54
+ const packageHash = await (0, hashOfPackage_js_1.getPackageHash)(packageRoot, this.repoInfo);
55
+ addToQueue(packageHash.internalDependencies, queue, done, workspaceInfo);
56
+ done.push(packageHash);
57
+ }
58
+ const internalPackagesHash = (0, hashOfPackage_js_1.generateHashOfInternalPackages)(done);
59
+ const buildCommandHash = (0, helpers_js_1.hashStrings)(salt);
60
+ const combinedHash = (0, helpers_js_1.hashStrings)([internalPackagesHash, buildCommandHash]);
61
+ return combinedHash;
62
+ }
63
+ }
64
+ exports.Hasher = Hasher;
65
+ __exportStar(require("./repoInfo.js"), exports);
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,qDAAoD;AAEpD,yDAAoF;AACpF,6CAA2D;AAE3D,+CAA4C;AAM5C,SAAS,MAAM,CAAC,IAAuB,EAAE,WAAmB;IAC1D,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,SAAS,CAAC,KAAe,EAAE,WAAmB;IACrD,OAAO,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,UAAU,CAAC,eAAyB,EAAE,KAAe,EAAE,IAAuB,EAAE,UAAyB;IACvH,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC/B,MAAM,cAAc,GAAG,IAAA,mCAAiB,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAE3D,IAAI,cAAc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