Page cover image

Install

To install Saffron, run:

npm install @darkobits/saffron

ESM

Saffron is a pure ESM package. If your application is also written as and compiled to pure ESM, you can import Saffron using ESM import syntax:

cli.ts
import * as cli from '@darkobits/saffron';

Or, if you prefer named imports:

cli.ts
import { command, init } from '@darkobits/saffron';

CommonJS

If your application is written in CommonJS, don't worry! You can still use Saffron with a dynamic import. However, dynamic imports must be await-ed, and CommonJS does not support top-level await statements, so the logic in your CLI must be wrapped in a function where we can then properly import Saffron:

cli.ts
async function main() {
  const cli = await import('@darkobits/saffron');
  
  // Or, if you prefer named imports:
  const { command, init } = await import('@darkobits/saffron');
  
  // Define your CLI here rather than at the top-level.
}

// Then, immediately invoke the above function. Easy peasy!
void main();

Examples in this guide will use ESM import syntax for its simplicity and brevity.

Last updated