Skip to content

Commit fd5f8b5

Browse files
committed
feat: add $.mainModule
1 parent 838cfbe commit fd5f8b5

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/cli/mod.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function dzx() {
7070
) => {
7171
if (script) {
7272
script = addProtocool(script);
73+
$.mainModule = script;
7374
if (worker) {
7475
spawnWorker(script, perms);
7576
} else {
@@ -96,6 +97,7 @@ export function dzx() {
9697
`data:application/typescript,${
9798
encodeURIComponent(`
9899
import "${new URL("./src/runtime/mod.ts", Deno.mainModule)}";
100+
$.mainModule = "${script}";
99101
await import("${script}");
100102
if ($.verbose) {
101103
const end = Date.now();
@@ -125,9 +127,8 @@ export function dzx() {
125127
async function importFromStdin(): Promise<void> {
126128
const data = new TextDecoder().decode(await io.readAll(Deno.stdin));
127129
if (data) {
128-
await import(
129-
`data:application/typescript,${encodeURIComponent(data)}`
130-
);
130+
$.mainModule = `data:application/typescript,${encodeURIComponent(data)}`;
131+
await import($.mainModule);
131132
} else {
132133
// @TODO: add support for exit code in ValidationError
133134
// throw new ValidationError(`Failed to read from stdin.`, 2);

src/runtime/mod.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { exec } from "./exec.ts";
44
import { quote } from "./quote.ts";
55

66
export type $ = typeof exec & typeof colors & {
7+
shell: string;
8+
mainModule: string;
79
verbose: boolean;
810
cwd: string;
9-
shell: string;
1011
quote: typeof shq;
1112
throwErors: boolean;
1213
};
@@ -17,6 +18,7 @@ Object.setPrototypeOf($, Object.getPrototypeOf(colors));
1718

1819
$._stack = [];
1920
$.shell = "/bin/sh";
21+
$.mainModule = "";
2022
$.verbose = false;
2123
$.cwd = Deno.cwd();
2224
$.quote = shq;

0 commit comments

Comments
 (0)