From 7a31b09a0d2035a5265a7478cf1b14043824bb68 Mon Sep 17 00:00:00 2001 From: Jaron Date: Wed, 1 Jan 2025 22:21:36 -0600 Subject: [PATCH] Added some stuff for beta release. Toying with a build script. --- bun.lockb | Bin 13077 -> 13441 bytes package.json | 21 +++++++---- scripts/build.ts | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 scripts/build.ts diff --git a/bun.lockb b/bun.lockb index 7fd744c4b21c2633f4bc547e6cb05ce8da200a89..75023fbc7f5fc4766e7ca45b9067a329e485ce75 100755 GIT binary patch delta 1953 zcmcIlYitx%6ux)5+uhl^MM_`WZD~8(*OYYI?H1aF+Nr!ELGTeslO{aYwk$(RE!%)4 zDiqV08juJlMo2U$Ka5R7v8fsqA3!1T0b-086ivh?CJRJtjEG2EzcagQ(3tp(lbreP zdCoca-Z}H)hF#_he*OBRuUs0hUv%@M^yv6^k(9c=lbbee@MaI3IUX}xY-hfi2nvgQ z`&tTj=J?`5{Fxy{-xEFYbv57~$lJrw2&+~}A!b5e0-OO10oh)az}<=vIgtB+X~1nj z7ciO<$Bv%1aA&x^qpj22Y9gOz6GCl-LkAWdFbs49CxINeJQ;K?0*Wby zJV1JiA#ah1X9o@9d6Z%)hWZ;CydRNSG?G#;=aFeM@+?S}dk z+U2h76tLIJV>AfeFVNLme$c6N(BFJW4lAmg%v3`?4&6fN6pm6HcDj<bQ1vYwWV#G_h6Y`RVpr*kYyM8WR4}7!fpCj)AQol; znf?pWy~wq!|3vJo@FetiBKz|(G8Tf_uSf_QOY_iIX+=9(_JNu1M6Rn8%yzyGOpGj- zgW0Ypbuh7XvqD(`rxZKN_(GeJk@^T^W|R* ztq~c|%@3bG_2cPPsq5@F>|G~6Ub?!Oy4GFqf9u=rtZhxyKdhIPs-DNDhMjFOO_M^)XQ-?jDj%C8Dj<-gLaXMcf z%ui1AC$B}$4P;!^6p5z&!8&}zPMTej>rIaOebuecm%V*oNRc~gv3s@thF*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e8fk>PI(1XE`K diff --git a/package.json b/package.json index bfae418..3dcb14d 100644 --- a/package.json +++ b/package.json @@ -4,19 +4,28 @@ "module": "src/index.ts", "type": "module", "main": "out/index.js", + "types": "out/index.d.ts", + "files": [ + "out" + ], "scripts": { "test": "bun run testing/demo.test.ts", "test:inspect": "bun --inspect testing/demo.test.ts", - "build": "bun run build:types && bun build src/index.ts --outdir out", - "build:packages": "bun run build:types && bun build src/index.ts --packages external --outdir out", - "build:nocheck": "bun run build:types:nocheck && bun build src/index.ts --outdir out --noCheck", + + "build": "bun run build:types && bun run build:core", + "build:packages": "bun run build:types && bun run build:core -- --packages external", + "build:nocheck": "bun run build:types:nocheck && bun run build:core", + + "build:core": "bun build src/index.ts --outdir out --drop=console,debugger", "build:types": "tsc --emitDeclarationOnly --project tsconfig.json", - "build:types:nocheck": "tsc --emitDeclarationOnly --project tsconfig.json --noCheck", - "build:watch": "concurrently \"tsc --emitDeclarationOnly --project tsconfig.json --watch\" \"bun build src/index.ts --outdir out --watch\"", - "build:packages:watch": "concurrently \"tsc --emitDeclarationOnly --project tsconfig.json --watch\" \"bun build src/index.ts --packages external --outdir out --watch\"" + "build:types:nocheck": "bun run build:types -- --noCheck", + + "build:watch": "concurrently \"bun run build:types -- --watch\" \"bun run build:core -- --watch\"", + "build:packages:watch": "concurrently \"bun run build:types -- --watch\" \"bun run build:core -- --packages external --watch\"" }, "devDependencies": { "@types/bun": "latest", + "commander": "^13.0.0", "concurrently": "^9.1.0" }, "peerDependencies": { diff --git a/scripts/build.ts b/scripts/build.ts new file mode 100644 index 0000000..7657a41 --- /dev/null +++ b/scripts/build.ts @@ -0,0 +1,92 @@ +#!/usr/bin/env bun +/** + * Not used at the moment, was just playing around with the idea of using the bun JavaScript API to build the project. + */ +import { Command } from 'commander'; +import { build, type BuildConfig } from 'bun'; +import concurrently from 'concurrently'; + +// Initialize Commander to handle CLI commands and options +const program = new Command(); + +// Paths and base TypeScript compilation command +const srcFile = 'src/index.ts'; +const outDir = 'out'; +const tscBaseCmd = 'tsc --emitDeclarationOnly --project tsconfig.json'; + +/** + * Handles the build process with optional watch and type emission. + * + * @param options - Object containing flags for watch, packages, noCheck, and typesOnly. + */ +async function runBuild(options: { + watch?: boolean; + packages?: boolean; + noCheck?: boolean; + typesOnly?: boolean; +}) { + // Handle TypeScript-only builds (e.g., for emitting declaration files without bundling) + if (options.typesOnly) { + // Construct the TypeScript command dynamically based on flags + const tscCmd = `${tscBaseCmd}${options.noCheck ? ' --noCheck' : ''}${options.watch ? ' --watch' : ''}`; + + // Run TypeScript compilation (watch mode if specified) + await Bun.spawn(tscCmd.split(' ')).exited; + return; // Exit early since no Bun build is needed for types-only mode + } + + // Define options for the Bun build process + const buildOptions: BuildConfig = { + entrypoints: [srcFile], + outdir: outDir, + drop: ['console', 'debugger'], // Strip console and debugger statements + packages: options.packages ? 'external' : undefined + }; + + // Handle watch mode: run both TypeScript and Bun build concurrently + if (options.watch) { + concurrently([ + { + // Run TypeScript watch for continuous type emission + command: `${tscBaseCmd} --watch${options.noCheck ? ' --noCheck' : ''}`, + name: 'tsc', // Label the TypeScript process for logging + }, + { + // Run Bun build in watch mode + command: `bun build ${srcFile} --outdir ${outDir} ${ + options.packages ? '--packages external' : '' + } ${options.noCheck ? '--noCheck' : ''} --watch`, + name: 'bun', // Label the Bun process for logging + }, + ], { + + }); + } else { + // Non-watch mode: Run TypeScript once, then trigger Bun build + await Bun.spawn(tscBaseCmd.split(' ')).exited; + + // Perform a standard Bun build + await build(buildOptions); + console.log(`Build completed.`); + } +} + +// Register the build command and attach optional flags +program + .command('build') + .description('Build project with options') + .option('--watch', 'Watch for changes and rebuild') + .option('--packages', 'Bundle external packages') + .option('--nocheck', 'Skip type checking') + .option('--types-only', 'Emit types without compiling the project') + .action((opts) => { + runBuild({ + watch: opts.watch, + packages: opts.packages, + noCheck: opts.nocheck, + typesOnly: opts.typesOnly, + }); + }); + +// Parse and execute CLI input +program.parse(); \ No newline at end of file