Skip to content

Commit

Permalink
Remove the dependency on "execa"
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Mar 22, 2024
1 parent d6e8c7d commit eeba648
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
9 changes: 2 additions & 7 deletions bin/php_minifier.cjs

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"php_minifier": "./bin/php_minifier.cjs"
},
"dependencies": {
"execa": "^8.0.1",
"fancy-log": "^2.0.0",
"get-port": "^7.1.0",
"plugin-error": "^2.0.1",
Expand All @@ -31,6 +30,7 @@
"del": "^7.1.0",
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
"execa": "^8.0.1",
"typedoc": "^0.25.12",
"typescript": "^5.4.3",
"typescript-eslint": "^7.3.1",
Expand Down
8 changes: 4 additions & 4 deletions src/fast_transformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type ChildProcess, spawn} from "node:child_process";
import {join, normalize, resolve} from "node:path";
import {fileURLToPath} from "node:url";
import {execa, type ExecaChildProcess} from "execa";
import getPort from "get-port";
import type {Transformer} from "./transformer.js";

Expand All @@ -27,7 +27,7 @@ export class FastTransformer implements Transformer {
/**
* The underlying PHP process.
*/
#process: ExecaChildProcess|null = null;
#process: ChildProcess|null = null;

/**
* Creates a new fast transformer.
Expand Down Expand Up @@ -57,8 +57,8 @@ export class FastTransformer implements Transformer {
return new Promise((fulfill, reject) => {
const root = typeof module == "undefined" ? fileURLToPath(new URL("../www", import.meta.url)) : join(__dirname, "../www");
const args = ["-S", `${FastTransformer.#address}:${this.#port}`, "-t", root];
this.#process = execa(this.#executable, args, {stdio: ["ignore", "pipe", "ignore"]});
this.#process.on("error", reject); // eslint-disable-line @typescript-eslint/no-floating-promises
this.#process = spawn(this.#executable, args, {stdio: ["ignore", "pipe", "ignore"]});
this.#process.on("error", reject);
setTimeout(() => fulfill(this.#port), 1_000);
});
}
Expand Down
7 changes: 5 additions & 2 deletions src/safe_transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {execFile} from "node:child_process";
import {normalize, resolve} from "node:path";
import {execa} from "execa"
import type {Transformer} from "./transformer.js";

/**
Expand Down Expand Up @@ -33,6 +33,9 @@ export class SafeTransformer implements Transformer {
* @returns The transformed script.
*/
async transform(file: string): Promise<string> {
return (await execa(this.#executable, ["-w", resolve(file)])).stdout;
return new Promise((fulfill, reject) => execFile(this.#executable, ["-w", resolve(file)], (error, stdout) => {
if (error) reject(error); // eslint-disable-line @typescript-eslint/prefer-promise-reject-errors
else fulfill(stdout);
}));
}
}

0 comments on commit eeba648

Please sign in to comment.