fix(core): recalculate dep-graph when root files are touched
This commit is contained in:
parent
4ca4268396
commit
1d1063fb1a
@ -97,6 +97,18 @@ function defaultReadFileAtRevision(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFileData(filePath: string): FileData {
|
||||||
|
const stat = fs.statSync(filePath);
|
||||||
|
return {
|
||||||
|
file: path
|
||||||
|
.relative(appRootPath, filePath)
|
||||||
|
.split(path.sep)
|
||||||
|
.join('/'),
|
||||||
|
ext: path.extname(filePath),
|
||||||
|
mtime: stat.mtimeMs
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function allFilesInDir(
|
export function allFilesInDir(
|
||||||
dirName: string,
|
dirName: string,
|
||||||
recurse: boolean = true
|
recurse: boolean = true
|
||||||
@ -118,14 +130,7 @@ export function allFilesInDir(
|
|||||||
const s = fs.statSync(child);
|
const s = fs.statSync(child);
|
||||||
if (!s.isDirectory()) {
|
if (!s.isDirectory()) {
|
||||||
// add starting with "apps/myapp/..." or "libs/mylib/..."
|
// add starting with "apps/myapp/..." or "libs/mylib/..."
|
||||||
res.push({
|
res.push(getFileData(child));
|
||||||
file: path
|
|
||||||
.relative(appRootPath, child)
|
|
||||||
.split(path.sep)
|
|
||||||
.join('/'),
|
|
||||||
ext: path.extname(child),
|
|
||||||
mtime: s.mtimeMs
|
|
||||||
});
|
|
||||||
} else if (s.isDirectory() && recurse) {
|
} else if (s.isDirectory() && recurse) {
|
||||||
res = [...res, ...allFilesInDir(child)];
|
res = [...res, ...allFilesInDir(child)];
|
||||||
}
|
}
|
||||||
@ -182,10 +187,19 @@ export function readNxJson(): NxJson {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Make this list extensible
|
||||||
|
export function rootWorkspaceFileNames(): string[] {
|
||||||
|
return [`package.json`, workspaceFileName(), `nx.json`, `tsconfig.json`];
|
||||||
|
}
|
||||||
|
|
||||||
export function readWorkspaceFiles(): FileData[] {
|
export function readWorkspaceFiles(): FileData[] {
|
||||||
const workspaceJson = readWorkspaceJson();
|
const workspaceJson = readWorkspaceJson();
|
||||||
const files = [];
|
const files = [];
|
||||||
|
|
||||||
|
files.push(
|
||||||
|
...rootWorkspaceFileNames().map(f => getFileData(`${appRootPath}/${f}`))
|
||||||
|
);
|
||||||
|
|
||||||
// Add known workspace files and directories
|
// Add known workspace files and directories
|
||||||
files.push(...allFilesInDir(appRootPath, false));
|
files.push(...allFilesInDir(appRootPath, false));
|
||||||
files.push(...allFilesInDir(`${appRootPath}/tools`));
|
files.push(...allFilesInDir(`${appRootPath}/tools`));
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { mkdirSync, readFileSync } from 'fs';
|
import { mkdirSync } from 'fs';
|
||||||
import { ProjectGraph } from './project-graph-models';
|
import { ProjectGraph } from './project-graph-models';
|
||||||
import { ProjectGraphBuilder } from './project-graph-builder';
|
import { ProjectGraphBuilder } from './project-graph-builder';
|
||||||
import { appRootPath } from '../../utils/app-root';
|
import { appRootPath } from '../../utils/app-root';
|
||||||
|
|||||||
@ -10,6 +10,9 @@ describe('Hasher', () => {
|
|||||||
hasha.mockImplementation(values => values.join('|'));
|
hasha.mockImplementation(values => values.join('|'));
|
||||||
hasha.fromFile.mockImplementation(path => Promise.resolve(hashes[path]));
|
hasha.fromFile.mockImplementation(path => Promise.resolve(hashes[path]));
|
||||||
fs.statSync.mockReturnValue({ size: 100 });
|
fs.statSync.mockReturnValue({ size: 100 });
|
||||||
|
fs.readFileSync.mockImplementation(() =>
|
||||||
|
JSON.stringify({ dependencies: {}, devDependencies: {} })
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create project hash', async done => {
|
it('should create project hash', async done => {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { ProjectGraph } from '../core/project-graph';
|
|||||||
import { NxJson } from '../core/shared-interfaces';
|
import { NxJson } from '../core/shared-interfaces';
|
||||||
import { Task } from './tasks-runner';
|
import { Task } from './tasks-runner';
|
||||||
import { statSync } from 'fs';
|
import { statSync } from 'fs';
|
||||||
|
import { rootWorkspaceFileNames } from '../core/file-utils';
|
||||||
|
|
||||||
const hasha = require('hasha');
|
const hasha = require('hasha');
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ export class Hasher {
|
|||||||
...Object.keys(this.nxJson.implicitDependencies || {}).map(r =>
|
...Object.keys(this.nxJson.implicitDependencies || {}).map(r =>
|
||||||
this.fileHashes.hashFile(r)
|
this.fileHashes.hashFile(r)
|
||||||
),
|
),
|
||||||
|
...rootWorkspaceFileNames().map(r => this.fileHashes.hashFile(r)),
|
||||||
this.fileHashes.hashFile('package-lock.json'),
|
this.fileHashes.hashFile('package-lock.json'),
|
||||||
this.fileHashes.hashFile('yarn.lock')
|
this.fileHashes.hashFile('yarn.lock')
|
||||||
]);
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user