From a0a6315e934886d000d9cac8f4d51134c650ee6a Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 22 Dec 2021 05:07:27 -0500 Subject: [PATCH] deeper module loading --- loader.mjs | 11 +++++++---- src/commands/help.ts | 1 - src/index.ts | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/loader.mjs b/loader.mjs index 0bdc909..76c96a4 100644 --- a/loader.mjs +++ b/loader.mjs @@ -3,6 +3,7 @@ import * as tsConfigPaths from "tsconfig-paths"; import chalk from 'chalk'; import { dirname, resolve as pathResolve } from 'path'; import { fileURLToPath } from 'url'; +import { sep } from 'path'; const __dirname = dirname(fileURLToPath(import.meta.url)); @@ -38,8 +39,7 @@ export async function resolve(specifier, context, defaultResolver) { '@commands:save': pathResolve(__dirname, 'src', 'commands', 'save.ts'), '@commands:help': pathResolve(__dirname, 'src', 'commands', 'help.ts'), - '@builtin:systemd': pathResolve(__dirname, 'src', 'modules', 'systemd.ts'), - '@builtin:sshd': pathResolve(__dirname, 'src', 'modules', 'sshd.ts'), + '@builtin:': (s) => pathResolve(__dirname, 'src', 'modules', s) + '.ts', '@echo off': pathResolve(__dirname, 'src', 'noop.ts') }; @@ -51,8 +51,11 @@ export async function resolve(specifier, context, defaultResolver) { const match = matches[0]; const replace = maps[match]; const len = match.length; - specifier = replace + specifier.substring(len) - + specifier = specifier.substring(len); + if(typeof replace === 'string') + specifier = replace + specifier + else if (typeof replace === 'function') + specifier = replace(specifier); } else if(matches.length > 1) { const error = `Ambiguous import specifier: ${specifier} matches: diff --git a/src/commands/help.ts b/src/commands/help.ts index 7beb729..7591ca9 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -18,6 +18,5 @@ export default function() { set v ...d : Set a kernel variable v : The name of the variable ...d : The value (or values, space delimited) - `) } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 42bf4db..279e0e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -132,4 +132,4 @@ const executor = createExecutor(kernel); }); checkpoint('Kernel Loaded'); -// import '@echo off'; +import '@echo off'; \ No newline at end of file