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-loggerv4.0.0 - Result Wrapper: Error handling wrapper around
@mks2508/no-throwv0.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:*)dockerodev4.0.4arktypev2.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 availabilitycreateContainer(options)- Create new containerstartContainer(name)- Start existing containerstopContainer(name, timeout)- Stop running containergetContainer(name)- Get container infolistContainers()- 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 workspacecloneRepository(name, options)- Clone git repogetGitStatus(name)- Get git statuslistFiles(name, path)- List directory contentsreadFile(name, path)- Read file from workspacewriteFile(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 environmentlistVolumes()- List all devenv volumesgetVolumeInfo(name)- Get volume detailsremoveVolume(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 filesave()- Save configuration to filegetImages()- Get Docker image namesgetTemplates()- 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 typecheckDevelopment
# Watch mode for development
bun run dev
# Run tests
bun testPublishing
Packages are published to npm with public access:
bun run changeset
bun run changeset:version
bun run changeset:publishPro Tip: All core packages use workspace:* protocol for internal dependencies, ensuring consistent versions during development.