Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@surma/rollup-plugin-off-main-thread
Advanced tools
Use Rollup with workers and ES6 modules today.
Use Rollup with workers and ES6 modules today.
$ npm install --save @surma/rollup-plugin-off-main-thread
Workers are JavaScript’s version of threads. Workers are important to use as the main thread is already overloaded, especially on slower or older devices.
This plugin takes care of shimming module support in workers and allows you to use new Worker()
.
OMT is the result of merging loadz0r and workz0r.
I set up a gist to show a full setup with OMT.
// rollup.config.js
import OMT from "@surma/rollup-plugin-off-main-thread";
export default {
input: ["src/main.js"],
output: {
dir: "dist",
// You _must_ use either “amd” or “esm” as your format.
// But note that only very few browsers have native support for
// modules in workers.
format: "amd"
},
plugins: [OMT()]
};
In your project's code use a module-relative path via new URL
to include a Worker:
const worker = new Worker(new URL("worker.js", import.meta.url), {
type: "module"
});
This will just work.
If required, the plugin also supports plain literal paths:
const worker = new Worker("./worker.js", { type: "module" });
However, those are less portable: in Rollup they would result in module-relative path, but if used directly in the browser, they'll be relative to the document URL instead.
Hence, they're deprecated and new URL
pattern is encouraged instead for portability.
If your worker constructor doesn't match workerRegexp
(see options below), you might find it easier to import the worker as a URL. In your project's code:
import workerURL from "omt:./worker.js";
import paintWorkletURL from "omt:./paint-worklet.js";
const worker = new Worker(workerURL, { name: "main-worker" });
CSS.paintWorklet.addModule(paintWorkletURL);
./worker.js
and ./paint-worklet.js
will be added to the output as chunks.
{
// ...
plugins: [OMT(options)];
}
loader
: A string containing the EJS template for the amd loader. If undefined
, OMT will use loader.ejs
.useEval
: Use fetch()
+ eval()
to load dependencies instead of <script>
tags and importScripts()
. This is not CSP compliant, but is required if you want to use dynamic imports in ServiceWorker.workerRegexp
: A RegExp to find new Workers()
calls. The second capture group must capture the provided file name without the quotes.amdFunctionName
: Function name to use instead of AMD’s define
.prependLoader
: A function that determines whether the loader code should be prepended to a certain chunk. Should return true if the load is suppsoed to be prepended.urlLoaderScheme
: Scheme to use when importing workers as URLs. If undefined
, OMT will use "omt"
.License Apache-2.0
FAQs
Use Rollup with workers and ES6 modules today.
The npm package @surma/rollup-plugin-off-main-thread receives a total of 2,739,266 weekly downloads. As such, @surma/rollup-plugin-off-main-thread popularity was classified as popular.
We found that @surma/rollup-plugin-off-main-thread demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.