function mapToRelative(map, filename) {
	if (!map) {
		return;
	}
	const sourceRoot = map.sourceRoot;
	const dirname = path.dirname(filename);

	/** @type {(s: string) => string} */
	const toRelative = (s) => {
		if (!s) {
			return s;
		}
		/** @type {string} */
		let sourcePath;
		if (s.startsWith('file:///')) {
			// windows has file:///C:/foo and posix has file:///foo, so we have to remove one extra on windows
			sourcePath = s.slice(IS_WINDOWS ? 8 : 7);
		} else if (sourceRoot) {
			const sep = sourceRoot[sourceRoot.length - 1] === '/' || s[0] === '/' ? '' : '/';
			sourcePath = `${sourceRoot}${sep}${s}`;
		} else {
			sourcePath = s;
		}
		return path.isAbsolute(sourcePath) ? path.relative(dirname, sourcePath) : sourcePath;
	};

	if (map.file) {
		map.file = path.basename(filename);
	}
	if (map.sources) {
		map.sources = map.sources.map(toRelative);
	}
	if (map.sourceRoot) {
		// we have prepended sourceRoot and computed relative paths from it
		// remove it here to avoid downstream processing prepending it again
		delete map.sourceRoot;
	}
}
convert absolute paths in sourcemap file refs to their relative equivalents to avoid leaking fs info

map is modified in place.

@param {SourceMapFileRefs | undefined} map sourcemap
@param {string} filename absolute path to file the sourcemap is for