0.14.0 • Published 1 month ago

@opentf/react-node-repl v0.14.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

 OPEN TECH FOUNDATION

React Node REPL

Demo

The Node.js REPL in a React component.

Live Demo | Documentation

Features

  • Simple API
  • Powered by WebContainers
  • Install npm packages locally, directly in the terminal
  • Switch between Terminal or Console View
  • Keyboard shortcuts
  • TypeScript support

Upcoming

  • Serialization of objects for better console view
  • Code formating
  • Syntax errors highlighting
  • TypeScript errors

Requirements

  • Your site must be served over HTTPS.
  • The following headers must be set in your deployed page.
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin

Installation

npm install @opentf/react-node-repl
yarn add @opentf/react-node-repl
pnpm add @opentf/react-node-repl
bun add @opentf/react-node-repl

Usage

import { NodeREPL } from "@opentf/react-node-repl";
import "@opentf/react-node-repl/lib/style.css";

export default function App() {
  const code = `console.log("Hello World")`;
  const deps = ["pkg1", "pkg2@1.2.3", "pkg3@beta"];

  return <NodeREPL code={code} deps={deps} layout="SPLIT_PANEL" />;
}

API

Props

PropTypeRequiredDefaultDescription
codestringNo""The main code to execute
depsstring[]No[]The npm dependencies.Eg: 'lodash', 'chalk@4.1.2'
setupCodestringNo""The setup code, used to init some values. Eg: const log = console.log
layoutstringNo"DEFAULT"The predefined layouts for the components.There are two types of layout: 1. DEFAULT2. SPLIT_PANEL
editorEditorPropsNoundefinedThe editor component config.
terminalTerminalPropsNoundefinedThe terminal component config.
consoleConsolePropsNoundefinedThe console component config.
styleReact.CSSPropertiesNo{}It is used to style the component container.

EditorProps

PropTypeRequiredDefaultDescription
headerbooleanNotrueShow / Hide the editor header component.
darkModebooleanNofalseThe editor dark mode toggle.
styleReact.CSSPropertiesNo{}It is used to style the editor container.

TerminalProps

PropTypeRequiredDefaultDescription
showbooleanNotrueShow / Hide the terminal component.
styleReact.CSSPropertiesNo{}It is used to style the terminal container.

ConsoleProps

PropTypeRequiredDefaultDescription
showbooleanNotrueShow / Hide the console component.
styleReact.CSSPropertiesNo{}It is used to style the console container.

Limitations

  • Currently, it runs only Node.js v18
  • By default, in REPL mode, you cannot use import statements. You need to fallback to require().
  • You can run ESM modules manually in the terminal with the ESM switch on. Eg: $ node main.js
  • It is not possible to run native addons.

Related

License

Copyright (c) 2021, Thanga Ganapathy (MIT License).

0.14.0

1 month ago

0.13.0

1 month ago

0.12.1

1 month ago

0.12.0

2 months ago

0.11.0

2 months ago

0.10.0

2 months ago

0.9.0

2 months ago

0.8.0

2 months ago

0.7.0

2 months ago

0.6.0

2 months ago

0.5.0

2 months ago

0.4.0

2 months ago

0.3.0

2 months ago

0.2.0

2 months ago

0.1.1

2 months ago

0.1.0

2 months ago