build/lib/treeshaking.ts/discoverAndReadFiles
function discoverAndReadFiles(ts: typeof import('typescript'), options: ITreeShakingOptions): IFileMap {
	const FILES: IFileMap = {};

	const in_queue: { [module: string]: boolean } = Object.create(null);
	const queue: string[] = [];

	const enqueue = (moduleId: string) => {
		// To make the treeshaker work on windows...
		moduleId = moduleId.replace(/\\/g, '/');
		if (in_queue[moduleId]) {
			return;
		}
		in_queue[moduleId] = true;
		queue.push(moduleId);
	};

	options.entryPoints.forEach((entryPoint) => enqueue(entryPoint));

	while (queue.length > 0) {
		const moduleId = queue.shift()!;
		const dts_filename = path.join(options.sourcesRoot, moduleId + '.d.ts');
		if (fs.existsSync(dts_filename)) {
			const dts_filecontents = fs.readFileSync(dts_filename).toString();
			FILES[`${moduleId}.d.ts`] = dts_filecontents;
			continue;
		}

		const js_filename = path.join(options.sourcesRoot, moduleId + '.js');
		if (fs.existsSync(js_filename)) {
			// This is an import for a .js file, so ignore it...
			continue;
		}

		let ts_filename: string;
		if (options.redirects[moduleId]) {
			ts_filename = path.join(options.sourcesRoot, options.redirects[moduleId] + '.ts');
		} else {
			ts_filename = path.join(options.sourcesRoot, moduleId + '.ts');
		}
		const ts_filecontents = fs.readFileSync(ts_filename).toString();
		const info = ts.preProcessFile(ts_filecontents);
		for (let i = info.importedFiles.length - 1; i >= 0; i--) {
			const importedFileName = info.importedFiles[i].fileName;

			if (options.importIgnorePattern.test(importedFileName)) {
				// Ignore vs/css! imports
				continue;
			}

			let importedModuleId = importedFileName;
			if (/(^\.\/)|(^\.\.\/)/.test(importedModuleId)) {
				importedModuleId = path.join(path.dirname(moduleId), importedModuleId);
			}
			enqueue(importedModuleId);
		}

		FILES[`${moduleId}.ts`] = ts_filecontents;
	}

	return FILES;
}