Skip to content

Using LUMOS with npm

Use LUMOS in your JavaScript/TypeScript projects without installing Rust. The @getlumos/cli npm package provides the full LUMOS functionality via WebAssembly.

  • No Rust Toolchain Required - Works with Node.js only
  • Cross-Platform - Single package for all platforms
  • Programmatic API - Use LUMOS in build scripts
  • TypeScript Support - Full type definitions included
  • Lightweight - 261 KB compressed (~750 KB unpacked)

Install globally to use the lumos command everywhere:

Terminal window
npm install -g @getlumos/cli
# or
yarn global add @getlumos/cli
# or
pnpm add -g @getlumos/cli

Verify installation:

Terminal window
lumos --version
# Output: 0.1.0

Install as a dev dependency in your project:

Terminal window
npm install --save-dev @getlumos/cli
# or
yarn add --dev @getlumos/cli
# or
pnpm add -D @getlumos/cli

Run directly without installing:

Terminal window
npx @getlumos/cli generate schema.lumos

The npm package provides the same CLI commands as the Rust version.

Terminal window
# Basic usage
lumos generate schema.lumos
# With custom output paths
lumos generate schema.lumos \\
--output-rust src/generated.rs \\
--output-typescript src/generated.ts
# Using npx
npx @getlumos/cli generate schema.lumos
Terminal window
lumos validate schema.lumos
# Output: ✓ Schema is valid
{
"scripts": {
"codegen": "lumos generate schema.lumos",
"validate": "lumos validate schema.lumos",
"prebuild": "npm run codegen"
}
}

Then run:

Terminal window
npm run codegen

Use LUMOS in your JavaScript/TypeScript code.

import { generate } from '@getlumos/cli';
const result = await generate('schema.lumos', {
outputRust: 'src/generated.rs',
outputTypeScript: 'src/generated.ts'
});
console.log('Generated Rust code:', result.rust);
console.log('Generated TypeScript code:', result.typescript);

API Signature:

function generate(
schemaPath: string,
options?: {
outputRust?: string;
outputTypeScript?: string;
}
): Promise<{
rust: string;
typescript: string;
}>;
import { validate } from '@getlumos/cli';
const result = await validate('schema.lumos');
if (result.valid) {
console.log('✓ Schema is valid');
} else {
console.error('✗ Schema validation failed');
console.error(result.errors);
process.exit(1);
}

API Signature:

function validate(schemaPath: string): Promise<{
valid: boolean;
errors?: string[];
}>;
import { generate } from '@getlumos/cli';
try {
await generate('schema.lumos');
} catch (error) {
if (error instanceof Error) {
console.error('Generation failed:', error.message);
}
process.exit(1);
}

Create a Vite plugin for automatic code generation:

vite-plugin-lumos.ts
import { Plugin } from 'vite';
import { generate } from '@getlumos/cli';
import { watch } from 'fs';
export function lumosPlugin(schemaPath: string): Plugin {
return {
name: 'vite-plugin-lumos',
async buildStart() {
// Generate on build start
await generate(schemaPath);
},
configureServer(server) {
// Watch schema file for changes
watch(schemaPath, async () => {
await generate(schemaPath);
server.ws.send({ type: 'full-reload' });
});
}
};
}

Usage in vite.config.ts:

import { defineConfig } from 'vite';
import { lumosPlugin } from './vite-plugin-lumos';
export default defineConfig({
plugins: [
lumosPlugin('schema.lumos')
]
});

Create a Webpack plugin:

webpack-plugin-lumos.js
const { generate } = require('@getlumos/cli');
class LumosPlugin {
constructor(schemaPath) {
this.schemaPath = schemaPath;
}
apply(compiler) {
compiler.hooks.beforeCompile.tapPromise('LumosPlugin', async () => {
await generate(this.schemaPath);
});
}
}
module.exports = LumosPlugin;

Usage in webpack.config.js:

const LumosPlugin = require('./webpack-plugin-lumos');
module.exports = {
plugins: [
new LumosPlugin('schema.lumos')
]
};
rollup.config.js
import { generate } from '@getlumos/cli';
export default {
input: 'src/index.ts',
plugins: [
{
name: 'lumos',
async buildStart() {
await generate('schema.lumos');
}
}
]
};
build.js
import { build } from 'esbuild';
import { generate } from '@getlumos/cli';
// Generate before building
await generate('schema.lumos');
await build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'dist/index.js'
});

name: Generate LUMOS Code
on: [push, pull_request]
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Generate LUMOS code
run: npx @getlumos/cli generate schema.lumos
- name: Validate generated files
run: |
git diff --exit-code generated.rs generated.ts || \\
(echo "Generated files are outdated!" && exit 1)
generate-code:
image: node:20
script:
- npm install
- npx @getlumos/cli generate schema.lumos
- git diff --exit-code generated.rs generated.ts
only:
- merge_requests
- main
version: 2.1
jobs:
generate:
docker:
- image: cimg/node:20.0
steps:
- checkout
- run: npm install
- run: npx @getlumos/cli generate schema.lumos
- run: git diff --exit-code
workflows:
validate:
jobs:
- generate

The npm package doesn’t have built-in watch mode, but you can create one:

watch.js
import { watch } from 'fs';
import { generate } from '@getlumos/cli';
const schemaPath = 'schema.lumos';
console.log(`👀 Watching ${schemaPath}...`);
watch(schemaPath, async (eventType) => {
if (eventType === 'change') {
console.log('🔄 Schema changed, regenerating...');
try {
await generate(schemaPath);
console.log('✓ Code regenerated');
} catch (error) {
console.error('✗ Generation failed:', error.message);
}
}
});

Run with:

Terminal window
node watch.js

Or use nodemon:

Terminal window
npm install --save-dev nodemon
# package.json
{
"scripts": {
"watch": "nodemon --watch schema.lumos --exec 'npm run codegen'"
}
}

apps/my-app/project.json
{
"targets": {
"codegen": {
"executor": "nx:run-commands",
"options": {
"command": "lumos generate schema.lumos",
"cwd": "apps/my-app"
}
},
"build": {
"dependsOn": ["codegen"]
}
}
}
turbo.json
{
"pipeline": {
"codegen": {
"outputs": ["generated.rs", "generated.ts"]
},
"build": {
"dependsOn": ["codegen"]
}
}
}

The package includes full TypeScript type definitions:

import type { GenerateOptions, GeneratedCode, ValidationResult } from '@getlumos/cli';
const options: GenerateOptions = {
outputRust: 'src/generated.rs',
outputTypeScript: 'src/generated.ts'
};
const result: GeneratedCode = await generate('schema.lumos', options);
const validation: ValidationResult = await validate('schema.lumos');

Ensure proper module resolution:

{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true,
"types": ["node"]
}
}

Featurenpm (@getlumos/cli)Rust (lumos-cli)
Installationnpm install -gcargo install
RequirementsNode.js 16+Rust toolchain
Size261 KB (compressed)~10 MB (native binary)
SpeedWASM (~10-20% slower)Native (fastest)
PlatformCross-platform (single package)Platform-specific binaries
Programmatic API✅ JavaScript/TypeScript❌ Rust only
CLI Commands✅ All commands✅ All commands
Watch Mode❌ Custom implementation❌ Not yet
LSP Support❌ Use Rust LSP✅ Via lumos-lsp

Choose npm if:

  • You don’t have Rust installed
  • You want programmatic API access
  • You’re building JavaScript/TypeScript projects
  • You need cross-platform compatibility

Choose Rust if:

  • You want maximum performance
  • You’re building Rust/Anchor projects
  • You need LSP integration
  • You prefer native binaries

Error:

Failed to load LUMOS WASM module

Fix: Ensure you’re using Node.js 16 or higher:

Terminal window
node --version # Should be >= 16.0.0

Error:

Cannot find module '@getlumos/cli'

Fix: Reinstall the package:

Terminal window
npm install --save-dev @getlumos/cli

Error:

EACCES: permission denied

Fix: Use npx instead of global install, or fix npm permissions:

Terminal window
npx @getlumos/cli generate schema.lumos

Error:

Cannot write to file: generated.rs

Fix: Ensure output directory exists and is writable:

Terminal window
mkdir -p src/generated
lumos generate schema.lumos --output-rust src/generated/types.rs

Add to .gitignore if regenerating in CI:

generated.rs
generated.ts

Avoid installing globally in CI:

Terminal window
npx @getlumos/cli generate schema.lumos

Generate multiple schemas in parallel:

import { generate } from '@getlumos/cli';
await Promise.all([
generate('schemas/accounts.lumos'),
generate('schemas/instructions.lumos'),
generate('schemas/events.lumos')
]);

codegen.js
import { generate, validate } from '@getlumos/cli';
async function main() {
// Validate first
const validation = await validate('schema.lumos');
if (!validation.valid) {
console.error('Schema validation failed');
process.exit(1);
}
// Generate
await generate('schema.lumos', {
outputRust: 'src/generated.rs',
outputTypeScript: 'src/types.ts'
});
console.log('✓ Code generated successfully');
}
main().catch(console.error);
{
"scripts": {
"prebuild": "node codegen.js",
"build": "tsc"
}
}
generate-all.ts
import { generate } from '@getlumos/cli';
import { readdirSync } from 'fs';
import { join } from 'path';
const schemasDir = './schemas';
const schemas = readdirSync(schemasDir)
.filter(file => file.endsWith('.lumos'));
for (const schema of schemas) {
const schemaPath = join(schemasDir, schema);
const name = schema.replace('.lumos', '');
await generate(schemaPath, {
outputRust: `src/generated/${name}.rs`,
outputTypeScript: `src/types/${name}.ts`
});
console.log(`✓ Generated ${name}`);
}