import type {Parameters} from '@roots/bud-framework/methods/setPath' import {isAbsolute} from 'node:path' import {BudError} from '@roots/bud-support/errors' import isString from '@roots/bud-support/isString' import isUndefined from '@roots/bud-support/isUndefined' export const all = (parameters: Parameters): Parameters => { if (isUndefined(parameters[0])) { throw BudError.normalize(`bud.setPath: no parameters provided`, { details: `At least one parameter must be provided.`, docs: new URL(`https://bud.js.org/docs/bud.setPath`), thrownBy: `bud.setPath`, }) } return parameters } export const baseDir = ([basedir]: [string]): string => { if (!isAbsolute(basedir)) { throw BudError.normalize( `bud.setPath: when only one parameter is provided, it must be an absolute path.`, { details: `The provided path is not absolute. Received \`${basedir}\`. This will be used as the base directory for all other paths.`, docs: new URL(`https://bud.js.org/docs/bud.setPath`), thrownBy: `bud.setPath`, }, ) } return basedir } export const stringPair = ([key, value]: [string, string]) => { if (!isString(value)) { throw BudError.normalize( `bud.setPath: tried to set path with a non-string value`, { details: `Path value must be a string. Received \`${typeof value}\``, docs: new URL(`https://bud.js.org/docs/bud.setPath`), thrownBy: `bud.setPath`, }, ) } if (!isString(key)) { throw BudError.normalize( `bud.setPath: Tried to set path with a non-string key`, { details: `Path label must be a string. Received \`${typeof key}\``, docs: new URL(`https://bud.js.org/docs/bud.setPath`), thrownBy: `bud.setPath`, }, ) } return [key, value] }