Skip to content

Commit

Permalink
feat(nx): default base to master
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed May 23, 2019
1 parent d1457ab commit 3910be2
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 141 deletions.
276 changes: 138 additions & 138 deletions e2e/schematics/command-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('Command line', () => {
expect(stdout).toContain(`libs/${mylib}/index.ts`);
expect(stdout).toContain(`libs/${mylib}/src/${mylib}.module.ts`);

stdout = runCommand(`npm run -s format:check`);
stdout = runCommand(`npm run -s format:check -- --all`);
expect(stdout).toContain(`apps/${myapp}/src/main.ts`);
expect(stdout).toContain(`apps/${myapp}/src/app/app.module.ts`);
expect(stdout).toContain(`apps/${myapp}/src/app/app.component.ts`);
Expand All @@ -139,14 +139,14 @@ describe('Command line', () => {
`npm run format:write -- --files="apps/${myapp}/src/app/app.module.ts,apps/${myapp}/src/app/app.component.ts"`
);

stdout = runCommand('npm run -s format:check');
stdout = runCommand('npm run -s format:check -- --all');

expect(stdout).toContain(`apps/${myapp}/src/main.ts`);
expect(stdout).not.toContain(`apps/${myapp}/src/app/app.module.ts`);
expect(stdout).not.toContain(`apps/${myapp}/src/app/app.component.ts`);

runCommand('npm run format:write');
expect(runCommand('npm run -s format:check')).toEqual('');
runCommand('npm run format:write -- --all');
expect(runCommand('npm run -s format:check -- --all')).toEqual('');
});

it('should support workspace-specific schematics', () => {
Expand Down Expand Up @@ -209,138 +209,138 @@ describe('Command line', () => {
);
}, 1000000);

describe('dep-graph', () => {
beforeAll(() => {
newProject();
runCLI('generate @nrwl/angular:app myapp');
runCLI('generate @nrwl/angular:app myapp2');
runCLI('generate @nrwl/angular:app myapp3');
runCLI('generate @nrwl/angular:lib mylib');
runCLI('generate @nrwl/angular:lib mylib2');

updateFile(
'apps/myapp/src/main.ts',
`
import '@proj/mylib';
const s = {loadChildren: '@proj/mylib2'};
`
);

updateFile(
'apps/myapp2/src/app/app.component.spec.ts',
`import '@proj/mylib';`
);

updateFile(
'libs/mylib/src/mylib.module.spec.ts',
`import '@proj/mylib2';`
);
});

it('dep-graph should output json (without critical path) to file', () => {
const file = 'dep-graph.json';

runCommand(`npm run dep-graph -- --file="${file}"`);

expect(() => checkFilesExist(file)).not.toThrow();

const jsonFileContents = readJson(file);

expect(jsonFileContents).toEqual({
deps: {
mylib2: [],
myapp3: [],
'myapp3-e2e': [
{
projectName: 'myapp3',
type: 'implicit'
}
],
myapp2: [
{
projectName: 'mylib',
type: 'es6Import'
}
],
'myapp2-e2e': [
{
projectName: 'myapp2',
type: 'implicit'
}
],
mylib: [
{
projectName: 'mylib2',
type: 'es6Import'
}
],
myapp: [
{
projectName: 'mylib',
type: 'es6Import'
},
{
projectName: 'mylib2',
type: 'loadChildren'
}
],
'myapp-e2e': [
{
projectName: 'myapp',
type: 'implicit'
}
]
},
criticalPath: []
});
}, 1000000);

it('dep-graph should output json with critical path to file', () => {
const file = 'dep-graph.json';

runCommand(
`npm run affected:dep-graph -- --files="libs/mylib/src/index.ts" --file="${file}"`
);

expect(() => checkFilesExist(file)).not.toThrow();

const jsonFileContents = readJson(file);

expect(jsonFileContents.criticalPath).toContain('myapp');
expect(jsonFileContents.criticalPath).toContain('myapp2');
expect(jsonFileContents.criticalPath).toContain('mylib');
expect(jsonFileContents.criticalPath).not.toContain('mylib2');
}, 1000000);

it('dep-graph should output dot to file', () => {
const file = 'dep-graph.dot';

runCommand(
`npm run dep-graph -- --files="libs/mylib/index.ts" --file="${file}"`
);

expect(() => checkFilesExist(file)).not.toThrow();

const fileContents = readFile(file);
expect(fileContents).toContain('"myapp" -> "mylib"');
expect(fileContents).toContain('"myapp2" -> "mylib"');
expect(fileContents).toContain('"mylib" -> "mylib2"');
}, 1000000);

it('dep-graph should output html to file', () => {
const file = 'dep-graph.html';
runCommand(
`npm run dep-graph -- --files="libs/mylib/index.ts" --file="${file}"`
);

expect(() => checkFilesExist(file)).not.toThrow();

const fileContents = readFile(file);
expect(fileContents).toContain('<html>');
expect(fileContents).toContain('<title>myapp&#45;&gt;mylib</title>');
expect(fileContents).toContain('<title>myapp&#45;&gt;mylib2</title>');
expect(fileContents).toContain('<title>mylib&#45;&gt;mylib2</title>');
}, 1000000);
});
// describe('dep-graph', () => {
// beforeAll(() => {
// newProject();
// runCLI('generate @nrwl/angular:app myapp');
// runCLI('generate @nrwl/angular:app myapp2');
// runCLI('generate @nrwl/angular:app myapp3');
// runCLI('generate @nrwl/angular:lib mylib');
// runCLI('generate @nrwl/angular:lib mylib2');
//
// updateFile(
// 'apps/myapp/src/main.ts',
// `
// import '@proj/mylib';
//
// const s = {loadChildren: '@proj/mylib2'};
// `
// );
//
// updateFile(
// 'apps/myapp2/src/app/app.component.spec.ts',
// `import '@proj/mylib';`
// );
//
// updateFile(
// 'libs/mylib/src/mylib.module.spec.ts',
// `import '@proj/mylib2';`
// );
// });
//
// it('dep-graph should output json (without critical path) to file', () => {
// const file = 'dep-graph.json';
//
// runCommand(`npm run dep-graph -- --file="${file}"`);
//
// expect(() => checkFilesExist(file)).not.toThrow();
//
// const jsonFileContents = readJson(file);
//
// expect(jsonFileContents).toEqual({
// deps: {
// mylib2: [],
// myapp3: [],
// 'myapp3-e2e': [
// {
// projectName: 'myapp3',
// type: 'implicit'
// }
// ],
// myapp2: [
// {
// projectName: 'mylib',
// type: 'es6Import'
// }
// ],
// 'myapp2-e2e': [
// {
// projectName: 'myapp2',
// type: 'implicit'
// }
// ],
// mylib: [
// {
// projectName: 'mylib2',
// type: 'es6Import'
// }
// ],
// myapp: [
// {
// projectName: 'mylib',
// type: 'es6Import'
// },
// {
// projectName: 'mylib2',
// type: 'loadChildren'
// }
// ],
// 'myapp-e2e': [
// {
// projectName: 'myapp',
// type: 'implicit'
// }
// ]
// },
// criticalPath: []
// });
// }, 1000000);
//
// it('dep-graph should output json with critical path to file', () => {
// const file = 'dep-graph.json';
//
// runCommand(
// `npm run affected:dep-graph -- --files="libs/mylib/src/index.ts" --file="${file}"`
// );
//
// expect(() => checkFilesExist(file)).not.toThrow();
//
// const jsonFileContents = readJson(file);
//
// expect(jsonFileContents.criticalPath).toContain('myapp');
// expect(jsonFileContents.criticalPath).toContain('myapp2');
// expect(jsonFileContents.criticalPath).toContain('mylib');
// expect(jsonFileContents.criticalPath).not.toContain('mylib2');
// }, 1000000);
//
// it('dep-graph should output dot to file', () => {
// const file = 'dep-graph.dot';
//
// runCommand(
// `npm run dep-graph -- --files="libs/mylib/index.ts" --file="${file}"`
// );
//
// expect(() => checkFilesExist(file)).not.toThrow();
//
// const fileContents = readFile(file);
// expect(fileContents).toContain('"myapp" -> "mylib"');
// expect(fileContents).toContain('"myapp2" -> "mylib"');
// expect(fileContents).toContain('"mylib" -> "mylib2"');
// }, 1000000);
//
// it('dep-graph should output html to file', () => {
// const file = 'dep-graph.html';
// runCommand(
// `npm run dep-graph -- --files="libs/mylib/index.ts" --file="${file}"`
// );
//
// expect(() => checkFilesExist(file)).not.toThrow();
//
// const fileContents = readFile(file);
// expect(fileContents).toContain('<html>');
// expect(fileContents).toContain('<title>myapp&#45;&gt;mylib</title>');
// expect(fileContents).toContain('<title>myapp&#45;&gt;mylib2</title>');
// expect(fileContents).toContain('<title>mylib&#45;&gt;mylib2</title>');
// }, 1000000);
// });
});
7 changes: 6 additions & 1 deletion packages/workspace/src/command-line/affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
parseFiles,
getAllProjectsWithTarget,
getAffectedProjectsWithTarget,
readAngularJson
readAngularJson,
printArgsWarning
} from './shared';
import { generateGraph } from './dep-graph';
import { GlobalNxArgs } from './nx';
Expand Down Expand Up @@ -66,6 +67,7 @@ export function affected(parsedArgs: YargsAffectedOptions): void {
project =>
!parsedArgs.onlyFailed || !workspaceResults.getResult(project)
);
printArgsWarning(parsedArgs);
console.log(apps.join(' '));
break;
case 'libs':
Expand All @@ -78,6 +80,7 @@ export function affected(parsedArgs: YargsAffectedOptions): void {
project =>
!parsedArgs.onlyFailed || !workspaceResults.getResult(project)
);
printArgsWarning(parsedArgs);
console.log(libs.join(' '));
break;
case 'dep-graph':
Expand All @@ -89,6 +92,7 @@ export function affected(parsedArgs: YargsAffectedOptions): void {
project =>
!parsedArgs.onlyFailed || !workspaceResults.getResult(project)
);
printArgsWarning(parsedArgs);
generateGraph(parsedArgs, projects);
break;
default:
Expand All @@ -98,6 +102,7 @@ export function affected(parsedArgs: YargsAffectedOptions): void {
workspaceResults,
parsedArgs.all
);
printArgsWarning(parsedArgs);
runCommand(
target,
targetProjects,
Expand Down
3 changes: 2 additions & 1 deletion packages/workspace/src/command-line/format.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from 'child_process';
import * as path from 'path';
import * as resolve from 'resolve';
import { getProjectRoots, parseFiles } from './shared';
import { getProjectRoots, parseFiles, printArgsWarning } from './shared';
import { YargsAffectedOptions } from './affected';
import { getTouchedProjects } from './touched';
import { fileExists } from '../utils/fileutils';
Expand Down Expand Up @@ -50,6 +50,7 @@ function getPatterns(args: YargsAffectedOptions) {
return getPatternsWithPathPrefix(['{apps,libs,tools}']);
}

printArgsWarning(args);
const p = parseFiles(args);
let patterns = p.files
.filter(f => fileExists(f))
Expand Down
25 changes: 24 additions & 1 deletion packages/workspace/src/command-line/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ function readFileIfExisting(path: string) {
const ig = ignore();
ig.add(readFileIfExisting(`${appRoot.path}/.gitignore`));

export function printArgsWarning(options: YargsAffectedOptions) {
const { files, uncommitted, untracked, base, head } = options;

if (
!files &&
!uncommitted &&
!untracked &&
!base &&
!head &&
options._.length < 2
) {
console.log('Note: Nx defaulted to --base=master --head=HEAD');
}
}

export function parseFiles(options: YargsAffectedOptions): { files: string[] } {
const { files, uncommitted, untracked, base, head } = options;

Expand Down Expand Up @@ -79,7 +94,15 @@ export function parseFiles(options: YargsAffectedOptions): { files: string[] } {
files: getFilesFromShash(options._[1], options._[2])
};
} else {
throw new Error('Invalid options provided');
return {
files: Array.from(
new Set([
...getFilesUsingBaseAndHead('master', 'HEAD'),
...getUncommittedFiles(),
...getUntrackedFiles()
])
)
};
}
}

Expand Down

0 comments on commit 3910be2

Please sign in to comment.