1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

feat(runtime): support urls for Deno.realPath and Deno.realPathSync (#10626)

This commit is contained in:
Casper Beyer 2021-05-17 12:31:21 +08:00 committed by GitHub
parent ac8ea823f5
commit 910935c071
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View file

@ -1467,7 +1467,7 @@ declare namespace Deno {
* Requires `allow-read` permission for the target path. * Requires `allow-read` permission for the target path.
* Also requires `allow-read` permission for the CWD if the target path is * Also requires `allow-read` permission for the CWD if the target path is
* relative.*/ * relative.*/
export function realPathSync(path: string): string; export function realPathSync(path: string | URL): string;
/** Resolves to the absolute normalized path, with symbolic links resolved. /** Resolves to the absolute normalized path, with symbolic links resolved.
* *
@ -1483,7 +1483,7 @@ declare namespace Deno {
* Requires `allow-read` permission for the target path. * Requires `allow-read` permission for the target path.
* Also requires `allow-read` permission for the CWD if the target path is * Also requires `allow-read` permission for the CWD if the target path is
* relative.*/ * relative.*/
export function realPath(path: string): Promise<string>; export function realPath(path: string | URL): Promise<string>;
export interface DirEntry { export interface DirEntry {
name: string; name: string;

View file

@ -1,9 +1,11 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { import {
assert, assert,
assertEquals,
assertMatch, assertMatch,
assertThrows, assertThrows,
assertThrowsAsync, assertThrowsAsync,
pathToAbsoluteFileUrl,
unitTest, unitTest,
} from "./test_util.ts"; } from "./test_util.ts";
@ -19,6 +21,12 @@ unitTest({ perms: { read: true } }, function realPathSyncSuccess(): void {
} }
}); });
unitTest({ perms: { read: true } }, function realPathSyncUrl(): void {
const relative = "cli/tests/fixture.json";
const url = pathToAbsoluteFileUrl(relative);
assertEquals(Deno.realPathSync(relative), Deno.realPathSync(url));
});
unitTest( unitTest(
{ {
perms: { read: true, write: true }, perms: { read: true, write: true },
@ -66,6 +74,15 @@ unitTest({ perms: { read: true } }, async function realPathSuccess(): Promise<
} }
}); });
unitTest(
{ perms: { read: true } },
async function realPathUrl(): Promise<void> {
const relative = "cli/tests/fixture.json";
const url = pathToAbsoluteFileUrl(relative);
assertEquals(await Deno.realPath(relative), await Deno.realPath(url));
},
);
unitTest( unitTest(
{ {
perms: { read: true, write: true }, perms: { read: true, write: true },

View file

@ -128,11 +128,11 @@
} }
function realPathSync(path) { function realPathSync(path) {
return core.opSync("op_realpath_sync", path); return core.opSync("op_realpath_sync", pathFromURL(path));
} }
function realPath(path) { function realPath(path) {
return core.opAsync("op_realpath_async", path); return core.opAsync("op_realpath_async", pathFromURL(path));
} }
function removeSync( function removeSync(