зеркало из https://github.com/microsoft/backfill.git
don't hash folder names
- git does not care about folders so to respect gitignore we need to do the same - as a bonus it improve perf as we don't need to call stats on every file
This commit is contained in:
Родитель
d5ac2caa4f
Коммит
2fd853d5a2
|
@ -24,7 +24,7 @@ describe("End to end", () => {
|
|||
|
||||
// Verify it produces the correct hash
|
||||
const ownHash = fs.readdirSync(path.join(packageRoot, hashPath));
|
||||
expect(ownHash).toContain("57f26541cc848f71a80fd9039137f1d50e013b92");
|
||||
expect(ownHash).toContain("88e8e1578cb7fd86d6162025488b985a49ee1482");
|
||||
|
||||
// ... and that `npm run compile` was run successfully
|
||||
const libFolderExist = await fs.pathExists(path.join(packageRoot, "lib"));
|
||||
|
|
|
@ -5,13 +5,6 @@ import tempy from "tempy";
|
|||
|
||||
import { getListOfGitFiles } from "../gitFiles";
|
||||
|
||||
function expectAreSame<T>(array1: T[], array2: T[]): void {
|
||||
expect(array1.length).toBe(array2.length);
|
||||
array1.forEach((value, index) => {
|
||||
expect(value).toBe(array2[index]);
|
||||
});
|
||||
}
|
||||
|
||||
describe("getFilesTrackedByGit()", () => {
|
||||
it("when packageRoot is also repo root", async () => {
|
||||
const cwd = tempy.directory();
|
||||
|
@ -27,9 +20,9 @@ describe("getFilesTrackedByGit()", () => {
|
|||
|
||||
const files = await getListOfGitFiles(cwd);
|
||||
|
||||
const expectedFiles = ["package.json", "src", path.join("src", "index.ts")];
|
||||
const expectedFiles = ["package.json", path.join("src", "index.ts")];
|
||||
|
||||
expectAreSame(files, expectedFiles);
|
||||
expect(files).toStrictEqual(expectedFiles);
|
||||
});
|
||||
it("when packageRoot is not repo root", async () => {
|
||||
const repoRoot = tempy.directory();
|
||||
|
@ -56,15 +49,11 @@ describe("getFilesTrackedByGit()", () => {
|
|||
const files = await getListOfGitFiles(packageRoot);
|
||||
|
||||
const expectedFiles = [
|
||||
"lib",
|
||||
path.join("lib", "index.d.ts"),
|
||||
"package.json",
|
||||
"src",
|
||||
path.join("src", "index.ts")
|
||||
];
|
||||
|
||||
console.log(files);
|
||||
|
||||
expectAreSame(files, expectedFiles);
|
||||
expect(files).toStrictEqual(expectedFiles);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -32,12 +32,15 @@ export async function getListOfGitFiles(
|
|||
* fast-glob.
|
||||
* We need to search from the repo root to git globby take
|
||||
* all the gitignore files in consideration.
|
||||
*
|
||||
* Notes:
|
||||
* - globby does not suuport objectMode when using gitignore mode
|
||||
* - we get only files because git does not care about folders
|
||||
*/
|
||||
// Note: globby does not support objectMode when using gitignore
|
||||
const absoluteFiles = await globby(relativePackagePath, {
|
||||
cwd: repoRoot,
|
||||
gitignore: true,
|
||||
onlyFiles: false,
|
||||
onlyFiles: true,
|
||||
absolute: true
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import crypto from "crypto";
|
||||
import path from "path";
|
||||
import fs from "fs-extra";
|
||||
|
||||
import { getListOfGitFiles } from "./gitFiles";
|
||||
|
||||
import { hashStrings } from "./helpers";
|
||||
|
@ -24,12 +25,9 @@ export async function generateHashOfFiles(
|
|||
// hash across platforms.
|
||||
hasher.update(toUnixPath(file));
|
||||
|
||||
const stat = await fs.stat(path.join(packageRoot, file));
|
||||
if (stat.isFile()) {
|
||||
const fileBuffer = await fs.readFile(path.join(packageRoot, file));
|
||||
const data = fileBuffer.toString().replace(newline, LF);
|
||||
hasher.update(data);
|
||||
}
|
||||
const fileBuffer = await fs.readFile(path.join(packageRoot, file));
|
||||
const data = fileBuffer.toString().replace(newline, LF);
|
||||
hasher.update(data);
|
||||
|
||||
return hasher.digest("hex");
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче