Add comments for esm vs cjs __dirname implementation

This commit is contained in:
Sander Declerck 2025-12-03 11:31:35 +01:00
parent b366466e11
commit aa441e7483
No known key found for this signature in database
3 changed files with 15 additions and 3 deletions

View file

@ -20,8 +20,12 @@ import {
} from "../src/packagemanager/pip/pipSettings.js"; } from "../src/packagemanager/pip/pipSettings.js";
/** @type {string} */ /** @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; let dirname;
if (import.meta.url) { if (import.meta.url) {
const filename = fileURLToPath(import.meta.url); const filename = fileURLToPath(import.meta.url);
dirname = path.dirname(filename); dirname = path.dirname(filename);

View file

@ -9,8 +9,12 @@ import { includePython } from "../config/cliArguments.js";
import { ECOSYSTEM_PY } from "../config/settings.js"; import { ECOSYSTEM_PY } from "../config/settings.js";
/** @type {string} */ /** @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; let dirname;
if (import.meta.url) { if (import.meta.url) {
const filename = fileURLToPath(import.meta.url); const filename = fileURLToPath(import.meta.url);
dirname = path.dirname(filename); dirname = path.dirname(filename);

View file

@ -9,8 +9,12 @@ import { includePython } from "../config/cliArguments.js";
import { fileURLToPath } from "url"; import { fileURLToPath } from "url";
/** @type {string} */ /** @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; let dirname;
if (import.meta.url) { if (import.meta.url) {
const filename = fileURLToPath(import.meta.url); const filename = fileURLToPath(import.meta.url);
dirname = path.dirname(filename); dirname = path.dirname(filename);