gperdomor / nx-tools

Nx Workspaces builders and tools
MIT License
360 stars 56 forks source link

Add debug information when nx is run in verbose #1127

Open Evanion opened 2 months ago

Evanion commented 2 months ago

I'm trying to setup our prject to use nx-container but It would really help if there was some output about what the package is doing when running with NX_VERBOSE_LOGGING=true or nx <command> --verbose

I tried cloning the repo, and doing the changes myself, but when husky tries to validate package-lock.json, it can't read it.. It's probably something to do with my corporate windows computer (i know husky have issues with windows).

In plugins/nx-container/src/executors/build/ executor.ts I propose the following additions:

//...
const args: string[] = await engine.getArgs(inputs, defContext);
    const buildCmd = engine.getCommand(args);

    logger.verbose(`Build command: ${buildCmd.command} ${buildCmd.args.join(' ')}`); // <-- first addition

    await getExecOutput(
      buildCmd.command,
      buildCmd.args.map((arg) => interpolate(arg)),
      {
        ignoreReturnCode: true,
      }
    ).then((res) => {
      logger.verbose(res.stdout); // <-- Second addition

      if (res.stderr.length > 0 && res.exitCode != 0) {
        throw new Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
      }
    });

    await engine.finalize(inputs, ctx);
//...

This would let you see the final build command that is sent to docker or what ever engine you are using, and It will let you see the output from that command.