diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d689b8b..5d0bf0e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,11 +9,11 @@ on: jobs: lint: - runs-on: ${{ matrix.os }} # runs a test on Ubuntu, Windows and macOS + runs-on: ${{ matrix.os }} strategy: matrix: - deno: ["v1.42.x"] + deno: ["v2.2.4"] os: [ubuntu-latest] steps: @@ -21,19 +21,19 @@ jobs: uses: actions/checkout@v4 - name: Setup Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 with: - deno-version: ${{ matrix.deno }} # tests across multiple Deno versions + deno-version: ${{ matrix.deno }} - name: Run Deno lint run: deno lint test: - runs-on: ${{ matrix.os }} # runs a test on Ubuntu, Windows and macOS + runs-on: ${{ matrix.os }} strategy: matrix: - deno: ["v1.42.0", "v1.38.0"] + deno: ["v2.2.4", "v2.1.x"] os: [macOS-latest, windows-latest, ubuntu-latest] steps: @@ -41,9 +41,9 @@ jobs: uses: actions/checkout@v4 - name: Setup Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 with: - deno-version: ${{ matrix.deno }} # tests across multiple Deno versions + deno-version: ${{ matrix.deno }} - name: Cache Dependencies run: deno cache deps.ts diff --git a/ADLMap.ts b/ADLMap.ts index 7d1c168..039dc69 100644 --- a/ADLMap.ts +++ b/ADLMap.ts @@ -24,7 +24,7 @@ export class ADLMap { } return existing; } - set(k: K, v: V) { + set(k: K, v: V) : ADLMap { const ind = this.findIndex(k); if (ind === -1) { this.data.push({ v1: k, v2: v }); @@ -41,11 +41,11 @@ export class ADLMap { entries(): [K, V][] { return this.data.map((p) => [p.v1, p.v2]); } - toData() { + toData() : sysTypes.Map { return this.data; } - findIndex(k: K) { + findIndex(k: K) : number { return this.data.findIndex((p) => this.isEqual(p.v1, k)); } } diff --git a/README.md b/README.md index 6e688e9..fb4ac57 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ across many files or shared between projects. ### Pre-Requisites - [Deno](https://deno.land/#installation) -- Requires deno v1.16.4 or greater +- Requires deno v2.1 or greater ### Install @@ -17,13 +17,18 @@ It is recommended to use `deno install` to install the tool, which provides a convenient entrypoint script and aliases the permission flags. ``` -deno install --global --allow-read --allow-write --allow-run -f --name dnit https://deno.land/x/dnit@dnit-v1.14.4/main.ts +deno install --global --allow-read --allow-write --allow-run -f --name dnit --config deno.json https://deno.land/x/dnit@dnit-v1.14.4/main.ts +``` + +Install from github: +``` +deno install --global --allow-read --allow-write --allow-run -f --name dnit --config deno.json https://raw.githubusercontent.com/PaulThompson/dnit/d53fa48ad8ecfa8f5c7df1d6a669e3033555bc74/main.ts ``` Install from source checkout: ``` -deno install --global --allow-read --allow-write --allow-run -f --name dnit ./main.ts +deno install --global --allow-read --allow-write --allow-run -f --name dnit --config deno.json ./main.ts ``` - Read, Write and Run permissions are required in order to operate on files and diff --git a/adl-gen/resolver.ts b/adl-gen/resolver.ts index 2015aa7..3507be2 100644 --- a/adl-gen/resolver.ts +++ b/adl-gen/resolver.ts @@ -1,6 +1,6 @@ // deno-lint-ignore-file /* @generated from adl */ -import { declResolver, ScopedDecl } from "./runtime/adl.ts"; +import { declResolver, ScopedDecl, ScopedName } from "./runtime/adl.ts"; import { _AST_MAP as dnit_manifest } from "./dnit/manifest.ts"; import { _AST_MAP as sys_types } from "./sys/types.ts"; @@ -9,4 +9,4 @@ export const ADL: { [key: string]: ScopedDecl } = { ...sys_types, }; -export const RESOLVER = declResolver(ADL); +export const RESOLVER : (scopedName: ScopedName)=>ScopedDecl = declResolver(ADL); diff --git a/adl-gen/runtime/adl.ts b/adl-gen/runtime/adl.ts index 405aa37..89667e5 100644 --- a/adl-gen/runtime/adl.ts +++ b/adl-gen/runtime/adl.ts @@ -1,5 +1,5 @@ //deno-lint-ignore-file -import type * as AST from "./sys/adlast.ts"; +import * as AST from "./sys/adlast.ts"; import type * as utils from "./utils.ts"; export type ScopedName = AST.ScopedName; @@ -16,7 +16,7 @@ export interface DeclResolver { export function declResolver( ...astMaps: ({ [key: string]: AST.ScopedDecl })[] -) { +) : (scopedName: AST.ScopedName) => AST.ScopedDecl { const astMap: { [key: string]: AST.ScopedDecl } = {}; for (let map of astMaps) { for (let scopedName in map) { diff --git a/adl-gen/runtime/dynamic.ts b/adl-gen/runtime/dynamic.ts index db880ba..881883a 100644 --- a/adl-gen/runtime/dynamic.ts +++ b/adl-gen/runtime/dynamic.ts @@ -1,6 +1,6 @@ import { typeExprsEqual } from "./utils.ts"; -import { JsonBinding } from "./json.ts"; -import { Dynamic } from "./sys/dynamic.ts"; +import type { JsonBinding } from "./json.ts"; +import type { Dynamic } from "./sys/dynamic.ts"; /** * Convert an ADL value to a dynamically typed value diff --git a/adl-gen/runtime/json.ts b/adl-gen/runtime/json.ts index 1854f5c..dae6eca 100644 --- a/adl-gen/runtime/json.ts +++ b/adl-gen/runtime/json.ts @@ -55,7 +55,7 @@ export function createJsonBinding( function fromJsonE(json: Json): T { try { return jb0.fromJson(json); - } catch (e) { + } catch (e : unknown) { throw mapJsonException(e); } } @@ -81,7 +81,7 @@ export interface JsonParseException { } // Map a JsonException to an Error value -export function mapJsonException(exception: {}): {} { +export function mapJsonException(exception: unknown): unknown { if ( exception && (exception as { kind: string })["kind"] == "JsonParseException" ) { @@ -125,7 +125,7 @@ export function jsonParseException(message: string): JsonParseException { * @param exception The exception to check. */ export function isJsonParseException( - exception: {}, + exception: unknown, ): exception is JsonParseException { return ( exception).kind === "JsonParseException"; } @@ -301,7 +301,7 @@ function vectorJsonBinding( jarr.forEach((eljson: Json, i: number) => { try { result.push(elementBinding().fromJson(eljson)); - } catch (e) { + } catch (e : unknown) { if (isJsonParseException(e)) { e.pushIndex(i); } diff --git a/adl-gen/runtime/utils.ts b/adl-gen/runtime/utils.ts index e61e70b..df2dac4 100644 --- a/adl-gen/runtime/utils.ts +++ b/adl-gen/runtime/utils.ts @@ -89,10 +89,10 @@ export function typeExprToStringUnscoped(te: AST.TypeExpr): string { // "Flavoured" nominal typing. // https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/ -const symS = Symbol(); -const symT = Symbol(); -const symU = Symbol(); -const symV = Symbol(); +const symS : unique symbol = Symbol(); +const symT : unique symbol = Symbol(); +const symU : unique symbol = Symbol(); +const symV : unique symbol = Symbol(); /// Zero ADL type params - literal string type Name (fully scoped module name) /// eg for 'newtype X = string' -> 'type X = Flavouring0<"X">;' diff --git a/deno.json b/deno.json index b60dac7..fdc8dac 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,18 @@ { + "name": "@dnit/dnit", + "version": "2.0.0-pre.0", + "exports": "./mod.ts", "fmt": { "exclude": [ "adl-gen/" ] + }, + "imports": { + "@std/cli": "jsr:@std/cli@^1.0.15", + "@std/crypto": "jsr:@std/crypto@^1.0.4", + "@std/fs": "jsr:@std/fs@^1.0.15", + "@std/log": "jsr:@std/log@^0.224.14", + "@std/path": "jsr:@std/path@^1.0.8", + "@std/semver": "jsr:@std/semver@^1.0.4" } } diff --git a/deno.lock b/deno.lock index f8dbbd0..71ee466 100644 --- a/deno.lock +++ b/deno.lock @@ -1,9 +1,93 @@ { - "version": "3", + "version": "4", + "specifiers": { + "jsr:@std/cli@*": "1.0.15", + "jsr:@std/cli@1.0.15": "1.0.15", + "jsr:@std/cli@^1.0.15": "1.0.15", + "jsr:@std/crypto@*": "1.0.4", + "jsr:@std/crypto@1.0.4": "1.0.4", + "jsr:@std/crypto@^1.0.4": "1.0.4", + "jsr:@std/fmt@^1.0.5": "1.0.6", + "jsr:@std/fs@1.0.15": "1.0.15", + "jsr:@std/fs@^1.0.11": "1.0.15", + "jsr:@std/fs@^1.0.15": "1.0.15", + "jsr:@std/io@~0.225.2": "0.225.2", + "jsr:@std/log@*": "0.224.14", + "jsr:@std/log@0.224.14": "0.224.14", + "jsr:@std/log@~0.224.14": "0.224.14", + "jsr:@std/path@*": "1.0.8", + "jsr:@std/path@1.0.8": "1.0.8", + "jsr:@std/path@^1.0.8": "1.0.8", + "jsr:@std/semver@*": "1.0.4", + "jsr:@std/semver@1.0.4": "1.0.4", + "jsr:@std/semver@^1.0.4": "1.0.4" + }, + "jsr": { + "@std/cli@1.0.15": { + "integrity": "e79ba3272ec710ca44d8342a7688e6288b0b88802703f3264184b52893d5e93f" + }, + "@std/crypto@1.0.4": { + "integrity": "cee245c453bd5366207f4d8aa25ea3e9c86cecad2be3fefcaa6cb17203d79340" + }, + "@std/fmt@1.0.6": { + "integrity": "a2c56a69a2369876ddb3ad6a500bb6501b5bad47bb3ea16bfb0c18974d2661fc" + }, + "@std/fs@1.0.15": { + "integrity": "c083fb479889d6440d768e498195c3fc499d426fbf9a6592f98f53884d1d3f41", + "dependencies": [ + "jsr:@std/path@^1.0.8" + ] + }, + "@std/io@0.225.2": { + "integrity": "3c740cd4ee4c082e6cfc86458f47e2ab7cb353dc6234d5e9b1f91a2de5f4d6c7" + }, + "@std/log@0.224.14": { + "integrity": "257f7adceee3b53bb2bc86c7242e7d1bc59729e57d4981c4a7e5b876c808f05e", + "dependencies": [ + "jsr:@std/fmt", + "jsr:@std/fs@^1.0.11", + "jsr:@std/io" + ] + }, + "@std/path@1.0.8": { + "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" + }, + "@std/semver@1.0.4": { + "integrity": "a62af791917d8fd6c48d6ebbb872f83fad3fc6671ffadbbd39ea229c2d34d175" + } + }, "remote": { + "https://deno.land/std@0.221.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975", + "https://deno.land/std@0.221.0/assert/_diff.ts": "4bf42969aa8b1a33aaf23eb8e478b011bfaa31b82d85d2ff4b5c4662d8780d2b", + "https://deno.land/std@0.221.0/assert/_format.ts": "0ba808961bf678437fb486b56405b6fefad2cf87b5809667c781ddee8c32aff4", "https://deno.land/std@0.221.0/assert/assert.ts": "bec068b2fccdd434c138a555b19a2c2393b71dfaada02b7d568a01541e67cdc5", + "https://deno.land/std@0.221.0/assert/assert_almost_equals.ts": "8b96b7385cc117668b0720115eb6ee73d04c9bcb2f5d2344d674918c9113688f", + "https://deno.land/std@0.221.0/assert/assert_array_includes.ts": "1688d76317fd45b7e93ef9e2765f112fdf2b7c9821016cdfb380b9445374aed1", + "https://deno.land/std@0.221.0/assert/assert_equals.ts": "4497c56fe7d2993b0d447926702802fc0becb44e319079e8eca39b482ee01b4e", "https://deno.land/std@0.221.0/assert/assert_exists.ts": "24a7bf965e634f909242cd09fbaf38bde6b791128ece08e33ab08586a7cc55c9", + "https://deno.land/std@0.221.0/assert/assert_false.ts": "6f382568e5128c0f855e5f7dbda8624c1ed9af4fcc33ef4a9afeeedcdce99769", + "https://deno.land/std@0.221.0/assert/assert_greater.ts": "4945cf5729f1a38874d7e589e0fe5cc5cd5abe5573ca2ddca9d3791aa891856c", + "https://deno.land/std@0.221.0/assert/assert_greater_or_equal.ts": "573ed8823283b8d94b7443eb69a849a3c369a8eb9666b2d1db50c33763a5d219", + "https://deno.land/std@0.221.0/assert/assert_instance_of.ts": "72dc1faff1e248692d873c89382fa1579dd7b53b56d52f37f9874a75b11ba444", + "https://deno.land/std@0.221.0/assert/assert_is_error.ts": "6596f2b5ba89ba2fe9b074f75e9318cda97a2381e59d476812e30077fbdb6ed2", + "https://deno.land/std@0.221.0/assert/assert_less.ts": "2b4b3fe7910f65f7be52212f19c3977ecb8ba5b2d6d0a296c83cde42920bb005", + "https://deno.land/std@0.221.0/assert/assert_less_or_equal.ts": "b93d212fe669fbde959e35b3437ac9a4468f2e6b77377e7b6ea2cfdd825d38a0", + "https://deno.land/std@0.221.0/assert/assert_match.ts": "ec2d9680ed3e7b9746ec57ec923a17eef6d476202f339ad91d22277d7f1d16e1", + "https://deno.land/std@0.221.0/assert/assert_not_equals.ts": "ac86413ab70ffb14fdfc41740ba579a983fe355ba0ce4a9ab685e6b8e7f6a250", + "https://deno.land/std@0.221.0/assert/assert_not_instance_of.ts": "8f720d92d83775c40b2542a8d76c60c2d4aeddaf8713c8d11df8984af2604931", + "https://deno.land/std@0.221.0/assert/assert_not_match.ts": "b4b7c77f146963e2b673c1ce4846473703409eb93f5ab0eb60f6e6f8aeffe39f", + "https://deno.land/std@0.221.0/assert/assert_not_strict_equals.ts": "da0b8ab60a45d5a9371088378e5313f624799470c3b54c76e8b8abeec40a77be", + "https://deno.land/std@0.221.0/assert/assert_object_match.ts": "e85e5eef62a56ce364c3afdd27978ccab979288a3e772e6855c270a7b118fa49", + "https://deno.land/std@0.221.0/assert/assert_rejects.ts": "5206ac37d883797d9504e3915a0c7b692df6efcdefff3889cc14bb5a325641dd", + "https://deno.land/std@0.221.0/assert/assert_strict_equals.ts": "0425a98f70badccb151644c902384c12771a93e65f8ff610244b8147b03a2366", + "https://deno.land/std@0.221.0/assert/assert_string_includes.ts": "dfb072a890167146f8e5bdd6fde887ce4657098e9f71f12716ef37f35fb6f4a7", + "https://deno.land/std@0.221.0/assert/assert_throws.ts": "31f3c061338aec2c2c33731973d58ccd4f14e42f355501541409ee958d2eb8e5", "https://deno.land/std@0.221.0/assert/assertion_error.ts": "9f689a101ee586c4ce92f52fa7ddd362e86434ffdf1f848e45987dc7689976b8", + "https://deno.land/std@0.221.0/assert/equal.ts": "fae5e8a52a11d3ac694bbe1a53e13a7969e3f60791262312e91a3e741ae519e2", + "https://deno.land/std@0.221.0/assert/fail.ts": "f310e51992bac8e54f5fd8e44d098638434b2edb802383690e0d7a9be1979f1c", + "https://deno.land/std@0.221.0/assert/mod.ts": "7e41449e77a31fef91534379716971bebcfc12686e143d38ada5438e04d4a90e", + "https://deno.land/std@0.221.0/assert/unimplemented.ts": "47ca67d1c6dc53abd0bd729b71a31e0825fc452dbcd4fde4ca06789d5644e7fd", + "https://deno.land/std@0.221.0/assert/unreachable.ts": "3670816a4ab3214349acb6730e3e6f5299021234657eefe05b48092f3848c270", "https://deno.land/std@0.221.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.mjs": "f65ea775c52c5641f0154d98d6059e261ca3dc917a8856209d60bc6cb406e699", "https://deno.land/std@0.221.0/crypto/_wasm/mod.ts": "e89fbbc3c4722602ff975dd85f18273c7741ec766a9b68f6de4fd1d9876409f8", "https://deno.land/std@0.221.0/crypto/crypto.ts": "7ccd24e766d026d92ee1260b5a1639624775e94456d2a95c3a42fd3d49df78ab", @@ -128,6 +212,17 @@ "https://deno.land/std@0.221.0/path/windows/resolve.ts": "8dae1dadfed9d46ff46cc337c9525c0c7d959fb400a6308f34595c45bdca1972", "https://deno.land/std@0.221.0/path/windows/to_file_url.ts": "40e560ee4854fe5a3d4d12976cef2f4e8914125c81b11f1108e127934ced502e", "https://deno.land/std@0.221.0/path/windows/to_namespaced_path.ts": "4ffa4fb6fae321448d5fe810b3ca741d84df4d7897e61ee29be961a6aac89a4c", + "https://deno.land/std@0.221.0/testing/asserts.ts": "0cb9c745d9b157bed062a4aa8647168d2221f6456c385a548b0ca24de9e0f3ca", "https://deno.land/x/semver@v1.4.1/mod.ts": "0b79c87562eb8a1f008ab0d98f8bb60076dd65bc06f1f8fdfac2d2dab162c27b" + }, + "workspace": { + "dependencies": [ + "jsr:@std/cli@^1.0.15", + "jsr:@std/crypto@^1.0.4", + "jsr:@std/fs@^1.0.15", + "jsr:@std/log@~0.224.14", + "jsr:@std/path@^1.0.8", + "jsr:@std/semver@^1.0.4" + ] } } diff --git a/deps.ts b/deps.ts index 3b31d86..9b65516 100644 --- a/deps.ts +++ b/deps.ts @@ -1,8 +1,8 @@ -import * as flags from "https://deno.land/std@0.221.0/flags/mod.ts"; -import * as path from "https://deno.land/std@0.221.0/path/mod.ts"; -import * as log from "https://deno.land/std@0.221.0/log/mod.ts"; -import * as fs from "https://deno.land/std@0.221.0/fs/mod.ts"; -import { crypto } from "https://deno.land/std@0.221.0/crypto/mod.ts"; -import * as semver from "https://deno.land/x/semver@v1.4.1/mod.ts"; -export { crypto, flags, fs, log, path, semver }; +import * as cli from "@std/cli/parse-args"; +import * as path from "@std/path"; +import * as log from "@std/log"; +import * as fs from "@std/fs"; +import { crypto } from "@std/crypto/crypto"; +import * as semver from "@std/semver"; +export { crypto, cli, fs, log, path, semver}; diff --git a/dnit.ts b/dnit.ts index fbd8c9d..d2ea54c 100644 --- a/dnit.ts +++ b/dnit.ts @@ -1,4 +1,4 @@ -import { crypto, flags, log, path } from "./deps.ts"; +import { cli, crypto, log, path } from "./deps.ts"; import { version } from "./version.ts"; import { textTable } from "./textTable.ts"; @@ -10,30 +10,30 @@ import { AsyncQueue } from "./asyncQueue.ts"; class ExecContext { /// All tasks by name - taskRegister = new Map(); + taskRegister : Map = new Map(); /// Tasks by target - targetRegister = new Map(); + targetRegister : Map = new Map(); /// Done or up-to-date tasks - doneTasks = new Set(); + doneTasks : Set = new Set(); /// In progress tasks - inprogressTasks = new Set(); + inprogressTasks : Set = new Set(); /// Queue for scheduling async work with specified number allowable concurrently. // deno-lint-ignore no-explicit-any asyncQueue: AsyncQueue; - internalLogger = log.getLogger("internal"); - taskLogger = log.getLogger("task"); - userLogger = log.getLogger("user"); + internalLogger : log.Logger = log.getLogger("internal"); + taskLogger : log.Logger = log.getLogger("task"); + userLogger : log.Logger = log.getLogger("user"); constructor( /// loaded hash manifest readonly manifest: Manifest, /// commandline args - readonly args: flags.Args, + readonly args: cli.Args, ) { if (args["verbose"] !== undefined) { this.internalLogger.levelName = "INFO"; @@ -53,7 +53,7 @@ class ExecContext { export interface TaskContext { logger: log.Logger; task: Task; - args: flags.Args; + args: cli.Args; exec: ExecContext; } @@ -394,7 +394,7 @@ export class TrackedFile { return statResult.kind === "fileInfo"; } - async getHash(statInput?: StatResult) { + async getHash(statInput?: StatResult) : Promise { let statResult = statInput; if (statResult === undefined) { statResult = await this.stat(); @@ -407,7 +407,7 @@ export class TrackedFile { return this.#getHash(this.path, statResult.fileInfo); } - async getTimestamp(statInput?: StatResult) { + async getTimestamp(statInput?: StatResult) : Promise { let statResult = statInput; if (statResult === undefined) { statResult = await this.stat(); @@ -564,7 +564,7 @@ export function task(taskParams: TaskParams): Task { return task; } -function showTaskList(ctx: ExecContext, args: flags.Args) { +function showTaskList(ctx: ExecContext, args: cli.Args) { if (args["quiet"]) { Array.from(ctx.taskRegister.values()).map((task) => console.log(task.name)); } else { @@ -615,20 +615,20 @@ class StdErrPlainHandler extends log.BaseHandler { }); } - log(msg: string): void { + override log(msg: string): void { Deno.stderr.writeSync(new TextEncoder().encode(msg + "\n")); } } /// StdErr handler on top of ConsoleHandler (which uses colors) class StdErrHandler extends log.ConsoleHandler { - log(msg: string): void { + override log(msg: string): void { Deno.stderr.writeSync(new TextEncoder().encode(msg + "\n")); } } -export async function setupLogging() { - await log.setup({ +export function setupLogging() { + log.setup({ handlers: { stderr: new StdErrHandler("DEBUG"), stderrPlain: new StdErrPlainHandler("DEBUG"), @@ -717,9 +717,9 @@ export async function execCli( cliArgs: string[], tasks: Task[], ): Promise { - const args = flags.parse(cliArgs); + const args = cli.parseArgs(cliArgs); - await setupLogging(); + setupLogging(); /// directory of user's entrypoint source as discovered by 'launch' util: const dnitDir = args["dnitDir"] || "./dnit"; @@ -781,7 +781,7 @@ export async function execBasic( tasks: Task[], manifest: Manifest, ): Promise { - const args = flags.parse(cliArgs); + const args = cli.parseArgs(cliArgs); const ctx = new ExecContext(manifest, args); tasks.forEach((t) => ctx.taskRegister.set(t.name, t)); diff --git a/dnit/.denoversion b/dnit/.denoversion index ba7c934..a0d4707 100644 --- a/dnit/.denoversion +++ b/dnit/.denoversion @@ -1 +1 @@ ->=1.16.4 <=1.42.0 +>=2.1 <3 diff --git a/dnit/deps.ts b/dnit/deps.ts index cce7ddc..97d0d66 100644 --- a/dnit/deps.ts +++ b/dnit/deps.ts @@ -1,11 +1,9 @@ // refer to own sources for ease of development -import { file, main, task } from "../dnit.ts"; +import { file, main, task, runAlways, type TaskContext } from "../dnit.ts"; import * as utils from "../utils.ts"; -import * as flags from "https://deno.land/std@0.221.0/flags/mod.ts"; -import * as path from "https://deno.land/std@0.221.0/path/mod.ts"; -import * as log from "https://deno.land/std@0.221.0/log/mod.ts"; -import * as fs from "https://deno.land/std@0.221.0/fs/mod.ts"; -import * as semver from "https://deno.land/x/semver@v1.4.1/mod.ts"; +import * as cli from "jsr:@std/cli@1.0.15/parse-args"; +import * as fs from "jsr:@std/fs@1.0.15"; +import * as semver from "jsr:@std/semver@1.0.4"; -export { file, flags, fs, log, main, path, semver, task, utils }; +export { file, cli, fs, main, runAlways, semver, task, utils, type TaskContext }; diff --git a/dnit/main.ts b/dnit/main.ts index 975a5bb..2839d38 100644 --- a/dnit/main.ts +++ b/dnit/main.ts @@ -1,5 +1,13 @@ -import { flags, log, semver, task, utils } from "./deps.ts"; -import { file, main, runAlways, TaskContext } from "../dnit.ts"; +import { + type cli, + file, + main, + runAlways, + semver, + task, + type TaskContext, + utils, +} from "./deps.ts"; import { fetchTags, @@ -12,7 +20,7 @@ import { runConsole } from "../utils.ts"; const tagPrefix = "dnit-v"; -async function getNextTagVersion(args: flags.Args): Promise { +async function getNextTagVersion(args: cli.Args): Promise { const current = await gitLatestTag(tagPrefix); type Args = { @@ -24,7 +32,9 @@ async function getNextTagVersion(args: flags.Args): Promise { const increment: "major" | "minor" | "patch" = args.major ? "major" : (xargs.minor ? "minor" : ("patch")); - const next = semver.inc(current, increment); + const next = semver.format( + semver.increment(semver.parse(current), increment), + ); return next; } @@ -32,8 +42,6 @@ const tag = task({ name: "tag", description: "Run git tag", action: async (ctx: TaskContext) => { - const current = await gitLatestTag(tagPrefix); - type Args = { "major"?: true; "minor"?: true; @@ -42,11 +50,13 @@ const tag = task({ "origin"?: string; "dry-run"?: true; }; + + const next = await getNextTagVersion(ctx.args); + const args: Args = ctx.args as Args; const increment: "major" | "minor" | "patch" = args.major ? "major" : (args.minor ? "minor" : ("patch")); - const next = semver.inc(current, increment); const tagMessage = args.message || `Tag ${increment} to ${next}`; const tagName = `${tagPrefix}${next}`; @@ -58,7 +68,7 @@ const tag = task({ console.log("Last commit: " + gitLastCommit); const conf = confirm( - `Git tag and push ${tagMessage} tagName?`, + `Git tag and push ${tagName} with message: ${tagMessage}?`, ); if (conf) { const cmds = dryRun ? ["echo"] : []; @@ -67,7 +77,8 @@ const tag = task({ cmds.concat(["git", "tag", "-a", "-m", tagMessage, tagName]), ); await utils.runConsole(cmds.concat(["git", "push", origin, tagName])); - log.info( + + ctx.logger.info( `${ dryRun ? "(dry-run) " : "" }Git tagged and pushed ${tagPrefix}${next}`, @@ -248,6 +259,60 @@ const killTest = task({ uptodate: runAlways, }); +const sourceCheckEntryPoints: string[] = [ + "main.ts", + "mod.ts", + "dnit/main.ts", +]; + +const check = task({ + name: "check", + description: "Run local checks", + action: async () => { + await Promise.all(sourceCheckEntryPoints.map(async (path) => { + await utils.runConsole([ + "deno", + "check", + path, + ]); + })); + }, + deps: [], + uptodate: runAlways, +}); + +const lint = task({ + name: "lint", + description: "Run local lint", + action: async () => { + await Promise.all(sourceCheckEntryPoints.map(async (path) => { + await utils.runConsole([ + "deno", + "lint", + path, + ]); + })); + }, + deps: [], + uptodate: runAlways, +}); + +const fmt = task({ + name: "fmt", + description: "Run local fmt", + action: async () => { + await Promise.all(sourceCheckEntryPoints.map(async (path) => { + await utils.runConsole([ + "deno", + "fmt", + path, + ]); + })); + }, + deps: [], + uptodate: runAlways, +}); + const tasks = [ test, genadl, @@ -257,6 +322,9 @@ const tasks = [ makeReleaseEdits, release, killTest, + check, + lint, + fmt, ]; main(Deno.args, tasks); diff --git a/example/.gitignore b/example/.gitignore deleted file mode 100644 index 721b360..0000000 --- a/example/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/dnit/.manifest.json -/msg.txt diff --git a/example/dnit/deps.ts b/example/dnit/deps.ts deleted file mode 100644 index 46ba351..0000000 --- a/example/dnit/deps.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { - file, - main, - task, -} from "https://deno.land/x/dnit@dnit-v1.14.4/dnit.ts"; -import * as flags from "https://deno.land/std@0.221.0/flags/mod.ts"; -import * as path from "https://deno.land/std@0.221.0/path/mod.ts"; -import * as log from "https://deno.land/std@0.221.0/log/mod.ts"; -import * as fs from "https://deno.land/std@0.221.0/fs/mod.ts"; - -export { file, flags, fs, log, main, path, task }; diff --git a/example/dnit/goodBye.ts b/example/dnit/goodBye.ts deleted file mode 100644 index f407d23..0000000 --- a/example/dnit/goodBye.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { task } from "./deps.ts"; -import { msg } from "./helloWorld.ts"; - -//import { red } from "fmt/colors.ts"; - -//console.log(red("hello world")); - -export const goodbye = task({ - name: "goodbye", - action: async () => { - // use ordinary typescript idiomatically if several actions are required - const actions = [ - async () => { - const txt = await Deno.readTextFile(msg.path); - console.log(txt); - }, - ]; - for (const action of actions) { - await action(); - } - }, - deps: [msg], -}); diff --git a/example/dnit/helloWorld.ts b/example/dnit/helloWorld.ts deleted file mode 100644 index 5bffba1..0000000 --- a/example/dnit/helloWorld.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { file, task } from "./deps.ts"; - -export const msg = file({ - path: "./msg.txt", -}); - -export const helloWorld = task({ - name: "helloWorld", - description: "foo", - action: async () => { - const cmd = new Deno.Command("sh", { - args: ["./writeMsg.sh"], - }); - await cmd.output(); - }, - deps: [ - file({ - path: "./writeMsg.sh", - }), - ], - targets: [ - msg, - ], -}); diff --git a/example/dnit/import_map.json b/example/dnit/import_map.json deleted file mode 100644 index 6842e29..0000000 --- a/example/dnit/import_map.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "imports": { - "fmt/": "https://deno.land/std@0.221.0/fmt/" - } -} diff --git a/example/dnit/main.ts b/example/dnit/main.ts deleted file mode 100644 index 20bfa27..0000000 --- a/example/dnit/main.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { main } from "./deps.ts"; -import { helloWorld } from "./helloWorld.ts"; -import { goodbye } from "./goodBye.ts"; - -const tasks = [ - helloWorld, - goodbye, -]; - -main(Deno.args, tasks); diff --git a/example/somedir/.gitignore b/example/somedir/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/example/writeMsg.sh b/example/writeMsg.sh deleted file mode 100755 index bdb0155..0000000 --- a/example/writeMsg.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# an example task - -cd "$( dirname "${BASH_SOURCE[0]}" )" - -echo "writing msg.txt" -echo helloworld > msg.txt diff --git a/launch.ts b/launch.ts index 88bdba1..505ca93 100644 --- a/launch.ts +++ b/launch.ts @@ -1,6 +1,6 @@ /// Convenience util to launch a user's dnit.ts -import { fs, log, path, semver } from "./deps.ts"; +import { fs, type log, path, semver } from "./deps.ts"; type UserSource = { baseDir: string; @@ -115,7 +115,7 @@ export function checkValidDenoVersion( denoVersion: string, denoReqSemverRange: string, ): boolean { - return semver.satisfies(denoVersion, denoReqSemverRange); + return semver.satisfies(semver.parse(denoVersion), semver.parseRange(denoReqSemverRange)) } export async function launch(logger: log.Logger): Promise { diff --git a/main.ts b/main.ts index 603f727..b993550 100644 --- a/main.ts +++ b/main.ts @@ -1,15 +1,16 @@ -import { flags, log, setupLogging } from "./mod.ts"; +import { setupLogging } from "./dnit.ts"; +import { cli, log } from "./deps.ts"; import { launch } from "./launch.ts"; import { version } from "./version.ts"; export async function main() { - const args = flags.parse(Deno.args); + const args: cli.Args = cli.parseArgs(Deno.args); if (args["version"] === true) { console.log(`dnit ${version}`); Deno.exit(0); } - await setupLogging(); + setupLogging(); const internalLogger = log.getLogger("internal"); if (args["verbose"] !== undefined) { @@ -18,9 +19,8 @@ export async function main() { internalLogger.info(`starting dnit launch using version: ${version}`); - launch(internalLogger).then((st) => { - Deno.exit(st.code); - }); + const st = await launch(internalLogger); + Deno.exit(st.code); } -main(); +await main(); diff --git a/manifest.ts b/manifest.ts index bdc182e..135d386 100644 --- a/manifest.ts +++ b/manifest.ts @@ -7,7 +7,7 @@ import { RESOLVER } from "./adl-gen/resolver.ts"; import { ADLMap } from "./ADLMap.ts"; export class Manifest { readonly filename: string; - readonly jsonBinding = J.createJsonBinding(RESOLVER, A.texprManifest()); + readonly jsonBinding : J.JsonBinding = J.createJsonBinding(RESOLVER, A.texprManifest()); tasks: ADLMap = new ADLMap( [], (k1, k2) => k1 === k2, diff --git a/tests/basic.test.ts b/tests/basic.test.ts index 7ba73df..0a73a0b 100644 --- a/tests/basic.test.ts +++ b/tests/basic.test.ts @@ -3,7 +3,7 @@ import { execBasic, runAlways, task, - TrackedFile, + type TrackedFile, trackFile, } from "../dnit.ts"; diff --git a/utils/git.ts b/utils/git.ts index ea7def6..0aa68cb 100644 --- a/utils/git.ts +++ b/utils/git.ts @@ -1,5 +1,5 @@ import { run, runConsole } from "./process.ts"; -import { task, TaskContext } from "../dnit.ts"; +import { task, type TaskContext } from "../dnit.ts"; export async function gitLatestTag(tagPrefix: string) { const describeStr = await run( diff --git a/version.ts b/version.ts index 00628f4..7f1cf46 100644 --- a/version.ts +++ b/version.ts @@ -1 +1 @@ -export const version = "1.14.4"; +export const version = "2.0.0-pre.0";