Sha256: 971b84c2143ae3163a37f2eafc5f64b2a60b57aae26e5feafb9cd89bb955b6b7

Contents?: true

Size: 1.33 KB

Versions: 15

Compression:

Stored size: 1.33 KB

Contents

const isArray = (value) => Array.isArray(value)
const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
const chdirTestApp = () => {
  try {
    return process.chdir('test/test_app')
  } catch (e) {
    return null
  }
}

const chdirCwd = () => process.chdir(process.cwd())

const resetEnv = () => {
  process.env = {}
}

const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)

const resolvedPath = (packageName) => {
  try {
    return require.resolve(packageName)
  } catch (e) {
    if (e.code !== 'MODULE_NOT_FOUND') {
      throw e
    }
    return null
  }
}

const moduleExists = (packageName) => !!resolvedPath(packageName)

const canProcess = (rule, fn) => {
  const modulePath = resolvedPath(rule)

  if (modulePath) {
    return fn(modulePath)
  }

  return null
}

const loaderMatches = (configLoader, loaderToCheck, fn) => {
  if (configLoader !== loaderToCheck) {
    return null
  }

  const loaderName = `${configLoader}-loader`

  if (!moduleExists(loaderName)) {
    throw new Error(
      `Your webpacker config specified using ${configLoader}, but ${loaderName} package is not installed. Please install ${loaderName} first.`
    )
  }

  return fn()
}

module.exports = {
  chdirTestApp,
  chdirCwd,
  isArray,
  isBoolean,
  ensureTrailingSlash,
  canProcess,
  moduleExists,
  resetEnv,
  loaderMatches
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
shakapacker-6.5.5 package/utils/helpers.js
shakapacker-6.5.4 package/utils/helpers.js
shakapacker-6.5.3 package/utils/helpers.js
shakapacker-6.5.2 package/utils/helpers.js
shakapacker-6.5.1 package/utils/helpers.js
shakapacker-6.5.0 package/utils/helpers.js
shakapacker-6.4.1 package/utils/helpers.js
shakapacker-6.4.0 package/utils/helpers.js
shakapacker-6.3.0 package/utils/helpers.js
shakapacker-6.3.0.pre.rc.1 package/utils/helpers.js
shakapacker-6.2.1 package/utils/helpers.js
shakapacker-6.2.0 package/utils/helpers.js
shakapacker-6.1.1 package/utils/helpers.js
shakapacker-6.1.0 package/utils/helpers.js
shakapacker-6.1.0.beta.0 package/utils/helpers.js