New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@teambit/compiler

Package Overview
Dependencies
Maintainers
18
Versions
1678
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teambit/compiler

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

0.0.83
Source
npm
Version published
Weekly downloads
2.4K
150.1%
Maintainers
18
Weekly downloads
 
Created
Source

Workspace Configuration

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

As a task

A task is running with bit build 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 getBuildPipe() array the following: this.compiler.createTask().

As a command

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);
}

Compiler Implementation

The compiler is responsible for two processes:

  • compile during development This compilation takes place on the workspace and the dists are saved inside the component dir. The provider should implement transpileFile function as follows:
transpileFile: (fileContent: string, options: { componentDir: string, filePath: string }) => Array<{ outputText: string, outputPath: string }> | null;

In case the compiler receives an unsupported file, it should return null.

  • compile for build (during the tag command) This compilation takes place on the isolated capsule. The provider should implement build function which returns the exit-code and the dist dir. From Compiler interface:
build(context: BuildContext): Promise<BuildResults>;

FYI, this api is going to be changed very soon. It should get components and capsules graph.

Points to consider when writing a compiler

Debugging experience on the workspace

Since the dists are written into the node_modules/component-name/dist-dir, the debugger needs to know where to find the source files. This can be easily achieved by setting the sourceRoot of the source-map file to the component-dir. As a reminder, this directory is passed to the transpile() method.

Error handling during build process

Without proper error handling, the build() will exit an the first error found. Catch the errors and add them to the ComponentResult.errors[] you return per component.

FAQs

Package last updated on 23 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts