<commit_before>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/
var MainTemplate = require("../MainTemplate");
var Template = require("../Template");

function NodeMainTemplate(outputOptions, asyncChunkLoading) {
	MainTemplate.call(this, outputOptions);
	this.asyncChunkLoading = asyncChunkLoading;
}
module.exports = NodeMainTemplate;

NodeMainTemplate.prototype = Object.create(MainTemplate.prototype);

NodeMainTemplate.prototype.requireFn = "webpackRequire";
NodeMainTemplate.prototype.renderLocalVars = function(hash, chunk) {
	var buf = MainTemplate.prototype.renderLocalVars.call(this, hash, chunk);
	if(chunk.chunks.length > 0) {
		buf.push(
			"",
			"// object to store loaded chunks",
			'// "1" means "already loaded"',
			"var installedChunks = {",
			this.indent(
				chunk.ids.map(function(id) {
					return id + ":1"
				}).join(",\n")
			),
			"};"
		);
	}
	return buf;
};

NodeMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) {
	var filename = this.outputOptions.filename || "bundle.js";
	var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
	var insertMoreModules = [
		"var moreModules = chunk.modules, chunkIds = chunk.ids;",
		"for(var moduleId in moreModules) {",
		this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
		"}"
	];
	if(this.asyncChunkLoading) {
		return [
			"if(installedChunks[chunkId] === 1) callback.call(null, " + this.requireFn + ");",
			"else if(!installedChunks[chunkId]) {",
			this.indent([
				"installedChunks[chunkId] = [callback];",
				"var filename = __dirname + " + JSON.stringify("/" + chunkFilename
						.replace(Template.REGEXP_HASH, hash)
						.replace(Template.REGEXP_NAME, ""))
					.replace(Template.REGEXP_ID, "\" + chunkId + \"") + ";",
				"require('fs').readFile(filename, 'utf-8',  function(err, content) {",
				this.indent([
					"if(err) { if(" + this.requireFn + ".onerror) return " + this.requireFn + ".onerror(err); else throw err; }",
					"var chunk = {};",
					"require('vm').runInThisContext('(function(exports) {' + content + '\\n})', filename)(chunk);",
				].concat(insertMoreModules).concat([
					"var callbacks = [];",
					"for(var i = 0; i < chunkIds.length; i++) {",
					this.indent([
						"if(Array.isArray(installedChunks[chunkIds[i]]))",
						this.indent([
							"callbacks = callbacks.concat(installedChunks[chunkIds[i]]);"
						]),
						"installedChunks[chunkIds[i]] = 1;"
					]),
					"}",
					"for(i = 0; i < callbacks.length; i++)",
					this.indent("callbacks[i].call(null, " + this.requireFn + ");")
				])),
				"});"
			]),
			"} else installedChunks[chunkId].push(callback);",
		];
	} else {
		return [
			"// \"1\" is the signal for \"already loaded\"",
			"if(!installedChunks[chunkId]) {",
			this.indent([
				"var chunk = require(" +
					JSON.stringify("./" + chunkFilename
						.replace(Template.REGEXP_HASH, hash)
						.replace(Template.REGEXP_NAME, ""))<commit_msg>fixed onError<commit_after>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/
var MainTemplate = require("../MainTemplate");
var Template = require("../Template");

function NodeMainTemplate(outputOptions, asyncChunkLoading) {
	MainTemplate.call(this, outputOptions);
	this.asyncChunkLoading = asyncChunkLoading;
}
module.exports = NodeMainTemplate;

NodeMainTemplate.prototype = Object.create(MainTemplate.prototype);

NodeMainTemplate.prototype.requireFn = "webpackRequire";
NodeMainTemplate.prototype.renderLocalVars = function(hash, chunk) {
	var buf = MainTemplate.prototype.renderLocalVars.call(this, hash, chunk);
	if(chunk.chunks.length > 0) {
		buf.push(
			"",
			"// object to store loaded chunks",
			'// "1" means "already loaded"',
			"var installedChunks = {",
			this.indent(
				chunk.ids.map(function(id) {
					return id + ":1"
				}).join(",\n")
			),
			"};"
		);
	}
	return buf;
};

NodeMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) {
	var filename = this.outputOptions.filename || "bundle.js";
	var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
	var insertMoreModules = [
		"var moreModules = chunk.modules, chunkIds = chunk.ids;",
		"for(var moduleId in moreModules) {",
		this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
		"}"
	];
	if(this.asyncChunkLoading) {
		return [
			"if(installedChunks[chunkId] === 1) callback.call(null, " + this.requireFn + ");",
			"else if(!installedChunks[chunkId]) {",
			this.indent([
				"installedChunks[chunkId] = [callback];",
				"var filename = __dirname + " + JSON.stringify("/" + chunkFilename
						.replace(Template.REGEXP_HASH, hash)
						.replace(Template.REGEXP_NAME, ""))
					.replace(Template.REGEXP_ID, "\" + chunkId + \"") + ";",
				"require('fs').readFile(filename, 'utf-8',  function(err, content) {",
				this.indent([
					"if(err) { if(" + this.requireFn + ".onError) return " + this.requireFn + ".onError(err); else throw err; }",
					"var chunk = {};",
					"require('vm').runInThisContext('(function(exports) {' + content + '\\n})', filename)(chunk);",
				].concat(insertMoreModules).concat([
					"var callbacks = [];",
					"for(var i = 0; i < chunkIds.length; i++) {",
					this.indent([
						"if(Array.isArray(installedChunks[chunkIds[i]]))",
						this.indent([
							"callbacks = callbacks.concat(installedChunks[chunkIds[i]]);"
						]),
						"installedChunks[chunkIds[i]] = 1;"
					]),
					"}",
					"for(i = 0; i < callbacks.length; i++)",
					this.indent("callbacks[i].call(null, " + this.requireFn + ");")
				])),
				"});"
			]),
			"} else installedChunks[chunkId].push(callback);",
		];
	} else {
		return [
			"// \"1\" is the signal for \"already loaded\"",
			"if(!installedChunks[chunkId]) {",
			this.indent([
				"var chunk = require(" +
					JSON.stringify("./" + chunkFilename
						.replace(Template.REGEXP_HASH, hash)
						.replace(Template.REGEXP_NAME, ""))
{'fraction_non_alphanumeric': 0.18654230512991338, 'fraction_numerical': 0.0029980013324450365, 'mean_word_length': 3.8584142394822005, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1526628', 'n_tokens_mistral': 2329, 'n_tokens_neox': 1980, 'n_words': 339}