#!/usr/bin/env node /** * MapLibre GL ≥ 6 is ESM-only and spawns a *module* worker resolved from `import.meta.url` * (`./maplibre-gl-worker.mjs`). Under Next/Turbopack that URL points at a chunk, so the worker 404s and no tile or * GeoJSON is ever parsed (black map). We serve the worker + its shared chunk from /public and call * `setWorkerUrl('/maplibre/maplibre-gl-worker.mjs')` before creating the map (see components/map/WorldMap.tsx). * Runs on `predev` / `prebuild` so the copy always matches the installed version. */ import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { createRequire } from 'node:module'; import path from 'node:path'; const require = createRequire(import.meta.url); const dist = path.dirname(require.resolve('maplibre-gl/package.json')) + '/dist'; const out = path.resolve(import.meta.dirname, '../public/maplibre'); mkdirSync(out, { recursive: true }); for (const f of ['maplibre-gl-worker.mjs', 'maplibre-gl-shared.mjs']) copyFileSync(path.join(dist, f), path.join(out, f)); const version = JSON.parse(readFileSync(path.join(dist, '../package.json'), 'utf8')).version; writeFileSync(path.join(out, 'VERSION'), `${version}\n`); console.log(`[maplibre] worker ${version} → public/maplibre/`);