Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@yonib05/workerize-loader
Advanced tools
Automatically move a module into a Web Worker (Webpack loader)
A webpack loader that moves a module and its dependencies into a Web Worker, automatically reflecting exported functions as asynchronous proxies.
Worker
npm install -D workerize-loader
worker.js:
// block for `time` ms, then return the number of loops we could run in that time:
export function expensive(time) {
let start = Date.now(),
count = 0
while (Date.now() - start < time) count++
return count
}
index.js: (our demo)
import worker from 'workerize-loader!./worker'
let instance = worker() // `new` is optional
instance.expensive(1000).then( count => {
console.log(`Ran ${count} loops`)
})
inline
Type: Boolean
Default: false
You can also inline the worker as a BLOB with the inline
parameter
// webpack.config.js
{
loader: 'workerize-loader',
options: { inline: true }
}
or
import worker from 'workerize-loader?inline!./worker'
If you're using Babel in your build, make sure you disabled commonJS transform. Otherwize, workerize-loader won't be able to retrieve the list of exported function from your worker script :
{
test: /\.js$/,
loader: "babel-loader",
options: {
presets: [
[
"env",
{
modules: false,
},
],
]
}
}
The inner workings here are heavily inspired by worker-loader. It's worth a read!
FAQs
Automatically move a module into a Web Worker (Webpack loader)
The npm package @yonib05/workerize-loader receives a total of 1 weekly downloads. As such, @yonib05/workerize-loader popularity was classified as not popular.
We found that @yonib05/workerize-loader 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.