How to use the @sanity/resolver.resolveRoles function in @sanity/resolver

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 / 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-loader / src / getBaseLoader.js View on Github external
return function sanityRoleLoader(input) {
    const callback = this.async()
    const query = loaderUtils.parseQuery(this.query)

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

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

        loader.call(this, {input, query, roles}, callback)
      })
      .catch(err => {
        this.emitWarning(err.message)
        callback(null, serializeError(err))
      })
  }
}
github sanity-io / sanity / packages / @sanity / server / src / getStyleVariables.js View on Github external
function getStyleVariables(basePath) {
  if (resolving) {
    return new Promise((resolve, reject) => {
      waiting.push({resolve, reject})
    })
  }

  resolving = true
  return resolveRoles({basePath})
    .then(result => {
      const role = result.fulfilled[roleName] || []
      const res = role.reduceRight((vars, impl) => {
        const implementer = requireUncached(impl.path)
        const implementation = implementer.__esModule && implementer.default || implementer

        if (!isPlainObject(implementation)) {
          throw new Error(
            `Plugin "${impl.plugin}" implemented "${roleName}", but did not export a plain object`
          )
        }

        return Object.assign(vars, implementation)
      }, {})

      while (waiting.length) {

@sanity/resolver

Resolves parts and plugins from a Sanity configuration

MIT
Latest version published 10 months ago

Package Health Score

88 / 100
Full package analysis