<commit_before>'use strict'

const path = require('path')
const loaderUtils = require('loader-utils')
const reduceConfig = require('@sanity/util').reduceConfig
const multiImplementationHandler = require('./multiImplementationHandler')

/* eslint-disable no-process-env */
const sanityEnv = process.env.SANITY_ENV
const env = typeof sanityEnv === 'undefined' ? process.env.NODE_ENV : sanityEnv
/* eslint-enable no-process-env */

function sanityPartLoader(input) {
  this.cacheable()

  const qs = this.resourceQuery.substring(this.resourceQuery.indexOf('?'))
  const request = (loaderUtils.parseQuery(qs) || {}).sanityPart

  const loadAll = request.indexOf('all:') === 0
  const partName = loadAll ? request.substr(4) : request

  // In certain cases (CSS when building statically),
  // a separate compiler instance is triggered
  if (!this._compiler.sanity) {
    return input
  }

  if (request === 'config:sanity') {
    const config = JSON.parse(input)
    const indent = env === 'production' ? 0 : 2
    const reduced = reduceConfig(config, env)
    return `module.exports = ${JSON.stringify(reduced, null, indent)}\n`
  }

  const parts = this._compiler.sanity.parts
  const basePath = this._compiler.sanity.basePath

  const dependencies = parts.plugins.map(plugin => path.join(plugin.path, 'sanity.json'))
  const implementations = (parts.implementations[partName] || []).map(impl => impl.path)

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

  // The debug role needs to return the whole parts tree
  if (partName === 'sanity:debug') {
    return `module.exports = ${JSON.stringify(parts, null, 2)}\n`
  }

  return loadAll
    ? multiImplementationHandler(partName, implementations)
    : input
}

module.exports = sanityPartLoader<commit_msg>[webpack-loader] Include base path in debug role values<commit_after>'use strict'

const path = require('path')
const loaderUtils = require('loader-utils')
const reduceConfig = require('@sanity/util').reduceConfig
const multiImplementationHandler = require('./multiImplementationHandler')

/* eslint-disable no-process-env */
const sanityEnv = process.env.SANITY_ENV
const env = typeof sanityEnv === 'undefined' ? process.env.NODE_ENV : sanityEnv
/* eslint-enable no-process-env */

function sanityPartLoader(input) {
  this.cacheable()

  const qs = this.resourceQuery.substring(this.resourceQuery.indexOf('?'))
  const request = (loaderUtils.parseQuery(qs) || {}).sanityPart

  const loadAll = request.indexOf('all:') === 0
  const partName = loadAll ? request.substr(4) : request

  // In certain cases (CSS when building statically),
  // a separate compiler instance is triggered
  if (!this._compiler.sanity) {
    return input
  }

  if (request === 'config:sanity') {
    const config = JSON.parse(input)
    const indent = env === 'production' ? 0 : 2
    const reduced = reduceConfig(config, env)
    return `module.exports = ${JSON.stringify(reduced, null, indent)}\n`
  }

  const parts = this._compiler.sanity.parts
  const basePath = this._compiler.sanity.basePath

  const dependencies = parts.plugins.map(plugin => path.join(plugin.path, 'sanity.json'))
  const implementations = (parts.implementations[partName] || []).map(impl => impl.path)

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

  // The debug role needs to return the whole parts tree
  if (partName === 'sanity:debug') {
    const debug = Object.assign({}, parts, {basePath})
    return `module.exports = ${JSON.stringify(debug, null, 2)}\n`
  }

  return loadAll
    ? multiImplementationHandler(partName, implementations)
    : input
}

module.exports = sanityPartLoader
{'fraction_non_alphanumeric': 0.13378196500672948, 'fraction_numerical': 0.0026917900403768506, 'mean_word_length': 4.464705882352941, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '365086', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1072, 'n_words': 269}