How to use @sanity/resolver - 10 common examples

To help you get started, we’ve selected a few @sanity/resolver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / cli / src / cli.js View on Github external
function resolveRootDir(cwd) {
  // Resolve project root directory
  try {
    return (
      resolveProjectRoot({
        basePath: cwd,
        sync: true
      }) || cwd
    )
  } catch (err) {
    console.warn(
      chalk.red(['Error occured trying to resolve project root:', err.message].join('\n'))
    )
    process.exit(1)
  }

  return false
}
github sanity-io / sanity / packages / @sanity / cli / src / bin / sanity.js View on Github external
process.exit(1)
  } else {
    throw err
  }
}

updateNotifier({pkg}).notify({defer: false})

const devMode = hasDevMode()
const args = parseArguments()
const isInit = args.groupOrCommand === 'init'

// Resolve project root directory
let workDir = cwd
try {
  workDir = resolveProjectRoot({
    basePath: cwd,
    sync: true
  }) || cwd
} catch (err) {
  console.warn(chalk.red([
    'Error occured trying to resolve project root:',
    err.message
  ].join('\n')))
  process.exit(1)
}

if (devMode) {
  require('source-map-support').install()

  process.on('unhandledRejection', (reason, promise) => {
    console.error('Unhandled Rejection:', reason.stack)
github sanity-io / sanity / packages / @sanity / webpack-loader / src / styleLoader.js View on Github external
const callback = this.async()
  const query = loaderUtils.parseQuery(this.query)

  if (!query.basePath) {
    callback(new Error('`basePath` property must be passed to style loader'))
    return
  }

  if (!query.style) {
    callback(new Error('`style` property must be passed to style loader'))
    return
  }

  this.addDependency(path.join(query.basePath, 'sanity.json'))

  resolver
    .resolveRoles({basePath: query.basePath})
    .then(roles => {
      if (this.cacheable) {
        this.cacheable()
      }

      // Also add plugin manifests as dependencies
      roles.plugins.forEach(plugin => {
        this.addDependency(path.join(plugin.path, 'sanity.json'))
      })

      const roleName = `style:${query.style}`

      // Do we have this role defined?
      const fulfillers = roles.fulfilled[roleName]
      if (!fulfillers || fulfillers.length === 0) {
github sanity-io / sanity / packages / @sanity / webpack-integration / src / v1 / resolveStyleImport.js View on Github external
function resolveStyleImport(moduleId, opts) {
  const id = moduleId.replace(/^\.\/(part|all:)/, '$1')
  if (!isSanityPart(id)) {
    return resolveNodeModule.sync(id, opts)
  }

  const parts = resolveParts({basePath: opts.root, sync: true})
  const loadAll = id.indexOf('all:') === 0
  const partName = loadAll ? id.substr(4) : id

  const part = parts.implementations[partName]
  if (!part) {
    throw new Error(`No implementers of part '${partName}'`)
  }

  const paths = part.map(implementer => implementer.path)
  return loadAll ? paths.reverse() : paths[0]
}
github sanity-io / sanity / packages / @sanity / server / src / baseServer.js View on Github external
const getDocumentComponent = basePath =>
  resolveParts({basePath}).then(res => {
    const part = res.implementations[docPart]
    if (!part) {
      throw new Error(
        `Part '${docPart}' is not implemented by any plugins, are you missing @sanity/base?`
      )
    }

    return getDefaultModule(requireUncached(part[0].path))
  })
github sanity-io / sanity / packages / @sanity / server / src / util / resolveStyleImport.js View on Github external
function resolveStyleImport(moduleId, opts) {
  const id = moduleId.replace(/^\.\/(part|all:)/, '$1')
  if (!isSanityPart(id)) {
    return resolveNodeModule.sync(id, opts)
  }

  const parts = resolveParts({basePath: opts.root, sync: true})
  const loadAll = id.indexOf('all:') === 0
  const partName = loadAll ? id.substr(4) : id

  const part = parts.implementations[partName]
  if (!part) {
    throw new Error(`No implementers of part '${partName}'`)
  }

  const paths = part.map(implementer => implementer.path)
  return loadAll ? paths.reverse() : paths[0]
}
github sanity-io / sanity / packages / @sanity / webpack-loader / src / PartResolverPlugin.js View on Github external
function cacheParts(params) {
    const instance = params.compiler || params
    instance.sanity = compiler.sanity || {basePath: basePath}
    return partResolver.resolveParts({env, basePath, additionalPlugins}).then(parts => {
      instance.sanity.parts = parts
    })
  }
github sanity-io / sanity / packages / @sanity / server / src / baseServer.js View on Github external
export function callInitializers(config) {
  resolveParts({config}).then(res => {
    const parts = res.implementations[initPart]
    if (!parts) {
      return
    }

    res.implementations[initPart]
      .map(part => getDefaultModule(require(part.path)))
      .forEach(initializer => initializer(config))
  })
}
github sanity-io / sanity / packages / @sanity / check / src / sanityCheck.js View on Github external
function sanityCheck(options) {
  return resolveParts({
    basePath: options.dir,
    useCompiledPaths: options.productionMode
  }).then(parts => checkImplementations(parts, options))
}

@sanity/resolver

Resolves parts and plugins from a Sanity configuration

MIT
Latest version published 9 months ago

Package Health Score

88 / 100
Full package analysis