@adddog/build-configs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sam Elie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,516 @@
1
+ # @adddog/build-configs
2
+
3
+ Reusable build configurations and CLI for [tsup](https://tsup.egoist.dev/) and [unbuild](https://github.com/unjs/unbuild) with sensible defaults, presets, and interactive setup.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **CLI Tool** - Interactive project initialization and build commands
8
+ - 📦 **Preset System** - Pre-configured setups for common use cases
9
+ - 🔧 **Smart Defaults** - Optimized configurations for Node.js libraries
10
+ - 🎯 **Type-Safe** - Full TypeScript support with discriminated unions
11
+ - 🔍 **Config Validation** - Zod-based validation for build configs
12
+ - 📝 **Auto-Discovery** - Automatically detects bundler and configuration files
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @adddog/build-configs
18
+ # or
19
+ pnpm add @adddog/build-configs
20
+ # or
21
+ yarn add @adddog/build-configs
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ### Interactive Initialization
27
+
28
+ The fastest way to get started:
29
+
30
+ ```bash
31
+ npx rad-build init
32
+ ```
33
+
34
+ This will guide you through:
35
+ 1. Choosing a bundler (tsup or unbuild)
36
+ 2. Selecting a preset or custom configuration
37
+ 3. Configuring output formats and features
38
+ 4. Automatically updating package.json
39
+
40
+ ### Build Your Project
41
+
42
+ ```bash
43
+ npx rad-build
44
+ ```
45
+
46
+ That's it! The CLI will detect your bundler and configuration automatically.
47
+
48
+ ## CLI Commands
49
+
50
+ ### `rad-build` (default)
51
+ Build your project with the configured bundler.
52
+
53
+ ```bash
54
+ # Build with auto-detected config
55
+ rad-build
56
+
57
+ # Build with specific config file
58
+ rad-build --config custom.config.ts
59
+
60
+ # Build with preset
61
+ rad-build --preset library-dual
62
+
63
+ # Build with CLI overrides
64
+ rad-build --format esm,cjs --minify
65
+
66
+ # Build specific entries
67
+ rad-build src/index.ts src/cli.ts
68
+ ```
69
+
70
+ **Options:**
71
+ - `--config <path>` - Path to config file
72
+ - `--preset <name>` - Use a preset configuration
73
+ - `--bundler <bundler>` - Specify bundler: `tsup` or `unbuild`
74
+ - `--format <formats>` - Output formats (comma-separated)
75
+ - `--minify` - Minify output
76
+ - `--watch` - Watch mode
77
+ - `--sourcemap` - Generate sourcemaps
78
+ - `--dts` - Generate TypeScript declarations
79
+ - `--clean` - Clean output directory before build
80
+
81
+ ### `rad-build init`
82
+ Initialize build configuration interactively.
83
+
84
+ ```bash
85
+ # Interactive setup
86
+ rad-build init
87
+
88
+ # Skip prompts with preset
89
+ rad-build init --preset library-esm
90
+
91
+ # Force overwrite existing config
92
+ rad-build init --force
93
+ ```
94
+
95
+ ### `rad-build watch`
96
+ Watch and rebuild on file changes.
97
+
98
+ ```bash
99
+ rad-build watch
100
+
101
+ # With specific config
102
+ rad-build watch --config custom.config.ts
103
+ ```
104
+
105
+ ### `rad-build validate`
106
+ Validate your build configuration.
107
+
108
+ ```bash
109
+ rad-build validate
110
+
111
+ # Validate specific config
112
+ rad-build validate --config tsup.config.ts
113
+ ```
114
+
115
+ ### `rad-build info`
116
+ Show build configuration and environment information.
117
+
118
+ ```bash
119
+ rad-build info
120
+ ```
121
+
122
+ ### `rad-build list-presets`
123
+ List all available presets.
124
+
125
+ ```bash
126
+ rad-build list-presets
127
+ ```
128
+
129
+ ## Programmatic API
130
+
131
+ ### Unified API (Recommended)
132
+
133
+ ```typescript
134
+ import { defineBuildConfig } from "@adddog/build-configs";
135
+
136
+ // For tsup
137
+ export default defineBuildConfig({
138
+ type: "tsup",
139
+ options: {
140
+ entry: ["src/index.ts"],
141
+ format: ["esm", "cjs"],
142
+ },
143
+ });
144
+
145
+ // For unbuild
146
+ export default defineBuildConfig({
147
+ type: "unbuild",
148
+ options: {
149
+ entries: ["src/index"],
150
+ },
151
+ });
152
+ ```
153
+
154
+ ### Direct API
155
+
156
+ **tsup.config.ts:**
157
+ ```typescript
158
+ import { makeTsupConfig } from "@adddog/build-configs/tsup";
159
+
160
+ export default makeTsupConfig({
161
+ entry: ["src/index.ts"],
162
+ format: ["esm", "cjs"],
163
+ });
164
+ ```
165
+
166
+ **build.config.ts:**
167
+ ```typescript
168
+ import { makeUnbuildConfig } from "@adddog/build-configs/unbuild";
169
+
170
+ export default makeUnbuildConfig({
171
+ entries: ["src/index"],
172
+ rollup: {
173
+ emitCJS: true,
174
+ },
175
+ });
176
+ ```
177
+
178
+ ## Presets
179
+
180
+ ### Library Presets
181
+
182
+ - **`library-esm`** - Modern ESM-only library
183
+ - **`library-dual`** - Library with both ESM and CJS outputs
184
+ - **`library-browser`** - Browser-compatible library with IIFE
185
+ - **`library-unbundled`** - File-to-file transpilation with mkdist
186
+ - **`library-monorepo`** - Optimized for monorepo internal packages
187
+
188
+ ### CLI Presets
189
+
190
+ - **`cli-simple`** - Simple CLI tool with single entry point
191
+ - **`cli-multi`** - CLI tool with multiple commands
192
+ - **`cli-bundled`** - CLI tool with all dependencies bundled
193
+
194
+ ### Component Presets
195
+
196
+ - **`react-component`** - React component library
197
+ - **`vue-component`** - Vue component library
198
+ - **`web-component`** - Framework-agnostic web components
199
+ - **`design-system`** - Design system with components and tokens
200
+
201
+ ### Complete Defaults Presets
202
+
203
+ These presets show **all available configuration options** with their default values. Perfect as a reference or starting point for customization:
204
+
205
+ - **`complete-tsup`** - Complete tsup config with all common options defined
206
+ - **`complete-unbuild`** - Complete unbuild config with all common options defined
207
+ - **`complete-tsup-full`** - Exhaustive tsup config with every possible option (including advanced features)
208
+ - **`complete-unbuild-full`** - Exhaustive unbuild config with every possible option (including hooks, all builders, etc.)
209
+
210
+ **Use cases:**
211
+ - Learn all available options for tsup or unbuild
212
+ - Start with a comprehensive config and remove what you don't need
213
+ - Reference for documentation and exploration
214
+
215
+ **Example:**
216
+ ```bash
217
+ # Initialize with complete defaults to see all options
218
+ rad-build init --preset complete-tsup
219
+
220
+ # Or for unbuild
221
+ rad-build init --preset complete-unbuild
222
+ ```
223
+
224
+ ### Using Presets
225
+
226
+ **Via CLI:**
227
+ ```bash
228
+ rad-build init --preset library-dual
229
+ ```
230
+
231
+ **Programmatically:**
232
+ ```typescript
233
+ import { getPreset } from "@adddog/build-configs/presets";
234
+
235
+ const preset = getPreset("library-dual");
236
+ ```
237
+
238
+ ## unbuild vs tsup: Key Differences
239
+
240
+ ### When to use unbuild
241
+
242
+ ✅ **Best for:**
243
+ - Building libraries with multiple entry points
244
+ - Preserving source file structure
245
+ - File-to-file transpilation (mkdist)
246
+ - Monorepo packages
247
+ - Advanced hooks and customization
248
+
249
+ **Output:**
250
+ ```
251
+ src/
252
+ index.ts
253
+ utils.ts
254
+ dist/
255
+ index.mjs ← Separate files
256
+ utils.mjs
257
+ ```
258
+
259
+ **Key Features:**
260
+ - Multiple builders: `rollup`, `mkdist`, `copy`, `untyped`
261
+ - Stub mode for development (no rebuild needed)
262
+ - Auto-inference from package.json
263
+ - Extensive lifecycle hooks
264
+
265
+ ### When to use tsup
266
+
267
+ ✅ **Best for:**
268
+ - Fastest possible builds (powered by esbuild)
269
+ - Simple libraries with 1-2 entry points
270
+ - Bundling everything together
271
+ - IIFE format for browsers
272
+ - Zero-config setup
273
+
274
+ **Output:**
275
+ ```
276
+ src/
277
+ index.ts
278
+ utils.ts
279
+ dist/
280
+ index.js ← Bundled together
281
+ ```
282
+
283
+ **Key Features:**
284
+ - Lightning-fast esbuild-based bundling
285
+ - Code splitting for ESM
286
+ - CSS support (experimental)
287
+ - Multiple output formats: ESM, CJS, IIFE
288
+ - Terser minification
289
+
290
+ ### Comparison Table
291
+
292
+ | Feature | unbuild | tsup |
293
+ |---------|---------|------|
294
+ | **Speed** | Fast (Rollup) | Fastest (esbuild) |
295
+ | **Bundling** | Unbundled by default | Bundled by default |
296
+ | **File Structure** | Preserved | Single output |
297
+ | **Entry Points** | Multiple | Multiple |
298
+ | **Output Formats** | ESM, CJS | ESM, CJS, IIFE |
299
+ | **Declaration Files** | ✓ (compatible/node16) | ✓ (with resolve) |
300
+ | **Source Maps** | ✓ | ✓ |
301
+ | **Tree Shaking** | ✓ (Rollup) | ✓ (esbuild + optional Rollup) |
302
+ | **Code Splitting** | Per file | Smart chunking |
303
+ | **Watch Mode** | ✓ (experimental) | ✓ |
304
+ | **Stub Mode** | ✓ | ✗ |
305
+ | **CSS Support** | Via plugins | ✓ (experimental) |
306
+ | **Hooks** | Extensive | Limited |
307
+ | **Config Complexity** | More options | Simpler |
308
+
309
+ ## Default Configurations
310
+
311
+ ### tsup Defaults
312
+
313
+ ```typescript
314
+ {
315
+ entry: ["src/index.ts"],
316
+ format: ["esm", "cjs"],
317
+ dts: {
318
+ resolve: true,
319
+ compilerOptions: { strict: true }
320
+ },
321
+ bundle: true,
322
+ splitting: false,
323
+ treeshake: true,
324
+ clean: true,
325
+ sourcemap: true,
326
+ target: "node18",
327
+ platform: "node",
328
+ minify: false,
329
+ keepNames: true,
330
+ skipNodeModulesBundle: true,
331
+ external: [/node_modules/]
332
+ }
333
+ ```
334
+
335
+ ### unbuild Defaults
336
+
337
+ ```typescript
338
+ {
339
+ entries: ["src/index"],
340
+ outDir: "dist",
341
+ declaration: "compatible",
342
+ sourcemap: true,
343
+ clean: true,
344
+ parallel: true,
345
+ failOnWarn: false,
346
+ rollup: {
347
+ emitCJS: false,
348
+ inlineDependencies: false,
349
+ esbuild: {
350
+ target: "node18",
351
+ minify: false
352
+ }
353
+ }
354
+ }
355
+ ```
356
+
357
+ ## Advanced Usage
358
+
359
+ ### Custom Config with Preset
360
+
361
+ ```typescript
362
+ import { makeTsupConfig } from "@adddog/build-configs/tsup";
363
+ import { getPreset } from "@adddog/build-configs/presets";
364
+
365
+ const preset = getPreset("library-dual");
366
+
367
+ export default makeTsupConfig({
368
+ ...preset.tsup,
369
+ // Override preset settings
370
+ minify: true,
371
+ target: "es2022",
372
+ });
373
+ ```
374
+
375
+ ### File-to-File Transpilation (unbuild)
376
+
377
+ ```typescript
378
+ import { makeUnbuildConfig } from "@adddog/build-configs/unbuild";
379
+
380
+ export default makeUnbuildConfig({
381
+ entries: [
382
+ "src/index",
383
+ {
384
+ builder: "mkdist",
385
+ input: "src/components/",
386
+ outDir: "dist/components/",
387
+ },
388
+ ],
389
+ });
390
+ ```
391
+
392
+ ### Multiple Builds
393
+
394
+ ```typescript
395
+ import { defineBuildConfig } from "unbuild";
396
+
397
+ export default defineBuildConfig([
398
+ {
399
+ name: "main",
400
+ entries: ["src/index"],
401
+ },
402
+ {
403
+ name: "minified",
404
+ entries: ["src/index"],
405
+ outDir: "dist/min",
406
+ rollup: {
407
+ esbuild: {
408
+ minify: true,
409
+ },
410
+ },
411
+ },
412
+ ]);
413
+ ```
414
+
415
+ ## Configuration Discovery
416
+
417
+ The CLI automatically discovers configuration in this order:
418
+
419
+ 1. CLI `--config` flag
420
+ 2. `build.config.{ts,js,mjs,cjs}`
421
+ 3. `tsup.config.{ts,js,mjs}`
422
+ 4. `.radbuildrc.{ts,js,json}`
423
+ 5. `radbuild` key in `package.json`
424
+
425
+ ## Migration
426
+
427
+ ### From tsup to unbuild
428
+
429
+ ```bash
430
+ # Your existing tsup.config.ts
431
+ import { defineConfig } from "tsup";
432
+
433
+ export default defineConfig({
434
+ entry: ["src/index.ts"],
435
+ format: ["esm", "cjs"],
436
+ dts: true,
437
+ });
438
+
439
+ # Convert to unbuild
440
+ import { makeUnbuildConfig } from "@adddog/build-configs/unbuild";
441
+
442
+ export default makeUnbuildConfig({
443
+ entries: ["src/index"],
444
+ rollup: {
445
+ emitCJS: true, // For CJS output
446
+ },
447
+ });
448
+ ```
449
+
450
+ ### From unbuild to tsup
451
+
452
+ ```bash
453
+ # Your existing build.config.ts
454
+ import { defineBuildConfig } from "unbuild";
455
+
456
+ export default defineBuildConfig({
457
+ entries: ["src/index"],
458
+ rollup: {
459
+ emitCJS: true,
460
+ },
461
+ });
462
+
463
+ # Convert to tsup
464
+ import { makeTsupConfig } from "@adddog/build-configs/tsup";
465
+
466
+ export default makeTsupConfig({
467
+ entry: ["src/index.ts"],
468
+ format: ["esm", "cjs"],
469
+ });
470
+ ```
471
+
472
+ ## Troubleshooting
473
+
474
+ ### Build fails with "Cannot find module"
475
+
476
+ Ensure dependencies are installed:
477
+ ```bash
478
+ pnpm install unbuild tsup
479
+ ```
480
+
481
+ ### CLI command not found
482
+
483
+ Link the package locally:
484
+ ```bash
485
+ pnpm link @adddog/build-configs
486
+ ```
487
+
488
+ ### Config validation fails
489
+
490
+ Run validation to see specific errors:
491
+ ```bash
492
+ rad-build validate
493
+ ```
494
+
495
+ ### Types not generated
496
+
497
+ Ensure `declaration` (unbuild) or `dts` (tsup) is enabled:
498
+ ```typescript
499
+ // tsup
500
+ export default makeTsupConfig({
501
+ dts: true,
502
+ });
503
+
504
+ // unbuild
505
+ export default makeUnbuildConfig({
506
+ declaration: true,
507
+ });
508
+ ```
509
+
510
+ ## API Reference
511
+
512
+ See [API Documentation](./docs/api.md) for complete API reference.
513
+
514
+ ## License
515
+
516
+ MIT
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+