Skip to content

Commit

Permalink
implement #1683, improve "bit list" to support wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfirst committed Jul 27, 2019
1 parent b56b6d8 commit 9ea431d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

- [#1683](https://github.com/teambit/bit/issues/1683) introduce `--namespace` flag for `bit list` to support namespaces with wildcards
- [#1727](https://github.com/teambit/bit/issues/1727) prevent saving objects that link to invalid objects
- [#1856](https://github.com/teambit/bit/issues/1856) fix links deletion from `node_modules` after installing packages by a compiler on a capsule
- [#1710](https://github.com/teambit/bit/issues/1710) improve performance of importing an entire collection
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2e-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ export default class Helper {
return this.runCmd('bit init --bare', this.envScopePath);
}

listRemoteScope(bare: boolean = true) {
return this.runCmd(`bit list ${this.remoteScope} ${bare ? '--bare' : ''}`);
listRemoteScope(bare: boolean = true, options: string = '') {
return this.runCmd(`bit list ${this.remoteScope} ${options} ${bare ? '--bare' : ''}`);
}
listLocalScope(options: string = '') {
return this.runCmd(`bit list ${options}`);
Expand Down
30 changes: 30 additions & 0 deletions e2e/flows/id-with-wildcard.e2e.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,35 @@ describe('component id with wildcard', function () {
});
});
});
describe('list with wildcard', () => {
let output;
before(() => {
helper.getClonedLocalScope(scopeAfterAdd);
helper.tagAllComponents();
output = helper.listLocalScope('--namespace "bar/*"');
});
it('should list only for the matched components', () => {
expect(output).to.have.string('bar/foo');
});
it('should not list unmatched components', () => {
expect(output).to.not.have.string('utils');
});
});
describe('list remote with wildcard', () => {
let output;
before(() => {
helper.getClonedLocalScope(scopeAfterAdd);
helper.tagAllComponents();
helper.reInitRemoteScope();
helper.exportAllComponents();
output = helper.listRemoteScope(true, '--namespace "bar/*"');
});
it('should list only for the matched components', () => {
expect(output).to.have.string('bar/foo');
});
it('should not list unmatched components', () => {
expect(output).to.not.have.string('utils');
});
});
});
});
25 changes: 12 additions & 13 deletions src/api/consumer/lib/list-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ export default (async function list({
if (scopeName) {
const remotes = await getScopeRemotes(scope);
const remote: Remote = await remotes.resolve(scopeName, scope);
return remoteList(remote, namespacesUsingWildcards);
return remoteList(remote);
}
return scopeList();

return scopeList(consumer, showAll, showRemoteVersion);
});

function remoteList(remote: Remote, namespacesUsingWildcards?: string): Promise<ListScopeResult[]> {
loader.start(BEFORE_REMOTE_LIST);
return remote.list(namespacesUsingWildcards);
}
function remoteList(remote: Remote): Promise<ListScopeResult[]> {
loader.start(BEFORE_REMOTE_LIST);
return remote.list(namespacesUsingWildcards);
}

async function scopeList(consumer: Consumer, showAll: boolean, showRemoteVersion: boolean): Promise<ListScopeResult[]> {
loader.start(BEFORE_LOCAL_LIST);
const componentsList = new ComponentsList(consumer);
return componentsList.listScope(showRemoteVersion, showAll);
}
async function scopeList(): Promise<ListScopeResult[]> {
loader.start(BEFORE_LOCAL_LIST);
const componentsList = new ComponentsList(consumer);
return componentsList.listScope(showRemoteVersion, showAll, namespacesUsingWildcards);
}
});
16 changes: 9 additions & 7 deletions src/cli/commands/public-cmds/list-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default class List extends Command {
['s', 'scope', 'show all components of the scope, including indirect dependencies'],
['b', 'bare', 'show bare output (more details, less pretty)'],
['o', 'outdated', 'show latest versions from remotes'],
['j', 'json', 'show the output in JSON format']
['j', 'json', 'show the output in JSON format'],
['n', 'namespace <string>', 'show only specified namespace by using wildcards']
];
loader = true;
migration = true;
Expand All @@ -30,14 +31,15 @@ export default class List extends Command {
scope = false,
bare = false,
json = false,
outdated = false
}: { ids?: boolean, scope?: boolean, bare?: boolean, json?: boolean, outdated?: boolean }
outdated = false,
namespace
}: { ids?: boolean, scope?: boolean, bare?: boolean, json?: boolean, outdated?: boolean, namespace?: string }
): Promise<any> {
const params = { scopeName, showAll: scope, showRemoteVersion: outdated };
if (hasWildcard(scopeName) && scopeName.includes('/')) {
const scopeNameSplit = scopeName.split('/');
params.scopeName = R.head(scopeNameSplit);
params.namespacesUsingWildcards = R.tail(scopeNameSplit).join('/');
if (namespace) {
const namespaceWithWildcard = hasWildcard(namespace) ? namespace : `${namespace}/*`;
// $FlowFixMe
params.namespacesUsingWildcards = namespaceWithWildcard;
}
return listScope(params).then(listScopeResults => ({
listScopeResults,
Expand Down
11 changes: 9 additions & 2 deletions src/consumer/component/components-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,16 @@ export default class ComponentsList {
/**
* get called when the Consumer is available, shows also components from remote scopes
*/
async listScope(showRemoteVersion: boolean, includeNested: boolean): Promise<ListScopeResult[]> {
async listScope(
showRemoteVersion: boolean,
includeNested: boolean,
namespacesUsingWildcards?: string
): Promise<ListScopeResult[]> {
const components: ModelComponent[] = await this.getModelComponents();
const componentsSorted = ComponentsList.sortComponentsByName(components);
const componentsFilteredByWildcards = namespacesUsingWildcards
? ComponentsList.filterComponentsByWildcard(components, namespacesUsingWildcards)
: components;
const componentsSorted = ComponentsList.sortComponentsByName(componentsFilteredByWildcards);
const listScopeResults: ListScopeResult[] = componentsSorted.map((component: ModelComponent) => ({
id: component.toBitIdWithLatestVersion(),
deprecated: component.deprecated
Expand Down

0 comments on commit 9ea431d

Please sign in to comment.