vite-node
Advanced tools
Comparing version 0.0.141 to 0.0.142
@@ -25,3 +25,4 @@ declare type FetchFunction = (id: string) => Promise<{ | ||
constructor(options: ViteNodeRunnerOptions); | ||
run(file: string): Promise<any>; | ||
executeFile(file: string): Promise<any>; | ||
executeId(id: string): Promise<any>; | ||
cachedRequest(rawId: string, callstack: string[]): Promise<any>; | ||
@@ -28,0 +29,0 @@ directRequest(id: string, fsPath: string, callstack: string[]): Promise<any>; |
@@ -76,4 +76,4 @@ import minimist from 'minimist'; | ||
for (const file of files) | ||
await runner.run(file); | ||
await runner.executeFile(file); | ||
await server.close(); | ||
} |
@@ -5,3 +5,3 @@ import { builtinModules, createRequire } from 'module'; | ||
import { resolve, dirname } from 'pathe'; | ||
import { slash, normalizeId, toFilePath } from './utils.js'; | ||
import { slash, normalizeId, toFilePath, isPrimitive } from './utils.js'; | ||
@@ -16,5 +16,8 @@ class ViteNodeRunner { | ||
} | ||
async run(file) { | ||
async executeFile(file) { | ||
return await this.cachedRequest(`/@fs/${slash(resolve(file))}`, []); | ||
} | ||
async executeId(id) { | ||
return await this.cachedRequest(id, []); | ||
} | ||
async cachedRequest(rawId, callstack) { | ||
@@ -103,3 +106,3 @@ var _a, _b; | ||
const result = Reflect[name](target, key, ...args); | ||
if (typeof target.default !== "object") | ||
if (isPrimitive(target.default)) | ||
return result; | ||
@@ -106,0 +109,0 @@ if (tryDefault && key === "default" || typeof result === "undefined") |
@@ -13,2 +13,5 @@ import { fileURLToPath, pathToFileURL } from 'url'; | ||
} | ||
function isPrimitive(v) { | ||
return v !== Object(v); | ||
} | ||
function toFilePath(id, root) { | ||
@@ -21,2 +24,2 @@ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname(root)) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id; | ||
export { isWindows, normalizeId, slash, toFilePath }; | ||
export { isPrimitive, isWindows, normalizeId, slash, toFilePath }; |
{ | ||
"name": "vite-node", | ||
"version": "0.0.141", | ||
"version": "0.0.142", | ||
"description": "Vite as Node.js runtime", | ||
@@ -66,3 +66,3 @@ "homepage": "https://github.com/vitest-dev/vitest#readme", | ||
}, | ||
"readme": "# vite-node\n\n[![NPM version](https://img.shields.io/npm/v/vite-node?color=a1b858&label=)](https://www.npmjs.com/package/vite-node)\n\nVite as Node runtime. The engine powers [Vitest](https://github.com/vitest-dev/vitest).\n\n## Features\n\n- Out-of-box ESM & TypeScript support (possible for more with plugins)\n- Top-level await\n- Vite plugins, resolve, aliasing\n- Respect `vite.config.ts`\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## 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 the server and running in the same context\n\n```ts\nimport { createServer } from 'vite'\nimport { ViteNodeServer } from 'vite-node/server'\nimport { ViteNodeRunner } from 'vite-node/client'\n\n// create vite server\nconst server = await createServer()\n// this is need to initialize the plugins\nawait server.pluginContainer.buildStart({})\n\n// create vite-node server\nconst node = new ViteNodeServer(server)\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})\n\n// execute the file\nawait runner.run('./example.ts')\n\n// close the vite server\nawait server.close()\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'/>\n </a>\n</p>\n\n## License\n\n[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)\n" | ||
"readme": "# vite-node\n\n[![NPM version](https://img.shields.io/npm/v/vite-node?color=a1b858&label=)](https://www.npmjs.com/package/vite-node)\n\nVite as Node runtime. The engine powers [Vitest](https://github.com/vitest-dev/vitest).\n\n## Features\n\n- Out-of-box ESM & TypeScript support (possible for more with plugins)\n- Top-level await\n- Vite plugins, resolve, aliasing\n- Respect `vite.config.ts`\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## 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 the server and running in the same context\n\n```ts\nimport { createServer } from 'vite'\nimport { ViteNodeServer } from 'vite-node/server'\nimport { ViteNodeRunner } from 'vite-node/client'\n\n// create vite server\nconst server = await createServer()\n// this is need to initialize the plugins\nawait server.pluginContainer.buildStart({})\n\n// create vite-node server\nconst node = new ViteNodeServer(server)\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})\n\n// execute the file\nawait runner.executeFile('./example.ts')\n\n// close the vite server\nawait server.close()\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'/>\n </a>\n</p>\n\n## License\n\n[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)\n" | ||
} |
@@ -60,3 +60,3 @@ # vite-node | ||
// execute the file | ||
await runner.run('./example.ts') | ||
await runner.executeFile('./example.ts') | ||
@@ -63,0 +63,0 @@ // close the vite server |
declare const isWindows: boolean; | ||
declare function slash(str: string): string; | ||
declare function normalizeId(id: string, base?: string): string; | ||
declare function isPrimitive(v: any): boolean; | ||
declare function toFilePath(id: string, root: string): string; | ||
export { isWindows, normalizeId, slash, toFilePath }; | ||
export { isPrimitive, isWindows, normalizeId, slash, toFilePath }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23172
497