Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(performance): allow creating a faster capsule #2162

Merged
merged 28 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4559ef3
feat(isolate): integrate librarian
imsnif Nov 19, 2019
232ff12
fix(isolator): status indication
imsnif Nov 20, 2019
af7c2e0
Revert "fix(isolator): status indication"
imsnif Nov 21, 2019
28bd6ac
Revert "feat(isolate): integrate librarian"
imsnif Nov 21, 2019
fc7e6e2
Merge branch 'master' into faster-capsule-build
imsnif Nov 21, 2019
cd0ebb0
feat(isolate): integrate librarian
imsnif Nov 22, 2019
5d1c5a2
fix(logging): suppress memfs fs experimental warnings
imsnif Nov 26, 2019
d076a56
feat(isolate): allow option to create a capsule without node_modules
imsnif Nov 26, 2019
f4d871b
fix(isolate): allow environment to direct bit not to delete the capsule
imsnif Nov 26, 2019
64b03bc
fix(isolate): properly handle a long lived capsule
imsnif Dec 3, 2019
1d2a505
fix(librarian): update version
imsnif Dec 4, 2019
bd6c172
chore(build): rerun build
imsnif Dec 4, 2019
1de5918
refactor(isolate): use installNpmPackages instead of skipNodeModules
imsnif Dec 4, 2019
c5ac138
fix(isolate): default true to installNpmPackages
imsnif Dec 4, 2019
20adafe
refactor(log): move env variable declaration
imsnif Dec 4, 2019
023154f
style(lint): eslint
imsnif Dec 4, 2019
9d77b2b
Merge branch 'master' into faster-capsule-build
imsnif Dec 4, 2019
a3cdc0f
fix(isolate): properly default to install npm packages
imsnif Dec 4, 2019
163c12d
fix(isolate): change cli flag to skipNpmInstall
imsnif Dec 4, 2019
afff48a
fix(isolate): adjust test
imsnif Dec 4, 2019
96053a7
refactor(style): clearer conditional and comment placement
imsnif Dec 5, 2019
61c3d4e
refactor(persisted-data): better flag name
imsnif Dec 5, 2019
c7e7562
chore(deps): get librarian from git tag
imsnif Dec 5, 2019
d7d0c3d
chore(deps): adjust for new librarian api
imsnif Dec 5, 2019
25ec5fb
chore(build): trigger build
imsnif Dec 5, 2019
ff0b595
docs(changelog): librarian integration
imsnif Dec 5, 2019
24b7452
Merge branch 'master' into faster-capsule-build
imsnif Dec 5, 2019
92fa48f
Merge branch 'master' into faster-capsule-build
imsnif Dec 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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