add.js
function getTaskCallback(callback) {
  let result = null
  // Get the callback function; throw errors, because we can't log them
  // later until we have identified a task name
  if (typeof callback === 'function') {
    result = callback
  } else if (typeof callback === 'string') {
    let id = callback.trim()
    // treat like a local path if it looks like one
    if (
      id.startsWith('./') ||
      id.startsWith('../') ||
      id.endsWith('.js') ||
      (id.includes('/') && !id.startsWith('@'))
    ) {
      if (path.isAbsolute(id) === false) {
        id = path.join(process.cwd(), id)
      }
    }
    try {
      result = require(id)
    } catch (err) {
      throw new Error(`Could not load module '${id}':\n${err}`)
    }
    if (typeof result !== 'function') {
      throw new Error(
        `Expected module '${id}' to export a function, was ${typeof result}`
      )
    }
  } else {
    throw new Error(
      `Callback argument must be a string or a named function\n${USAGE_INFO}`
    )
  }
  const { displayName, name } = result || {}
  if (typeof displayName !== 'string' && typeof name !== 'string') {
    throw new Error(
      `Callback function cannot be anonymous\n(Use a function declaration or the displayName property.)\n${USAGE_INFO}`
    )
  }
  return result
}
function getTaskCallback(callback) {
  let result = null
  // Get the callback function; throw errors, because we can't log them
  // later until we have identified a task name
  if (typeof callback === 'function') {
    result = callback
  } else if (typeof callback === 'string') {
    let id = callback.trim()
    // treat like a local path if it looks like one
    if (
      id.startsWith('./') ||
      id.startsWith('../') ||
      id.endsWith('.js') ||
      (id.includes('/') && !id.startsWith('@'))
    ) {
      if (path.isAbsolute(id) === false) {
        id = path.join(process.cwd(), id)
      }
    }
    try {
      result = require(id)
    } catch (err) {
      throw new Error(`Could not load module '${id}':\n${err}`)
    }
    if (typeof result !== 'function') {
      throw new Error(
        `Expected module '${id}' to export a function, was ${typeof result}`
      )
    }
  } else {
    throw new Error(
      `Callback argument must be a string or a named function\n${USAGE_INFO}`
    )
  }
  const { displayName, name } = result || {}
  if (typeof displayName !== 'string' && typeof name !== 'string') {
    throw new Error(
      `Callback function cannot be anonymous\n(Use a function declaration or the displayName property.)\n${USAGE_INFO}`
    )
  }
  return result
}
function getTaskCallback ( callback ) { let result = null // Get the callback function; throw errors, because we can't log them // later until we have identified a task name if ( typeof callback === 'function' ) { result = callback } else if ( typeof callback === 'string' ) { let id = callback . trim ( ) // treat like a local path if it looks like one if ( id . startsWith ( './' ) || id . startsWith ( '../' ) || id . endsWith ( '.js' ) || ( id . includes ( '/' ) && ! id . startsWith ( '@' ) ) ) { if ( path . isAbsolute ( id ) === false ) { id = path . join ( process . cwd ( ) , id ) } } try { result = require ( id ) } catch ( err ) { throw new Error ( ` ${ id } \n ${ err } ` ) } if ( typeof result !== 'function' ) { throw new Error ( ` ${ id } ${ typeof result } ` ) } } else { throw new Error ( ` \n ${ USAGE_INFO } ` ) } const { displayName , name } = result || { } if ( typeof displayName !== 'string' && typeof name !== 'string' ) { throw new Error ( ` \n \n ${ USAGE_INFO } ` ) } return result }
Check that a declared task uses a valid callback function
@param {string|Function} callback
@return {Function}
@throws {Error}
Check that a declared task uses a valid callback function