bunup 0.15.4 → 0.15.6

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/dist/cli/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  build,
5
5
  processLoadedConfigs,
6
6
  resolveBuildOptions
7
- } from "../shared/bunup-x9dadf6b.js";
7
+ } from "../shared/bunup-1dt09a96.js";
8
8
  import {
9
9
  BunupCLIError,
10
10
  BunupWatchError,
@@ -20,24 +20,24 @@ import {
20
20
  logTime,
21
21
  logger,
22
22
  parseErrorMessage
23
- } from "../shared/bunup-1svmcpnr.js";
23
+ } from "../shared/bunup-k8ycyv8v.js";
24
24
 
25
25
  // packages/bunup/src/cli/index.ts
26
26
  import { loadConfig } from "coffi";
27
27
  import pc4 from "picocolors";
28
28
  // packages/bunup/package.json
29
- var version = "0.15.4";
29
+ var version = "0.15.6";
30
30
 
31
31
  // packages/bunup/src/printer/print-build-report.ts
32
32
  import { promisify } from "util";
33
33
  import { brotliCompress } from "zlib";
34
34
  import pc from "picocolors";
35
35
  var brotliAsync = promisify(brotliCompress);
36
- async function printBuildReport(buildOutput) {
37
- const options = buildOutput.options;
36
+ async function printBuildReport(buildResult) {
37
+ const options = buildResult.build.options;
38
38
  const { gzip = true, brotli = false, maxBundleSize } = options.report ?? {};
39
39
  const showCompression = gzip || brotli;
40
- const files = await Promise.all(buildOutput.files.map(async (file) => {
40
+ const files = await Promise.all(buildResult.files.map(async (file) => {
41
41
  const pathRelative = file.pathRelativeToOutdir;
42
42
  const size = file.size;
43
43
  const isDts = file.dts && file.kind === "entry-point";
@@ -193,8 +193,8 @@ async function watch(userOptions, rootDir, configFilePath) {
193
193
  ${buildCount > 1 ? pc2.magentaBright(`[x${buildCount}] `) : ""}${pc2.green(`Changed:`)} ${changed}${options.name ? ` ${pc2.bgBlueBright(` ${options.name} `)}` : ""}`);
194
194
  }
195
195
  const start = performance.now();
196
- const buildOutput = await build(userOptions, rootDir);
197
- await printBuildReport(buildOutput);
196
+ const buildResult = await build(userOptions, rootDir);
197
+ await printBuildReport(buildResult);
198
198
  if (!initial) {
199
199
  console.log(`
200
200
  ${pc2.green("\u2713")} Rebuild completed in ${pc2.green(logTime(performance.now() - start))}`);
@@ -331,7 +331,7 @@ async function main(args = Bun.argv.slice(2)) {
331
331
  }
332
332
  logger.info("Build started");
333
333
  const startTime = performance.now();
334
- const buildOutputs = [];
334
+ const buildResults = [];
335
335
  await Promise.all(configsToProcess.flatMap(({ options, rootDir }) => {
336
336
  const optionsArray = ensureArray(options);
337
337
  return optionsArray.map(async (o) => {
@@ -342,13 +342,13 @@ async function main(args = Bun.argv.slice(2)) {
342
342
  if (userOptions.watch) {
343
343
  await watch(userOptions, rootDir, filepath);
344
344
  } else {
345
- buildOutputs.push(await build(userOptions, rootDir));
345
+ buildResults.push(await build(userOptions, rootDir));
346
346
  }
347
347
  });
348
348
  }));
349
349
  const buildTimeMs = performance.now() - startTime;
350
350
  if (!cliOptions.watch && !shouldSilent) {
351
- await Promise.all(buildOutputs.map((o) => printBuildReport(o)));
351
+ await Promise.all(buildResults.map((o) => printBuildReport(o)));
352
352
  }
353
353
  if (cliOptions.watch) {
354
354
  console.log(`
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BuildContext, BuildMeta, BuildOptions, BuildOutput, BuildOutputFile, BunupPlugin, DefineConfigItem, DefineWorkspaceItem, WithOptional, WithRequired } from "./shared/bunup-zbep6g87";
2
- declare function build(userOptions: Partial<BuildOptions>, rootDir?: string): Promise<BuildOutput>;
1
+ import { BuildContext, BuildMeta, BuildOptions, BuildOutputFile, BuildResult, BunupPlugin, DefineConfigItem, DefineWorkspaceItem, WithOptional, WithRequired } from "./shared/bunup-daehgh3v";
2
+ declare function build(userOptions: Partial<BuildOptions>, rootDir?: string): Promise<BuildResult>;
3
3
  declare function defineConfig(options: DefineConfigItem | WithRequired<DefineConfigItem, "name">[]): DefineConfigItem | WithRequired<DefineConfigItem, "name">[];
4
4
  declare function defineWorkspace(options: WithOptional<DefineWorkspaceItem, "config">[], sharedOptions?: Partial<DefineConfigItem>): DefineWorkspaceItem[];
5
- export { defineWorkspace, defineConfig, build, DefineWorkspaceItem, DefineConfigItem, BunupPlugin, BuildOutputFile, BuildOutput, BuildOptions, BuildMeta, BuildContext };
5
+ export { defineWorkspace, defineConfig, build, DefineWorkspaceItem, DefineConfigItem, BunupPlugin, BuildResult, BuildOutputFile, BuildOptions, BuildMeta, BuildContext };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // @bun
2
2
  import {
3
3
  build
4
- } from "./shared/bunup-x9dadf6b.js";
5
- import"./shared/bunup-1svmcpnr.js";
4
+ } from "./shared/bunup-1dt09a96.js";
5
+ import"./shared/bunup-k8ycyv8v.js";
6
6
  // packages/bunup/src/define.ts
7
7
  function defineConfig(options) {
8
8
  return options;
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BuildOptions, BunupPlugin, BunupPluginHooks, exports, injectStyles, unused } from "./shared/bunup-zbep6g87";
1
+ import { BuildOptions, BunupPlugin, BunupPluginHooks, exports, injectStyles, unused } from "./shared/bunup-daehgh3v";
2
2
  type CopyOptions = {
3
3
  /** Whether to follow symbolic links when copying files. */
4
4
  followSymlinks?: boolean;
package/dist/plugins.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  logger,
8
8
  shims,
9
9
  unused
10
- } from "./shared/bunup-1svmcpnr.js";
10
+ } from "./shared/bunup-k8ycyv8v.js";
11
11
 
12
12
  // packages/bunup/src/plugins/copy.ts
13
13
  import { basename, extname, join } from "path";
@@ -20,7 +20,7 @@ import {
20
20
  parseErrorMessage,
21
21
  shims,
22
22
  unused
23
- } from "./bunup-1svmcpnr.js";
23
+ } from "./bunup-k8ycyv8v.js";
24
24
 
25
25
  // packages/bunup/src/loaders.ts
26
26
  import path from "path";
@@ -205,8 +205,8 @@ function useClient() {
205
205
  return {
206
206
  name: "use-client",
207
207
  hooks: {
208
- onBuildDone: async ({ output }) => {
209
- for (const file of output.files) {
208
+ onBuildDone: async ({ files }) => {
209
+ for (const file of files) {
210
210
  let text = await Bun.file(file.fullPath).text();
211
211
  const hasUseClient = text.split(`
212
212
  `).some((line) => line.trim().startsWith(`"use client";`));
@@ -327,21 +327,21 @@ function filterBunupPlugins(plugins) {
327
327
  return [];
328
328
  return plugins.filter((p) => ("hooks" in p));
329
329
  }
330
- async function runPluginBuildStartHooks(bunupPlugins, options) {
330
+ async function runPluginBuildStartHooks(bunupPlugins, ctx) {
331
331
  if (!bunupPlugins)
332
332
  return;
333
333
  for (const plugin of bunupPlugins) {
334
334
  if (plugin.hooks.onBuildStart) {
335
- await plugin.hooks.onBuildStart(options);
335
+ await plugin.hooks.onBuildStart(ctx);
336
336
  }
337
337
  }
338
338
  }
339
- async function runPluginBuildDoneHooks(bunupPlugins, options, output, meta) {
339
+ async function runPluginBuildDoneHooks(bunupPlugins, ctx) {
340
340
  if (!bunupPlugins)
341
341
  return;
342
342
  for (const plugin of bunupPlugins) {
343
343
  if (plugin.hooks.onBuildDone) {
344
- await plugin.hooks.onBuildDone({ options, output, meta });
344
+ await plugin.hooks.onBuildDone(ctx);
345
345
  }
346
346
  }
347
347
  }
@@ -397,10 +397,6 @@ async function build(userOptions, rootDir = process.cwd()) {
397
397
  }
398
398
  ac = new AbortController;
399
399
  const options = resolveBuildOptions(userOptions);
400
- const buildOutput = {
401
- files: [],
402
- options
403
- };
404
400
  if (options.silent) {
405
401
  logger.setSilent(options.silent);
406
402
  }
@@ -419,7 +415,7 @@ async function build(userOptions, rootDir = process.cwd()) {
419
415
  const allPlugins = resolvePlugins(options, packageJson.data);
420
416
  const bunupPlugins = filterBunupPlugins(allPlugins);
421
417
  const bunPlugins = filterBunPlugins(allPlugins);
422
- await runPluginBuildStartHooks(bunupPlugins, options);
418
+ await runPluginBuildStartHooks(bunupPlugins, { options });
423
419
  const entryArray = ensureArray(options.entry);
424
420
  const entrypoints = getFilesFromGlobs(entryArray, rootDir);
425
421
  if (!entrypoints.length) {
@@ -433,6 +429,7 @@ async function build(userOptions, rootDir = process.cwd()) {
433
429
  once: options.name,
434
430
  muted: true
435
431
  });
432
+ const buildOutputFiles = [];
436
433
  const absoluteEntrypoints = entrypoints.map((file) => `${rootDir}/${file}`);
437
434
  const resolvedDefine = getResolvedDefine(options.define, options.env);
438
435
  const resolvedMinify = getResolvedMinify(options);
@@ -484,8 +481,8 @@ async function build(userOptions, rootDir = process.cwd()) {
484
481
  const pathRelativeToRootDir = path2.join(options.outDir, pathRelativeToOutdir);
485
482
  const fullPath = path2.resolve(rootDir, pathRelativeToRootDir);
486
483
  await Bun.write(fullPath, content);
487
- if (!buildOutput.files.some((f) => f.fullPath === fullPath)) {
488
- buildOutput.files.push({
484
+ if (!buildOutputFiles.some((f) => f.fullPath === fullPath)) {
485
+ buildOutputFiles.push({
489
486
  fullPath,
490
487
  pathRelativeToRootDir,
491
488
  pathRelativeToOutdir,
@@ -524,7 +521,7 @@ async function build(userOptions, rootDir = process.cwd()) {
524
521
  const pathRelativeToRootDir = cleanPath(`${options.outDir}/${pathRelativeToOutdir}`);
525
522
  const fullPath = path2.join(rootDir, pathRelativeToRootDir);
526
523
  await Bun.write(fullPath, file.dts);
527
- buildOutput.files.push({
524
+ buildOutputFiles.push({
528
525
  fullPath,
529
526
  pathRelativeToRootDir,
530
527
  pathRelativeToOutdir,
@@ -540,14 +537,28 @@ async function build(userOptions, rootDir = process.cwd()) {
540
537
  throw new BunupDTSBuildError(parseErrorMessage(error));
541
538
  }
542
539
  }
543
- await runPluginBuildDoneHooks(bunupPlugins, options, buildOutput, {
544
- packageJson,
545
- rootDir
540
+ const buildResult = {
541
+ files: buildOutputFiles,
542
+ build: {
543
+ options,
544
+ meta: {
545
+ packageJson,
546
+ rootDir
547
+ }
548
+ }
549
+ };
550
+ await runPluginBuildDoneHooks(bunupPlugins, {
551
+ files: buildOutputFiles,
552
+ options,
553
+ meta: {
554
+ packageJson,
555
+ rootDir
556
+ }
546
557
  });
547
558
  if (options.onSuccess) {
548
559
  await executeOnSuccess(options.onSuccess, options, ac.signal);
549
560
  }
550
- return buildOutput;
561
+ return buildResult;
551
562
  }
552
563
 
553
564
  export { processLoadedConfigs, resolveBuildOptions, build };
@@ -38,39 +38,54 @@ type BuildOutputFile = {
38
38
  size: number;
39
39
  };
40
40
  /**
41
- * Represents the output of a build operation
41
+ * Build configuration and metadata used during build execution.
42
42
  */
43
- type BuildOutput = {
44
- /** Array of generated files with their paths and contents */
43
+ type BuildContext = {
44
+ /** Build configuration options that were used */
45
+ options: BuildOptions;
46
+ /** Build execution metadata */
47
+ meta: BuildMeta;
48
+ };
49
+ /**
50
+ * Build output containing generated files and build context.
51
+ */
52
+ type BuildResult = {
53
+ /** Generated output files */
45
54
  files: BuildOutputFile[];
46
- /** Options used for the build */
55
+ /** Build configuration and metadata that were used */
56
+ build: BuildContext;
57
+ };
58
+ /**
59
+ * Context provided when build starts.
60
+ */
61
+ type OnBuildStartCtx = {
62
+ /** Build configuration options that will be used */
47
63
  options: BuildOptions;
48
64
  };
49
65
  /**
50
- * Context provided to build hooks
66
+ * Context provided when build completes.
67
+ * Flattened structure for easy access in plugin hooks.
51
68
  */
52
- type BuildContext = {
53
- /** The build options that were used */
69
+ type OnBuildDoneCtx = {
70
+ /** Generated output files */
71
+ files: BuildOutputFile[];
72
+ /** Build configuration options that were used */
54
73
  options: BuildOptions;
55
- /** The output of the build */
56
- output: BuildOutput;
57
- /** The meta data of the build */
74
+ /** Build execution metadata */
58
75
  meta: BuildMeta;
59
76
  };
60
77
  /**
61
- * Hooks that can be implemented by Bunup plugins
78
+ * Hooks that can be implemented by Bunup plugins.
62
79
  */
63
80
  type BunupPluginHooks = {
64
81
  /**
65
- * Called when a build is successfully completed
66
- * @param ctx Build context containing options and output
82
+ * Called when a build is successfully completed.
67
83
  */
68
- onBuildDone?: (ctx: BuildContext) => MaybePromise<void>;
84
+ onBuildDone?: (ctx: OnBuildDoneCtx) => MaybePromise<void>;
69
85
  /**
70
- * Called before a build starts
71
- * @param options Build options that will be used
86
+ * Called before a build starts.
72
87
  */
73
- onBuildStart?: (options: BuildOptions) => MaybePromise<void>;
88
+ onBuildStart?: (ctx: OnBuildStartCtx) => MaybePromise<void>;
74
89
  };
75
90
  /**
76
91
  * Represents a Bunup-specific plugin
@@ -661,4 +676,4 @@ type DefineWorkspaceItem = {
661
676
  root: string;
662
677
  config?: DefineConfigItem | WithRequired<DefineConfigItem, "name">[];
663
678
  };
664
- export { WithOptional, WithRequired, DefineConfigItem, DefineWorkspaceItem, BuildMeta, BuildOutputFile, BuildOutput, BuildContext, BunupPluginHooks, BunupPlugin, exports, injectStyles, unused, BuildOptions };
679
+ export { WithOptional, WithRequired, DefineConfigItem, DefineWorkspaceItem, BuildMeta, BuildOutputFile, BuildContext, BuildResult, BunupPluginHooks, BunupPlugin, exports, injectStyles, unused, BuildOptions };
@@ -466,17 +466,17 @@ function exports(options = {}) {
466
466
  };
467
467
  }
468
468
  async function processPackageJsonExports(ctx, options) {
469
- const { output, options: buildOptions, meta } = ctx;
469
+ const { files, options: buildOptions, meta } = ctx;
470
470
  if (!meta.packageJson.path || !meta.packageJson.data) {
471
471
  return;
472
472
  }
473
473
  try {
474
- const { exportsField, entryPoints } = generateExportsFields(output.files, options.exclude, options.excludeCli, options.excludeCss, ctx);
474
+ const { exportsField, entryPoints } = generateExportsFields(files, options.exclude, options.excludeCli, options.excludeCss, ctx);
475
475
  const updatedFiles = createUpdatedFilesArray(meta.packageJson.data, buildOptions.outDir);
476
476
  const mergedExports = mergeCustomExportsWithGenerated(exportsField, options.customExports, ctx);
477
477
  const finalExports = addPackageJsonOrWildcardExport(mergedExports, options.includePackageJson, options.all);
478
478
  const newPackageJson = createUpdatedPackageJson(meta.packageJson.data, entryPoints, finalExports, updatedFiles);
479
- await validateBinFields(meta.packageJson.data, buildOptions.name, meta.packageJson.path);
479
+ await validateBinFields(meta.packageJson.data, buildOptions.name, meta.packageJson.path, meta.rootDir);
480
480
  if (Bun.deepEquals(newPackageJson, meta.packageJson.data)) {
481
481
  return;
482
482
  }
@@ -620,7 +620,10 @@ function mergeCustomExportsWithGenerated(baseExports, customExportsProvider, ctx
620
620
  if (!customExportsProvider) {
621
621
  return mergedExports;
622
622
  }
623
- const customExports = customExportsProvider(ctx);
623
+ const customExports = customExportsProvider({
624
+ options: ctx.options,
625
+ meta: ctx.meta
626
+ });
624
627
  if (!customExports) {
625
628
  return mergedExports;
626
629
  }
@@ -669,7 +672,7 @@ var CLI_EXCLUSION_PATTERNS = [
669
672
  "**/bin/index.{ts,tsx,js,jsx,mjs,cjs}"
670
673
  ];
671
674
  function isExcluded(entrypoint, exclude, excludeCli, ctx) {
672
- const userPatterns = typeof exclude === "function" ? exclude(ctx) : exclude;
675
+ const userPatterns = typeof exclude === "function" ? exclude({ options: ctx.options, meta: ctx.meta }) : exclude;
673
676
  const cliPatterns = excludeCli !== false ? CLI_EXCLUSION_PATTERNS : [];
674
677
  const allPatterns = [...cliPatterns, ...userPatterns ?? []];
675
678
  return allPatterns.some((pattern) => new Bun.Glob(pattern).match(entrypoint));
@@ -733,20 +736,22 @@ function exportFieldToEntryPoint(exportField) {
733
736
  return "module";
734
737
  }
735
738
  }
736
- async function validateBinFields(packageJsonData, projectName, packageJsonPath) {
737
- if (!packageJsonData?.bin)
739
+ async function validateBinFields(packageJsonData, projectName, packageJsonPath, rootDir) {
740
+ if (!packageJsonData?.bin || !rootDir)
738
741
  return;
739
742
  const bin = packageJsonData.bin;
740
743
  const invalidBins = [];
741
744
  if (typeof bin === "string") {
742
- const exists = await Bun.file(bin).exists();
745
+ const fullPath = path2.resolve(rootDir, bin);
746
+ const exists = await Bun.file(fullPath).exists();
743
747
  if (!exists) {
744
748
  invalidBins.push(`bin field points to ${pc3.yellow(bin)}`);
745
749
  }
746
750
  } else if (typeof bin === "object" && bin !== null) {
747
751
  for (const [name, binPath] of Object.entries(bin)) {
748
752
  if (typeof binPath === "string") {
749
- const exists = await Bun.file(binPath).exists();
753
+ const fullPath = path2.resolve(rootDir, binPath);
754
+ const exists = await Bun.file(fullPath).exists();
750
755
  if (!exists) {
751
756
  invalidBins.push(`${pc3.yellow(pc3.bold(name))} points to ${pc3.red(binPath)}`);
752
757
  }
@@ -886,10 +891,10 @@ function unused(options = {}) {
886
891
  name: "unused",
887
892
  hooks: {
888
893
  onBuildDone: async (ctx) => {
889
- const { options: buildOptions, output, meta } = ctx;
894
+ const { options: buildOptions, meta, files } = ctx;
890
895
  if (buildOptions.watch)
891
896
  return;
892
- const usedDeps = await collectUsedDependencies(output.files, buildOptions);
897
+ const usedDeps = await collectUsedDependencies(files, buildOptions);
893
898
  const pkgDeps = extractPackageDependencies(meta.packageJson.data?.dependencies);
894
899
  const unusedDeps = findUnusedDependencies(pkgDeps, usedDeps, ignore);
895
900
  const misplacedTypes = findMisplacedTypes(pkgDeps, usedDeps, ignore);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bunup",
3
3
  "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
- "version": "0.15.4",
4
+ "version": "0.15.6",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -50,8 +50,8 @@
50
50
  "type-check": "tsc --noEmit"
51
51
  },
52
52
  "dependencies": {
53
- "@bunup/dts": "^0.14.29",
54
- "@bunup/shared": "0.15.2",
53
+ "@bunup/dts": "^0.14.32",
54
+ "@bunup/shared": "0.15.4",
55
55
  "chokidar": "^4.0.3",
56
56
  "coffi": "^0.1.37",
57
57
  "lightningcss": "^1.30.2",
@@ -69,6 +69,6 @@
69
69
  }
70
70
  },
71
71
  "devDependencies": {
72
- "@types/bun": "^1.2.23"
72
+ "@types/bun": "^1.3.0"
73
73
  }
74
74
  }