mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-31 11:40:47 +08:00
Merge pull request #7237 from svi3c/master
Add sandboxed-module definitions
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Type definitions for sandboxed-module v2.0.3
|
||||
// Project: https://github.com/felixge/node-sandboxed-module
|
||||
// Definitions by: Sven Reglitzki <https://github.com/svi3c/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="sandboxed-module.d.ts" />
|
||||
|
||||
import SandboxedModule = require("sandboxed-module");
|
||||
|
||||
var sandboxedModule:SandboxedModule = SandboxedModule.load("foo");
|
||||
var sandboxedModuleExports:any = SandboxedModule.require("foo");
|
||||
|
||||
var sandboxedModuleExportsWithOptions:any = SandboxedModule.require("foo", {
|
||||
requires: {
|
||||
someDep: {}
|
||||
},
|
||||
globals: {
|
||||
theAnswer: 42
|
||||
},
|
||||
locals: {
|
||||
someLocal: 1
|
||||
},
|
||||
sourceTransformers: {
|
||||
identity: (src:string) => src
|
||||
},
|
||||
singleOnly: true,
|
||||
sourceTransformersSingleOnly: true
|
||||
});
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
// Type definitions for sandboxed-module v2.0.3
|
||||
// Project: https://github.com/felixge/node-sandboxed-module
|
||||
// Definitions by: Sven Reglitzki <https://github.com/svi3c/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "sandboxed-module" {
|
||||
|
||||
interface SandboxOptions {
|
||||
/**
|
||||
* An object containing moduleIds and the values to inject for them when required by the sandboxed module.
|
||||
* This does not affect children of the sandboxed module.
|
||||
*/
|
||||
requires?: Object;
|
||||
/**
|
||||
* An object of global variables to inject into the sandboxed module.
|
||||
*/
|
||||
globals?: Object;
|
||||
/**
|
||||
* An object of local variables to inject into the sandboxed module.
|
||||
*/
|
||||
locals?: Object;
|
||||
/**
|
||||
* An object of named functions which will transform the source code required with SandboxedModule.require.
|
||||
* For example, CoffeeScript & istanbul support is implemented with built-in sourceTransformer functions
|
||||
* (see #registerBuiltInSourceTransformer).
|
||||
*
|
||||
* A source transformer receives the source (as it's been transformed thus far) and must return the transformed
|
||||
* source (whether it's changed or unchanged).
|
||||
*
|
||||
* An example source transformer to change all instances of the number "3" to "5" would look like this:
|
||||
*
|
||||
* SandboxedModule.require('../fixture/baz', {
|
||||
* sourceTransformers: {
|
||||
* turn3sInto5s: function(source) {
|
||||
* return source.replace(/3/g,'5');
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
sourceTransformers?: Object;
|
||||
/**
|
||||
* If false, modules that are required by the sandboxed module will not be sandboxed. By default all modules
|
||||
* required by the sandboxedModule will be sandboxed using the same options that were used for the original
|
||||
* sandboxed module.
|
||||
*/
|
||||
singleOnly?: boolean;
|
||||
/**
|
||||
* If false, the source transformers will not be run against modules required by the sandboxed module.
|
||||
* By default it will take the same value as {@link SandboxOptions.singleOnly}.
|
||||
*/
|
||||
sourceTransformersSingleOnly?: boolean;
|
||||
}
|
||||
|
||||
class SandboxedModule {
|
||||
/**
|
||||
* See {@link SandboxOptions.requires}
|
||||
*/
|
||||
required:Object;
|
||||
/**
|
||||
* See {@link SandboxOptions.globals}
|
||||
*/
|
||||
globals:Object;
|
||||
/**
|
||||
* See {@link SandboxOptions.locals}
|
||||
*/
|
||||
locals:Object;
|
||||
/**
|
||||
* See {@link SandboxOptions.sourceTransformers}.
|
||||
*/
|
||||
sourceTransformers:Object;
|
||||
/**
|
||||
* The full path to the module.
|
||||
*/
|
||||
filename:string;
|
||||
/**
|
||||
* The underlaying node.js Module instance.
|
||||
*/
|
||||
module:string;
|
||||
/**
|
||||
* A getter returning the sandboxedModule.module.exports object.
|
||||
*/
|
||||
exports:any;
|
||||
/**
|
||||
* Returns a new SandboxedModule where moduleId is a regular module path / id as you would normally pass into
|
||||
* require(). The new module will be loaded in its own v8 context, but otherwise have access to the normal
|
||||
* node.js environment.
|
||||
*
|
||||
* @param moduleId the ID of the module to load
|
||||
* @param options the loading options
|
||||
*/
|
||||
static load(moduleId:string, options?:SandboxOptions):SandboxedModule
|
||||
|
||||
/**
|
||||
* Identical to {@link SandboxedModule.load()}, but returns sandboxedModule.exports directly.
|
||||
*
|
||||
* @param moduleId the ID of the module to require
|
||||
* @param options the requiring options
|
||||
*/
|
||||
static require(moduleId:string, options?:SandboxOptions):any
|
||||
}
|
||||
|
||||
export = SandboxedModule;
|
||||
}
|
||||
Reference in New Issue
Block a user