function unpkgPlugin({ resolutions = new Map(), publicPath = '@npm/', perPackage = false } = {}) {
	const reverseResolutions = new Map();
	publicPath = publicPath.replace(/\/$/, '') + '/';

	function manualChunks(filename, { getModuleInfo }) {
		// if this is a submodule of a package entry, merge it into the entry:
		if (filename.startsWith(PREFIX_INTERNAL)) {
			const info = getModuleInfo(filename);
			filename = info.importers.find(p => p.startsWith(PREFIX)) || filename;
		}

		let root = filename.substring(5);
		root = reverseResolutions.get(root) || root;
		// return '@npm/' + filename.substring(5).match(/^((?:@[^@/?]+\/)?[^@/?]+)/)[0];
		return publicPath + root.replace(/\//g, ':').replace(/\.([cm]js|[tj]sx?)$/, '');
	}

	return {
		name: 'unpkg-plugin',

		async resolveId(s, from) {
			if (/^np[md]\//.test(s)) s = s.substring(5);

			if (from && /^np[md]\//.test(from)) from = from.substring(5);

			const isRelativeToPackage = from && /^((?:@[^@/?]+\/)?[^@/?]+)(?:@[^/?]+)?(?:\/([^?]+))?(?:\?.*)?$/.test(from);
			const isRelativeImport = /^\.?\.?(\/|$)/.test(s);

			if (isRelativeImport) {
				// resolve relative imports from within a package:
				if (from && isRelativeToPackage) {
					s = path.join(path.dirname(from), s);
				} else {
					// otherwise it's a local import, don't process it:
					return null;
				}
			}

			// strip unpkg URL prefix:
			s = s.replace(/^https?:\/\/unpkg\.com\/((?:@[^@/?]+\/)?[^@/?]+)(@[^/?]+)?(\/[^?]+)?\?module/g, '$1$2$3');

			const resolved = await unpkgResolve(s);

			resolutions.set(s, resolved);
			reverseResolutions.set(resolved, s);

			const isInternalImport = isRelativeImport && from && isRelativeToPackage;
			if (isInternalImport) {
				return PREFIX_INTERNAL + resolved;
			}

			if (perPackage && from) {
				return { id: publicPath + s, external: true };
			}

			return PREFIX + resolved;
		},

		load(id) {
			if (/^np[md]\//.test(id)) {
				return unpkg(id.substring(5));
			}
		},

		options(options) {
			let mc = options.manualChunks;
			if (typeof mc === 'object') {
				const mapping = mc;
				// @TODO: this is probably not the same behavior as manualChunks:{}
				// https://github.com/rollup/rollup/blob/07e0b205c93a3953ec860fc496d8d3d36524f24a/src/ModuleLoader.ts#L186
				mc = filename => {
					for (const alias in mapping) {
						if (mapping[alias].includes(filename)) {
							return alias;
						}
					}
				};
			}
			return {
				...options,
				manualChunks(filename, ctx) {
					if (/^np[md]\//.test(filename)) {
						return manualChunks(filename, ctx);
					}

					if (typeof mc === 'function') {
						return mc.apply(this, arguments);
					}
				}
			};
		}
	};
}
Progressively load and cache individual dependency modules from unpkg.com
@param {object} [options]
@returns {import('rollup').Plugin}