Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): hash npm projects based on version #6879

Merged
merged 1 commit into from Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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