vite-node 0.28.4 → 0.28.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,6 +48,32 @@ npx vite-node --options.deps.inline="module-name" --options.deps.external="/modu
48
48
 
49
49
  Note that for options supporting RegExps, strings passed to the CLI must start _and_ end with a `/`;
50
50
 
51
+ ### Hashbang
52
+
53
+ If 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).
54
+
55
+ Simply add `#!/usr/bin/env vite-node --script` at the top of your file:
56
+
57
+ _file.ts_
58
+ ```ts
59
+ #!/usr/bin/env vite-node --script
60
+
61
+ console.log('argv:', process.argv.slice(2))
62
+ ```
63
+
64
+ And make the file executable:
65
+ ```sh
66
+ chmod +x ./file.ts
67
+ ```
68
+
69
+ Now, you can run the file without passing it into Vite Node:
70
+ ```sh
71
+ $ ./file.ts hello
72
+ argv: [ 'hello' ]
73
+ ```
74
+
75
+ Note 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.
76
+
51
77
  ## Programmatic Usage
52
78
 
53
79
  In 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
package/dist/cli.cjs CHANGED
@@ -6,8 +6,8 @@ var vite = require('vite');
6
6
  var server = require('./server.cjs');
7
7
  var client = require('./client.cjs');
8
8
  var utils = require('./utils.cjs');
9
- var hmr = require('./chunk-hmr.cjs');
10
9
  var sourceMap = require('./source-map.cjs');
10
+ var hmr = require('./chunk-hmr.cjs');
11
11
  require('perf_hooks');
12
12
  require('pathe');
13
13
  require('debug');
@@ -25,20 +25,26 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
25
25
  var cac__default = /*#__PURE__*/_interopDefaultLegacy(cac);
26
26
  var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
27
27
 
28
- var version = "0.28.4";
28
+ var version = "0.28.5";
29
29
 
30
30
  const cli = cac__default["default"]("vite-node");
31
- cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
32
- cli.command("[...files]").action(run);
31
+ cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").help();
32
+ cli.command("[...files]").allowUnknownOptions().action(run);
33
33
  cli.parse();
34
34
  async function run(files, options = {}) {
35
35
  var _a;
36
+ if (options.script) {
37
+ files = [files[0]];
38
+ options = {};
39
+ process.argv = [process.argv[0], files[0], ...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])];
40
+ } else {
41
+ process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
42
+ }
36
43
  if (!files.length) {
37
44
  console.error(c__default["default"].red("No files specified."));
38
45
  cli.outputHelp();
39
46
  process.exit(1);
40
47
  }
41
- process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
42
48
  const serverOptions = options.options ? parseServerOptions(options.options) : {};
43
49
  const server$1 = await vite.createServer({
44
50
  logLevel: "error",
package/dist/cli.d.ts CHANGED
@@ -2,6 +2,7 @@ import { e as ViteNodeServerOptions } from './types-63205a44.js';
2
2
 
3
3
  interface CliOptions {
4
4
  root?: string;
5
+ script?: boolean;
5
6
  config?: string;
6
7
  watch?: boolean;
7
8
  options?: ViteNodeServerOptionsCLI;
package/dist/cli.mjs CHANGED
@@ -18,20 +18,26 @@ import 'node:path';
18
18
  import 'node:vm';
19
19
  import 'node:events';
20
20
 
21
- var version = "0.28.4";
21
+ var version = "0.28.5";
22
22
 
23
23
  const cli = cac("vite-node");
24
- cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
25
- cli.command("[...files]").action(run);
24
+ cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").help();
25
+ cli.command("[...files]").allowUnknownOptions().action(run);
26
26
  cli.parse();
27
27
  async function run(files, options = {}) {
28
28
  var _a;
29
+ if (options.script) {
30
+ files = [files[0]];
31
+ options = {};
32
+ process.argv = [process.argv[0], files[0], ...process.argv.slice(2).filter((arg) => arg !== "--script" && arg !== files[0])];
33
+ } else {
34
+ process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
35
+ }
29
36
  if (!files.length) {
30
37
  console.error(c.red("No files specified."));
31
38
  cli.outputHelp();
32
39
  process.exit(1);
33
40
  }
34
- process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
35
41
  const serverOptions = options.options ? parseServerOptions(options.options) : {};
36
42
  const server = await createServer({
37
43
  logLevel: "error",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.28.4",
3
+ "version": "0.28.5",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",