Back to Napplet Machines V8
SOURCE / PINNED RELEASE

Made of little things.

Napplet Machines V8

Release
f041ff5dc40c…
Author-recorded commit
71c68951e1dd…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-b5572362d4a

Archive hash verified: 996282af7a380b0d…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

tests/load.mjs
import { readFileSync } from 'node:fs';
import { resolve, dirname } from 'node:path';
import { runInNewContext } from 'node:vm';
import ts from 'typescript';
export function makeLoader(globals = {}, sdk = {}) {
  const cache = new Map();
  return function load(file) {
    file = resolve(file);
    if (cache.has(file)) return cache.get(file);
    const module = { exports: {} };
    cache.set(file, module.exports);
    const source = ts.transpileModule(readFileSync(file, 'utf8'), {
      compilerOptions: {
        module: ts.ModuleKind.CommonJS,
        target: ts.ScriptTarget.ES2022,
      },
    }).outputText;
    runInNewContext(source, {
      exports: module.exports,
      module,
      structuredClone,
      atob,
      btoa,
      console,
      Math,
      Number,
      Array,
      Object,
      Map,
      Set,
      JSON,
      ...globals,
      require: (name) =>
        name === '@napplet/sdk'
          ? sdk
          : name.endsWith('.json')
            ? JSON.parse(readFileSync(resolve(dirname(file), name), 'utf8'))
            : load(resolve(dirname(file), name.replace(/\.js$/, '.ts'))),
    });
    return module.exports;
  };
}
export const load = makeLoader();