Skip to content

Commit

Permalink
refactoring. remove the old "test" extension, the new "tester" extens…
Browse files Browse the repository at this point in the history
…ion replaces it. Remove the fixture of gulp-ts, it is not needed now that TS compiler is in the core. remove code from watch and update compiler README (#2710)
  • Loading branch information
davidfirst authored Jun 7, 2020
1 parent ff7d02f commit 79b6a2a
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 265 deletions.
16 changes: 0 additions & 16 deletions e2e/fixtures/extensions/gulp-ts/default-tsconfig.js

This file was deleted.

10 changes: 0 additions & 10 deletions e2e/fixtures/extensions/gulp-ts/gulp-ts.manifest.js

This file was deleted.

1 change: 0 additions & 1 deletion e2e/fixtures/extensions/gulp-ts/index.js

This file was deleted.

23 changes: 0 additions & 23 deletions e2e/fixtures/extensions/gulp-ts/transpile.js

This file was deleted.

30 changes: 0 additions & 30 deletions src/e2e-helper/e2e-fixtures-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,36 +227,6 @@ export default () => 'comp${index} and ' + ${nextComp}();`;
this.addComponentBarFoo();
}

addExtensionGulpTS() {
const extensionsDir = path.join(this.getFixturesDir(), 'extensions');
const extDestination = path.join(this.scopes.localPath, 'extensions');
fs.copySync(path.join(extensionsDir, 'gulp-ts'), path.join(extDestination, 'gulp-ts'));

this.command.addComponent('extensions/gulp-ts', { i: 'extensions/gulp-ts' });

this.npm.initNpm();
const dependencies = {
gulp: '^4.0.2',
'gulp-typescript': '^6.0.0-alpha.1',
merge2: '^1.3.0',
react: '^16.12.0',
typescript: '^3.7.5'
};
const devDependencies = {
'@types/react': '^16.9.17'
};

this.packageJson.addKeyValue({ dependencies, devDependencies });
this.command.runCmd('npm i');
this.command.link();

// @todo: currently, the defaultScope is not enforced, so unless the extension is exported
// first, the full-id won't be recognized when loading the extension.
// once defaultScope is mandatory, make sure this is working without the next two lines
this.command.tagComponent('extensions/gulp-ts');
this.command.exportComponent('extensions/gulp-ts');
}

addExtensionTS() {
const extensionsDir = path.join(__dirname, '..', 'extensions');
const extDestination = path.join(this.scopes.localPath, 'extensions');
Expand Down
2 changes: 0 additions & 2 deletions src/extensions/bit/manifests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { PaperExt } from '../paper';
import { React } from '../react';
import { ReporterExt } from '../reporter';
import { ScopeExtension } from '../scope';
import { TestExt } from '../test';
import { TesterExtension } from '../tester';
import { ReleasesExtension } from '../releases';
import { VariantsExt } from '../variants';
Expand Down Expand Up @@ -53,7 +52,6 @@ export const manifestsMap = {
[React.name]: React,
[ReporterExt.name]: ReporterExt,
[ScopeExtension.name]: ScopeExtension,
[TestExt.name]: TestExt,
// TODO: take from the extension itself & change name to follow convention
Tester: TesterExtension,
// TODO: take from the extension itself & change name to follow convention
Expand Down
41 changes: 19 additions & 22 deletions src/extensions/compile/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
### Workspace Configuration

The compiler is configured inside an environment and not directly on the component level.

## As a task
An example:
```
"extensions": {
"scripts": {
"build": [
"my-compiler:task-name"
],
}
}
```
To run: `bit run build`.
A task is running with `bit run` or during the tag process on the capsules or the workspace (depends on the specific compiler implementation).
The env extension should have this compiler extension as a dependency first, then add to the `release()` array the following: `this.compile.task`.

## As a command
An example:
```
"extensions": {
"compile": {
"compiler": "my-compiler"
}
A command is running on the workspace.
To run: `bit compile`.
An example of configuring a compiler in the React env.
```
/**
* returns a component compiler.
*/
getCompiler(): Compiler {
// eslint-disable-next-line global-require
const tsConfig = require('./typescript/tsconfig.json');
return this.ts.createCompiler(tsConfig);
}
```

To run: `bit compile`

### Compiler Implementation
The compiler is responsible for two processes:
1. compile during development
Expand All @@ -37,8 +33,9 @@ In case the compiler receive an unsupported file, it should return null.

2. compile for release (during the tag command)
This compilation takes place on the isolated capsule.
The provider should implement `defineCompiler` function which returns the filename of the task file without the extension.
An example:
The provider should implement `compileOnCapsules` function which returns the exit-code and the dist dir.
From Compiler interface:
```
const defineCompiler = () => ({ taskFile: 'transpile' });
compileOnCapsules(capsuleDirs: string[]): { resultCode: number; error: Error | null };
```
FYI, this api is going to be changed very soon. It should get components and capsules graph.
4 changes: 0 additions & 4 deletions src/extensions/compile/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ export interface Compiler {
options: { componentDir: string; filePath: string }
) => Array<{ outputText: string; outputPath: string }> | null;
compileOnCapsules(capsuleDirs: string[]): { resultCode: number; error: Error | null };
// @todo: it might not be needed if Flows doesn't help, needs to be discussed
defineCompiler?: () => { taskFile: string; name: string }; // @todo: remove the "name", it's a hack
// @todo: remove once we finalized the compilation on capsule
watchMultiple?: (capsulePaths: string[]) => any;
}
1 change: 0 additions & 1 deletion src/extensions/test/index.ts

This file was deleted.

62 changes: 0 additions & 62 deletions src/extensions/test/test.cmd.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/extensions/test/test.manifest.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/extensions/test/test.provider.ts

This file was deleted.

46 changes: 0 additions & 46 deletions src/extensions/test/test.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/extensions/watch/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default class Watch {
}

async watchAll() {
// await this.handleComponentsWithExternalWatchers();
// TODO: run build in the beginning of process (it's work like this in other envs)
const watcher = this._getWatcher();
console.log(chalk.yellow(`bit binary version: ${BIT_VERSION}`));
Expand Down Expand Up @@ -68,27 +67,6 @@ export default class Watch {
});
}

/**
* some compiler work way faster with their watchers, such as `tsc -w`
* @todo: recognize when after loading the component the capsule-path changed and then, kill the
* watcher and re-create it.
*/
async handleComponentsWithExternalWatchers() {
// await this.populateWatcherProcesses();
this.multipleWatchers.forEach(watchProcessData => {
const watchProcess = watchProcessData.watchProcess;
const compilerIdStr = watchProcessData.compilerId.toString();
// @ts-ignore
watchProcess.stderr.on('data', data => {
console.log(`Error from ${compilerIdStr}`, data);
});
// @ts-ignore
watchProcess.stdout.on('data', data => {
console.log(chalk.bold(`Data from ${compilerIdStr}\n`), data.toString());
});
});
}

async _handleChange(filePath: string, isNew = false) {
const start = new Date().getTime();
const componentId = await this._getBitIdByPathAndReloadConsumer(filePath, isNew);
Expand Down

0 comments on commit 79b6a2a

Please sign in to comment.