11#!/usr/bin/env bun
22
3- import { convert_lockfile_to_nix_expression } from "./bun2nix-wasm.js" ;
3+ import { convert_lockfile_to_nix_expression , Options } from "./bun2nix-wasm.js" ;
44
55import sade from "sade" ;
66import pkgJson from "./package.json" with { type : "json" } ;
77
88const prog = sade ( "bun2nix" , true ) ;
99
1010/** `bun2nix` command line options. */
11- type Opts = {
11+ type CliOpts = {
1212 /** String path to the lockfile to read in. */
1313 "lock-file" : string ;
1414 /** Output file to write to - writes to stdout if undefined. */
1515 "output-file" : string | undefined ;
16+ /** The prefix to use when copying workspace or file packages. */
17+ "copy-prefix" : string ;
1618} ;
1719
1820/**
1921 * Generate a nix expression for a given bun lockfile
2022 * Writes to stdout if `output-file` is not specified.
2123 *
22- * @param {Opts } opts - An instance of bun2nix CLI options
24+ * @param {CliOpts } opts - An instance of bun2nix CLI options
2325 */
24- export async function generateNixExpression ( opts : Opts ) : Promise < void > {
26+ export async function generateNixExpression ( opts : CliOpts ) : Promise < void > {
2527 const lock_file = Bun . file ( opts [ "lock-file" ] ) ;
2628 const contents = await lock_file . text ( ) ;
2729
28- const nix_expression = convert_lockfile_to_nix_expression ( contents ) ;
30+ const options = new Options ( opts [ "copy-prefix" ] ) ;
31+
32+ const nix_expression = convertLockfileToNixExpression ( contents , options ) ;
2933
3034 const output_file = opts [ "output-file" ] || Bun . stdout ;
3135 await Bun . write ( output_file , nix_expression + "\n" ) ;
4347 "-o, --output-file" ,
4448 "The output file to write to - if no file location is provided, print to stdout instead" ,
4549 )
50+ . option (
51+ "-c, --copy-prefix" ,
52+ "The prefix to use when copying workspace or file packages" ,
53+ "./" ,
54+ )
4655 . action ( ( opts ) => generateNixExpression ( opts ) ) ;
4756
4857prog . parse ( process . argv ) ;
@@ -51,8 +60,12 @@ prog.parse(process.argv);
5160 * Convert Bun Lockfile to a Nix expression
5261 *
5362 * @param {string } contents - The contents of a bun lockfile
63+ * @param {Options } options - Lockfile conversion options
5464 * @return {string } The generated nix expression
5565 */
56- export function convertLockfileToNixExpression ( contents : string ) : string {
57- return convert_lockfile_to_nix_expression ( contents ) ;
66+ export function convertLockfileToNixExpression (
67+ contents : string ,
68+ options : Options ,
69+ ) : string {
70+ return convert_lockfile_to_nix_expression ( contents , options ) ;
5871}
0 commit comments