vite-node 0.28.3 → 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 +26 -0
- package/dist/chunk-hmr.cjs +1 -0
- package/dist/chunk-hmr.mjs +1 -0
- package/dist/cli.cjs +10 -4
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +10 -4
- package/dist/client.cjs +6 -2
- package/dist/client.mjs +6 -2
- package/package.json +1 -1
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/chunk-hmr.cjs
CHANGED
|
@@ -148,6 +148,7 @@ async function handleMessage(runner, emitter, files, payload) {
|
|
|
148
148
|
break;
|
|
149
149
|
case "full-reload":
|
|
150
150
|
notifyListeners(runner, "vite:beforeFullReload", payload);
|
|
151
|
+
maps.customListenersMap.delete("vite:beforeFullReload");
|
|
151
152
|
reload(runner, files);
|
|
152
153
|
break;
|
|
153
154
|
case "prune":
|
package/dist/chunk-hmr.mjs
CHANGED
|
@@ -141,6 +141,7 @@ async function handleMessage(runner, emitter, files, payload) {
|
|
|
141
141
|
break;
|
|
142
142
|
case "full-reload":
|
|
143
143
|
notifyListeners(runner, "vite:beforeFullReload", payload);
|
|
144
|
+
maps.customListenersMap.delete("vite:beforeFullReload");
|
|
144
145
|
reload(runner, files);
|
|
145
146
|
break;
|
|
146
147
|
case "prune":
|
package/dist/cli.cjs
CHANGED
|
@@ -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.
|
|
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
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.
|
|
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/dist/client.cjs
CHANGED
|
@@ -192,8 +192,6 @@ class ViteNodeRunner {
|
|
|
192
192
|
if (importee && id.startsWith(utils.VALID_ID_PREFIX))
|
|
193
193
|
importee = void 0;
|
|
194
194
|
id = utils.normalizeRequestId(id, this.options.base);
|
|
195
|
-
if (!id.startsWith("/") && !id.startsWith("./") && !id.startsWith("../"))
|
|
196
|
-
importee = void 0;
|
|
197
195
|
if (!this.shouldResolveId(id))
|
|
198
196
|
return [id, id];
|
|
199
197
|
const { path, exists } = utils.toFilePath(id, this.root);
|
|
@@ -266,6 +264,12 @@ ${getStack()}`), 2e3);
|
|
|
266
264
|
configurable: false
|
|
267
265
|
});
|
|
268
266
|
const cjsExports = new Proxy(exports, {
|
|
267
|
+
get: (target, p, receiver) => {
|
|
268
|
+
if (Reflect.has(target, p))
|
|
269
|
+
return Reflect.get(target, p, receiver);
|
|
270
|
+
return Reflect.get(Object.prototype, p, receiver);
|
|
271
|
+
},
|
|
272
|
+
getPrototypeOf: () => Object.prototype,
|
|
269
273
|
set: (_, p, value) => {
|
|
270
274
|
if (p === "default" && this.shouldInterop(modulePath, { default: value })) {
|
|
271
275
|
exportAll(cjsExports, value);
|
package/dist/client.mjs
CHANGED
|
@@ -165,8 +165,6 @@ class ViteNodeRunner {
|
|
|
165
165
|
if (importee && id.startsWith(VALID_ID_PREFIX))
|
|
166
166
|
importee = void 0;
|
|
167
167
|
id = normalizeRequestId(id, this.options.base);
|
|
168
|
-
if (!id.startsWith("/") && !id.startsWith("./") && !id.startsWith("../"))
|
|
169
|
-
importee = void 0;
|
|
170
168
|
if (!this.shouldResolveId(id))
|
|
171
169
|
return [id, id];
|
|
172
170
|
const { path, exists } = toFilePath(id, this.root);
|
|
@@ -239,6 +237,12 @@ ${getStack()}`), 2e3);
|
|
|
239
237
|
configurable: false
|
|
240
238
|
});
|
|
241
239
|
const cjsExports = new Proxy(exports, {
|
|
240
|
+
get: (target, p, receiver) => {
|
|
241
|
+
if (Reflect.has(target, p))
|
|
242
|
+
return Reflect.get(target, p, receiver);
|
|
243
|
+
return Reflect.get(Object.prototype, p, receiver);
|
|
244
|
+
},
|
|
245
|
+
getPrototypeOf: () => Object.prototype,
|
|
242
246
|
set: (_, p, value) => {
|
|
243
247
|
if (p === "default" && this.shouldInterop(modulePath, { default: value })) {
|
|
244
248
|
exportAll(cjsExports, value);
|