-
-
Notifications
You must be signed in to change notification settings - Fork 558
chore(deps): bump maplibre-gl to 6.0.0 #1510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7dd2a0a
08cdcb7
c08c1e6
5c90876
bb811c4
266c6c6
f60d41d
e9139cb
a1a2f88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { setWorkerUrl } from "maplibre-gl"; | ||
| // Vite bundles the worker (it imports `./maplibre-gl-shared.mjs`) and hands back | ||
| // the emitted asset URL. | ||
| import maplibreWorkerUrl from "maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url"; | ||
|
|
||
| /** | ||
| * Point MapLibre at its bundled worker. | ||
| * | ||
| * v6 ships the worker as a **separate file** and locates it at runtime with | ||
| * `new URL("./maplibre-gl-worker.mjs", import.meta.url)`. That is a computed | ||
| * string, not a static `new URL(…, import.meta.url)` literal, so no bundler can | ||
| * see it: the file is never emitted, and at runtime the URL resolves next to the | ||
| * hashed app chunk (`/assets/maplibre-gl-worker.mjs`), where nothing exists. In | ||
| * the web build the SPA fallback answers that request with `index.html`, so the | ||
| * failure is not even a 404 — the worker is handed HTML, and the request hangs | ||
| * rather than erroring. | ||
| * | ||
| * `setWorkerUrl` overrides that lookup with an asset the build actually emits. | ||
| * Must run before the first `Map` is constructed, so it is imported for effect | ||
| * from the app entry. | ||
| */ | ||
| setWorkerUrl(maplibreWorkerUrl); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import type { Plugin } from "vite"; | ||
|
|
||
| /** | ||
| * Rewrite `import X from "maplibre-gl"` to `import * as X from "maplibre-gl"` | ||
| * inside the published bundles of packages that still target MapLibre v5. | ||
| * | ||
| * MapLibre v6 is ESM-only with **no default export**, so a dist file compiled | ||
| * against v5's default export is a hard bundling error: | ||
| * | ||
| * [MISSING_EXPORT] "default" is not exported by ".../maplibre-gl.mjs" | ||
| * | ||
| * A namespace object is a drop-in for what these bundles actually do with the | ||
| * binding (`X.Map`, `new X.Popup()`, …), so the rewrite is safe. | ||
| * | ||
| * This is a **temporary** shim for third-party packages we do not control. Every | ||
| * opengeos-owned package has already been migrated and released, so the list | ||
| * below should only ever shrink. See opengeos/GeoLibre#1489 (blocker 1). | ||
| * | ||
| * The plugin fails the build if a listed package stops matching — that means it | ||
| * either shipped a fix (delete the entry) or changed its bundle shape (revisit), | ||
| * and silently shimming nothing would hide both. | ||
| */ | ||
| const SHIMMED_PACKAGES = ["@esri/maplibre-arcgis", "@geoman-io/maplibre-geoman-free"] as const; | ||
|
|
||
| // Matches a default import of maplibre-gl in minified or unminified ESM: | ||
| // import Zt from"maplibre-gl" import e from "maplibre-gl" | ||
| const DEFAULT_IMPORT = /\bimport\s+([A-Za-z_$][\w$]*)\s+from\s*(["'])maplibre-gl\2/g; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quality/robustness (low-medium confidence):
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regex only matches a bare default import ( That in itself would likely fail loudly ( Low confidence this pattern actually appears in either package's current bundle (no way to check |
||
|
|
||
| export function maplibreDefaultImportShim(): Plugin { | ||
| const rewritten = new Set<string>(); | ||
|
|
||
| return { | ||
| name: "geolibre:maplibre-default-import-shim", | ||
| enforce: "pre", | ||
| apply: () => true, | ||
|
|
||
| transform(code, id) { | ||
| const pkg = SHIMMED_PACKAGES.find((name) => id.includes(`/node_modules/${name}/`)); | ||
| if (!pkg || !code.includes("maplibre-gl")) return null; | ||
|
|
||
| DEFAULT_IMPORT.lastIndex = 0; | ||
| if (!DEFAULT_IMPORT.test(code)) return null; | ||
|
|
||
| rewritten.add(pkg); | ||
| DEFAULT_IMPORT.lastIndex = 0; | ||
| return { | ||
| code: code.replace( | ||
| DEFAULT_IMPORT, | ||
| (_match, binding: string, quote: string) => | ||
| `import * as ${binding} from ${quote}maplibre-gl${quote}`, | ||
| ), | ||
| map: null, | ||
| }; | ||
| }, | ||
|
|
||
| buildEnd(error) { | ||
| if (error) return; | ||
| const stale = SHIMMED_PACKAGES.filter((name) => !rewritten.has(name)); | ||
| if (stale.length === 0) return; | ||
| this.error( | ||
| `maplibre default-import shim matched nothing in: ${stale.join(", ")}. ` + | ||
| `If the package now ships a v6-compatible build, remove it from ` + | ||
| `SHIMMED_PACKAGES in vite-plugins/maplibre-default-import-shim.ts.`, | ||
| ); | ||
| }, | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor/low-confidence nit: this hardcodes
maplibre-gl/dist/maplibre-gl-worker.mjsas the worker entry path. The PR wisely addedtests/maplibre-shim-parity.test.tsto guard the other MapLibre-v6 workaround (the import shim) against silently rotting when the dependency updates, but there's no equivalent guard here — if a futuremaplibre-glpatch renames/moves this dist file, the failure mode is exactly the one this PR just fixed (a silently-hanging worker request), and nothing in CI would catch it. Worth considering a cheap existence check (e.g. an e2e/smoke assertion that the worker actually loads, or at least a comment pointing at what to re-verify onmaplibre-glbumps) so a future Dependabot bump doesn't quietly reintroduce this bug.