<commit_before>const { resolve } = require('path');
const webpack = require('webpack');
const fs = require('fs.promised');

const FILE = 'preact.config.js';

module.exports = async function (env, config, ssr=false) {
	env.config = env.config || FILE;
	let myConfig = resolve(env.cwd, env.config);

	try {
		await fs.stat(myConfig);
	} catch (e) {
		if (env.config === FILE) return;
		throw new Error(`preact-cli config could not be loaded!\nFile ${env.config} not found.`);
	}

	require('babel-register')({
		presets: [require.resolve('babel-preset-env')]
	});
	const m = require(myConfig);
	const transformer = m && m.default || m;
	try {
		let helpers = new WebpackConfigHelpers(env.cwd);
		await transformer(config, Object.assign({}, env, { ssr }), helpers);
	} catch (err) {
		throw new Error(`Error at ${myConfig}: \n` + err);
	}
};

/**
 * WebpackConfigHelpers
 *
 * @class WebpackConfigHelpers<commit_msg>use transforms for the current node version in preact.config.js<commit_after>const { resolve } = require('path');
const webpack = require('webpack');
const fs = require('fs.promised');

const FILE = 'preact.config.js';

module.exports = async function (env, config, ssr=false) {
	env.config = env.config || FILE;
	let myConfig = resolve(env.cwd, env.config);

	try {
		await fs.stat(myConfig);
	} catch (e) {
		if (env.config === FILE) return;
		throw new Error(`preact-cli config could not be loaded!\nFile ${env.config} not found.`);
	}

	require('babel-register')({
		presets: [[require.resolve('babel-preset-env'), {
			"targets": { "node": "current" }
		}]]
	});
	const m = require(myConfig);
	const transformer = m && m.default || m;
	try {
		let helpers = new WebpackConfigHelpers(env.cwd);
		await transformer(config, Object.assign({}, env, { ssr }), helpers);
	} catch (err) {
		throw new Error(`Error at ${myConfig}: \n` + err);
	}
};

/**
 * WebpackConfigHelpers
 *
 * @class WebpackConfigHelpers
{'fraction_non_alphanumeric': 0.17248566961959355, 'fraction_numerical': 0.0, 'mean_word_length': 4.3185595567867034, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3427247', 'n_tokens_mistral': 676, 'n_tokens_neox': 660, 'n_words': 168}