Open MercatoDocsSearch docsAPI reference

CLI

mercato module add

Install a package into the app and register its module. Use the catalog entry to confirm the package name and check which files changed afterward.

yarn mercato module add fetches a module package from npm or GitHub, auto-discovers the module it contains, registers it in your app's src/modules.ts, and runs the code generators. It is the primary command for adding pre-built modules published under the @open-mercato/* scope. Third-party packages that follow the same module conventions can be installed too by passing --allow-third-party. If the package is already installed, mercato module enable supports the same optional --eject flow without reinstalling dependencies.

To find a module package, search modules.openmercato.com: every module page shows the exact install command for the version the catalog recommends (libraries and adapters install with yarn add and yarn generate, not module add). See Modules catalog.

To create and publish a reusable package from your own standalone app, see Publishing Custom Modules. GitHub packages can be installed directly with module add, or with Yarn followed by module enable.

Usage

# Single-module package — module is selected automatically
yarn mercato module add <packageSpec>

# Multi-module package — select which module to enable
yarn mercato module add <packageSpec> --module <moduleId>

# Copy module source into src/modules/<moduleId>/
yarn mercato module add <packageSpec> --module <moduleId> --eject

# Install a third-party (non-@open-mercato) module package
yarn mercato module add <packageSpec> --allow-third-party

<packageSpec> accepts npm package specifiers: <name>, <name>@<version>, or <name>@<tag> (e.g., @open-mercato/test-package@preview, @fastwhitecat/[email protected]). The npm: prefix is also supported, including unscoped packages (npm:marketing-consents@preview). GitHub locators accept github:owner/repository, owner/repository, HTTPS URLs, SSH URLs, and [email protected]:owner/repository.git, with an optional #ref. Use github:repository for an authenticated-account repository shorthand and npm:repository to select npm explicitly. Legacy bare unscoped module add arguments remain npm package names. Packages outside the @open-mercato/* scope and GitHub sources require --allow-third-party.

GitHub installation uses the GitHub CLI (gh) to resolve repository metadata and pin the selected ref to a commit. Run gh auth login first for private repositories and authenticated-account shorthand.

Options

OptionDescriptionDefault
<packageSpec>npm package specifier or GitHub locator. Third-party npm packages and GitHub sources require --allow-third-party. –
--module <moduleId>Select a specific module from a package that contains multiple modules. Required when the package exposes more than one module; omit for single-module packages.auto
--ejectCopy the module source into src/modules/<moduleId>/ and load it as a local (@app) module. Cross-module imports inside the copied source are automatically rewritten to reference the originating package. Omit this flag to keep the module installed in node_modules.false
--allow-third-partyAllow installing a package outside the @open-mercato/* scope. The package must still pass the module-structure validation below. Required as an explicit opt-in for supply-chain safety.false

Package Eligibility

Only packages that satisfy all of the following criteria can be installed with this command:

Module identity and ejectability are read directly from each module's src/modules/<moduleId>/index.ts – no extra fields in package.json are required. The @open-mercato/* scope is not a hard requirement for the module to work; it only gates the implicit-trust default, which --allow-third-party overrides.

When a descriptor declares metadata.requires, it must use a static array containing only string literals. Computed arrays, spreads, identifiers, and non-string entries fail enablement because the CLI must validate dependencies without executing package code.

Fresh Releases and the 5-Day Age Gate

Apps created with create-mercato-app set npmMinimalAgeGate: 5d in .yarnrc.yml, so Yarn refuses third-party versions published less than 5 days ago. The @open-mercato/* scope is preapproved and installs immediately. The module page shows the date a fresh release becomes installable as Installable from, and its install command keeps the previous version until then. Pass that exact version in <packageSpec>.

What the Command Does

  1. Parses <packageSpec> and inspects the selected source before changing the app's dependency binding. For npm, it uses npm pack --ignore-scripts to inspect the published artifact, retains the requested npm selector, and verifies the installed version matches the inspected artifact. This preflight requires the npm executable and registry access even when Yarn could otherwise satisfy an install from its offline cache. In an intentionally offline environment, install through Yarn first and then run yarn mercato module enable <packageName>. Local file: sources are inspected directly. For GitHub, it resolves and inspects a pinned commit. GitHub preflight validates repository layout and export-map coverage from source paths; because it derives the corresponding dist/ paths without downloading a built package, actual compiled output is verified only after Yarn installs the pinned commit.
  2. Discovers the shipped module IDs and selects --module, or the sole module when there is exactly one. Missing or ambiguous selections stop before Yarn runs.
  3. Checks the selected runtime module ID against existing registrations and local source. It also checks every enabled module using the package binding: an update must preserve their canonical source and module directories. A conflicting provider or binding replacement stops before Yarn changes the dependency.
  4. Installs the inspected target using Yarn (yarn add for standalone apps; yarn workspace <app> add inside a monorepo). The inspection suppresses npm pack lifecycle scripts; installation still uses the app's normal package-manager behavior.
  5. Revalidates the installed package, selected module, existing consumers, and source identity. Then it checks metadata.requires against enabled modules. Missing dependencies include a npx create-mercato-module install command for package or GitHub locators, or enablement guidance for legacy module IDs. A same-name module from another origin does not satisfy an origin-qualified requirement.
  6. Registers the selected module in src/modules.ts:
    • Default flow: uses the installed package binding in from; GitHub installations retain a canonical locator.
    • With --eject: verifies ejectable: true, validates the source and destination, copies into src/modules/<moduleId>/, rewrites supported cross-module imports, and registers from: '@app' with retained provenance. An existing destination is preserved and must be reviewed before retrying.
  7. Runs the generators for the module registry, entity IDs, DI bindings, and API client. Duplicate enabled runtime IDs are rejected before generator output is written.

If validation fails after Yarn finishes, the dependency can remain installed without completed enablement. Inspect the reported state, src/modules.ts, and the package binding and lockfile; restore the intended binding through the package manager before retrying. If registration succeeded but generation failed, the module remains enabled and generated artifacts are stale: fix the error and rerun yarn mercato generate.

Examples

Install a single-module package with the default installed flow:

yarn mercato module add @open-mercato/test-package

Install a specific preview tag:

yarn mercato module add @open-mercato/test-package@preview

Install one module from a multi-module package:

yarn mercato module add @open-mercato/core --module currencies

Install and copy the module source into your app for local ownership:

yarn mercato module add @open-mercato/test-package --eject

Install a third-party module package published under a different scope:

yarn mercato module add @fastwhitecat/[email protected] --allow-third-party

Dependency identities and provenance

metadata.requires accepts legacy module IDs (customers), scoped npm packages with optional versions or tags (@pkarw/marketing_consents@preview), explicit npm locators (npm:[email protected]), and GitHub locators in the forms supported above. Bare snake-case names remain legacy runtime module IDs. Other bare repository shorthand is accepted only when it resolves unambiguously among enabled module origins; use npm:<name> to disambiguate an unscoped npm dependency. The suggested npx create-mercato-module install command also supports authenticated-account repository shorthand.

Canonical identities are npm:<package-name> and github:<owner>/<repository>. Versions, tags, and Git refs select what to install; dependency validation compares source identity and does not enforce version constraints. For example, npm:@pkarw/marketing_consents and npm:@open-mercato/marketing_consents are different origins even when both export marketing_consents.

Origin comes from the declared dependency source and optional retained provenance. An npm-installed package has an npm identity; its package.json repository field does not also make it a GitHub-installed module. A GitHub-installed package retains its GitHub identity even when its manifest has an npm package name. packageName records that manifest name, rather than adding a second source identity. Local file: directories and tarballs do not establish either origin: their canonical manifest name can populate packageName, while an unknown locator is omitted. Replacing an active binding must preserve proven source continuity for every enabled consumer before Yarn runs.

Module metadata and src/modules.ts can retain optional locator provenance for ejected or linked modules. Existing entries without these fields remain valid; a directory name alone never establishes npm or GitHub provenance. When retained provenance disagrees with an observable dependency source or installed manifest, generation stops with recovery guidance.

{
  id: 'marketing_consents',
  from: '@app',
  locator: 'github:pkarw/marketing-consents',
  packageName: '@pkarw/marketing_consents',
}

This entry satisfies a requirement for github:pkarw/marketing-consents or the legacy ID marketing_consents; it does not establish npm:@pkarw/marketing_consents as its installation source.

yarn mercato module add npm:@pkarw/marketing_consents@preview --allow-third-party
yarn mercato module add github:pkarw/marketing-consents --allow-third-party
yarn mercato module add 'https://github.com/pkarw/marketing-consents.git#main' --allow-third-party

Aliases, updates, and provider replacement

A package alias changes the dependency binding, while the runtime module ID remains the module directory name. Install an alias with Yarn, then enable that binding:

yarn add visits_source@npm:@agency/[email protected]
yarn mercato module enable visits_source --module visits --allow-third-party

The registration uses from: 'visits_source', retains the canonical manifest name @agency/visits, and resolves the npm origin npm:@agency/visits. Aliases cannot enable two providers exporting visits at the same time. module add accepts canonical npm and GitHub sources; use module enable for a binding already installed under an alias.

An update from the same npm package or canonical GitHub repository can keep existing enabled modules when the inspected target preserves all modules using that binding. Switching the binding to another origin, or dropping a module still used by an enabled entry, requires an explicit replacement:

  1. Remove the affected entries from src/modules.ts, including conditional registrations. This disables their generated discovery; an empty enabled-module list stays empty.
  2. Preserve and review local source and data. Resolve any occupied src/modules/<moduleId>/ destination before adding another provider. While the old package remains installed, resolve or reconfigure modules whose origin-qualified metadata.requires refers to the old provider, and review manually authored imports.
  3. Run yarn mercato generate and yarn build successfully before changing the dependency binding. Stop and fix failures while the old package remains available.
  4. Replace the dependency through the package manager and enable the intended provider.
  5. Run yarn mercato generate and yarn build again, then run tests covering the replacement.

Disabling discovery does not uninstall a dependency, delete source or data, or remove manually authored imports. Review those imports before removing a package or changing its binding. The CLI does not rename runtime IDs, rewrite arbitrary application imports, or migrate provider data.

A single package-backed registration with an app-local overlay remains supported. Two enabled entries with the same ID are invalid even when their from values match. To recover, keep the intended single registration, retain any local overlay files, and regenerate; do not repair generated registries by hand.

Post-Install Steps

# 1. Apply any new database migrations introduced by the module
yarn db:migrate

# 2. Start the dev server
yarn dev

If you ran the command with --eject, the module source is now in src/modules/<moduleId>/. You can freely edit it – the framework loads it from your local source rather than the package.

Troubleshooting

Previous: yarn initialize · Next: mercato module enable