diff --git a/deno.jsonc b/deno.jsonc index 1140ab8..ac64d8a 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -9,7 +9,7 @@ "rm -rf .coverage &&", "deno test &&", "deno coverage .coverage &&", - "rm -rf tests/.coverage tests/.coverage.report tests/.deno.lock tests/.junit.xml" + "rm -rf tests/.coverage tests/.coverage.report tests/.deno.lock tests/.junit.xml tests/.mod.bin tests/.mod.bin.exe tests/*.exe" ], "deno": { "test": { @@ -18,6 +18,7 @@ "traceOps": true, "permissions": { "read": true, + "env": ["TEST_INHERIT"], "write": [".deno-make.json"], "run": ["deno"] } diff --git a/deno.lock b/deno.lock index 851bf29..d6af86e 100644 --- a/deno.lock +++ b/deno.lock @@ -175,6 +175,12 @@ "https://deno.land/std@0.204.0/path/windows/separator.ts": "ae21f27015f10510ed1ac4a0ba9c4c9c967cbdd9d9e776a3e4967553c397bd5d", "https://deno.land/std@0.204.0/path/windows/to_file_url.ts": "8e9ea9e1ff364aa06fa72999204229952d0a279dbb876b7b838b2b2fea55cce3", "https://deno.land/std@0.204.0/path/windows/to_namespaced_path.ts": "e0f4d4a5e77f28a5708c1a33ff24360f35637ba6d8f103d19661255ef7bfd50d", + "https://deno.land/std@0.205.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", + "https://deno.land/std@0.205.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", + "https://deno.land/std@0.205.0/fmt/colors.ts": "c51c4642678eb690dcf5ffee5918b675bf01a33fba82acf303701ae1a4f8c8d9", + "https://deno.land/std@0.205.0/json/common.ts": "ecd5e87d45b5f0df33238ed8b1746e1444da7f5c86ae53d0f0b04280f41a25bb", + "https://deno.land/std@0.205.0/jsonc/mod.ts": "b88dce28eb3645667caa856538ae2fe87af51410822544a0b45a4177ef3bd7dd", + "https://deno.land/std@0.205.0/jsonc/parse.ts": "c1096e2b7ffb4996d7ed841dfdb29a4fccc78edcc55299beaa20d6fe5facf7b6", "https://deno.land/x/zod@v3.21.4/ZodError.ts": "4de18ff525e75a0315f2c12066b77b5c2ae18c7c15ef7df7e165d63536fdf2ea", "https://deno.land/x/zod@v3.21.4/errors.ts": "5285922d2be9700cc0c70c95e4858952b07ae193aa0224be3cbd5cd5567eabef", "https://deno.land/x/zod@v3.21.4/external.ts": "a6cfbd61e9e097d5f42f8a7ed6f92f93f51ff927d29c9fbaec04f03cbce130fe", diff --git a/mod.ts b/mod.ts index ad34935..8690422 100644 --- a/mod.ts +++ b/mod.ts @@ -1,8 +1,8 @@ // Imports -import * as JSONC from "https://deno.land/std@0.203.0/jsonc/mod.ts" +import * as JSONC from "https://deno.land/std@0.205.0/jsonc/mod.ts" import { z as is } from "https://deno.land/x/zod@v3.21.4/mod.ts" import { fromZodError } from "https://esm.sh/zod-validation-error@1.5.0?pin=v133" -import { bgBrightBlue, bold, gray, italic, underline, yellow } from "https://deno.land/std@0.203.0/fmt/colors.ts" +import { bgBrightBlue, bold, gray, italic, underline, yellow } from "https://deno.land/std@0.205.0/fmt/colors.ts" // Structure flags ========================================================================================================= @@ -162,7 +162,7 @@ const modules = { /** Inspect flags */ const inspect = is.union([ - is.string().transform((v) => v ? `--inspect='${v}'` : ""), + is.string().min(1).transform((v) => `--inspect='${v}'`), is.object({ listen: is.string().min(1).optional().transform((v) => v ? `--inspect='${v}'` : ""), break: is.string().min(1).optional().transform((v) => v ? `--inspect-brk='${v}'` : ""), @@ -355,8 +355,9 @@ const vendor = common.extend({ const _make = is.object({ task: is.union([is.string(), is.array(is.string())]).transform((v) => Array.isArray(v) ? v.join(" ") : v), - description: is.union([is.string(), is.array(is.string())]).transform((v) => Array.isArray(v) ? v.join(" ") : v) - .default(""), + description: is.union([is.string(), is.array(is.string())]).default("").transform((v) => + Array.isArray(v) ? v.join(" ") : v + ), env: is.record(is.string(), is.union([is.boolean(), is.string()])).transform(( v, ) => @@ -411,7 +412,7 @@ export async function make( config = "deno.jsonc", log = console.log, exit = true, - stdio = "inherit" as "inherit" | "null", + stdio = "inherit" as "inherit" | "piped" | "null", } = {}, ) { const { "+tasks": _tasks = {} } = JSONC.parse( @@ -429,27 +430,33 @@ export async function make( }), ) if (task) { - const temp = ".deno-make.json" const { task: raw, env, deno, cwd } = tasks[task] + const temp = ".deno-make.json" + const decoder = new TextDecoder() try { const make = command(raw, { deno }) await Deno.writeTextFile(temp, JSON.stringify({ tasks: { make } })) const process = new Deno.Command("deno", { - args: ["task", "--config", temp, "make"], + args: ["task", ...(cwd ? ["--cwd", cwd] : []), "--config", temp, "make"], stdout: stdio, stderr: stdio, stdin: stdio, env, - cwd, windowsRawArguments: true, - }) - const { code } = await process.output() + }).spawn() + if (stdio === "piped") { + const { stdout, stderr } = await process.output() + log(decoder.decode(stdout)) + log(decoder.decode(stderr)) + await process.stdin?.close() + } + const { code } = await process.status if (exit) { Deno.exit(code) } return { code } } finally { - await Deno.remove(temp) + await Deno.remove(temp).catch(() => null) } } else if (Object.keys(tasks).length) { for ( diff --git a/mod_test.ts b/mod_test.ts index 8fde8b7..5a8d5b7 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -15,9 +15,9 @@ for await (const { path, name: _name } of expandGlob("tests/*.jsonc")) { const { code } = await make({ task, config: path, + stdio: "piped", log: (message) => stdio.push(message), exit: false, - stdio: "null", }) try { expect(code).to.equal(0) diff --git a/tests/.deno.lock b/tests/.deno.lock deleted file mode 100644 index 37f10ce..0000000 --- a/tests/.deno.lock +++ /dev/null @@ -1,4 +0,0 @@ -{ - "version": "3", - "remote": {} -} diff --git a/tests/deno_common.jsonc b/tests/deno_common.jsonc index d42a661..e760597 100644 --- a/tests/deno_common.jsonc +++ b/tests/deno_common.jsonc @@ -33,7 +33,6 @@ "flags:general:number": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "seed": 0 @@ -43,7 +42,6 @@ "flags:general:array": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "v8Flags": ["--print-code"] @@ -71,7 +69,6 @@ "flags:lock:string": { "task": "deno help", "cwd": "tests", - "deno": { "vendor": { "lock": "deno.lock" @@ -87,7 +84,6 @@ "flags:lock:boolean": { "task": "deno help", "cwd": "tests", - "deno": { "info": { "lock": false @@ -100,7 +96,6 @@ "flags:lock:object": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "lock": { @@ -118,17 +113,16 @@ "flags:permissions:all": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "permissions": { - "allow": true, + "all": true, "prompt": true } }, "test": { "permissions": { - "allow": false + "all": false } } } @@ -136,7 +130,6 @@ "flags:permissions:boolean": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "permissions": { @@ -169,7 +162,6 @@ "flags:permissions:array": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "permissions": { @@ -198,7 +190,6 @@ "flags:permissions:allow_deny_object": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "permissions": { @@ -227,55 +218,61 @@ "flags:modules:boolean": { "task": "deno help", "cwd": "tests", - "deno": { "run": { - "cached": true, - "remote": true, - "npm": true, - "check": true, - "reload": true, - "node_modules": true, - "vendor": true + "modules": { + "cached": true, + "remote": true, + "npm": true, + "check": true, + "reload": true, + "node_modules": true, + "vendor": true + } }, "test": { - "cached": false, - "remote": false, - "npm": false, - "check": false, - "reload": false, - "node_modules": false, - "vendor": false + "modules": { + "cached": false, + "remote": false, + "npm": false, + "check": false, + "reload": false, + "node_modules": false, + "vendor": false + } } } }, "flags:modules:string": { "task": "deno help", "cwd": "tests", - "deno": { "run": { - "check": "all" + "modules": { + "check": "all" + } } } }, "flags:modules:array": { "task": "deno help", "cwd": "tests", - "deno": { "run": { - "reload": ["npm:"] + "modules": { + "reload": ["npm:"] + } }, "test": { - "reload": [] + "modules": { + "reload": [] + } } } }, "flags:inspect:string": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "inspect": "127.0.0.1:9229" @@ -284,14 +281,12 @@ }, "flags:inspect:object": { "task": "deno help", - "cwd": "tests", - "deno": { "run": { "inspect": { "listen": "127.0.0.1:9229", "break": "127.0.0.1:9230", - "wait:": "127.0.0.1:9229" + "wait:": "127.0.0.1:9231" } }, "test": { @@ -303,7 +298,6 @@ "flags:watch:boolean": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "watch": true @@ -316,7 +310,6 @@ "flags:watch:array": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "watch": ["mod.ts"] @@ -329,7 +322,6 @@ "flags:watch:object": { "task": "deno help", "cwd": "tests", - "deno": { "run": { "watch": { diff --git a/tests/deno_compile.jsonc b/tests/deno_compile.jsonc index 0967ef4..bec27e7 100644 --- a/tests/deno_compile.jsonc +++ b/tests/deno_compile.jsonc @@ -1 +1,34 @@ -{} +{ + "tasks": { + "make": "deno run --allow-env --allow-read --allow-write=.deno-make.json --allow-run=deno ./mod.ts $0" + }, + "+tasks": { + "flags:none": { + "task": "deno compile mod.ts", + "cwd": "tests" + }, + "flags:case_1": { + "task": "deno compile mod.ts", + "cwd": "tests", + "deno": { + "compile": { + "include": ["mod_test.ts"], + "output": ".mod.bin", + "target": "x86_64-unknown-linux-gnu" + } + } + }, + "flags:case_2": { + "task": "deno compile mod.ts", + "cwd": "tests", + "deno": { + "compile": { + "include": [], + "output": ".mod.bin", + "target": "x86_64-pc-windows-msvc", + "terminal": false + } + } + } + } +} diff --git a/tests/deno_coverage.jsonc b/tests/deno_coverage.jsonc index 71dd6c3..1558586 100644 --- a/tests/deno_coverage.jsonc +++ b/tests/deno_coverage.jsonc @@ -35,15 +35,15 @@ } } }, - "flags:array": { + /*"flags:array": { "task": "deno coverage .coverage", "cwd": "tests", "deno": { "coverage": { - "ignore": ["foo"] + "ignore": ["../.coverage"] } } - }, + },*/ "flags:array_empty": { "task": "deno coverage .coverage", "cwd": "tests", diff --git a/tests/deno_fmt.jsonc b/tests/deno_fmt.jsonc index bf98d34..402cd26 100644 --- a/tests/deno_fmt.jsonc +++ b/tests/deno_fmt.jsonc @@ -14,7 +14,6 @@ "fmt": { "check": true, "tabs": true, - "singleQuote": true, "semicolons": true } } @@ -31,6 +30,16 @@ } } }, + "flags:single_quote": { + "task": "deno fmt mod.ts || true", + "cwd": "tests", + "deno": { + "fmt": { + "check": true, + "singleQuote": true + } + } + }, "flags:string": { "task": "deno fmt mod.ts", "cwd": "tests", @@ -56,7 +65,7 @@ "cwd": "tests", "deno": { "fmt": { - "ignore": ["*"] + "ignore": ["mod_test.ts"] } } }, diff --git a/tests/deno_make.jsonc b/tests/deno_make.jsonc index 6a40965..e3bccd0 100644 --- a/tests/deno_make.jsonc +++ b/tests/deno_make.jsonc @@ -22,7 +22,7 @@ "task": "exit 1", "env": { "DINOSAUR": "🦖", - "INHERIT": true + "TEST_INHERIT": true } }, "make:cwd": { diff --git a/tests/deno_test.jsonc b/tests/deno_test.jsonc index 1f58e1d..f545ff5 100644 --- a/tests/deno_test.jsonc +++ b/tests/deno_test.jsonc @@ -48,19 +48,19 @@ } }, "flags:string": { - "task": "deno test tests/mod_test.ts", + "task": "deno test mod_test.ts", "cwd": "tests", "deno": { "test": { "coverage": ".coverage", "reporter": "junit", "filter": "junit", - "junitPath": "tests/.junit.xml" + "junitPath": ".junit.xml" } } }, "flags:array": { - "task": "deno test tests/mod_test.ts", + "task": "deno test mod_test.ts", "cwd": "tests", "deno": { "test": { @@ -69,7 +69,7 @@ } }, "flags:array_empty": { - "task": "deno test tests/mod_test.ts", + "task": "deno test mod_test.ts", "cwd": "tests", "deno": { "test": { diff --git a/tests/deno_types.jsonc b/tests/deno_types.jsonc index 81bb2f6..d401fa6 100644 --- a/tests/deno_types.jsonc +++ b/tests/deno_types.jsonc @@ -6,6 +6,13 @@ "flags:none": { "task": "deno types", "cwd": "tests" + }, + "flags:common": { + "task": "deno types", + "cwd": "tests", + "types": { + "quiet": true + } } } } diff --git a/tests/deno_uninstall.jsonc b/tests/deno_uninstall.jsonc index 0967ef4..3c3e9ec 100644 --- a/tests/deno_uninstall.jsonc +++ b/tests/deno_uninstall.jsonc @@ -1 +1,23 @@ -{} +{ + "tasks": { + "make": "deno run --allow-env --allow-read --allow-write=.deno-make.json --allow-run=deno ./mod.ts $0" + }, + "+tasks": { + "flags:none": { + "task": "deno help", + "cwd": "tests", + "deno": { + "uninstall": {} + } + }, + "flags:root": { + "task": "deno help", + "cwd": "tests", + "deno": { + "uninstall": { + "root": "/tmp" + } + } + } + } +}