Compare commits

...

5 Commits

Author SHA1 Message Date
Jason Jean f555865cdb Release 10.0.13 2020-08-19 17:21:01 -04:00
Victor Savkin f75adb8d67 fix(core): explicitly store workspace files instead of deriving them from hashes 2020-08-19 16:37:17 -04:00
Victor Savkin 1cfe419643 fix(core): dont override sigint 2020-08-19 16:37:17 -04:00
Victor Savkin 550fabb72a fix(core): respect nxignore when using git hashing 2020-08-19 16:37:17 -04:00
Victor Savkin c21454e62c fix(core): add a workaround for potential bugs in git hasher (#3521) 2020-08-19 16:37:17 -04:00
5 changed files with 47 additions and 15 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@nrwl/nx-source",
"version": "10.0.12",
"version": "10.0.13",
"description": "Extensible Dev Tools for Monorepos",
"homepage": "https://nx.dev",
"main": "index.js",
+1 -5
View File
@@ -95,11 +95,7 @@ function setUpOutputWatching(captureStderr: boolean, forwardOutput: boolean) {
}
});
process.on('SIGINT', () => {
writeToDisk(forwardOutput, outWithErr);
});
process.on('SIGTERM', () => {
writeToDisk(forwardOutput, outWithErr);
process.exit(15);
});
}
+3 -3
View File
@@ -215,12 +215,12 @@ export function rootWorkspaceFileData(): FileData[] {
}
export function readWorkspaceFiles(): FileData[] {
const workspaceJson = readWorkspaceJson();
performance.mark('read workspace files:start');
if (defaultFileHasher.usesGitForHashing) {
const r = defaultFileHasher
.allFiles()
const ignoredGlobs = getIgnoredGlobs();
const r = defaultFileHasher.workspaceFiles
.filter((f) => !ignoredGlobs.ignores(f))
.map((f) => getFileData(`${appRootPath}/${f}`));
performance.mark('read workspace files:end');
performance.measure(
@@ -20,6 +20,7 @@ export function extractNameAndVersion(content: string): string {
export class FileHasher {
fileHashes: { [path: string]: string } = {};
workspaceFiles = [];
usesGitForHashing = false;
constructor(private readonly hashing: HashingImp) {
@@ -29,6 +30,7 @@ export class FileHasher {
init() {
performance.mark('init hashing:start');
this.fileHashes = {};
this.workspaceFiles = [];
this.getHashesFromGit();
this.usesGitForHashing = Object.keys(this.fileHashes).length > 0;
performance.mark('init hashing:end');
@@ -49,14 +51,15 @@ export class FileHasher {
return this.fileHashes[relativePath];
}
allFiles() {
return Object.keys(this.fileHashes);
}
private getHashesFromGit() {
const sliceIndex = appRootPath.length + 1;
getFileHashes(appRootPath).forEach((hash, filename) => {
this.fileHashes[filename.substr(sliceIndex)] = hash;
/**
* we have to store it separately because fileHashes can be modified
* later on and can contain files that do not exist in the workspace
*/
this.workspaceFiles.push(filename.substr(sliceIndex));
});
}
@@ -1,4 +1,6 @@
import { spawnSync } from 'child_process';
import { join } from 'path';
import { statSync } from 'fs';
function parseGitLsTree(output: string): Map<string, string> {
const changes: Map<string, string> = new Map<string, string>();
@@ -102,8 +104,39 @@ function gitStatus(
deletedFiles.push(filename);
}
});
const status = getGitHashForFiles(filesToHash, path);
return { deletedFiles, status };
const updated = checkForDeletedFiles(path, filesToHash, deletedFiles);
const status = getGitHashForFiles(updated.filesToHash, path);
return { deletedFiles: updated.deletedFiles, status };
}
/**
* This is only needed because of potential issues with interpreting "git status".
* We had a few issues where we didn't interpret renames correctly. Even though
* doing this somewhat slow, we will keep it for now.
*
* @vsavkin remove it in nx 10.2
*/
function checkForDeletedFiles(
path: string,
files: string[],
deletedFiles: string[]
) {
let filesToHash = [];
files.forEach((f) => {
try {
statSync(join(path, f)).isFile();
filesToHash.push(f);
} catch (err) {
console.warn(
`Warning: Fell back to using 'fs' to identify ${f} as deleted. Please open an issue at https://github.com/nrwl/nx so we can investigate.`
);
deletedFiles.push(f);
}
});
return { filesToHash, deletedFiles };
}
export function getFileHashes(path: string): Map<string, string> {