test/node_modules/execa/lib/arguments/file-url.js
2024-08-13 09:27:52 +08:00

16 lines
532 B
JavaScript

import {fileURLToPath} from 'node:url';
// Allow some arguments/options to be either a file path string or a file URL
export const safeNormalizeFileUrl = (file, name) => {
const fileString = normalizeFileUrl(file);
if (typeof fileString !== 'string') {
throw new TypeError(`${name} must be a string or a file URL: ${fileString}.`);
}
return fileString;
};
// Same but also allows other values, e.g. `boolean` for the `shell` option
export const normalizeFileUrl = file => file instanceof URL ? fileURLToPath(file) : file;