diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dced4a3..252ece51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ Any BREAKING CHANGE between minor versions will be documented here in upper case - `deno task serve --quiet` no longer logs the http server requests. - BREAKING: The `includes` option of `sass` plugin accepts only a string (previously `string[]` was also accepted). +- BREAKING: Removed all `Deno.run` calls and replaced with the new `Deno.Command` API. + - Removed the `ScriptOptions` argument of `lume.run()`. ### Fixed - `multilanguage` plugin: diff --git a/ci.ts b/ci.ts index b6cc2cc6..ca7f622c 100644 --- a/ci.ts +++ b/ci.ts @@ -55,20 +55,18 @@ export default async function main(args: string[]) { checkDenoVersion(); const [lumeArgs, denoArgs] = await getArgs(args, quiet); - const process = Deno.run({ - cmd: [ - Deno.execPath(), + const { code } = new Deno.Command(Deno.execPath(), { + args: [ "run", ...denoArgs, import.meta.resolve("./cli.ts"), ...lumeArgs, ], - }); + stdout: "inherit", + stderr: "inherit", + }).outputSync(); - const status = await process.status(); - process.close(); - - if (!status.success) { + if (code !== 0) { addEventListener("unload", () => Deno.exit(1)); } } diff --git a/cli/build.ts b/cli/build.ts index 1dbba6dc..d6a433ff 100644 --- a/cli/build.ts +++ b/cli/build.ts @@ -120,7 +120,11 @@ export async function build( windows: "explorer", }; - Deno.run({ cmd: [commands[Deno.build.os], `http://localhost:${port}/`] }); + new Deno.Command(commands[Deno.build.os], { + args: [`http://localhost:${port}/`], + stdout: "inherit", + stderr: "inherit", + }).output(); } site.dispatchEvent({ type: "afterStartServer" }); diff --git a/cli/import_map.ts b/cli/import_map.ts index c5284e68..d33167a9 100644 --- a/cli/import_map.ts +++ b/cli/import_map.ts @@ -66,17 +66,17 @@ export async function importMap(url: URL, plugins: string[] = []) { if (configFile) { console.log("Reloading Deno cache..."); - const process = Deno.run({ - cmd: [ - Deno.execPath(), + const command = new Deno.Command(Deno.execPath(), { + args: [ "cache", "--unstable", "--reload", configFile, ], + stdout: "inherit", + stderr: "inherit", }); - await process.status(); - process.close(); + await command.output(); } } diff --git a/core.ts b/core.ts index 0b9ce2e2..0ae3a85b 100644 --- a/core.ts +++ b/core.ts @@ -21,11 +21,7 @@ import type { EventOptions, } from "./core/events.ts"; -import type { - default as Scripts, - ScriptOptions, - ScriptOrFunction, -} from "./core/scripts.ts"; +import type { default as Scripts, ScriptOrFunction } from "./core/scripts.ts"; import type { default as FS, Entry, Loader } from "./core/fs.ts"; import type Logger from "./core/logger.ts"; @@ -135,7 +131,6 @@ export type { RequestHandler, ScopeFilter, Scopes, - ScriptOptions, ScriptOrFunction, Scripts, Server, diff --git a/core/scripts.ts b/core/scripts.ts index f71d1006..45e50d5a 100644 --- a/core/scripts.ts +++ b/core/scripts.ts @@ -4,8 +4,8 @@ export interface Options { /** The logger to use */ logger: Logger; - /** The default cwd for scripts */ - options: ScriptOptions; + /** The current working directory */ + cwd?: string; } /** @@ -16,15 +16,15 @@ export default class Scripts { /** The logger to output messages in the terminal */ logger: Logger; - /** The default options to execute the scripts */ - options: ScriptOptions; + /** The current working directory */ + cwd: string; /** All registered scripts and functions */ scripts = new Map(); constructor(options: Options) { this.logger = options.logger; - this.options = options.options; + this.cwd = options.cwd || Deno.cwd(); } /** Register one or more scripts under a specific name */ @@ -34,13 +34,10 @@ export default class Scripts { /** Run one or more commands */ async run( - options: ScriptOptions, ...names: ScriptOrFunction[] ): Promise { - options = { ...this.options, ...options }; - for (const name of names) { - const success = await this.#run(options, name); + const success = await this.#run(name); if (!success) { return false; @@ -51,16 +48,16 @@ export default class Scripts { } /** Run an individual script or function */ - async #run(options: ScriptOptions, name: ScriptOrFunction): Promise { + async #run(name: ScriptOrFunction): Promise { if (typeof name === "string" && this.scripts.has(name)) { this.logger.log(`⚡️ ${name}`); const command = this.scripts.get(name)!; - return this.run(options, ...command); + return this.run(...command); } if (Array.isArray(name)) { const results = await Promise.all( - name.map((n) => this.#run(options, n)), + name.map((n) => this.#run(n)), ); return results.every((success) => success); } @@ -69,7 +66,7 @@ export default class Scripts { return this.#runFunction(name); } - return this.#runScript(options, name); + return this.#runScript(name); } /** Run a function */ @@ -82,15 +79,21 @@ export default class Scripts { } /** Run a shell command */ - async #runScript(options: ScriptOptions, script: string) { + async #runScript(script: string) { this.logger.log(`⚡️ ${script}`); - const cmd = shArgs(script); - const process = Deno.run({ cmd, ...options }); - const status = await process.status(); - process.close(); + const args = shArgs(script); + const cmd = args.shift()!; + + const command = new Deno.Command(cmd, { + args, + stdout: "inherit", + stderr: "inherit", + cwd: this.cwd, + }); - return status.success; + const output = await command.output(); + return output.code === 0; } } @@ -103,6 +106,3 @@ function shArgs(script: string) { /** A script or function */ export type ScriptOrFunction = string | (() => unknown) | ScriptOrFunction[]; - -/** The options for a script */ -export type ScriptOptions = Omit; diff --git a/core/site.ts b/core/site.ts index f6ee6f0c..91ebfa64 100644 --- a/core/site.ts +++ b/core/site.ts @@ -36,7 +36,6 @@ import type { Plugin, Processor, ScopeFilter, - ScriptOptions, ScriptOrFunction, StaticFile, } from "../core.ts"; @@ -183,7 +182,7 @@ export default class Site { // Other stuff const events = new Events(); const logger = new Logger({ quiet }); - const scripts = new Scripts({ logger, options: { cwd } }); + const scripts = new Scripts({ logger, cwd }); const writer = new Writer({ src, dest, logger }); // Save everything in the site instance @@ -274,8 +273,8 @@ export default class Site { } /** Runs a script or function registered previously */ - async run(name: string, options: ScriptOptions = {}): Promise { - return await this.scripts.run(options, name); + async run(name: string): Promise { + return await this.scripts.run(name); } /**