Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
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))
})
}
}
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) {