@reliverse/build 2.2.9 → 2.3.2

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.
@@ -124,7 +124,7 @@ export class BuildCache {
124
124
  }
125
125
  this.hits++;
126
126
  return entry;
127
- } catch (_error) {
127
+ } catch {
128
128
  this.misses++;
129
129
  return null;
130
130
  }
@@ -145,7 +145,7 @@ export class BuildCache {
145
145
  };
146
146
  const cacheFilePath = this.getCacheFilePath(key);
147
147
  writeFileSync(cacheFilePath, JSON.stringify(entry, null, 2));
148
- } catch (_error) {
148
+ } catch {
149
149
  }
150
150
  }
151
151
  delete(key) {
@@ -158,7 +158,7 @@ export class BuildCache {
158
158
  const fs = require("node:fs");
159
159
  fs.unlinkSync(cacheFilePath);
160
160
  }
161
- } catch (_error) {
161
+ } catch {
162
162
  }
163
163
  }
164
164
  clear() {
@@ -176,7 +176,7 @@ export class BuildCache {
176
176
  }
177
177
  }
178
178
  }
179
- } catch (_error) {
179
+ } catch {
180
180
  }
181
181
  }
182
182
  getStats() {
@@ -202,7 +202,7 @@ export class BuildCache {
202
202
  misses: this.misses,
203
203
  size: totalSize
204
204
  };
205
- } catch (_error) {
205
+ } catch {
206
206
  return { hits: this.hits, misses: this.misses, size: 0 };
207
207
  }
208
208
  }
@@ -25,11 +25,11 @@ export declare const FRONTEND_HTML_PATTERNS: readonly ["index.html", "public/ind
25
25
  /**
26
26
  * Common JavaScript/TypeScript entry point patterns
27
27
  */
28
- export declare const JS_ENTRY_PATTERNS: readonly ["src/main.ts", "src/main.js", "src/index.ts", "src/index.js", "main.ts", "main.js", "index.ts", "index.js"];
28
+ export declare const JS_ENTRY_PATTERNS: readonly ["src/main.ts", "src/main.js", "src/mod.ts", "src/index.js", "main.ts", "main.js", "index.ts", "index.js"];
29
29
  /**
30
30
  * Common library entry point patterns
31
31
  */
32
- export declare const LIBRARY_ENTRY_PATTERNS: readonly ["src/index.ts", "src/mod.ts", "index.ts", "src/index.js", "src/mod.js", "index.js"];
32
+ export declare const LIBRARY_ENTRY_PATTERNS: readonly ["src/mod.ts", "src/mod.ts", "index.ts", "src/index.js", "src/mod.js", "index.js"];
33
33
  /**
34
34
  * Common Go project directories
35
35
  */
@@ -13,7 +13,7 @@ export const FRONTEND_HTML_PATTERNS = [
13
13
  export const JS_ENTRY_PATTERNS = [
14
14
  "src/main.ts",
15
15
  "src/main.js",
16
- "src/index.ts",
16
+ "src/mod.ts",
17
17
  "src/index.js",
18
18
  "main.ts",
19
19
  "main.js",
@@ -21,7 +21,7 @@ export const JS_ENTRY_PATTERNS = [
21
21
  "index.js"
22
22
  ];
23
23
  export const LIBRARY_ENTRY_PATTERNS = [
24
- "src/index.ts",
24
+ "src/mod.ts",
25
25
  "src/mod.ts",
26
26
  "index.ts",
27
27
  "src/index.js",
@@ -343,7 +343,7 @@ export class DevServer {
343
343
  this.notifyClients("reload");
344
344
  break;
345
345
  }
346
- } catch (_error) {
346
+ } catch {
347
347
  }
348
348
  }
349
349
  notifyClients(type, data) {
@@ -144,7 +144,7 @@ export class HTMLProcessor {
144
144
  }
145
145
  }
146
146
  }
147
- } catch (_error) {
147
+ } catch {
148
148
  }
149
149
  return files;
150
150
  }
@@ -57,6 +57,7 @@ export interface BuildOptions {
57
57
  watch?: boolean;
58
58
  bundler?: "bun" | "mkdist";
59
59
  target?: "browser" | "bun" | "node";
60
+ targets?: string | string[];
60
61
  format?: "esm" | "cjs" | "iife";
61
62
  minify?: boolean | MinifyOptions;
62
63
  minifyWhitespace?: boolean;
@@ -142,6 +143,11 @@ export interface BuildOptions {
142
143
  filter?: string | string[];
143
144
  goOnly?: boolean;
144
145
  tsOnly?: boolean;
146
+ compress?: boolean;
147
+ entry?: string | string[];
148
+ outdir?: string;
149
+ outfile?: string;
150
+ runtime?: "bun" | "node";
145
151
  }
146
152
  export interface CacheEntry {
147
153
  hash: string;
package/dist/mod.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BuildCache } from "./impl/cache.js";
2
2
  import type { BuildOptions, BuildResult, BuildSummary, PackageInfo } from "./impl/types.js";
3
3
  export type { GoBuildOptions } from "@reliverse/config/impl/build";
4
- export type { PackageKind, RegistryType, } from "@reliverse/config/impl/publish";
4
+ export type { PackageKind, RegistryType } from "@reliverse/config/impl/publish";
5
5
  export type { PreparePackageJsonOptions } from "@reliverse/typerso";
6
6
  export { addBinFieldToPackageJson, extractPackageName, parseBinArgument, preparePackageJsonForPublishing, transformExportsForBuild, } from "@reliverse/typerso";
7
7
  export type { DtsGeneratorOptions, DtsGeneratorResult, } from "./impl/dts-generator.js";
package/dist/mod.js CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  SVGAsReactPlugin,
49
49
  TypeScriptDeclarationsPlugin,
50
50
  WorkerPlugin
51
- } from "./impl/plugins/index.js";
51
+ } from "./impl/plugins/mod.js";
52
52
  import { validateTSConfig } from "./impl/tsconfig-validator.js";
53
53
  import { validateBuildConfig } from "./impl/type-guards.js";
54
54
  import {
@@ -402,57 +402,94 @@ const compileToExecutable = async (pkg, _outputs, options) => {
402
402
  await relinka.warn(`\u26A0\uFE0F ${pkg.name}: No entry point found for compilation`);
403
403
  return;
404
404
  }
405
- const executableName = entryPoint.split("/").pop()?.split("\\").pop()?.replace(/\.(ts|js|mjs|cjs)$/, "") || "app";
406
- const executablePath = join(
407
- pkg.outputDir,
408
- executableName + (process.platform === "win32" ? ".exe" : "")
409
- );
410
- if (!existsSync(pkg.outputDir)) {
411
- mkdirSync(pkg.outputDir, { recursive: true });
405
+ let targets = [];
406
+ if (options.targets) {
407
+ const targetsInput = Array.isArray(options.targets) ? options.targets : [options.targets];
408
+ for (const target of targetsInput) {
409
+ if (target === "all") {
410
+ targets.push("darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64", "windows-x64");
411
+ } else if (target === "native") {
412
+ const platform = process.platform === "darwin" ? "darwin" : process.platform === "win32" ? "windows" : "linux";
413
+ const arch = process.arch === "arm64" ? "arm64" : "x64";
414
+ targets.push(`${platform}-${arch}`);
415
+ } else {
416
+ targets.push(target);
417
+ }
418
+ }
419
+ targets = [...new Set(targets)];
420
+ } else {
421
+ const platform = process.platform === "darwin" ? "darwin" : process.platform === "win32" ? "windows" : "linux";
422
+ const arch = process.arch === "arm64" ? "arm64" : "x64";
423
+ targets = [`${platform}-${arch}`];
412
424
  }
413
- await relinka.info(
414
- `\u{1F528} Compiling ${pkg.name} to executable: ${executablePath}`
415
- );
416
- try {
417
- const buildConfig = {
418
- entrypoints: [entryPoint],
419
- outfile: executablePath,
420
- compile: true,
421
- target: options.target || "bun",
422
- format: options.format || "cjs"
423
- };
424
- if (process.platform === "win32") {
425
- if (options.windowsHideConsole)
426
- buildConfig.windowsHideConsole = options.windowsHideConsole;
427
- if (options.windowsIcon) buildConfig.windowsIcon = options.windowsIcon;
428
- if (options.windowsTitle) buildConfig.windowsTitle = options.windowsTitle;
429
- if (options.windowsPublisher)
430
- buildConfig.windowsPublisher = options.windowsPublisher;
431
- if (options.windowsVersion)
432
- buildConfig.windowsVersion = options.windowsVersion;
433
- if (options.windowsDescription)
434
- buildConfig.windowsDescription = options.windowsDescription;
435
- if (options.windowsCopyright)
436
- buildConfig.windowsCopyright = options.windowsCopyright;
437
- }
438
- const { $ } = await import("bun");
425
+ const isMultiTarget = targets.length > 1;
426
+ const { $ } = await import("bun");
427
+ for (const platform of targets) {
428
+ const shouldCreateSubdir = isMultiTarget;
429
+ const targetDir = shouldCreateSubdir ? join(pkg.outputDir, platform) : pkg.outputDir;
430
+ if (!existsSync(targetDir)) {
431
+ mkdirSync(targetDir, { recursive: true });
432
+ }
433
+ const ext = entryPoint.split(".").pop() || "";
434
+ const nameWithoutExt = ext ? entryPoint.slice(0, -ext.length - 1) : entryPoint;
435
+ const baseName = nameWithoutExt.split("/").pop()?.split("\\").pop() || "app";
436
+ const isWindows = platform.includes("windows");
437
+ const executableName = isWindows ? `${baseName}.exe` : baseName;
438
+ const executablePath = join(targetDir, executableName);
439
+ await relinka.info(
440
+ `\u{1F528} Compiling ${pkg.name} for ${platform}: ${executablePath}`
441
+ );
439
442
  try {
440
- const cmd = $`bun build ${entryPoint} --outfile ${executablePath} --compile --target ${buildConfig.target || "bun"}`;
441
- await cmd.cwd(pkg.path).quiet();
443
+ const compileArgs = [
444
+ "build",
445
+ entryPoint,
446
+ "--compile",
447
+ "--outfile",
448
+ executablePath,
449
+ "--target",
450
+ `bun-${platform}`
451
+ // Bun requires the bun- prefix
452
+ ];
453
+ if (options.minify ?? true) {
454
+ compileArgs.push("--minify");
455
+ }
456
+ if (options.sourcemap ?? false) {
457
+ compileArgs.push("--sourcemap");
458
+ }
459
+ if (options.bytecode) {
460
+ compileArgs.push("--bytecode");
461
+ }
462
+ if (options.external) {
463
+ const externals = Array.isArray(options.external) ? options.external : [options.external];
464
+ for (const ext2 of externals) {
465
+ compileArgs.push("--external", ext2);
466
+ }
467
+ }
468
+ const result = await $`bun ${compileArgs}`.cwd(pkg.path).quiet();
469
+ if (result.exitCode !== 0) {
470
+ throw new Error(`Compilation failed for ${platform}`);
471
+ }
472
+ if (!existsSync(executablePath)) {
473
+ throw new Error(`Executable was not created at ${executablePath}`);
474
+ }
475
+ const stats = statSync(executablePath);
476
+ await relinka.success(
477
+ `\u2705 ${pkg.name} (${platform}): Executable created (${formatBytes(stats.size)})`
478
+ );
442
479
  } catch (error) {
443
- await relinka.error(`\u274C Bun CLI compilation failed: ${error}`);
480
+ await relinka.error(`\u274C ${pkg.name} (${platform}): Compilation failed - ${error}`);
444
481
  throw error;
445
482
  }
446
- if (!existsSync(executablePath)) {
447
- throw new Error(`Executable was not created at ${executablePath}`);
483
+ }
484
+ if (options.compress && isMultiTarget) {
485
+ await relinka.info(`\u{1F4E6} Compressing builds for ${pkg.name}...`);
486
+ for (const platform of targets) {
487
+ const platformDir = join(pkg.outputDir, platform);
488
+ if (existsSync(platformDir)) {
489
+ await $`cd ${pkg.outputDir} && tar -czf ${platform}.tar.gz ${platform}`.quiet();
490
+ await $`rm -rf ${platformDir}`.quiet();
491
+ }
448
492
  }
449
- const stats = statSync(executablePath);
450
- await relinka.success(
451
- `\u2705 ${pkg.name}: Executable created (${formatBytes(stats.size)})`
452
- );
453
- } catch (error) {
454
- await relinka.error(`\u274C ${pkg.name}: Compilation failed - ${error}`);
455
- throw error;
456
493
  }
457
494
  };
458
495
  const buildWithMkdist = async (pkg, options, _bunBuildConfig) => {
@@ -758,7 +795,11 @@ export const buildPackage = async (pkg, options = {}, cache) => {
758
795
  }
759
796
  debugLogger.logConfigResolution(pkg, pkg.buildConfig ? "dler" : "default");
760
797
  debugLogger.logBuildOptions(mergedOptions, pkg);
761
- debugLogger.logEntryPoints(pkg);
798
+ const entryPoints = mergedOptions.entry ? (Array.isArray(mergedOptions.entry) ? mergedOptions.entry : [mergedOptions.entry]).map(
799
+ (ep) => resolve(pkg.path, ep)
800
+ ) : pkg.entryPoints;
801
+ const outputDir = mergedOptions.outdir ? resolve(pkg.path, mergedOptions.outdir) : pkg.outputDir;
802
+ debugLogger.logEntryPoints({ ...pkg, entryPoints });
762
803
  const startTime = Date.now();
763
804
  try {
764
805
  const validation = validateBuildConfig(mergedOptions);
@@ -768,8 +809,8 @@ export const buildPackage = async (pkg, options = {}, cache) => {
768
809
  );
769
810
  }
770
811
  const buildConfig = {
771
- entrypoints: pkg.entryPoints,
772
- outdir: pkg.outputDir,
812
+ entrypoints: entryPoints,
813
+ outdir: outputDir,
773
814
  target: validTarget,
774
815
  format: validFormat,
775
816
  sourcemap: validSourcemap,
@@ -1022,7 +1063,12 @@ export const buildPackage = async (pkg, options = {}, cache) => {
1022
1063
  });
1023
1064
  }
1024
1065
  if (mergedOptions.compile && result.success && result.outputs) {
1025
- await compileToExecutable(pkg, result.outputs, mergedOptions);
1066
+ const modifiedPkg = {
1067
+ ...pkg,
1068
+ entryPoints,
1069
+ outputDir
1070
+ };
1071
+ await compileToExecutable(modifiedPkg, result.outputs, mergedOptions);
1026
1072
  }
1027
1073
  if (result.success) {
1028
1074
  try {
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@reliverse/build",
3
+ "version": "2.3.2",
4
+ "private": false,
3
5
  "description": "Build utils for Reliverse ecosystem",
6
+ "license": "MIT",
4
7
  "author": "reliverse",
5
- "version": "2.2.9",
6
- "private": false,
8
+ "files": [
9
+ "dist",
10
+ "package.json"
11
+ ],
7
12
  "type": "module",
8
13
  "exports": {
9
14
  ".": {
@@ -11,13 +16,16 @@
11
16
  "default": "./dist/mod.js"
12
17
  }
13
18
  },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
14
22
  "dependencies": {
15
- "@reliverse/config": "2.2.9",
16
- "@reliverse/helpers": "2.2.13",
17
- "@reliverse/relinka": "2.2.9",
18
- "@reliverse/mapkit": "2.2.9",
19
- "@reliverse/matcha": "2.2.9",
20
- "@reliverse/typerso": "2.2.9",
23
+ "@reliverse/config": "2.3.2",
24
+ "@reliverse/helpers": "2.3.2",
25
+ "@reliverse/mapkit": "2.3.2",
26
+ "@reliverse/matcha": "2.3.2",
27
+ "@reliverse/relinka": "2.3.2",
28
+ "@reliverse/typerso": "2.3.2",
21
29
  "autoprefixer": "^10.4.23",
22
30
  "c12": "^3.3.3",
23
31
  "cssnano": "^7.1.2",
@@ -30,13 +38,5 @@
30
38
  "pkg-types": "^2.3.0",
31
39
  "semver": "^7.7.3",
32
40
  "tinyglobby": "^0.2.15"
33
- },
34
- "publishConfig": {
35
- "access": "public"
36
- },
37
- "files": [
38
- "dist",
39
- "package.json"
40
- ],
41
- "license": "MIT"
41
+ }
42
42
  }
File without changes
File without changes