Introducing a new way to review your PRs.

Read the announcement

solana-foundation / create-solana-dapp

The fastest way to create Solana apps 🚀 Templates 👉 https://github.com/solana-foundation/templates

View on GitHub

18 documents · Updated Nov 6, 2026

docs / dependency-installation-and-package-managers

Dependency installation and package managers

Dependency installation turns a cloned template into a usable project. The scaffolding pipeline chooses one supported package manager, checks template requirements, removes metadata that would conflict with that choice, and runs the matching install command in the new project.

This page is a child of Project scaffolding pipeline. Read Target path and project metadata for the destination and package metadata context, and Template acquisition and recovery for the source handoff that produces the target project.

Package-manager selection

The package-manager selection is the shared decision that drives both template compatibility and dependency installation. The CLI first infers the manager that invoked it, while project-level detection can infer a manager from lock files when no explicit choice is supplied.

The supported managers are:

ManagerProject lock file
npmpackage-lock.json
pnpmpnpm-lock.yaml
yarnyarn.lock
bunbun.lock

Invocation detection uses package-manager environment markers and falls back to npm. Lock-file detection checks for Yarn, pnpm, and Bun files in that order, then falls back to npm. The selected manager is carried in the resolved creation arguments and is used by later tasks. src/index.ts src/…/package-manager.ts src/…/package-manager.ts

References: src/index.ts• L61-70 src/…/package-manager.ts• L16-36 src/…/package-manager.ts• L131-143

Template package-manager requirements

Template package-manager requirements let a template choose the tool that its scripts and dependencies expect. The requirement is read from the template's create-solana-dapp metadata after the template is copied to the target directory.

When the template requires a manager, the pipeline uses that manager if the user did not make an explicit conflicting choice. An explicit conflict stops creation. The required manager must also be available in the target environment. This check changes the effective manager before compatibility cleanup and installation run.

flowchart TD
    A[Template package metadata] --> B{Template requires a manager?}
    B -- No --> C[Keep selected manager]
    B -- Yes --> D{Explicit choice conflicts?}
    D -- Yes --> E[Stop with a compatibility error]
    D -- No --> F{Required manager available?}
    F -- No --> G[Stop with an availability error]
    F -- Yes --> H[Use template-required manager]

This rule protects templates that depend on a particular package-manager behavior. A missing package manager is reported before any install command is run. src/…/init-script-package-manager.ts src/…/init-script-schema.ts

References: src/…/init-script-package-manager.ts• L8-32 src/…/init-script-schema.ts• L4-10 src/…/get-args-result.ts• L5-19

Compatibility cleanup

Compatibility cleanup removes a template's packageManager pin when it names a different effective manager. A package-manager pin is metadata such as pnpm@10.15.1; some managers reject a project that names another manager, so leaving the pin can prevent installation.

The cleanup runs after template requirements update the effective manager. It keeps a matching pin and removes only a conflicting pin. It preserves the rest of package.json, warns about the change, and runs even when dependency installation is skipped. This ordering also ensures later template scripts do not run through a package-manager declaration that cannot work with the selected tool. src/…/create-app.ts src/…/remove-incompatible-package-manager.ts

References: src/…/create-app.ts• L32-47 src/…/remove-incompatible-package-manager.ts• L18-35 src/…/get-package-json.ts• L6-31

Dependency installation

The dependency-installation task prepares the target project for one package manager and then runs its install operation. The task is enabled unless the user selects skipInstall, so a skipped install does not prevent the earlier package-manager checks or metadata cleanup.

The task follows this sequence:

  1. Select the install command and expected lock file for the effective manager.
  2. Remove existing lock files that belong to other supported managers.
  3. Run the selected install command in the target directory.
  4. Report success through the task runner or fail with an installation error.

The selected lock file stays in place. Other lock files are removed without a shell command so stale resolution data cannot compete with the selected manager. A failure while removing a lock-file path stops installation rather than hiding an unexpected filesystem problem. src/…/create-app-task-install-dependencies.ts

sequenceDiagram
    participant P as Scaffolding pipeline
    participant A as Package-manager adapter
    participant F as Target project
    participant C as Child-process adapter

    P->>A: Resolve install command and lock file
    A-->>P: Manager-specific install plan
    P->>F: Remove stale lock files
    P->>C: Run install in target directory
    C-->>P: Success or error with log path
    P-->>P: Show task result or fail creation

References: src/…/create-app-task-install-dependencies.ts• L10-43 src/…/create-app.ts• L50-72 src/…/child-process-utils.ts• L15-39

Package-manager adapters

The package-manager adapter is the boundary between the scaffolding flow and external package-manager commands. It gives each supported manager a common operation set while accounting for differences in install syntax, lock files, executable choice, and manager version behavior.

ManagerInstall behaviorAdapter concerns
npmInstalls without running package scriptsUses npx for executable commands
pnpmInstalls without scripts and permits lock-file updatesChooses pnpm exec or pnpx from the installed version
yarnUses the installed Yarn generationHandles Classic and Berry command differences
bunUses Bun's install commandUses Bun directly and does not expose a registry lookup command

The adapter also provides commands for global additions and registry lookup where the manager supports them. It reads and caches the installed manager version because the version affects command selection. The install task consumes only the install command and lock-file result, while other pipeline operations can use the remaining adapter commands. src/…/package-manager.ts src/…/package-manager.ts

References: src/…/package-manager.ts• L38-114 src/…/package-manager.ts• L116-129 src/…/create-app-task-install-dependencies.ts• L10-12

Installation errors

Installation errors stop the task and preserve diagnostic output outside the target directory. The child-process adapter runs the command with the target as its working directory, captures standard output and error text, and writes an error log beside the target before the task reports failure.

This placement matters because the broader creation flow can remove a newly created target after a failure. The external log remains available for diagnosis even when the failed project directory does not. src/…/child-process-utils.ts src/…/create-app.ts

References: src/…/child-process-utils.ts• L15-39 src/…/create-app.ts• L22-79 src/…/clack-tasks.ts• L31-56

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the supported-manager list aligned with the lock-file map, template schema, and command adapter.
  • Preserve the order between template manager precedence, package metadata cleanup, option scripts, and dependency installation.
  • Keep each adapter's expected lock file aligned with the lock files removed before install.
  • Keep installation diagnostics outside a target directory that the failure cleanup can delete.
  • Keep the explicit-selection rule aligned between argument resolution and template manager validation.

Important failure modes

TriggerConsequenceGuard
A template requires a manager that is not installedCreation stops before dependency installationCheck the required manager version in the target context
An explicit manager conflicts with the template requirementCreation stops instead of running incompatible scriptsReject the explicit selection before changing the effective manager
A generated package.json pins another managerThe selected manager can reject the projectRemove only the conflicting packageManager field
A stale lock-file path cannot be removedInstallation does not run with uncertain dependency statePropagate the removal error rather than suppress it
The install command exits with an errorCreation fails and the target may be cleaned upWrite command output to the adjacent error log

Key files

FileWhy to read it
src/…/create-app.tsShows where manager precedence, cleanup, and installation fit in the scaffolding order
src/…/package-manager.tsDefines supported managers, detection rules, version checks, and command adapters
src/…/init-script-package-manager.tsDefines how template requirements affect the effective manager
src/…/remove-incompatible-package-manager.tsDefines package metadata cleanup for conflicting manager pins
src/…/create-app-task-install-dependencies.tsDefines stale lock-file cleanup and the install task
src/…/child-process-utils.tsDefines command execution and preserved installation diagnostics
src/…/init-script-schema.tsDefines the template metadata field that can require a manager