@reliverse/dler 2.1.4 → 2.1.5

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.
@@ -4,659 +4,612 @@ import {
4
4
  validateAndExit
5
5
  } from "@reliverse/dler-build";
6
6
  import { replaceExportsInPackages } from "@reliverse/dler-helpers";
7
- import {
8
- defineCmd,
9
- defineCmdArgs,
10
- defineCmdCfg
11
- } from "@reliverse/dler-launcher";
7
+ import { defineArgs, defineCommand } from "@reliverse/dler-launcher";
12
8
  import { logger } from "@reliverse/dler-logger";
13
- const buildCmd = async (args) => {
14
- try {
15
- if (typeof process.versions.bun === "undefined") {
16
- logger.error("\u274C This command requires Bun runtime. Sorry.");
17
- process.exit(1);
18
- }
19
- if (args.goOnly && args.tsOnly) {
20
- logger.error(
21
- "\u274C --go-only and --ts-only cannot be used together. Please use only one."
22
- );
23
- process.exit(1);
9
+ export default defineCommand({
10
+ meta: {
11
+ name: "build",
12
+ description: "Build all workspace packages using configurable bundler (mkdist for libraries, bun for apps) with dler.ts configuration. Auto-detects frontend apps and libraries. Supports presets: --production, --dev, --library, --react, --node, --monorepo.",
13
+ examples: [
14
+ "dler build",
15
+ 'dler build --filter "@reliverse/dler-prompt,@reliverse/dler-build"',
16
+ 'dler build --filter "@reliverse/dler-*"',
17
+ 'dler build --ignore "@reliverse/*"',
18
+ 'dler build --ignore "@reliverse/dler-colors" --ignore "@reliverse/dler-v1"',
19
+ 'dler build --ignore "@reliverse/dler-colors @reliverse/dler-v1"',
20
+ "dler build --cwd /path/to/monorepo",
21
+ "dler build --cwd /path/to/monorepo --ignore @reliverse/*",
22
+ "dler build --concurrency 8",
23
+ "dler build --concurrency 2 --stopOnError",
24
+ "dler build --ignore @reliverse/* --concurrency 6 --stopOnError",
25
+ "dler build --verbose",
26
+ "dler build --verbose --ignore @reliverse/*",
27
+ "dler build --verbose --concurrency 2 --stopOnError",
28
+ "dler build --watch",
29
+ "dler build --watch --verbose",
30
+ "dler build --target node --format cjs",
31
+ "dler build --minify --sourcemap linked",
32
+ "dler build --target browser --format esm --splitting false",
33
+ "dler build --external react --external react-dom",
34
+ "dler build --watch --target browser --minify --sourcemap inline",
35
+ "dler build --production",
36
+ "dler build --dev",
37
+ "dler build --bytecode --format cjs --target bun",
38
+ "dler build --minifyWhitespace --minifySyntax --minifyIdentifiers",
39
+ "dler build --drop console.log --drop debugger",
40
+ `dler build --env PUBLIC_* --define '{"__VERSION__":"1.0.0"}'`,
41
+ "dler build --banner 'use client' --footer '// built with dler'",
42
+ "dler build --entryNaming '[dir]/[name].[ext]' --chunkNaming '[name]-[hash].[ext]'",
43
+ "dler build --compile --production",
44
+ "dler build --noCache --verbose",
45
+ "dler build --packages external --external 'react*'",
46
+ "dler build --publicPath /assets/ --root ./src",
47
+ "",
48
+ "# Standalone Executable Examples:",
49
+ "dler build --compile --production --target bun",
50
+ "dler build --compile --target node --format cjs --minify",
51
+ "dler build --compile --bytecode --format cjs --target bun",
52
+ "dler build --compile --windowsIcon app.ico --windowsTitle 'My App'",
53
+ "dler build --compile --production --env inline --drop console.log",
54
+ "",
55
+ "# Note: --compile generates executables alongside bundles",
56
+ "# For Bun executables, use --target bun --format cjs --bytecode for best performance",
57
+ "# For Node executables, use --target node --format cjs",
58
+ "",
59
+ "# Preset Examples:",
60
+ "dler build --production # Optimized for production",
61
+ "dler build --dev # Development mode with watch",
62
+ "dler build --library # Library build (external deps)",
63
+ "dler build --react # React app with JSX support",
64
+ "dler build --node # Node.js server build",
65
+ "dler build --monorepo # Monorepo optimized build",
66
+ "",
67
+ "# Bundler Examples:",
68
+ "dler build --bundler mkdist # Use mkdist bundler (default for libraries)",
69
+ "dler build --bundler bun # Use Bun bundler (default for apps)",
70
+ "dler build --bundler mkdist --kind library",
71
+ "dler build --bundler bun --kind library",
72
+ "",
73
+ "# Note: mkdist preserves file structure and is ideal for libraries",
74
+ "# bun bundles dependencies and is ideal for applications",
75
+ "",
76
+ "# New Bun bundler features:",
77
+ "dler build --noBundle --target node",
78
+ "dler build --reactFastRefresh --watch",
79
+ "dler build --noClearScreen --watch",
80
+ "dler build --windowsHideConsole --windowsIcon app.ico --compile",
81
+ "dler build --app --serverComponents",
82
+ "dler build --debugDumpServerFiles --debugNoMinify",
83
+ "",
84
+ "# Enhanced Features:",
85
+ "dler build --bundleAnalyzer --performanceMonitoring",
86
+ "dler build --generateTypes --typeCheck",
87
+ "dler build --macros --sideEffects false",
88
+ `dler build --bundleSizeLimit 1048576 --performanceBudget '{"maxBundleSize":1048576}'`,
89
+ "dler build --imageOptimization --fontOptimization --cssOptimization",
90
+ "dler build --svgAsReact --cssModules --workerSupport",
91
+ "dler build --plugins 'react-refresh,typescript-declarations,bundle-analyzer'",
92
+ "",
93
+ "# Frontend App Examples:",
94
+ "dler build --devServer --watch --open --reactFastRefresh",
95
+ "dler build --production --html --cssChunking --bundleAnalyzer",
96
+ "dler build --target browser --format esm --html --cssChunking --svgAsReact",
97
+ "dler build --devServer --port 8080 --open --cssModules",
98
+ "dler build --html --publicAssets static --cssChunking --imageOptimization",
99
+ "",
100
+ "# Full-stack App Examples:",
101
+ "dler build --target browser --format esm --html --assets public --workerSupport",
102
+ "dler build --devServer --watch --target browser --html --performanceMonitoring",
103
+ "",
104
+ "# Library Examples:",
105
+ "dler build --library --generateTypes --typeCheck",
106
+ "dler build --target bun --format esm --generateTypes --bundleAnalyzer",
107
+ "dler build --target node --format cjs --generateTypes --sideEffects false",
108
+ "",
109
+ "# Configuration Examples:",
110
+ "# Create dler.ts in your monorepo root:",
111
+ "# export default {",
112
+ "# build: {",
113
+ "# global: { target: 'bun', format: 'esm' },",
114
+ "# packages: { 'my-package': { minify: true, generateTypes: true } },",
115
+ "# patterns: [{ pattern: 'apps/*', config: { target: 'browser', html: true, bundleAnalyzer: true } }]",
116
+ "# }",
117
+ "# }",
118
+ "",
119
+ "# Note: Configuration is only supported via dler.ts",
120
+ "# package.json build fields are not supported",
121
+ "",
122
+ "# Config Discovery Examples:",
123
+ "dler build --maxConfigDepth 5",
124
+ "",
125
+ "# TSConfig Validation Examples:",
126
+ "dler build --validateTsconfig",
127
+ "dler build --strictTsconfig",
128
+ "dler build --validateTsconfig --verbose",
129
+ "dler build --noValidateTsconfig",
130
+ "",
131
+ "# Note: --validateTsconfig checks tsconfig.json for common issues",
132
+ "# Use --strictTsconfig to make validation errors fatal",
133
+ "",
134
+ "# DTS Provider Examples:",
135
+ "dler build --dtsProvider dts-bundle-generator",
136
+ "dler build --dtsProvider api-extractor",
137
+ "dler build --dtsProvider typescript",
138
+ "dler build --dtsProvider mkdist",
139
+ "dler build --generateTypes --dtsProvider dts-bundle-generator",
140
+ "",
141
+ "# Note: dts-bundle-generator is the default provider for better bundling",
142
+ "# mkdist provider offers VFS-based processing with automatic relative import resolution",
143
+ "# Use --dtsProvider to override the default provider",
144
+ "",
145
+ "# Go Build Examples:",
146
+ "dler build --go-provider xgo",
147
+ "dler build --go-provider native",
148
+ "dler build --go-targets linux/amd64",
149
+ "dler build --go-targets 'linux/amd64,windows/amd64,darwin/arm64'",
150
+ "dler build --go-output-dir release",
151
+ "dler build --go-output-name my-binary",
152
+ "dler build --go-build-mode c-shared",
153
+ "dler build --go-ldflags '-s -w -X main.version=1.0.0'",
154
+ "dler build --go-main-file main.go",
155
+ "dler build --go-version 1.21.0",
156
+ "dler build --go-enable",
157
+ "",
158
+ "# Note: Go build is auto-detected if .go files exist in the package",
159
+ "# Use --go-enable to explicitly enable, or configure in dler.ts",
160
+ "# Use --go-provider xgo for cross-compilation (requires xgo installed)",
161
+ "# Use --go-provider native for native builds (limited cross-compilation)",
162
+ "",
163
+ "# Build Type Selection Examples:",
164
+ "dler build --go-only",
165
+ "dler build --ts-only",
166
+ "dler build --go-only --go-targets linux/amd64",
167
+ "dler build --ts-only --target node --format cjs",
168
+ "",
169
+ "# Note: --go-only skips TypeScript builds and only builds Go binaries",
170
+ "# Note: --ts-only skips Go builds and only builds TypeScript/JavaScript",
171
+ "# Note: --go-only and --ts-only cannot be used together"
172
+ ]
173
+ },
174
+ args: defineArgs({
175
+ ignore: {
176
+ type: "string",
177
+ description: "Package(s) to ignore (supports wildcards like @reliverse/*)"
178
+ },
179
+ filter: {
180
+ type: "string",
181
+ description: "Package(s) to include (supports wildcards and comma-separated values like '@reliverse/dler-prompt,@reliverse/dler-build'). Takes precedence over --ignore when both are provided."
182
+ },
183
+ cwd: {
184
+ type: "string",
185
+ description: "Working directory (monorepo root)"
186
+ },
187
+ concurrency: {
188
+ type: "number",
189
+ description: "Number of packages to build concurrently (default: 5)"
190
+ },
191
+ stopOnError: {
192
+ type: "boolean",
193
+ description: "Stop on first error instead of collecting all errors (default: false)"
194
+ },
195
+ verbose: {
196
+ type: "boolean",
197
+ description: "Verbose mode (default: false)"
198
+ },
199
+ watch: {
200
+ type: "boolean",
201
+ description: "Watch mode for hot rebuild (default: false)"
202
+ },
203
+ bundler: {
204
+ type: "string",
205
+ description: "Bundler to use: bun (fast, bundles deps) or mkdist (preserves structure, default for libraries)"
206
+ },
207
+ target: {
208
+ type: "string",
209
+ description: "Build target: browser, bun, or node (default: bun)"
210
+ },
211
+ format: {
212
+ type: "string",
213
+ description: "Output format: esm, cjs, or iife (default: esm)"
214
+ },
215
+ minify: {
216
+ type: "boolean",
217
+ description: "Enable all minification options (default: false)"
218
+ },
219
+ minifyWhitespace: {
220
+ type: "boolean",
221
+ description: "Minify whitespace (default: false)"
222
+ },
223
+ minifySyntax: {
224
+ type: "boolean",
225
+ description: "Minify syntax and inline constants (default: false)"
226
+ },
227
+ minifyIdentifiers: {
228
+ type: "boolean",
229
+ description: "Minify variable and function identifiers (default: false)"
230
+ },
231
+ sourcemap: {
232
+ type: "string",
233
+ description: "Sourcemap option: none, linked, inline, or external (default: none)"
234
+ },
235
+ splitting: {
236
+ type: "boolean",
237
+ description: "Enable code splitting (default: true)"
238
+ },
239
+ external: {
240
+ type: "string",
241
+ description: "External packages to exclude from bundle (supports wildcards)"
242
+ },
243
+ bytecode: {
244
+ type: "boolean",
245
+ description: "Generate bytecode for faster cold starts (requires format: cjs, target: bun)"
246
+ },
247
+ drop: {
248
+ type: "string",
249
+ description: "Drop function calls (e.g., 'console.log', 'debugger')"
250
+ },
251
+ packages: {
252
+ type: "string",
253
+ description: "How to handle dependencies: bundle or external (default: bundle)"
254
+ },
255
+ publicPath: {
256
+ type: "string",
257
+ description: "Prefix for import paths in bundled code"
258
+ },
259
+ root: {
260
+ type: "string",
261
+ description: "Project root for resolving relative paths"
262
+ },
263
+ define: {
264
+ type: "string",
265
+ description: `Define global constants (JSON format, e.g., '{"__VERSION__":"1.0.0"}')`
266
+ },
267
+ naming: {
268
+ type: "string",
269
+ description: "Customize output file naming (JSON format)"
270
+ },
271
+ env: {
272
+ type: "string",
273
+ description: "Environment variable handling: inline, disable, or prefix like PUBLIC_*"
274
+ },
275
+ banner: {
276
+ type: "string",
277
+ description: "Add banner to bundled code (e.g., 'use client')"
278
+ },
279
+ footer: {
280
+ type: "string",
281
+ description: "Add footer to bundled code"
282
+ },
283
+ conditions: {
284
+ type: "string",
285
+ description: "Package.json exports conditions for import resolution"
286
+ },
287
+ loader: {
288
+ type: "string",
289
+ description: "Custom loaders for file extensions (JSON format)"
290
+ },
291
+ ignoreDCEAnnotations: {
292
+ type: "boolean",
293
+ description: "Ignore dead code elimination annotations"
294
+ },
295
+ emitDCEAnnotations: {
296
+ type: "boolean",
297
+ description: "Force emit dead code elimination annotations"
298
+ },
299
+ throw: {
300
+ type: "boolean",
301
+ description: "Throw on build errors instead of returning success: false"
302
+ },
303
+ production: {
304
+ type: "boolean",
305
+ description: "Enable production mode (minify=true, sourcemap=none, env=inline)"
306
+ },
307
+ dev: {
308
+ type: "boolean",
309
+ description: "Enable development mode (watch=true, sourcemap=linked, env=disable)"
310
+ },
311
+ library: {
312
+ type: "boolean",
313
+ description: "Enable library mode (packages=external, bundler=mkdist, generateTypes=true)"
314
+ },
315
+ react: {
316
+ type: "boolean",
317
+ description: "Enable React preset (jsx=automatic, target=browser)"
318
+ },
319
+ node: {
320
+ type: "boolean",
321
+ description: "Enable Node preset (target=node, format=cjs)"
322
+ },
323
+ monorepo: {
324
+ type: "boolean",
325
+ description: "Enable monorepo preset (concurrency=auto, validateTsconfig=true)"
326
+ },
327
+ compile: {
328
+ type: "boolean",
329
+ description: "Generate standalone executable (default: false)"
330
+ },
331
+ allowPrivateBuild: {
332
+ type: "string",
333
+ description: "Allow building packages with private: true in package.json. Can be a package name pattern or comma-separated patterns (e.g., '@reliverse/*')"
334
+ },
335
+ replaceExports: {
336
+ type: "boolean",
337
+ description: "Replace exports from ./dist/*.js to ./src/*.ts after build (default: false)"
338
+ },
339
+ replaceExportsIgnorePackages: {
340
+ type: "string",
341
+ description: "Packages to ignore when replacing exports (supports glob patterns like @reliverse/*)"
342
+ },
343
+ cache: {
344
+ type: "boolean",
345
+ description: "Enable build cache (default: true)"
346
+ },
347
+ noCache: {
348
+ type: "boolean",
349
+ description: "Disable build cache (default: false)"
350
+ },
351
+ generateTypes: {
352
+ type: "boolean",
353
+ description: "Generate TypeScript declaration files (default: false)"
354
+ },
355
+ typeCheck: {
356
+ type: "boolean",
357
+ description: "Run type checking during build (default: false)"
358
+ },
359
+ validateTsconfig: {
360
+ type: "boolean",
361
+ description: "Validate tsconfig.json for common issues (default: true)"
362
+ },
363
+ strictTsconfig: {
364
+ type: "boolean",
365
+ description: "Make tsconfig validation errors fatal (default: false)"
366
+ },
367
+ dtsProvider: {
368
+ type: "string",
369
+ description: "DTS generation provider: dts-bundle-generator, api-extractor, typescript, or mkdist (default: dts-bundle-generator)"
370
+ },
371
+ maxConfigDepth: {
372
+ type: "number",
373
+ description: "Maximum depth to search for dler.ts config files (default: 3)"
374
+ },
375
+ entryNaming: {
376
+ type: "string",
377
+ description: "Naming pattern for entry files (e.g., '[dir]/[name].[ext]')"
378
+ },
379
+ chunkNaming: {
380
+ type: "string",
381
+ description: "Naming pattern for chunk files (e.g., '[name]-[hash].[ext]')"
382
+ },
383
+ assetNaming: {
384
+ type: "string",
385
+ description: "Naming pattern for asset files (e.g., '[name]-[hash].[ext]')"
386
+ },
387
+ noBundle: {
388
+ type: "boolean",
389
+ description: "Disable bundling (transpile only) (default: false)"
390
+ },
391
+ reactFastRefresh: {
392
+ type: "boolean",
393
+ description: "Enable React Fast Refresh (default: false)"
394
+ },
395
+ noClearScreen: {
396
+ type: "boolean",
397
+ description: "Don't clear screen in watch mode (default: false)"
398
+ },
399
+ windowsHideConsole: {
400
+ type: "boolean",
401
+ description: "Hide console window on Windows (default: false)"
402
+ },
403
+ windowsIcon: {
404
+ type: "string",
405
+ description: "Path to Windows icon file (.ico) for executable"
406
+ },
407
+ windowsTitle: {
408
+ type: "string",
409
+ description: "Windows executable title"
410
+ },
411
+ app: {
412
+ type: "boolean",
413
+ description: "Enable app mode (default: false)"
414
+ },
415
+ serverComponents: {
416
+ type: "boolean",
417
+ description: "Enable server components support (default: false)"
418
+ },
419
+ debugDumpServerFiles: {
420
+ type: "boolean",
421
+ description: "Dump server files for debugging (default: false)"
422
+ },
423
+ debugNoMinify: {
424
+ type: "boolean",
425
+ description: "Disable minification for debugging (default: false)"
426
+ },
427
+ bundleAnalyzer: {
428
+ type: "boolean",
429
+ description: "Enable bundle analyzer (default: false)"
430
+ },
431
+ performanceMonitoring: {
432
+ type: "boolean",
433
+ description: "Enable performance monitoring (default: false)"
434
+ },
435
+ bundleSizeLimit: {
436
+ type: "number",
437
+ description: "Maximum bundle size in bytes (default: unlimited)"
438
+ },
439
+ performanceBudget: {
440
+ type: "string",
441
+ description: `Performance budget configuration (JSON format, e.g., '{"maxBundleSize":1048576}')`
442
+ },
443
+ imageOptimization: {
444
+ type: "boolean",
445
+ description: "Enable image optimization (default: false)"
446
+ },
447
+ fontOptimization: {
448
+ type: "boolean",
449
+ description: "Enable font optimization (default: false)"
450
+ },
451
+ cssOptimization: {
452
+ type: "boolean",
453
+ description: "Enable CSS optimization (default: false)"
454
+ },
455
+ svgAsReact: {
456
+ type: "boolean",
457
+ description: "Convert SVG to React components (default: false)"
458
+ },
459
+ cssModules: {
460
+ type: "boolean",
461
+ description: "Enable CSS modules (default: false)"
462
+ },
463
+ workerSupport: {
464
+ type: "boolean",
465
+ description: "Enable worker support (default: false)"
466
+ },
467
+ plugins: {
468
+ type: "string",
469
+ description: "Comma-separated list of plugins (e.g., 'react-refresh,typescript-declarations')"
470
+ },
471
+ macros: {
472
+ type: "boolean",
473
+ description: "Enable Bun macros (default: false)"
474
+ },
475
+ sideEffects: {
476
+ type: "boolean",
477
+ description: "Mark package as side-effect free (default: false)"
478
+ },
479
+ devServer: {
480
+ type: "boolean",
481
+ description: "Enable development server (default: false)"
482
+ },
483
+ port: {
484
+ type: "number",
485
+ description: "Development server port (default: 3000)"
486
+ },
487
+ open: {
488
+ type: "boolean",
489
+ description: "Open browser on dev server start (default: false)"
490
+ },
491
+ html: {
492
+ type: "boolean",
493
+ description: "Generate HTML file (default: false)"
494
+ },
495
+ cssChunking: {
496
+ type: "boolean",
497
+ description: "Enable CSS chunking (default: false)"
498
+ },
499
+ publicAssets: {
500
+ type: "string",
501
+ description: "Public assets directory (default: 'public')"
502
+ },
503
+ assets: {
504
+ type: "string",
505
+ description: "Assets directory (default: 'assets')"
506
+ },
507
+ goProvider: {
508
+ type: "string",
509
+ description: "Go build provider: xgo or native (default: xgo)"
510
+ },
511
+ goTargets: {
512
+ type: "string",
513
+ description: "Go build targets (comma-separated, e.g., 'linux/amd64,windows/amd64')"
514
+ },
515
+ goOutputDir: {
516
+ type: "string",
517
+ description: "Go output directory (default: 'dist')"
518
+ },
519
+ goOutputName: {
520
+ type: "string",
521
+ description: "Go output binary name (default: package name)"
522
+ },
523
+ goBuildMode: {
524
+ type: "string",
525
+ description: "Go build mode: default, c-shared, or c-archive (default: default)"
526
+ },
527
+ goLdflags: {
528
+ type: "string",
529
+ description: "Go linker flags (default: '-s -w')"
530
+ },
531
+ goMainFile: {
532
+ type: "string",
533
+ description: "Main Go file to build (default: main.go)"
534
+ },
535
+ goVersion: {
536
+ type: "string",
537
+ description: "Go version for xgo (default: 1.20.3)"
538
+ },
539
+ goOnly: {
540
+ type: "boolean",
541
+ description: "Skip TypeScript builds and only build Go binaries (default: false)"
542
+ },
543
+ tsOnly: {
544
+ type: "boolean",
545
+ description: "Skip Go builds and only build TypeScript/JavaScript (default: false)"
546
+ },
547
+ goEnable: {
548
+ type: "boolean",
549
+ description: "Enable Go build (default: auto-detect)"
24
550
  }
25
- const goOptions = {};
26
- if (args.goProvider) goOptions.provider = args.goProvider;
27
- if (args.goTargets) {
28
- goOptions.targets = args.goTargets;
29
- }
30
- if (args.goOutputDir) goOptions.outputDir = args.goOutputDir;
31
- if (args.goOutputName) goOptions.outputName = args.goOutputName;
32
- if (args.goBuildMode) goOptions.buildMode = args.goBuildMode;
33
- if (args.goLdflags) goOptions.ldflags = args.goLdflags;
34
- if (args.goMainFile) goOptions.mainFile = args.goMainFile;
35
- if (args.goVersion) goOptions.goVersion = args.goVersion;
36
- if (args.goEnable !== void 0) goOptions.enable = args.goEnable;
37
- const buildOptionsInput = { ...args };
38
- if (Object.keys(goOptions).length > 0) {
39
- buildOptionsInput.go = goOptions;
40
- }
41
- const buildOptions = applyPresets(buildOptionsInput);
42
- validateAndExit(buildOptions);
43
- const results = await runBuildOnAllPackages(
44
- args.ignore,
45
- args.cwd,
46
- {
551
+ }),
552
+ run: async ({ args }) => {
553
+ try {
554
+ if (typeof process.versions.bun === "undefined") {
555
+ logger.error("\u274C This command requires Bun runtime. Sorry.");
556
+ process.exit(1);
557
+ }
558
+ if (args.goOnly && args.tsOnly) {
559
+ logger.error(
560
+ "\u274C --go-only and --ts-only cannot be used together. Please use only one."
561
+ );
562
+ process.exit(1);
563
+ }
564
+ const goOptions = {};
565
+ if (args.goProvider) goOptions.provider = args.goProvider;
566
+ if (args.goTargets) {
567
+ goOptions.targets = args.goTargets;
568
+ }
569
+ if (args.goOutputDir) goOptions.outputDir = args.goOutputDir;
570
+ if (args.goOutputName) goOptions.outputName = args.goOutputName;
571
+ if (args.goBuildMode) goOptions.buildMode = args.goBuildMode;
572
+ if (args.goLdflags) goOptions.ldflags = args.goLdflags;
573
+ if (args.goMainFile) goOptions.mainFile = args.goMainFile;
574
+ if (args.goVersion) goOptions.goVersion = args.goVersion;
575
+ if (args.goEnable !== void 0) goOptions.enable = args.goEnable;
576
+ const buildOptionsInput = { ...args };
577
+ if (Object.keys(goOptions).length > 0) {
578
+ buildOptionsInput.go = goOptions;
579
+ }
580
+ const buildOptions = applyPresets(buildOptionsInput);
581
+ validateAndExit(buildOptions);
582
+ const results = await runBuildOnAllPackages(args.ignore, args.cwd, {
47
583
  ...buildOptions,
48
584
  allowPrivateBuild: args.allowPrivateBuild,
49
585
  filter: args.filter
586
+ });
587
+ if (results.hasErrors) {
588
+ process.exit(1);
50
589
  }
51
- );
52
- if (results.hasErrors) {
53
- process.exit(1);
54
- }
55
- const shouldReplaceExports = args.replaceExports === true;
56
- if (shouldReplaceExports && !buildOptions.watch) {
57
- if (args.verbose) {
58
- logger.info(
59
- "\n\u{1F4DD} Replacing exports from ./src/*.ts to ./dist/*.js after build..."
60
- );
590
+ const shouldReplaceExports = args.replaceExports === true;
591
+ if (shouldReplaceExports && !buildOptions.watch) {
592
+ if (args.verbose) {
593
+ logger.info(
594
+ "\n\u{1F4DD} Replacing exports from ./src/*.ts to ./dist/*.js after build..."
595
+ );
596
+ }
597
+ await replaceExportsInPackages({
598
+ direction: "ts-to-js",
599
+ cwd: args.cwd,
600
+ ignorePackages: args.replaceExportsIgnorePackages,
601
+ verbose: args.verbose
602
+ });
61
603
  }
62
- await replaceExportsInPackages({
63
- direction: "ts-to-js",
64
- cwd: args.cwd,
65
- ignorePackages: args.replaceExportsIgnorePackages,
66
- verbose: args.verbose
67
- });
68
- }
69
- logger.success("\n\u2705 All packages built successfully!");
70
- } catch (error) {
71
- logger.error("\n\u274C Build failed:");
72
- if (error instanceof Error) {
73
- logger.error(error.message);
74
- } else {
75
- logger.error(String(error));
604
+ logger.success("\n\u2705 All packages built successfully!");
605
+ } catch (error) {
606
+ logger.error("\n\u274C Build failed:");
607
+ if (error instanceof Error) {
608
+ logger.error(error.message);
609
+ } else {
610
+ logger.error(String(error));
611
+ }
612
+ process.exit(1);
76
613
  }
77
- process.exit(1);
78
614
  }
79
- };
80
- const buildCmdArgs = defineCmdArgs({
81
- ignore: {
82
- type: "string",
83
- description: "Package(s) to ignore (supports wildcards like @reliverse/*)"
84
- },
85
- filter: {
86
- type: "string",
87
- description: "Package(s) to include (supports wildcards and comma-separated values like '@reliverse/dler-prompt,@reliverse/dler-build'). Takes precedence over --ignore when both are provided."
88
- },
89
- cwd: {
90
- type: "string",
91
- description: "Working directory (monorepo root)"
92
- },
93
- concurrency: {
94
- type: "number",
95
- description: "Number of packages to build concurrently (default: 5)"
96
- },
97
- stopOnError: {
98
- type: "boolean",
99
- description: "Stop on first error instead of collecting all errors (default: false)"
100
- },
101
- verbose: {
102
- type: "boolean",
103
- description: "Verbose mode (default: false)"
104
- },
105
- watch: {
106
- type: "boolean",
107
- description: "Watch mode for hot rebuild (default: false)"
108
- },
109
- bundler: {
110
- type: "string",
111
- description: "Bundler to use: bun (fast, bundles deps) or mkdist (preserves structure, default for libraries)"
112
- },
113
- target: {
114
- type: "string",
115
- description: "Build target: browser, bun, or node (default: bun)"
116
- },
117
- format: {
118
- type: "string",
119
- description: "Output format: esm, cjs, or iife (default: esm)"
120
- },
121
- minify: {
122
- type: "boolean",
123
- description: "Enable all minification options (default: false)"
124
- },
125
- minifyWhitespace: {
126
- type: "boolean",
127
- description: "Minify whitespace (default: false)"
128
- },
129
- minifySyntax: {
130
- type: "boolean",
131
- description: "Minify syntax and inline constants (default: false)"
132
- },
133
- minifyIdentifiers: {
134
- type: "boolean",
135
- description: "Minify variable and function identifiers (default: false)"
136
- },
137
- sourcemap: {
138
- type: "string",
139
- description: "Sourcemap option: none, linked, inline, or external (default: none)"
140
- },
141
- splitting: {
142
- type: "boolean",
143
- description: "Enable code splitting (default: true)"
144
- },
145
- external: {
146
- type: "string",
147
- description: "External packages to exclude from bundle (supports wildcards)"
148
- },
149
- bytecode: {
150
- type: "boolean",
151
- description: "Generate bytecode for faster cold starts (requires format: cjs, target: bun)"
152
- },
153
- drop: {
154
- type: "string",
155
- description: "Drop function calls (e.g., 'console.log', 'debugger')"
156
- },
157
- packages: {
158
- type: "string",
159
- description: "How to handle dependencies: bundle or external (default: bundle)"
160
- },
161
- publicPath: {
162
- type: "string",
163
- description: "Prefix for import paths in bundled code"
164
- },
165
- root: {
166
- type: "string",
167
- description: "Project root for resolving relative paths"
168
- },
169
- define: {
170
- type: "string",
171
- description: `Define global constants (JSON format, e.g., '{"__VERSION__":"1.0.0"}')`
172
- },
173
- naming: {
174
- type: "string",
175
- description: "Customize output file naming (JSON format)"
176
- },
177
- env: {
178
- type: "string",
179
- description: "Environment variable handling: inline, disable, or prefix like PUBLIC_*"
180
- },
181
- banner: {
182
- type: "string",
183
- description: "Add banner to bundled code (e.g., 'use client')"
184
- },
185
- footer: {
186
- type: "string",
187
- description: "Add footer to bundled code"
188
- },
189
- conditions: {
190
- type: "string",
191
- description: "Package.json exports conditions for import resolution"
192
- },
193
- loader: {
194
- type: "string",
195
- description: "Custom loaders for file extensions (JSON format)"
196
- },
197
- ignoreDCEAnnotations: {
198
- type: "boolean",
199
- description: "Ignore dead code elimination annotations"
200
- },
201
- emitDCEAnnotations: {
202
- type: "boolean",
203
- description: "Force emit dead code elimination annotations"
204
- },
205
- throw: {
206
- type: "boolean",
207
- description: "Throw on build errors instead of returning success: false"
208
- },
209
- production: {
210
- type: "boolean",
211
- description: "Enable production mode (minify=true, sourcemap=none, env=inline)"
212
- },
213
- dev: {
214
- type: "boolean",
215
- description: "Enable development mode (minify=false, sourcemap=inline, watch=true)"
216
- },
217
- compile: {
218
- type: "boolean",
219
- description: "Generate standalone Bun executable"
220
- },
221
- cache: {
222
- type: "boolean",
223
- description: "Enable build caching (default: true)"
224
- },
225
- noCache: {
226
- type: "boolean",
227
- description: "Disable build caching"
228
- },
229
- entryNaming: {
230
- type: "string",
231
- description: "Entry point naming pattern (e.g., '[dir]/[name].[ext]')"
232
- },
233
- chunkNaming: {
234
- type: "string",
235
- description: "Chunk naming pattern (e.g., '[name]-[hash].[ext]')"
236
- },
237
- assetNaming: {
238
- type: "string",
239
- description: "Asset naming pattern (e.g., '[name]-[hash].[ext]')"
240
- },
241
- // Frontend-specific options
242
- html: {
243
- type: "boolean",
244
- description: "Enable HTML entry point processing (auto-detected for frontend apps)"
245
- },
246
- cssChunking: {
247
- type: "boolean",
248
- description: "Chunk CSS to reduce duplication (default: true for frontend apps)"
249
- },
250
- devServer: {
251
- type: "boolean",
252
- description: "Start dev server with HMR (requires --watch)"
253
- },
254
- port: {
255
- type: "number",
256
- description: "Dev server port (default: 3000)"
257
- },
258
- open: {
259
- type: "boolean",
260
- description: "Open browser on dev server start"
261
- },
262
- publicAssets: {
263
- type: "string",
264
- description: "Public assets directory (default: public)"
265
- },
266
- jsxRuntime: {
267
- type: "string",
268
- description: "JSX runtime: automatic or classic (default: automatic)"
269
- },
270
- jsxImportSource: {
271
- type: "string",
272
- description: "JSX import source (e.g., 'react' for classic runtime)"
273
- },
274
- keepNames: {
275
- type: "boolean",
276
- description: "Preserve original function and class names when minifying"
277
- },
278
- debug: {
279
- type: "boolean",
280
- description: "Enable debug mode with verbose internal logging"
281
- },
282
- experimental: {
283
- type: "string",
284
- description: "Enable experimental features (comma-separated list)"
285
- },
286
- // New Bun bundler features
287
- noBundle: {
288
- type: "boolean",
289
- description: "Transpile only \u2014 do not bundle"
290
- },
291
- reactFastRefresh: {
292
- type: "boolean",
293
- description: "Enable React Fast Refresh transform (for development testing)"
294
- },
295
- noClearScreen: {
296
- type: "boolean",
297
- description: "Don't clear the terminal when rebuilding with --watch"
298
- },
299
- // Windows executable options
300
- windowsHideConsole: {
301
- type: "boolean",
302
- description: "Prevent a console window from opening when running a compiled Windows executable"
303
- },
304
- windowsIcon: {
305
- type: "string",
306
- description: "Set an icon for the Windows executable"
307
- },
308
- windowsTitle: {
309
- type: "string",
310
- description: "Set the Windows executable product name"
311
- },
312
- windowsPublisher: {
313
- type: "string",
314
- description: "Set the Windows executable company name"
315
- },
316
- windowsVersion: {
317
- type: "string",
318
- description: "Set the Windows executable version (e.g. 1.2.3.4)"
319
- },
320
- windowsDescription: {
321
- type: "string",
322
- description: "Set the Windows executable description"
323
- },
324
- windowsCopyright: {
325
- type: "string",
326
- description: "Set the Windows executable copyright notice"
327
- },
328
- // Experimental features
329
- app: {
330
- type: "boolean",
331
- description: "(EXPERIMENTAL) Build a web app for production using Bun Bake"
332
- },
333
- serverComponents: {
334
- type: "boolean",
335
- description: "(EXPERIMENTAL) Enable React Server Components"
336
- },
337
- debugDumpServerFiles: {
338
- type: "boolean",
339
- description: "When --app is set, dump all server files to disk even for static builds"
340
- },
341
- debugNoMinify: {
342
- type: "boolean",
343
- description: "When --app is set, disable all minification"
344
- },
345
- // Enhanced features
346
- macros: {
347
- type: "boolean",
348
- description: "Enable Bun macros support for compile-time code generation"
349
- },
350
- sideEffects: {
351
- type: "string",
352
- description: "Configure sideEffects for tree-shaking (boolean or JSON array)"
353
- },
354
- bundleAnalyzer: {
355
- type: "boolean",
356
- description: "Generate bundle analysis report"
357
- },
358
- typeCheck: {
359
- type: "boolean",
360
- description: "Run TypeScript type checking during build"
361
- },
362
- generateTypes: {
363
- type: "boolean",
364
- description: "Generate TypeScript declaration files (.d.ts)"
365
- },
366
- bundleSizeLimit: {
367
- type: "number",
368
- description: "Set maximum bundle size limit in bytes"
369
- },
370
- performanceBudget: {
371
- type: "string",
372
- description: "Set performance budget (JSON format)"
373
- },
374
- // Asset optimization
375
- imageOptimization: {
376
- type: "boolean",
377
- description: "Enable image optimization (WebP conversion, compression)"
378
- },
379
- fontOptimization: {
380
- type: "boolean",
381
- description: "Enable font optimization (subsetting, compression)"
382
- },
383
- cssOptimization: {
384
- type: "boolean",
385
- description: "Enable CSS optimization (purge, minify, autoprefixer)"
386
- },
387
- // Modern loaders
388
- svgAsReact: {
389
- type: "boolean",
390
- description: "Transform SVG files into React components"
391
- },
392
- cssModules: {
393
- type: "boolean",
394
- description: "Enable CSS Modules support"
395
- },
396
- workerSupport: {
397
- type: "boolean",
398
- description: "Enable Web Worker support"
399
- },
400
- // Plugin system
401
- plugins: {
402
- type: "string",
403
- description: "Load custom plugins (comma-separated list)"
404
- },
405
- // Performance monitoring
406
- performanceMonitoring: {
407
- type: "boolean",
408
- description: "Enable performance monitoring and reporting"
409
- },
410
- bundleAnalysis: {
411
- type: "boolean",
412
- description: "Generate detailed bundle analysis"
413
- },
414
- maxConfigDepth: {
415
- type: "number",
416
- description: "Maximum directory levels to search up for dler.ts config (default: 3)"
417
- },
418
- // Package kind and bin definitions
419
- kind: {
420
- type: "string",
421
- description: "Package kind: library, cli, browser-app, or native-app"
422
- },
423
- bin: {
424
- type: "string",
425
- description: "Binary definitions for CLI packages (e.g., 'dler=dist/cli.js,login=dist/foo/bar/login.js')"
426
- },
427
- // TSConfig validation
428
- strictTsconfig: {
429
- type: "boolean",
430
- description: "Make TSConfig validation errors fatal (default: false)"
431
- },
432
- validateTsconfig: {
433
- type: "boolean",
434
- description: "Validate tsconfig.json files for common issues (default: true)"
435
- },
436
- dtsProvider: {
437
- type: "string",
438
- description: "Provider for generating .d.ts files: dts-bundle-generator (default), api-extractor, typescript, or mkdist"
439
- },
440
- replaceExports: {
441
- type: "boolean",
442
- description: "Replace exports from ./src/*.ts to ./dist/*.js after build completes (default: false)"
443
- },
444
- replaceExportsIgnorePackages: {
445
- type: "string",
446
- description: "Packages to ignore when replacing exports (supports glob patterns like @reliverse/*)"
447
- },
448
- allowPrivateBuild: {
449
- type: "string",
450
- description: "Allow building private packages (supports wildcards like @reliverse/* to build all packages starting with @reliverse/)"
451
- },
452
- // Go build options
453
- goEnable: {
454
- type: "boolean",
455
- description: "Enable Go build (default: auto-detected if .go files exist)"
456
- },
457
- goProvider: {
458
- type: "string",
459
- description: "Go build provider: xgo (cross-compilation) or native (default: xgo)"
460
- },
461
- goTargets: {
462
- type: "string",
463
- description: "Go build targets (e.g., 'linux/amd64' or 'linux/amd64,windows/amd64')"
464
- },
465
- goOutputDir: {
466
- type: "string",
467
- description: "Go binary output directory (default: release)"
468
- },
469
- goOutputName: {
470
- type: "string",
471
- description: "Go binary name prefix (default: derived from package name)"
472
- },
473
- goBuildMode: {
474
- type: "string",
475
- description: "Go build mode: c-shared, c-archive, or exe (default: c-shared)"
476
- },
477
- goLdflags: {
478
- type: "string",
479
- description: "Go linker flags (default: '-s -w')"
480
- },
481
- goMainFile: {
482
- type: "string",
483
- description: "Main Go file to build (default: main.go)"
484
- },
485
- goVersion: {
486
- type: "string",
487
- description: "Go version for xgo (default: 1.20.3)"
488
- },
489
- goOnly: {
490
- type: "boolean",
491
- description: "Skip TypeScript builds and only build Go binaries (default: false)"
492
- },
493
- tsOnly: {
494
- type: "boolean",
495
- description: "Skip Go builds and only build TypeScript/JavaScript (default: false)"
496
- }
497
- });
498
- const buildCmdCfg = defineCmdCfg({
499
- name: "build",
500
- description: "Build all workspace packages using configurable bundler (mkdist for libraries, bun for apps) with dler.ts configuration. Auto-detects frontend apps and libraries. Supports presets: --production, --dev, --library, --react, --node, --monorepo.",
501
- examples: [
502
- "dler build",
503
- 'dler build --filter "@reliverse/dler-prompt,@reliverse/dler-build"',
504
- 'dler build --filter "@reliverse/dler-*"',
505
- 'dler build --ignore "@reliverse/*"',
506
- 'dler build --ignore "@reliverse/dler-colors" --ignore "@reliverse/dler-v1"',
507
- 'dler build --ignore "@reliverse/dler-colors @reliverse/dler-v1"',
508
- "dler build --cwd /path/to/monorepo",
509
- "dler build --cwd /path/to/monorepo --ignore @reliverse/*",
510
- "dler build --concurrency 8",
511
- "dler build --concurrency 2 --stopOnError",
512
- "dler build --ignore @reliverse/* --concurrency 6 --stopOnError",
513
- "dler build --verbose",
514
- "dler build --verbose --ignore @reliverse/*",
515
- "dler build --verbose --concurrency 2 --stopOnError",
516
- "dler build --watch",
517
- "dler build --watch --verbose",
518
- "dler build --target node --format cjs",
519
- "dler build --minify --sourcemap linked",
520
- "dler build --target browser --format esm --splitting false",
521
- "dler build --external react --external react-dom",
522
- "dler build --watch --target browser --minify --sourcemap inline",
523
- "dler build --production",
524
- "dler build --dev",
525
- "dler build --bytecode --format cjs --target bun",
526
- "dler build --minifyWhitespace --minifySyntax --minifyIdentifiers",
527
- "dler build --drop console.log --drop debugger",
528
- `dler build --env PUBLIC_* --define '{"__VERSION__":"1.0.0"}'`,
529
- "dler build --banner 'use client' --footer '// built with dler'",
530
- "dler build --entryNaming '[dir]/[name].[ext]' --chunkNaming '[name]-[hash].[ext]'",
531
- "dler build --compile --production",
532
- "dler build --noCache --verbose",
533
- "dler build --packages external --external 'react*'",
534
- "dler build --publicPath /assets/ --root ./src",
535
- "",
536
- "# Standalone Executable Examples:",
537
- "dler build --compile --production --target bun",
538
- "dler build --compile --target node --format cjs --minify",
539
- "dler build --compile --bytecode --format cjs --target bun",
540
- "dler build --compile --windowsIcon app.ico --windowsTitle 'My App'",
541
- "dler build --compile --production --env inline --drop console.log",
542
- "",
543
- "# Note: --compile generates executables alongside bundles",
544
- "# For Bun executables, use --target bun --format cjs --bytecode for best performance",
545
- "# For Node executables, use --target node --format cjs",
546
- "",
547
- "# Preset Examples:",
548
- "dler build --production # Optimized for production",
549
- "dler build --dev # Development mode with watch",
550
- "dler build --library # Library build (external deps)",
551
- "dler build --react # React app with JSX support",
552
- "dler build --node # Node.js server build",
553
- "dler build --monorepo # Monorepo optimized build",
554
- "",
555
- "# Bundler Examples:",
556
- "dler build --bundler mkdist # Use mkdist bundler (default for libraries)",
557
- "dler build --bundler bun # Use Bun bundler (default for apps)",
558
- "dler build --bundler mkdist --kind library",
559
- "dler build --bundler bun --kind library",
560
- "",
561
- "# Note: mkdist preserves file structure and is ideal for libraries",
562
- "# bun bundles dependencies and is ideal for applications",
563
- "",
564
- "# New Bun bundler features:",
565
- "dler build --noBundle --target node",
566
- "dler build --reactFastRefresh --watch",
567
- "dler build --noClearScreen --watch",
568
- "dler build --windowsHideConsole --windowsIcon app.ico --compile",
569
- "dler build --app --serverComponents",
570
- "dler build --debugDumpServerFiles --debugNoMinify",
571
- "",
572
- "# Enhanced Features:",
573
- "dler build --bundleAnalyzer --performanceMonitoring",
574
- "dler build --generateTypes --typeCheck",
575
- "dler build --macros --sideEffects false",
576
- `dler build --bundleSizeLimit 1048576 --performanceBudget '{"maxBundleSize":1048576}'`,
577
- "dler build --imageOptimization --fontOptimization --cssOptimization",
578
- "dler build --svgAsReact --cssModules --workerSupport",
579
- "dler build --plugins 'react-refresh,typescript-declarations,bundle-analyzer'",
580
- "",
581
- "# Frontend App Examples:",
582
- "dler build --devServer --watch --open --reactFastRefresh",
583
- "dler build --production --html --cssChunking --bundleAnalyzer",
584
- "dler build --target browser --format esm --html --cssChunking --svgAsReact",
585
- "dler build --devServer --port 8080 --open --cssModules",
586
- "dler build --html --publicAssets static --cssChunking --imageOptimization",
587
- "",
588
- "# Full-stack App Examples:",
589
- "dler build --target browser --format esm --html --assets public --workerSupport",
590
- "dler build --devServer --watch --target browser --html --performanceMonitoring",
591
- "",
592
- "# Library Examples:",
593
- "dler build --library --generateTypes --typeCheck",
594
- "dler build --target bun --format esm --generateTypes --bundleAnalyzer",
595
- "dler build --target node --format cjs --generateTypes --sideEffects false",
596
- "",
597
- "# Configuration Examples:",
598
- "# Create dler.ts in your monorepo root:",
599
- "# export default {",
600
- "# build: {",
601
- "# global: { target: 'bun', format: 'esm' },",
602
- "# packages: { 'my-package': { minify: true, generateTypes: true } },",
603
- "# patterns: [{ pattern: 'apps/*', config: { target: 'browser', html: true, bundleAnalyzer: true } }]",
604
- "# }",
605
- "# }",
606
- "",
607
- "# Note: Configuration is only supported via dler.ts",
608
- "# package.json build fields are not supported",
609
- "",
610
- "# Config Discovery Examples:",
611
- "dler build --maxConfigDepth 5",
612
- "",
613
- "# TSConfig Validation Examples:",
614
- "dler build --validateTsconfig",
615
- "dler build --strictTsconfig",
616
- "dler build --validateTsconfig --verbose",
617
- "dler build --noValidateTsconfig",
618
- "",
619
- "# Note: --validateTsconfig checks tsconfig.json for common issues",
620
- "# Use --strictTsconfig to make validation errors fatal",
621
- "",
622
- "# DTS Provider Examples:",
623
- "dler build --dtsProvider dts-bundle-generator",
624
- "dler build --dtsProvider api-extractor",
625
- "dler build --dtsProvider typescript",
626
- "dler build --dtsProvider mkdist",
627
- "dler build --generateTypes --dtsProvider dts-bundle-generator",
628
- "",
629
- "# Note: dts-bundle-generator is the default provider for better bundling",
630
- "# mkdist provider offers VFS-based processing with automatic relative import resolution",
631
- "# Use --dtsProvider to override the default provider",
632
- "",
633
- "# Go Build Examples:",
634
- "dler build --go-provider xgo",
635
- "dler build --go-provider native",
636
- "dler build --go-targets linux/amd64",
637
- "dler build --go-targets 'linux/amd64,windows/amd64,darwin/arm64'",
638
- "dler build --go-output-dir release",
639
- "dler build --go-output-name my-binary",
640
- "dler build --go-build-mode c-shared",
641
- "dler build --go-ldflags '-s -w -X main.version=1.0.0'",
642
- "dler build --go-main-file main.go",
643
- "dler build --go-version 1.21.0",
644
- "dler build --go-enable",
645
- "",
646
- "# Note: Go build is auto-detected if .go files exist in the package",
647
- "# Use --go-enable to explicitly enable, or configure in dler.ts",
648
- "# Use --go-provider xgo for cross-compilation (requires xgo installed)",
649
- "# Use --go-provider native for native builds (limited cross-compilation)",
650
- "",
651
- "# Build Type Selection Examples:",
652
- "dler build --go-only",
653
- "dler build --ts-only",
654
- "dler build --go-only --go-targets linux/amd64",
655
- "dler build --ts-only --target node --format cjs",
656
- "",
657
- "# Note: --go-only skips TypeScript builds and only builds Go binaries",
658
- "# Note: --ts-only skips Go builds and only builds TypeScript/JavaScript",
659
- "# Note: --go-only and --ts-only cannot be used together"
660
- ]
661
615
  });
662
- export default defineCmd(buildCmd, buildCmdArgs, buildCmdCfg);