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 clearOutputFolder();
|
||||||
await bundleSafeChain();
|
await bundleSafeChain();
|
||||||
await copyShellScripts();
|
await copyShellScripts();
|
||||||
await copyAndModifyPackageJson(target);
|
await copyAndModifyPackageJson();
|
||||||
await buildSafeChainBinary(target);
|
await buildSafeChainBinary(target);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
@ -41,8 +41,14 @@ async function copyShellScripts() {
|
||||||
"./build/bin/startup-scripts",
|
"./build/bin/startup-scripts",
|
||||||
{ recursive: true }
|
{ 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(
|
const packageJsonContent = await readFile(
|
||||||
"./packages/safe-chain/package.json",
|
"./packages/safe-chain/package.json",
|
||||||
"utf-8"
|
"utf-8"
|
||||||
|
|
@ -61,8 +67,11 @@ async function copyAndModifyPackageJson(target) {
|
||||||
packageJson.type = "commonjs";
|
packageJson.type = "commonjs";
|
||||||
packageJson.pkg = {
|
packageJson.pkg = {
|
||||||
outputPath: "dist",
|
outputPath: "dist",
|
||||||
assets: ["node_modules/certifi/**/*", "bin/startup-scripts/**/*"],
|
assets: [
|
||||||
targets: [target],
|
"node_modules/certifi/**/*",
|
||||||
|
"bin/startup-scripts/**/*",
|
||||||
|
"bin/path-wrappers/**/*",
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
await writeFile("./build/package.json", JSON.stringify(packageJson, null, 2));
|
await writeFile("./build/package.json", JSON.stringify(packageJson, null, 2));
|
||||||
|
|
@ -71,8 +80,6 @@ async function copyAndModifyPackageJson(target) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSafeChainBinary(target) {
|
function buildSafeChainBinary(target) {
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error("Target: " + target);
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const pkg = spawn(
|
const pkg = spawn(
|
||||||
"npx",
|
"npx",
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,19 @@ import { ECOSYSTEM_JS, setEcoSystem } from "../src/config/settings.js";
|
||||||
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
||||||
import { main } from "../src/main.js";
|
import { main } from "../src/main.js";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
import fs from "fs";
|
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) {
|
if (process.argv.length < 3) {
|
||||||
ui.writeError("No command provided. Please provide a command to execute.");
|
ui.writeError("No command provided. Please provide a command to execute.");
|
||||||
ui.emptyLine();
|
ui.emptyLine();
|
||||||
|
|
@ -23,7 +34,15 @@ initializeCliArguments(process.argv);
|
||||||
|
|
||||||
const command = process.argv[2];
|
const command = process.argv[2];
|
||||||
|
|
||||||
const pkgManagerCommands = ["npm", "npx", "yarn"];
|
const pkgManagerCommands = [
|
||||||
|
"npm",
|
||||||
|
"npx",
|
||||||
|
"yarn",
|
||||||
|
"bun",
|
||||||
|
"bunx",
|
||||||
|
"pnpm",
|
||||||
|
"pnpx",
|
||||||
|
];
|
||||||
|
|
||||||
if (pkgManagerCommands.includes(command)) {
|
if (pkgManagerCommands.includes(command)) {
|
||||||
ui.writeInformation(process.argv.join(", "));
|
ui.writeInformation(process.argv.join(", "));
|
||||||
|
|
@ -102,7 +121,7 @@ function writeHelp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVersion() {
|
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 data = await fs.promises.readFile(packageJsonPath);
|
||||||
const json = JSON.parse(data.toString("utf8"));
|
const json = JSON.parse(data.toString("utf8"));
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,16 @@ import { fileURLToPath } from "url";
|
||||||
import { includePython } from "../config/cliArguments.js";
|
import { includePython } from "../config/cliArguments.js";
|
||||||
import { ECOSYSTEM_PY } from "../config/settings.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.
|
* Loops over the detected shells and calls the setup function for each.
|
||||||
*/
|
*/
|
||||||
|
|
@ -37,10 +47,8 @@ export async function setupCi() {
|
||||||
*/
|
*/
|
||||||
function createUnixShims(shimsDir) {
|
function createUnixShims(shimsDir) {
|
||||||
// Read the template file
|
// Read the template file
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
const templatePath = path.resolve(
|
const templatePath = path.resolve(
|
||||||
__dirname,
|
dirname,
|
||||||
"path-wrappers",
|
"path-wrappers",
|
||||||
"templates",
|
"templates",
|
||||||
"unix-wrapper.template.sh"
|
"unix-wrapper.template.sh"
|
||||||
|
|
@ -78,10 +86,8 @@ function createUnixShims(shimsDir) {
|
||||||
*/
|
*/
|
||||||
function createWindowsShims(shimsDir) {
|
function createWindowsShims(shimsDir) {
|
||||||
// Read the template file
|
// Read the template file
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
const templatePath = path.resolve(
|
const templatePath = path.resolve(
|
||||||
__dirname,
|
dirname,
|
||||||
"path-wrappers",
|
"path-wrappers",
|
||||||
"templates",
|
"templates",
|
||||||
"windows-wrapper.template.cmd"
|
"windows-wrapper.template.cmd"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,17 @@ import fs from "fs";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { includePython } from "../config/cliArguments.js";
|
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.
|
* Loops over the detected shells and calls the setup function for each.
|
||||||
|
|
@ -103,7 +114,7 @@ function copyStartupFiles() {
|
||||||
|
|
||||||
// Use absolute path for source
|
// Use absolute path for source
|
||||||
const sourcePath = path.join(
|
const sourcePath = path.join(
|
||||||
__dirname,
|
dirname,
|
||||||
includePython() ? "startup-scripts/include-python" : "startup-scripts",
|
includePython() ? "startup-scripts/include-python" : "startup-scripts",
|
||||||
file
|
file
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,10 @@ function printSafeChainWarning() {
|
||||||
|
|
||||||
function wrapSafeChainCommand() {
|
function wrapSafeChainCommand() {
|
||||||
local original_cmd="$1"
|
local original_cmd="$1"
|
||||||
local aikido_cmd="$2"
|
|
||||||
|
|
||||||
# Remove the first 2 arguments (original_cmd and aikido_cmd) from $@
|
if command -v safe-chain > /dev/null 2>&1; then
|
||||||
# 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 the aikido command is available, just run it with the provided arguments
|
# If the aikido command is available, just run it with the provided arguments
|
||||||
"$aikido_cmd" "$@"
|
safe-chain "$@"
|
||||||
else
|
else
|
||||||
# If the aikido command is not available, print a warning and run the original command
|
# If the aikido command is not available, print a warning and run the original command
|
||||||
printSafeChainWarning "$original_cmd"
|
printSafeChainWarning "$original_cmd"
|
||||||
|
|
@ -27,27 +22,27 @@ function wrapSafeChainCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function npx() {
|
function npx() {
|
||||||
wrapSafeChainCommand "npx" "aikido-npx" "$@"
|
wrapSafeChainCommand "npx" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function yarn() {
|
function yarn() {
|
||||||
wrapSafeChainCommand "yarn" "aikido-yarn" "$@"
|
wrapSafeChainCommand "yarn" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function pnpm() {
|
function pnpm() {
|
||||||
wrapSafeChainCommand "pnpm" "aikido-pnpm" "$@"
|
wrapSafeChainCommand "pnpm" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function pnpx() {
|
function pnpx() {
|
||||||
wrapSafeChainCommand "pnpx" "aikido-pnpx" "$@"
|
wrapSafeChainCommand "pnpx" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function bun() {
|
function bun() {
|
||||||
wrapSafeChainCommand "bun" "aikido-bun" "$@"
|
wrapSafeChainCommand "bun" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function bunx() {
|
function bunx() {
|
||||||
wrapSafeChainCommand "bunx" "aikido-bunx" "$@"
|
wrapSafeChainCommand "bunx" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function npm() {
|
function npm() {
|
||||||
|
|
@ -58,5 +53,5 @@ function npm() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wrapSafeChainCommand "npm" "aikido-npm" "$@"
|
wrapSafeChainCommand "npm" "$@"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue