<commit_before>// @flow

import path from 'path'
import { createFileTransformer, loadLocalFromContext } from 'pundle-api'

import manifest from '../package.json'

function createComponent({ extensions = ['.less'], options = {} }: { extensions?: Array<string>, options?: Object } = {}) {
  return createFileTransformer({
    name: 'pundle-transformer-less',
    version: manifest.version,
    priority: 2000,
    async callback({ file, context }) {
      const extName = path.extname(file.filePath)
      if (!extensions.includes(extName)) return null

      const { name, exported } = loadLocalFromContext(context, ['less'])
      if (!name) {
        throw new Error(`'less' not found in '${context.config.rootDirectory}'`)
      }

      const processed = await exported.render(typeof file.contents === 'string' ? file.contents : file.contents.toString(), {
        sourceMap: {},
        paths: [path.dirname(file.filePath)],
        ...options,
      })

      return {
        contents: processed.css,
        sourceMap: JSON.parse(processed.map),
      }
    },
  })
}

module.exports = createComponent<commit_msg>:bug: Fix invalid source map for imported files in transformer-less<commit_after>// @flow

import path from 'path'
import { createFileTransformer, loadLocalFromContext } from 'pundle-api'

import manifest from '../package.json'

function createComponent({ extensions = ['.less'], options = {} }: { extensions?: Array<string>, options?: Object } = {}) {
  return createFileTransformer({
    name: 'pundle-transformer-less',
    version: manifest.version,
    priority: 2000,
    async callback({ file, context }) {
      const extName = path.extname(file.filePath)
      if (!extensions.includes(extName)) return null

      const { name, exported } = loadLocalFromContext(context, ['less'])
      if (!name) {
        throw new Error(`'less' not found in '${context.config.rootDirectory}'`)
      }

      const processed = await exported.render(typeof file.contents === 'string' ? file.contents : file.contents.toString(), {
        filename: file.filePath,
        sourceMap: {},
        ...options,
      })

      return {
        contents: processed.css,
        sourceMap: JSON.parse(processed.map),
      }
    },
  })
}

module.exports = createComponent
{'fraction_non_alphanumeric': 0.14028934677772906, 'fraction_numerical': 0.0035072336694432268, 'mean_word_length': 3.149090909090909, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1075797', 'n_tokens_mistral': 644, 'n_tokens_neox': 623, 'n_words': 160}