Provider swap

From FriendlyInternet/nuxt-crouton · View interactive version

Provider swap is an AI agent skill from the GitHub repository FriendlyInternet/nuxt-crouton. Swap the external provider/library that backs a crouton package (e.g. the map renderer, geocoder, editor engine, storage SDK) while keeping the package's public API stable so consuming apps need no changes. Use when asked to "change the X provider", "replace library Y in package Z", "switch from <ve

How to use this skill

Skill file

Swap a package's external provider (keep the public API)

Replacing the library/SaaS behind a crouton package — the map renderer, the

geocoder, the rich-text engine, a storage SDK — is a **refactor with an API

contract, not a rewrite. The bar: consuming apps (and the generator output)

keep working with zero edits.** This skill is the playbook + the traps, distilled

from the Mapbox→MapLibre swap (#538): a package consumed as a Nuxt layer leaks

its provider's types and templates into every app, so the swap has more surface

than the component files suggest.

When to use

geocoder", "swap the editor engine in crouton-editor", "use a different upload SDK".

pure version bump (use dependency-sweep).

Hard gates first (don't skip)

provider swap is multi-file; an epic + the swap as the unit of work.

(echo '<pkg>' >> .claude/.package-edit-approved; remove it when done).

what you build: which library, which tile/style/host, API keys vs keyless,

what replaces capabilities the new provider lacks (e.g. MapLibre has no

geocoding; Mapbox style URLs are incompatible). Honour repo constraints

(OSS, self-hostable, no mandatory SaaS — see ecosystem-check).

The protocol

1. Map the surface before touching code

Grep the package for every public seam, and the whole repo for consumers:

rg -l '<old-lib>|<OldType>|<old-css-prefix>' packages/<pkg>
rg -l 'Crouton<Pkg>|use<Pkg>|<exported-const>' packages apps pocs docs

List: components, composables, server/ routes, app/types, nuxt.config.ts

(modules/runtimeConfig/css), crouton.manifest.ts (**incl. its generator

contribution templates**), package.json, CLAUDE.md/README, docs site,

.env.example. The manifest's generator template and the docs are the bits most

often forgotten.

2. Learn the new library's real API — from the dist, not the docs

Docs sites often 403/whiff. The source of truth is the published types:

npm view <new-lib> version exports peerDependencies
cd /tmp && npm pack <new-lib>@<ver> && tar -xzf *.tgz
# read package/dist/index.d.ts for exact props/events/exports

Confirm: required peers (are the heavy ones optional?), whether it touches

window (→ client-only + build.transpile), and which capabilities are missing

vs the old provider (plan replacements).

3. Keep the public API stable (the whole point)

(e.g. export const OLD_STYLES = NEW_STYLES) so external imports don't break.

useGeocode expects { features:[{center,...}] }), **normalise the new

provider's response back to it** rather than changing callers.

Marker/Popup/Map runtime API → only import strings + CSS prefixes change), but

verify per-symbol against the .d.ts.

4. Don't forget the generator + config surface

(enhanceForm/enhanceList) and detection patterns. Update the template to

the new provider, and keep its bindings consistent with the package's own

components (e.g. the slot→marker :map="map as any" cast — see the type-clash

trap below).

deps that hit the DOM, replace token/runtimeConfig with the new keys.

5. Sync the docs (large surface)

Package CLAUDE.md + README, the docs site page, the modules/packages tables,

and .env.example all name the old provider. Search and update. Add a short

migration note (what env vars went away, what URLs are now invalid).

6. Verify — and add a fixture if one is missing

generates from it.** A typecheck of existing apps can miss the generated path

(e.g. velo uses a bespoke form, so the generated map form's type bug only

surfaced once with-maps generated one). Add/extend an e2e fixture

(e2e/CLAUDE.md) that exercises the swapped surface; run e2e-smoke.

Gotchas (each one bit during #538)

(MapLibre: no geocoding, incompatible style URLs). Decide the replacement with

the user before coding (step "Hard gates").

new lib (a transitive old one + your new one), the same class can have two type

identities; a slot value typed by one won't satisfy a prop typed by the other

("missing _privateMethod from type Map$1"). Cast at the boundary (as any)

consistently, matching how the package's own components already bind it.

(step 6).

contribution should only apply when the app uses that package; collection-name

reservations are global footguns (see #558).

Output

A PR (Closes #NN) where: the public API is byte-stable for consumers, the new

provider is keyless/self-hostable per constraints (or the key is documented),

docs carry a migration note, and a fixture proves a generated consuming surface

still boots + works. Run postmortem at epic close — provider swaps are exactly

the kind of first-of-their-kind work whose lessons should feed back here.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.