Menu

Package Manager

Relevant source files

The Package Manager is OwnLang's command-line utility for project management and dependency handling. It provides the own command for initializing projects, managing dependencies, and running scripts. The system uses a global registry hosted on GitHub and manages local project configurations through own-package.json files.

For information about other CLI tools like the beautifier and linter, see CLI Tools and Utilities. For details about the REPL interactive environment, see Interactive REPL.

Architecture Overview

The package manager is implemented as a collection of OwnLang classes that work together to provide comprehensive project management functionality.

Class Structure and Dependencies

Package Manager Class Hierarchy

Sources: ownlang-desktop/src/main/resources/scripts/own.own25-29 ownlang-desktop/src/main/resources/scripts/own/Own.own5-8

System Context and Initialization

The package manager creates a shared context object that provides common services to all components:

Context PropertyPurposeImplementation
DEBUGDebug logging flagEnvironment variable OWN_DEBUG
TMPDIRTemporary directory pathEnvironment variables TEMP/TMP
OSNAMEOperating system detectionJava system property os.name
loggerColored console outputCustom logging with ANSI colors
registryGlobal package registryGitHub-hosted JSON registry
configProject configurationown-package.json management
packagesPackage operationsDownload, install, usage display
projectsProject scaffoldingDefault file generation

Sources: ownlang-desktop/src/main/resources/scripts/own.own20-29 ownlang-desktop/src/main/resources/scripts/own.own10-18

Command Line Interface

The package manager supports multiple commands through argument pattern matching in the main script:

Command Processing Flow

Command Routing in own.own

Sources: ownlang-desktop/src/main/resources/scripts/own.own31-40

Available Commands

CommandSyntaxPurpose
initown initInitialize new project with default structure
addown add <package>Add package dependency to configuration
installown installDownload all dependencies from configuration
runown run [script]Execute project scripts (default or named)
usageown usage <package>Display package usage documentation

Sources: ownlang-desktop/src/main/resources/scripts/own/Own.own61-74

Configuration System

Project configuration is managed through the own-package.json file, which follows a structured format similar to Node.js package.json.

Configuration Schema

The Config class handles all configuration operations and provides default values:

PropertyDefault ValuePurpose
nameCurrent directory name (sanitized)Project identifier
version"1.0.0"Project version
authorCurrent user nameProject author
program"main.own"Main program file
scripts{"default": ["$ownlang$", "-f", "$program$"]}Executable scripts
dependencies{}Package dependencies

Sources: ownlang-desktop/src/main/resources/scripts/own/Config.own41-57

Configuration File Operations

Configuration Lifecycle Management

Sources: ownlang-desktop/src/main/resources/scripts/own/Config.own12-38

Package Registry and Management

The package manager uses a global registry hosted on GitHub to discover and download packages.

Registry Architecture

Registry Data Flow

Sources: ownlang-desktop/src/main/resources/scripts/own/Registry.own4 ownlang-desktop/src/main/resources/scripts/own/Registry.own10

Package Download Process

The system supports different package types, with GitHub Gists being the primary supported format:

Package TypeSourceFile Resolution
gistGitHub Gist APIRaw URL extraction from JSON response
DefaultNot implementedEmpty array returned

The download process involves:

  1. Registry Lookup: Check if package exists in global registry
  2. Version Validation: Compare requested version with available version
  3. File Enumeration: Get list of files from package source
  4. Local Download: Download files to own-modules/<package>/ directory
  5. Configuration Update: Save dependency to own-package.json

Sources: ownlang-desktop/src/main/resources/scripts/own/Packages.own81-93 ownlang-desktop/src/main/resources/scripts/own/Packages.own104-114

Package Usage Documentation

Packages can provide usage documentation through .usage.own files. The usage command displays this documentation:

Usage Documentation Display

Sources: ownlang-desktop/src/main/resources/scripts/own/Packages.own129-144

Project Management

The Projects class handles project initialization and default file creation.

Project Initialization

When own init is executed, the system:

  1. Configuration Creation: Generate or merge own-package.json with defaults
  2. File Scaffolding: Create default program files if they don't exist
  3. Directory Setup: Ensure proper project structure

The default program template creates a simple "Hello, world!" application:

Sources: ownlang-desktop/src/main/resources/scripts/own/Projects.own6-8 ownlang-desktop/src/main/resources/scripts/own/Own.own10-17

Script Execution

The package manager supports running predefined scripts through variable substitution:

VariableReplacementPurpose
$ownlang$ownlang or ownlang.cmdOwnLang executable (OS-specific)
$program$Configuration program valueMain program file
$dir$Current working directoryProject directory path

Scripts are executed using Java's ProcessBuilder with inherited I/O for seamless integration with the terminal environment.

Sources: ownlang-desktop/src/main/resources/scripts/own/Own.own38-59 ownlang-desktop/src/main/resources/scripts/own/Own.own3