Files
Peter Steinberger c70aee247e refactor(scripts): migrate JavaScript tools to TypeScript (#121005)
* refactor(scripts): migrate JavaScript tools to TypeScript

* fix(ci): keep changed-scope preflight zero-install

* fix(ci): preserve zero-install script owners

* fix(ci): complete script migration follow-through

* fix(release): keep stable closeout zero-install

* fix(scripts): preserve standalone execution boundaries

* fix(scripts): repair standalone loader boundaries

* fix(scripts): normalize gateway observation ids

* fix(scripts): keep Docker packager standalone

* test(scripts): preserve rebase cleanup helpers

* test(sessions): use tracked temp directory
2026-08-09 07:21:35 -07:00

36 lines
1.2 KiB
JavaScript

// Compares direct-run paths and module URLs across POSIX and Windows path rules.
import path from "node:path";
import { fileURLToPath } from "node:url";
/**
* Return whether a direct-run path points at the current module path.
* @internal Directly tested script implementation detail.
* @param {string | undefined} directPath
* @param {string | undefined} modulePath
* @param {NodeJS.Platform} [platform]
* @returns {boolean}
*/
export function isDirectRunPath(directPath, modulePath, platform = process.platform) {
if (!directPath || !modulePath) {
return false;
}
const pathImpl = platform === "win32" ? path.win32 : path;
/** @type {(value: string) => string} */
const normalize =
platform === "win32"
? (value) => pathImpl.resolve(value).toLowerCase()
: (value) => pathImpl.resolve(value);
return normalize(directPath) === normalize(modulePath);
}
/**
* Return whether a direct-run path points at the current module URL.
* @param {string | undefined} directPath
* @param {string} moduleUrl
* @param {NodeJS.Platform} [platform]
* @returns {boolean}
*/
export function isDirectRunUrl(directPath, moduleUrl, platform = process.platform) {
return isDirectRunPath(directPath, fileURLToPath(moduleUrl), platform);
}