Skip to content

Commit

Permalink
rename compiler extension from "compile" to "@teambit/compiler" (#2855)
Browse files Browse the repository at this point in the history
also, change the extension to the new format (with a class).
  • Loading branch information
davidfirst committed Jul 17, 2020
1 parent 7138e50 commit e403658
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 100 deletions.
15 changes: 8 additions & 7 deletions e2e/harmony/compile.e2e.4.ts
Expand Up @@ -3,10 +3,11 @@ import fs from 'fs-extra';
import chai, { expect } from 'chai';
import Helper from '../../src/e2e-helper/e2e-helper';
import { HARMONY_FEATURE } from '../../src/api/consumer/lib/feature-toggle';
import { Extensions } from '../../src/constants';

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

describe('compile extension', function () {
describe('compile extension', function() {
this.timeout(0);
let helper: Helper;
before(() => {
Expand All @@ -26,7 +27,7 @@ describe('compile extension', function () {
appOutput = helper.fixtures.populateComponentsTS(3, undefined, true);
const environments = {
env: '@teambit/react',
config: {},
config: {}
};
helper.extensions.addExtensionToVariant('*', '@teambit/envs', environments);
scopeBeforeTag = helper.scopeHelper.cloneLocalScope();
Expand All @@ -38,7 +39,7 @@ describe('compile extension', function () {
it('should not create a capsule as it is not needed for development', () => {
const capsulesJson = helper.command.runCmd('bit capsule-list -j');
const capsules = JSON.parse(capsulesJson);
capsules.capsules.forEach((c) => expect(c).to.not.have.string('comp1'));
capsules.capsules.forEach(c => expect(c).to.not.have.string('comp1'));
});
it('should write the dists files inside the node-modules of the component', () => {
const nmComponent = path.join(
Expand Down Expand Up @@ -69,8 +70,8 @@ describe('compile extension', function () {
it('should save the dists in the objects', () => {
const catComp2 = helper.command.catComponent('comp2@latest');
expect(catComp2).to.have.property('extensions');
const compileExt = catComp2.extensions.find((e) => e.name === 'compile');
const files = compileExt.artifacts.map((d) => d.relativePath);
const compileExt = catComp2.extensions.find(e => e.name === Extensions.compiler);
const files = compileExt.artifacts.map(d => d.relativePath);
expect(files).to.include('dist/index.js');
expect(files).to.include('dist/index.d.ts'); // makes sure it saves declaration files
});
Expand Down Expand Up @@ -133,8 +134,8 @@ describe('compile extension', function () {
it('should still save the dists on the component with the compiler', () => {
const catComp = helper.command.catComponent('comp3@latest');
expect(catComp).to.have.property('extensions');
const compileExt = catComp.extensions.find((e) => e.name === 'compile');
const files = compileExt.artifacts.map((d) => d.relativePath);
const compileExt = catComp.extensions.find(e => e.name === Extensions.compiler);
const files = compileExt.artifacts.map(d => d.relativePath);
expect(files).to.include('dist/index.js');
});
});
Expand Down
10 changes: 6 additions & 4 deletions src/constants.ts
Expand Up @@ -51,13 +51,13 @@ type origins = 'IMPORTED' | 'AUTHORED' | 'NESTED';
export const COMPONENT_ORIGINS = {
IMPORTED: 'IMPORTED' as origins,
AUTHORED: 'AUTHORED' as origins,
NESTED: 'NESTED' as origins,
NESTED: 'NESTED' as origins
};

export const TESTS_FORK_LEVEL = {
NONE: 'NONE',
ONE: 'ONE',
COMPONENT: 'COMPONENT',
COMPONENT: 'COMPONENT'
};

export const DEFAULT_INDEX_NAME = 'index';
Expand Down Expand Up @@ -166,7 +166,7 @@ export const IGNORE_LIST = [
'**/node_modules/**',
'**/package-lock.json',
'**/yarn.lock',
'**/LICENSE',
'**/LICENSE'
];

/**
Expand Down Expand Up @@ -303,7 +303,7 @@ export const HOOKS_NAMES = [
POST_DEPRECATE_REMOTE,
POST_UNDEPRECATE_REMOTE,
PRE_REMOVE_REMOTE,
POST_REMOVE_REMOTE,
POST_REMOVE_REMOTE
];

/**
Expand Down Expand Up @@ -439,4 +439,6 @@ export const IMPORT_PENDING_MSG =
export enum Extensions {
dependencyResolver = '@teambit/dependency-resolver',
pkg = '@teambit/pkg',
compiler = '@teambit/compiler',
envs = '@teambit/envs'
}
6 changes: 3 additions & 3 deletions src/extensions/bit/manifests.ts
@@ -1,5 +1,5 @@
import { CLIExtension } from '../cli';
import { CompileExt } from '../compiler';
import { CompilerExtension } from '../compiler';
import { ComponentFactoryExt } from '../component';
import { ComponentGraphExt } from '../graph';
import { ConfigExt } from '../config';
Expand Down Expand Up @@ -31,7 +31,7 @@ import { CompositionsExtension } from '../compositions';
export const manifestsMap = {
[CLIExtension.name]: CLIExtension,
[WorkspaceExt.name]: WorkspaceExt,
[CompileExt.name]: CompileExt,
[CompilerExtension.id]: CompilerExtension,
[ComponentFactoryExt.id]: ComponentFactoryExt,
[PreviewExtension.name]: PreviewExtension,
[ConfigExt.name]: ConfigExt,
Expand Down Expand Up @@ -62,5 +62,5 @@ export const manifestsMap = {
[BuilderExtension.id]: BuilderExtension,
[VariantsExt.name]: VariantsExt,
[WatcherExtension.name]: WatcherExtension,
[WorkspaceExt.name]: WorkspaceExt,
[WorkspaceExt.name]: WorkspaceExt
};
26 changes: 10 additions & 16 deletions src/extensions/compiler/compiler.extension.ts
@@ -1,25 +1,19 @@
import { ExtensionManifest } from '@teambit/harmony';
import { WorkspaceExt } from '../workspace';
import { Environments } from '../environments';
import { Workspace } from '../workspace';
import { CLIExtension } from '../cli';
import { CompileCmd } from './compiler.cmd';
import { Compile } from './compile';
import { CompilerTask } from './compiler.task';
import { Extensions } from '../../constants';

const name = 'compile';

export default {
name,
dependencies: [CLIExtension, WorkspaceExt, Environments],
provider: provideCompile,
} as ExtensionManifest;

export type CompileDeps = [CLIExtension, Workspace, Environments];

export async function provideCompile([cli, workspace, envs]: CompileDeps) {
const compilerTask = new CompilerTask(name);
const compile = new Compile(workspace, envs, compilerTask);
cli.register(new CompileCmd(compile));
return compile;
export class CompilerExtension {
static id = Extensions.compiler;
static dependencies = [CLIExtension, WorkspaceExt, Environments];
static async provider([cli, workspace, envs]: [CLIExtension, Workspace, Environments]) {
const compilerTask = new CompilerTask(CompilerExtension.id);
const compile = new Compile(workspace, envs, compilerTask);
cli.register(new CompileCmd(compile));
return compile;
}
}
2 changes: 1 addition & 1 deletion src/extensions/compiler/index.ts
@@ -1,3 +1,3 @@
export { Compile } from './compile';
export { Compiler } from './types';
export { default as CompileExt } from './compiler.extension';
export { CompilerExtension } from './compiler.extension';
8 changes: 4 additions & 4 deletions src/extensions/react/react.extension.ts
Expand Up @@ -2,7 +2,7 @@ import { Environments } from '../environments';
import { ReactEnv } from './react.env';
import { JestExtension } from '../jest';
import { TypescriptExtension } from '../typescript';
import { Compile, CompileExt } from '../compiler';
import { Compile, CompilerExtension } from '../compiler';
import { WebpackExtension } from '../webpack';
import { Component } from '../component';
import { WorkspaceExt, Workspace } from '../workspace';
Expand Down Expand Up @@ -76,20 +76,20 @@ export class ReactExtension {
return {
abstract: docs.description,
filePath: docs.filePath,
properties: docs.properties,
properties: docs.properties
};
}

static dependencies = [
Environments,
JestExtension,
TypescriptExtension,
CompileExt,
CompilerExtension,
WebpackExtension,
WorkspaceExt,
GraphQLExtension,
PkgExtension,
TesterExtension,
TesterExtension
];

static provider([envs, jest, ts, compile, webpack, workspace, graphql, pkg, tester]: ReactDeps) {
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/stencil/stencil.extension.ts
Expand Up @@ -2,7 +2,7 @@ import { TranspileOptions } from '@stencil/core/compiler';
import { StencilCompiler } from './stencil.compiler';
import { Environments } from '../environments';
import { StencilEnv } from './stencil.env';
import { CompileExt, Compile } from '../compiler';
import { CompilerExtension, Compile } from '../compiler';
import { StencilTester } from './stencil.tester';
import { WorkspaceExt, Workspace } from '../workspace';
// import { StencilDevServer } from './stencil.dev-server';
Expand Down Expand Up @@ -30,7 +30,7 @@ export class StencilExtension {
// return new StencilDevServer({}, this.workspace);
}

static dependencies = [Environments, CompileExt, WorkspaceExt, WebpackExtension];
static dependencies = [Environments, CompilerExtension, WorkspaceExt, WebpackExtension];

static async provider([envs, compiler, workspace, webpack]: [Environments, Compile, Workspace, WebpackExtension]) {
const stencil = new StencilExtension(workspace);
Expand Down
30 changes: 15 additions & 15 deletions src/extensions/watch/watch.extension.ts
Expand Up @@ -5,7 +5,7 @@ import R from 'ramda';
import chalk from 'chalk';
import { WorkspaceExt, Workspace } from '../workspace';
import { WatchCommand } from './watch.cmd';
import { CompileExt } from '../compiler';
import { CompilerExtension } from '../compiler';
import { CLIExtension } from '../cli';
/* eslint no-console: 0 */
import loader from '../../cli/loader';
Expand Down Expand Up @@ -67,19 +67,19 @@ export class WatcherExtension {
watcher.on('ready', () => {
log(chalk.yellow(STARTED_WATCHING_MSG));
});
watcher.on('change', (p) => {
watcher.on('change', p => {
log(`file ${p} has been changed`);
this._handleChange(p).catch((err) => reject(err));
this._handleChange(p).catch(err => reject(err));
});
watcher.on('add', (p) => {
watcher.on('add', p => {
log(`file ${p} has been added`);
this._handleChange(p, true).catch((err) => reject(err));
this._handleChange(p, true).catch(err => reject(err));
});
watcher.on('unlink', (p) => {
watcher.on('unlink', p => {
log(`file ${p} has been removed`);
this._handleChange(p).catch((err) => reject(err));
this._handleChange(p).catch(err => reject(err));
});
watcher.on('error', (err) => {
watcher.on('error', err => {
log(`Watcher error ${err}`);
reject(err);
});
Expand Down Expand Up @@ -122,7 +122,7 @@ export class WatcherExtension {

// :TODO @david we should document all extension public apis.
isComponentWatchedExternally(componentId: BitId) {
const watcherData = this.multipleWatchers.find((m) => m.componentIds.find((id) => id.isEqual(componentId)));
const watcherData = this.multipleWatchers.find(m => m.componentIds.find(id => id.isEqual(componentId)));
if (watcherData) {
console.log(`${componentId.toString()} is watched by ${watcherData.compilerId.toString()}`);
return true;
Expand All @@ -144,7 +144,7 @@ export class WatcherExtension {
}

if (isNew && !componentId) {
const trackDir = Object.keys(this.trackDirs).find((dir) => relativeFile.startsWith(dir));
const trackDir = Object.keys(this.trackDirs).find(dir => relativeFile.startsWith(dir));
if (trackDir) {
const id = this.trackDirs[trackDir];
const bitId = this.consumer.getParsedId(id);
Expand All @@ -167,28 +167,28 @@ export class WatcherExtension {
// https://github.com/paulmillr/chokidar/issues/773
// https://github.com/paulmillr/chokidar/issues/492
// https://github.com/paulmillr/chokidar/issues/724
ignored: (path) => {
ignored: path => {
// Ignore package.json temporarily since it cerates endless loop since it's re-written after each build
if (path.includes('dist') || path.includes('node_modules') || path.includes('package.json')) {
return true;
}
return false;
},
persistent: true,
useFsEvents: false,
useFsEvents: false
});
}

_getPathsToWatch(): string[] {
const componentsFromBitMap = this.consumer.bitMap.getAllComponents();
const paths = componentsFromBitMap.map((componentMap) => {
const paths = componentsFromBitMap.map(componentMap => {
const componentId = componentMap.id.toString();
const trackDir = componentMap.getTrackDir();
if (trackDir) {
this.trackDirs[trackDir] = componentId;
}
const relativePaths = trackDir ? [trackDir] : componentMap.getFilesRelativeToConsumer();
const absPaths = relativePaths.map((relativePath) => this.consumer.toAbsolutePath(relativePath));
const absPaths = relativePaths.map(relativePath => this.consumer.toAbsolutePath(relativePath));
if (this.verbose) {
console.log(`watching ${chalk.bold(componentId)}\n${absPaths.join('\n')}`);
}
Expand All @@ -197,7 +197,7 @@ export class WatcherExtension {
return R.flatten(paths);
}

static dependencies = [CLIExtension, CompileExt, WorkspaceExt];
static dependencies = [CLIExtension, CompilerExtension, WorkspaceExt];

static slots = [Slot.withType<Watcher>()];

Expand Down

0 comments on commit e403658

Please sign in to comment.