Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(core): hash npm projects based on version (#6879)
  • Loading branch information
FrozenPandaz committed Aug 27, 2021
1 parent 12ed2d3 commit 677e481
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/workspace/src/core/hasher/hasher.spec.ts
Expand Up @@ -6,6 +6,7 @@ jest.doMock('../../utils/app-root', () => {
});

import fs = require('fs');
import { DependencyType } from '@nrwl/devkit';
import { Hasher } from './hasher';

jest.mock('fs');
Expand Down Expand Up @@ -272,6 +273,53 @@ describe('Hasher', () => {
});
});

it('should hash dependent npm project versions', async () => {
hashes['/filea'] = 'a.hash';
hashes['/fileb'] = 'b.hash';
const hasher = new Hasher(
{
nodes: {
'npm:react': {
name: 'parent',
type: 'npm',
data: {
version: '17.0.0',
},
},
app: {
name: 'app',
type: 'app',
data: {
root: '',
files: [{ file: '/filea.ts', hash: 'a.hash' }],
},
},
},
dependencies: {
'npm:react': [],
app: [
{ source: 'app', target: 'npm:react', type: DependencyType.static },
],
},
},
{} as any,
{},
createHashing()
);

const hash = await hasher.hashTaskWithDepsAndContext({
target: { project: 'app', target: 'build' },
id: 'app-build',
overrides: { prop: 'prop-value' },
});

// note that the parent hash is based on parent source files only!
expect(hash.details.nodes).toEqual({
app: '/filea.ts|a.hash|""|""|{"compilerOptions":{"paths":{"@nrwl/parent":["libs/parent/src/index.ts"],"@nrwl/child":["libs/child/src/index.ts"]}}}',
'npm:react': '17.0.0',
});
});

it('should hash when circular dependencies', async () => {
hashes['/filea'] = 'a.hash';
hashes['/fileb'] = 'b.hash';
Expand Down
7 changes: 7 additions & 0 deletions packages/workspace/src/core/hasher/hasher.ts
Expand Up @@ -15,6 +15,7 @@ import { performance } from 'perf_hooks';
import { appRootPath } from '../../utils/app-root';
import { workspaceFileName } from '../file-utils';
import { defaultHashing, HashingImpl } from './hashing-impl';
import { isNpmProject } from '../project-graph';

export interface Hash {
value: string;
Expand Down Expand Up @@ -341,6 +342,12 @@ class ProjectHasher {
if (!this.sourceHashes[projectName]) {
this.sourceHashes[projectName] = new Promise(async (res) => {
const p = this.projectGraph.nodes[projectName];

if (isNpmProject(p)) {
res(this.hashing.hashArray([p.data.version]));
return;
}

const fileNames = p.data.files.map((f) => f.file);
const values = p.data.files.map((f) => f.hash);

Expand Down

0 comments on commit 677e481

Please sign in to comment.