2.0.11 • Published 7 months ago

@kwruntime/core v2.0.11

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

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

Install:

npx @kwruntime/core --install 

After installing, you can run any script in JavaScript/TypeScript/Civet with the command kwruntime

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!
2.0.3

10 months ago

2.0.2

10 months ago

2.0.5

10 months ago

2.0.4

10 months ago

2.0.11

7 months ago

2.0.7

9 months ago

2.0.6

9 months ago

2.0.9

7 months ago

2.0.10

7 months ago

2.0.8

9 months ago

2.0.1

10 months ago

1.1.39

2 years ago

1.1.20

3 years ago

1.1.19

3 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago