// A script that finds its own directory with `new URL(..., import.meta.url).pathname` // gets a URL-encoded path: on a checkout whose path holds a space (every lane under // "/Volumes/Cotton SSD") it opens "Cotton%20SSD" and fails. fileURLToPath decodes it. // swiftwords hit this with ios-strings-catalogue.mjs on 22 Oct 2026 (coordinator). import { readdirSync, readFileSync, statSync } from "node:fs"; import { join, relative } from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; const SCRIPTS = fileURLToPath(new URL("..", import.meta.url)); function walk(dir: string): string[] { return readdirSync(dir).flatMap((name) => { const path = join(dir, name); if (name === "node_modules") return []; if (statSync(path).isDirectory()) return walk(path); return /\.(mjs|cjs|js|ts)$/.test(name) ? [path] : []; }); } describe("a script finds its own directory through fileURLToPath", () => { it("no script reads import.meta.url's pathname, which stays URL-encoded", () => { const offenders = walk(SCRIPTS) .filter((path) => /import\.meta\.url\)\.pathname/.test(readFileSync(path, "utf8"))) .map((path) => relative(SCRIPTS, path)) .filter((path) => path !== "__tests__/script-paths-decode-urls.test.ts"); expect(offenders).toEqual([]); }); });