Skip to content

Commit

Permalink
feat(nx): add report function to @nrwl/workspace which lists versions…
Browse files Browse the repository at this point in the history
… of select packages
  • Loading branch information
catfireparty authored and vsavkin committed Oct 4, 2019
1 parent 98fc5e0 commit 1d377ea
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 8 deletions.
6 changes: 4 additions & 2 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ Please provide detailed steps for reproducing the issue.
2. step 2
3. ...

If you can provide steps to reproduce from scratch, that would be enormously appreciated (i.e. where the first step is `npx create-nx-workspace@latest repro-workspace`)

### Context

Please provide any relevant information about your setup:

- version of Nx used
- version of Nx used (_Please run `nx report` at the root of your workspace and copy the results here if you are using Nx 8.6.1 or greater_)
- 3rd-party libraries and their versions
- and most importantly - a use-case that fails

**A minimal reproduce scenario using allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.**
**A minimal reproduction scenario allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.**

### Failure Logs

Expand Down
21 changes: 21 additions & 0 deletions docs/angular/api-workspace/npmscripts/report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# report

Reports useful version numbers to copy into the Nx issue template

## Usage

```bash
nx report
```

Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`.

## Options

### help

Show help

### version

Show version number
21 changes: 21 additions & 0 deletions docs/react/api-workspace/npmscripts/report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# report

Reports useful version numbers to copy into the Nx issue template

## Usage

```bash
nx report
```

Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`.

## Options

### help

Show help

### version

Show version number
21 changes: 21 additions & 0 deletions docs/web/api-workspace/npmscripts/report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# report

Reports useful version numbers to copy into the Nx issue template

## Usage

```bash
nx report
```

Install `@nrwl/cli` globally to invoke the command directly using `nx`, or use `npm run nx` or `yarn nx`.

## Options

### help

Show help

### version

Show version number
34 changes: 34 additions & 0 deletions e2e/report.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { packagesWeCareAbout } from '@nrwl/workspace/src/command-line/report';
import { ensureProject, forEachCli, runCLI } from './utils';

const testTimeout = 120000;

forEachCli('nx', () => {
describe('report', () => {
it(
`should report package versions`,
async () => {
ensureProject();

const reportOutput = runCLI('report');

packagesWeCareAbout.forEach(p => {
expect(reportOutput).toContain(p);
});
},
testTimeout
);
});
});

forEachCli('angular', () => {
describe('report', () => {
it(
`shouldn't do anything at all`,
async () => {
// report is an Nx only command
},
testTimeout
);
});
});
38 changes: 37 additions & 1 deletion e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exec, execSync } from 'child_process';
import { readFileSync, statSync, writeFileSync, renameSync } from 'fs';
import { readFileSync, renameSync, statSync, writeFileSync } from 'fs';
import { ensureDirSync } from 'fs-extra';
import * as path from 'path';

Expand Down Expand Up @@ -317,6 +317,42 @@ export function runNgAdd(
}
}

export function runCLIFromSubfolder(
command?: string,
subFolder?: string,
opts = {
silenceError: false
}
): string {
const backToRoot = subFolder
? subFolder
.split('/')
.map(_ => '..')
.join('/')
: '.';

try {
return execSync(
`node ${backToRoot}/node_modules/@nrwl/cli/bin/nx.js ${command}`,
{
cwd: tmpProjPath(subFolder)
}
)
.toString()
.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
''
);
} catch (e) {
if (opts.silenceError) {
return e.stdout.toString();
} else {
console.log(e.stdout.toString(), e.stderr.toString());
throw e;
}
}
}

export function runCLI(
command?: string,
opts = {
Expand Down
17 changes: 12 additions & 5 deletions packages/workspace/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node
import { execSync } from 'child_process';
import { platform } from 'os';
import * as yargs from 'yargs';

import { nxVersion } from '../utils/versions';
import { affected } from './affected';
import { generateGraph } from './dep-graph';
import { format } from './format';
import { workspaceLint } from './lint';
import { report } from './report';
import { workspaceSchematic } from './workspace-schematic';
import { generateGraph } from './dep-graph';
import { nxVersion } from '../utils/versions';
import { execSync } from 'child_process';
import { platform } from 'os';

const noop = (yargs: yargs.Argv): yargs.Argv => yargs;

Expand All @@ -28,6 +28,7 @@ export const supportedNxCommands = [
'workspace-schematic',
'workspace-lint',
'migrate',
'report',
'--help',
'--version'
];
Expand Down Expand Up @@ -198,6 +199,12 @@ export const commandsObject = yargs
});
}
)
.command(
'report',
'Reports useful version numbers to copy into the Nx issue template',
noop,
_ => report()
)
.help('help')
.version(nxVersion)
.option('quiet', { type: 'boolean', hidden: true });
Expand Down
53 changes: 53 additions & 0 deletions packages/workspace/src/command-line/report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { terminal } from '@angular-devkit/core';
import { readFileSync } from 'fs';
import * as path from 'path';
import { appRootPath } from '../utils/app-root';
import { output } from './output';

export const packagesWeCareAbout = [
'@nrwl/angular',
'@nrwl/cli',
'@nrwl/cypress',
'@nrwl/eslint-plugin-nx',
'@nrwl/express',
'@nrwl/jest',
'@nrwl/linter',
'@nrwl/nest',
'@nrwl/next',
'@nrwl/node',
'@nrwl/react',
'@nrwl/schematics',
'@nrwl/tao',
'@nrwl/web',
'@nrwl/workspace',
'typescript'
];

/**
* Reports relevant version numbers for adding to an Nx issue report
*
* @remarks
*
* Must be run within an Nx workspace
*
*/
export function report() {
const nodeModulesDir = path.join(appRootPath, 'node_modules');
const bodyLines = [];

packagesWeCareAbout.forEach(p => {
let status = 'Not Found';
try {
const packageJson = JSON.parse(
readFileSync(path.join(nodeModulesDir, p, 'package.json')).toString()
);
status = packageJson.version;
} catch {}
bodyLines.push(`${terminal.green(p)} : ${terminal.bold(status)}`);
});

output.log({
title: 'Report complete - copy this into the issue template',
bodyLines
});
}

0 comments on commit 1d377ea

Please sign in to comment.