JSPM

  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q73517F

Runtime for typescript/civet, with URL imports, NPM imports, GITHUB imports, GITLAB imports and more. The fun of deno, inside node.js + civet language.

Package Exports

  • @kwruntime/core
  • @kwruntime/core/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kwruntime/core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

kwruntime/core (2.x)

Major update for this project. The entire process of importing URLs, files, and other languages has been redesigned.

Features of kwruntime/core

  • Allows importing URLs (in the style of Deno)
  • Allows importing npm packages directly at runtime, even for ESM packages
  • Built-in support for TypeScript and Civet

Getting started

For installation instructions, click here: INSTALL


kwruntime /path/to/file.civet

Within node.js

const {kwruntime} = require("@kwruntime/core")

main()
async function main(){
    const axios = await kwruntime.import("npm:axios@0.27.2")
    const response = await axios("https://ipinfo.io")
    console.info("Response:", response.data)
}

or setting the execution to a file (similar result to how it would be executed in the terminal):

const {kwruntime} = require("@kwruntime/core")
// execute the file server.civet
kwruntime.main([process.argv[1], __dirname + "/server.civet"])

Typescript and civet support

interface Person {
  name: string;
  age: number;
}

function greet(person: Person): string {
  return "Hello, " + person.name + "!";
}

const alice: Person = {
  name: "Alice",
  age: 36
};

console.log(greet(alice));

You can also write in Civet:

interface Person
    name: string
    age: number

function greet(person: Person): string
    return "Hello, " + person.name + "!"

alice: Person := 
    name: "Alice"
    age: 36
    
console.log greet alice

Output:

kwruntime test.civet
Hello, Alice!

import from NPM packages, no need to install

Example: server.civet using express

express from "npm:express@4.18.2"

app := express()
app.get "/", (req, res): void =>
    res.send "Welcome to the kwruntime!"
app.listen 8000
console.info "Server active"

And test:

curl http://127.0.0.1:8080
Welcome to the kwruntime!

import from URL

express from "https://esm.sh/express@4.21.2"

app := express()
app.get "/", (req, res): void =>
    res.send "Welcome to the kwruntime!"
app.listen 8000
console.info "Server active"

WARNING: Importing from esm.sh is a bit slow at the moment. It is recommended to import using npm as in the previous example.

Si quiere ver el progreso de la compilación de archivos typescript/civet, ajuste la variable de entorno DEBUG=1

DEBUG=1 kwruntime /path/to/file

And test:

curl http://127.0.0.1:8080
Welcome to the kwruntime!