From d5f3231e9ac5d0e3d83625286d9ed971a3295ee5 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 6 Apr 2024 12:21:25 -0400 Subject: [PATCH 1/5] feat: publish to jsr --- deno.json | 22 ++++++++++++++++++++- mod.test.ts | 4 ++-- mod.ts | 18 ++++++++--------- src/command.ts | 16 +++++++-------- src/command_handler.ts | 4 ++-- src/commands/cat.ts | 4 ++-- src/commands/cd.ts | 4 ++-- src/commands/cp_mv.ts | 4 ++-- src/commands/echo.ts | 4 ++-- src/commands/exit.ts | 4 ++-- src/commands/export.ts | 4 ++-- src/commands/mkdir.ts | 4 ++-- src/commands/printenv.ts | 4 ++-- src/commands/pwd.ts | 4 ++-- src/commands/rm.ts | 6 +++--- src/commands/sleep.ts | 4 ++-- src/commands/test.ts | 4 ++-- src/commands/touch.ts | 2 +- src/commands/unset.ts | 4 ++-- src/commands/which.ts | 6 +++--- src/common.ts | 13 ++++++++---- src/console/confirm.ts | 2 +- src/console/logger.ts | 3 ++- src/console/multiSelect.ts | 2 +- src/console/progress/interval.ts | 2 +- src/console/progress/mod.ts | 4 ++-- src/console/prompt.ts | 2 +- src/console/select.ts | 2 +- src/console/testUtils.ts | 2 +- src/deps.test.ts | 17 +++++----------- src/deps.ts | 34 ++++++++++++++++---------------- src/pipes.ts | 2 +- src/request.ts | 4 ++-- src/runtimes/process.deno.ts | 2 +- src/runtimes/process.node.ts | 2 +- src/shell.ts | 18 ++++++++--------- src/test/server.deno.ts | 2 +- src/test/server.node.ts | 2 +- src/vendor/outdent.ts | 3 ++- 39 files changed, 132 insertions(+), 112 deletions(-) diff --git a/deno.json b/deno.json index 9c30823..d9ae36c 100644 --- a/deno.json +++ b/deno.json @@ -1,4 +1,6 @@ { + "name": "@david/dax", + "version": "0.0.0", "lock": false, "tasks": { "test": "deno test -A", @@ -18,7 +20,25 @@ } }, "exclude": [ + ".gitattributes", + ".gitignore", + ".github", + ".rustfmt.toml", + ".vscode", + "Cargo.toml", + "Cargo.lock", "npm/", "target/" - ] + ], + "exports": "./mod.ts", + "imports": { + "@std/assert": "jsr:@std/assert@0.213.0", + "@std/io/": "jsr:/@std/io@0.213.0/", + "which_runtime": "jsr:/@david/which-runtime@0.2", + "@std/fmt/": "jsr:/@std/fmt@0.213.0/", + "@std/fs": "jsr:@std/fs@0.213.0", + "@std/path": "jsr:@std/path@0.213.0", + "@std/streams/": "jsr:/@std/streams@0.213.0/", + "which": "jsr:@david/which@0.3" + } } diff --git a/mod.test.ts b/mod.test.ts index 6a20ff2..7a6514e 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -2,8 +2,8 @@ import { readAll, readerFromStreamReader } from "./src/deps.ts"; import $, { build$, CommandBuilder, - CommandContext, - CommandHandler, + type CommandContext, + type CommandHandler, KillSignal, KillSignalController, Path, diff --git a/mod.ts b/mod.ts index ff1ddb2..67c4a43 100644 --- a/mod.ts +++ b/mod.ts @@ -8,8 +8,8 @@ import { } from "./src/command.ts"; import { Box, - Delay, - DelayIterator, + type Delay, + type DelayIterator, delayToIterator, delayToMs, formatMillis, @@ -19,32 +19,32 @@ import { } from "./src/common.ts"; import { confirm, - ConfirmOptions, + type ConfirmOptions, maybeConfirm, maybeMultiSelect, maybePrompt, maybeSelect, multiSelect, - MultiSelectOptions, + type MultiSelectOptions, ProgressBar, - ProgressOptions, + type ProgressOptions, prompt, - PromptOptions, + type PromptOptions, select, - SelectOptions, + type SelectOptions, } from "./src/console/mod.ts"; import { colors, outdent, which, whichSync } from "./src/deps.ts"; import { wasmInstance } from "./src/lib/mod.ts"; import { RequestBuilder, withProgressBarFactorySymbol } from "./src/request.ts"; import { createPath, Path } from "./src/path.ts"; -import { TemplateExpr } from "./src/command.ts"; +import type { TemplateExpr } from "./src/command.ts"; export type { Delay, DelayIterator } from "./src/common.ts"; export { TimeoutError } from "./src/common.ts"; export { FsFileWrapper, Path } from "./src/path.ts"; /** @deprecated Import `Path` instead. */ const PathRef = Path; -export { PathRef }; +export type { PathRef }; export type { ExpandGlobOptions, PathSymlinkOptions, SymlinkOptions, WalkEntry, WalkOptions } from "./src/path.ts"; export { CommandBuilder, diff --git a/src/command.ts b/src/command.ts index a01ba34..3f8e9d0 100644 --- a/src/command.ts +++ b/src/command.ts @@ -1,4 +1,4 @@ -import { CommandHandler } from "./command_handler.ts"; +import type { CommandHandler } from "./command_handler.ts"; import { cdCommand } from "./commands/cd.ts"; import { printEnvCommand } from "./commands/printenv.ts"; import { cpCommand, mvCommand } from "./commands/cp_mv.ts"; @@ -14,7 +14,7 @@ import { testCommand } from "./commands/test.ts"; import { touchCommand } from "./commands/touch.ts"; import { unsetCommand } from "./commands/unset.ts"; import { Box, delayToMs, errorToString, LoggerTreeBox } from "./common.ts"; -import { Delay } from "./common.ts"; +import type { Delay } from "./common.ts"; import { Buffer, colors, path, readerFromStreamReader, writerFromStreamWriter } from "./deps.ts"; import { CapturingBufferWriter, @@ -22,12 +22,12 @@ import { InheritStaticTextBypassWriter, NullPipeWriter, PipedBuffer, - Reader, - ShellPipeReaderKind, + type Reader, + type ShellPipeReaderKind, ShellPipeWriter, - ShellPipeWriterKind, - Writer, - WriterSync, + type ShellPipeWriterKind, + type Writer, + type WriterSync, } from "./pipes.ts"; import { parseCommand, spawn } from "./shell.ts"; import { isShowingProgressBars } from "./console/progress/interval.ts"; @@ -590,7 +590,7 @@ export class CommandBuilder implements PromiseLike { } /** @internal */ - [setCommandTextStateSymbol](textState: CommandBuilderStateCommand) { + [setCommandTextStateSymbol](textState: CommandBuilderStateCommand): CommandBuilder { return this.#newWithState((state) => { state.command = textState; }); diff --git a/src/command_handler.ts b/src/command_handler.ts index d297fcd..7d56eaf 100644 --- a/src/command_handler.ts +++ b/src/command_handler.ts @@ -1,6 +1,6 @@ -import { ExecuteResult } from "./result.ts"; +import type { ExecuteResult } from "./result.ts"; import type { KillSignal } from "./command.ts"; -import { Reader } from "./pipes.ts"; +import type { Reader } from "./pipes.ts"; /** Used to read from stdin. */ export type CommandPipeReader = "inherit" | "null" | Reader; diff --git a/src/commands/cat.ts b/src/commands/cat.ts index 7c74860..6212f20 100644 --- a/src/commands/cat.ts +++ b/src/commands/cat.ts @@ -1,5 +1,5 @@ -import { CommandContext } from "../command_handler.ts"; -import { ExecuteResult } from "../result.ts"; +import type { CommandContext } from "../command_handler.ts"; +import type { ExecuteResult } from "../result.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; import { errorToString, resolvePath } from "../common.ts"; diff --git a/src/commands/cd.ts b/src/commands/cd.ts index 1a8d6ca..3ab3f56 100644 --- a/src/commands/cd.ts +++ b/src/commands/cd.ts @@ -1,6 +1,6 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString, resolvePath } from "../common.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; export async function cdCommand(context: CommandContext): Promise { try { diff --git a/src/commands/cp_mv.ts b/src/commands/cp_mv.ts index 96b2462..b5e8d16 100644 --- a/src/commands/cp_mv.ts +++ b/src/commands/cp_mv.ts @@ -1,5 +1,5 @@ -import { CommandContext } from "../command_handler.ts"; -import { ExecuteResult } from "../result.ts"; +import type { CommandContext } from "../command_handler.ts"; +import type { ExecuteResult } from "../result.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; import { errorToString, resolvePath, safeLstat } from "../common.ts"; import { path } from "../deps.ts"; diff --git a/src/commands/echo.ts b/src/commands/echo.ts index 76a06f8..bec4129 100644 --- a/src/commands/echo.ts +++ b/src/commands/echo.ts @@ -1,6 +1,6 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; export function echoCommand(context: CommandContext): ExecuteResult | Promise { try { diff --git a/src/commands/exit.ts b/src/commands/exit.ts index f26ee26..1b4b48a 100644 --- a/src/commands/exit.ts +++ b/src/commands/exit.ts @@ -1,6 +1,6 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; export function exitCommand(context: CommandContext): ExecuteResult | Promise { try { diff --git a/src/commands/export.ts b/src/commands/export.ts index 5930c00..02330a9 100644 --- a/src/commands/export.ts +++ b/src/commands/export.ts @@ -1,5 +1,5 @@ -import { CommandContext } from "../command_handler.ts"; -import { EnvChange, ExecuteResult } from "../result.ts"; +import type { CommandContext } from "../command_handler.ts"; +import type { EnvChange, ExecuteResult } from "../result.ts"; export function exportCommand(context: CommandContext): ExecuteResult { const changes: EnvChange[] = []; diff --git a/src/commands/mkdir.ts b/src/commands/mkdir.ts index eb2738c..a1e14c8 100644 --- a/src/commands/mkdir.ts +++ b/src/commands/mkdir.ts @@ -1,6 +1,6 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString, resolvePath } from "../common.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; import { safeLstat } from "../common.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; diff --git a/src/commands/printenv.ts b/src/commands/printenv.ts index 84a3381..c390db7 100644 --- a/src/commands/printenv.ts +++ b/src/commands/printenv.ts @@ -1,6 +1,6 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; export function printEnvCommand(context: CommandContext): ExecuteResult | Promise { // windows expects env vars to be upcased diff --git a/src/commands/pwd.ts b/src/commands/pwd.ts index ba2c784..b8ab53d 100644 --- a/src/commands/pwd.ts +++ b/src/commands/pwd.ts @@ -1,7 +1,7 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; import { path } from "../deps.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; export function pwdCommand(context: CommandContext): ExecuteResult | Promise { diff --git a/src/commands/rm.ts b/src/commands/rm.ts index 52d667a..573b993 100644 --- a/src/commands/rm.ts +++ b/src/commands/rm.ts @@ -1,7 +1,7 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString, resolvePath } from "../common.ts"; -import { ExecuteResult } from "../result.ts"; -import { ArgKind, parseArgKinds } from "./args.ts"; +import type { ExecuteResult } from "../result.ts"; +import { type ArgKind, parseArgKinds } from "./args.ts"; export async function rmCommand( context: CommandContext, diff --git a/src/commands/sleep.ts b/src/commands/sleep.ts index 94bc52a..41ab172 100644 --- a/src/commands/sleep.ts +++ b/src/commands/sleep.ts @@ -1,6 +1,6 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; -import { ExecuteResult, getAbortedResult } from "../result.ts"; +import { type ExecuteResult, getAbortedResult } from "../result.ts"; export async function sleepCommand(context: CommandContext): Promise { try { diff --git a/src/commands/test.ts b/src/commands/test.ts index d99d6ee..7251347 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -1,7 +1,7 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString, resolvePath, safeLstat } from "../common.ts"; import { fs } from "../deps.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; export async function testCommand(context: CommandContext): Promise { try { diff --git a/src/commands/touch.ts b/src/commands/touch.ts index abffe42..6c0c12f 100644 --- a/src/commands/touch.ts +++ b/src/commands/touch.ts @@ -1,4 +1,4 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; diff --git a/src/commands/unset.ts b/src/commands/unset.ts index 714b9c5..fb99762 100644 --- a/src/commands/unset.ts +++ b/src/commands/unset.ts @@ -1,6 +1,6 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; export function unsetCommand(context: CommandContext): ExecuteResult | Promise { try { diff --git a/src/commands/which.ts b/src/commands/which.ts index ad14a3b..64e94ac 100644 --- a/src/commands/which.ts +++ b/src/commands/which.ts @@ -1,8 +1,8 @@ -import { CommandContext } from "../command_handler.ts"; +import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; -import { ExecuteResult } from "../result.ts"; +import type { ExecuteResult } from "../result.ts"; import { whichFromContext } from "../shell.ts"; -import { ArgKind, parseArgKinds } from "./args.ts"; +import { type ArgKind, parseArgKinds } from "./args.ts"; export async function whichCommand( context: CommandContext, diff --git a/src/common.ts b/src/common.ts index a1809ea..8cb5ff7 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,8 +1,8 @@ import { logger } from "./console/mod.ts"; import { BufReader, path } from "./deps.ts"; -import { Reader } from "./pipes.ts"; +import type { Reader } from "./pipes.ts"; -export const symbols = { +interface Symbols { /** Use this symbol to enable the provided object to be written to in * an output redirect within a template literal expression. * @@ -17,7 +17,7 @@ export const symbols = { * await $`echo 1 > ${myObj}`; * ``` */ - writable: Symbol.for("dax.writableStream"), + readonly writable: symbol; /** Use this symbol to enable the provided object to be read from in * an input redirect within a template literal expression. * @@ -32,6 +32,11 @@ export const symbols = { * await $`gzip < ${myObj}`; * ``` */ + readonly readable: symbol; +} + +export const symbols: Symbols = { + writable: Symbol.for("dax.writableStream"), readable: Symbol.for("dax.readableStream"), }; @@ -41,7 +46,7 @@ export class TimeoutError extends Error { super(message); } - get name() { + get name(): string { return "TimeoutError"; } } diff --git a/src/console/confirm.ts b/src/console/confirm.ts index ed2f3ba..ae5701e 100644 --- a/src/console/confirm.ts +++ b/src/console/confirm.ts @@ -1,5 +1,5 @@ import { colors } from "../deps.ts"; -import { createSelection, Keys, resultOrExit, SelectionOptions, TextItem } from "./utils.ts"; +import { createSelection, Keys, resultOrExit, type SelectionOptions, type TextItem } from "./utils.ts"; /** Options for showing confirming a yes or no question. */ export interface ConfirmOptions { diff --git a/src/console/logger.ts b/src/console/logger.ts index b9dfc73..626c4c5 100644 --- a/src/console/logger.ts +++ b/src/console/logger.ts @@ -1,4 +1,4 @@ -import { ConsoleSize, isOutputTty, safeConsoleSize, staticText, TextItem } from "./utils.ts"; +import { type ConsoleSize, isOutputTty, safeConsoleSize, staticText, type TextItem } from "./utils.ts"; export enum LoggerRefreshItemKind { ProgressBars, @@ -49,4 +49,5 @@ const logger = { logAboveStaticText, }; +// deno-lint-ignore verbatim-module-syntax -- Bug https://github.com/denoland/deno_lint/pull/1262 export { logger }; diff --git a/src/console/multiSelect.ts b/src/console/multiSelect.ts index 9e741f8..cb1a2f3 100644 --- a/src/console/multiSelect.ts +++ b/src/console/multiSelect.ts @@ -1,5 +1,5 @@ import { colors } from "../deps.ts"; -import { createSelection, Keys, resultOrExit, SelectionOptions, TextItem } from "./utils.ts"; +import { createSelection, Keys, resultOrExit, type SelectionOptions, type TextItem } from "./utils.ts"; /** Single options within a multi-select option. */ export interface MultiSelectOption { diff --git a/src/console/progress/interval.ts b/src/console/progress/interval.ts index c9f6140..3bb730a 100644 --- a/src/console/progress/interval.ts +++ b/src/console/progress/interval.ts @@ -1,5 +1,5 @@ import { logger, LoggerRefreshItemKind } from "../logger.ts"; -import { ConsoleSize, isOutputTty, TextItem } from "../utils.ts"; +import { type ConsoleSize, isOutputTty, type TextItem } from "../utils.ts"; export interface RenderIntervalProgressBar { render(size: ConsoleSize): TextItem[]; diff --git a/src/console/progress/mod.ts b/src/console/progress/mod.ts index 07f66e3..a568358 100644 --- a/src/console/progress/mod.ts +++ b/src/console/progress/mod.ts @@ -1,7 +1,7 @@ import { colors } from "../../deps.ts"; -import { ConsoleSize, isOutputTty, safeConsoleSize, TextItem } from "../utils.ts"; +import { type ConsoleSize, isOutputTty, safeConsoleSize, type TextItem } from "../utils.ts"; import { humanDownloadSize } from "./format.ts"; -import { addProgressBar, forceRender, removeProgressBar, RenderIntervalProgressBar } from "./interval.ts"; +import { addProgressBar, forceRender, removeProgressBar, type RenderIntervalProgressBar } from "./interval.ts"; export { isShowingProgressBars } from "./interval.ts"; diff --git a/src/console/prompt.ts b/src/console/prompt.ts index 797a698..ebafd32 100644 --- a/src/console/prompt.ts +++ b/src/console/prompt.ts @@ -1,5 +1,5 @@ import { colors } from "../deps.ts"; -import { createSelection, Keys, resultOrExit, SelectionOptions, TextItem } from "./utils.ts"; +import { createSelection, Keys, resultOrExit, type SelectionOptions, type TextItem } from "./utils.ts"; /** Options for showing an input where the user enters a value. */ export interface PromptOptions { diff --git a/src/console/select.ts b/src/console/select.ts index 2d65d67..99fb030 100644 --- a/src/console/select.ts +++ b/src/console/select.ts @@ -1,5 +1,5 @@ import { colors } from "../deps.ts"; -import { createSelection, Keys, resultOrExit, SelectionOptions, TextItem } from "./utils.ts"; +import { createSelection, Keys, resultOrExit, type SelectionOptions, type TextItem } from "./utils.ts"; /** Options for showing a selection that only has one result. */ export interface SelectOptions { diff --git a/src/console/testUtils.ts b/src/console/testUtils.ts index 49f5da3..d939ffb 100644 --- a/src/console/testUtils.ts +++ b/src/console/testUtils.ts @@ -1,5 +1,5 @@ import { wasmInstance } from "../lib/mod.ts"; -import { Keys, SelectionOptions } from "./utils.ts"; +import type { Keys, SelectionOptions } from "./utils.ts"; export function createTester( renderer: Pick, "render" | "onKey">, diff --git a/src/deps.test.ts b/src/deps.test.ts index 9fdc4e1..7ea9aac 100644 --- a/src/deps.test.ts +++ b/src/deps.test.ts @@ -1,16 +1,9 @@ -import { createPath, Path } from "./path.ts"; +import { createPath, type Path } from "./path.ts"; -export { - assert, - assertEquals, - assertMatch, - assertRejects, - assertStringIncludes, - assertThrows, -} from "https://deno.land/std@0.213.0/assert/mod.ts"; -export { toWritableStream } from "https://deno.land/std@0.213.0/io/to_writable_stream.ts"; -export { toReadableStream } from "https://deno.land/std@0.213.0/io/to_readable_stream.ts"; -export { isNode } from "https://deno.land/x/which_runtime@0.2.0/mod.ts"; +export { assert, assertEquals, assertMatch, assertRejects, assertStringIncludes, assertThrows } from "@std/assert"; +export { toWritableStream } from "@std/io/to_writable_stream"; +export { toReadableStream } from "@std/io/to_readable_stream"; +export { isNode } from "which_runtime"; /** * Creates a temporary directory, changes the cwd to this directory, diff --git a/src/deps.ts b/src/deps.ts index 3083e47..8fc6ee4 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -1,19 +1,19 @@ -export * as colors from "https://deno.land/std@0.213.0/fmt/colors.ts"; -export * as fs from "https://deno.land/std@0.213.0/fs/mod.ts"; -export { Buffer } from "https://deno.land/std@0.213.0/io/buffer.ts"; -export { BufReader } from "https://deno.land/std@0.213.0/io/buf_reader.ts"; -export * as path from "https://deno.land/std@0.213.0/path/mod.ts"; -export { readAll } from "https://deno.land/std@0.213.0/io/read_all.ts"; -export { readerFromStreamReader } from "https://deno.land/std@0.213.0/streams/reader_from_stream_reader.ts"; -export { writeAll, writeAllSync } from "https://deno.land/std@0.213.0/io/write_all.ts"; +export * as colors from "@std/fmt/colors"; +export * as fs from "@std/fs"; +export { Buffer } from "@std/io/buffer"; +export { BufReader } from "@std/io/buf_reader"; +export * as path from "@std/path"; +export { readAll } from "@std/io/read_all"; +export { readerFromStreamReader } from "@std/streams/reader_from_stream_reader"; +export { writeAll, writeAllSync } from "@std/io/write_all"; export { outdent } from "./vendor/outdent.ts"; -export { RealEnvironment as DenoWhichRealEnvironment, which, whichSync } from "https://deno.land/x/which@0.3.0/mod.ts"; -export { writerFromStreamWriter } from "https://deno.land/std@0.213.0/streams/writer_from_stream_writer.ts"; +export { RealEnvironment as DenoWhichRealEnvironment, which, whichSync } from "which"; +export { writerFromStreamWriter } from "@std/streams/writer_from_stream_writer"; -export { emptyDir, emptyDirSync } from "https://deno.land/std@0.213.0/fs/empty_dir.ts"; -export { ensureDir, ensureDirSync } from "https://deno.land/std@0.213.0/fs/ensure_dir.ts"; -export { ensureFile, ensureFileSync } from "https://deno.land/std@0.213.0/fs/ensure_file.ts"; -export { expandGlob, type ExpandGlobOptions, expandGlobSync } from "https://deno.land/std@0.213.0/fs/expand_glob.ts"; -export { move, moveSync } from "https://deno.land/std@0.213.0/fs/move.ts"; -export { copy, copySync } from "https://deno.land/std@0.213.0/fs/copy.ts"; -export { walk, type WalkEntry, WalkError, type WalkOptions, walkSync } from "https://deno.land/std@0.213.0/fs/walk.ts"; +export { emptyDir, emptyDirSync } from "@std/fs/empty_dir"; +export { ensureDir, ensureDirSync } from "@std/fs/ensure_dir"; +export { ensureFile, ensureFileSync } from "@std/fs/ensure_file"; +export { expandGlob, type ExpandGlobOptions, expandGlobSync } from "@std/fs/expand_glob"; +export { move, moveSync } from "@std/fs/move"; +export { copy, copySync } from "@std/fs/copy"; +export { walk, type WalkEntry, WalkError, type WalkOptions, walkSync } from "@std/fs/walk"; diff --git a/src/pipes.ts b/src/pipes.ts index e77f779..b9e3519 100644 --- a/src/pipes.ts +++ b/src/pipes.ts @@ -1,4 +1,4 @@ -import { type FsFileWrapper, Path } from "./path.ts"; +import type { FsFileWrapper, Path } from "./path.ts"; import { logger } from "./console/logger.ts"; import { Buffer, writeAll, writeAllSync } from "./deps.ts"; import type { RequestBuilder } from "./request.ts"; diff --git a/src/request.ts b/src/request.ts index aa7f69d..f7316bc 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,7 +1,7 @@ import { formatMillis, symbols } from "./common.ts"; import { TimeoutError } from "./common.ts"; -import { Delay, delayToMs, filterEmptyRecordValues, getFileNameFromUrl } from "./common.ts"; -import { ProgressBar } from "./console/mod.ts"; +import { type Delay, delayToMs, filterEmptyRecordValues, getFileNameFromUrl } from "./common.ts"; +import type { ProgressBar } from "./console/mod.ts"; import { Path } from "./path.ts"; interface RequestBuilderState { diff --git a/src/runtimes/process.deno.ts b/src/runtimes/process.deno.ts index 142294e..ecba188 100644 --- a/src/runtimes/process.deno.ts +++ b/src/runtimes/process.deno.ts @@ -1,4 +1,4 @@ -import { SpawnCommand } from "./process.common.ts"; +import type { SpawnCommand } from "./process.common.ts"; export const spawnCommand: SpawnCommand = (path, options) => { const child = new Deno.Command(path, options).spawn(); diff --git a/src/runtimes/process.node.ts b/src/runtimes/process.node.ts index fc7594c..8207a07 100644 --- a/src/runtimes/process.node.ts +++ b/src/runtimes/process.node.ts @@ -1,6 +1,6 @@ import * as cp from "node:child_process"; import { Readable, Writable } from "node:stream"; -import { SpawnCommand } from "./process.common.ts"; +import type { SpawnCommand } from "./process.common.ts"; import { getSignalAbortCode } from "../command.ts"; function toNodeStdio(stdio: "inherit" | "null" | "piped") { diff --git a/src/shell.ts b/src/shell.ts index ff91a26..fe3f758 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -1,6 +1,6 @@ -import { KillSignal } from "./command.ts"; -import { CommandContext, CommandHandler, type CommandPipeReader } from "./command_handler.ts"; -import { errorToString, getExecutableShebangFromPath, ShebangInfo } from "./common.ts"; +import type { KillSignal } from "./command.ts"; +import type { CommandContext, CommandHandler, CommandPipeReader } from "./command_handler.ts"; +import { errorToString, getExecutableShebangFromPath, type ShebangInfo } from "./common.ts"; import { DenoWhichRealEnvironment, fs, path, which } from "./deps.ts"; import { wasmInstance } from "./lib/mod.ts"; import { @@ -8,14 +8,14 @@ import { NullPipeWriter, pipeReadableToWriterSync, PipeSequencePipe, - PipeWriter, - Reader, - ShellPipeReaderKind, + type PipeWriter, + type Reader, + type ShellPipeReaderKind, ShellPipeWriter, - ShellPipeWriterKind, + type ShellPipeWriterKind, } from "./pipes.ts"; -import { EnvChange, ExecuteResult, getAbortedResult } from "./result.ts"; -import { SpawnedChildProcess } from "./runtimes/process.common.ts"; +import { type EnvChange, type ExecuteResult, getAbortedResult } from "./result.ts"; +import type { SpawnedChildProcess } from "./runtimes/process.common.ts"; import { spawnCommand } from "./runtimes/process.deno.ts"; const neverAbortedSignal = new AbortController().signal; diff --git a/src/test/server.deno.ts b/src/test/server.deno.ts index cb82043..a7d5827 100644 --- a/src/test/server.deno.ts +++ b/src/test/server.deno.ts @@ -1,4 +1,4 @@ -import { Server, StartServerHandler } from "./server.common.ts"; +import type { Server, StartServerHandler } from "./server.common.ts"; export const startServer: StartServerHandler = (options) => { return new Promise((resolve, _reject) => { diff --git a/src/test/server.node.ts b/src/test/server.node.ts index 1212c97..4a96fc8 100644 --- a/src/test/server.node.ts +++ b/src/test/server.node.ts @@ -1,5 +1,5 @@ import http from "node:http"; -import { Server, StartServerHandler } from "./server.common.ts"; +import type { Server, StartServerHandler } from "./server.common.ts"; export const startServer: StartServerHandler = (options) => { return new Promise((resolve, reject) => { diff --git a/src/vendor/outdent.ts b/src/vendor/outdent.ts index 5abe4c0..886e916 100644 --- a/src/vendor/outdent.ts +++ b/src/vendor/outdent.ts @@ -163,7 +163,7 @@ function createInstance(options: Options): Outdent { return fullOutdent; } -const defaultOutdent = createInstance({ +const defaultOutdent: Outdent = createInstance({ trimLeadingNewline: true, trimTrailingNewline: true, }); @@ -189,6 +189,7 @@ export interface Outdent { // */ // pass(strings: TemplateStringsArray, ...values: Array): [TemplateStringsArray, ...Array]; } + export interface Options { trimLeadingNewline?: boolean; trimTrailingNewline?: boolean; From a5ef5fa614e3be1343c58fee8199dbf1714f95d7 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 6 Apr 2024 12:32:43 -0400 Subject: [PATCH 2/5] Start moving away from deps.ts pattern --- deno.json | 16 ++++++++-------- mod.test.ts | 3 ++- mod.ts | 7 +++++-- src/command.ts | 3 ++- src/commands/test.ts | 4 ++-- src/console/confirm.ts | 2 +- src/console/multiSelect.ts | 2 +- src/console/progress/mod.ts | 2 +- src/console/prompt.ts | 2 +- src/console/select.ts | 2 +- src/deps.test.ts | 4 ++-- src/deps.ts | 20 +++++--------------- src/path.test.ts | 8 +++++--- src/path.ts | 28 ++++++++++------------------ src/shell.ts | 5 +++-- 15 files changed, 49 insertions(+), 59 deletions(-) diff --git a/deno.json b/deno.json index d9ae36c..982b453 100644 --- a/deno.json +++ b/deno.json @@ -32,13 +32,13 @@ ], "exports": "./mod.ts", "imports": { - "@std/assert": "jsr:@std/assert@0.213.0", - "@std/io/": "jsr:/@std/io@0.213.0/", - "which_runtime": "jsr:/@david/which-runtime@0.2", - "@std/fmt/": "jsr:/@std/fmt@0.213.0/", - "@std/fs": "jsr:@std/fs@0.213.0", - "@std/path": "jsr:@std/path@0.213.0", - "@std/streams/": "jsr:/@std/streams@0.213.0/", - "which": "jsr:@david/which@0.3" + "@std/assert": "jsr:@std/assert@^0.221.0", + "@std/fmt": "jsr:@std/fmt@^0.221.0", + "@std/fs": "jsr:@std/fs@0.221.0", + "@std/io": "jsr:@std/io@0.221.0", + "@std/path": "jsr:@std/path@0.221.0", + "@std/streams": "jsr:@std/streams@0.221.0", + "which": "jsr:@david/which@0.3", + "which_runtime": "jsr:@david/which-runtime@0.2" } } diff --git a/mod.test.ts b/mod.test.ts index 7a6514e..4a3aa0a 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -21,7 +21,8 @@ import { usingTempDir, withTempDir, } from "./src/deps.test.ts"; -import { Buffer, colors, path } from "./src/deps.ts"; +import * as colors from "@std/fmt/colors"; +import { Buffer, path } from "./src/deps.ts"; import { setNotTtyForTesting } from "./src/console/utils.ts"; // Deno will not be a tty because it captures the pipes, but Node diff --git a/mod.ts b/mod.ts index 67c4a43..f3dd9dd 100644 --- a/mod.ts +++ b/mod.ts @@ -33,7 +33,8 @@ import { select, type SelectOptions, } from "./src/console/mod.ts"; -import { colors, outdent, which, whichSync } from "./src/deps.ts"; +import * as colors from "@std/fmt/colors"; +import { outdent, which, whichSync } from "./src/deps.ts"; import { wasmInstance } from "./src/lib/mod.ts"; import { RequestBuilder, withProgressBarFactorySymbol } from "./src/request.ts"; import { createPath, Path } from "./src/path.ts"; @@ -44,7 +45,9 @@ export { TimeoutError } from "./src/common.ts"; export { FsFileWrapper, Path } from "./src/path.ts"; /** @deprecated Import `Path` instead. */ const PathRef = Path; -export type { PathRef }; +// bug in deno: https://github.com/denoland/deno_lint/pull/1262 +// deno-lint-ignore verbatim-module-syntax +export { PathRef }; export type { ExpandGlobOptions, PathSymlinkOptions, SymlinkOptions, WalkEntry, WalkOptions } from "./src/path.ts"; export { CommandBuilder, diff --git a/src/command.ts b/src/command.ts index 3f8e9d0..38d51b5 100644 --- a/src/command.ts +++ b/src/command.ts @@ -15,7 +15,8 @@ import { touchCommand } from "./commands/touch.ts"; import { unsetCommand } from "./commands/unset.ts"; import { Box, delayToMs, errorToString, LoggerTreeBox } from "./common.ts"; import type { Delay } from "./common.ts"; -import { Buffer, colors, path, readerFromStreamReader, writerFromStreamWriter } from "./deps.ts"; +import * as colors from "@std/fmt/colors"; +import { Buffer, path, readerFromStreamReader, writerFromStreamWriter } from "./deps.ts"; import { CapturingBufferWriter, CapturingBufferWriterSync, diff --git a/src/commands/test.ts b/src/commands/test.ts index 7251347..53f20b5 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -1,6 +1,6 @@ import type { CommandContext } from "../command_handler.ts"; import { errorToString, resolvePath, safeLstat } from "../common.ts"; -import { fs } from "../deps.ts"; +import { exists } from "@std/fs/exists"; import type { ExecuteResult } from "../result.ts"; export async function testCommand(context: CommandContext): Promise { @@ -17,7 +17,7 @@ export async function testCommand(context: CommandContext): Promise { const path = createPath("src"); @@ -110,7 +112,7 @@ Deno.test("components", () => { assert(!component.includes("/")); assert(!component.includes("\\")); } - let expectedLength = srcDir.toString().split(stdPath.SEP).length; + let expectedLength = srcDir.toString().split(stdPath.SEPARATOR).length; if (Deno.build.os !== "windows") { expectedLength--; // for leading slash } diff --git a/src/path.ts b/src/path.ts index d44c7c2..de4abd9 100644 --- a/src/path.ts +++ b/src/path.ts @@ -1,31 +1,23 @@ -import { - emptyDir, - emptyDirSync, - ensureDir, - ensureDirSync, - ensureFile, - ensureFileSync, - expandGlob, - expandGlobSync, - path as stdPath, - walk, - walkSync, - writeAll, - writeAllSync, -} from "./deps.ts"; +import { path as stdPath, writeAll, writeAllSync } from "./deps.ts"; + +import { emptyDir, emptyDirSync } from "@std/fs/empty-dir"; +import { ensureDir, ensureDirSync } from "@std/fs/ensure-dir"; +import { ensureFile, ensureFileSync } from "@std/fs/ensure-file"; +import { expandGlob, expandGlobSync } from "@std/fs/expand-glob"; +import { walk, walkSync } from "@std/fs/walk"; import { symbols } from "./common.ts"; /** * `ExpandGlobOptions` from https://deno.land/std/fs/expand_glob.ts * @internal */ -type DenoStdExpandGlobOptions = import("./deps.ts").ExpandGlobOptions; +type DenoStdExpandGlobOptions = import("@std/fs/expand-glob").ExpandGlobOptions; export type ExpandGlobOptions = DenoStdExpandGlobOptions; /** * `WalkOptions` from https://deno.land/std/fs/walk.ts * @internal */ -type DenoStdWalkOptions = import("./deps.ts").WalkOptions; +type DenoStdWalkOptions = import("@std/fs/walk").WalkOptions; export type WalkOptions = DenoStdWalkOptions; const PERIOD_CHAR_CODE = ".".charCodeAt(0); @@ -470,7 +462,7 @@ export class Path { } } - #stdWalkEntryToDax(entry: import("./deps.ts").WalkEntry): WalkEntry { + #stdWalkEntryToDax(entry: import("@std/fs/walk").WalkEntry): WalkEntry { return { ...entry, path: new Path(entry.path), diff --git a/src/shell.ts b/src/shell.ts index fe3f758..91c2f77 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -1,7 +1,8 @@ import type { KillSignal } from "./command.ts"; import type { CommandContext, CommandHandler, CommandPipeReader } from "./command_handler.ts"; import { errorToString, getExecutableShebangFromPath, type ShebangInfo } from "./common.ts"; -import { DenoWhichRealEnvironment, fs, path, which } from "./deps.ts"; +import { existsSync } from "@std/fs/exists"; +import { DenoWhichRealEnvironment, path, which } from "./deps.ts"; import { wasmInstance } from "./lib/mod.ts"; import { NullPipeReader, @@ -897,7 +898,7 @@ async function executeSimpleCommand(command: SimpleCommand, parentContext: Conte } function checkMapCwdNotExistsError(cwd: string, err: unknown) { - if ((err as any).code === "ENOENT" && !fs.existsSync(cwd)) { + if ((err as any).code === "ENOENT" && !existsSync(cwd)) { throw new Error(`Failed to launch command because the cwd does not exist (${cwd}).`, { cause: err, }); From db35af96f4440840731b3498b2543ce001eed983 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 6 Apr 2024 12:47:12 -0400 Subject: [PATCH 3/5] Move away from deps.ts --- mod.test.ts | 24 +++++++++--------------- mod.ts | 19 ++++++++++--------- src/command.test.ts | 2 +- src/command.ts | 23 +++++++++++++---------- src/command_handler.ts | 2 +- src/commands/args.test.ts | 2 +- src/commands/cat.test.ts | 2 +- src/commands/cat.ts | 2 +- src/commands/cp_mv.ts | 4 ++-- src/commands/mkdir.test.ts | 2 +- src/commands/mkdir.ts | 2 +- src/commands/pwd.test.ts | 2 +- src/commands/pwd.ts | 2 +- src/commands/rm.test.ts | 2 +- src/commands/test.ts | 2 +- src/common.test.ts | 5 +++-- src/common.ts | 3 ++- src/console/confirm.test.ts | 2 +- src/console/multiSelect.test.ts | 2 +- src/console/progress/format.test.ts | 2 +- src/console/progress/mod.test.ts | 2 +- src/console/prompt.test.ts | 2 +- src/console/select.test.ts | 2 +- src/deps.ts | 9 --------- src/path.test.ts | 4 ++-- src/path.ts | 8 +++++--- src/pipes.test.ts | 4 ++-- src/pipes.ts | 9 +++++---- src/request.test.ts | 11 +++++++---- src/runtimes/process.node.ts | 2 +- src/shell.ts | 5 +++-- src/{deps.test.ts => with_temp_dir.ts} | 5 ----- 32 files changed, 81 insertions(+), 88 deletions(-) delete mode 100644 src/deps.ts rename src/{deps.test.ts => with_temp_dir.ts} (73%) diff --git a/mod.test.ts b/mod.test.ts index 4a3aa0a..4ac3112 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -1,4 +1,11 @@ -import { readAll, readerFromStreamReader } from "./src/deps.ts"; +import { assert, assertEquals, assertMatch, assertRejects, assertStringIncludes, assertThrows } from "@std/assert"; +import * as colors from "@std/fmt/colors"; +import { Buffer } from "@std/io/buffer"; +import { readAll } from "@std/io/read-all"; +import { toWritableStream } from "@std/io/to-writable-stream"; +import * as path from "@std/path"; +import { readerFromStreamReader } from "@std/streams/reader-from-stream-reader"; +import { isNode } from "which_runtime"; import $, { build$, CommandBuilder, @@ -9,21 +16,8 @@ import $, { Path, PathRef, } from "./mod.ts"; -import { - assert, - assertEquals, - assertMatch, - assertRejects, - assertStringIncludes, - assertThrows, - isNode, - toWritableStream, - usingTempDir, - withTempDir, -} from "./src/deps.test.ts"; -import * as colors from "@std/fmt/colors"; -import { Buffer, path } from "./src/deps.ts"; import { setNotTtyForTesting } from "./src/console/utils.ts"; +import { usingTempDir, withTempDir } from "./src/with_temp_dir.ts"; // Deno will not be a tty because it captures the pipes, but Node // will be, so manually say that we're not a tty for testing so diff --git a/mod.ts b/mod.ts index f3dd9dd..baaaa4f 100644 --- a/mod.ts +++ b/mod.ts @@ -1,3 +1,5 @@ +import * as colors from "@std/fmt/colors"; +import { which, whichSync } from "which"; import { CommandBuilder, escapeArg, @@ -6,6 +8,7 @@ import { template, templateRaw, } from "./src/command.ts"; +import type { TemplateExpr } from "./src/command.ts"; import { Box, type Delay, @@ -33,12 +36,10 @@ import { select, type SelectOptions, } from "./src/console/mod.ts"; -import * as colors from "@std/fmt/colors"; -import { outdent, which, whichSync } from "./src/deps.ts"; import { wasmInstance } from "./src/lib/mod.ts"; -import { RequestBuilder, withProgressBarFactorySymbol } from "./src/request.ts"; import { createPath, Path } from "./src/path.ts"; -import type { TemplateExpr } from "./src/command.ts"; +import { RequestBuilder, withProgressBarFactorySymbol } from "./src/request.ts"; +import { outdent } from "./src/vendor/outdent.ts"; export type { Delay, DelayIterator } from "./src/common.ts"; export { TimeoutError } from "./src/common.ts"; @@ -48,7 +49,6 @@ const PathRef = Path; // bug in deno: https://github.com/denoland/deno_lint/pull/1262 // deno-lint-ignore verbatim-module-syntax export { PathRef }; -export type { ExpandGlobOptions, PathSymlinkOptions, SymlinkOptions, WalkEntry, WalkOptions } from "./src/path.ts"; export { CommandBuilder, CommandChild, @@ -59,7 +59,6 @@ export { type TemplateExpr, } from "./src/command.ts"; export type { CommandContext, CommandHandler, CommandPipeReader, CommandPipeWriter } from "./src/command_handler.ts"; -export type { Closer, Reader, ShellPipeReaderKind, ShellPipeWriterKind, WriterSync } from "./src/pipes.ts"; export type { ConfirmOptions, MultiSelectOption, @@ -70,6 +69,8 @@ export type { PromptOptions, SelectOptions, } from "./src/console/mod.ts"; +export type { ExpandGlobOptions, PathSymlinkOptions, SymlinkOptions, WalkEntry, WalkOptions } from "./src/path.ts"; +export type { Closer, Reader, ShellPipeReaderKind, ShellPipeWriterKind, WriterSync } from "./src/pipes.ts"; export { RequestBuilder, RequestResponse } from "./src/request.ts"; // these are used when registering commands export type { @@ -138,17 +139,17 @@ export interface $Template { * `outdent` from the https://deno.land/x/outdent module. * @internal */ -type Outdent = typeof import("./src/deps.ts").outdent; +type Outdent = typeof outdent; /** * `which` from the https://deno.land/x/which module. * @internal */ -type Which = typeof import("./src/deps.ts").which; +type Which = typeof import("which").which; /** * `whichSync` from the https://deno.land/x/which module. * @internal */ -type WhichSync = typeof import("./src/deps.ts").whichSync; +type WhichSync = typeof import("which").whichSync; /** Collection of built-in properties that come with a `$`. */ export interface $BuiltInProperties { diff --git a/src/command.test.ts b/src/command.test.ts index d326bbf..d10ed00 100644 --- a/src/command.test.ts +++ b/src/command.test.ts @@ -1,5 +1,5 @@ +import { assertEquals } from "@std/assert"; import { escapeArg } from "./command.ts"; -import { assertEquals } from "./deps.test.ts"; Deno.test("escapes arg", () => { assertEquals(escapeArg("hello"), "hello"); diff --git a/src/command.ts b/src/command.ts index 38d51b5..7b2314e 100644 --- a/src/command.ts +++ b/src/command.ts @@ -1,22 +1,29 @@ +import * as colors from "@std/fmt/colors"; +import { Buffer } from "@std/io/buffer"; +import * as path from "@std/path"; +import { readerFromStreamReader } from "@std/streams/reader-from-stream-reader"; +import { writerFromStreamWriter } from "@std/streams/writer-from-stream-writer"; import type { CommandHandler } from "./command_handler.ts"; +import { catCommand } from "./commands/cat.ts"; import { cdCommand } from "./commands/cd.ts"; -import { printEnvCommand } from "./commands/printenv.ts"; import { cpCommand, mvCommand } from "./commands/cp_mv.ts"; import { echoCommand } from "./commands/echo.ts"; -import { catCommand } from "./commands/cat.ts"; import { exitCommand } from "./commands/exit.ts"; import { exportCommand } from "./commands/export.ts"; import { mkdirCommand } from "./commands/mkdir.ts"; -import { rmCommand } from "./commands/rm.ts"; +import { printEnvCommand } from "./commands/printenv.ts"; import { pwdCommand } from "./commands/pwd.ts"; +import { rmCommand } from "./commands/rm.ts"; import { sleepCommand } from "./commands/sleep.ts"; import { testCommand } from "./commands/test.ts"; import { touchCommand } from "./commands/touch.ts"; import { unsetCommand } from "./commands/unset.ts"; +import { whichCommand } from "./commands/which.ts"; import { Box, delayToMs, errorToString, LoggerTreeBox } from "./common.ts"; import type { Delay } from "./common.ts"; -import * as colors from "@std/fmt/colors"; -import { Buffer, path, readerFromStreamReader, writerFromStreamWriter } from "./deps.ts"; +import { symbols } from "./common.ts"; +import { isShowingProgressBars } from "./console/progress/interval.ts"; +import { Path } from "./path.ts"; import { CapturingBufferWriter, CapturingBufferWriterSync, @@ -30,13 +37,9 @@ import { type Writer, type WriterSync, } from "./pipes.ts"; -import { parseCommand, spawn } from "./shell.ts"; -import { isShowingProgressBars } from "./console/progress/interval.ts"; -import { Path } from "./path.ts"; import { RequestBuilder } from "./request.ts"; +import { parseCommand, spawn } from "./shell.ts"; import { StreamFds } from "./shell.ts"; -import { symbols } from "./common.ts"; -import { whichCommand } from "./commands/which.ts"; type BufferStdio = "inherit" | "null" | "streamed" | Buffer; type StreamKind = "stdout" | "stderr" | "combined"; diff --git a/src/command_handler.ts b/src/command_handler.ts index 7d56eaf..cb21280 100644 --- a/src/command_handler.ts +++ b/src/command_handler.ts @@ -1,6 +1,6 @@ -import type { ExecuteResult } from "./result.ts"; import type { KillSignal } from "./command.ts"; import type { Reader } from "./pipes.ts"; +import type { ExecuteResult } from "./result.ts"; /** Used to read from stdin. */ export type CommandPipeReader = "inherit" | "null" | Reader; diff --git a/src/commands/args.test.ts b/src/commands/args.test.ts index af289bd..0bd376e 100644 --- a/src/commands/args.test.ts +++ b/src/commands/args.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../deps.test.ts"; +import { assertEquals } from "@std/assert"; import { parseArgKinds } from "./args.ts"; Deno.test("parses", () => { diff --git a/src/commands/cat.test.ts b/src/commands/cat.test.ts index f70fa83..7788494 100644 --- a/src/commands/cat.test.ts +++ b/src/commands/cat.test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertThrows } from "../deps.test.ts"; +import { assertEquals, assertThrows } from "@std/assert"; import { parseCatArgs } from "./cat.ts"; Deno.test("test cat parse args", () => { diff --git a/src/commands/cat.ts b/src/commands/cat.ts index 6212f20..00827ed 100644 --- a/src/commands/cat.ts +++ b/src/commands/cat.ts @@ -1,7 +1,7 @@ import type { CommandContext } from "../command_handler.ts"; +import { errorToString, resolvePath } from "../common.ts"; import type { ExecuteResult } from "../result.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; -import { errorToString, resolvePath } from "../common.ts"; interface CatFlags { paths: string[]; diff --git a/src/commands/cp_mv.ts b/src/commands/cp_mv.ts index b5e8d16..e61fc5b 100644 --- a/src/commands/cp_mv.ts +++ b/src/commands/cp_mv.ts @@ -1,8 +1,8 @@ +import * as path from "@std/path"; import type { CommandContext } from "../command_handler.ts"; +import { errorToString, resolvePath, safeLstat } from "../common.ts"; import type { ExecuteResult } from "../result.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; -import { errorToString, resolvePath, safeLstat } from "../common.ts"; -import { path } from "../deps.ts"; export async function cpCommand( context: CommandContext, diff --git a/src/commands/mkdir.test.ts b/src/commands/mkdir.test.ts index b24f4c3..1cdda11 100644 --- a/src/commands/mkdir.test.ts +++ b/src/commands/mkdir.test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertThrows } from "../deps.test.ts"; +import { assertEquals, assertThrows } from "@std/assert"; import { parseArgs } from "./mkdir.ts"; Deno.test("test mkdir parse args", () => { diff --git a/src/commands/mkdir.ts b/src/commands/mkdir.ts index a1e14c8..b5ebf0f 100644 --- a/src/commands/mkdir.ts +++ b/src/commands/mkdir.ts @@ -1,7 +1,7 @@ import type { CommandContext } from "../command_handler.ts"; import { errorToString, resolvePath } from "../common.ts"; -import type { ExecuteResult } from "../result.ts"; import { safeLstat } from "../common.ts"; +import type { ExecuteResult } from "../result.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; export async function mkdirCommand( diff --git a/src/commands/pwd.test.ts b/src/commands/pwd.test.ts index e8d2695..940dbbf 100644 --- a/src/commands/pwd.test.ts +++ b/src/commands/pwd.test.ts @@ -1,4 +1,4 @@ -import { assert, assertEquals, assertThrows } from "../deps.test.ts"; +import { assert, assertEquals, assertThrows } from "@std/assert"; import { parseArgs } from "./pwd.ts"; Deno.test("pwd: parseArgs", () => { diff --git a/src/commands/pwd.ts b/src/commands/pwd.ts index b8ab53d..15be017 100644 --- a/src/commands/pwd.ts +++ b/src/commands/pwd.ts @@ -1,6 +1,6 @@ +import * as path from "@std/path"; import type { CommandContext } from "../command_handler.ts"; import { errorToString } from "../common.ts"; -import { path } from "../deps.ts"; import type { ExecuteResult } from "../result.ts"; import { bailUnsupported, parseArgKinds } from "./args.ts"; diff --git a/src/commands/rm.test.ts b/src/commands/rm.test.ts index 5b280b0..4780260 100644 --- a/src/commands/rm.test.ts +++ b/src/commands/rm.test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertThrows } from "../deps.test.ts"; +import { assertEquals, assertThrows } from "@std/assert"; import { parseArgs } from "./rm.ts"; Deno.test("parse rm arguments", () => { diff --git a/src/commands/test.ts b/src/commands/test.ts index 53f20b5..ccd669f 100644 --- a/src/commands/test.ts +++ b/src/commands/test.ts @@ -1,6 +1,6 @@ +import { exists } from "@std/fs/exists"; import type { CommandContext } from "../command_handler.ts"; import { errorToString, resolvePath, safeLstat } from "../common.ts"; -import { exists } from "@std/fs/exists"; import type { ExecuteResult } from "../result.ts"; export async function testCommand(context: CommandContext): Promise { diff --git a/src/common.test.ts b/src/common.test.ts index 7e0bd4c..e896b22 100644 --- a/src/common.test.ts +++ b/src/common.test.ts @@ -1,3 +1,6 @@ +import { assertEquals } from "@std/assert"; +import { Buffer } from "@std/io/buffer"; +import * as path from "@std/path"; import { delayToIterator, delayToMs, @@ -7,8 +10,6 @@ import { resolvePath, TreeBox, } from "./common.ts"; -import { assertEquals } from "./deps.test.ts"; -import { Buffer, path } from "./deps.ts"; Deno.test("should get delay value", () => { assertEquals(delayToMs(10), 10); diff --git a/src/common.ts b/src/common.ts index 8cb5ff7..94b5bd2 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,5 +1,6 @@ +import { BufReader } from "@std/io/buf-reader"; +import * as path from "@std/path"; import { logger } from "./console/mod.ts"; -import { BufReader, path } from "./deps.ts"; import type { Reader } from "./pipes.ts"; interface Symbols { diff --git a/src/console/confirm.test.ts b/src/console/confirm.test.ts index 2dbcac5..3d26d3b 100644 --- a/src/console/confirm.test.ts +++ b/src/console/confirm.test.ts @@ -1,5 +1,5 @@ +import { assertEquals } from "@std/assert"; import { innerConfirm } from "./confirm.ts"; -import { assertEquals } from "../deps.test.ts"; import { createTester } from "./testUtils.ts"; import { Keys } from "./utils.ts"; diff --git a/src/console/multiSelect.test.ts b/src/console/multiSelect.test.ts index 0fdaba5..d52af2e 100644 --- a/src/console/multiSelect.test.ts +++ b/src/console/multiSelect.test.ts @@ -1,5 +1,5 @@ +import { assertEquals } from "@std/assert"; import { innerMultiSelect } from "./multiSelect.ts"; -import { assertEquals } from "../deps.test.ts"; import { createTester } from "./testUtils.ts"; import { Keys } from "./utils.ts"; diff --git a/src/console/progress/format.test.ts b/src/console/progress/format.test.ts index 6e919b8..99436af 100644 --- a/src/console/progress/format.test.ts +++ b/src/console/progress/format.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../../deps.test.ts"; +import { assertEquals } from "@std/assert"; import { humanDownloadSize } from "./format.ts"; Deno.test("should format bytes", () => { diff --git a/src/console/progress/mod.test.ts b/src/console/progress/mod.test.ts index 763658f..325124e 100644 --- a/src/console/progress/mod.test.ts +++ b/src/console/progress/mod.test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../../deps.test.ts"; +import { assertEquals } from "@std/assert"; import { wasmInstance } from "../../lib/mod.ts"; import { renderProgressBar } from "./mod.ts"; diff --git a/src/console/prompt.test.ts b/src/console/prompt.test.ts index a0c27a9..9d006dc 100644 --- a/src/console/prompt.test.ts +++ b/src/console/prompt.test.ts @@ -1,5 +1,5 @@ +import { assertEquals } from "@std/assert"; import { innerPrompt } from "./prompt.ts"; -import { assertEquals } from "../deps.test.ts"; import { createTester } from "./testUtils.ts"; import { Keys } from "./utils.ts"; diff --git a/src/console/select.test.ts b/src/console/select.test.ts index aff07cb..d43f30b 100644 --- a/src/console/select.test.ts +++ b/src/console/select.test.ts @@ -1,5 +1,5 @@ +import { assertEquals } from "@std/assert"; import { innerSelect } from "./select.ts"; -import { assertEquals } from "../deps.test.ts"; import { createTester } from "./testUtils.ts"; import { Keys } from "./utils.ts"; diff --git a/src/deps.ts b/src/deps.ts deleted file mode 100644 index ab68a8a..0000000 --- a/src/deps.ts +++ /dev/null @@ -1,9 +0,0 @@ -export { Buffer } from "@std/io/buffer"; -export { BufReader } from "@std/io/buf-reader"; -export * as path from "@std/path"; -export { readAll } from "@std/io/read-all"; -export { readerFromStreamReader } from "@std/streams/reader-from-stream-reader"; -export { writeAll, writeAllSync } from "@std/io/write-all"; -export { outdent } from "./vendor/outdent.ts"; -export { RealEnvironment as DenoWhichRealEnvironment, which, whichSync } from "which"; -export { writerFromStreamWriter } from "@std/streams/writer-from-stream-writer"; diff --git a/src/path.test.ts b/src/path.test.ts index bac97e3..6a7e688 100644 --- a/src/path.test.ts +++ b/src/path.test.ts @@ -1,8 +1,8 @@ import { assert, assertEquals, assertRejects, assertThrows } from "@std/assert"; +import * as stdPath from "@std/path"; import { isNode } from "which_runtime"; -import { withTempDir } from "./deps.test.ts"; import { createPath, Path } from "./path.ts"; -import * as stdPath from "@std/path"; +import { withTempDir } from "./with_temp_dir.ts"; Deno.test("create from path ref", () => { const path = createPath("src"); diff --git a/src/path.ts b/src/path.ts index 50f1db8..f6384da 100644 --- a/src/path.ts +++ b/src/path.ts @@ -1,5 +1,7 @@ -import { path as stdPath, writeAll, writeAllSync } from "./deps.ts"; +import { writeAll, writeAllSync } from "@std/io/write-all"; +import * as stdPath from "@std/path"; +import { copy, copySync } from "@std/fs/copy"; import { emptyDir, emptyDirSync } from "@std/fs/empty-dir"; import { ensureDir, ensureDirSync } from "@std/fs/ensure-dir"; import { ensureFile, ensureFileSync } from "@std/fs/ensure-file"; @@ -1035,7 +1037,7 @@ export class Path { */ async copy(destinationPath: string | URL | Path, options?: { overwrite?: boolean }): Promise { const pathRef = ensurePath(destinationPath); - await fs.copy(this.#path, pathRef.#path, options); + await copy(this.#path, pathRef.#path, options); return pathRef; } @@ -1044,7 +1046,7 @@ export class Path { */ copySync(destinationPath: string | URL | Path, options?: { overwrite?: boolean }): Path { const pathRef = ensurePath(destinationPath); - fs.copySync(this.#path, pathRef.#path, options); + copySync(this.#path, pathRef.#path, options); return pathRef; } diff --git a/src/pipes.test.ts b/src/pipes.test.ts index bf91ec8..20235a0 100644 --- a/src/pipes.test.ts +++ b/src/pipes.test.ts @@ -1,5 +1,5 @@ -import { assertEquals } from "./deps.test.ts"; -import { Buffer } from "./deps.ts"; +import { assertEquals } from "@std/assert"; +import { Buffer } from "@std/io/buffer"; import { InheritStaticTextBypassWriter } from "./pipes.ts"; Deno.test("should line buffer the inherit static text bypass writer", () => { diff --git a/src/pipes.ts b/src/pipes.ts index b9e3519..14f5b1e 100644 --- a/src/pipes.ts +++ b/src/pipes.ts @@ -1,9 +1,10 @@ -import type { FsFileWrapper, Path } from "./path.ts"; -import { logger } from "./console/logger.ts"; -import { Buffer, writeAll, writeAllSync } from "./deps.ts"; -import type { RequestBuilder } from "./request.ts"; +import { Buffer } from "@std/io/buffer"; +import { writeAll, writeAllSync } from "@std/io/write-all"; import type { CommandBuilder, KillSignal } from "./command.ts"; import { abortSignalToPromise } from "./common.ts"; +import { logger } from "./console/logger.ts"; +import type { FsFileWrapper, Path } from "./path.ts"; +import type { RequestBuilder } from "./request.ts"; const encoder = new TextEncoder(); diff --git a/src/request.test.ts b/src/request.test.ts index cb62f88..2740d22 100644 --- a/src/request.test.ts +++ b/src/request.test.ts @@ -1,9 +1,12 @@ -import { Buffer, path } from "./deps.ts"; -import { assert, assertEquals, assertRejects, isNode, toWritableStream } from "./deps.test.ts"; -import { RequestBuilder } from "./request.ts"; -import { startServer } from "./test/server.deno.ts"; +import { assert, assertEquals, assertRejects } from "@std/assert"; +import { Buffer } from "@std/io/buffer"; +import { toWritableStream } from "@std/io/to-writable-stream"; +import * as path from "@std/path"; +import { isNode } from "which_runtime"; import $ from "../mod.ts"; import { TimeoutError } from "./common.ts"; +import { RequestBuilder } from "./request.ts"; +import { startServer } from "./test/server.deno.ts"; async function withServer(action: (serverUrl: URL) => Promise) { const server = await startServer({ diff --git a/src/runtimes/process.node.ts b/src/runtimes/process.node.ts index 8207a07..b018e9f 100644 --- a/src/runtimes/process.node.ts +++ b/src/runtimes/process.node.ts @@ -1,7 +1,7 @@ import * as cp from "node:child_process"; import { Readable, Writable } from "node:stream"; -import type { SpawnCommand } from "./process.common.ts"; import { getSignalAbortCode } from "../command.ts"; +import type { SpawnCommand } from "./process.common.ts"; function toNodeStdio(stdio: "inherit" | "null" | "piped") { switch (stdio) { diff --git a/src/shell.ts b/src/shell.ts index 91c2f77..1f36812 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -1,8 +1,9 @@ +import { existsSync } from "@std/fs/exists"; +import * as path from "@std/path"; +import { RealEnvironment as DenoWhichRealEnvironment, which } from "which"; import type { KillSignal } from "./command.ts"; import type { CommandContext, CommandHandler, CommandPipeReader } from "./command_handler.ts"; import { errorToString, getExecutableShebangFromPath, type ShebangInfo } from "./common.ts"; -import { existsSync } from "@std/fs/exists"; -import { DenoWhichRealEnvironment, path, which } from "./deps.ts"; import { wasmInstance } from "./lib/mod.ts"; import { NullPipeReader, diff --git a/src/deps.test.ts b/src/with_temp_dir.ts similarity index 73% rename from src/deps.test.ts rename to src/with_temp_dir.ts index 0cfb6c7..a90922a 100644 --- a/src/deps.test.ts +++ b/src/with_temp_dir.ts @@ -1,10 +1,5 @@ import { createPath, type Path } from "./path.ts"; -export { assert, assertEquals, assertMatch, assertRejects, assertStringIncludes, assertThrows } from "@std/assert"; -export { toWritableStream } from "@std/io/to-writable-stream"; -export { toReadableStream } from "@std/io/to-readable-stream"; -export { isNode } from "which_runtime"; - /** * Creates a temporary directory, changes the cwd to this directory, * then cleans up and restores the cwd when complete. From d01bfab7bee00f0b500c372e0423ec0476bd4535 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 6 Apr 2024 12:49:16 -0400 Subject: [PATCH 4/5] Add publish to jsr workflow --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac72cbc..01079af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,9 @@ jobs: if: | github.event_name == 'push' || !startsWith(github.event.pull_request.head.label, 'dsherret:') + permissions: + contents: read + id-token: write runs-on: ${{ matrix.os }} timeout-minutes: 30 strategy: @@ -44,6 +47,10 @@ jobs: registry-url: 'https://registry.npmjs.org' - name: npm build run: deno run -A ./scripts/build_npm.ts ${{steps.get_tag_version.outputs.TAG_VERSION}} + + - name: Publish to JSR on tag + if: runner.os == 'Linux' + run: deno run -A jsr:@david/publish-on-tag@0.1.3 - name: npm publish if: startsWith(github.ref, 'refs/tags/') && runner.os == 'Linux' env: From 71c6d963b06beee7815da2a9e763b6e1d1c0a710 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 6 Apr 2024 13:18:37 -0400 Subject: [PATCH 5/5] Fix npm build and add lockfile --- .gitignore | 1 - README.md | 19 ++- deno.json | 2 +- deno.lock | 398 +++++++++++++++++++++++++++++++++++++++++++ mod.test.ts | 4 +- scripts/build_npm.ts | 10 +- 6 files changed, 421 insertions(+), 13 deletions(-) create mode 100644 deno.lock diff --git a/.gitignore b/.gitignore index 7838b1f..3b1adaa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /target .vscode -deno.lock npm diff --git a/README.md b/README.md index 2ac2a3f..e4dd4d3 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,26 @@ Cross-platform shell tools for Deno and Node.js inspired by [zx](https://github. 1. Good for application code in addition to use as a shell script replacement. 1. Named after my cat. +## Install + +Deno: + +```sh +# or skip and import directly from `jsr:@david/dax@` +deno add @david/dax +``` + +Node: + +```sh +npm install dax-sh +``` + ## Executing commands ```ts #!/usr/bin/env -S deno run --allow-all -import $ from "https://deno.land/x/dax/mod.ts"; +import $ from "@david/dax"; // "dax-sh" in Node // run a command await $`echo 5`; // outputs: 5 @@ -40,8 +55,6 @@ await Promise.all([ ]); ``` -Note: Above instructions are for Deno. For Node.js, install via `npm install --save-dev dax-sh` then import via `import $ from "dax-sh";`. - ### Getting output Get the stdout of a command (makes stdout "quiet"): diff --git a/deno.json b/deno.json index 982b453..084dba4 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,6 @@ { "name": "@david/dax", "version": "0.0.0", - "lock": false, "tasks": { "test": "deno test -A", "wasmbuild": "deno run -A https://deno.land/x/wasmbuild@0.15.6/main.ts --sync --out ./src/lib" @@ -32,6 +31,7 @@ ], "exports": "./mod.ts", "imports": { + "@deno/dnt": "jsr:@deno/dnt@^0.41.1", "@std/assert": "jsr:@std/assert@^0.221.0", "@std/fmt": "jsr:@std/fmt@^0.221.0", "@std/fs": "jsr:@std/fs@0.221.0", diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..ec757f9 --- /dev/null +++ b/deno.lock @@ -0,0 +1,398 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "jsr:@david/which-runtime@0.2": "jsr:@david/which-runtime@0.2.0", + "jsr:@david/which@0.3": "jsr:@david/which@0.3.0", + "jsr:@deno/cache-dir@^0.8.0": "jsr:@deno/cache-dir@0.8.0", + "jsr:@deno/dnt@^0.41.1": "jsr:@deno/dnt@0.41.1", + "jsr:@std/assert@^0.218.2": "jsr:@std/assert@0.218.2", + "jsr:@std/assert@^0.221.0": "jsr:@std/assert@0.221.0", + "jsr:@std/bytes@^0.218.2": "jsr:@std/bytes@0.218.2", + "jsr:@std/bytes@^0.221.0": "jsr:@std/bytes@0.221.0", + "jsr:@std/fmt@^0.218.2": "jsr:@std/fmt@0.218.2", + "jsr:@std/fmt@^0.221.0": "jsr:@std/fmt@0.221.0", + "jsr:@std/fs@0.221.0": "jsr:@std/fs@0.221.0", + "jsr:@std/fs@^0.218.2": "jsr:@std/fs@0.218.2", + "jsr:@std/io@0.221.0": "jsr:@std/io@0.221.0", + "jsr:@std/io@^0.218.2": "jsr:@std/io@0.218.2", + "jsr:@std/io@^0.221.0": "jsr:@std/io@0.221.0", + "jsr:@std/path@0.221.0": "jsr:@std/path@0.221.0", + "jsr:@std/path@^0.218.2": "jsr:@std/path@0.218.2", + "jsr:@std/path@^0.221.0": "jsr:@std/path@0.221.0", + "jsr:@std/streams@0.221.0": "jsr:@std/streams@0.221.0", + "npm:@ts-morph/bootstrap@0.22": "npm:@ts-morph/bootstrap@0.22.0", + "npm:code-block-writer@^13.0.1": "npm:code-block-writer@13.0.1", + "npm:esbuild@0.20.0": "npm:esbuild@0.20.0" + }, + "jsr": { + "@david/which-runtime@0.2.0": { + "integrity": "69c59142babcff447efff6a6460316131b702ce1713f9f5ddbbb909136d6d7cd" + }, + "@david/which@0.3.0": { + "integrity": "6bdb62c40ac90edcf328e854fa8103a8db21e7c326089cbe3c3a1cf7887d3204" + }, + "@deno/cache-dir@0.8.0": { + "integrity": "e87e80a404958f6350d903e6238b72afb92468378b0b32111f7a1e4916ac7fe7", + "dependencies": [ + "jsr:@std/fs@^0.218.2", + "jsr:@std/io@^0.218.2" + ] + }, + "@deno/dnt@0.41.1": { + "integrity": "8746a773e031ae19ef43d0eece850217b76cf1d0118fdd8e059652d7023d4aff", + "dependencies": [ + "jsr:@deno/cache-dir@^0.8.0", + "jsr:@std/fmt@^0.218.2", + "jsr:@std/fs@^0.218.2", + "jsr:@std/path@^0.218.2", + "npm:@ts-morph/bootstrap@0.22", + "npm:code-block-writer@^13.0.1" + ] + }, + "@std/assert@0.218.2": { + "integrity": "7f0a5a1a8cf86607cd6c2c030584096e1ffad27fc9271429a8cb48cfbdee5eaf" + }, + "@std/assert@0.221.0": { + "integrity": "a5f1aa6e7909dbea271754fd4ab3f4e687aeff4873b4cef9a320af813adb489a" + }, + "@std/bytes@0.218.2": { + "integrity": "91fe54b232dcca73856b79a817247f4a651dbb60d51baafafb6408c137241670" + }, + "@std/bytes@0.221.0": { + "integrity": "64a047011cf833890a4a2ab7293ac55a1b4f5a050624ebc6a0159c357de91966" + }, + "@std/fmt@0.218.2": { + "integrity": "99526449d2505aa758b6cbef81e7dd471d8b28ec0dcb1491d122b284c548788a" + }, + "@std/fmt@0.221.0": { + "integrity": "379fed69bdd9731110f26b9085aeb740606b20428ce6af31ef6bd45ef8efa62a" + }, + "@std/fs@0.218.2": { + "integrity": "dd9431453f7282e8c577cc22c9e6d036055a9a980b5549f887d6012969fabcca", + "dependencies": [ + "jsr:@std/assert@^0.218.2", + "jsr:@std/path@^0.218.2" + ] + }, + "@std/fs@0.221.0": { + "integrity": "028044450299de8ed5a716ade4e6d524399f035513b85913794f4e81f07da286", + "dependencies": [ + "jsr:@std/assert@^0.221.0", + "jsr:@std/path@^0.221.0" + ] + }, + "@std/io@0.218.2": { + "integrity": "c64fbfa087b7c9d4d386c5672f291f607d88cb7d44fc299c20c713e345f2785f", + "dependencies": [ + "jsr:@std/bytes@^0.218.2" + ] + }, + "@std/io@0.221.0": { + "integrity": "faf7f8700d46ab527fa05cc6167f4b97701a06c413024431c6b4d207caa010da", + "dependencies": [ + "jsr:@std/assert@^0.221.0", + "jsr:@std/bytes@^0.221.0" + ] + }, + "@std/path@0.218.2": { + "integrity": "b568fd923d9e53ad76d17c513e7310bda8e755a3e825e6289a0ce536404e2662", + "dependencies": [ + "jsr:@std/assert@^0.218.2" + ] + }, + "@std/path@0.221.0": { + "integrity": "0a36f6b17314ef653a3a1649740cc8db51b25a133ecfe838f20b79a56ebe0095", + "dependencies": [ + "jsr:@std/assert@^0.221.0" + ] + }, + "@std/streams@0.221.0": { + "integrity": "47f2f74634b47449277c0ee79fe878da4424b66bd8975c032e3afdca88986e61", + "dependencies": [ + "jsr:@std/io@^0.221.0" + ] + } + }, + "npm": { + "@esbuild/aix-ppc64@0.20.0": { + "integrity": "sha512-fGFDEctNh0CcSwsiRPxiaqX0P5rq+AqE0SRhYGZ4PX46Lg1FNR6oCxJghf8YgY0WQEgQuh3lErUFE4KxLeRmmw==", + "dependencies": {} + }, + "@esbuild/android-arm64@0.20.0": { + "integrity": "sha512-aVpnM4lURNkp0D3qPoAzSG92VXStYmoVPOgXveAUoQBWRSuQzt51yvSju29J6AHPmwY1BjH49uR29oyfH1ra8Q==", + "dependencies": {} + }, + "@esbuild/android-arm@0.20.0": { + "integrity": "sha512-3bMAfInvByLHfJwYPJRlpTeaQA75n8C/QKpEaiS4HrFWFiJlNI0vzq/zCjBrhAYcPyVPG7Eo9dMrcQXuqmNk5g==", + "dependencies": {} + }, + "@esbuild/android-x64@0.20.0": { + "integrity": "sha512-uK7wAnlRvjkCPzh8jJ+QejFyrP8ObKuR5cBIsQZ+qbMunwR8sbd8krmMbxTLSrDhiPZaJYKQAU5Y3iMDcZPhyQ==", + "dependencies": {} + }, + "@esbuild/darwin-arm64@0.20.0": { + "integrity": "sha512-AjEcivGAlPs3UAcJedMa9qYg9eSfU6FnGHJjT8s346HSKkrcWlYezGE8VaO2xKfvvlZkgAhyvl06OJOxiMgOYQ==", + "dependencies": {} + }, + "@esbuild/darwin-x64@0.20.0": { + "integrity": "sha512-bsgTPoyYDnPv8ER0HqnJggXK6RyFy4PH4rtsId0V7Efa90u2+EifxytE9pZnsDgExgkARy24WUQGv9irVbTvIw==", + "dependencies": {} + }, + "@esbuild/freebsd-arm64@0.20.0": { + "integrity": "sha512-kQ7jYdlKS335mpGbMW5tEe3IrQFIok9r84EM3PXB8qBFJPSc6dpWfrtsC/y1pyrz82xfUIn5ZrnSHQQsd6jebQ==", + "dependencies": {} + }, + "@esbuild/freebsd-x64@0.20.0": { + "integrity": "sha512-uG8B0WSepMRsBNVXAQcHf9+Ko/Tr+XqmK7Ptel9HVmnykupXdS4J7ovSQUIi0tQGIndhbqWLaIL/qO/cWhXKyQ==", + "dependencies": {} + }, + "@esbuild/linux-arm64@0.20.0": { + "integrity": "sha512-uTtyYAP5veqi2z9b6Gr0NUoNv9F/rOzI8tOD5jKcCvRUn7T60Bb+42NDBCWNhMjkQzI0qqwXkQGo1SY41G52nw==", + "dependencies": {} + }, + "@esbuild/linux-arm@0.20.0": { + "integrity": "sha512-2ezuhdiZw8vuHf1HKSf4TIk80naTbP9At7sOqZmdVwvvMyuoDiZB49YZKLsLOfKIr77+I40dWpHVeY5JHpIEIg==", + "dependencies": {} + }, + "@esbuild/linux-ia32@0.20.0": { + "integrity": "sha512-c88wwtfs8tTffPaoJ+SQn3y+lKtgTzyjkD8NgsyCtCmtoIC8RDL7PrJU05an/e9VuAke6eJqGkoMhJK1RY6z4w==", + "dependencies": {} + }, + "@esbuild/linux-loong64@0.20.0": { + "integrity": "sha512-lR2rr/128/6svngnVta6JN4gxSXle/yZEZL3o4XZ6esOqhyR4wsKyfu6qXAL04S4S5CgGfG+GYZnjFd4YiG3Aw==", + "dependencies": {} + }, + "@esbuild/linux-mips64el@0.20.0": { + "integrity": "sha512-9Sycc+1uUsDnJCelDf6ZNqgZQoK1mJvFtqf2MUz4ujTxGhvCWw+4chYfDLPepMEvVL9PDwn6HrXad5yOrNzIsQ==", + "dependencies": {} + }, + "@esbuild/linux-ppc64@0.20.0": { + "integrity": "sha512-CoWSaaAXOZd+CjbUTdXIJE/t7Oz+4g90A3VBCHLbfuc5yUQU/nFDLOzQsN0cdxgXd97lYW/psIIBdjzQIwTBGw==", + "dependencies": {} + }, + "@esbuild/linux-riscv64@0.20.0": { + "integrity": "sha512-mlb1hg/eYRJUpv8h/x+4ShgoNLL8wgZ64SUr26KwglTYnwAWjkhR2GpoKftDbPOCnodA9t4Y/b68H4J9XmmPzA==", + "dependencies": {} + }, + "@esbuild/linux-s390x@0.20.0": { + "integrity": "sha512-fgf9ubb53xSnOBqyvWEY6ukBNRl1mVX1srPNu06B6mNsNK20JfH6xV6jECzrQ69/VMiTLvHMicQR/PgTOgqJUQ==", + "dependencies": {} + }, + "@esbuild/linux-x64@0.20.0": { + "integrity": "sha512-H9Eu6MGse++204XZcYsse1yFHmRXEWgadk2N58O/xd50P9EvFMLJTQLg+lB4E1cF2xhLZU5luSWtGTb0l9UeSg==", + "dependencies": {} + }, + "@esbuild/netbsd-x64@0.20.0": { + "integrity": "sha512-lCT675rTN1v8Fo+RGrE5KjSnfY0x9Og4RN7t7lVrN3vMSjy34/+3na0q7RIfWDAj0e0rCh0OL+P88lu3Rt21MQ==", + "dependencies": {} + }, + "@esbuild/openbsd-x64@0.20.0": { + "integrity": "sha512-HKoUGXz/TOVXKQ+67NhxyHv+aDSZf44QpWLa3I1lLvAwGq8x1k0T+e2HHSRvxWhfJrFxaaqre1+YyzQ99KixoA==", + "dependencies": {} + }, + "@esbuild/sunos-x64@0.20.0": { + "integrity": "sha512-GDwAqgHQm1mVoPppGsoq4WJwT3vhnz/2N62CzhvApFD1eJyTroob30FPpOZabN+FgCjhG+AgcZyOPIkR8dfD7g==", + "dependencies": {} + }, + "@esbuild/win32-arm64@0.20.0": { + "integrity": "sha512-0vYsP8aC4TvMlOQYozoksiaxjlvUcQrac+muDqj1Fxy6jh9l9CZJzj7zmh8JGfiV49cYLTorFLxg7593pGldwQ==", + "dependencies": {} + }, + "@esbuild/win32-ia32@0.20.0": { + "integrity": "sha512-p98u4rIgfh4gdpV00IqknBD5pC84LCub+4a3MO+zjqvU5MVXOc3hqR2UgT2jI2nh3h8s9EQxmOsVI3tyzv1iFg==", + "dependencies": {} + }, + "@esbuild/win32-x64@0.20.0": { + "integrity": "sha512-NgJnesu1RtWihtTtXGFMU5YSE6JyyHPMxCwBZK7a6/8d31GuSo9l0Ss7w1Jw5QnKUawG6UEehs883kcXf5fYwg==", + "dependencies": {} + }, + "@nodelib/fs.scandir@2.1.5": { + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dependencies": { + "@nodelib/fs.stat": "@nodelib/fs.stat@2.0.5", + "run-parallel": "run-parallel@1.2.0" + } + }, + "@nodelib/fs.stat@2.0.5": { + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dependencies": {} + }, + "@nodelib/fs.walk@1.2.8": { + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dependencies": { + "@nodelib/fs.scandir": "@nodelib/fs.scandir@2.1.5", + "fastq": "fastq@1.17.1" + } + }, + "@ts-morph/bootstrap@0.22.0": { + "integrity": "sha512-MI5q7pid4swAlE2lcHwHRa6rcjoIMyT6fy8uuZm8BGg7DHGi/H5bQ0GMZzbk3N0r/LfStMdOYPkl+3IwvfIQ2g==", + "dependencies": { + "@ts-morph/common": "@ts-morph/common@0.22.0" + } + }, + "@ts-morph/common@0.22.0": { + "integrity": "sha512-HqNBuV/oIlMKdkLshXd1zKBqNQCsuPEsgQOkfFQ/eUKjRlwndXW1AjN9LVkBEIukm00gGXSRmfkl0Wv5VXLnlw==", + "dependencies": { + "fast-glob": "fast-glob@3.3.2", + "minimatch": "minimatch@9.0.3", + "mkdirp": "mkdirp@3.0.1", + "path-browserify": "path-browserify@1.0.1" + } + }, + "balanced-match@1.0.2": { + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dependencies": {} + }, + "brace-expansion@2.0.1": { + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dependencies": { + "balanced-match": "balanced-match@1.0.2" + } + }, + "braces@3.0.2": { + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dependencies": { + "fill-range": "fill-range@7.0.1" + } + }, + "code-block-writer@13.0.1": { + "integrity": "sha512-c5or4P6erEA69TxaxTNcHUNcIn+oyxSRTOWV+pSYF+z4epXqNvwvJ70XPGjPNgue83oAFAPBRQYwpAJ/Hpe/Sg==", + "dependencies": {} + }, + "esbuild@0.20.0": { + "integrity": "sha512-6iwE3Y2RVYCME1jLpBqq7LQWK3MW6vjV2bZy6gt/WrqkY+WE74Spyc0ThAOYpMtITvnjX09CrC6ym7A/m9mebA==", + "dependencies": { + "@esbuild/aix-ppc64": "@esbuild/aix-ppc64@0.20.0", + "@esbuild/android-arm": "@esbuild/android-arm@0.20.0", + "@esbuild/android-arm64": "@esbuild/android-arm64@0.20.0", + "@esbuild/android-x64": "@esbuild/android-x64@0.20.0", + "@esbuild/darwin-arm64": "@esbuild/darwin-arm64@0.20.0", + "@esbuild/darwin-x64": "@esbuild/darwin-x64@0.20.0", + "@esbuild/freebsd-arm64": "@esbuild/freebsd-arm64@0.20.0", + "@esbuild/freebsd-x64": "@esbuild/freebsd-x64@0.20.0", + "@esbuild/linux-arm": "@esbuild/linux-arm@0.20.0", + "@esbuild/linux-arm64": "@esbuild/linux-arm64@0.20.0", + "@esbuild/linux-ia32": "@esbuild/linux-ia32@0.20.0", + "@esbuild/linux-loong64": "@esbuild/linux-loong64@0.20.0", + "@esbuild/linux-mips64el": "@esbuild/linux-mips64el@0.20.0", + "@esbuild/linux-ppc64": "@esbuild/linux-ppc64@0.20.0", + "@esbuild/linux-riscv64": "@esbuild/linux-riscv64@0.20.0", + "@esbuild/linux-s390x": "@esbuild/linux-s390x@0.20.0", + "@esbuild/linux-x64": "@esbuild/linux-x64@0.20.0", + "@esbuild/netbsd-x64": "@esbuild/netbsd-x64@0.20.0", + "@esbuild/openbsd-x64": "@esbuild/openbsd-x64@0.20.0", + "@esbuild/sunos-x64": "@esbuild/sunos-x64@0.20.0", + "@esbuild/win32-arm64": "@esbuild/win32-arm64@0.20.0", + "@esbuild/win32-ia32": "@esbuild/win32-ia32@0.20.0", + "@esbuild/win32-x64": "@esbuild/win32-x64@0.20.0" + } + }, + "fast-glob@3.3.2": { + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "dependencies": { + "@nodelib/fs.stat": "@nodelib/fs.stat@2.0.5", + "@nodelib/fs.walk": "@nodelib/fs.walk@1.2.8", + "glob-parent": "glob-parent@5.1.2", + "merge2": "merge2@1.4.1", + "micromatch": "micromatch@4.0.5" + } + }, + "fastq@1.17.1": { + "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", + "dependencies": { + "reusify": "reusify@1.0.4" + } + }, + "fill-range@7.0.1": { + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dependencies": { + "to-regex-range": "to-regex-range@5.0.1" + } + }, + "glob-parent@5.1.2": { + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": { + "is-glob": "is-glob@4.0.3" + } + }, + "is-extglob@2.1.1": { + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dependencies": {} + }, + "is-glob@4.0.3": { + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dependencies": { + "is-extglob": "is-extglob@2.1.1" + } + }, + "is-number@7.0.0": { + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dependencies": {} + }, + "merge2@1.4.1": { + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dependencies": {} + }, + "micromatch@4.0.5": { + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dependencies": { + "braces": "braces@3.0.2", + "picomatch": "picomatch@2.3.1" + } + }, + "minimatch@9.0.3": { + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dependencies": { + "brace-expansion": "brace-expansion@2.0.1" + } + }, + "mkdirp@3.0.1": { + "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", + "dependencies": {} + }, + "path-browserify@1.0.1": { + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dependencies": {} + }, + "picomatch@2.3.1": { + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dependencies": {} + }, + "queue-microtask@1.2.3": { + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dependencies": {} + }, + "reusify@1.0.4": { + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dependencies": {} + }, + "run-parallel@1.2.0": { + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dependencies": { + "queue-microtask": "queue-microtask@1.2.3" + } + }, + "to-regex-range@5.0.1": { + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dependencies": { + "is-number": "is-number@7.0.0" + } + } + } + }, + "remote": {}, + "workspace": { + "dependencies": [ + "jsr:@david/which-runtime@0.2", + "jsr:@david/which@0.3", + "jsr:@deno/dnt@^0.41.1", + "jsr:@std/assert@^0.221.0", + "jsr:@std/fmt@^0.221.0", + "jsr:@std/fs@0.221.0", + "jsr:@std/io@0.221.0", + "jsr:@std/path@0.221.0", + "jsr:@std/streams@0.221.0" + ] + } +} diff --git a/mod.test.ts b/mod.test.ts index 4ac3112..2bde4f6 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -276,7 +276,7 @@ Deno.test("stderrJson", async () => { }); Deno.test("stderr text", async () => { - const result = await $`deno eval "console.error(1)"`.text("stderr"); + const result = await $`deno eval "console.error(1)"`.env("NO_COLOR", "1").text("stderr"); assertEquals(result, "1"); }); @@ -1134,7 +1134,7 @@ Deno.test("command .lines()", async () => { }); Deno.test("command .lines('stderr')", async () => { - const result = await $`deno eval "console.error(1); console.error(2)"`.lines("stderr"); + const result = await $`deno eval "console.error(1); console.error(2)"`.env("NO_COLOR", "1").lines("stderr"); assertEquals(result, ["1", "2"]); }); diff --git a/scripts/build_npm.ts b/scripts/build_npm.ts index 4ef746c..80dfb92 100644 --- a/scripts/build_npm.ts +++ b/scripts/build_npm.ts @@ -1,7 +1,4 @@ -import { - build, - emptyDir, -} from "https://raw.githubusercontent.com/denoland/dnt/2a144787a696cdb6bf3488358edf5f76bd296767/mod.ts"; +import { build, emptyDir } from "@deno/dnt"; import $ from "../mod.ts"; $.cd($.path(import.meta).parentOrThrow().parentOrThrow()); @@ -11,6 +8,7 @@ await emptyDir("./npm"); await build({ entryPoints: ["./mod.ts"], outDir: "./npm", + importMap: "./deno.json", shims: { deno: true, custom: [{ @@ -104,10 +102,10 @@ await $`deno run -A npm:esbuild@0.20.0 --bundle --platform=node --packages=exter const npmPath = $.path("npm"); // remove all the javascript files in the script folder -for (const entry of npmPath.join("script").walkSync({ exts: ["js"] })) { +for (const entry of npmPath.join("script").walkSync({ includeDirs: false, exts: ["js"] })) { entry.path.removeSync(); } -for (const entry of npmPath.join("esm").walkSync({ exts: ["js"] })) { +for (const entry of npmPath.join("esm").walkSync({ includeDirs: false, exts: ["js"] })) { entry.path.removeSync(); }