@endo/compartment-mapper
Version:
The compartment mapper assembles Node applications in a sandbox
91 lines • 3.88 kB
TypeScript
export function makeFunctorFromMap(readPowers: ReadFn | ReadPowers | MaybeReadPowers, compartmentMap: PackageCompartmentMapDescriptor, options?: BundleOptions): Promise<string>;
export function makeScriptFromMap(readPowers: ReadFn | ReadPowers | MaybeReadPowers, compartmentMap: PackageCompartmentMapDescriptor, options?: BundleOptions): Promise<string>;
/**
* The bundler kit defines a language-specific behavior for injecting a module
* into a bundle.
* Each module must allocate cells for its imports and exports, link those cells
* to the cells of dependencies, and provide both the linker and evaluation behavior
* for the module.
* The linker behavior gets injected in a lexical scope with the linker runtime
* and has access to the cells of all modules, whereas the evaluation behavior
* gets injected in the generated script's top level lexical scope, so has
* no accidental visibility into the linkage runtime.
*
* For example, JSON modules produce a single "default" cell ("getCells"):
*
* { default: cell('default') },
*
* Then, the JSON gets injected verbatim for the evaluation behavior ("getFunctor").
* The linker simply sets the cell to the value.
*
* functors[0]['default'].set(modules[0]);
*
* For an ECMAScript or CommonJS module, the evaluation behavior is a function
* that the linker runtime can call to inject it with the cells it needs by
* the names it sees for them.
*/
export type BundlerKit = {
/**
* Produces a JavaScript string consisting of
* a function expression followed by a comma delimiter that will be evaluated in
* a lexical scope with no free variables except the globals.
* In the generated bundle runtime, the function will receive an environment
* record: a record mapping every name of the corresponding module's internal
* namespace to a "cell" it can use to get, set, or observe the linked
* variable.
*/
getFunctor: () => string;
/**
* Produces a JavaScript string consisting of
* a JavaScript object and a trailing comma.
* The string is evaluated in the linker runtime's lexical context.
*/
getCells: () => string;
/**
* Produces a JavaScript string,
* a statement that effects the module's evaluation behavior using the cells
* it imports and exports and the evaluated "functor".
*/
getFunctorCall: () => string;
/**
* Produces a JavaScript string
* that may include statements that bind the cells reexported by this module.
*/
getReexportsWiring: () => string;
};
export type BundleModule<SpecificModuleSource extends unknown> = {
key: string;
exit: string;
compartmentName: string;
moduleSpecifier: string;
sourceDirname: string;
parser: string;
record: StaticModuleType & SpecificModuleSource;
resolvedImports: Record<string, string>;
indexedImports: Record<string, number>;
bytes: Uint8Array;
index: number;
bundlerKit: BundlerKit;
};
export type BundleExit = {
exit: string;
index: number;
bundlerKit: BundlerKit;
indexedImports: Record<string, number>;
resolvedImports: Record<string, string>;
};
export type GetBundlerKit<SpecificModuleSource extends unknown> = (module: BundleModule<SpecificModuleSource>, params: {
useEvaluate?: boolean | undefined;
sourceUrlPrefix?: string | undefined;
}) => BundlerKit;
export type BundlerSupport<SpecificModuleSource extends unknown> = {
runtime: string;
getBundlerKit: GetBundlerKit<SpecificModuleSource>;
};
import type { ReadFn } from './types.js';
import type { ReadPowers } from './types.js';
import type { MaybeReadPowers } from './types.js';
import type { PackageCompartmentMapDescriptor } from './types.js';
import type { BundleOptions } from './types.js';
import type { StaticModuleType } from 'ses';
//# sourceMappingURL=bundle-lite.d.ts.map