Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tool: Add eszip build subcommand #69

Merged
merged 4 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions lib/eszip.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env -S deno run --allow-run=deno --allow-read --allow-write --allow-net=deno.land --no-check

/**
* CLI utility to list/extract/run ESZIPs
*/
// CLI utility to build/list/extract/run ESZIPs

import { Parser } from "./mod.ts";
import { build, Parser } from "./mod.ts";
import { dirname, join } from "https://deno.land/std@0.127.0/path/mod.ts";
import { assertStrictEquals } from "https://deno.land/std@0.127.0/testing/asserts.ts";

Expand Down Expand Up @@ -133,7 +131,15 @@ async function run(eszip: ESZIP, specifier: string) {
const importMap = join(tmpDir, "source", "import_map.json");
// Run
const p = Deno.run({
cmd: ["deno", "run", "-A", "--import-map", importMap, specifier],
cmd: [
"deno",
"run",
"-A",
"--no-check",
"--import-map",
importMap,
specifier,
],
});
await p.status();
} finally {
Expand All @@ -151,18 +157,33 @@ async function main() {
return console.log("TODO");
}

const eszip = await loadESZIP(filename);

switch (subcmd) {
case "build":
case "b": {
const eszip = await build([filename]);
let out = rest[0];
if (!out) {
// Create outfile name from url filename
out = new URL(filename).pathname.split("/").pop() || "out.eszip";
littledivy marked this conversation as resolved.
Show resolved Hide resolved
}
console.log(`${out}.eszip: ${eszip.length} bytes`);
await Deno.writeFile(`${out}.eszip`, eszip);
return;
}
case "x":
case "extract":
case "extract": {
const eszip = await loadESZIP(filename);
return await eszip.extract(rest[0] ?? Deno.cwd());
}
case "l":
case "ls":
case "list":
case "list": {
const eszip = await loadESZIP(filename);
return console.log(eszip.list().join("\n"));
}
case "r":
case "run": {
const eszip = await loadESZIP(filename);
const specifier = rest[0];
if (!specifier) {
return console.error("Please provide a specifier to run");
Expand Down
12 changes: 5 additions & 7 deletions lib/eszip_wasm.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,11 @@ const imports = {
__wbindgen_string_get: function (arg0, arg1) {
const obj = getObject(arg1);
var ret = typeof (obj) === "string" ? obj : undefined;
var ptr0 = isLikeNone(ret)
? 0
: passStringToWasm0(
ret,
wasm.__wbindgen_malloc,
wasm.__wbindgen_realloc,
);
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(
ret,
wasm.__wbindgen_malloc,
wasm.__wbindgen_realloc,
);
var len0 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len0;
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
Expand Down