Skip to content

Commit

Permalink
feat: default pathContext to sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed May 10, 2023
1 parent cbd42bc commit e085219
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/nodevm.js
Expand Up @@ -18,12 +18,12 @@
*/

/**
* This callback will be called to specify the context to use "per" module.
* This callback will be called to specify the context to use "per" module. Defaults to 'sandbox' if no return value provided.
*
* NOTE: many interoperating modules must live in the same context.
*
* @callback pathContextCallback
* @param {string} moduleName - Name of the module requested.
* @param {string} modulePath - The full path to the module filename being requested.
* @param {string} extensionType - The type of extension (node, js, json)
* @return {("host"|"sandbox")} The context for this module.
*/
Expand Down Expand Up @@ -191,7 +191,7 @@ class NodeVM extends VM {
* @param {("host"|"sandbox"|pathContextCallback)} [options.require.context="host"] -
* <code>host</code> to require modules in host and proxy them to sandbox.
* <code>sandbox</code> to load, compile and require modules in sandbox.
* <code>pathContext(module, ext)</code> to choose a mode per module.
* <code>pathContext(modulePath, ext)</code> to choose a mode per module (full path provided).
* Builtin modules except <code>events</code> always required in host and proxied to sandbox.
* @param {string[]} [options.require.import] - Array of modules to be loaded into NodeVM on start.
* @param {resolveCallback} [options.require.resolve] - An additional lookup function in case a module wasn't
Expand Down
2 changes: 1 addition & 1 deletion lib/resolver-compat.js
Expand Up @@ -332,7 +332,7 @@ function resolverFromOptions(vm, options, override, compiler) {
};
}

const pathContext = typeof options.context === 'function' ? ((module, ext) => options.context(module, ext) || 'host') : (() => context);
const pathContext = typeof options.context === 'function' ? ((module, ext) => options.context(module, ext) || 'sandbox') : (() => context);

if (typeof externalOpt !== 'object') {
return new DefaultResolver(fsOpt, builtins, checkPath, [], pathContext, newCustomResolver, hostRequire, compiler, strict);
Expand Down

0 comments on commit e085219

Please sign in to comment.