Docs menuSource code delivery

Source code delivery

lpm add copies the files of a source package into the consumer's project. The consumer is the developer who runs lpm add. LPM CLI does not install the package itself as a dependency that the resolver manages.

lpm add @lpm.dev/acme.login-form

The copied files are part of the project. The consumer owns them, can change them, and decides when to take a newer package version.

Source delivery or dependency installation

lpm addlpm install
PurposeDeliver project-owned sourceManage a versioned dependency
UpdatesRe-run deliberately and review conflictsResolver-managed
CustomizationEdit the delivered files directlyWrap, configure, or fork the dependency
Typical useComponents, templates, starters, examplesLibraries, tools, and Swift packages

LPM.dev Registry package pages show lpm add if a version contains a valid lpm.config.json or a valid package.json > lpm.source path. Other versions show lpm install.

lpm add can copy a tarball from the LPM.dev Registry, npm, or a private registry in .npmrc. The LPM CLI add reference describes the routing and every command flag.

Configurable or simple delivery

Source packages have two delivery paths:

Package contentsLPM CLI behavior
Root lpm.config.jsonPrompts for options, selects files, rewrites imports, and installs declared dependencies
package.json > lpm.source without configCopies the declared source path. It does not ask for package options or install dependencies

lpm add can also copy the source of an ordinary package. Without lpm.config.json, LPM CLI makes a simple copy. It then lists the external imports in the copied JavaScript and TypeScript files, so that the consumer can install those packages.

Choose package options

The author defines the configurable fields in lpm.config.json. In an interactive run, lpm add asks for each field that the package spec does not set:

lpm add @lpm.dev/acme.ui-kit

To set fields in advance, add query values to the package spec:

lpm add "@lpm.dev/acme.ui-kit?component=dialog,button&styling=panda"

LPM CLI does not ask for a field that the spec sets. Separate multiple selections with commas.

--yes skips the prompts. For each field that the spec does not set, it uses the value in defaultConfig or the field's default. A required boolean field without a default is false. A required field with only one option uses that option. If a required field still has no value, the command fails and tells you to set it in the spec. An optional field without a value includes every file variant for that field.

lpm add @lpm.dev/acme.ui-kit --yes

A run is non-interactive if you pass --yes or --json, or if no terminal is attached. Every non-interactive run fills the fields with these --yes rules.

Source configuration describes how to write lpm.config.json.

Choose a destination

To set the destination, pass --path:

lpm add @lpm.dev/acme.ui-kit --path src/components/ui

Without --path, an interactive run in a JavaScript or TypeScript project asks for the install directory. The prompt suggests a directory from the project structure, and the consumer can change it. In a non-interactive run, a simple copy without lpm.config.json requires --path. A package with lpm.config.json uses the default directory of its ecosystem.

To preview the selected files and file actions without changing the project, pass --dry-run:

lpm add @lpm.dev/acme.ui-kit --dry-run

Import rewriting

For JavaScript and TypeScript source, LPM CLI can rewrite internal imports to match the consumer's destination and import alias.

LPM CLI gets the consumer alias from these sources, in order:

  1. An explicit --alias.
  2. In an interactive run, the alias prompt. The prompt suggests the alias from the tsconfig.json or jsconfig.json path mappings.
  3. In a non-interactive run, the tsconfig.json or jsconfig.json path mappings.

If the consumer leaves the alias prompt empty, LPM CLI keeps relative imports.

If the author declares importAlias in lpm.config.json, LPM CLI rewrites the imports that use the author alias. If the consumer has an alias, LPM CLI also rewrites relative imports between delivered files. This works even if the author did not declare importAlias.

// Package source
import { cn } from "../../lib/utils"

// Delivered source
import { cn } from "@/components/design-system/lib/utils"

A bare import names a package, such as react, next/link, or @radix-ui/dialog. LPM CLI does not change bare imports.

Existing files

When a destination file already exists:

  • LPM CLI replaces an unchanged file from an earlier lpm add of the same package with the new version.
  • An interactive run can keep the file, overwrite it, or show a diff first.
  • A non-interactive run keeps the existing file.
  • --force overwrites the existing file.
  • LPM CLI skips a JavaScript or TypeScript file whose content is identical to the new file.

LPM CLI does not replace a file that the consumer changed, unless the consumer chooses to overwrite it or passes --force.

Declared dependencies

A package with lpm.config.json can declare dependencies for each consumer choice. LPM CLI adds the matching dependencies to the consumer's package.json. Then it runs the selected package manager.

Dependencies can come from npm, the LPM.dev Registry, or a private registry in .npmrc. The default package manager is LPM CLI. To use another one, pass --pm with npm, pnpm, yarn, or bun. With --pm auto, LPM CLI selects the package manager from the lockfile in the project.

lpm add @lpm.dev/acme.ui-kit --pm lpm
lpm add @lpm.dev/acme.ui-kit --no-install-deps

If lpm.config.json has no dependencies field, LPM CLI uses the source package's dependencies and peerDependencies as a legacy fallback. If the config declares dependencies, LPM CLI does not use the fallback, even when the selected options match no entries.

If LPM CLI must install dependencies, the consumer project must have a package.json. LPM CLI looks for it before it copies files. To copy the files and manage the imports yourself, pass --no-install-deps.

Failure and removal

If the file copy, the package.json change, or the dependency installation fails, LPM CLI undoes the add. It restores the copied files, package.json, and the affected lockfiles to their state before the add. It also removes the directories that it created for the add.

After a successful add, LPM CLI records the delivered files in lpm-sources.json at the project root. lpm remove uses this record to find the files that the package wrote. The lpm remove reference describes the removal.

Swift packages

Use lpm install for Swift libraries. It edits Package.swift or the Xcode dependency host. Swift Package Manager then resolves the transitive dependencies and verifies the Registry signatures.

lpm add remains a legacy Swift source-copy path. It does not create a Swift manifest, and it does not link a local package into .xcodeproj.

Swift Package Registry describes the current Swift installation model.

See also