![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@bestest/node-module-sandbox
Advanced tools
This module is trying to separate node modules creation in selected context, without touching i.e. regular require
cache.
Warning: Remember, you should not treat this as a safe sandbox solution! It is also changing some default behaviors, so you may treat is as a buggy as well.
// fn.js
exports.fn = () => 3
// main.js
const { NodeModuleSandbox } = require('@bestest/node-module-sandbox')
const sandbox1 = new NodeModuleSandbox()
const sandbox2 = new NodeModuleSandbox()
// Modify fn.js module in "sandbox1"
sandbox1.executeScript('require("./fn").fn = () => 5')
// Verify that './fn' has been modified in "sandbox1"
console.log(sandbox1.executeScript('require("./fn").fn()')) // 5
// Verify that './fn' has been modified in "sandbox2"
console.log(sandbox2.executeScript('require("./fn").fn()')) // 3
// Verify that './fn' has not been modified locally
console.log(require('./fn').fn()) // 3
const { NodeModuleSandbox } = require('@bestest/node-module-sandbox')
const sandbox = new NodeModuleSandbox()
// Remember that this function will be serialized,
// so you should not use anything from outside of its context.
const fn = (callback) => {
setTimeout(() => {
callback(10)
}, 1000)
}
// Remember that this function will be serialized,
// so you should not use anything from outside of its context.
const fn2 = (x, y, z) => {
console.log('Sum:', x + y + z)
}
sandbox.executeScriptWithArguments(fn, value => {
console.log('The value is', value)
})
sandbox.executeScriptWithArguments(fn2, 1, 2, 3)
const { FileSystem } = require('@bestest/fs')
const { NodeModuleSandbox } = require('@bestest/node-module-sandbox')
const fileSystem = new FileSystem()
fileSystem.setLocalFile('./fixture.json', '"text"')
fileSystem.setLocalFile('./example.js', `
module.exports = {
root: "/root/"
}
`)
fileSystem.setLocalFile('./a.js', `
// File system can be mocked as well
const fs = require('fs')
const fixture = JSON.parse(fs.readFileSync('./fixture.json'))
console.log(require('./example').root + fixture) // "/root/text"
`)
const sandbox = new NodeModuleSandbox({
modules: { fs: fileSystem.fs }
})
sandbox.requireModule('./a.js', module) // logs "/root/text"
sandbox.requireModule('./a.js', module) // does nothing - this module is already resolved
sandbox.executeScript('require("./a.js")') // does nothing - this module is already resolved
Due to the way it is resolved, there are some differences in behavior:
.js
and .json
files will be loaded without any registered extension handlers (i.e. ts-node
or @babel/register
)Module context (module
, require
, __dirname
, __filename
) will be replaced, but other global objects will still be the same.
Unfortunately, there is no API yet available to access and modify ESMLoader.
FAQs
Sandbox Node.js modules along with require function
The npm package @bestest/node-module-sandbox receives a total of 4 weekly downloads. As such, @bestest/node-module-sandbox popularity was classified as not popular.
We found that @bestest/node-module-sandbox demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.