mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Fix __dirname for esm / fix e2e tests.
This commit is contained in:
parent
8c2e8c9597
commit
f1ee6567df
5 changed files with 67 additions and 29 deletions
19
build.js
19
build.js
|
|
@ -15,7 +15,7 @@ if (!target) {
|
|||
await clearOutputFolder();
|
||||
await bundleSafeChain();
|
||||
await copyShellScripts();
|
||||
await copyAndModifyPackageJson(target);
|
||||
await copyAndModifyPackageJson();
|
||||
await buildSafeChainBinary(target);
|
||||
})();
|
||||
|
||||
|
|
@ -41,8 +41,14 @@ async function copyShellScripts() {
|
|||
"./build/bin/startup-scripts",
|
||||
{ recursive: true }
|
||||
);
|
||||
await mkdir("./build/bin/path-wrappers", { recursive: true });
|
||||
await cp(
|
||||
"./packages/safe-chain/src/shell-integration/path-wrappers/",
|
||||
"./build/bin/path-wrappers",
|
||||
{ recursive: true }
|
||||
);
|
||||
}
|
||||
async function copyAndModifyPackageJson(target) {
|
||||
async function copyAndModifyPackageJson() {
|
||||
const packageJsonContent = await readFile(
|
||||
"./packages/safe-chain/package.json",
|
||||
"utf-8"
|
||||
|
|
@ -61,8 +67,11 @@ async function copyAndModifyPackageJson(target) {
|
|||
packageJson.type = "commonjs";
|
||||
packageJson.pkg = {
|
||||
outputPath: "dist",
|
||||
assets: ["node_modules/certifi/**/*", "bin/startup-scripts/**/*"],
|
||||
targets: [target],
|
||||
assets: [
|
||||
"node_modules/certifi/**/*",
|
||||
"bin/startup-scripts/**/*",
|
||||
"bin/path-wrappers/**/*",
|
||||
],
|
||||
};
|
||||
|
||||
await writeFile("./build/package.json", JSON.stringify(packageJson, null, 2));
|
||||
|
|
@ -71,8 +80,6 @@ async function copyAndModifyPackageJson(target) {
|
|||
}
|
||||
|
||||
function buildSafeChainBinary(target) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Target: " + target);
|
||||
return new Promise((resolve, reject) => {
|
||||
const pkg = spawn(
|
||||
"npx",
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
|
|
|
|||
|
|
@ -8,6 +8,16 @@ import { fileURLToPath } from "url";
|
|||
import { includePython } from "../config/cliArguments.js";
|
||||
import { ECOSYSTEM_PY } from "../config/settings.js";
|
||||
|
||||
/** @type {string} */
|
||||
let dirname;
|
||||
|
||||
if (import.meta.url) {
|
||||
const filename = fileURLToPath(import.meta.url);
|
||||
dirname = path.dirname(filename);
|
||||
} else {
|
||||
dirname = __dirname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops over the detected shells and calls the setup function for each.
|
||||
*/
|
||||
|
|
@ -37,10 +47,8 @@ export async function setupCi() {
|
|||
*/
|
||||
function createUnixShims(shimsDir) {
|
||||
// Read the template file
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const templatePath = path.resolve(
|
||||
__dirname,
|
||||
dirname,
|
||||
"path-wrappers",
|
||||
"templates",
|
||||
"unix-wrapper.template.sh"
|
||||
|
|
@ -78,10 +86,8 @@ function createUnixShims(shimsDir) {
|
|||
*/
|
||||
function createWindowsShims(shimsDir) {
|
||||
// Read the template file
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const templatePath = path.resolve(
|
||||
__dirname,
|
||||
dirname,
|
||||
"path-wrappers",
|
||||
"templates",
|
||||
"windows-wrapper.template.cmd"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,17 @@ import fs from "fs";
|
|||
import os from "os";
|
||||
import path from "path";
|
||||
import { includePython } from "../config/cliArguments.js";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
/** @type {string} */
|
||||
let dirname;
|
||||
|
||||
if (import.meta.url) {
|
||||
const filename = fileURLToPath(import.meta.url);
|
||||
dirname = path.dirname(filename);
|
||||
} else {
|
||||
dirname = __dirname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops over the detected shells and calls the setup function for each.
|
||||
|
|
@ -103,7 +114,7 @@ function copyStartupFiles() {
|
|||
|
||||
// Use absolute path for source
|
||||
const sourcePath = path.join(
|
||||
__dirname,
|
||||
dirname,
|
||||
includePython() ? "startup-scripts/include-python" : "startup-scripts",
|
||||
file
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,15 +9,10 @@ function printSafeChainWarning() {
|
|||
|
||||
function wrapSafeChainCommand() {
|
||||
local original_cmd="$1"
|
||||
local aikido_cmd="$2"
|
||||
|
||||
# Remove the first 2 arguments (original_cmd and aikido_cmd) from $@
|
||||
# so that "$@" now contains only the arguments passed to the original command
|
||||
shift 2
|
||||
|
||||
if command -v "$aikido_cmd" > /dev/null 2>&1; then
|
||||
if command -v safe-chain > /dev/null 2>&1; then
|
||||
# If the aikido command is available, just run it with the provided arguments
|
||||
"$aikido_cmd" "$@"
|
||||
safe-chain "$@"
|
||||
else
|
||||
# If the aikido command is not available, print a warning and run the original command
|
||||
printSafeChainWarning "$original_cmd"
|
||||
|
|
@ -27,27 +22,27 @@ function wrapSafeChainCommand() {
|
|||
}
|
||||
|
||||
function npx() {
|
||||
wrapSafeChainCommand "npx" "aikido-npx" "$@"
|
||||
wrapSafeChainCommand "npx" "$@"
|
||||
}
|
||||
|
||||
function yarn() {
|
||||
wrapSafeChainCommand "yarn" "aikido-yarn" "$@"
|
||||
wrapSafeChainCommand "yarn" "$@"
|
||||
}
|
||||
|
||||
function pnpm() {
|
||||
wrapSafeChainCommand "pnpm" "aikido-pnpm" "$@"
|
||||
wrapSafeChainCommand "pnpm" "$@"
|
||||
}
|
||||
|
||||
function pnpx() {
|
||||
wrapSafeChainCommand "pnpx" "aikido-pnpx" "$@"
|
||||
wrapSafeChainCommand "pnpx" "$@"
|
||||
}
|
||||
|
||||
function bun() {
|
||||
wrapSafeChainCommand "bun" "aikido-bun" "$@"
|
||||
wrapSafeChainCommand "bun" "$@"
|
||||
}
|
||||
|
||||
function bunx() {
|
||||
wrapSafeChainCommand "bunx" "aikido-bunx" "$@"
|
||||
wrapSafeChainCommand "bunx" "$@"
|
||||
}
|
||||
|
||||
function npm() {
|
||||
|
|
@ -58,5 +53,5 @@ function npm() {
|
|||
return
|
||||
fi
|
||||
|
||||
wrapSafeChainCommand "npm" "aikido-npm" "$@"
|
||||
wrapSafeChainCommand "npm" "$@"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue