function sucrasePlugin(opts = {}) {
	const include = /** @type {Array<string|RegExp>} */ ([]).concat(opts.include || []);
	const allTransforms = [];
	if (opts.typescript) allTransforms.push('typescript');

	function shouldProcess(id) {
		const ch = id[0];
		if (ch === '\0') return false;
		if (opts.typescript && /\.tsx?$/.test(id)) return true;
		return include.length > 0 && include.some(pattern => id.match(pattern));
	}

	return {
		name: 'sucrase',
		transform(code, id) {
			if (!shouldProcess(id)) return null;

			// What is this nonsense?
			// Sucrase fails to parse JSX if the JSX transform is not enabled, but we don't want it enabled.
			// Here we trick Sucrase into thinking the JSX transform is enabled when it calls parse().
			// Transformation checks .includes("jsx") a second time, for which we return false preventing the transform.
			let jsxInjected = false;
			const transforms = allTransforms.slice();
			transforms.includes = function (v) {
				if (v === 'jsx' && !jsxInjected) {
					return (jsxInjected = true);
				}
				return allTransforms.includes(v);
			};

			try {
				const result = transform(code, {
					transforms,
					production: opts.production === true,
					filePath: id,
					sourceMapOptions: opts.sourcemap
						? {
								compiledFilename: id
						  }
						: undefined
				});

				let sourceMap = null;
				if (opts.sourcemap && result.sourceMap) {
					result.sourceMap.sourcesContent = [code];
					sourceMap = result.sourceMap;
				}

				return {
					code: result.code,
					map: sourceMap
				};
			} catch (err) {
				// Enhance error with code frame
				err.codeFrame = wmrCodeFrame(code, err.loc.line - 1, err.loc.column);
				throw err;
			}
		}
	};
}
Transform (TypeScript) files with Sucrase.
@param {object} [opts]
@param {string|RegExp|Array<string|RegExp>} [opts.include=[]] Process files matching these regular expressions
@param {boolean} [opts.typescript]
@param {boolean} [opts.sourcemap=false]
@param {boolean} [opts.production=false]