Skip to content

feat: convert to npm workspaces monorepo with per-package publishing#368

Draft
alexluckett wants to merge 23 commits into
mainfrom
maplibre-peer-dependency
Draft

feat: convert to npm workspaces monorepo with per-package publishing#368
alexluckett wants to merge 23 commits into
mainfrom
maplibre-peer-dependency

Conversation

@alexluckett

Copy link
Copy Markdown
Contributor

The problem

@defra/interactive-map currently ships as a single npm package where map provider dependencies (maplibre-gl, @arcgis/core, ol, etc.) are declared as optional peer dependencies at the package root.

A single package.json cannot declare different peer dependencies for different sub-path exports. A consumer installs interactive-map but npm has no knowledge of whether they're using the MapLibre or ESRI provider — npm's checks run at a different level. The result: any consuming service can silently drop a required map provider and npm won't flag the breakage. In the case of forms-engine-plugin, maplibre-gl was almost accidentally dropped with no build-time error — the build would have succeeded and failed only at runtime, potentially in production.

The only way to make maplibre-gl a required peer dependency of the MapLibre provider — without also forcing ESRI consumers to install it — is to give each provider and plugin its own published package.

Solution

Converts the repository to an npm workspaces monorepo. Each provider and plugin becomes its own scoped npm package with required peer dependencies based only on what that package actually needs. The existing file hierarchy, CI pipeline, and build system remain architecturally consistent — publishing gains a loop to publish each package individually.

New package naming convention:

@defra/interactive-map                       # core
@defra/interactive-map-provider-maplibre     # provider: maplibre
@defra/interactive-map-plugin-draw-ml        # plugin: draw-ml
@defra/interactive-map-plugin-search         # plugin: search

Benefits:

  • Install-time enforcement of required dependencies via native npm tooling
  • Consumers install only what they use — core can get smaller over time
  • Clearer naming: the package name tells you whether something is a provider or plugin
  • Future flexibility: mature plugins/providers can be spun off into their own repo with independent version numbers

What changed

  • Each provider and plugin gains its own package.json with scoped name and required peer deps
  • The beta/ directory is dropped — beta status is now signalled via publishConfig.tag: "beta" per package rather than file hierarchy
  • scripts/publish-package.sh extended to stamp lockstep versions into all workspace packages and publish each one
  • Rollup and webpack build paths updated for the flattened directory structure
  • Datasets maplibre adapter added as a separate rollup entry, enabling the ./adapters/maplibre sub-path export
  • Four direct node_modules/ import paths in draw-ml replaced with public MapboxDraw API equivalents
  • Fixed a bug in the publish script where npm publish --prefix was silently publishing the root package instead of each workspace package

Consumer migration

The only breaking change is the import path. Update sub-path imports to the new package names:

Before After
@defra/interactive-map/providers/maplibre @defra/interactive-map-provider-maplibre
@defra/interactive-map/plugins/interact @defra/interactive-map-plugin-interact
@defra/interactive-map/plugins/search @defra/interactive-map-plugin-search
@defra/interactive-map/plugins/datasets/adapters/maplibre @defra/interactive-map-plugin-datasets/adapters/maplibre
(and so on for each plugin/provider)

maplibre-gl is already externalised by rollup for ESM builds, making it
functionally a peer dependency. This aligns package.json with the build
behaviour and the existing docs guidance, consistent with how @arcgis/core
and ol are declared.

Also removes a try/catch in the ESRI provider that was swallowing the
native module-not-found error with a less informative message.
Move beta providers (esri, openlayers, open-names) and beta plugins (scale-bar, datasets, draw-ml, draw-es, draw-ol, frame, map-styles, use-location) to their canonical locations at the root of providers/ and plugins/ directories. This aligns with the new npm workspaces monorepo structure where publishConfig.tag will indicate beta status rather than directory convention.
Add package.json files for maplibre (stable), esri, openlayers, and open-names (beta) providers. Each declares @defra/interactive-map and required engine peer dependencies, with files field limiting published output to dist/ only.
- Remove ./css export from interact plugin (no SCSS source files)
- Add missing ./css export to draw-ol plugin (has SCSS source files)
- Add rollup entry for datasets maplibre adapter sub-path export
- Add adapter index.js re-exporting maplibreLayerAdapter as named export
- Fix publish script: replace npm publish --prefix with npm publish ./
  (--prefix targets the npm prefix dir, not the package dir; bare paths
  are treated as git URLs — ./ prefix is required for local directories)
@alexluckett alexluckett marked this pull request as draft June 18, 2026 08:57
# Conflicts:
#	plugins/datasets/src/adapters/maplibre/registry/mapLibreDataset.js
Main-side commits added logger imports at the old beta/ directory depth.
The merge auto-applied them verbatim onto the flattened paths, leaving
one too many '../' levels. Build (rollup) caught these; jest masked them
via mocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant