From c3f74e3524b5d5acc3e78646946552d15747dbcd Mon Sep 17 00:00:00 2001 From: Daniel Shafer Date: Fri, 23 Oct 2026 16:05:49 +0000 Subject: [PATCH] fix(path): accept readonly array in common() --- path/_common/common.ts | 2 +- path/common.ts | 2 +- path/common_test.ts | 20 ++++++++++++++++++++ path/posix/common.ts | 2 +- path/windows/common.ts | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/path/_common/common.ts b/path/_common/common.ts index 9ff1619ca04e..940d79455d71 100644 --- a/path/_common/common.ts +++ b/path/_common/common.ts @@ -1,7 +1,7 @@ // Copyright 2018-2026 the Deno authors. MIT license. // This module is browser compatible. -export function common(paths: string[], sep: string): string { +export function common(paths: readonly string[], sep: string): string { const [first = "", ...remaining] = paths; const parts = first.split(sep); diff --git a/path/common.ts b/path/common.ts index 36c9d678cf6e..4e56b60c499d 100644 --- a/path/common.ts +++ b/path/common.ts @@ -30,6 +30,6 @@ import { SEPARATOR } from "./constants.ts"; * } * ``` */ -export function common(paths: string[]): string { +export function common(paths: readonly string[]): string { return _common(paths, SEPARATOR); } diff --git a/path/common_test.ts b/path/common_test.ts index db18ec809be6..04a4b9be3a36 100644 --- a/path/common_test.ts +++ b/path/common_test.ts @@ -96,3 +96,23 @@ Deno.test({ assertEquals(actual, "file://deno/"); }, }); + +Deno.test({ + name: "common() accepts readonly arrays", + fn() { + const posixPaths: readonly string[] = [ + "./deno/std/path/mod.ts", + "./deno/std/fs/mod.ts", + ]; + assertEquals(posix.common(posixPaths), "./deno/std/"); + + const windowsPaths: readonly string[] = [ + "C:\\deno\\std\\path\\mod.ts", + "C:\\deno\\std\\fs\\mod.ts", + ]; + assertEquals(windows.common(windowsPaths), "C:\\deno\\std\\"); + + const paths = ["./deno/std/path/mod.ts", "./deno/std/path/mod.ts"] as const; + assertEquals(common(paths), "./deno/std/path/mod.ts"); + }, +}); diff --git a/path/posix/common.ts b/path/posix/common.ts index 61255fa7908b..ca20ea3f538d 100644 --- a/path/posix/common.ts +++ b/path/posix/common.ts @@ -21,6 +21,6 @@ import { SEPARATOR } from "./constants.ts"; * @param paths The paths to compare. * @returns The common path. */ -export function common(paths: string[]): string { +export function common(paths: readonly string[]): string { return _common(paths, SEPARATOR); } diff --git a/path/windows/common.ts b/path/windows/common.ts index 393893bf8543..13475e13996b 100644 --- a/path/windows/common.ts +++ b/path/windows/common.ts @@ -22,6 +22,6 @@ import { SEPARATOR } from "./constants.ts"; * @param paths The paths to compare. * @returns The common path. */ -export function common(paths: string[]): string { +export function common(paths: readonly string[]): string { return _common(paths, SEPARATOR); }