From dfc31cb156bfe041f37b2043cd943b388c835c0c Mon Sep 17 00:00:00 2001 From: Sven Reglitzki Date: Sun, 20 Mar 2016 09:00:31 +0100 Subject: [PATCH] Add some static methods to sandboxed-module --- sandboxed-module/sandboxed-module-tests.ts | 6 ++++++ sandboxed-module/sandboxed-module.d.ts | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/sandboxed-module/sandboxed-module-tests.ts b/sandboxed-module/sandboxed-module-tests.ts index 6f115ad2c..f70279178 100644 --- a/sandboxed-module/sandboxed-module-tests.ts +++ b/sandboxed-module/sandboxed-module-tests.ts @@ -10,6 +10,12 @@ import SandboxedModule = require("sandboxed-module"); var sandboxedModule:SandboxedModule = SandboxedModule.load("foo"); var sandboxedModuleExports:any = SandboxedModule.require("foo"); +SandboxedModule.configure({ + globals: {Math} +}); + +SandboxedModule.registerBuiltInSourceTransformer("coffee"); + var sandboxedModuleExportsWithOptions:any = SandboxedModule.require("foo", { requires: { someDep: {} diff --git a/sandboxed-module/sandboxed-module.d.ts b/sandboxed-module/sandboxed-module.d.ts index d67932f4d..55290cbc7 100644 --- a/sandboxed-module/sandboxed-module.d.ts +++ b/sandboxed-module/sandboxed-module.d.ts @@ -97,6 +97,24 @@ declare module "sandboxed-module" { * @param options the requiring options */ static require(moduleId:string, options?:SandboxOptions):any + /** + * Sets options globally across all uses of {@link SandboxedModule.load()} and {@link SandboxedModule.require()}. + * This way, a commonly needed require, global, local, or sourceTransformer can be specified once across all + * sandboxed modules. + * @param options the loading and requiring default options + */ + static configure(options:SandboxOptions):void + /** + * Enables a built-in source transformer by name. Currently, SandboxedModule ships with two built in source + * transformers: + * * "coffee" - Compiles source with CoffeeScript [Enabled by default for backwards compatibility]. + * Be sure to run require('coffee-script').register() or require('coffee-script/register') as well. + * * "istanbul" - Instruments sources via istanbul when istanbul code coverage is running. + * For example, if you'd like to use SandboxedModule in conjunction with istanbul, just run + * SandboxedModule.registerBuiltInSourceTransformer('istanbul'). + * @param name The name of the built-in source transformer + */ + static registerBuiltInSourceTransformer(name:String):void } export = SandboxedModule;