{"id":19746788,"url":"https://github.com/cweili/vm-worker","last_synced_at":"2026-03-09T16:42:45.326Z","repository":{"id":39249863,"uuid":"501129942","full_name":"Cweili/vm-worker","owner":"Cweili","description":"Tiny virtual machine for browser to execute javascript modules in Web Worker","archived":false,"fork":false,"pushed_at":"2024-10-07T22:01:51.000Z","size":61,"stargazers_count":8,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T08:48:11.509Z","etag":null,"topics":["browser","esm","esmodules","exec","execute","javascript","typescript","virtual-machine","vm","webworker","webworkers"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cweili.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-08T06:39:06.000Z","updated_at":"2025-02-14T06:10:19.000Z","dependencies_parsed_at":"2024-07-10T09:52:55.040Z","dependency_job_id":"5e0bd302-3fbe-40bb-af54-8d79a162d31d","html_url":"https://github.com/Cweili/vm-worker","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":0.09433962264150941,"last_synced_commit":"37d9c6037612e4232bf8b9085f1dc760996fb5cb"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/Cweili/vm-worker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cweili%2Fvm-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cweili%2Fvm-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cweili%2Fvm-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cweili%2Fvm-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cweili","download_url":"https://codeload.github.com/Cweili/vm-worker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cweili%2Fvm-worker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271745693,"owners_count":24813516,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","esm","esmodules","exec","execute","javascript","typescript","virtual-machine","vm","webworker","webworkers"],"created_at":"2024-11-12T02:15:55.303Z","updated_at":"2025-09-19T20:12:52.056Z","avatar_url":"https://github.com/Cweili.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# VM Worker\n\n[![npm][badge-version]][npm]\n[![bundle size][badge-size]][bundlephobia]\n[![npm downloads][badge-downloads]][npm]\n[![license][badge-license]][license]\n\n[![github][badge-issues]][github]\n[![build][badge-build]][workflows]\n[![coverage][badge-coverage]][coveralls]\n\nTiny virtual machine for browser to execute javascript modules in Web Worker.\n\n## Features\n\n- Run code in a isolated scope without pollute your environment\n- Support CommonJS and ESModules (by plugin)\n- Support TypeScript and Flow (by plugin)\n- Based on Web Worker\n\n## Usage\n\n### Basic usage\n\nApp.js\n\n```js\nimport VM from 'vm-worker'\n\nconst vm = VM({\n  debug: false, // default false\n  timeout: 100000, // default 100000ms\n})\n\nawait vm.require([\n  {\n    path: 'module-one/index.js',\n    src: 'module.exports = 1',\n  },\n  {\n    path: '/dirA/a.js',\n    url: 'https://xxx.com/a.js',\n  },\n  {\n    path: '/dirB/b.js',\n    src: 'module.exports = require(\"../dirA/a\")',\n  },\n])\n\nawait vm.exec('/dirB/b.js', 1, 2) // =\u003e 4\n\nvm.terminate()\n```\n\na.js\n\n```js\nmodule.exports = (a, b) =\u003e (a + b + require('module-one'))\n```\n\n### ESModule Plugin\n\nApp.js\n\n```js\nimport VM from 'vm-worker'\nimport ESMPlugin from 'vm-worker/dist/plugins/esmodule.esm'\n\nconst vm = VM({\n  plugins: [\n    ESMPlugin(),\n  ],\n})\n\nawait vm.require([\n  {\n    path: 'module-one/index.js',\n    src: `export const ONE = 1`\n  },\n  {\n    path: '/dirA/a.js',\n    url: 'https://xxx.com/a.js',\n  },\n  {\n    path: '/dirB/b.js',\n    src: `import { plus } from \"../dirA/a\"\n          export default plus`,\n  },\n])\n\nawait vm.exec('/dirB/b.js', 1, 2) // =\u003e 4\n\nvm.terminate()\n```\n\na.js\n\n```js\nimport { ONE } from 'module-one'\n\nexport function plus(a, b) {\n  return a + b + ONE\n}\n```\n\n### Sucrase plugin\n\nSucrase is similar to Babel, which compiles TypeScript, Flow and JSX to standard JavaScript.\n\n[Sucrase transform options document](https://github.com/alangpierce/sucrase#transforms)\n\nApp.js\n\n```ts\nimport VM from 'vm-worker'\nimport SucrasePlugin from 'vm-worker/dist/plugins/sucrase.esm'\n\nconst vm = VM({\n  plugins: [\n    SucrasePlugin({\n      ... // Sucrase transform options\n    }),\n  ],\n})\n\nawait vm.require([\n  {\n    path: 'module-one/index.js',\n    src: `export const ONE: number = 1`\n  },\n  {\n    path: '/dirA/a.js',\n    url: 'https://xxx.com/a.js',\n  },\n  {\n    path: '/dirB/b.js',\n    src: `import { plus } from \"../dirA/a\"\n          export default plus`,\n  },\n])\n\nawait vm.exec('/dirB/b.js', 1, 2) // =\u003e 4\n\nvm.terminate()\n```\n\na.js\n\n```ts\nimport { ONE } from 'module-one'\n\nexport function plus(a: number, b: number) {\n  return a + b + ONE\n}\n```\n\n## Installation\n\n```sh\nnpm i vm-worker\n```\n\n[badge-version]: https://img.shields.io/npm/v/vm-worker.svg\n[badge-downloads]: https://img.shields.io/npm/dt/vm-worker.svg\n[npm]: https://www.npmjs.com/package/vm-worker\n\n[badge-size]: https://img.shields.io/bundlephobia/minzip/vm-worker.svg\n[bundlephobia]: https://bundlephobia.com/result?p=vm-worker\n\n[badge-license]: https://img.shields.io/npm/l/vm-worker.svg\n[license]: https://github.com/Cweili/vm-worker/blob/master/LICENSE\n\n[badge-issues]: https://img.shields.io/github/issues/Cweili/vm-worker.svg\n[github]: https://github.com/Cweili/vm-worker\n\n[badge-build]: https://img.shields.io/github/actions/workflow/status/Cweili/vm-worker/ci.yml?branch=master\n[workflows]: https://github.com/Cweili/vm-worker/actions/workflows/ci.yml?query=branch%3Amaster\n\n[badge-coverage]: https://img.shields.io/coveralls/github/Cweili/vm-worker/master.svg\n[coveralls]: https://coveralls.io/github/Cweili/vm-worker?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcweili%2Fvm-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcweili%2Fvm-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcweili%2Fvm-worker/lists"}