summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-05 18:46:37 -0400
committerGitHub <noreply@github.com>2023-03-05 22:46:37 +0000
commit76b173b60c975fe7540d04aac5b7a40be67fe466 (patch)
tree0d1a58abce1b336e1e20ceeeeb7319030a3142b5 /runtime/js
parent1ab16e2426819af2c534e8a99b98f244626de512 (diff)
refactor: move "pathFromURL" to deno_web extension (#18037)
This API is required by several extensions like "ext/node", "ext/ffi" and also FS APIs that we want to move to a separate crate. Because of that "pathFromURL" API was moved to "deno_web" extension so other extension crates can rely on it.
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/06_util.js67
-rw-r--r--runtime/js/10_permissions.js2
-rw-r--r--runtime/js/30_fs.js2
-rw-r--r--runtime/js/40_process.js3
4 files changed, 3 insertions, 71 deletions
diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js
index fc134d52d..db4564e32 100644
--- a/runtime/js/06_util.js
+++ b/runtime/js/06_util.js
@@ -1,18 +1,10 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-const core = globalThis.Deno.core;
-const internals = globalThis.__bootstrap.internals;
const primordials = globalThis.__bootstrap.primordials;
const {
- decodeURIComponent,
- ObjectPrototypeIsPrototypeOf,
Promise,
SafeArrayIterator,
- SafeRegExp,
- StringPrototypeReplace,
- TypeError,
} = primordials;
-import { URLPrototype } from "internal:deno_url/00_url.js";
let logDebug = false;
let logSource = "JS";
@@ -46,64 +38,6 @@ function createResolvable() {
return promise;
}
-// Keep in sync with `fromFileUrl()` in `std/path/win32.ts`.
-function pathFromURLWin32(url) {
- let p = StringPrototypeReplace(
- url.pathname,
- new SafeRegExp(/^\/*([A-Za-z]:)(\/|$)/),
- "$1/",
- );
- p = StringPrototypeReplace(
- p,
- /\//g,
- "\\",
- );
- p = StringPrototypeReplace(
- p,
- new SafeRegExp(/%(?![0-9A-Fa-f]{2})/g),
- "%25",
- );
- let path = decodeURIComponent(p);
- if (url.hostname != "") {
- // Note: The `URL` implementation guarantees that the drive letter and
- // hostname are mutually exclusive. Otherwise it would not have been valid
- // to append the hostname and path like this.
- path = `\\\\${url.hostname}${path}`;
- }
- return path;
-}
-
-// Keep in sync with `fromFileUrl()` in `std/path/posix.ts`.
-function pathFromURLPosix(url) {
- if (url.hostname !== "") {
- throw new TypeError(`Host must be empty.`);
- }
-
- return decodeURIComponent(
- StringPrototypeReplace(
- url.pathname,
- new SafeRegExp(/%(?![0-9A-Fa-f]{2})/g),
- "%25",
- ),
- );
-}
-
-function pathFromURL(pathOrUrl) {
- if (ObjectPrototypeIsPrototypeOf(URLPrototype, pathOrUrl)) {
- if (pathOrUrl.protocol != "file:") {
- throw new TypeError("Must be a file URL.");
- }
-
- return core.build.os == "windows"
- ? pathFromURLWin32(pathOrUrl)
- : pathFromURLPosix(pathOrUrl);
- }
- return pathOrUrl;
-}
-
-// TODO(bartlomieju): remove
-internals.pathFromURL = pathFromURL;
-
function writable(value) {
return {
value,
@@ -145,7 +79,6 @@ export {
getterOnly,
log,
nonEnumerable,
- pathFromURL,
readOnly,
setLogDebug,
writable,
diff --git a/runtime/js/10_permissions.js b/runtime/js/10_permissions.js
index acdbae8e7..13ea9828b 100644
--- a/runtime/js/10_permissions.js
+++ b/runtime/js/10_permissions.js
@@ -2,8 +2,8 @@
const core = globalThis.Deno.core;
const ops = core.ops;
+import { pathFromURL } from "internal:deno_web/00_infra.js";
import { Event, EventTarget } from "internal:deno_web/02_event.js";
-import { pathFromURL } from "internal:runtime/06_util.js";
const primordials = globalThis.__bootstrap.primordials;
const {
ArrayIsArray,
diff --git a/runtime/js/30_fs.js b/runtime/js/30_fs.js
index fc0bbdca5..19e7f372b 100644
--- a/runtime/js/30_fs.js
+++ b/runtime/js/30_fs.js
@@ -24,7 +24,7 @@ import {
ReadableStreamPrototype,
writableStreamForRid,
} from "internal:deno_web/06_streams.js";
-import { pathFromURL } from "internal:runtime/06_util.js";
+import { pathFromURL } from "internal:deno_web/00_infra.js";
function chmodSync(path, mode) {
ops.op_chmod_sync(pathFromURL(path), mode);
diff --git a/runtime/js/40_process.js b/runtime/js/40_process.js
index 9599b7b74..28bb2870c 100644
--- a/runtime/js/40_process.js
+++ b/runtime/js/40_process.js
@@ -18,8 +18,7 @@ const {
} = primordials;
import { FsFile } from "internal:runtime/30_fs.js";
import { readAll } from "internal:deno_io/12_io.js";
-import { pathFromURL } from "internal:runtime/06_util.js";
-import { assert } from "internal:deno_web/00_infra.js";
+import { assert, pathFromURL } from "internal:deno_web/00_infra.js";
import * as abortSignal from "internal:deno_web/03_abort_signal.js";
import {
readableStreamCollectIntoUint8Array,