<commit_before>import type { RawSourceMap } from "source-map";
import type { Schema } from "schema-utils/declarations/validate";
import type { AssetInfo, Configuration } from "../lib";
import Compilation from "../lib/Compilation";
import NormalModule, { InputFileSystem } from "../lib/NormalModule";
import type { Mode } from "./WebpackOptions";
import type { Logger } from "../lib/logging/Logger";

export interface NormalModuleLoaderContext {
	version: number;
	getOptions(schema: Schema): any;
	emitWarning(warning: Error | string): void;
	emitError(error: Error | string): void;
	getLogger(name: string): Logger;
	resolve(context: string, request: string, callback: any): any;
	getResolve(
		options: Configuration
	): (context: string, request: string, callback: any) => Promise<any>;
	emitFile(
		name: string,
		content: string,
		sourceMap?: string,
		assetInfo?: AssetInfo
	): void;
	addBuildDependency(dep: string): void;
	utils: {
		absolutify: (context: string, request: string) => string;
		contextify: (context: string, request: string) => string;
	};
	rootContext: string;
	webpack?: boolean;
	sourceMap?: boolean;
	mode: Mode;
	_module?: NormalModule;
	_compilation?: Compilation;
	_compiler?: Compiler;
	fs: InputFileSystem;
}

/** The types added to LoaderContextBase by https://github.com/webpack/loader-runner */
export interface LoaderRunnerLoaderContext {
	/**
	 * Add a directory as dependency of the loader result.
	 */
	addContextDependency(context: string): void;

	/**
	 * Adds a file as dependency of the loader result in order to make them watchable.
	 * For example, html-loader uses this technique as it finds src and src-set attributes.
	 * Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
	 */
	addDependency(file: string): void;

	addMissingDependency(context: string): void;

	/**
	 * Make this loader async.
	 */
	async(): (
		err: Error | undefined | null,
		content?: string | Buffer,
		sourceMap?: string | RawSourceMap,
		additionalData?: Record<string, any>,
		...args: any[]
	) => void | undefined;

	/**
	 * Make this loader result cacheable. By default it's cacheable.
	 * A cacheable loader must have a deterministic result, when inputs and dependencies haven't changed.
	 * This means the loader shouldn't have other dependencies than specified with this.addDependency.
	 * Most loaders are deterministic and cacheable.
	 */
	cacheable(flag?: boolean): void;

	callback(): void;

	/**
	 * Remove all dependencies of the loader result. Even initial dependencies and these of other loaders.
	 */
	clearDependencies(): void;

	/**
	 * The directory of the module. Can be used as context for resolving other stuff.
	 * eg '/workspaces/ts-loader/examples/vanilla/src'
	 */
	context: string;

	readonly currentRequest: string;

	readonly data: any;
	/**
	 * alias of addDependency
	 * Adds a file as dependency of the loader result in order to make them watchable.
	 * For example, html-loader uses this technique as it finds src and src-set attributes.
	 * Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
	 */
	dependency(file: string): void;

	getContextDependencies(): string[];

	getDependencies(): string[];

	getMissingDependencies(): string[];

	/**
	 * The index in the loaders array of the current loader.
	 * In the example: in loader1: 0, in loader2: 1
	 */
	loaderIndex: number;

	/**
	 * Resolves the given request to a module, applies all configured loaders and calls
	 * back with the generated source, the sourceMap and the module instance (usually an
	 * instance of NormalModule). Use this function if you need to know the source code
	 * of another module to generate the result.
	 */
	loadModule(
		request: string,
		callback: (
			err: Error | null,
			source: string,
			sourceMap: any,
			module: NormalModule
		) => void
	): void;

	readonly previousRequest: string;

	readonly query: any;

	readonly remainingRequest: string;

	readonly request: string;

	/**
	 * An array of all the loaders. It is writeable in the pitch phase.
	 * loaders = [{request: string, path: string, query: string, module: function}]
	 *
	 * In the example:
	 * [
	 *   { request: "/abc/loader1.js?xyz",
	 *     path: "/abc/loader1.js",
	 *     query: "?xyz",
	 *     module: [Function]
	 *   },
	 *   { request: "/abc/node_modules/loader2/index.js",
	 *     path: "/abc/node_modules/loader2/index.js",
	 *     query: "",
	 *     module: [Function]
	 *   }
	 * ]
	 */
	loaders: {
		request: string;
		path: string;
		query: string;
		fragment: string;
		options: any;
		ident: string;
		normal: any;
		pitch: any;
		raw: any;
		data: any;
		pitchExecuted: boolean;
		normalExecuted: boolean;
	}[];

	/**
	 * The resource file.
	 * In the example: "/abc/resource.js"
	 */
	resourcePath: string;
}

export interface LoaderDefinition {
	(this: LoaderContext & EmptyContextAdditions, contents: string): string;
}<commit_msg>Update declarations/LoaderContext.d.ts<commit_after>import type { RawSourceMap } from "source-map";
import type { Schema } from "schema-utils/declarations/validate";
import type { AssetInfo, Configuration } from "../lib";
import Compilation from "../lib/Compilation";
import NormalModule, { InputFileSystem } from "../lib/NormalModule";
import type { Mode } from "./WebpackOptions";
import type { Logger } from "../lib/logging/Logger";

export interface NormalModuleLoaderContext {
	version: number;
	getOptions(schema: Schema): any;
	emitWarning(warning: Error | string): void;
	emitError(error: Error | string): void;
	getLogger(name: string): Logger;
	resolve(context: string, request: string, callback: any): any;
	getResolve(
		options: Configuration
	): (context: string, request: string, callback: any) => Promise<any>;
	emitFile(
		name: string,
		content: string,
		sourceMap?: string,
		assetInfo?: AssetInfo
	): void;
	addBuildDependency(dep: string): void;
	utils: {
		absolutify: (context: string, request: string) => string;
		contextify: (context: string, request: string) => string;
	};
	rootContext: string;
	webpack?: boolean;
	sourceMap?: boolean;
	mode: Mode;
	_module?: NormalModule;
	_compilation?: Compilation;
	_compiler?: Compiler;
	fs: InputFileSystem;
}

/** The types added to LoaderContextBase by https://github.com/webpack/loader-runner */
export interface LoaderRunnerLoaderContext {
	/**
	 * Add a directory as dependency of the loader result.
	 */
	addContextDependency(context: string): void;

	/**
	 * Adds a file as dependency of the loader result in order to make them watchable.
	 * For example, html-loader uses this technique as it finds src and src-set attributes.
	 * Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
	 */
	addDependency(file: string): void;

	addMissingDependency(context: string): void;

	/**
	 * Make this loader async.
	 */
	async(): (
		err: Error | undefined | null,
		content?: string | Buffer,
		sourceMap?: string | RawSourceMap,
		additionalData?: Record<string, any>,
		...args: any[]
	) => void | undefined;

	/**
	 * Make this loader result cacheable. By default it's cacheable.
	 * A cacheable loader must have a deterministic result, when inputs and dependencies haven't changed.
	 * This means the loader shouldn't have other dependencies than specified with this.addDependency.
	 * Most loaders are deterministic and cacheable.
	 */
	cacheable(flag?: boolean): void;

	callback(): void;

	/**
	 * Remove all dependencies of the loader result. Even initial dependencies and these of other loaders.
	 */
	clearDependencies(): void;

	/**
	 * The directory of the module. Can be used as context for resolving other stuff.
	 * eg '/workspaces/ts-loader/examples/vanilla/src'
	 */
	context: string;

	readonly currentRequest: string;

	readonly data: any;
	/**
	 * alias of addDependency
	 * Adds a file as dependency of the loader result in order to make them watchable.
	 * For example, html-loader uses this technique as it finds src and src-set attributes.
	 * Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
	 */
	dependency(file: string): void;

	getContextDependencies(): string[];

	getDependencies(): string[];

	getMissingDependencies(): string[];

	/**
	 * The index in the loaders array of the current loader.
	 * In the example: in loader1: 0, in loader2: 1
	 */
	loaderIndex: number;

	/**
	 * Resolves the given request to a module, applies all configured loaders and calls
	 * back with the generated source, the sourceMap and the module instance (usually an
	 * instance of NormalModule). Use this function if you need to know the source code
	 * of another module to generate the result.
	 */
	loadModule(
		request: string,
		callback: (
			err: Error | null,
			source: string,
			sourceMap: any,
			module: NormalModule
		) => void
	): void;

	readonly previousRequest: string;

	readonly query: any;

	readonly remainingRequest: string;

	readonly request: string;

	/**
	 * An array of all the loaders. It is writeable in the pitch phase.
	 * loaders = [{request: string, path: string, query: string, module: function}]
	 *
	 * In the example:
	 * [
	 *   { request: "/abc/loader1.js?xyz",
	 *     path: "/abc/loader1.js",
	 *     query: "?xyz",
	 *     module: [Function]
	 *   },
	 *   { request: "/abc/node_modules/loader2/index.js",
	 *     path: "/abc/node_modules/loader2/index.js",
	 *     query: "",
	 *     module: [Function]
	 *   }
	 * ]
	 */
	loaders: {
		request: string;
		path: string;
		query: string;
		fragment: string;
		options: any;
		ident: string;
		normal: any;
		pitch: any;
		raw: any;
		data: any;
		pitchExecuted: boolean;
		normalExecuted: boolean;
	}[];

	/**
	 * The resource file.
	 * In the example: "/abc/resource.js"
	 */
	resourcePath: string;
}

type LoaderContext = NormalModuleLoaderContext & LoaderRunnerLoaderContext;

declare class EmptyContextAdditions {
	_EmptyContextAdditions: true
}

export interface LoaderDefinition {
	(this: LoaderContext & EmptyContextAdditions, contents: string): string;
}
{'fraction_non_alphanumeric': 0.1141978370870126, 'fraction_numerical': 0.001587459073320766, 'mean_word_length': 3.8298993770963103, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '5193061', 'n_tokens_mistral': 3114, 'n_tokens_neox': 2845, 'n_words': 1070}