
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
monaco-worker-manager
Advanced tools
A Monaco worker manager handles workers in a type safe manner.
This project has a peer dependency on monaco-editor. It’s recommded to add it explicitly.
npm install monaco-editor monaco-editor-manager
Create a module that contains a Monaco web worker, let’s call it my.worker.ts.
import { initialize } from 'monaco-worker-manager/worker';
import { doValidate } from 'my-language-service';
export interface MyWorker {
doValidate: (uri: string) => Violation[];
}
initialize<MyWorker>((ctx, options) => {
function getModel(uri: string): worker.IMirrorModel | undefined {
for (const model of ctx.getMirrorModels()) {
if (String(model.uri) === uri) {
return model;
}
}
}
return {
doValidate(uri) {
const model = getModel(uri);
if (!model) {
return [];
}
return doValidate(model, options);
},
};
});
Now create a monaco environment and create a worker manager in the main thread:
import { editor, Uri } from 'monaco-editor';
import { createWorkerManager } from 'monaco-worker-manager';
import { MyWorker } from './my.worker';
const myLabel = 'myLabel';
const myModuleId = 'my.worker';
window.MonacoEnvironment = {
getWorker(moduleId, label) {
switch (label) {
case 'editorWorkerService':
return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker', import.meta.url));
case myLabel:
return new Worker(new URL('my.worker', import.meta.url));
default:
throw new Error(`Unknown label ${label}`);
}
},
};
const workerManager = createWorkerManager<MyWorker>({
label: myLabel,
moduleId: myModuleId,
});
const model = editor.createModel('Hello Monaco!', 'plaintext', Uri.parse('file:///hello.txt'));
async function main(): Promise<void> {
const worker = await workerManager.getWorker(model.uri);
const diagnostics = await worker.doValidate(String(model.uri));
console.log(diagnostics);
}
main();
This project exposes 2 modules: one to use in the main thread, another to create your own worker.
monaco-worker-manager#createWorkerManager(options)Create a worker manager.
A worker manager is an object which deals with Monaco based web workers, such as cleanups and idle timeouts.
options.createData: The data to send over when creating the worker. (Optional)options.interval How often to check if a worker is idle in milliseconds. (Optional, default:
30_000)options.label: A label to be used to identify the web worker.options.moduleId: The module id to be used to identify the web worker.options.stopWhenIdleFor: The worker is stopped after this time has passed in milliseconds. Set
to Infinity to never stop the worker. (Optional, default: 120_000)A disposable object with the following keys:
getWorker(...resources: Uri[]): An unbound method for getting the web worker.updateCreateData(newCreateData): An unbound method which updates the create data and reloads the
worker.monaco-worker-manager/worker#initialize(fn)Create a web worker in a type safe manner.
The function will be called with the following arguments:
FAQs
Easily deal with monaco workers
We found that monaco-worker-manager 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.