microvium
Version:
A compact, embeddable scripting engine for microcontrollers for executing small scripts written in a subset of JavaScript.
52 lines (51 loc) • 2.47 kB
TypeScript
import Microvium, { ImportHook, ModuleObject, ModuleSpecifier } from "../lib";
import resolve from 'resolve';
export interface ModuleOptions extends resolve.SyncOpts {
/**
* The "project" directory -- where to resolve initial specifiers from. This
* is used as the basedir for core module specifiers, and for specifiers for
* the root module (modules imported directly, rather than as nested
* dependencies of other modules). Nested dependencies always use a basedir
* corresponding to the location of the dependency.
*/
basedir?: string;
/**
* Core modules are those that can be referenced from anywhere with the same
* specifier, like node's 'fs' module which is not loaded as a relative path.
*
* This mapping either produces an object (e.g. if the core module is
* implemented by the host directly), or it produces another specifier that
* identifies the core module (e.g. a path specifier). If a specifier is
* provided, it is resolved relative to the basedir.
*/
coreModules?: {
[specifier: string]: ModuleObject | ModuleSpecifier;
};
/**
* - 'none': no access to file system (only specified core modules will be available)
* - 'sub-dir-only': only files that a subdirectory of the initial basedir will be accessible.
* - 'unrestricted': whole file system is eligible for import
*
* Defaults to 'subdir-only'
*/
fileSystemAccess?: 'none' | 'subdir-only' | 'unrestricted';
/**
* Allow access to node core modules such as 'http' or 'fs'
*/
allowNodeCoreModules?: boolean;
/** Glob patterns consumed by minimatch library to specify files eligible to
* be imported. Only files listed here can be imported. Defaults to match all
* files. */
includes?: string[];
/** Glob patterns consumed by minimatch library to specify files not eligible
* to be imported. Only files listed here can be imported. Files that are both
* included and excluded are excluded. Defaults to match no files. */
excludes?: string[];
}
/**
* Create a node-style module importer for the given VM and options.
*
* The term "node-style" here refers to the fact that the importer primarily
* works around filenames. Module caching is done on the full path
*/
export declare function nodeStyleImporter(vm: Microvium, options?: ModuleOptions): ImportHook;