|
1 |
| -import { io, path } from "../../mod.ts"; |
| 1 | +import { io, path } from "../runtime/mod.ts"; |
2 | 2 | import { bundleCommand } from "./bundle.ts";
|
3 | 3 | import { compileCommand } from "./compile.ts";
|
4 | 4 | import { Command, ValidationError } from "./deps.ts";
|
5 | 5 |
|
6 | 6 | export function dzx() {
|
7 |
| - const start = Date.now(); |
8 | 7 | return new Command<void>()
|
9 | 8 | .version("0.2.0")
|
10 | 9 | .name("dzx")
|
@@ -64,42 +63,41 @@ export function dzx() {
|
64 | 63 | _args?: Array<string>,
|
65 | 64 | ) => {
|
66 | 65 | if (script) {
|
67 |
| - script = addProtocool(script); |
68 |
| - $.mainModule = script; |
| 66 | + $.mainModule = addProtocool(script); |
69 | 67 | if (worker) {
|
70 |
| - spawnWorker(script, perms); |
| 68 | + spawnWorker(perms); |
71 | 69 | } else {
|
72 |
| - await import(script); |
| 70 | + await import($.mainModule); |
73 | 71 | }
|
74 | 72 | } else if (Deno.isatty(Deno.stdin.rid)) {
|
75 | 73 | throw new ValidationError(`Missing argument(s): script`);
|
76 | 74 | } else {
|
77 | 75 | await importFromStdin();
|
78 | 76 | }
|
79 | 77 | if ($.verbose) {
|
80 |
| - const end = Date.now(); |
81 |
| - console.log($.bold("time: %ss"), Math.round(end - start) / 1000); |
| 78 | + console.log($.bold("time: %ss"), Math.round($.time) / 1000); |
82 | 79 | }
|
83 | 80 | },
|
84 | 81 | )
|
85 | 82 | .command("bundle", bundleCommand())
|
86 | 83 | .command("compile", compileCommand());
|
87 | 84 |
|
88 |
| - function spawnWorker(script: string, perms: Permissions): void { |
| 85 | + function spawnWorker(perms: Permissions): void { |
89 | 86 | new Worker(
|
90 | 87 | `data:application/typescript,${
|
91 | 88 | encodeURIComponent(`
|
92 | 89 | import "${new URL("./src/runtime/mod.ts", Deno.mainModule)}";
|
93 |
| - $.mainModule = "${script}"; |
94 |
| - await import("${script}"); |
| 90 | + $.mainModule = "${$.mainModule}"; |
| 91 | + $.startTime = ${$.startTime}; |
| 92 | + await import("${$.mainModule}"); |
95 | 93 | if ($.verbose) {
|
96 | 94 | const end = Date.now();
|
97 |
| - console.log($.bold("time: %ss"), Math.round(end - ${start}) / 1000); |
| 95 | + console.log($.bold("time: %ss"), Math.round($.time) / 1000); |
98 | 96 | }
|
99 | 97 | self.close();`)
|
100 | 98 | }`,
|
101 | 99 | {
|
102 |
| - name: script, |
| 100 | + name: $.mainModule, |
103 | 101 | type: "module",
|
104 | 102 | deno: {
|
105 | 103 | namespace: true,
|
|
0 commit comments