<commit_before>import {
	resolve
} from 'path';

import getPatterns from '../../library/utilities/get-patterns';
import getStaticCacheItem from '../../library/utilities/get-static-cache-item';

export default function (application) {
	const patterns = application.configuration.patterns || {};

	// Create one-off special config
	const config = {
		transforms: { // eslint-disable-line quote-props
			react: {
				inFormat: 'jsx',
				outFormat: 'js',
				resolveDependencies: false,
				convertDependencies: true
			},
			'react-mount': {
				inFormat: 'js',
				outFormat: 'js'
			},
			browserify: {
				inFormat: 'js',
				outFormat: 'js'
			}
		},
		patterns: {
			path: patterns.path,
			formats: {
				jsx: {
					name: 'Component',
					transforms: ['react', 'react-mount', 'browserify']
				},
				html: {
					name: 'Component',
					transforms: ['react', 'react-mount', 'browserify']
				}
			}
		}
	};

	return async function() {
		this.type = 'js';

		// collect some base data
		const cwd = application.runtime.patterncwd || application.runtime.cwd;
		const base = resolve(cwd, config.patterns.path);
		const mountableCacheRoot = resolve(cwd, '.cache', 'react-mount');

		// special cache for react-mount
		// TODO: remove this when patterns.formats[ext] support arrays
		const cached = await getStaticCacheItem({
			id: this.params.id,
			base: mountableCacheRoot,
			cache: application.cache,
			extension: 'js',
			stream: true
		});

		if (cached) {
			this.body = cached;
			return;
		}

		// get the react-transformed patterns
		const patterns = await getPatterns({
			id: this.params.id,
			config,
			base,
			factory: application.pattern.factory,
			transforms: application.transforms,<commit_msg>fix(routes): compute transforms for react-mount<commit_after>import {
	resolve
} from 'path';

import {merge} from 'lodash';

import getPatterns from '../../library/utilities/get-patterns';
import getStaticCacheItem from '../../library/utilities/get-static-cache-item';

function getMountTransformChain(format, transforms) {
	const formatChanging = format.transforms.findIndex(transformName => {
		const {outFormat} = transforms[transformName];
		return ['js', 'jsx'].indexOf(outFormat) === -1;
	});

	const index = formatChanging === -1 ?
		format.transforms.length :
		formatChanging;

	return format.transforms
		.slice(0, index)
		.concat(['react-mount', 'browserify']);
}

export default function (application) {
	const patterns = application.configuration.patterns || {};
	const transforms = application.configuration.transforms;
	const jsxFormat = application.configuration.patterns.formats.jsx;
	const mountTransforms = getMountTransformChain(jsxFormat, transforms);

	// Create one-off special config
	const config = merge(
		{},
		{
			transforms,
			patterns
		},
		{
			transforms: { // eslint-disable-line quote-props
				react: {
					inFormat: 'jsx',
					outFormat: 'js',
					resolveDependencies: false,
					convertDependencies: true
				},
				'react-mount': {
					inFormat: 'js',
					outFormat: 'js'
				},
				browserify: {
					inFormat: 'js',
					outFormat: 'js'
				}
			},
			patterns: {
				formats: {
					jsx: {
						name: 'Component',
						transforms: mountTransforms
					}
				}
			}
		}
	);

	return async function() {
		this.type = 'js';

		// collect some base data
		const cwd = application.runtime.patterncwd || application.runtime.cwd;
		const base = resolve(cwd, config.patterns.path);
		const mountableCacheRoot = resolve(cwd, '.cache', 'react-mount');

		// special cache for react-mount
		// TODO: remove this when patterns.formats[ext] support arrays
		const cached = await getStaticCacheItem({
			id: this.params.id,
			base: mountableCacheRoot,
			cache: application.cache,
			extension: 'js',
			stream: true
		});

		if (cached) {
			this.body = cached;
			return;
		}

		// get the react-transformed patterns
		const patterns = await getPatterns({
			id: this.params.id,
			config,
			base,
			factory: application.pattern.factory,
			transforms: application.transforms,
{'fraction_non_alphanumeric': 0.13458683819891143, 'fraction_numerical': 0.0007422068283028204, 'mean_word_length': 3.2828389830508473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6332135', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1252, 'n_words': 300}