Skip to content

Commit

Permalink
Merge 92fa48f into 9d02f49
Browse files Browse the repository at this point in the history
  • Loading branch information
imsnif authored Dec 6, 2019
2 parents 9d02f49 + 92fa48f commit b86eeea
Show file tree
Hide file tree
Showing 12 changed files with 624 additions and 148 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

- [#2162](https://github.com/teambit/bit/pull/2162) - add integration with [librarian](https://github.com/teambit/librarian)
- [#2178](https://github.com/teambit/bit/issues/2178) fix adding ts types packages to respect overrides settings
- [#2176](https://github.com/teambit/bit/issues/2176) fix workspace overrides to not leak rules to unrelated components
- [#2176](https://github.com/teambit/bit/issues/2176) fix workspace overrides to not leak rules to unrelated component
- [#2171](https://github.com/teambit/bit/issues/2171) fix component-not-found when exporting to multiple scopes and there are dependencies between them

## [14.6.1-dev.2] - 2019-12-04
Expand Down
51 changes: 34 additions & 17 deletions components/core/capsule/capsule.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import State from "./state";
import State from './state';
import Container from './container';
// @ts-ignore
import { Volume } from "memfs/lib/volume";
import Console from "./console";
import librarian from 'librarian';
import { Volume } from 'memfs/lib/volume';
import Console from './console';
// @ts-ignore
import { Union } from 'unionfs';
import { ContainerFS } from './container';
import { Exec } from "./container";
import { Exec } from './container';

import loader from '../../../src/cli/loader'; // TODO: better (have the capsule accept the loader as an arg?)

export class ContainerFactoryOptions {
image: string = '';
config: object = {};
};
}

export default class Capsule {
constructor(
Expand Down Expand Up @@ -41,6 +44,8 @@ export default class Capsule {
*/
static image = 'ubuntu';

componentName?: string;

/**
* default capsule config.
*/
Expand All @@ -63,15 +68,29 @@ export default class Capsule {
this.container.on(event, fn);
}

updateFs(fs: {[path: string]: string}, fn: Function): void {
Object.keys(fs).forEach((path) => {
updateFs(fs: { [path: string]: string }, fn: Function): void {
Object.keys(fs).forEach(path => {
// @ts-ignorex
this.fs.writeFile(path, fs[path], () => {
if (Object.keys(fs).length === 1) fn();
});
});
}

async execNode(executable: string, args: any) {
// TODO: better
const loaderPrefix = this.componentName ? `isolating ${this.componentName}` : '';
const log = message => (this.componentName ? loader.setText(`${loaderPrefix}: ${message}`) : {});
const { patchFileSystem } = librarian.api();
const onScriptRun = () =>
this.componentName ? loader.setText(`running build for ${this.componentName} in an isolated environment`) : {}; // TODO: do this from the compiler/tester so we can customize the message
await patchFileSystem(executable, { args, cwd: this.container.path, log, onScriptRun });
}

setComponentName(componentName: string) {
this.componentName = componentName;
}

outputFile(file: string, data: any, options: Object): Promise<any> {
return this.container.outputFile(file, data, options);
}
Expand All @@ -89,7 +108,7 @@ export default class Capsule {
}

resume() {
return this.container.resume()
return this.container.resume();
}

stop() {
Expand Down Expand Up @@ -117,21 +136,19 @@ export default class Capsule {

private static buildFs(memFs: Volume, containerFs: ContainerFS): Volume {
const fs = new Union();
fs
.use(memFs)
.use(containerFs);
fs.use(memFs).use(containerFs);

return fs;
}

static async create<T extends Capsule>(
containerFactory: (options: ContainerFactoryOptions) => Promise<Container>,
volume: Volume = new Volume(),
initialState: State = new State(),
console: Console = new Console()
): Promise<T> {
containerFactory: (options: ContainerFactoryOptions) => Promise<Container>,
volume: Volume = new Volume(),
initialState: State = new State(),
console: Console = new Console()
): Promise<T> {
const container = await containerFactory({ image: this.image, config: this.config });
const fs = await ContainerFS.fromJSON(container, {});
return (new this(container, this.buildFs(volume, fs), console, initialState) as T);
return new this(container, this.buildFs(volume, fs), console, initialState) as T;
}
}
25 changes: 13 additions & 12 deletions components/core/capsule/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default interface Container {
* container id
*/
id: string;
path: string;

/**
* execute a command on the container
Expand All @@ -20,13 +21,13 @@ export default interface Container {
/**
* put a file or a directory to the container.
*/
put(files: {[path: string]: string}, options: { overwrite?: boolean, path: string }): Promise<void>;
put(files: { [path: string]: string }, options: { overwrite?: boolean; path: string }): Promise<void>;

on(event: string, fn: (data: any) => void): void;

on(event: string, fn: (data: any) => void): void;

/**
* start a container.
*/
*/
start(): Promise<void>;

/**
Expand Down Expand Up @@ -69,37 +70,37 @@ export type ContainerStatus = {
/**
* array of open container ports
*/
ports: number[],
ports: number[];

/**
* container host
*/
host: string,
host: string;
};

export type CommitOptions = {
/**
* repository name for the created image
*/
repo: string,
repo: string;

/**
* tag name for the create image
*/
tag: string,
tag: string;

/**
* commit message
*/
comment: string,
comment: string;

/**
* author of the image.
*/
author: string,
author: string;

/**
* whether to pause the container before committing
*/
pause: boolean,
pause: boolean;
};
2 changes: 1 addition & 1 deletion e2e/commands/isolate.e2e.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('run bit isolate', function() {
describe('with the same parameters as pack is using', () => {
let isolatePath;
before(() => {
isolatePath = helper.command.isolateComponent('bar/foo', '-olw');
isolatePath = helper.command.isolateComponent('bar/foo', '-owls');
});
it('should be able to generate the links correctly and require the dependencies', () => {
const appJsFixture = `const barFoo = require('./');
Expand Down
2 changes: 1 addition & 1 deletion e2e/functionalities/custom-module-resolutions.e2e.2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('custom module resolutions', function() {
describe('importing the component using isolated environment', () => {
let isolatePath;
before(() => {
isolatePath = helper.command.isolateComponent('bar/foo', '-olw');
isolatePath = helper.command.isolateComponent('bar/foo', '-olws');
});
it('should be able to generate the links correctly and require the dependencies', () => {
const appJsFixture = `const barFoo = require('./');
Expand Down
Loading

0 comments on commit b86eeea

Please sign in to comment.