Skip to content

Commit

Permalink
fix conflicts after merging master to harmony/main (#2358)
Browse files Browse the repository at this point in the history
* fix #2211 and #2308, when exporting to multiple scopes, make sure to not export their dependencies when these dependencies themselves are not export pending (#2309)

* bump dev version

* resolve #2268, prevent logger from holding the terminal once a command is completed by adding an error handler. Also, changed some "logger.debug" to "logger.silly". Also, support configuring the logger level by running "bit config set log_level <level>". Also, limit the number of concurrent files write to 100 (#2310)

* fix typo in the BitId README

* fix "bit status" and "bit tag" when new components require each other by module paths (#2313)

* Fix e2e-tests to avoid code execution inside "describe" blocks (#2329)

* move all Helper instantiation from describe to before.
* fix defaultScope tests, remove code that was entered by mistake in the describe block to before block.
* delete javascript-hook.e2e file, the tests there were written long ago, marked as "skip" and not relevant anymore.

* support import/require statements of module paths when it has no scope-name (e.g. "@bit/button") (#2331)

* resolve part of #2341, enable "--all" flag when "--all-versions" is used and vice versa, to enable re-exporting a component after deleting it (#2345)

* Fixed broken link leading to quick start guide (#2338)

* fix dynamic dist reference from package.json (#1808) when isolating via capsule (#2348)

* remove .only from extension tests

Co-authored-by: Erik <[email protected]>
  • Loading branch information
davidfirst and arebokert authored Feb 17, 2020
1 parent 80987cf commit a53e20c
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 47 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

- fix dynamic dist reference from package.json (#1808) when isolating via capsule
- [#2341](https://github.com/teambit/bit/issues/2341) fix `bit export --all` to successfully export when deleted from remote
- support a basic flow of using module paths when no scopeDefault is set
- support configuring the logger level by running `bit config set log_level <level>`.
- [#2268](https://github.com/teambit/bit/issues/2268) prevent logger from holding the terminal once a command is completed

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

![Bit Workflow](https://storage.googleapis.com/static.bit.dev/docs/images/quick_start.png)

[Documentation](https://docs.bit.dev)[Tutorials](https://docs.bit.dev/docs/tutorials/bit-react-tutorial)[Quick start guide ](https://docs.bit.dev/quick-start)[Workflows](https://docs.bit.dev/docs/workflows/workflows)[bit.dev](https://bit.dev)
[Documentation](https://docs.bit.dev)[Tutorials](https://docs.bit.dev/docs/tutorials/bit-react-tutorial)[Quick start guide ](https://docs.bit.dev/docs/quick-start)[Workflows](https://docs.bit.dev/docs/workflows/workflows)[bit.dev components cloud](https://bit.dev)[Video demo](https://www.youtube.com/watch?v=E5lgoz6-nfs)

## What is Bit? 🤔

Bit is an [open-source](https://github.com/teambit/bit) cli tool for collaborating on isolated components across projects and repositories.
Use Bit to distribute discrete components from a design library or a project into a standalone reusable package and utilize it across applications.
Bit is an [open-source](https://github.com/teambit/bit) cli tool for collaborating on isolated components across projects and repositories.
Use Bit to distribute discrete components from a design library or a project into a standalone reusable package and utilize it across applications.
You can set up your own server for components collaboration, or use the [bit.dev cloud](#bitdev-cloud-%EF%B8%8F) hosting for private and public components sharing.

## Why Bit? 🎖️
Expand All @@ -26,15 +26,15 @@ You can set up your own server for components collaboration, or use the [bit.dev

## Installation 🚪

Using npm:
Using npm:

```bash
npm install bit-bin --global
```

Using yarn:
Using yarn:
```bash
yarn global add bit-bin
yarn global add bit-bin
```

Bit cli requires node 8.12 and above. Check other [installation](https://docs.bit.dev/docs/installation) methods.
Expand All @@ -43,7 +43,7 @@ Bit cli requires node 8.12 and above. Check other [installation](https://docs.bi

## bit.dev cloud 🌩️

Use [bit.dev](https://bit.dev) cloud hosting solution as a shared server and showcase for your components.
Use [bit.dev](https://bit.dev) cloud hosting solution as a shared server and showcase for your components.
<p align="center">
<a href="https://bit.dev"><img src="https://storage.googleapis.com/bit-docs/component-discovery-bit-react-gif.gif"></a>
</p>
Expand Down
12 changes: 12 additions & 0 deletions e2e/commands/build.e2e.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ describe('bit build', function() {
expect(packageJson).to.have.property('dynamicValue');
expect(packageJson.dynamicValue).equal('dist/bar/foo.js');
});
describe('isolating into a capsule', () => {
let capsuleDir;
before(() => {
capsuleDir = helper.general.generateRandomTmpDirName();
helper.command.runCmd(`bit isolate bar/foo --use-capsule --directory ${capsuleDir}`);
});
it('should update the package.json in the capsule', () => {
const capsulePackageJson = helper.packageJson.read(capsuleDir);
expect(capsulePackageJson).to.have.property('dynamicValue');
expect(capsulePackageJson.dynamicValue).equal('dist/bar/foo.js');
});
});
describe('importing when the dist is outside the components dir', () => {
before(() => {
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
Expand Down
35 changes: 35 additions & 0 deletions e2e/commands/export.e2e.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1208,4 +1208,39 @@ describe('bit export command', function() {
expect(list).to.have.lengthOf(1);
});
});
describe('export after re-creating the remote', () => {
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
helper.fixtures.populateWorkspaceWithUtilsIsType();
helper.command.tagAllComponents();
helper.command.exportAllComponents();
helper.scopeHelper.reInitRemoteScope();
});
describe('export without any flag', () => {
it('should show a message that nothing to export', () => {
const output = helper.command.exportAllComponents();
expect(output).to.have.string('nothing to export');
});
});
describe('export with --all flag', () => {
before(() => {
helper.scopeHelper.reInitRemoteScope();
helper.command.export(`${helper.scopes.remote} ${helper.scopes.remote}/* --all`);
});
it('should export them successfully', () => {
const list = helper.command.listRemoteScopeParsed();
expect(list).to.have.lengthOf(1);
});
});
describe('export with --all flag', () => {
before(() => {
helper.scopeHelper.reInitRemoteScope();
helper.command.export(`${helper.scopes.remote} ${helper.scopes.remote}/* --all-versions`);
});
it('should export them successfully', () => {
const list = helper.command.listRemoteScopeParsed();
expect(list).to.have.lengthOf(1);
});
});
});
});
56 changes: 56 additions & 0 deletions e2e/flows/no-scope.e2e.2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import chai, { expect } from 'chai';
import Helper from '../../src/e2e-helper/e2e-helper';

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

describe('import/require using module paths when no scope is set', function() {
this.timeout(0);
let helper: Helper;
before(() => {
helper = new Helper();
});
after(() => {
helper.scopeHelper.destroy();
});
describe('basic flow', () => {
before(() => {
helper.scopeHelper.setNewLocalAndRemoteScopes();
helper.fixtures.populateWorkspaceWithThreeComponentsAndModulePath(false);
helper.command.runCmd('bit link');
});
it('bit status should not break', () => {
const status = helper.command.statusJson();
expect(status.newComponents).have.lengthOf(3);
expect(status.invalidComponents).have.lengthOf(0);
});
describe('tagging the components', () => {
let tagOutput;
before(() => {
tagOutput = helper.command.tagAllComponents();
});
it('should be able to to tag them successfully', () => {
expect(tagOutput).to.have.string('tagged');
});
it('bit status should not show any issue', () => {
const status = helper.command.statusJson();
expect(status.stagedComponents).have.lengthOf(3);
expect(status.newComponents).have.lengthOf(0);
expect(status.modifiedComponent).have.lengthOf(0);
expect(status.invalidComponents).have.lengthOf(0);
});
// this should work once codemod is implemented
describe.skip('exporting the components', () => {
before(() => {
helper.command.exportAllComponents();
});
it('should be able to export them all successfully', () => {
const status = helper.command.statusJson();
expect(status.stagedComponents).have.lengthOf(0);
expect(status.newComponents).have.lengthOf(0);
expect(status.modifiedComponent).have.lengthOf(0);
expect(status.invalidComponents).have.lengthOf(0);
});
});
});
});
});
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ process.env.MEMFS_DONT_WARN = 'true'; // suppress fs experimental warnings from
// performance dramatically. (see http://bluebirdjs.com/docs/api/promise.longstacktraces.html)
Bluebird.config({
longStackTraces: true
// longStackTraces: Boolean(process.env.BLUEBIRD_DEBUG)
});

// loudRejection();
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/public-cmds/export-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export default class Export extends Command {
eject,
includeDependencies,
setCurrentScope,
includeNonStaged: all,
allVersions,
includeNonStaged: all || allVersions,
allVersions: allVersions || all,
codemod: rewire,
force
}).then(results => ({
Expand Down
8 changes: 2 additions & 6 deletions src/consumer/component-ops/component-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,10 @@ export default class ComponentWriter {
if (!isReplaceNeeded) {
return packageJsonChangedProps;
}
if (!this.component.dists || !this.component.dists.distsRootDir) {
throw new Error(
`package.json has a dynamic value ${COMPONENT_DIST_PATH_TEMPLATE}, however, the dist root is not set`
);
}
const distRootDir = this.component.dists.getDistDir(this.consumer, this.writeToPath || '.');
const distRelativeToPackageJson = getPathRelativeRegardlessCWD(
path.dirname(packageJson.filePath), // $FlowFixMe
this.component.dists.distsRootDir
distRootDir
);
return Object.keys(packageJsonChangedProps).reduce((acc, key) => {
const val = packageJsonChangedProps[key].replace(COMPONENT_DIST_PATH_TEMPLATE, distRelativeToPackageJson);
Expand Down
14 changes: 11 additions & 3 deletions src/e2e-helper/e2e-fixtures-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,20 @@ export default class FixtureHelper {
this.addComponentBarFoo();
}

populateWorkspaceWithThreeComponentsAndModulePath() {
populateWorkspaceWithThreeComponentsAndModulePath(useDefaultScope = true) {
this.fs.createFile('utils', 'is-type.js', fixtures.isType);
this.addComponentUtilsIsType();
this.fs.createFile('utils', 'is-string.js', fixtures.isStringModulePath(this.scopes.remote));

const isStringFixture = useDefaultScope
? fixtures.isStringModulePath(this.scopes.remote)
: fixtures.isStringModulePathNoScope;
this.fs.createFile('utils', 'is-string.js', isStringFixture);
this.addComponentUtilsIsString();
this.createComponentBarFoo(fixtures.barFooModulePath(this.scopes.remote));

const barFooFixture = useDefaultScope
? fixtures.barFooModulePath(this.scopes.remote)
: fixtures.barFooModulePathNoScope;
this.createComponentBarFoo(barFooFixture);
this.addComponentBarFoo();
}

Expand Down
4 changes: 4 additions & 0 deletions src/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const isStringTS =
"import isType from './is-type'; export default function isString() { return isType() + ' and got is-string'; };";
export const isStringModulePath = remoteScope =>
`const isType = require('@bit/${remoteScope}.utils.is-type'); module.exports = function isString() { return isType() + ' and got is-string'; };`;
export const isStringModulePathNoScope =
"const isType = require('@bit/utils.is-type'); module.exports = function isString() { return isType() + ' and got is-string'; };";
export const barFooFixture =
"const isString = require('../utils/is-string.js'); module.exports = function foo() { return isString() + ' and got foo'; };";
export const barFooFixtureV2 =
Expand All @@ -53,6 +55,8 @@ describe('foo', () => {
});`;
export const barFooModulePath = remoteScope =>
`const isString = require('@bit/${remoteScope}.utils.is-string'); module.exports = function foo() { return isString() + ' and got foo'; };`;
export const barFooModulePathNoScope =
"const isString = require('@bit/utils.is-string'); module.exports = function foo() { return isString() + ' and got foo'; };";
export const appPrintIsType = "const isType = require('./components/utils/is-type'); console.log(isType());";
export const appPrintIsTypeCapsule = "const isType = require('.'); console.log(isType());";
export const appPrintIsString = "const isString = require('./components/utils/is-string'); console.log(isString());";
Expand Down
68 changes: 68 additions & 0 deletions src/utils/bit/package-name-to-component-id.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,74 @@ describe('packageNameToComponentId', function() {
// @ts-ignore
consumer = new Consumer({ projectPath: '', config: {} });
});
describe('when a packageName has no dots', () => {
it('should return bitId with no-scope when it is on bitmap', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds(new BitId({ name: 'foo' })) };
const result = packageNameToComponentId(consumer, '@bit/foo', '@bit');
expect(result.scope).to.be.null;
expect(result.name).to.equal('foo');
});
it('should throw when is not on bitmap', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds() };
const func = () => packageNameToComponentId(consumer, '@bit/foo', '@bit');
expect(func).to.throw();
});
});
describe('when a packageName has one dot', () => {
it('should return bitId with no-scope when it is on bitmap this way', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds(new BitId({ name: 'bar/foo' })) };
const result = packageNameToComponentId(consumer, '@bit/bar.foo', '@bit');
expect(result.scope).to.be.null;
expect(result.name).to.equal('bar/foo');
});
it('should return bitId with scope and name when it is on bitmap this way', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds(new BitId({ scope: 'bar', name: 'foo' })) };
const result = packageNameToComponentId(consumer, '@bit/bar.foo', '@bit');
expect(result.scope).to.equal('bar');
expect(result.name).to.equal('foo');
});
it('should return bitId with scope and name when it is not on bitmap as it cannot be new component', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds() };
const result = packageNameToComponentId(consumer, '@bit/bar.foo', '@bit');
expect(result.scope).to.equal('bar');
expect(result.name).to.equal('foo');
});
});
describe('when a packageName has two dots', () => {
it('should return bitId with no-scope when it is on bitmap this way', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds(new BitId({ name: 'foo/bar/qux' })) };
const result = packageNameToComponentId(consumer, '@bit/foo.bar.qux', '@bit');
expect(result.scope).to.be.null;
expect(result.name).to.equal('foo/bar/qux');
});
it('should return bitId with scope without dot and name when it is on bitmap this way', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds(new BitId({ scope: 'foo', name: 'bar/qux' })) };
const result = packageNameToComponentId(consumer, '@bit/foo.bar.qux', '@bit');
expect(result.scope).to.equal('foo');
expect(result.name).to.equal('bar/qux');
});
it('should return bitId with scope with dot and name when it is on bitmap this way', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds(new BitId({ scope: 'foo.bar', name: 'qux' })) };
const result = packageNameToComponentId(consumer, '@bit/foo.bar.qux', '@bit');
expect(result.scope).to.equal('foo.bar');
expect(result.name).to.equal('qux');
});
it('should return bitId with scope with dot and name when it is not on bitmap', () => {
// @ts-ignore
consumer.bitMap = { getAllBitIds: () => new BitIds() };
const result = packageNameToComponentId(consumer, '@bit/foo.bar.qux', '@bit');
expect(result.scope).to.equal('foo.bar');
expect(result.name).to.equal('qux');
});
});
it('should parse the path correctly when a component is not in bitMap and has one dot', () => {
const result = packageNameToComponentId(consumer, '@bit/remote.comp', '@bit');
expect(result.scope).to.equal('remote');
Expand Down
Loading

0 comments on commit a53e20c

Please sign in to comment.