function processGlobalPlugin({ NODE_ENV = 'development', env = {}, sourcemap }) {
	const processObj = JSON.stringify({ browser: true, env: { ...env, NODE_ENV } });

	const PREFIX = `\0builtins:`;

	return {
		name: 'process-global',
		resolveId(id) {
			if (id === `${PREFIX}process.js`) return id;
		},
		load(id) {
			if (id === `${PREFIX}process.js`) return `export default ${processObj};`;
		},
		transform(code, id) {
			if (!/\.([tj]sx?|mjs)$/.test(id)) return;

			const ctx = { falsePositive: false };
			const result = transform(code, {
				plugins: [acornEnvPlugin({ ...env, NODE_ENV }, ctx)],
				parse: this.parse,
				filename: id,
				// Default is to generate sourcemaps, needs an explicit
				// boolean
				sourceMaps: !!sourcemap
			});

			if (ctx.falsePositive) {
				return;
			}

			code = result.code;
			const s = new MagicString(code);

			// if that wasn't the only way `process.env` was referenced...
			if (code.match(/[^a-zA-Z0-9]process\.env/)) {
				// hack: avoid injecting imports into commonjs modules
				if (/^\s*(import|export)[\s{]/gm.test(code)) {
					s.prepend(`import process from '${PREFIX}process.js';\n`);
				} else {
					s.prepend(`var process=${processObj};\n`);
				}
			} else {
				const reg = /typeof(\s+|\s*\(+\s*)process([^a-zA-Z$_.])/g;
				let match = null;
				while ((match = reg.exec(code)) !== null) {
					s.overwrite(match.index, match.index + match[0].length, `typeof${match[1]}undefined${match[2]}`);
				}
			}

			/** @type {*} */
			const map = sourcemap
				? mergeSourceMaps([
						result.map,
						s.generateMap({ source: id, file: path.posix.basename(id), includeContent: true })
				  ])
				: null;

			return {
				code: s.toString(),
				map
			};
		}
	};
}
Inject process globals and inline process.env.NODE_ENV.
@param {object} options
@param {string} [options.NODE_ENV] constant to inline for `process.env.NODE_ENV`
@param {Record<string, string>} [options.env]
@param {boolean} [options.sourcemap]
@returns {import('rollup').Plugin}