Skip to content

Commit

Permalink
refactor: import from path instead of data url
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed May 8, 2021
1 parent a8226a4 commit ad6431a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions dzx.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/// <reference path="./types.d.ts" />

import { readAll } from "./deps.ts";
import { join } from "./deps.ts";
import { join, readAll } from "./deps.ts";
import { ProcessError } from "./src/process_error.ts";
import { $ } from "./mod.ts";

window.$ = $;

let script: string | undefined = Deno.args[0];
const script: string | undefined = Deno.args[0];

try {
if (!script) {
if (!Deno.isatty(Deno.stdin.rid)) {
script = new TextDecoder().decode(await readAll(Deno.stdin));
if (script) {
const data = new TextDecoder().decode(await readAll(Deno.stdin));
if (data) {
await import(
`data:application/typescript,${encodeURIComponent(script)}`
`data:application/typescript,${encodeURIComponent(data)}`
);
} else {
console.error(`usage: dzx <script>`);
Expand All @@ -25,8 +24,9 @@ try {
} else if (script.startsWith("http://") || script.startsWith("https://")) {
await import(script);
} else if (script) {
const data = await Deno.readTextFile(join($.cwd, script));
await import(`data:application/typescript,${encodeURIComponent(data)}`);
await import(join($.cwd, script));
// const data = await Deno.readTextFile(join($.cwd, script));
// await import(`data:application/typescript,${encodeURIComponent(data)}`);
} else {
console.error(`usage: dzx <script>`);
Deno.exit(1);
Expand Down

0 comments on commit ad6431a

Please sign in to comment.