async function bundleNpmModule(mod, { source, alias, cwd }) {
	let npmProviderPlugin;

	if (source === 'unpkg') {
		throw Error('unpkg plugin is disabled');
		// npmProviderPlugin = unpkgPlugin({
		// 	publicPath: '/@npm',
		// 	perPackage: true
		// });
	} else {
		npmProviderPlugin = npmPlugin({
			publicPath: '/@npm'
		});
	}

	const bundle = await rollup.rollup({
		input: mod,
		onwarn: onWarn,
		// input: '\0entry',
		cache: npmCache,
		shimMissingExports: true,
		treeshake: false,
		// inlineDynamicImports: true,
		// shimMissingExports: true,
		preserveEntrySignatures: 'allow-extension',
		plugins: [
			nodeBuiltinsPlugin({}),
			aliasPlugin({ alias, cwd }),
			npmProviderPlugin,
			processGlobalPlugin({
				sourcemap: false,
				NODE_ENV: 'development'
			}),
			commonjs({
				extensions: ['.js', '.cjs', ''],
				sourceMap: false,
				transformMixedEsModules: true
			}),
			json(),
			{
				name: 'no-builtins',
				load(s) {
					if (s === 'fs' || s === 'path') {
						return 'export default {};';
					}
				}
			},
			{
				name: 'never-disk',
				load(s) {
					throw Error('local access not allowed');
				}
			}
		]
	});

	npmCache = bundle.cache;

	const { output } = await bundle.generate({
		format: 'es',
		indent: false,
		// entryFileNames: '[name].js',
		// chunkFileNames: '[name].js',
		// Don't transform paths at all:
		paths: String
	});

	return output[0].code;
}
Bundle am npm module entry path into a single file
@param {string} mod The module to bundle, including subpackage/path
@param {object} options
@param {'npm'|'unpkg'} [options.source]
@param {Record<string,string>} [options.alias]
@param {string} [options.cwd]