Fix __dirname for esm / fix e2e tests.

This commit is contained in:
Sander Declerck 2025-11-28 12:57:48 +01:00
parent 8c2e8c9597
commit f1ee6567df
No known key found for this signature in database
5 changed files with 67 additions and 29 deletions

View file

@ -10,8 +10,19 @@ import { ECOSYSTEM_JS, setEcoSystem } from "../src/config/settings.js";
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
import { main } from "../src/main.js";
import path from "path";
import { fileURLToPath } from "url";
import fs from "fs";
/** @type {string} */
let dirname;
if (import.meta.url) {
const filename = fileURLToPath(import.meta.url);
dirname = path.dirname(filename);
} else {
dirname = __dirname;
}
if (process.argv.length < 3) {
ui.writeError("No command provided. Please provide a command to execute.");
ui.emptyLine();
@ -23,7 +34,15 @@ initializeCliArguments(process.argv);
const command = process.argv[2];
const pkgManagerCommands = ["npm", "npx", "yarn"];
const pkgManagerCommands = [
"npm",
"npx",
"yarn",
"bun",
"bunx",
"pnpm",
"pnpx",
];
if (pkgManagerCommands.includes(command)) {
ui.writeInformation(process.argv.join(", "));
@ -102,7 +121,7 @@ function writeHelp() {
}
async function getVersion() {
const packageJsonPath = path.join(__dirname, "..", "package.json");
const packageJsonPath = path.join(dirname, "..", "package.json");
const data = await fs.promises.readFile(packageJsonPath);
const json = JSON.parse(data.toString("utf8"));