Skip to content

Commit ce2a1c7

Browse files
authored
feat(cli): start repl by default and print dzx version on start (#34)
1 parent 607b12a commit ce2a1c7

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/cli/mod.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@ import { VERSION } from "../../version.ts";
22
import { path } from "../runtime/mod.ts";
33
import { bundleCommand } from "./bundle.ts";
44
import { compileCommand } from "./compile.ts";
5-
import {
6-
Command,
7-
DenoLandProvider,
8-
UpgradeCommand,
9-
ValidationError,
10-
} from "./deps.ts";
5+
import { Command, DenoLandProvider, UpgradeCommand } from "./deps.ts";
116
import { addProtocol } from "../_utils.ts";
127
import { evalCommand } from "./eval.ts";
138
import { importModule } from "./lib/bootstrap.ts";
149
import { getModuleFromStdin } from "./lib/stream.ts";
1510
import { getMarkdownModule } from "./lib/markdown.ts";
1611
import { spawnWorker } from "./lib/worker.ts";
17-
import { replCommand } from "./repl.ts";
12+
import { repl, replCommand } from "./repl.ts";
1813

1914
export function dzx() {
2015
return new Command()
@@ -62,9 +57,21 @@ export function dzx() {
6257
"Allow file system write access.",
6358
{ depends: ["worker"] },
6459
)
60+
.option(
61+
"--compat",
62+
"Node compatibility mode. Currently only enables built-in node modules like 'fs' and globals like 'process'.",
63+
)
64+
.option(
65+
"--inspect <host:string>",
66+
"Activate inspector on host:port. (default: 127.0.0.1:9229)",
67+
)
68+
.option(
69+
"--inspect-brk <host:string>",
70+
"Activate inspector on host:port and break at start of user script.",
71+
)
6572
.option(
6673
"-w, --worker",
67-
"Run script in an isolated web worker with it's own permissions.",
74+
"Run script in an isolated web worker with it's own permissions. (experimental)",
6875
)
6976
.option(
7077
"-v, --verbose",
@@ -83,12 +90,13 @@ export function dzx() {
8390
.stopEarly()
8491
.action(
8592
async (
86-
{ worker, verbose, ...perms },
93+
{ worker, verbose, ...options },
8794
script?: string,
8895
args: Array<string> = [],
8996
) => {
9097
if (!script && Deno.isatty(Deno.stdin.rid)) {
91-
throw new ValidationError(`Missing argument(s): script`);
98+
await repl({ ...options, verbose });
99+
return;
92100
}
93101

94102
let mainModule: string;
@@ -103,7 +111,7 @@ export function dzx() {
103111

104112
if (worker) {
105113
spawnWorker({
106-
perms,
114+
perms: options,
107115
mainModule,
108116
args,
109117
verbose,

src/cli/repl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { VERSION } from "../../version.ts";
12
import { error } from "../_utils.ts";
23
import { Command } from "./deps.ts";
34
import { bootstrap } from "./lib/bootstrap.ts";
@@ -54,7 +55,7 @@ export async function repl(
5455
"repl",
5556
"--unstable", // dzx requires unstable
5657
"--eval",
57-
`${runtime}\n$.throwErrors = true;`,
58+
`${runtime}\n$.throwErrors = true;\nconsole.log("dzx ${VERSION}");`,
5859
];
5960

6061
const flags = generateFlags({

0 commit comments

Comments
 (0)