diff --git a/lib/resolver-compat.js b/lib/resolver-compat.js index 06cd7e2..9c74ea0 100644 --- a/lib/resolver-compat.js +++ b/lib/resolver-compat.js @@ -46,8 +46,8 @@ function makeExternalMatcher(obj) { class LegacyResolver extends DefaultResolver { - constructor(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler, externals, allowTransitive) { - super(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler); + constructor(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler, strict, externals, allowTransitive) { + super(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler, strict); this.externals = externals; this.currMod = undefined; this.trustedMods = new WeakMap(); @@ -282,7 +282,8 @@ function resolverFromOptions(vm, options, override, compiler) { root: rootPaths, resolve: customResolver, customRequire: hostRequire = defaultRequire, - context = 'host' + context = 'host', + strict = true, } = options; const builtins = genBuiltinsFromOptions(vm, builtinOpt, mockOpt, override); @@ -325,7 +326,7 @@ function resolverFromOptions(vm, options, override, compiler) { } if (typeof externalOpt !== 'object') { - return new DefaultResolver(builtins, checkPath, [], () => context, newCustomResolver, hostRequire, compiler); + return new DefaultResolver(builtins, checkPath, [], () => context, newCustomResolver, hostRequire, compiler, strict); } let transitive = false; @@ -336,7 +337,7 @@ function resolverFromOptions(vm, options, override, compiler) { transitive = context === 'sandbox' && externalOpt.transitive; } externals = external.map(makeExternalMatcher); - return new LegacyResolver(builtins, checkPath, [], () => context, newCustomResolver, hostRequire, compiler, externals, transitive); + return new LegacyResolver(builtins, checkPath, [], () => context, newCustomResolver, hostRequire, compiler, strict, externals, transitive); } exports.resolverFromOptions = resolverFromOptions; diff --git a/lib/resolver.js b/lib/resolver.js index 7575463..8ff5eb8 100644 --- a/lib/resolver.js +++ b/lib/resolver.js @@ -140,12 +140,13 @@ class Resolver { class DefaultResolver extends Resolver { - constructor(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler) { + constructor(builtinModules, checkPath, globalPaths, pathContext, customResolver, hostRequire, compiler, strict) { super(builtinModules, globalPaths, hostRequire); this.checkPath = checkPath; this.pathContext = pathContext; this.customResolver = customResolver; this.compiler = compiler; + this.strict = strict; this.packageCache = {__proto__: null}; this.scriptCache = {__proto__: null}; } @@ -200,7 +201,7 @@ class DefaultResolver extends Resolver { this.checkAccess(mod, filename); if (this.pathContext(filename, 'js') === 'sandbox') { const script = this.readScript(filename); - vm.run(script, {filename, strict: true, module: mod, wrapper: 'none', dirname: mod.path}); + vm.run(script, {filename, strict: this.strict, module: mod, wrapper: 'none', dirname: mod.path}); } else { const m = this.hostRequire(filename); mod.exports = vm.readonly(m);