pluginmigrate

package
v0.18.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package pluginmigrate moves extensions living in custom/ under Composer management: Shopware Store plugins are required from the Store packagist (and their local copy removed), everything else is registered as a Composer path repository. Afterwards `project upgrade` can resolve every extension.

Index

Constants

View Source
const StoreRepositoryURL = "https://packages.shopware.com"

StoreRepositoryURL is the Shopware packagist serving Store plugins.

Variables

RunSteps lists the visible steps in execution order.

Functions

This section is empty.

Types

type ActionKind

type ActionKind int

ActionKind classifies how one extension is migrated.

const (
	// ActionStoreRequire requires the extension from the Shopware Store
	// packagist and removes the local copy.
	ActionStoreRequire ActionKind = iota
	// ActionComposerRequire requires the extension from a repository the
	// project already resolves against (packagist.org or a configured
	// composer repository) and removes the local copy. Needs no Store token.
	ActionComposerRequire
	// ActionPathRepository keeps the files where they are and registers them
	// as a Composer path repository.
	ActionPathRepository
	// ActionUnsupported marks an extension the migrator cannot handle (no
	// composer.json with a package name); it is left untouched.
	ActionUnsupported
)

func (ActionKind) Label

func (k ActionKind) Label() string

Label returns the review-table text for an action.

type Availability

type Availability struct {
	// Store lists the package names on packages.shopware.com the token can
	// access (nil without a token).
	Store map[string]struct{}
	// Published maps a scanned extension's composer name to the versions the
	// project's regular repositories offer (packagist.org plus the composer
	// repositories configured in composer.json). Needs no token.
	Published map[string][]string
}

Availability describes which reachable Composer repositories can serve the scanned extensions.

type HeadlessOptions

type HeadlessOptions struct {
	// Token is the Shopware Packagist token (SHOPWARE_PACKAGIST_TOKEN).
	// Empty is allowed: every extension is then managed via a path
	// repository instead of being required from the Store.
	Token string
	// DryRun stops after printing the plan without modifying any file.
	DryRun bool
	// Out receives the progress output.
	Out io.Writer
}

HeadlessOptions configure a non-interactive migration run.

type Plan

type Plan struct {
	Extensions []PlannedExtension
	// AddStoreRepository adds packages.shopware.com to composer.json.
	AddStoreRepository bool
}

Plan is the full migration the review step confirms.

func BuildPlan

func BuildPlan(extensions []ScannedExtension, avail Availability) Plan

BuildPlan classifies the scanned extensions, preferring the source that keeps updates flowing: the Shopware Store (token required), then a repository the project already resolves against (packagist.org or a configured composer repository — no token needed) when it offers the exact installed version, then a path repository as the fallback that also puts the extension under Composer management — just without updates.

func (Plan) Actionable

func (p Plan) Actionable() bool

Actionable reports whether the plan changes anything.

func (Plan) Count

func (p Plan) Count(kind ActionKind) int

Count returns how many extensions carry the given action.

func (Plan) PathRepositories

func (p Plan) PathRepositories() []string

PathRepositories lists the relative paths registered as path repositories.

func (Plan) RemoveDirs

func (p Plan) RemoveDirs() []string

RemoveDirs lists the absolute directories removed after the require succeeded — the local copies of extensions that are now installed from a repository instead.

func (Plan) RequireArgs

func (p Plan) RequireArgs() []string

RequireArgs lists the `composer require` arguments of the plan.

type PlannedExtension

type PlannedExtension struct {
	ScannedExtension
	Kind ActionKind
	// RequireArg is the `composer require` argument, empty for unsupported
	// extensions.
	RequireArg string
}

PlannedExtension is one extension with its migration action.

type PluginMigrator

type PluginMigrator struct {
	// contains filtered or unexported fields
}

PluginMigrator migrates a project's custom/ extensions to Composer.

External dependencies live in unexported fields with production defaults so tests can replace them per instance.

func NewPluginMigrator

func NewPluginMigrator(projectRoot string, exec executor.Executor) *PluginMigrator

NewPluginMigrator creates a migrator for the project at projectRoot. The executor runs composer and the console in the project's environment.

func (*PluginMigrator) FetchAvailability

func (m *PluginMigrator) FetchAvailability(ctx context.Context, token string, extensions []ScannedExtension) (Availability, error)

FetchAvailability queries packages.shopware.com (when a token is given — this doubles as the token validation) and the project's regular Composer repositories for the scanned extensions.

func (*PluginMigrator) Run

func (m *PluginMigrator) Run(ctx context.Context, plan Plan, token string) <-chan StepEvent

Run executes the migration asynchronously and streams progress events. The channel closes after a final StepFinished event. Failures before the destructive directory removal roll composer.json, composer.lock, and auth.json back.

func (*PluginMigrator) RunHeadless

func (m *PluginMigrator) RunHeadless(ctx context.Context, opts HeadlessOptions) error

RunHeadless migrates the project's custom/ extensions without the TUI — for --no-interaction runs and environments without a terminal.

func (*PluginMigrator) Scan

Scan lists the extensions living below custom/ — the ones Composer does not manage. It is read-only.

type ScannedExtension

type ScannedExtension struct {
	Name         string
	ComposerName string
	Version      string
	// Path is absolute; RelPath is relative to the project root
	// (e.g. custom/plugins/SwagDemo).
	Path    string
	RelPath string
}

ScannedExtension is one extension found below custom/.

type StepEvent

type StepEvent struct {
	Step  StepID
	State StepState
	Line  string
	Err   error
}

StepEvent is emitted while the migration executes. Line events carry streamed subprocess output (State is StateRunning); state events mark step transitions.

type StepID

type StepID int

StepID identifies one step of the migration execution.

const (
	StepWriteConfig StepID = iota
	StepComposerRequire
	StepRemoveDirs
	StepPluginRefresh
	// StepFinished is the synthetic final event: StateOK when the migration
	// succeeded, StateFail (with Err) when it was aborted and rolled back.
	StepFinished
)

func (StepID) Label

func (s StepID) Label() string

Label returns the checklist text for a step.

type StepState

type StepState int

StepState is the lifecycle state of a step.

const (
	StatePending StepState = iota
	StateRunning
	StateOK
	StateWarn
	StateFail
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL