MKS DevEnv

Core Packages

Shared utilities and core functionality for mks-dev-environment

Core Packages

The core/packages/ directory contains shared libraries and utilities used across all mks-dev-environment applications.

Architecture Overview

Package: @@mks-devenv/utils

Version: 0.0.1 Location: core/packages/utils/

Overview

Shared utilities package providing logging and error handling wrappers around external libraries.

Features

  • Logger Wrapper: Typed wrapper around @mks2508/better-logger v4.0.0
  • Result Wrapper: Error handling wrapper around @mks2508/no-throw v0.1.0
  • Type Constants: Shared type definitions and utility types

Exports

// Main exports
import { createLogger } from '@mks-devenv/utils/logger';
import { ok, err, isErr, tryCatch } from '@mks-devenv/utils/result';

Logger Usage

import { createLogger } from '@mks-devenv/utils/logger';

const log = createLogger('MyComponent');
log.info('Message');
log.success('Success!');
log.error('Error occurred');

Result Pattern Usage

import { ok, err, isErr, tryCatch } from '@mks-devenv/utils/result';

type Result<T> = { ok: true; value: T } | { ok: false; error: Error };

function divide(a: number, b: number): Result<number> {
  if (b === 0) return err(new Error('Division by zero'));
  return ok(a / b);
}

const result = divide(10, 2);
if (isErr(result)) {
  console.error(result.error);
} else {
  console.log(result.value); // 5
}

Package: @mks-dev-environment/core

Version: 0.0.1 Location: core/packages/main/

Overview

Main library package that builds upon utils for higher-level functionality.

Dependencies

  • @mks-devenv/utils (workspace:*)
  • Node.js >= 18.0.0

Package: @@mks-devenv/core

Version: 0.0.1 Location: core/packages/devenv-core/

Overview

Core functionality for containerized development environments. Provides services for Docker container management, workspace operations, persistence, and configuration.

Dependencies

  • @mks-devenv/utils (workspace:*)
  • dockerode v4.0.4
  • arktype v2.1.29

Module Exports

import {
  ContainerService,
  WorkspaceService,
  PersistenceService,
  ConfigService,
} from '@mks-devenv/core';

import type {
  IDevEnvironment,
  ICreateEnvironmentOptions,
  IContainerCreateOptions,
  IFileInfo,
  IGitStatus,
} from '@mks-devenv/core';

ContainerService

Manages Docker containers for development environments.

Key Methods:

  • ping() - Check Docker daemon availability
  • createContainer(options) - Create new container
  • startContainer(name) - Start existing container
  • stopContainer(name, timeout) - Stop running container
  • getContainer(name) - Get container info
  • listContainers() - List all devenv containers

Example:

import { ContainerService } from '@mks-devenv/core';

const container = new ContainerService();

// Check Docker is running
const pingResult = await container.ping();
if (isErr(pingResult)) {
  console.error('Docker not available');
}

// Create container
const createResult = await container.createContainer({
  name: 'devenv-myproject',
  image: 'mks-devenv-full:latest',
  ports: [
    { containerPort: 8443, hostPort: 8443, protocol: 'tcp' }
  ],
  volumes: [
    { name: 'workspace', mountPath: '/workspace', type: 'volume' }
  ],
  env: { PASSWORD: 'secure123' }
});

WorkspaceService

Manages workspace files and git operations.

Key Methods:

  • createWorkspace(name) - Create new workspace
  • cloneRepository(name, options) - Clone git repo
  • getGitStatus(name) - Get git status
  • listFiles(name, path) - List directory contents
  • readFile(name, path) - Read file from workspace
  • writeFile(name, path, content) - Write file to workspace

Example:

import { WorkspaceService } from '@mks-devenv/core';

const workspace = new WorkspaceService();

// Clone repository
const cloneResult = await workspace.cloneRepository('myproject', {
  url: 'https://github.com/user/repo.git',
  branch: 'main'
});

// Get git status
const status = await workspace.getGitStatus('myproject');
console.log(status.branch, status.files);

PersistenceService

Manages Docker volumes for data persistence.

Key Methods:

  • createEnvironmentVolumes(name) - Create volumes for environment
  • listVolumes() - List all devenv volumes
  • getVolumeInfo(name) - Get volume details
  • removeVolume(name) - Delete volume

Volume Structure:

  • {name}-workspace - Project files
  • {name}-config - Application configs
  • {name}-data - Application data

ConfigService

Manages environment configuration.

Key Methods:

  • load() - Load configuration from file
  • save() - Save configuration to file
  • getImages() - Get Docker image names
  • getTemplates() - Get available templates

Config Location: ~/.config/devenv/config.json

Type System

The core packages use Arktype for schema validation:

import { type } from 'arktype';

export const CreateEnvironmentOptionsSchema = type({
  name: 'string',
  template: 'string.optional',
  ide: 'string.optional',
  gitRepo: 'string.optional',
  gitBranch: 'string.optional',
});

Build System

All core packages use:

  • Rolldown v1.0.0-beta.58 for bundling
  • TSGO (@typescript/native-preview) for type checking
  • Bun workspaces for dependency management
# Build all core packages
cd core/packages/utils && bun run build
cd core/packages/main && bun run build
cd core/packages/devenv-core && bun run build

# Type check
bun run typecheck

Development

# Watch mode for development
bun run dev

# Run tests
bun test

Publishing

Packages are published to npm with public access:

bun run changeset
bun run changeset:version
bun run changeset:publish

Pro Tip: All core packages use workspace:* protocol for internal dependencies, ensuring consistent versions during development.

Actions

On this page