imba-shell
Version:
Interactive debugger and REPL for Imba.
547 lines (524 loc) • 25.6 kB
JavaScript
globalThis.IMBA_MANIFEST={};globalThis.IMBA_ASSETS_PATH='assets';
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
mod
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
// src/index.imba
var src_exports = {};
__export(src_exports, {
Command: () => Command,
Compilers: () => Compilers_exports,
ContextHelpers: () => ContextHelpers_exports,
Errors: () => Errors_exports,
ImbaRepl: () => ImbaRepl,
Runners: () => Runners_exports,
UpdateNotifier: () => UpdateNotifier
});
module.exports = __toCommonJS(src_exports);
// src/Compilers/index.imba
var Compilers_exports = {};
__export(Compilers_exports, {
Compiler: () => Compiler,
ImbaCompiler: () => ImbaCompiler,
TypeScriptCompiler: () => TypeScriptCompiler
});
// node_modules/imba/src/imba/runtime.mjs
var __init__$ = /* @__PURE__ */ Symbol.for("#__init__"), __initor__$ = /* @__PURE__ */ Symbol.for("#__initor__"), __inited__$ = /* @__PURE__ */ Symbol.for("#__inited__"), __hooks__$ = /* @__PURE__ */ Symbol.for("#__hooks__");
var __meta__$ = /* @__PURE__ */ Symbol.for("#meta"), __imba__$ = /* @__PURE__ */ Symbol.for("imba");
var HAS = {
SUPERCALLS: 1 << 3,
CONSTRUCTOR: 1 << 4
}, ClassFlags = {
IsExtension: 1 << 0,
IsTag: 1 << 1,
HasDescriptors: 1 << 2,
HasSuperCalls: 1 << 3,
HasConstructor: 1 << 4,
HasFields: 1 << 5,
HasMixins: 1 << 6,
HasInitor: 1 << 7,
HasDecorators: 1 << 8,
IsObjectExtension: 1 << 9
}, mmap = /* @__PURE__ */ new Map(), state = globalThis[__imba__$] || (globalThis[__imba__$] = {
counter: 0,
classes: mmap
});
function meta$(klass, defaults = {}) {
var _a;
return mmap.has(klass) || mmap.set(klass, {
symbol: /* @__PURE__ */ Symbol(klass.name),
parent: (_a = Object.getPrototypeOf(klass.prototype)) == null ? void 0 : _a.constructor,
for: klass,
uses: null,
inits: null,
id: state.counter++,
...defaults
}), mmap.get(klass);
}
function iterable$(a) {
var _a;
return ((_a = a == null ? void 0 : a.toIterable) == null ? void 0 : _a.call(a)) || a;
}
function isSameDesc(a, b) {
if (!a || !b)
return !1;
if (a.get)
return b.get === a.get;
if (a.set)
return b.set === a.set;
if (a.value)
return a.value === b.value;
}
function extend$(target, ext, descs, cache = {}) {
let klass = target.constructor;
!descs && ext && (descs = Object.getOwnPropertyDescriptors(ext), delete descs.constructor, descs[__init__$] && (console.warn(`Cannot define plain fields when extending class ${klass.name}`), delete descs[__init__$]));
let meta = meta$(klass);
if (meta && meta.augments) {
let map = /* @__PURE__ */ new Map();
for (let key of Object.keys(descs)) {
let orig = Object.getOwnPropertyDescriptor(target, key);
for (let augmented of meta.augments) {
let defines = map.get(augmented);
defines || map.set(augmented, defines = {});
let augmentedKey = Object.getOwnPropertyDescriptor(augmented.prototype, key);
augmentedKey && !isSameDesc(orig, augmentedKey) ? console.warn("wont extend", key, augmentedKey, orig) : defines[key] = descs[key];
}
}
for (let [augmented, defines] of map)
Object.keys(defines).length && extend$(augmented.prototype, null, defines);
}
return Object.defineProperties(target, descs), target;
}
function augment$(klass, mixin) {
let meta = meta$(klass), mix = meta$(mixin);
if (mix.parent && !(klass.prototype instanceof mix.parent))
throw new Error(`Mixin ${mixin.name} has superclass not present in target class`);
if (!mix.augments) {
mix.augments = /* @__PURE__ */ new Set();
let ref = mix.ref = /* @__PURE__ */ Symbol(mixin.name), native = Object[Symbol.hasInstance];
mixin.prototype[ref] = !0, Object.defineProperty(mixin, Symbol.hasInstance, {
value: function(rel) {
return this === mixin ? rel && !!rel[ref] : native.call(this, rel);
}
});
}
if (klass.prototype[mix.ref])
return klass;
if (mix.uses)
for (let v of mix.uses)
augment$(klass, v);
mix.augments.add(klass), meta.uses || (meta.uses = []), meta.uses.push(mixin);
let descs = Object.getOwnPropertyDescriptors(mixin.prototype);
return delete descs.constructor, descs[__init__$] && (meta.inits || (meta.inits = []), meta.inits.push(mixin.prototype[__init__$]), delete descs[__init__$]), Object.defineProperties(klass.prototype, descs), (mixin == null ? void 0 : mixin.mixed) instanceof Function && mixin.mixed(klass), klass;
}
var sup = {
cache: {},
self: null,
target: null,
proxy: new Proxy({}, {
apply: (_, key, ...params) => sup.target[key].apply(sup.self, params),
get: (_, key) => Reflect.get(sup.target, key, sup.self),
set: (_, key, value, receiver) => Reflect.set(sup.target, key, value, sup.self)
})
};
function register$(klass, symbol, name2, flags, into = null) {
var _a;
let proto = Object.getPrototypeOf(klass.prototype), mixed = flags & ClassFlags.HasMixins, meta;
if (mixed && (mmap.set(klass, mmap.get(proto.constructor)), proto = Object.getPrototypeOf(proto)), into) {
let target = flags & ClassFlags.IsObjectExtension ? into : into.prototype, meta2 = meta$(klass);
if (meta2.uses) {
into === target && console.warn("Cannot extend object with mixins");
for (let mixin of meta2.uses)
augment$(into, mixin);
}
return flags & ClassFlags.HasSuperCalls && (sup.cache[symbol] = Object.create(
Object.getPrototypeOf(target),
Object.getOwnPropertyDescriptors(target)
)), extend$(target, klass.prototype), into;
}
let supr = proto == null ? void 0 : proto.constructor;
if (meta = meta$(klass, { symbol }), Object.defineProperty(klass, __meta__$, { value: meta, enumerable: !1, configurable: !0 }), name2 && klass.name !== name2 && Object.defineProperty(klass, "name", { value: name2, configurable: !0 }), meta.flags = flags, flags & ClassFlags.HasConstructor && (klass.prototype[__initor__$] = symbol), meta.uses)
for (let mixin of meta.uses)
(_a = mixin.mixes) == null || _a.call(mixin, klass);
return (supr == null ? void 0 : supr.inherited) instanceof Function && supr.inherited(klass), klass;
}
function inited$(obj, symbol) {
var _a;
obj[__initor__$] === symbol && ((_a = obj[__inited__$]) == null || _a.call(obj), obj[__hooks__$] && obj[__hooks__$].inited(obj));
}
// package.json
var name = "imba-shell", version = "0.5.3";
// src/Compilers/Compiler.imba
var import_fs = __toESM(require("fs")), import_os = __toESM(require("os")), import_path = __toESM(require("path")), c$0 = /* @__PURE__ */ Symbol(), _Compiler = class {
[__init__$]($$ = null, deep = !0, fields = !0) {
var $0;
this.directory = $$ && ($0 = $$.directory) !== void 0 ? $0 : import_path.default.join(import_os.default.tmpdir(), "." + name), this.code = $$ ? $$.code : void 0, this.sessionId = $$ ? $$.sessionId : void 0;
}
constructor(code, sessionId) {
if (this[__init__$](), typeof code != "string")
throw new TypeError("Expected code to be a String.");
if (typeof sessionId != "string")
throw new TypeError("Expected sessionId to be a String.");
import_fs.default.existsSync(this.directory) || import_fs.default.mkdirSync(this.directory, { recursive: !0 }), this.code = code, this.sessionId = sessionId, inited$(this, c$0);
}
static code(code, sessionId) {
return new this(code, sessionId);
}
}, Compiler = _Compiler;
(() => {
register$(_Compiler, c$0, "Compiler", 16);
})();
// src/Compilers/ImbaCompiler.imba
var import_child_process3 = require("child_process");
// src/Runners/index.imba
var Runners_exports = {};
__export(Runners_exports, {
ImbaRunner: () => ImbaRunner,
TypeScriptRunner: () => TypeScriptRunner
});
// src/Runners/ImbaRunner.imba
var import_path2 = require("path");
var import_child_process = require("child_process"), import_fs2 = __toESM(require("fs"));
// src/Errors/ImbaMissingException.imba
var c$02 = /* @__PURE__ */ Symbol(), _ImbaMissingException = class extends Error {
}, ImbaMissingException = _ImbaMissingException;
(() => {
register$(_ImbaMissingException, c$02, "ImbaMissingException", 0);
})();
// src/Runners/ImbaRunner.imba
var import_path3 = __toESM(require("path")), c$03 = /* @__PURE__ */ Symbol(), _ImbaRunner = class {
static get ext() {
return process.platform === "win32" ? ".cmd" : "";
}
static get imba() {
let local = import_path3.default.join(process.cwd(), "node_modules", ".bin", "imba"), onboard = import_path3.default.join(__dirname, "..", "node_modules", ".bin", "imba");
return import_fs2.default.existsSync(local) ? local : onboard;
}
static instance(compiler = !1) {
let file = this.imba + (compiler ? "c" : "") + this.ext;
if (!import_fs2.default.existsSync(file))
throw new ImbaMissingException("Imba not found at " + file);
return file;
}
static get version() {
return (0, import_child_process.execSync)("" + this.instance(!0) + " -v").toString().trim();
}
}, ImbaRunner = _ImbaRunner;
(() => {
register$(_ImbaRunner, c$03, "ImbaRunner", 0);
})();
// src/Runners/TypeScriptRunner.imba
var import_path4 = require("path");
var import_child_process2 = require("child_process"), import_fs3 = __toESM(require("fs"));
// src/Errors/TypeScriptMissingException.imba
var c$04 = /* @__PURE__ */ Symbol(), _TypeScriptMissingException = class extends Error {
}, TypeScriptMissingException = _TypeScriptMissingException;
(() => {
register$(_TypeScriptMissingException, c$04, "TypeScriptMissingException", 0);
})();
// src/Runners/TypeScriptRunner.imba
var import_path5 = __toESM(require("path")), c$05 = /* @__PURE__ */ Symbol(), _TypeScriptRunner = class {
static get tsc() {
let local = import_path5.default.join(process.cwd(), "node_modules", ".bin", "tsc"), onboard = import_path5.default.join(__dirname, "..", "node_modules", ".bin", "tsc");
return import_fs3.default.existsSync(local) ? local : onboard;
}
static instance() {
let file = this.tsc;
if (!import_fs3.default.existsSync(file))
throw new TypeScriptMissingException("tsc not found at " + file);
return file;
}
static get version() {
return (0, import_child_process2.execSync)("" + this.instance() + " -v").toString().trim().split(" ")[1];
}
}, TypeScriptRunner = _TypeScriptRunner;
(() => {
register$(_TypeScriptRunner, c$05, "TypeScriptRunner", 0);
})();
// src/Compilers/ImbaCompiler.imba
var import_fs4 = __toESM(require("fs")), import_os2 = require("os"), import_path6 = __toESM(require("path")), c$06 = /* @__PURE__ */ Symbol(), _ImbaCompiler = class extends Compiler {
get() {
import_fs4.default.writeFileSync(import_path6.default.join(this.directory, this.sessionId), this.code.trim());
let results = (0, import_child_process3.execSync)("" + ImbaRunner.instance(!0) + " " + import_path6.default.join(this.directory, this.sessionId) + " --platform=node --format=cjs --print");
return import_fs4.default.rmSync(import_path6.default.join(this.directory, this.sessionId)), results.toString();
}
}, ImbaCompiler = _ImbaCompiler;
(() => {
register$(_ImbaCompiler, c$06, "ImbaCompiler", 0);
})();
// src/Compilers/TypeScriptCompiler.imba
var import_typescript = require("typescript");
var c$07 = /* @__PURE__ */ Symbol(), _TypeScriptCompiler = class extends Compiler {
get() {
return (0, import_typescript.transpile)(this.code.trim(), {
module: "CommonJS",
target: "ESNext",
moduleResolution: "node",
esModuleInterop: !0
});
}
}, TypeScriptCompiler = _TypeScriptCompiler;
(() => {
register$(_TypeScriptCompiler, c$07, "TypeScriptCompiler", 0);
})();
// src/ContextHelpers.imba
var ContextHelpers_exports = {};
__export(ContextHelpers_exports, {
clear: () => clear,
exit: () => exit
});
function exit() {
return console.log("Exit: Goodbye"), process.exit();
}
function clear() {
process.stdout.write("\x1B[2J\x1B[0;0f");
}
// src/Errors/index.imba
var Errors_exports = {};
__export(Errors_exports, {
ImbaMissingException: () => ImbaMissingException,
InvalidLanguageException: () => InvalidLanguageException
});
// src/Errors/InvalidLanguageException.imba
var c$08 = /* @__PURE__ */ Symbol(), _InvalidLanguageException = class extends Error {
}, InvalidLanguageException = _InvalidLanguageException;
(() => {
register$(_InvalidLanguageException, c$08, "InvalidLanguageException", 0);
})();
// src/Command.imba
var import_fs5 = require("fs");
var import_path7 = require("path"), import_child_process4 = require("child_process");
var c$09 = /* @__PURE__ */ Symbol(), _Command = class {
[__init__$]($$ = null, deep = !0, fields = !0) {
var $0;
this.args = $$ && ($0 = $$.args) !== void 0 ? $0 : [], this.watch = $$ && ($0 = $$.watch) !== void 0 ? $0 : !1;
}
get isRuntime() {
return !1;
}
constructor() {
this[__init__$](), this.args = process.argv.slice(2), inited$(this, c$09);
}
enableWatcher() {
return this.watch = !0, this.args = this.args.filter(function(arg) {
return !["-w", "--watch"].includes(arg);
});
}
printVersion() {
return console.log("Imba Shell v" + version + " (imba " + ImbaRunner.version + ")");
}
displayHelp() {
return this.isRuntime ? console.log(`\x1B[32mUsage:\x1B[0m
[options] [\x1B[2m<script>\x1B[0m]
`) : console.log(`\x1B[32mUsage:\x1B[0m
\x1B[2mimba-shell\x1B[0m [options]
`), console.log("\x1B[32mOptions:\x1B[0m"), console.log(" \x1B[32m-h, --help\x1B[0m Display help"), console.log(" \x1B[32m-v, --version\x1B[0m Display this application version"), this.isRuntime ? console.log(" \x1B[32m-w, --watch\x1B[0m Continously build and watch project") : console.log(" \x1B[32m --ts\x1B[0m Run Repl in TypeScript mode");
}
invalidCommand() {
return console.log('The "' + this.args[0] + '" option does not exist.'), process.exit(1);
}
run() {
if (this.isRuntime) {
if (this.args[0] && (this.args[0].trim() == "--watch" || this.args[0].trim() == "-w") && this.enableWatcher(), this.watch == !1 && !this.args[0])
return this.displayHelp();
(this.args[0] == null && this.watch || !(0, import_fs5.existsSync)((0, import_path7.join)(process.cwd(), this.args[0])) && !this.args[0].trim().startsWith("-")) && (console.log("Error: Script missing."), process.exit(1));
}
return !this.isRuntime && this.args.length == 1 && this.args[0] == "--ts" || !(this.args.length > 0) ? this.handle(this.args[0] ? "typescript" : "imba") : this.args.length > 0 ? this.args[0].trim() == "--version" || this.args[0].trim() == "-v" ? this.printVersion() : this.args[0].trim() == "--help" || this.args[0].trim() == "-h" ? this.displayHelp() : (0, import_fs5.existsSync)((0, import_path7.join)(process.cwd(), this.args[0])) ? this.exec() : this.invalidCommand() : this.handle();
}
exec() {
let fallbackScript = this.createFallbackScript();
process.platform === "win32" && (this.args[0] = fallbackScript || (0, import_path7.join)(process.cwd(), this.args[0])), this.args.splice(1, 0, "--");
let watcher = [];
this.watch && watcher.push("-w");
let options = {
stdio: "inherit",
cwd: process.cwd()
};
if (process.platform === "win32") {
let sh = process.env.comspec || "cmd", shFlag = "/d /s /c";
options.windowsVerbatimArguments = !0, (0, import_child_process4.spawnSync)(sh, [shFlag, ImbaRunner.instance(), ...watcher, ...this.args], options);
} else
(0, import_child_process4.spawnSync)(ImbaRunner.instance(), [...watcher, ...this.args], options);
if (fallbackScript !== null)
return (0, import_fs5.unlinkSync)(fallbackScript);
}
createFallbackScript() {
let sourceScript = null, fallbackScript = null;
if (!(this.args[0].endsWith(".imba") || this.args[0].endsWith(".ts"))) {
sourceScript = (0, import_path7.join)(process.cwd(), this.args[0]), fallbackScript = (0, import_path7.join)(process.cwd(), (0, import_path7.dirname)(this.args[0]), "." + (0, import_path7.basename)(this.args[0]) + ".imba");
try {
(0, import_fs5.copyFileSync)(sourceScript, fallbackScript), this.args[0] = (0, import_path7.join)((0, import_path7.dirname)(this.args[0]), "." + (0, import_path7.basename)(this.args[0]) + ".imba");
} catch {
fallbackScript = null;
}
}
return fallbackScript;
}
handle() {
return null;
}
}, Command = _Command;
(() => {
register$(_Command, c$09, "Command", 16);
})();
// src/ImbaRepl.imba
var import_os4 = require("os"), import_path9 = require("path"), import_node_repl = __toESM(require("node:repl"));
// src/UpdateNotifier.imba
var import_fs6 = __toESM(require("fs")), import_https = __toESM(require("https")), import_os3 = __toESM(require("os")), import_path8 = __toESM(require("path")), c$010 = /* @__PURE__ */ Symbol(), _UpdateNotifier = class {
[__init__$]($$ = null, deep = !0, fields = !0) {
var $0;
this.package = $$ && ($0 = $$.package) !== void 0 ? $0 : "https://registry.npmjs.org/-/package/" + name + "/dist-tags", this.directory = $$ && ($0 = $$.directory) !== void 0 ? $0 : import_path8.default.join(import_os3.default.homedir(), "." + name);
}
constructor() {
this[__init__$](), import_fs6.default.existsSync(this.directory) || import_fs6.default.mkdirSync(this.directory), this.shouldFetchLatestVersion() && this.fetchLatestVersion(), inited$(this, c$010);
}
shouldFetchLatestVersion() {
let file = import_path8.default.join(this.directory, "latest.json");
if (!import_fs6.default.existsSync(file))
return !0;
let fileDate = import_fs6.default.statSync(file).mtime, currentDate = new Date(), _FILE_DATE = Date.UTC(fileDate.getFullYear(), fileDate.getMonth(), fileDate.getDate()), _CURRENT_DATE = Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()), _MS_PER_DAY = 1e3 * 60 * 60 * 24, shouldRefresh = Math.floor((_CURRENT_DATE - _FILE_DATE) / _MS_PER_DAY > 0);
return shouldRefresh && import_fs6.default.unlinkSync(file), shouldRefresh;
}
compareVersion(latestVersion) {
return version.trim() == latestVersion.trim() ? 0 : latestVersion.localeCompare(version) == 1;
}
fetchLatestVersion() {
var self = this;
let request = import_https.default.get(this.package);
return request.on("response", function(response) {
if (response.statusCode !== 200)
return;
let data = "";
return response.on("data", function(chunk) {
return data += chunk;
}), response.on("end", function() {
return self.storeVersion(data);
});
}), request.end(), request.on("error", function() {
});
}
storeVersion(data) {
let latestPath = import_path8.default.join(this.directory, "latest.json");
return import_fs6.default.writeFileSync(latestPath, data);
}
check(callback = null) {
if (!import_fs6.default.existsSync(import_path8.default.join(this.directory, "latest.json")))
return;
let response = JSON.parse(import_fs6.default.readFileSync(import_path8.default.join(this.directory, "latest.json")).toString());
if (!this.compareVersion(response.latest))
return;
if (callback && typeof callback == "function")
return response.current = version, callback(response);
let repeat = function(char$) {
return char$.repeat(name.length * 2);
};
return console.log("┌─────────────────────────────────────────────────────" + repeat("─") + "─┐"), console.log("│ " + repeat(" ") + "│"), console.log("│ New version available: v" + response.latest + " (current: v" + version + ") " + repeat(" ") + "│"), console.log("│ Run \x1B[32mnpm install -g " + name + "\x1B[0m or \x1B[32myarn global add " + name + "\x1B[0m to update! │"), console.log("│ " + repeat(" ") + "│"), console.log("└──────────────────────────────────────────────────────" + repeat("─") + "┘"), null;
}
}, UpdateNotifier = _UpdateNotifier;
(() => {
register$(_UpdateNotifier, c$010, "UpdateNotifier", 16);
})();
// src/ImbaRepl.imba
var c$011 = /* @__PURE__ */ Symbol(), _ImbaRepl = class {
[__init__$]($$ = null, deep = !0, fields = !0) {
var $0;
this.ctxCallbacks = $$ && ($0 = $$.ctxCallbacks) !== void 0 ? $0 : [], this.cmdCallbacks = $$ && ($0 = $$.cmdCallbacks) !== void 0 ? $0 : [], this.update = $$ && ($0 = $$.update) !== void 0 ? $0 : null, this.language = $$ && ($0 = $$.language) !== void 0 ? $0 : "imba", this.prompt = $$ && ($0 = $$.prompt) !== void 0 ? $0 : ">>> ", this.historyPath = $$ && ($0 = $$.historyPath) !== void 0 ? $0 : null;
}
constructor(language = "imba", prompt = ">>> ", historyPath = null) {
if (this[__init__$](), typeof language != "string")
throw new TypeError("Expected language to be a String.");
if (!["imba", "typescript"].includes(language.toLowerCase()))
throw new InvalidLanguageException('Expected language to be "imba" or "typescript".');
if (typeof prompt != "string")
throw new TypeError("Expected prompt to be a String.");
if (historyPath && typeof historyPath != "string")
throw new TypeError("Expected historyPath to be a String.");
this.language = language.toLowerCase(), this.prompt = prompt, this.historyPath = historyPath, inited$(this, c$011);
}
registerCallback(callback) {
if (typeof callback != "function")
throw new TypeError("Expected callback to be a Function.");
return this.ctxCallbacks.push(callback), this;
}
registerCommand(name2, callback) {
if (typeof name2 != "string")
throw new TypeError("Expected command name to be a String.");
return this.cmdCallbacks.push({ name: name2, callback }), this;
}
shouldUpdate(callback = null) {
if (callback && typeof callback != "function")
throw new TypeError("Expected callback to be a Function.");
return this.update = callback || !0, this;
}
async run(options = {}) {
var self = this;
if (options !== null && !(options !== null && typeof options == "object" && Array.isArray(options) === !1))
throw new TypeError("Expected repl options to be an Object.");
let compilerVersion = this.language == "imba" ? "imba " + ImbaRunner.version : "typescript " + TypeScriptRunner.version;
console.log("Imba Shell v" + version + " (" + compilerVersion + ") by Donald Pakkies"), this.update && new UpdateNotifier().check(this.update);
let server = await import_node_repl.default.start({ prompt: this.prompt, ...options });
this.historyPath && server.setupHistory(this.historyPath, function(err, cb) {
if (err)
throw err;
}), this.registerCommand("clear", function() {
return clear(), process.stdout.write(self.prompt);
}), this.registerCommand("exit", function() {
return exit();
});
for (let $1 = 0, $2 = iterable$(this.ctxCallbacks), $3 = $2.length; $1 < $3; $1++) {
let handler = $2[$1];
handler(server.context);
}
for (let $4 = 0, $5 = iterable$(this.cmdCallbacks), $6 = $5.length; $4 < $6; $4++) {
let handler = $5[$4];
server.defineCommand(handler.name, handler.callback);
}
for (let $7 = 0, $8 = Object.keys(ContextHelpers_exports), $9 = $8.length, key, handler; $7 < $9; $7++)
key = $8[$7], handler = ContextHelpers_exports[key], server.context[key] = handler;
let cmdEval = server.eval, sessionId = String(new Date().valueOf());
return server.eval = function(cmd, context, file, cb) {
let compiledCode = self.language == "imba" ? ImbaCompiler.code(cmd, sessionId).get() : TypeScriptCompiler.code(cmd, sessionId).get();
return cmdEval(compiledCode || "", context, file, async function(error, results) {
if (error)
return cb(error);
try {
return cb(null, await Promise.resolve(results));
} catch (err) {
return cb(err);
}
});
}, server.sessionId = sessionId, server.input.on("keypress", function(chunk, key) {
if (key.name == "tab" && key.shift)
return server.write(" ");
}), server;
}
}, ImbaRepl = _ImbaRepl;
(() => {
register$(_ImbaRepl, c$011, "ImbaRepl", 16);
})();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Command,
Compilers,
ContextHelpers,
Errors,
ImbaRepl,
Runners,
UpdateNotifier
});
//__FOOT__
//# sourceMappingURL=./index.js.map