Dune is an open-source, cross-platform, shell around the V8 engine, written in Rust and capable of running JavaScript (dah) and TypeScript code out of the box.
Developed completely for fun and experimentation.
Mac, Linux:
curl -fsSL https://raw.githubusercontent.com/aalykiot/dune/main/install.sh | sh
Windows
You have to manually download and unzip the release build.
A powershell installation script is coming soon.
From Source:
Clone the repo and build it using Cargo.
git clone https://github.com/aalykiot/dune.git && cd ./dune && cargo release
Make sure to create a
.dune
directory under your user.
A simple example.
import shortid from 'https://cdn.skypack.dev/shortid';
console.log(shortid()); //=> "lXN1aGba2"
Another example using the net module.
import net from 'net';
const server = net.createServer(async (socket) => {
console.log('Got new connection!');
await socket.write('Hello! π\n');
await socket.destroy();
});
server.listen(3000, '127.0.0.1', () => {
console.log('Server is listening on port 3000...');
});
The complete API reference is in the next section.
-
global
: reference to the global object. -
globalThis
: same asglobal
. -
console
: a subset of the WHATWG console. -
TextEncoder
/TextDecoder
: WHATWG encoding API. -
setTimeout
/setInterval
/clearTimeout
/clearInterval
: DOM style timers. -
setImmediate
/clearImmediate
: node.js like immediate timers. -
process
: an object that provides info about the current dune process.
-
argv
: an array containing the command-line arguments passed when the dune process was launched. -
cwd()
: current working directory. -
env
: an object containing the user environment. -
exit([code])
: exits the program with the given code. -
getActiveResourcesInfo()
: an array of strings containing the types of the active resources that are currently keeping the event loop alive. -
memoryUsage()
: an object describing the memory usage. -
pid
: PID of the process. -
platform
: a string identifying the operating system platform. -
uptime()
: a number describing the amount of time (in seconds) the process is running. -
version
: the dune version. -
versions
: an object listing the version strings of dune and its dependencies. -
binding(module)
: exposes modules with bindings to Rust. -
kill(pid, [signal])
: sends the signal to the process identified by pid. -
stdout
: points to system'sstdout
stream. -
stdin
: points to system'sstdin
stream. -
stderr
: points to system'sstderr
stream.
This module should also include a
Sync
method for every async operation available.
-
copyFile(src, dest)
: copiessrc
todest
. -
createReadStream(path, [options])
: creates a readable IO stream. -
createWriteStream(path, [options])
: creates a writable IO stream. -
open(path, [mode])
: asynchronous file open. -
mkdir(path, [options])
: creates a directory. -
readFile(path, [options])
: reads the entire contents of a file. -
rmdir(path, [options])
: deletes a directory (must be empty). -
rm(path, [options])
: removes files and directories. -
stat(path)
: retrieves statistics for the file. -
writeFile(String|Uint8Array , data, [options])
: writes data to the file, replacing the file if it already exists.
-
fd
: the numeric file descriptor. -
close()
: closes the file. -
createReadStream()
: creates a readable IO stream. -
createWriteStream()
: creates a writable IO stream. -
read([size, [offset]])
: reads data from the file. -
stat()
: retrieves statistics for the file. -
write(String|Uint8Array, [offset])
: writes data to the file.
-
createServer([connectionListener])
: Creates a new TCP server. -
createConnection(options, [connectionListener])
: Creates unix socket connection to a remote host.
Net.Server is a class extending
EventEmitter
.
-
listen(port, [host], [callback])
: Begin accepting connections on the specified port and host. -
close([callback])
: Stops the server from accepting new connections and keeps existing connections. -
address()
: Returns the bound address. -
getConnections()
: Get the number of concurrent connections on the server. -
Event: 'listening'
: Emitted when the server has been bound after callingserver.listen
. -
Event: 'connection'
: Emitted when a new connection is made. -
Event: 'close'
: Emitted when the server closes. -
Event: 'error'
: Emitted when an error occurs.
Net.Socket is a class extending
EventEmitter
.
-
connect(options, [connectionListener])
: Opens the connection for a given socket. -
setEncoding(encoding)
: Set the encoding for the socket. -
write(data, [callback])
: Sends data on the socket. -
end([data])
: Half-closes the socket. i.e., it sends a FIN packet. -
destroy()
: Closes and discards the TCP socket stream. -
address()
: Returns the bound address. -
remoteAddress
: The string representation of the remote IP address. -
remotePort
: The numeric representation of the remote port. -
bytesRead
: The amount of received bytes. -
bytesWritten
: The amount of bytes sent. -
Event: 'connect'
: Emitted when a socket connection is successfully established. -
Event: 'data'
: Emitted when data is received. -
Event: 'end'
: Emitted when the other end of the socket sends a FIN packet. -
Event: 'error'
: Emitted when an error occurs. -
Event: 'close'
: Emitted once the socket is fully closed.
-
timeOrigin
: specifies the millisecond timestamp at which the current process began. -
now()
: returns the millisecond timestamp, where 0 represents the start of the current process.
The assertion API is copied from: https://assert-js.norbert.tech/
-
true(value)
: asserts that value is equal to true. -
false(value)
: asserts that value is equal to false. -
instanceOf(value, class)
: asserts that value is an instance of specific class. -
integer(value)
: asserts that value is valid integer. -
number(value)
: asserts that value is valid number (integer, float). -
oddNumber(value)
: asserts that value is odd number. -
evenNumber(value)
: asserts that value is event number. -
greaterThan(value, limit)
: asserts that number is greater than. -
greaterThanOrEqual(value, limit)
: asserts that number is greater than or equal. -
lessThan(value, limit)
: asserts that number is less than. -
lessThanOrEqual(value, limit)
: asserts that number is less than or equal. -
string(value)
: asserts that value is valid string. -
boolean(value)
: asserts that value is valid boolean. -
equal(actual, expected)
: asserts that value is equal to expected value. -
objectEqual(actual, expected)
: asserts that value is equal to expected value. -
object(value)
: asserts that value is valid object. -
hasFunction(name, object)
: asserts that object has function. -
hasProperty(name, object)
: asserts that object has property. -
isFunction(fn)
: asserts that value is valid function. -
array(value)
: asserts that value is valid array. -
count(expected, arrayValue)
: asserts that array have specific number of elements. -
notEmpty(arrayValue)
: asserts that array is not empty. -
throws(fn, error)
: asserts that function throws expected exception.
This project is licensed under the MIT license.