question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add project hash information to `nx print-affected` output

See original GitHub issue

Description

I’d like to see a set of fields added to the print affected json output, something like

{
  "projects": [...],
  "projectGraph": {...},
  "hashes": {
    "my-app": {
       "current": "4b669d95627bf6724502d7b4ff6f41d3654c50ba9e3b1cf31e72c138370423f8",
       "previous": "0bdb20fbd1788957302f4cf356ff0449ee3c2d10960814f6c34fd399fa64f5d3"
    }
  }
}

This hash key should include all projects, not just the affected ones.

Motivation

I use nx print-affected in order to dynamically generate a CI pipeline which works amazingly well, however I have a need to determine the current hash of an unchanged project so that I can fetch the docker container

Suggested Implementaion

I assume that the affected projects is determined by some hashing already, so it must be feasible to add this into the affected output

Alternate Implementations

This could be a completely different command line tool if needed.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:19
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
douglaswardcommented, Feb 2, 2022

If there isn’t any plans to support exposing the hash again, which would be super sad, then maybe it is enough to use the Hasher in a custom script by importing it from import { Hasher } from '@nrwl/workspace/src/core/hasher/hasher';.

ng print-affected --target=build --all could provide the ProjectGraph and the tasks needed to get the hashes from the Hasher using the hashTaskWithDepsAndContext function.

e.g. something like

import { Hasher } from '@nrwl/workspace/src/core/hasher/hasher';

const hasher = new Hasher(projectGraph, nxConfig, {});
const hash = await hasher.hashTaskWithDepsAndContext(task);
4reactions
maxime1992commented, Jul 5, 2021

I spent some time during a hackday to see if I could get something in our case to get back the hash on a per app/per lib case.

I did dug into the diff mentioned by @zakhenry, I also looked into “NX plugins and devkit”, “NX plugins”, “Creating Custom Executors”, the affected function and the runAllTasks function (which uses the Hasher). Unfortunately, I don’t think there’s any way to export those directly without updating the code on NX side.

Plugins and custom executors won’t be able to add something like/modify the affected command.

I also tried a dummy approach of using NX through a node script like this:

const nrwlWorkspace = require('@nrwl/workspace/src/command-line/affected');

const main = async () => {
  const affected = await nrwlWorkspace.affected('print-affected', {
    _: ['print-affected'],
    target: 'build',
    uncommitted: undefined,
    untracked: undefined,
    all: undefined,
    exclude: [],
    skipNxCache: false,
    onlyFailed: false,
    $0: '/home/maxime/Documents/cloudnc/code/frontend/node_modules/.bin/nx',
  });

  console.log(affected.tasks.map((task) => `${task.target.project} - ${task.hash}`));
};

main();

but unless I copy the whole affected file to modify it, I don’t think there’s any argument I can pass to tweak the output 🤔. And for obvious reason I don’t want to do that (that’d be like maintaining a small fork of NX…).

I’m also confused by the commit that @zakhenry mentioned. This commit is called “feat(core): add support for custom hashers” so I’d expect the ability to customize the hashing strategy from a consumer point of view but maybe that’s not it.

Anyway from here I’ve got 2 things to highlight:

  • I think it’d be nice to avoid a breaking change in the affected command. I remember @vsavkin saying he was trying real hard to avoid breaking changes in all the commands in the nrwl stream last week so this may just be something that they did’t realize was used. This is also not documented anywhere as far as I’m aware so maybe calling this a breaking change is unfair but on the other hand it’s in the output of a public command
  • Maybe it’d be interesting to have a system plugin at the highest possible level (like create custom commands?). So that someone could implement a command to give exactly what they need for example (nx my-custom-command). But this may go against nx philosophy, unsure

Thanks for any help on this 🙏 We’re now stuck to nx 12.2.0 till we solve it as our CI pipeline relies on the hashes 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started with Monorepo with Nx Nrwl - Rupesh Tiwari
Let's create a loggingService inside our logger project. Use Nx Console to create angular service. This is dry run result of angular service ......
Read more >
Module: index - Nx
The Nx Devkit is used to customize Nx for different technologies and use cases. ... Hash. • Hash: Object ... Adds project configuration...
Read more >
How to Deploy Nx monorepos to Netlify
‍ Next-level monorepos with Nx. Let's add a new app to our repo, a bike-store-api : api project added next to the...
Read more >
10x Faster CI with Nx and Github Actions - Medium
Depending on the target and the Github reference, the print-affected command provided by Nx CLI returns the list of projects affected by the ......
Read more >
Nrwl/Community #support #npm-packages #random
I've added root and feature state using nrwl ngrx schematics and it inserted ... Does anyone know of a way to run nx...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found