2026-01-29 00:32:04 +00:00
|
|
|
// Package publishers provides release publishing implementations.
|
|
|
|
|
package publishers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"embed"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"text/template"
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
|
|
|
|
|
"github.com/host-uk/core/pkg/io"
|
2026-01-29 00:32:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//go:embed templates/npm/*.tmpl
|
|
|
|
|
var npmTemplates embed.FS
|
|
|
|
|
|
|
|
|
|
// NpmConfig holds npm-specific configuration.
|
|
|
|
|
type NpmConfig struct {
|
|
|
|
|
// Package is the npm package name (e.g., "@host-uk/core").
|
|
|
|
|
Package string
|
|
|
|
|
// Access is the npm access level: "public" or "restricted".
|
|
|
|
|
Access string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NpmPublisher publishes releases to npm using the binary wrapper pattern.
|
|
|
|
|
type NpmPublisher struct{}
|
|
|
|
|
|
|
|
|
|
// NewNpmPublisher creates a new npm publisher.
|
|
|
|
|
func NewNpmPublisher() *NpmPublisher {
|
|
|
|
|
return &NpmPublisher{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Name returns the publisher's identifier.
|
|
|
|
|
func (p *NpmPublisher) Name() string {
|
|
|
|
|
return "npm"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Publish publishes the release to npm.
|
|
|
|
|
// It generates a binary wrapper package that downloads the correct platform binary on postinstall.
|
|
|
|
|
func (p *NpmPublisher) Publish(ctx context.Context, release *Release, pubCfg PublisherConfig, relCfg ReleaseConfig, dryRun bool) error {
|
|
|
|
|
// Parse npm config
|
|
|
|
|
npmCfg := p.parseConfig(pubCfg, relCfg)
|
|
|
|
|
|
|
|
|
|
// Validate configuration
|
|
|
|
|
if npmCfg.Package == "" {
|
|
|
|
|
return fmt.Errorf("npm.Publish: package name is required (set publish.npm.package in config)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get repository
|
|
|
|
|
repo := ""
|
|
|
|
|
if relCfg != nil {
|
|
|
|
|
repo = relCfg.GetRepository()
|
|
|
|
|
}
|
|
|
|
|
if repo == "" {
|
|
|
|
|
detectedRepo, err := detectRepository(release.ProjectDir)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: could not determine repository: %w", err)
|
|
|
|
|
}
|
|
|
|
|
repo = detectedRepo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get project name (binary name)
|
|
|
|
|
projectName := ""
|
|
|
|
|
if relCfg != nil {
|
|
|
|
|
projectName = relCfg.GetProjectName()
|
|
|
|
|
}
|
|
|
|
|
if projectName == "" {
|
|
|
|
|
// Try to infer from package name
|
|
|
|
|
parts := strings.Split(npmCfg.Package, "/")
|
|
|
|
|
projectName = parts[len(parts)-1]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Strip leading 'v' from version for npm
|
|
|
|
|
version := strings.TrimPrefix(release.Version, "v")
|
|
|
|
|
|
|
|
|
|
// Template data
|
|
|
|
|
data := npmTemplateData{
|
|
|
|
|
Package: npmCfg.Package,
|
|
|
|
|
Version: version,
|
|
|
|
|
Description: fmt.Sprintf("%s CLI", projectName),
|
|
|
|
|
License: "MIT",
|
|
|
|
|
Repository: repo,
|
|
|
|
|
BinaryName: projectName,
|
|
|
|
|
ProjectName: projectName,
|
|
|
|
|
Access: npmCfg.Access,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if dryRun {
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
return p.dryRunPublish(release.FS, data, &npmCfg)
|
2026-01-29 00:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
return p.executePublish(ctx, release.FS, data, &npmCfg)
|
2026-01-29 00:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parseConfig extracts npm-specific configuration from the publisher config.
|
|
|
|
|
func (p *NpmPublisher) parseConfig(pubCfg PublisherConfig, relCfg ReleaseConfig) NpmConfig {
|
|
|
|
|
cfg := NpmConfig{
|
|
|
|
|
Package: "",
|
|
|
|
|
Access: "public",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Override from extended config if present
|
|
|
|
|
if ext, ok := pubCfg.Extended.(map[string]any); ok {
|
|
|
|
|
if pkg, ok := ext["package"].(string); ok && pkg != "" {
|
|
|
|
|
cfg.Package = pkg
|
|
|
|
|
}
|
|
|
|
|
if access, ok := ext["access"].(string); ok && access != "" {
|
|
|
|
|
cfg.Access = access
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cfg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// npmTemplateData holds data for npm templates.
|
|
|
|
|
type npmTemplateData struct {
|
|
|
|
|
Package string
|
|
|
|
|
Version string
|
|
|
|
|
Description string
|
|
|
|
|
License string
|
|
|
|
|
Repository string
|
|
|
|
|
BinaryName string
|
|
|
|
|
ProjectName string
|
|
|
|
|
Access string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// dryRunPublish shows what would be done without actually publishing.
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
func (p *NpmPublisher) dryRunPublish(m io.Medium, data npmTemplateData, cfg *NpmConfig) error {
|
2026-01-29 00:32:04 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
fmt.Println("=== DRY RUN: npm Publish ===")
|
|
|
|
|
fmt.Println()
|
|
|
|
|
fmt.Printf("Package: %s\n", data.Package)
|
|
|
|
|
fmt.Printf("Version: %s\n", data.Version)
|
|
|
|
|
fmt.Printf("Access: %s\n", data.Access)
|
|
|
|
|
fmt.Printf("Repository: %s\n", data.Repository)
|
|
|
|
|
fmt.Printf("Binary: %s\n", data.BinaryName)
|
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
|
|
// Generate and show package.json
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
pkgJSON, err := p.renderTemplate(m, "templates/npm/package.json.tmpl", data)
|
2026-01-29 00:32:04 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("npm.dryRunPublish: %w", err)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("Generated package.json:")
|
|
|
|
|
fmt.Println("---")
|
|
|
|
|
fmt.Println(pkgJSON)
|
|
|
|
|
fmt.Println("---")
|
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
|
|
fmt.Println("Would run: npm publish --access", data.Access)
|
|
|
|
|
fmt.Println()
|
|
|
|
|
fmt.Println("=== END DRY RUN ===")
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// executePublish actually creates and publishes the npm package.
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
func (p *NpmPublisher) executePublish(ctx context.Context, m io.Medium, data npmTemplateData, cfg *NpmConfig) error {
|
2026-01-29 00:32:04 +00:00
|
|
|
// Check for NPM_TOKEN
|
|
|
|
|
if os.Getenv("NPM_TOKEN") == "" {
|
|
|
|
|
return fmt.Errorf("npm.Publish: NPM_TOKEN environment variable is required")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create temp directory for package
|
|
|
|
|
tmpDir, err := os.MkdirTemp("", "npm-publish-*")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to create temp directory: %w", err)
|
|
|
|
|
}
|
feat: infrastructure packages and lint cleanup (#281)
* ci: consolidate duplicate workflows and merge CodeQL configs
Remove 17 duplicate workflow files that were split copies of the
combined originals. Each family (CI, CodeQL, Coverage, PR Build,
Alpha Release) had the same job duplicated across separate
push/pull_request/schedule/manual trigger files.
Merge codeql.yml and codescan.yml into a single codeql.yml with
a language matrix covering go, javascript-typescript, python,
and actions — matching the previous default setup coverage.
Remaining workflows (one per family):
- ci.yml (push + PR + manual)
- codeql.yml (push + PR + schedule, all languages)
- coverage.yml (push + PR + manual)
- alpha-release.yml (push + manual)
- pr-build.yml (PR + manual)
- release.yml (tag push)
- agent-verify.yml, auto-label.yml, auto-project.yml
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add collect, config, crypt, plugin packages and fix all lint issues
Add four new infrastructure packages with CLI commands:
- pkg/config: layered configuration (defaults → file → env → flags)
- pkg/crypt: crypto primitives (Argon2id, AES-GCM, ChaCha20, HMAC, checksums)
- pkg/plugin: plugin system with GitHub-based install/update/remove
- pkg/collect: collection subsystem (GitHub, BitcoinTalk, market, papers, excavate)
Fix all golangci-lint issues across the entire codebase (~100 errcheck,
staticcheck SA1012/SA1019/ST1005, unused, ineffassign fixes) so that
`core go qa` passes with 0 issues.
Closes #167, #168, #170, #250, #251, #252, #253, #254, #255, #256
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 11:34:43 +00:00
|
|
|
defer func() { _ = os.RemoveAll(tmpDir) }()
|
2026-01-29 00:32:04 +00:00
|
|
|
|
|
|
|
|
// Create bin directory
|
|
|
|
|
binDir := filepath.Join(tmpDir, "bin")
|
|
|
|
|
if err := os.MkdirAll(binDir, 0755); err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to create bin directory: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate package.json
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
pkgJSON, err := p.renderTemplate(m, "templates/npm/package.json.tmpl", data)
|
2026-01-29 00:32:04 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to render package.json: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(filepath.Join(tmpDir, "package.json"), []byte(pkgJSON), 0644); err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to write package.json: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate install.js
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
installJS, err := p.renderTemplate(m, "templates/npm/install.js.tmpl", data)
|
2026-01-29 00:32:04 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to render install.js: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(filepath.Join(tmpDir, "install.js"), []byte(installJS), 0644); err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to write install.js: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate run.js
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
runJS, err := p.renderTemplate(m, "templates/npm/run.js.tmpl", data)
|
2026-01-29 00:32:04 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to render run.js: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(filepath.Join(binDir, "run.js"), []byte(runJS), 0755); err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to write run.js: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create .npmrc with token
|
feat: git command, build improvements, and go fmt git-aware (#74)
* feat(go): make go fmt git-aware by default
- By default, only check changed Go files (modified, staged, untracked)
- Add --all flag to check all files (previous behaviour)
- Reduces noise when running fmt on large codebases
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat(build): minimal output by default, add missing i18n
- Default output now shows single line: "Success Built N artifacts (dir)"
- Add --verbose/-v flag to show full detailed output
- Add all missing i18n translations for build commands
- Errors still show failure reason in minimal mode
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add root-level `core git` command
- Create pkg/gitcmd with git workflow commands as root menu
- Export command builders from pkg/dev (AddCommitCommand, etc.)
- Commands available under both `core git` and `core dev` for compatibility
- Git commands: health, commit, push, pull, work, sync, apply
- GitHub orchestration stays in dev: issues, reviews, ci, impact
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat(qa): add docblock coverage checking
Implement docblock/docstring coverage analysis for Go code:
- New `core qa docblock` command to check coverage
- Shows compact file:line list when under threshold
- Integrate with `core go qa` as a default check
- Add --docblock-threshold flag (default 80%)
The checker uses Go AST parsing to find exported symbols
(functions, types, consts, vars) without documentation.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: address CodeRabbit review feedback
- Fix doc comment: "status" → "health" in gitcmd package
- Implement --check flag for `core go fmt` (exits non-zero if files need formatting)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* docs: add docstrings for 100% coverage
Add documentation comments to all exported symbols:
- pkg/build: ProjectType constants
- pkg/cli: LogLevel, RenderStyle, TableStyle
- pkg/framework: ServiceFor, MustServiceFor, Core.Core
- pkg/git: GitError.Error, GitError.Unwrap
- pkg/i18n: Handler Match/Handle methods
- pkg/log: Level constants
- pkg/mcp: Tool input/output types
- pkg/php: Service constants, QA types, service methods
- pkg/process: ServiceError.Error
- pkg/repos: RepoType constants
- pkg/setup: ChangeType, ChangeCategory constants
- pkg/workspace: AddWorkspaceCommands
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* chore: standardize line endings to LF
Add .gitattributes to enforce LF line endings for all text files.
Normalize all existing files to use Unix-style line endings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: address CodeRabbit review feedback
- cmd_format.go: validate --check/--fix mutual exclusivity, capture stderr
- cmd_docblock.go: return error instead of os.Exit(1) for proper error handling
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: address CodeRabbit review feedback (round 2)
- linuxkit.go: propagate state update errors, handle cmd.Wait() errors in waitForExit
- mcp.go: guard against empty old_string in editDiff to prevent runaway edits
- cmd_docblock.go: log parse errors instead of silently skipping
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 10:48:44 +00:00
|
|
|
npmrc := "//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n"
|
2026-01-29 00:32:04 +00:00
|
|
|
if err := os.WriteFile(filepath.Join(tmpDir, ".npmrc"), []byte(npmrc), 0600); err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: failed to write .npmrc: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run npm publish
|
|
|
|
|
cmd := exec.CommandContext(ctx, "npm", "publish", "--access", data.Access)
|
|
|
|
|
cmd.Dir = tmpDir
|
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
cmd.Env = append(os.Environ(), "NPM_TOKEN="+os.Getenv("NPM_TOKEN"))
|
|
|
|
|
|
|
|
|
|
fmt.Printf("Publishing %s@%s to npm...\n", data.Package, data.Version)
|
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
|
return fmt.Errorf("npm.Publish: npm publish failed: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("Published %s@%s to npm\n", data.Package, data.Version)
|
|
|
|
|
fmt.Printf(" https://www.npmjs.com/package/%s\n", data.Package)
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// renderTemplate renders an embedded template with the given data.
|
Migrate pkg/release to io.Medium abstraction (#290)
* chore(io): migrate pkg/release to io.Medium abstraction
Migrated `pkg/release` and its subpackages to use the `io.Medium` abstraction for filesystem operations. This enables better testability and support for alternative storage backends.
Changes:
- Added `FS io.Medium` field to `release.Release` and `publishers.Release` structs.
- Updated `LoadConfig`, `ConfigExists`, and `WriteConfig` in `pkg/release/config.go` to accept `io.Medium`.
- Updated `Publish`, `Run`, `findArtifacts`, and `buildArtifacts` in `pkg/release/release.go` to use `io.Medium`.
- Migrated all publishers (`aur`, `chocolatey`, `docker`, `github`, `homebrew`, `linuxkit`, `npm`, `scoop`) to use `io.Medium` for file operations.
- Implemented custom template overrides in publishers by checking for templates in `.core/templates/<publisher>/` via `io.Medium`.
- Updated all relevant tests to provide `io.Medium`.
* chore(io): fix missing callers in pkg/release migration
Updated callers of `release` package functions that had their signatures changed during the `io.Medium` migration.
Fixed files:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These changes ensure the project compiles successfully by providing `io.Local` to `LoadConfig`, `WriteConfig`, and `ConfigExists`.
* chore(io): fix build errors in pkg/release migration
Fixed compilation errors by updating all callers of `release.LoadConfig`, `release.ConfigExists`, and `release.WriteConfig` to provide the required `io.Medium` argument.
Files updated:
- `internal/cmd/ci/cmd_init.go`
- `internal/cmd/ci/cmd_publish.go`
- `pkg/build/buildcmd/cmd_release.go`
These entry points now correctly pass `io.Local` to the `release` package functions.
2026-02-04 15:07:13 +00:00
|
|
|
func (p *NpmPublisher) renderTemplate(m io.Medium, name string, data npmTemplateData) (string, error) {
|
|
|
|
|
var content []byte
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
// Try custom template from medium
|
|
|
|
|
customPath := filepath.Join(".core", name)
|
|
|
|
|
if m != nil && m.IsFile(customPath) {
|
|
|
|
|
customContent, err := m.Read(customPath)
|
|
|
|
|
if err == nil {
|
|
|
|
|
content = []byte(customContent)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fallback to embedded template
|
|
|
|
|
if content == nil {
|
|
|
|
|
content, err = npmTemplates.ReadFile(name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("failed to read template %s: %w", name, err)
|
|
|
|
|
}
|
2026-01-29 00:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmpl, err := template.New(filepath.Base(name)).Parse(string(content))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("failed to parse template %s: %w", name, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
if err := tmpl.Execute(&buf, data); err != nil {
|
|
|
|
|
return "", fmt.Errorf("failed to execute template %s: %w", name, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf.String(), nil
|
|
|
|
|
}
|