From aa441e74831dbd2575654c482f999db41438d499 Mon Sep 17 00:00:00 2001 From: Sander Declerck Date: Wed, 3 Dec 2025 11:31:35 +0100 Subject: [PATCH] Add comments for esm vs cjs __dirname implementation --- packages/safe-chain/bin/safe-chain.js | 6 +++++- packages/safe-chain/src/shell-integration/setup-ci.js | 6 +++++- packages/safe-chain/src/shell-integration/setup.js | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/safe-chain/bin/safe-chain.js b/packages/safe-chain/bin/safe-chain.js index 2bd47e1..7a1d6ab 100755 --- a/packages/safe-chain/bin/safe-chain.js +++ b/packages/safe-chain/bin/safe-chain.js @@ -20,8 +20,12 @@ import { } from "../src/packagemanager/pip/pipSettings.js"; /** @type {string} */ +// This checks the current file's dirname in a way that's compatible with: +// - Modulejs (import.meta.url) +// - ES modules (__dirname) +// This is needed because safe-chain's npm package is built using ES modules, +// but building the binaries requires commonjs. let dirname; - if (import.meta.url) { const filename = fileURLToPath(import.meta.url); dirname = path.dirname(filename); diff --git a/packages/safe-chain/src/shell-integration/setup-ci.js b/packages/safe-chain/src/shell-integration/setup-ci.js index 9228673..bc5c5e6 100644 --- a/packages/safe-chain/src/shell-integration/setup-ci.js +++ b/packages/safe-chain/src/shell-integration/setup-ci.js @@ -9,8 +9,12 @@ import { includePython } from "../config/cliArguments.js"; import { ECOSYSTEM_PY } from "../config/settings.js"; /** @type {string} */ +// This checks the current file's dirname in a way that's compatible with: +// - Modulejs (import.meta.url) +// - ES modules (__dirname) +// This is needed because safe-chain's npm package is built using ES modules, +// but building the binaries requires commonjs. let dirname; - if (import.meta.url) { const filename = fileURLToPath(import.meta.url); dirname = path.dirname(filename); diff --git a/packages/safe-chain/src/shell-integration/setup.js b/packages/safe-chain/src/shell-integration/setup.js index 45a1fb8..d5c4be9 100644 --- a/packages/safe-chain/src/shell-integration/setup.js +++ b/packages/safe-chain/src/shell-integration/setup.js @@ -9,8 +9,12 @@ import { includePython } from "../config/cliArguments.js"; import { fileURLToPath } from "url"; /** @type {string} */ +// This checks the current file's dirname in a way that's compatible with: +// - Modulejs (import.meta.url) +// - ES modules (__dirname) +// This is needed because safe-chain's npm package is built using ES modules, +// but building the binaries requires commonjs. let dirname; - if (import.meta.url) { const filename = fileURLToPath(import.meta.url); dirname = path.dirname(filename);