Skip to content

Commit 3a6ce8a

Browse files
author
David First
authored
Feature/dynamic namespaces (teambit#1151)
* support dynamic namespaces (replaced the box+name format with a dynamic name that can have multiple slashes to indicate a hierarchical namespace) * performance improvement - do not loadFromFileSystem the same component twice * prevent importing different components with scope+name equals to a local name
1 parent 5433e99 commit 3a6ce8a

File tree

138 files changed

+2053
-1310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+2053
-1310
lines changed

.eslintignore-circle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ specs/scope/migrations/objectsFixtures/simple-component.js
1515
specs/specs-runner/fixtures/invalid-tester.js
1616
src/api/consumer/lib/isolate.js
1717
src/api/consumer/lib/migrate.js
18-
src/api/consumer/lib/untrack.js
1918
src/api/scope/lib/deprecate.js
2019
src/api/scope/lib/modify-ci-props.js
2120
src/cli/command-registrar-builder.js
@@ -50,7 +49,6 @@ src/cli/cli-utils.js
5049
src/cli/command.js
5150
src/cli/commands/private-cmds/_fetch-cmd.js
5251
src/cli/commands/private-cmds/scope-config-cmd.js
53-
src/cli/commands/public-cmds/commit-cmd.js
5452
src/cli/commands/public-cmds/config-cmd.js
5553
src/cli/commands/public-cmds/list-cmd.js
5654
src/cli/commands/public-cmds/logout-cmd.js
@@ -68,7 +66,6 @@ src/utils/array/filter-async.js
6866
src/utils/buffer/from.js
6967
src/utils/path.js
7068
src/api/scope/lib/put.js
71-
src/bit-id/bit-ids.js
7269
src/cli/commands/private-cmds/ci-update-cmd.js
7370
src/consumer/specs-results/specs-results.js
7471
src/driver/driver.js
@@ -92,7 +89,6 @@ src/cli/templates/docs-template.js
9289
src/consumer/component/sources/source-file.js
9390
src/consumer/migrations/consumer-migrator.js
9491
specs/scope/migrations/scope-migrator.spec.js
95-
src/bit-id/bit-id.js
9692
src/cli/chalk-box.js
9793
src/cli/commands/public-cmds/deprecate-cmd.js
9894
src/scope/migrations/component-version/to-semver-migration.js

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [unreleased]
99

10+
- support dynamic namespaces (replaced the box+name format with a dynamic name that can have multiple slashes to indicate a hierarchical namespace)
11+
1012
## [[13.0.4] - 2018-07-24](https://github.com/teambit/bit/releases/tag/v13.0.4)
1113

1214
### New

e2e/bitsrc-tester.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import requestify from 'requestify';
22

33
// const apiBaseUrl = process.env.NODE_ENV === 'production' ? 'https://api.bitsrc.io' : 'https://api-stg.bitsrc.io';
4+
const supportTestingOnBitsrc = false;
45
const apiBaseUrl = process.env.BITSRC_ENV === 'stg' ? 'https://api-stg.bitsrc.io' : 'https://api.bitsrc.io';
56
const username = process.env.testerBitsrcUsername || 'tester';
67
const password = process.env.testerBitsrcPassword;
78

8-
export { username };
9+
export { username, supportTestingOnBitsrc };
910
const debugMode = !!process.env.npm_config_debug;
1011
export default class BitsrcTester {
1112
cookies;
1213

1314
init() {
15+
if (!supportTestingOnBitsrc) throw new Error('supportTestingOnBitsrc is set to false');
1416
return requestify
1517
.post(`${apiBaseUrl}/user/login`, { username, password })
1618
.then((res) => {

e2e/commands/add.e2e.1.js

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
VersionShouldBeRemoved,
1212
MainFileIsDir
1313
} from '../../src/consumer/component-ops/add-components/exceptions';
14+
import { InvalidName } from '../../src/bit-id/exceptions';
1415

1516
chai.use(require('chai-fs'));
1617

@@ -369,38 +370,18 @@ describe('bit add command', function () {
369370
expect(bitMap['bar/foo1'].origin).to.equal('AUTHORED');
370371
});
371372
it('Should prevent adding a file with invalid keys in namespace', () => {
372-
let errMsg;
373+
const error = new InvalidName('bar.f/foo');
373374
helper.createComponentBarFoo();
374-
const normalizedPath = path.normalize('bar/foo.js');
375-
try {
376-
helper.addComponentWithOptions(normalizedPath, { i: 'bar.f/foo' });
377-
} catch (err) {
378-
errMsg = err.message;
379-
}
380-
expect(errMsg).to.have.string(
381-
`Command failed: ${
382-
helper.bitBin
383-
} add ${normalizedPath} -i bar.f/foo\nerror: "bar.f/foo" is invalid, component IDs can only contain alphanumeric, lowercase characters, and the following ["-", "_", "$", "!"]\n`
384-
);
375+
const addFunc = () => helper.addComponentWithOptions('bar/foo.js', { i: 'bar.f/foo' });
376+
helper.expectToThrow(addFunc, error);
385377
});
386378
it('Should prevent adding a file with invalid keys in ID', () => {
387-
let errMsg;
379+
const error = new InvalidName('bar/fo.o');
388380
helper.createComponentBarFoo();
389-
let normalizedPath;
390-
try {
391-
normalizedPath = path.normalize('bar/foo.js');
392-
helper.addComponentWithOptions(normalizedPath, { i: 'bar/fo.o' });
393-
} catch (err) {
394-
errMsg = err.message;
395-
}
396-
expect(errMsg).to.have.string(
397-
`Command failed: ${
398-
helper.bitBin
399-
} add ${normalizedPath} -i bar/fo.o\nerror: "bar/fo.o" is invalid, component IDs can only contain alphanumeric, lowercase characters, and the following ["-", "_", "$", "!"]\n`
400-
);
381+
const addFunc = () => helper.addComponentWithOptions('bar/foo.js', { i: 'bar/fo.o' });
382+
helper.expectToThrow(addFunc, error);
401383
});
402384
it.skip('Bitmap mainFile should point to correct mainFile', () => {});
403-
it.skip('should not allow adding a component with an existing box-name and component-name', () => {});
404385
});
405386
describe('adding file to existing tagged component', () => {
406387
let bitMap;
@@ -534,24 +515,17 @@ describe('bit add command', function () {
534515
});
535516
it('Should return error if used an invalid ID', () => {
536517
helper.createFile('bar', 'foo.js');
537-
let errorMessage;
538-
try {
539-
helper.addComponentWithOptions('bar', {
540-
i: 'Bar/Foo'
541-
});
542-
} catch (err) {
543-
errorMessage = err.message;
544-
}
545-
546-
expect(errorMessage).to.have.string('error: "Bar/Foo" is invalid, component IDs can only contain');
518+
const addFunc = () => helper.addComponentWithOptions('bar/foo.js', { i: 'Bar/foo' });
519+
const error = new InvalidName('Bar/foo');
520+
helper.expectToThrow(addFunc, error);
547521
});
548-
it('Should add component with global namespace if used parcial ID', () => {
522+
it('should add component with id contains only one level', () => {
549523
helper.createFile('bar', 'foo.js');
550524
helper.addComponentWithOptions('bar', {
551525
i: 'foo'
552526
});
553527
const bitMap = helper.readBitMap();
554-
expect(bitMap).to.have.property('global/foo');
528+
expect(bitMap).to.have.property('foo');
555529
});
556530
it('Should add dir files with spec from multiple dsls when test files are placed in same structure', () => {
557531
helper.createFile('bar', 'foo.js');

e2e/commands/deprecate.e2e.1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('bit deprecate command', function () {
4141
expect(listOutput).to.contain.string('bar/foo [Deprecated]');
4242
});
4343
it('should export component as deprecated ', () => {
44-
helper.deprecateComponent(`${helper.remoteScope}/bar/foo`);
44+
helper.deprecateComponent('bar/foo');
4545
helper.exportAllComponents();
4646
output = helper.listRemoteScope(false);
4747
expect(output).to.contain.string('bar/foo');

e2e/commands/export.e2e.1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ describe('bit export command', function () {
262262
helper.addRemoteScope();
263263
helper.importComponent('bar/foo');
264264

265-
helper.commitComponentBarFoo(); // v3
265+
helper.commitComponent('bar/foo -f'); // v3
266266
helper.exportComponent(`${helper.remoteScope}/bar/foo`);
267267
});
268268
it('should export it with no errors', () => {
269269
const output = helper.listRemoteScope();
270-
expect(output.includes(`${helper.remoteScope}/bar/[email protected]`)).to.be.true;
270+
expect(output).to.have.string(`${helper.remoteScope}/bar/[email protected]`);
271271
});
272272
});
273273

@@ -337,7 +337,7 @@ describe('bit export command', function () {
337337
helper.commitComponentBarFoo();
338338
helper.exportComponent('bar/foo');
339339
try {
340-
output = helper.exportComponent('bar/foo');
340+
output = helper.exportComponent('bar/foo', undefined, false);
341341
} catch (err) {
342342
errorOutput = err.message;
343343
}
@@ -346,7 +346,7 @@ describe('bit export command', function () {
346346
expect(output).to.be.undefined;
347347
});
348348
it('should throw an error saying the component was already exported', () => {
349-
expect(errorOutput.includes('has been already exported')).to.be.true;
349+
expect(errorOutput).to.have.string('has been already exported');
350350
});
351351
});
352352

e2e/commands/import.e2e.1.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ describe('bit import', function () {
2929
// export a new simple component
3030
helper.createFile('global', 'simple.js');
3131
helper.addComponent(path.normalize('global/simple.js'));
32-
helper.commitComponent('simple');
33-
helper.exportComponent('simple');
32+
helper.commitComponent('global/simple');
33+
helper.exportComponent('global/simple');
3434

3535
helper.reInitLocalScope();
3636
helper.addRemoteScope();
@@ -272,7 +272,7 @@ describe('bit import', function () {
272272
let output;
273273
before(() => {
274274
helper.reInitLocalScope();
275-
helper.setComponentsDirInBitJson('{scope}/{namespace}-{name}');
275+
helper.setComponentsDirInBitJson('{scope}/-{name}-');
276276
helper.addRemoteScope();
277277
helper.importComponent('global/simple');
278278
output = helper.importComponent('global/simple');
@@ -281,15 +281,15 @@ describe('bit import', function () {
281281
expect(output).to.have.string('successfully imported one component');
282282
});
283283
it('should import the component into new dir structure according to dsl', () => {
284-
expect(path.join(helper.localScopePath, helper.remoteScope, 'global-simple')).to.be.a.directory(
284+
expect(path.join(helper.localScopePath, helper.remoteScope, '-global/simple-')).to.be.a.directory(
285285
'should not be empty'
286286
).and.not.empty;
287287
});
288288
it('bitmap should contain component with correct rootDir according to dsl', () => {
289289
const bitMap = helper.readBitMap();
290290
const cmponentId = `${helper.remoteScope}/global/[email protected]`;
291291
expect(bitMap).to.have.property(cmponentId);
292-
expect(bitMap[cmponentId].rootDir).to.equal(`${helper.remoteScope}/global-simple`);
292+
expect(bitMap[cmponentId].rootDir).to.equal(`${helper.remoteScope}/-global/simple-`);
293293
});
294294
});
295295
});
@@ -676,8 +676,8 @@ describe('bit import', function () {
676676
const simpleFixture = 'import a from "lodash.isboolean"; ';
677677
helper.createFile('global', 'simple.js', simpleFixture);
678678
helper.addComponentWithOptions('global/simple.js', { i: 'global/simple' });
679-
helper.commitComponent('simple');
680-
helper.exportComponent('simple');
679+
helper.commitComponent('global/simple');
680+
helper.exportComponent('global/simple');
681681

682682
helper.addNpmPackage('lodash.isstring', '4.0.0');
683683
const withDepsFixture = 'import a from "./global/simple.js"; import c from "lodash.isstring"';
@@ -2109,8 +2109,8 @@ console.log(barFoo.default());`;
21092109
const simpleFixture = 'import a from "lodash.isboolean"; ';
21102110
helper.createFile('global', 'simple.js', simpleFixture);
21112111
helper.addComponentWithOptions('global/simple.js', { i: 'global/simple' });
2112-
helper.commitComponent('simple');
2113-
helper.exportComponent('simple');
2112+
helper.commitComponent('global/simple');
2113+
helper.exportComponent('global/simple');
21142114
helper.addNpmPackage('lodash.isstring', '4.0.0');
21152115
const withDepsFixture = 'import a from "./global/simple.js"; import c from "lodash.isstring"';
21162116
helper.createFile('', 'with-deps.js', withDepsFixture);
@@ -2137,7 +2137,7 @@ console.log(barFoo.default());`;
21372137
});
21382138
it('should contain workspaces array in package.json and private true', () => {
21392139
const pkgJson = helper.readPackageJson(helper.localScopePath);
2140-
expect(pkgJson.workspaces).to.include('components/.dependencies/*/*/*/*', 'components/*/*');
2140+
expect(pkgJson.workspaces).to.include('components/.dependencies/**/*', 'components/**/*');
21412141
expect(pkgJson.private).to.be.true;
21422142
});
21432143
it('component dep should be install as npm package', () => {
@@ -2152,7 +2152,7 @@ console.log(barFoo.default());`;
21522152
it('Should not contain duplicate regex in workspaces dir if we run import again ', () => {
21532153
helper.importComponent('comp/with-deps --override');
21542154
const pkgJson = helper.readPackageJson(helper.localScopePath);
2155-
expect(pkgJson.workspaces).to.include('components/.dependencies/*/*/*/*', 'components/*/*');
2155+
expect(pkgJson.workspaces).to.include('components/.dependencies/**/*', 'components/**/*');
21562156
expect(pkgJson.workspaces).to.be.ofSize(2);
21572157
expect(path.join(helper.localScopePath, 'yarn.lock')).to.be.a.file('no yarn lock file');
21582158
});
@@ -2166,19 +2166,15 @@ console.log(barFoo.default());`;
21662166
helper.addKeyValueToPackageJson({ workspaces: ['comp'] });
21672167
helper.importComponent('comp/with-deps --override');
21682168
const pkgJson = helper.readPackageJson();
2169-
expect(pkgJson.workspaces).to.include(
2170-
'components/.dependencies/*/*/*/*',
2171-
'components/*/*',
2172-
'test/comp/with-deps'
2173-
);
2169+
expect(pkgJson.workspaces).to.include('components/.dependencies/**/*', 'components/**/*', 'test/comp/with-deps');
21742170
});
21752171
it('Should save workspaces with custom import path ', () => {
21762172
helper.reInitLocalScope();
21772173
helper.addRemoteScope(helper.remoteScopePath);
21782174
helper.manageWorkspaces();
21792175
helper.importComponent('comp/with-deps -p test');
21802176
const pkgJson = helper.readPackageJson();
2181-
expect(pkgJson.workspaces).to.include('components/.dependencies/*/*/*/*', 'components/*/*', 'test');
2177+
expect(pkgJson.workspaces).to.include('components/.dependencies/**/*', 'components/**/*', 'test');
21822178
});
21832179
});
21842180
describe('importing a component when it has a local tag', () => {

e2e/commands/merge.e2e.2.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ describe('bit merge command', function () {
8787
it('as an intermediate step, make sure the dependencies are correct', () => {
8888
const barFoo = helper.catComponent('bar/[email protected]');
8989
expect(barFoo.dependencies).to.have.lengthOf(1);
90-
expect(barFoo.dependencies[0].id).to.equal('utils/[email protected]');
90+
expect(barFoo.dependencies[0].id.name).to.equal('utils/is-string');
91+
expect(barFoo.dependencies[0].id.version).to.equal('0.0.2');
9192
expect(barFoo.flattenedDependencies).to.have.lengthOf(2);
92-
expect(barFoo.flattenedDependencies).to.include('utils/is-string@0.0.2');
93-
expect(barFoo.flattenedDependencies).to.include('utils/is-type@0.0.2');
93+
expect(barFoo.flattenedDependencies).to.deep.include({ name: 'utils/is-string', version: '0.0.2' });
94+
expect(barFoo.flattenedDependencies).to.deep.include({ name: 'utils/is-type', version: '0.0.2' });
9495
});
9596
describe('as authored', () => {
9697
before(() => {

e2e/commands/remove.e2e.2.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,6 @@ describe('bit remove command', function () {
361361
helper.exportComponent('utils/is-string');
362362
helper.exportComponent('utils/is-string2');
363363
});
364-
it.skip('should remove component version only', () => {
365-
const output = helper.removeComponent(`${helper.remoteScope}/utils/[email protected] -s`);
366-
expect(output).to.contain.string('successfully removed components');
367-
expect(output).to.contain.string(`${helper.remoteScope}/utils/[email protected]`);
368-
});
369364
it('should import component is-string with no issues', () => {
370365
helper.reInitLocalScope();
371366
helper.addRemoteScope();

e2e/commands/show.e2e.2.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,11 @@ describe('bit show command', function () {
129129
});
130130

131131
it('should include the name correctly', () => {
132-
expect(output).to.include({ name: 'comp' });
132+
expect(output).to.include({ name: 'comp/comp' });
133133
});
134134

135-
it('should include the namespace correctly', () => {
136-
expect(output).to.include({ box: 'comp' });
137-
});
138-
139-
// TODO: Check again after this commit merged: 6ee69fab36f5b9f31fa576216c6bf22808d0d459
140-
it.skip('should include the version correctly', () => {
141-
expect(output).to.include({ version: 1 });
135+
it('should include the version correctly', () => {
136+
expect(output).to.include({ version: '0.0.1' });
142137
});
143138

144139
// TODO: get the version dynamically
@@ -276,14 +271,18 @@ describe('bit show command', function () {
276271
helper.addComponentBarFoo();
277272
helper.commitComponentBarFoo();
278273
helper.exportAllComponents();
279-
});
280-
it('should show deprecated component', () => {
281274
helper.deprecateComponent(`${helper.remoteScope}/bar/foo`, '-r');
282-
output = JSON.parse(helper.runCmd(`bit show ${helper.remoteScope}/bar/foo -j`));
275+
});
276+
it('should show the component as deprecated when using "--remote" flag', () => {
277+
output = JSON.parse(helper.runCmd(`bit show ${helper.remoteScope}/bar/foo -j -r`));
283278
expect(output).to.include({ deprecated: true });
284279
});
280+
it('should not show the component as deprecated when not using "--remote" flag', () => {
281+
output = JSON.parse(helper.runCmd(`bit show ${helper.remoteScope}/bar/foo -j`));
282+
expect(output).to.include({ deprecated: false });
283+
});
285284
});
286-
describe('show deprecated remote component', () => {
285+
describe('show non-deprecated remote component', () => {
287286
let output;
288287
before(() => {
289288
helper.setNewLocalAndRemoteScopes();
@@ -292,7 +291,11 @@ describe('bit show command', function () {
292291
helper.commitComponentBarFoo();
293292
helper.exportAllComponents();
294293
});
295-
it('should show regular component', () => {
294+
it('should indicate a component as non-deprecated when using "--remote" flag', () => {
295+
output = JSON.parse(helper.runCmd(`bit show ${helper.remoteScope}/bar/foo -j -r`));
296+
expect(output).to.include({ deprecated: false });
297+
});
298+
it('should indicate a component as non-deprecated when not using "--remote flag', () => {
296299
output = JSON.parse(helper.runCmd(`bit show ${helper.remoteScope}/bar/foo -j`));
297300
expect(output).to.include({ deprecated: false });
298301
});
@@ -580,8 +583,7 @@ function add(a, b) {
580583
const parsedOutput = JSON.parse(output);
581584
expect(parsedOutput).to.be.ofSize(1);
582585
expect(parsedOutput[0]).to.to.include({
583-
name: 'foo',
584-
box: 'bar',
586+
name: 'bar/foo',
585587
version: '0.0.1'
586588
});
587589
});

0 commit comments

Comments
 (0)