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 / initialization-script-configuration

Initialization script configuration

Initialization script configuration is the template contract that tells the generator how to adapt a copied project. The contract lives in the create-solana-dapp entry of the template's package.json and describes tool requirements, package-manager rules, option flags, file changes, and user instructions.

Configuration contract

Metadata location

The generator reads initialization metadata from the create-solana-dapp package field after it copies a template. A package file without this field is valid and means that the template has no custom initialization rules. The package reader validates this field while it keeps unrelated package data available to the rest of the generation flow.

References: src/…/init-script-schema.ts• L4-5 src/…/get-package-json.ts• L6-31

Top-level fields

The top-level object groups configuration by the kind of project change it describes. All fields are optional, so a template can publish only the rules it needs.

FieldConfiguration role
versionsDeclares minimum versions for supported local tools.
packageManagerStates the package manager required by the template.
optionsDefines Boolean feature flags and their effects.
renameDescribes template-name replacements in selected paths.
instructionsSupplies follow-up text for the user.
skillsSupplies skill names for later agent-skill setup.

The schema also exports matching parser objects and inferred types. This gives template authors and package consumers one shared description of the runtime contract.

References: src/…/init-script-schema.ts• L67-84 src/index.ts• L19-38

Validation rules

Value shapes

Schema validation checks the type and basic shape of each declared value before the generation flow uses it. Instructions and skills are lists of strings. Version values are strings. The package manager is limited to the supported manager names.

Rename data is a map from a source name to a replacement entry. Each entry needs a to value and at least one search-path list. The current spelling is in; the older paths spelling remains accepted for compatibility, but one entry cannot use both spellings.

References: src/…/init-script-schema.ts• L7-47 src/…/package-manager.ts• L16-17

Package-file boundary

The package reader treats a missing package file as an input error and rejects invalid JSON or invalid initialization metadata. This boundary protects later setup steps from using a partial contract. It does not require every normal package.json field to be described by the initialization schema.

References: src/…/get-package-json.ts• L6-31

Rename compatibility

paths is a migration form for in, not a second path source. A template should use in in new metadata. If a legacy entry uses paths, the generator can process it and reports a deprecation warning; an entry with neither path field cannot pass schema validation.

References: src/…/init-script-schema.ts• L19-47 src/…/init-script-rename.ts• L51-53 src/…/init-script-rename.ts• L121-125

Option declarations

Option names and metadata

Options turn template-specific choices into Boolean command-line flags. Each option is a named record under options, and its name must start with a lower-case letter followed by lower-case letters, digits, or hyphens. The command line presents that name with a -- prefix.

An option can describe one or more effects. Its metadata can set a default, provide a description, assign a group, attach rename rules, add instructions, or name a package script to run before dependency installation.

FieldMeaning
defaultSelects the option when no option in its group was requested.
descriptionGives a consumer text that describes the choice.
groupPlaces the option in a mutually exclusive set.
renameAdds file or path changes for the selected option.
instructionsAdds follow-up text for the selected option.
runNames a package script and optional safe arguments.

References: src/…/init-script-schema.ts• L49-65 src/…/get-args-result.ts• L16-19

Default and group behavior

Groups express alternatives, not labels. A default option in a group is selected when no option from that group was requested. A requested option replaces that group's default, while defaults outside requested groups remain selected. Selecting two options from one group is invalid.

The generator checks requested names against the selected template's declarations. An unknown name fails before option effects run and includes the available names when there are any. This keeps command-line input tied to the metadata of the chosen template.

References: src/…/init-script-options.ts• L11-69 test/init-script-options.test.ts• L42-59 src/…/create-app.ts• L50-55

Selected option effects

After option selection, the generator collects the selected options' rename rules and instruction text. It keeps the rename rules as a shared set of search-and-replace scopes, so one rename does not rewrite the output produced by another selected rename.

This step passes both kinds of effects to the later initialization flow. The flow applies the content changes and reports the instruction text after setup.

References: src/…/init-script-options.ts• L72-85 test/init-script-options.test.ts• L61-74

Option script values

The run field points to a script name in the template's package.json; it is not a free-form shell command. It may include safe arguments made from letters, digits, whitespace, and a limited set of punctuation. Shell metacharacters and quoted arguments are rejected because the value reaches a shell.

The named script must exist when the option is selected. The selected option and its metadata are resolved before any option script runs, so a script that changes package.json cannot remove the already selected option effects or instructions.

References: src/…/init-script-schema.ts• L55-63 src/…/create-app.ts• L50-69 src/…/create-app-task-run-option-script.ts• L15-53

Version constraints

Supported requirements

The optional versions object states minimum versions for adb, anchor, and solana. Each key is optional, so a template can declare only the tools needed by its setup. The values are version strings that the local tool check compares as minimum requirements.

The requirement is advisory during initialization. A missing tool or a version below the requirement produces a warning and install or update guidance. A matching or newer version passes, and the check does not install or update the tool.

References: src/…/init-script-schema.ts• L13-17 src/…/init-script-version.ts• L5-18 src/…/init-script-version-check.ts• L8-41 src/…/validate-version.ts• L3-10

Requirement semantics

Version values mean “at least this version,” rather than “exactly this version.” The checker maps each declared key to its local version command and parses the command output before applying the minimum rule. An absent requirement is skipped, so omitting a key means that the template does not request a compatibility check for that tool.

References: src/…/init-script-version-check.ts• L8-24 src/…/init-script-version.ts• L13-15 src/…/get-version-command.ts• L1-29

Package-manager rules

Supported managers

The packageManager field can require pnpm, npm, yarn, or bun. The value is a template requirement, not a general package-manager configuration block. The generator uses it to choose the manager for later package operations.

References: src/…/init-script-schema.ts• L9-10 src/…/package-manager.ts• L16-17 src/…/init-script-package-manager.ts• L8-12

Selection and availability

When a template requires a package manager, an explicit conflicting user choice fails. If the user did not make a conflicting explicit choice, the template requirement becomes the effective manager. The generator then checks that the required manager is available in the target environment; an unavailable manager fails generation.

This rule lets a template protect commands that depend on a specific manager while still allowing the normal invocation manager to remain in use for templates with no requirement. A matching package-manager pin is retained, while an incompatible pin is handled by the broader creation flow before package work starts.

References: src/…/init-script-package-manager.ts• L8-32 src/…/create-app.ts• L32-48 src/…/package-manager.ts• L118-129

Instruction metadata

Base instructions

The top-level instructions list carries plain text for work that the generator should report after setup rather than execute itself. An absent or empty list contributes no messages. When present, its strings remain in their declared order.

References: src/…/init-script-schema.ts• L7-8 src/…/init-script-instructions.ts• L4-16

Option instructions

An option can add its own instruction list beside its project changes. The generator combines instructions from selected options with the base list, removes empty messages, and replaces {pm} with the effective package-manager name before returning the result to the caller.

This metadata gives a template a way to explain manual follow-up steps. It does not turn instruction text into a command or make the generator execute it.

References: src/…/init-script-schema.ts• L49-54 src/…/init-script-options.ts• L72-85 src/…/create-app-task-run-init-script.ts• L36-48

Change checklist

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

  • Keep the create-solana-dapp field and package reader aligned. A schema change that is not read at the package boundary has no effect on templates.
  • Keep option-name validation aligned with CLI flag extraction. A name accepted in metadata must be representable as the Boolean flag that reaches option resolution.
  • Keep option groups and defaults aligned with selection rules. Changing one side can select multiple alternatives or suppress the wrong default.
  • Keep every run declaration aligned with a package script in the same template. The schema can accept the name even though execution fails when the script is absent.
  • Keep version keys aligned with the version-check dispatch. A newly accepted key must also have a local command and compatibility check.
  • Keep package-manager enum values aligned with manager detection and command adapters. A newly accepted value must be usable for availability checks and later package work.
  • Preserve {pm} as the instruction placeholder contract when changing package-manager selection or instruction output.
  • Keep selected option rename scopes aligned with the shared rename flow. Applying them as separate passes can let one selected rename change another rename's output.

Important failure modes

TriggerConsequenceGuard
The initialization object has the wrong shape or a malformed field.Package data is rejected before initialization can use it.Validate template package.json with the shared initialization schema.
A rename entry uses both in and paths, or neither.The contract fails validation.Use one path list and prefer in for new templates.
A requested option is not declared by the selected template.Option resolution stops before project changes run.Declare the option under options or remove the flag.
Two selected options share a group.The selected configuration is rejected as mutually exclusive.Select at most one option in each group.
An option run value contains rejected shell characters.The initialization schema rejects the option metadata.Put complex commands in a package script and use only the allowed script reference form.
A required package manager is unavailable or conflicts with an explicit choice.Generation fails before package work starts.Install the required manager and select it when the template requires it.
A required tool is missing or below its minimum version.Initialization warns but continues without fixing the tool.Install or update the tool before relying on the template's setup.

Key files

FileWhy to read it
src/…/init-script-schema.tsDefines the full initialization contract and its value rules.
src/…/get-package-json.tsShows where package data and initialization metadata are parsed.
src/…/init-script-options.tsDefines option validation, defaults, groups, selected transformations, and instructions.
test/init-script-options.test.tsShows the guarantees for group defaults, mutually exclusive flags, unknown flags, and selected option effects.
src/…/init-script-version.ts and src/…/init-script-version-check.tsShow how declared tool requirements become compatibility checks and warnings.
src/…/validate-version.tsDefines the minimum-version rule.
src/…/init-script-package-manager.tsDefines template package-manager precedence and availability checks.
src/…/init-script-instructions.tsDefines the handling of base instruction metadata.
src/…/create-app-task-run-init-script.tsShows how selected metadata becomes final instructions during initialization.
src/…/create-app.tsShows when metadata is read and options are resolved in the creation flow.