{"name":"vite-node","version":"2.1.7","author":{"name":"Anthony Fu","email":"anthonyfu117@hotmail.com"},"license":"MIT","_id":"vite-node@2.1.7","maintainers":[{"name":"antfu","email":"anthonyfu117@hotmail.com"},{"name":"patak","email":"hey.patak@gmail.com"},{"name":"oreanno","email":"foxzdavinci@gmail.com"},{"name":"vitestbot","email":"vitest.dev@gmail.com"}],"homepage":"https://github.com/vitest-dev/vitest/blob/main/packages/vite-node#readme","bugs":{"url":"https://github.com/vitest-dev/vitest/issues"},"bin":{"vite-node":"vite-node.mjs"},"dist":{"shasum":"58bc9babc570ddf9cfbb2272d6d8d73ca28d139d","tarball":"http://registry-npm.ywwl.com/vite-node/download/vite-node-2.1.7.tgz","fileCount":37,"integrity":"sha512-b/5MxSWd0ftWt1B1LHfzCw0ASzaxHztUwP0rcsBhkDSGy9ZDEDieSIjFG3I78nI9dUN0eSeD6LtuKPZGjwwpZQ==","signatures":[{"sig":"MEQCIDuA4VWFXx+PyEJhHPAyuJhm2YuC0OUOWwdMNPr9o0FrAiAbxGA6067O+j4liYES3X9P4sbTir/6QhRGdmbWOe5dYg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/vite-node@2.1.7","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":204304,"size":56846,"noattachment":false,"key":"/vite-node/-/vite-node-2.1.7.tgz"},"main":"./dist/index.mjs","type":"module","_from":"file:vite-node-2.1.7.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":"^18.0.0 || ^20.0.0 || >=22.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"},"./*":"./*","./hmr":{"types":"./dist/hmr.d.ts","import":"./dist/hmr.mjs","require":"./dist/hmr.cjs"},"./utils":{"types":"./dist/utils.d.ts","import":"./dist/utils.mjs","require":"./dist/utils.cjs"},"./client":{"types":"./dist/client.d.ts","import":"./dist/client.mjs","require":"./dist/client.cjs"},"./server":{"types":"./dist/server.d.ts","import":"./dist/server.mjs","require":"./dist/server.cjs"},"./constants":{"types":"./dist/constants.d.ts","import":"./dist/constants.mjs","require":"./dist/constants.cjs"},"./source-map":{"types":"./dist/source-map.d.ts","import":"./dist/source-map.mjs","require":"./dist/source-map.cjs"}},"funding":"https://opencollective.com/vitest","scripts":{"dev":"rollup -c --watch --watch.include 'src/**' -m inline","build":"rimraf dist && rollup -c","typecheck":"tsc --noEmit"},"_npmUser":{"name":"vitestbot","email":"vitest.dev@gmail.com"},"_resolved":"/tmp/f96a5f8f4b66030fc1166cca3f7c8f6c/vite-node-2.1.7.tgz","_integrity":"sha512-b/5MxSWd0ftWt1B1LHfzCw0ASzaxHztUwP0rcsBhkDSGy9ZDEDieSIjFG3I78nI9dUN0eSeD6LtuKPZGjwwpZQ==","repository":{"url":"git+https://github.com/vitest-dev/vitest.git","type":"git","directory":"packages/vite-node"},"_npmVersion":"10.8.2","description":"Vite as Node.js runtime","directories":{},"sideEffects":false,"_nodeVersion":"20.18.1","dependencies":{"cac":"^6.7.14","vite":"^5.0.0","debug":"^4.3.7","pathe":"^1.1.2","es-module-lexer":"^1.5.4"},"typesVersions":{"*":{"*":["./dist/*","./dist/index.d.ts"]}},"_hasShrinkwrap":false,"devDependencies":{"tinyrainbow":"^1.2.0","@types/debug":"^4.1.12","@jridgewell/trace-mapping":"^0.3.25"},"_npmOperationalInternal":{"tmp":"tmp/vite-node_2.1.7_1733132938798_0.7999773029290431","host":"s3://npm-registry-packages"},"readme":"<p align=\"center\">\n<img src=\"https://raw.githubusercontent.com/antfu-collective/vite-node/refs/heads/main/assets/vite-node.svg\" alt=\"vite-node logo\" height=\"120\">\n</p>\n\n<h1 align=\"center\">\nvite-node\n</h1>\n<p align=\"center\">\nVite as Node runtime.<br>The engine that powers <a href=\"https://github.com/nuxt/nuxt\">Nuxt 3 Dev SSR</a> and <i><a href=\"https://github.com/vitest-dev/vitest/pull/8208\">used to</a></i> power <a href=\"https://github.com/vitest-dev/vitest\">Vitest</a>.\n\n<p>\n<p align=\"center\">\n  <a href=\"https://npmx.dev/package/vite-node\"><img src=\"https://img.shields.io/npm/v/vite-node?color=FCC72B&label=\" alt=\"vite-node\"></a>\n<p>\n\n> [!NOTE]\n> This project is firstly inspired by [Nuxt 3's SSR](https://antfu.me/posts/dev-ssr-on-nuxt) implementation made by [@pi0](https://github.com/pi0), as a PoC. Later, it made [Vitest](https://github.com/vitest-dev/vitest) possible by providing the same pipeline as in Vite. It served the ecosystem well for a few years and later became a more generalized built-in solution as [Vite Environment Module Runner](https://vite.dev/guide/api-environment.html). Vitest has [migrated to the new official solution](https://github.com/vitest-dev/vitest/pull/8208), which means `vite-node` has finished its mission. We will still keep it around for the ecosystem that built around it, but for new projects, please consider using the builtin Vite one instead.\n\n## Features\n\n- On-demand evaluation\n- Vite's pipeline, plugins, resolve, aliasing\n- Out-of-box ESM & TypeScript support\n- Respect `vite.config.ts`\n- Hot module replacement (HMR)\n- Separate server/client architecture\n- Top-level `await`\n- Shims for `__dirname` and `__filename` in ESM\n- Access to native node modules like `fs`, `path`, etc.\n\n## CLI Usage\n\nRun JS/TS file on Node.js using Vite's resolvers and transformers.\n\n```bash\nnpx vite-node index.ts\n```\n\nOptions:\n\n```bash\nnpx vite-node -h\n```\n\n### Options via CLI\n\n[All `ViteNodeServer` options](https://github.com/antfu-collective/vite-node/blob/main/src/types.ts#L92-L111) are supported by the CLI. They may be defined through the dot syntax, as shown below:\n\n```bash\nnpx vite-node --options.deps.inline=\"module-name\" --options.deps.external=\"/module-regexp/\" index.ts\n```\n\nNote that for options supporting RegExps, strings passed to the CLI must start _and_ end with a `/`;\n\n### Hashbang\n\nIf you prefer to write scripts that don't need to be passed into Vite Node, you can declare it in the [hashbang](https://bash.cyberciti.biz/guide/Shebang).\n\nSimply add `#!/usr/bin/env vite-node --script` at the top of your file:\n\n_file.ts_\n\n```ts\n#!/usr/bin/env vite-node --script\n\nconsole.log('argv:', process.argv.slice(2))\n```\n\nAnd make the file executable:\n\n```sh\nchmod +x ./file.ts\n```\n\nNow, you can run the file without passing it into Vite Node:\n\n```sh\n$ ./file.ts hello\nargv: [ 'hello' ]\n```\n\nNote that when using the `--script` option, Vite Node forwards every argument and option to the script to execute, even the one supported by Vite Node itself.\n\n## Programmatic Usage\n\nIn Vite Node, the server and runner (client) are separated, so you can integrate them in different contexts (workers, cross-process, or remote) if needed. The demo below shows a simple example of having both (server and runner) running in the same context\n\n```ts\nimport { createServer, version as viteVersion } from 'vite'\nimport { ViteNodeRunner } from 'vite-node/client'\nimport { ViteNodeServer } from 'vite-node/server'\nimport { installSourcemapsSupport } from 'vite-node/source-map'\n\n// create vite server\nconst server = await createServer({\n  optimizeDeps: {\n    // It's recommended to disable deps optimization\n    noDiscovery: true,\n    include: undefined,\n  },\n})\n\n// For old Vite, this is needed to initialize the plugins.\nif (Number(viteVersion.split('.')[0]) < 6) {\n  await server.pluginContainer.buildStart({})\n}\n\n// create vite-node server\nconst node = new ViteNodeServer(server)\n\n// fixes stacktraces in Errors\ninstallSourcemapsSupport({\n  getSourceMap: source => node.getSourceMap(source),\n})\n\n// create vite-node runner\nconst runner = new ViteNodeRunner({\n  root: server.config.root,\n  base: server.config.base,\n  // when having the server and runner in a different context,\n  // you will need to handle the communication between them\n  // and pass to this function\n  fetchModule(id) {\n    return node.fetchModule(id)\n  },\n  resolveId(id, importer) {\n    return node.resolveId(id, importer)\n  },\n})\n\n// execute the file\nawait runner.executeFile('./example.ts')\n\n// close the vite server\nawait server.close()\n```\n\n## Debugging\n\n### Debug Transformation\n\nSometimes you might want to inspect the transformed code to investigate issues. You can set environment variable `VITE_NODE_DEBUG_DUMP=true` to let vite-node write the transformed result of each module under `.vite-node/dump`.\n\nIf you want to debug by modifying the dumped code, you can change the value of `VITE_NODE_DEBUG_DUMP` to `load` and search for the dumped files and use them for executing.\n\n```bash\nVITE_NODE_DEBUG_DUMP=load vite-node example.ts\n```\n\nOr programmatically:\n\n```js\nimport { ViteNodeServer } from 'vite-node/server'\n\nconst server = new ViteNodeServer(viteServer, {\n  debug: {\n    dumpModules: true,\n    loadDumppedModules: true,\n  },\n})\n```\n\n### Debug Execution\n\nIf the process gets stuck, it might be because there are unresolvable circular dependencies. You can set `VITE_NODE_DEBUG_RUNNER=true` for vite-node to warn about this.\n\n```bash\nVITE_NODE_DEBUG_RUNNER=true vite-node example.ts\n```\n\nOr programmatically:\n\n```js\nimport { ViteNodeRunner } from 'vite-node/client'\n\nconst runner = new ViteNodeRunner({\n  debug: true,\n})\n```\n\n## Credits\n\nBased on [@pi0](https://github.com/pi0)'s brilliant idea of having a Vite server as the on-demand transforming service for [Nuxt's Vite SSR](https://github.com/nuxt/vite/pull/201).\n\nThanks [@brillout](https://github.com/brillout) for kindly sharing this package name.\n\n## Sponsors\n\n<p align=\"center\">\n  <a href=\"https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg\">\n    <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt=\"Sponsors\" />\n  </a>\n</p>\n\n## License\n\n[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)\n","publish_time":1733132938981,"_cnpm_publish_time":1733132938981,"dist-tags":{"beta":"4.0.0-beta.19","latest":"6.0.0"}}