Create Runtime

Create a new Harmony runtime is useful for introducing your platform to new runtimes like React Native, NodeJS, Browser and on. You can use our official Harmony runtimes:

Install the needed runtimes:

bit install @bitdev/harmony.runtimes.browser-runtime @bitdev/harmony.runtimes.nodejs-runtime
CopiedCopy

Compose the runtimes into the runtimes key property in your Harmony platform:

import { HarmonyPlatform } from '@bitdev/harmony.harmony-platform';
import { PeopleAspect } from '@pied/people.people'; 
import { Browser } from '@bitdev/harmony.runtimes.browser-runtime';
import { NodeJSRuntime } from '@bitdev/harmony.runtimes.nodejs-runtime';

export const PiedPiperPlatform = HarmonyPlatform.from({
  name: 'pied-piper',

  runtimes: [
    new NodeJSRuntime(),
    new BrowserRuntime()
  ],

  aspects: [
    PeopleAspect
  ]
});

export default PiedPiperPlatform;
CopiedCopy

After using a runtime in your Harmony platform, runtimes files of the used files would be loaded into the platform.

Create a runtime

You can create a new Harmony runtime using the following command:

bit create runtime python-runtime
CopiedCopy

Use the runtime in the Harmony platform to introduce new runtimes to it:

import type { AppBuildResult } from "@teambit/application";
import { ComponentID } from '@teambit/component-id';
import { HarmonyRuntimeContext, RuntimeBuildContext, Runtime } from "@bitdev/harmony.harmony-platform";
import { ReactSsr } from '@bitdev/react.app-types.react-ssr';
import { BrowserRuntimeDef } from "./browser-runtime-definition.js";
import { BrowserRuntimeOptions } from "./browser-runtime-options.js";

/**
 * A UI runtime for Harmony platforms.
 */
export class BrowserRuntime implements Runtime {
  // name of the runtime.
  name = 'browser';

  // reference to the runtime aspect.
  runtimeAspect = import.meta.resolve('./browser-runtime.aspect.js');

  // default port range for the runtime.
  portRange: [number, number] = [3000, 3100];

  async run(context: HarmonyRuntimeContext) {
    // runner path is the main path for your aspect. 
    // use it as the entry for the your platform runtime.
    const runnerPath = context.runnerPath;

    // return the Bit ApplicationInstance. 
    // This includes the port, url and name for the platform runtime.
    return result;
  }

  async build(context: RuntimeBuildContext): Promise<AppBuildResult> {
    // runner path is the main path for your aspect. 
    // use it as the entry for the your platform runtime.
    const runnerPath = context.runnerPath;
    // add your build logic here.
  }
}
CopiedCopy

Using in Aspects

To use a configured runtime in your Aspects add a file corresponding to the name of your runtime, e.g. people.[runtime-name].runtime.ts. Aspects usually have more than a single runtime implemented.

Testing runtimes

Testing runtimes is similar to testing NodeJS modules. Learn more on testing NodeJS modules in the NodeJS testing section.

Runtime documentation

Runtime template comes with an MDX docs template for a runtime. Use it as a base and expand. Learn more on documenting NodeJS modules.