lifo field in package.json that defines command entries and capabilities.
Package Structure
A Lifo package is a standard npm package with additional metadata:Package Manifest
Add alifo field to your package.json:
Manifest Format
Thelifo field defines command mappings:
Writing Commands
Lifo packages support both CommonJS and ES Modules.CommonJS Format
Export an async function that receivesctx and lifo:
ES Module Format
Export a default async function:The Lifo API
Package commands receive a speciallifo object with enhanced capabilities:
Importing Dependencies
Load npm packages directly from CDN:LIFO_CDN environment variable:
Loading WebAssembly
Load and execute WASM modules:Path Resolution
Resolve relative paths:Using Node.js Built-ins
Lifo provides Node.js compatibility shims:process- Process information and controlconsole- Logging (outputs to ctx.stdout/stderr)Buffer- Binary data handlingrequire()- Module loadingsetTimeout,setInterval,clearTimeout,clearInterval__filename,__dirname- Module paths
Requiring Local Modules
Load modules relative to your package:Complete Example: JSON Formatter
Advanced: Using External Dependencies
Import packages dynamically at runtime:Package Discovery
Lifo looks for packages in these locations:./node_modules/- Local project dependencies../node_modules/- Parent directories (walked upward)/usr/lib/node_modules/- Global system packages/usr/share/pkg/node_modules/- Shared package repository
Reading Package Manifests
Programmatically read package metadata:Error Handling
Handle errors gracefully:Testing Packages
Test your commands using the Lifo test utilities:Best Practices
- Command naming: Use descriptive, hyphenated names (
json-format, notjf) - Exit codes: Return
0for success,1for errors,130for cancellation - Help text: Show usage when called without required arguments
- Error messages: Write errors to
stderr, data tostdout - Stdin support: Accept input from pipes when appropriate
- Environment variables: Use
ctx.envfor configuration - Signal handling: Check
ctx.signal.abortedfor long operations - Dependencies: Use
lifo.import()instead of bundling large libraries - Documentation: Include README with examples
- Versioning: Follow semantic versioning