import { createRequire } from 'node:module'; import path from 'node:path'; /** * setRTLTextPlugin() takes the URL of a classic script that the GL worker pulls in * with importScripts. mapbox-gl-rtl-text ships exactly that as * dist/mapbox-gl-rtl-text.js, but its "exports" field publishes only the ESM/WASM * entry, so the resolver refuses the subpath. Resolving the entry it does publish * and stepping across to dist keeps this working wherever npm hoists the package. * * Shared by vite.config.js and vitest.config.ts: the build needs it to emit the * asset, and the test run needs it because a lazily imported engine module reaches * the same specifier. * * The pattern is a regex, not a string key: the import carries a `?url` suffix, * which a string alias will not match. It is left unanchored on purpose so the * query survives the rewrite and Vite still emits an asset URL. */ export const rtlTextAlias = { find: /^@mapbox\/mapbox-gl-rtl-text\/dist\/mapbox-gl-rtl-text\.js/, replacement: path.join( path.dirname(createRequire(import.meta.url).resolve('@mapbox/mapbox-gl-rtl-text')), '../dist/mapbox-gl-rtl-text.js', ), }; /** * Same shape for Plyr's icon sprite. The package publishes its JS and CSS entries * and nothing else, so `plyr/dist/plyr.svg` is refused by the resolver although * the file is right there. The player has to point at a copy on this origin * (#2341): its default is the sprite on cdn.plyr.io, which the CSP refuses. */ export const plyrSpriteAlias = { find: /^plyr\/dist\/plyr\.svg/, replacement: path.join( path.dirname(createRequire(import.meta.url).resolve('plyr')), 'plyr.svg', ), };