@midnight-ntwrk/midnight-js-compact
v4.0.2
Published
Compact fetcher
Downloads
5,168
Readme
Compact
Compact compiler manager for Midnight smart contracts. Fetches, manages, and runs the compactc compiler.
Installation
yarn add -D @midnight-ntwrk/midnight-js-compactQuick Start
# Fetch the compiler (version from COMPACTC_VERSION env var)
yarn fetch-compactc
# Compile a contract
yarn run-compactc ./contract.compact ./outputCLI Commands
fetch-compactc
Downloads and manages Compact compiler versions.
| Flag | Description |
| --------------------- | ------------------------------------- |
| --version=<version> | Specify version to download |
| --force | Force re-download existing version |
| --list-versions | List all installed versions |
| --cleanup=<count> | Keep only the latest N versions |
| --help | Show help |
# Download specific version
yarn fetch-compactc --version=1.0.0
# List installed versions
yarn fetch-compactc --list-versions
# Cleanup old versions, keep latest 3
yarn fetch-compactc --cleanup=3run-compactc
Executes the Compact compiler.
yarn run-compactc <input-file> <output-dir> [options]Configuration
Environment Variables
| Variable | Description | Default |
| --------------------- | ---------------------------------------------------------------- | -------------------------------- |
| COMPACTC_VERSION | Version to fetch/run (required if --version not provided) | - |
| COMPACT_HOME | Custom Compact installation path (skips managed versions) | - |
| COMPACT_REPO | GitHub repository for downloading the compiler | LFDT-Minokawa/compact |
| COMPACT_TAG_PREFIX | Release tag prefix prepended to the version | v |
| COMPACT_DOCKER_IMAGE| Docker image for unsupported platforms | ghcr.io/midnight-ntwrk/compactc|
Platform Support
| Platform | Architecture | Method | | --------------- | --------------- | -------- | | macOS | arm64, x64 | Binary | | Linux | arm64, x64 | Binary | | Other | - | Docker |
Version Management
The package manages multiple compiler versions in managed/ directory:
managed/
├── 1.0.0/
│ └── compactc
├── 1.1.0/
│ └── compactc
└── 1.2.0/
└── compactcWhen COMPACT_HOME is not set and no specific version is requested, the latest installed version is used.
API
VersionManager
import { VersionManager } from '@midnight-ntwrk/midnight-js-compact';
const manager = new VersionManager(packageDir);
manager.listVersions(); // Get all installed versions
manager.versionExists('1.0.0'); // Check if version exists
manager.getVersionDir('1.0.0'); // Get version directory path
manager.getCompactcPath('1.0.0'); // Get compactc binary path
manager.removeVersion('1.0.0'); // Remove specific version
manager.cleanupOldVersions(3); // Keep only latest 3 versionsUtility Functions
import { resolveCompactPath } from '@midnight-ntwrk/midnight-js-compact';
// Resolves path to compactc (respects COMPACT_HOME, falls back to managed versions)
const compactPath = resolveCompactPath(packageDir, optionalVersion);Resources
Terms & License
By using this package, you agree to Midnight's Terms and Conditions and Privacy Policy.
Licensed under Apache License 2.0.
