@rushstack/package-deps-hash 3.1.6 → 3.1.7

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
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@rushstack/package-deps-hash",
3
3
  "entries": [
4
+ {
5
+ "version": "3.1.7",
6
+ "tag": "@rushstack/package-deps-hash_v3.1.7",
7
+ "date": "Thu, 09 Dec 2021 00:21:54 GMT",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "comment": "When detecting changes relative to a target branch, use the merge base between the target branch and the current commit as the comparison ref."
12
+ }
13
+ ],
14
+ "dependency": [
15
+ {
16
+ "comment": "Updating dependency \"@rushstack/heft\" to `0.43.1`"
17
+ },
18
+ {
19
+ "comment": "Updating dependency \"@rushstack/heft-node-rig\" to `1.4.2`"
20
+ }
21
+ ]
22
+ }
23
+ },
4
24
  {
5
25
  "version": "3.1.6",
6
26
  "tag": "@rushstack/package-deps-hash_v3.1.6",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Change Log - @rushstack/package-deps-hash
2
2
 
3
- This log was last generated on Wed, 08 Dec 2021 19:05:08 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 09 Dec 2021 00:21:54 GMT and should not be manually modified.
4
+
5
+ ## 3.1.7
6
+ Thu, 09 Dec 2021 00:21:54 GMT
7
+
8
+ ### Patches
9
+
10
+ - When detecting changes relative to a target branch, use the merge base between the target branch and the current commit as the comparison ref.
4
11
 
5
12
  ## 3.1.6
6
13
  Wed, 08 Dec 2021 19:05:08 GMT
@@ -1 +1 @@
1
- {"version":3,"file":"getRepoState.d.ts","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA0BlE;AAED;;;GAGG;AACH,MAAM,WAAW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AAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAoC9E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBnE;AAID;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,uBAAuB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAmBrF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1B,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CAyDN;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,uBAAuB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBnG;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,uBAAuB,EAAE,MAAM,EAC/B,QAAQ,GAAE,MAAe,EACzB,OAAO,CAAC,EAAE,MAAM,GACf,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CA8B9B"}
@@ -199,6 +199,8 @@ function getRepoChanges(currentWorkingDirectory, revision = 'HEAD', gitPath) {
199
199
  'diff-index',
200
200
  '--color=never',
201
201
  '--no-renames',
202
+ // rush change targets origin/main with this, and usually the current branch is not synced, so use the merge-base
203
+ '--merge-base',
202
204
  '--no-commit-id',
203
205
  '--cached',
204
206
  '-z',
@@ -1 +1 @@
1
- {"version":3,"file":"getRepoState.js","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":";AAAA,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vE,qBAAqB,CAAC,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,KAAK,CAAC;AACf,CAAC;AApBD,oCAoBC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,uBAA+B,EAC/B,WAAmB,MAAM,EACzB,OAAgB;IAEhB,MAAM,aAAa,GAAW,WAAW,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IAE5E,MAAM,MAAM,GAA2C,8BAAU,CAAC,SAAS,CACzE,OAAO,IAAI,KAAK,EAChB;QACE,qBAAqB;QACrB,YAAY;QACZ,eAAe;QACf,cAAc;QACd,gBAAgB;QAChB,UAAU;QACV,IAAI;QACJ,QAAQ;QACR,IAAI;KACL,EACD;QACE,uBAAuB,EAAE,aAAa;KACvC,CACF,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;KACzF;IAED,MAAM,OAAO,GAAiC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAE/E,OAAO,OAAO,CAAC;AACjB,CAAC;AAhCD,wCAgCC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport type * as child_process from 'child_process';\r\nimport { Executable } from '@rushstack/node-core-library';\r\n\r\n/**\r\n * Parses the output of the \"git ls-tree -r -z\" command\r\n * @internal\r\n */\r\nexport function parseGitLsTree(output: string): Map<string, string> {\r\n const result: Map<string, string> = new Map();\r\n\r\n // Parse the output\r\n // With the -z modifier, paths are delimited by nulls\r\n // A line looks like:\r\n // <mode> <type> <newhash>\\t<path>\\0\r\n // 100644 blob a300ccb0b36bd2c85ef18e3c619a2c747f95959e\\ttools/prettier-git/prettier-git.js\\0\r\n\r\n let last: number = 0;\r\n let index: number = output.indexOf('\\0', last);\r\n while (index >= 0) {\r\n const item: string = output.slice(last, index);\r\n\r\n const tabIndex: number = item.indexOf('\\t');\r\n const filePath: string = item.slice(tabIndex + 1);\r\n\r\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\r\n const hash: string = item.slice(tabIndex - 40, tabIndex);\r\n result.set(filePath, hash);\r\n\r\n last = index + 1;\r\n index = output.indexOf('\\0', last);\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Information about the changes to a file.\r\n * @beta\r\n */\r\nexport interface IFileDiffStatus {\r\n mode: string;\r\n oldhash: string;\r\n newhash: string;\r\n status: 'A' | 'D' | 'M';\r\n}\r\n\r\n/**\r\n * Parses the output of `git diff-index --color=never --no-renames --no-commit-id -z <REVISION> --\r\n * Returns a map of file path to diff\r\n * @internal\r\n */\r\nexport function parseGitDiffIndex(output: string): Map<string, IFileDiffStatus> {\r\n const result: Map<string, IFileDiffStatus> = new Map();\r\n\r\n // Parse the output\r\n // With the -z modifier, paths are delimited by nulls\r\n // A line looks like:\r\n // :<oldmode> <newmode> <oldhash> <newhash> <status>\\0<path>\\0\r\n // :100644 100644 a300ccb0b36bd2c85ef18e3c619a2c747f95959e 0000000000000000000000000000000000000000 M\\0tools/prettier-git/prettier-git.js\\0\r\n\r\n let last: number = 0;\r\n let index: number = output.indexOf('\\0', last);\r\n while (index >= 0) {\r\n const header: string = output.slice(last, index);\r\n const status: IFileDiffStatus['status'] = header.slice(-1) as IFileDiffStatus['status'];\r\n\r\n last = index + 1;\r\n index = output.indexOf('\\0', last);\r\n const filePath: string = output.slice(last, index);\r\n\r\n // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.\r\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\r\n const mode: string = header.slice(8, 14);\r\n const oldhash: string = header.slice(-83, -43);\r\n const newhash: string = header.slice(-42, -2);\r\n result.set(filePath, {\r\n mode,\r\n oldhash,\r\n newhash,\r\n status\r\n });\r\n\r\n last = index + 1;\r\n index = output.indexOf('\\0', last);\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Parses the output of `git status -z -u`\r\n *\r\n * @param output - The raw output from Git\r\n * @returns a map of file path to if it exists\r\n * @internal\r\n */\r\nexport function parseGitStatus(output: string): Map<string, boolean> {\r\n const result: Map<string, boolean> = new Map();\r\n\r\n // Parse the output\r\n // With the -z modifier, paths are delimited by nulls\r\n // A line looks like:\r\n // XY <path>\\0\r\n // M tools/prettier-git/prettier-git.js\\0\r\n\r\n let last: number = 0;\r\n let index: number = output.indexOf('\\0', last);\r\n while (index >= 0) {\r\n // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.\r\n const workingTreeStatus: string = output.charAt(last + 2);\r\n const exists: boolean =\r\n workingTreeStatus !== 'D' && (workingTreeStatus !== ' ' || output.charAt(last + 1) !== 'D');\r\n const filePath: string = output.slice(last + 3, index);\r\n\r\n result.set(filePath, exists);\r\n\r\n last = index + 1;\r\n index = output.indexOf('\\0', last);\r\n }\r\n\r\n return result;\r\n}\r\n\r\nconst repoRootCache: Map<string, string> = new Map();\r\n\r\n/**\r\n * Finds the root of the current Git repository\r\n *\r\n * @param currentWorkingDirectory - The working directory for which to locate the repository\r\n * @param gitPath - The path to the Git executable\r\n *\r\n * @returns The full path to the root directory of the Git repository\r\n * @beta\r\n */\r\nexport function getRepoRoot(currentWorkingDirectory: string, gitPath?: string): string {\r\n let cachedResult: string | undefined = repoRootCache.get(currentWorkingDirectory);\r\n if (!cachedResult) {\r\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n ['--no-optional-locks', 'rev-parse', '--show-toplevel'],\r\n {\r\n currentWorkingDirectory\r\n }\r\n );\r\n\r\n if (result.status !== 0) {\r\n throw new Error(`git rev-parse exited with status ${result.status}: ${result.stderr}`);\r\n }\r\n\r\n repoRootCache.set(currentWorkingDirectory, (cachedResult = result.stdout.trim()));\r\n }\r\n\r\n return cachedResult;\r\n}\r\n\r\n/**\r\n * Augments the state value with modifications that are not in the index.\r\n * @param rootDirectory - The root directory of the Git repository\r\n * @param state - The current map of git path -> object hash. Will be mutated.\r\n * @param gitPath - The path to the Git executable\r\n * @internal\r\n */\r\nexport function applyWorkingTreeState(\r\n rootDirectory: string,\r\n state: Map<string, string>,\r\n gitPath?: string\r\n): void {\r\n const statusResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n ['--no-optional-locks', 'status', '-z', '-u', '--no-renames', '--'],\r\n {\r\n currentWorkingDirectory: rootDirectory\r\n }\r\n );\r\n\r\n if (statusResult.status !== 0) {\r\n throw new Error(`git status exited with status ${statusResult.status}: ${statusResult.stderr}`);\r\n }\r\n\r\n const locallyModified: Map<string, boolean> = parseGitStatus(statusResult.stdout);\r\n\r\n const filesToHash: string[] = [];\r\n for (const [filePath, exists] of locallyModified) {\r\n if (exists) {\r\n filesToHash.push(filePath);\r\n } else {\r\n state.delete(filePath);\r\n }\r\n }\r\n\r\n if (filesToHash.length) {\r\n // Use --stdin-paths arg to pass the list of files to git in order to avoid issues with\r\n // command length\r\n const hashObjectResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n ['hash-object', '--stdin-paths'],\r\n { input: filesToHash.join('\\n') }\r\n );\r\n\r\n if (hashObjectResult.status !== 0) {\r\n throw new Error(\r\n `git hash-object exited with status ${hashObjectResult.status}: ${hashObjectResult.stderr}`\r\n );\r\n }\r\n\r\n const hashStdout: string = hashObjectResult.stdout.trim();\r\n\r\n // The result of \"git hash-object\" will be a list of file hashes delimited by newlines\r\n const hashes: string[] = hashStdout.split('\\n');\r\n\r\n if (hashes.length !== filesToHash.length) {\r\n throw new Error(\r\n `Passed ${filesToHash.length} file paths to Git to hash, but received ${hashes.length} hashes.`\r\n );\r\n }\r\n\r\n const len: number = hashes.length;\r\n for (let i: number = 0; i < len; i++) {\r\n const hash: string = hashes[i];\r\n const filePath: string = filesToHash[i];\r\n state.set(filePath, hash);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.\r\n * @param currentWorkingDirectory - The working directory. Only used to find the repository root.\r\n * @param gitPath - The path to the Git executable\r\n * @beta\r\n */\r\nexport function getRepoState(currentWorkingDirectory: string, gitPath?: string): Map<string, string> {\r\n const rootDirectory: string = getRepoRoot(currentWorkingDirectory, gitPath);\r\n\r\n const lsTreeResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n ['--no-optional-locks', 'ls-tree', '-r', '-z', '--full-name', 'HEAD', '--'],\r\n {\r\n currentWorkingDirectory: rootDirectory\r\n }\r\n );\r\n\r\n if (lsTreeResult.status !== 0) {\r\n throw new Error(`git ls-tree exited with status ${lsTreeResult.status}: ${lsTreeResult.stderr}`);\r\n }\r\n\r\n const state: Map<string, string> = parseGitLsTree(lsTreeResult.stdout);\r\n\r\n applyWorkingTreeState(rootDirectory, state, gitPath);\r\n\r\n return state;\r\n}\r\n\r\n/**\r\n * 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.\r\n * @param currentWorkingDirectory - The working directory. Only used to find the repository root.\r\n * @param revision - The Git revision specifier to detect changes relative to. Defaults to HEAD (i.e. will compare staged vs. committed)\r\n * @param gitPath - The path to the Git executable\r\n * @returns A map from the Git file path to the corresponding file change metadata\r\n * @beta\r\n */\r\nexport function getRepoChanges(\r\n currentWorkingDirectory: string,\r\n revision: string = 'HEAD',\r\n gitPath?: string\r\n): Map<string, IFileDiffStatus> {\r\n const rootDirectory: string = getRepoRoot(currentWorkingDirectory, gitPath);\r\n\r\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n [\r\n '--no-optional-locks',\r\n 'diff-index',\r\n '--color=never',\r\n '--no-renames',\r\n '--no-commit-id',\r\n '--cached',\r\n '-z',\r\n revision,\r\n '--'\r\n ],\r\n {\r\n currentWorkingDirectory: rootDirectory\r\n }\r\n );\r\n\r\n if (result.status !== 0) {\r\n throw new Error(`git diff-index exited with status ${result.status}: ${result.stderr}`);\r\n }\r\n\r\n const changes: Map<string, IFileDiffStatus> = parseGitDiffIndex(result.stdout);\r\n\r\n return changes;\r\n}\r\n"]}
1
+ {"version":3,"file":"getRepoState.js","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,oEAA0D;AAE1D;;;GAGG;AACH,SAAgB,cAAc,CAAC,MAAc;IAC3C,MAAM,MAAM,GAAwB,IAAI,GAAG,EAAE,CAAC;IAE9C,mBAAmB;IACnB,qDAAqD;IACrD,qBAAqB;IACrB,oCAAoC;IACpC,6FAA6F;IAE7F,IAAI,IAAI,GAAW,CAAC,CAAC;IACrB,IAAI,KAAK,GAAW,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/C,OAAO,KAAK,IAAI,CAAC,EAAE;QACjB,MAAM,IAAI,GAAW,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAE/C,MAAM,QAAQ,GAAW,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAW,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QAElD,+EAA+E;QAC/E,MAAM,IAAI,GAAW,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;QACzD,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAE3B,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC;QACjB,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACpC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,wCA0BC;AAaD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,MAAM,MAAM,GAAiC,IAAI,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AAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,kCAAkC,YAAY,CAAC,MAAM,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;KAClG;IAED,MAAM,KAAK,GAAwB,cAAc,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAEvE,qBAAqB,CAAC,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,KAAK,CAAC;AACf,CAAC;AApBD,oCAoBC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,uBAA+B,EAC/B,WAAmB,MAAM,EACzB,OAAgB;IAEhB,MAAM,aAAa,GAAW,WAAW,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;IAE5E,MAAM,MAAM,GAA2C,8BAAU,CAAC,SAAS,CACzE,OAAO,IAAI,KAAK,EAChB;QACE,qBAAqB;QACrB,YAAY;QACZ,eAAe;QACf,cAAc;QACd,iHAAiH;QACjH,cAAc;QACd,gBAAgB;QAChB,UAAU;QACV,IAAI;QACJ,QAAQ;QACR,IAAI;KACL,EACD;QACE,uBAAuB,EAAE,aAAa;KACvC,CACF,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;KACzF;IAED,MAAM,OAAO,GAAiC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAE/E,OAAO,OAAO,CAAC;AACjB,CAAC;AAlCD,wCAkCC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport type * as child_process from 'child_process';\r\nimport { Executable } from '@rushstack/node-core-library';\r\n\r\n/**\r\n * Parses the output of the \"git ls-tree -r -z\" command\r\n * @internal\r\n */\r\nexport function parseGitLsTree(output: string): Map<string, string> {\r\n const result: Map<string, string> = new Map();\r\n\r\n // Parse the output\r\n // With the -z modifier, paths are delimited by nulls\r\n // A line looks like:\r\n // <mode> <type> <newhash>\\t<path>\\0\r\n // 100644 blob a300ccb0b36bd2c85ef18e3c619a2c747f95959e\\ttools/prettier-git/prettier-git.js\\0\r\n\r\n let last: number = 0;\r\n let index: number = output.indexOf('\\0', last);\r\n while (index >= 0) {\r\n const item: string = output.slice(last, index);\r\n\r\n const tabIndex: number = item.indexOf('\\t');\r\n const filePath: string = item.slice(tabIndex + 1);\r\n\r\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\r\n const hash: string = item.slice(tabIndex - 40, tabIndex);\r\n result.set(filePath, hash);\r\n\r\n last = index + 1;\r\n index = output.indexOf('\\0', last);\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Information about the changes to a file.\r\n * @beta\r\n */\r\nexport interface IFileDiffStatus {\r\n mode: string;\r\n oldhash: string;\r\n newhash: string;\r\n status: 'A' | 'D' | 'M';\r\n}\r\n\r\n/**\r\n * Parses the output of `git diff-index --color=never --no-renames --no-commit-id -z <REVISION> --\r\n * Returns a map of file path to diff\r\n * @internal\r\n */\r\nexport function parseGitDiffIndex(output: string): Map<string, IFileDiffStatus> {\r\n const result: Map<string, IFileDiffStatus> = new Map();\r\n\r\n // Parse the output\r\n // With the -z modifier, paths are delimited by nulls\r\n // A line looks like:\r\n // :<oldmode> <newmode> <oldhash> <newhash> <status>\\0<path>\\0\r\n // :100644 100644 a300ccb0b36bd2c85ef18e3c619a2c747f95959e 0000000000000000000000000000000000000000 M\\0tools/prettier-git/prettier-git.js\\0\r\n\r\n let last: number = 0;\r\n let index: number = output.indexOf('\\0', last);\r\n while (index >= 0) {\r\n const header: string = output.slice(last, index);\r\n const status: IFileDiffStatus['status'] = header.slice(-1) as IFileDiffStatus['status'];\r\n\r\n last = index + 1;\r\n index = output.indexOf('\\0', last);\r\n const filePath: string = output.slice(last, index);\r\n\r\n // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.\r\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\r\n const mode: string = header.slice(8, 14);\r\n const oldhash: string = header.slice(-83, -43);\r\n const newhash: string = header.slice(-42, -2);\r\n result.set(filePath, {\r\n mode,\r\n oldhash,\r\n newhash,\r\n status\r\n });\r\n\r\n last = index + 1;\r\n index = output.indexOf('\\0', last);\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Parses the output of `git status -z -u`\r\n *\r\n * @param output - The raw output from Git\r\n * @returns a map of file path to if it exists\r\n * @internal\r\n */\r\nexport function parseGitStatus(output: string): Map<string, boolean> {\r\n const result: Map<string, boolean> = new Map();\r\n\r\n // Parse the output\r\n // With the -z modifier, paths are delimited by nulls\r\n // A line looks like:\r\n // XY <path>\\0\r\n // M tools/prettier-git/prettier-git.js\\0\r\n\r\n let last: number = 0;\r\n let index: number = output.indexOf('\\0', last);\r\n while (index >= 0) {\r\n // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.\r\n const workingTreeStatus: string = output.charAt(last + 2);\r\n const exists: boolean =\r\n workingTreeStatus !== 'D' && (workingTreeStatus !== ' ' || output.charAt(last + 1) !== 'D');\r\n const filePath: string = output.slice(last + 3, index);\r\n\r\n result.set(filePath, exists);\r\n\r\n last = index + 1;\r\n index = output.indexOf('\\0', last);\r\n }\r\n\r\n return result;\r\n}\r\n\r\nconst repoRootCache: Map<string, string> = new Map();\r\n\r\n/**\r\n * Finds the root of the current Git repository\r\n *\r\n * @param currentWorkingDirectory - The working directory for which to locate the repository\r\n * @param gitPath - The path to the Git executable\r\n *\r\n * @returns The full path to the root directory of the Git repository\r\n * @beta\r\n */\r\nexport function getRepoRoot(currentWorkingDirectory: string, gitPath?: string): string {\r\n let cachedResult: string | undefined = repoRootCache.get(currentWorkingDirectory);\r\n if (!cachedResult) {\r\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n ['--no-optional-locks', 'rev-parse', '--show-toplevel'],\r\n {\r\n currentWorkingDirectory\r\n }\r\n );\r\n\r\n if (result.status !== 0) {\r\n throw new Error(`git rev-parse exited with status ${result.status}: ${result.stderr}`);\r\n }\r\n\r\n repoRootCache.set(currentWorkingDirectory, (cachedResult = result.stdout.trim()));\r\n }\r\n\r\n return cachedResult;\r\n}\r\n\r\n/**\r\n * Augments the state value with modifications that are not in the index.\r\n * @param rootDirectory - The root directory of the Git repository\r\n * @param state - The current map of git path -> object hash. Will be mutated.\r\n * @param gitPath - The path to the Git executable\r\n * @internal\r\n */\r\nexport function applyWorkingTreeState(\r\n rootDirectory: string,\r\n state: Map<string, string>,\r\n gitPath?: string\r\n): void {\r\n const statusResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n ['--no-optional-locks', 'status', '-z', '-u', '--no-renames', '--'],\r\n {\r\n currentWorkingDirectory: rootDirectory\r\n }\r\n );\r\n\r\n if (statusResult.status !== 0) {\r\n throw new Error(`git status exited with status ${statusResult.status}: ${statusResult.stderr}`);\r\n }\r\n\r\n const locallyModified: Map<string, boolean> = parseGitStatus(statusResult.stdout);\r\n\r\n const filesToHash: string[] = [];\r\n for (const [filePath, exists] of locallyModified) {\r\n if (exists) {\r\n filesToHash.push(filePath);\r\n } else {\r\n state.delete(filePath);\r\n }\r\n }\r\n\r\n if (filesToHash.length) {\r\n // Use --stdin-paths arg to pass the list of files to git in order to avoid issues with\r\n // command length\r\n const hashObjectResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n ['hash-object', '--stdin-paths'],\r\n { input: filesToHash.join('\\n') }\r\n );\r\n\r\n if (hashObjectResult.status !== 0) {\r\n throw new Error(\r\n `git hash-object exited with status ${hashObjectResult.status}: ${hashObjectResult.stderr}`\r\n );\r\n }\r\n\r\n const hashStdout: string = hashObjectResult.stdout.trim();\r\n\r\n // The result of \"git hash-object\" will be a list of file hashes delimited by newlines\r\n const hashes: string[] = hashStdout.split('\\n');\r\n\r\n if (hashes.length !== filesToHash.length) {\r\n throw new Error(\r\n `Passed ${filesToHash.length} file paths to Git to hash, but received ${hashes.length} hashes.`\r\n );\r\n }\r\n\r\n const len: number = hashes.length;\r\n for (let i: number = 0; i < len; i++) {\r\n const hash: string = hashes[i];\r\n const filePath: string = filesToHash[i];\r\n state.set(filePath, hash);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.\r\n * @param currentWorkingDirectory - The working directory. Only used to find the repository root.\r\n * @param gitPath - The path to the Git executable\r\n * @beta\r\n */\r\nexport function getRepoState(currentWorkingDirectory: string, gitPath?: string): Map<string, string> {\r\n const rootDirectory: string = getRepoRoot(currentWorkingDirectory, gitPath);\r\n\r\n const lsTreeResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n ['--no-optional-locks', 'ls-tree', '-r', '-z', '--full-name', 'HEAD', '--'],\r\n {\r\n currentWorkingDirectory: rootDirectory\r\n }\r\n );\r\n\r\n if (lsTreeResult.status !== 0) {\r\n throw new Error(`git ls-tree exited with status ${lsTreeResult.status}: ${lsTreeResult.stderr}`);\r\n }\r\n\r\n const state: Map<string, string> = parseGitLsTree(lsTreeResult.stdout);\r\n\r\n applyWorkingTreeState(rootDirectory, state, gitPath);\r\n\r\n return state;\r\n}\r\n\r\n/**\r\n * 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.\r\n * @param currentWorkingDirectory - The working directory. Only used to find the repository root.\r\n * @param revision - The Git revision specifier to detect changes relative to. Defaults to HEAD (i.e. will compare staged vs. committed)\r\n * @param gitPath - The path to the Git executable\r\n * @returns A map from the Git file path to the corresponding file change metadata\r\n * @beta\r\n */\r\nexport function getRepoChanges(\r\n currentWorkingDirectory: string,\r\n revision: string = 'HEAD',\r\n gitPath?: string\r\n): Map<string, IFileDiffStatus> {\r\n const rootDirectory: string = getRepoRoot(currentWorkingDirectory, gitPath);\r\n\r\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\r\n gitPath || 'git',\r\n [\r\n '--no-optional-locks',\r\n 'diff-index',\r\n '--color=never',\r\n '--no-renames',\r\n // rush change targets origin/main with this, and usually the current branch is not synced, so use the merge-base\r\n '--merge-base',\r\n '--no-commit-id',\r\n '--cached',\r\n '-z',\r\n revision,\r\n '--'\r\n ],\r\n {\r\n currentWorkingDirectory: rootDirectory\r\n }\r\n );\r\n\r\n if (result.status !== 0) {\r\n throw new Error(`git diff-index exited with status ${result.status}: ${result.stderr}`);\r\n }\r\n\r\n const changes: Map<string, IFileDiffStatus> = parseGitDiffIndex(result.stdout);\r\n\r\n return changes;\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/package-deps-hash",
3
- "version": "3.1.6",
3
+ "version": "3.1.7",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "dist/package-deps-hash.d.ts",
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "devDependencies": {
14
14
  "@rushstack/eslint-config": "2.5.0",
15
- "@rushstack/heft": "0.43.0",
16
- "@rushstack/heft-node-rig": "1.4.1",
15
+ "@rushstack/heft": "0.43.1",
16
+ "@rushstack/heft-node-rig": "1.4.2",
17
17
  "@rushstack/node-core-library": "3.44.1",
18
18
  "@types/heft-jest": "1.0.1",
19
19
  "@types/node": "12.20.24"