Skip to content
Myr

file-url.js

This file

Path

lib/arguments/file-url.js

25 lines · 960 bytes · JavaScript

Last changed by

Fix deno node:process execPath compatibility (#1160)CJbefore adoptionf3a1bf3

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 1–4why, one step back
1import {fileURLToPath} from 'node:url';
23// Allow some arguments/options to be either a file path string or a file URL4export const safeNormalizeFileUrl = (file, name) => {

Fix deno node:process execPath compatibility (#1160)CJbefore adoptionf3a1bf3

line 5why, one step back
5 const fileString = normalizeFileUrl(normalizeDenoExecPath(file));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 6–12why, one step back
6
7 if (typeof fileString !== 'string') {8 throw new TypeError(`${name} must be a string or a file URL: ${fileString}.`);9 }1011 return fileString;12};

Fix deno node:process execPath compatibility (#1160)CJbefore adoptionf3a1bf3

lines 13–22why, one step back
13
14// In Deno node:process execPath is a special object, not just a string:15// https://github.com/denoland/deno/blob/f460188e583f00144000aa0d8ade08218d47c3c1/ext/node/polyfills/process.ts#L34416const normalizeDenoExecPath = file => isDenoExecPath(file)17 ? file.toString()18 : file;1920export const isDenoExecPath = file => typeof file !== 'string'21 && file22 && Object.getPrototypeOf(file) === String.prototype;

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 23–25why, one step back
23
24// Same but also allows other values, e.g. `boolean` for the `shell` option25export const normalizeFileUrl = file => file instanceof URL ? fileURLToPath(file) : file;