-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable executing commands on remote components outside of bit-workspa…
…ce (#1884) * implements #1837, enable running "bit list" of a remote scope without a bit-workspace * allow bit-deprecate and bit-undeprecate to work outside bit-workspace * change the machine of lint to be medium instead of small (hopefully it will fix the error of "Flow returned an error: Out of retries, exiting!") * enable remove remote components using wildcards regardless whether the components exist locally * enable remove components from a remote scope outside of a bit-workspace
- Loading branch information
1 parent
0401d3b
commit 5ffb681
Showing
18 changed files
with
300 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { expect } from 'chai'; | ||
import Helper from '../e2e-helper'; | ||
import { ConsumerNotFound } from '../../src/consumer/exceptions'; | ||
|
||
describe('bit remote command', function () { | ||
this.timeout(0); | ||
const helper = new Helper(); | ||
after(() => { | ||
helper.destroyEnv(); | ||
}); | ||
describe('exporting a component to a global remote', () => { | ||
before(() => { | ||
helper.reInitLocalScope(); | ||
helper.reInitRemoteScope(); | ||
helper.runCmd(`bit remote add file://${helper.remoteScopePath} --global`); | ||
helper.createComponentBarFoo(); | ||
helper.addComponentBarFoo(); | ||
helper.tagAllComponents(); | ||
helper.exportAllComponents(); | ||
helper.cleanLocalScope(); | ||
}); | ||
after(() => { | ||
helper.runCmd(`bit remote del ${helper.remoteScope} --global`); | ||
}); | ||
it('bit status should throw an error ConsumerNotFound', () => { | ||
const error = new ConsumerNotFound(); | ||
const func = () => helper.status(); | ||
helper.expectToThrow(func, error); | ||
}); | ||
it('bit list without --remote flag should throw an error ConsumerNotFound', () => { | ||
const error = new ConsumerNotFound(); | ||
const func = () => helper.listLocalScope(); | ||
helper.expectToThrow(func, error); | ||
}); | ||
it('bit list with --remote flag should list the global remote successfully', () => { | ||
const output = helper.listRemoteScope(); | ||
expect(output).to.have.string('found 1 components'); | ||
}); | ||
it('bit show should show the component and not throw an error about missing workspace', () => { | ||
const output = helper.showComponent(`${helper.remoteScope}/bar/foo --remote`); | ||
expect(output).to.have.string('bar/foo'); | ||
}); | ||
describe('bit deprecate with --remote flag', () => { | ||
let output; | ||
before(() => { | ||
output = helper.deprecateComponent(`${helper.remoteScope}/bar/foo`, '--remote'); | ||
}); | ||
it('should not throw an error', () => { | ||
expect(output).to.have.string('deprecated components'); | ||
}); | ||
it('should deprecate successfully', () => { | ||
const list = helper.listRemoteScopeParsed(); | ||
expect(list[0].deprecated).to.be.true; | ||
}); | ||
describe('bit undeprecate with --remote flag', () => { | ||
let undeprecateOutput; | ||
before(() => { | ||
undeprecateOutput = helper.undeprecateComponent(`${helper.remoteScope}/bar/foo`, '--remote'); | ||
}); | ||
it('should not throw an error', () => { | ||
expect(undeprecateOutput).to.have.string('undeprecated components'); | ||
}); | ||
it('should deprecate successfully', () => { | ||
const list = helper.listRemoteScopeParsed(); | ||
expect(list[0].deprecated).to.be.false; | ||
}); | ||
}); | ||
}); | ||
describe('bit remove with --remote flag', () => { | ||
let output; | ||
before(() => { | ||
output = helper.removeComponent(`${helper.remoteScope}/bar/foo`, '--silent --remote'); | ||
}); | ||
it('should not throw an error', () => { | ||
expect(output).to.have.string('successfully removed'); | ||
}); | ||
it('should remove successfully', () => { | ||
const list = helper.listRemoteScopeParsed(); | ||
expect(list).to.have.lengthOf(0); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
/** @flow */ | ||
import { loadConsumer, Consumer } from '../../../consumer'; | ||
import { loadConsumer, loadConsumerIfExist, Consumer } from '../../../consumer'; | ||
import loader from '../../../cli/loader'; | ||
import { BEFORE_REMOTE_DEPRECATE, BEFORE_REMOTE_UNDEPRECATE } from '../../../cli/loader/loader-messages'; | ||
import { BitId } from '../../../bit-id'; | ||
import { | ||
deprecateRemote, | ||
deprecateMany, | ||
undeprecateRemote, | ||
undeprecateMany | ||
} from '../../../scope/component-ops/components-deprecation'; | ||
import { Remotes } from '../../../remotes'; | ||
import { getScopeRemotes } from '../../../scope/scope-remotes'; | ||
import BitIds from '../../../bit-id/bit-ids'; | ||
|
||
export async function deprecate({ ids, remote }: { ids: string[], remote: boolean }): Promise<any> { | ||
if (remote) loader.start(BEFORE_REMOTE_DEPRECATE); | ||
if (remote) { | ||
loader.start(BEFORE_REMOTE_DEPRECATE); | ||
const consumer = await loadConsumerIfExist(); | ||
const bitIds = getBitIdsForRemote(ids); | ||
const remotes = await getRemotes(consumer); | ||
const scope = consumer ? consumer.scope : null; | ||
return deprecateRemote(remotes, scope, bitIds); | ||
} | ||
const consumer = await loadConsumer(); | ||
const bitIds = getBitIds(ids, remote, consumer); | ||
return consumer.deprecate(bitIds, remote); | ||
const bitIds = getBitIdsForLocal(ids, consumer); | ||
return deprecateMany(consumer.scope, bitIds); | ||
} | ||
|
||
export async function undeprecate({ ids, remote }: { ids: string[], remote: boolean }): Promise<any> { | ||
if (remote) loader.start(BEFORE_REMOTE_UNDEPRECATE); | ||
if (remote) { | ||
loader.start(BEFORE_REMOTE_UNDEPRECATE); | ||
const consumer = await loadConsumerIfExist(); | ||
const bitIds = getBitIdsForRemote(ids); | ||
const remotes = await getRemotes(consumer); | ||
const scope = consumer ? consumer.scope : null; | ||
return undeprecateRemote(remotes, scope, bitIds); | ||
} | ||
const consumer = await loadConsumer(); | ||
const bitIds = getBitIds(ids, remote, consumer); | ||
return consumer.undeprecate(bitIds, remote); | ||
const bitIds = getBitIdsForLocal(ids, consumer); | ||
return undeprecateMany(consumer.scope, bitIds); | ||
} | ||
|
||
function getBitIds(ids: string[], remote: boolean, consumer: Consumer): BitId[] { | ||
return ids.map((id) => { | ||
return remote ? BitId.parse(id, true) : consumer.getParsedId(id); | ||
}); | ||
function getRemotes(consumer: ?Consumer): Promise<Remotes> { | ||
return consumer ? getScopeRemotes(consumer.scope) : Remotes.getGlobalRemotes(); | ||
} | ||
|
||
function getBitIdsForLocal(ids: string[], consumer: Consumer): BitIds { | ||
return BitIds.fromArray(ids.map(id => consumer.getParsedId(id))); | ||
} | ||
|
||
function getBitIdsForRemote(ids: string[]): BitId[] { | ||
return ids.map(id => BitId.parse(id, true)); | ||
} |
Oops, something went wrong.