bunup 0.14.21 → 0.15.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/dist/cli/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  build,
5
5
  processLoadedConfigs,
6
6
  resolveBuildOptions
7
- } from "../shared/bunup-3cppvv1c.js";
7
+ } from "../shared/bunup-04me8aq6.js";
8
8
  import {
9
9
  BunupCLIError,
10
10
  BunupWatchError,
@@ -20,13 +20,13 @@ import {
20
20
  logTime,
21
21
  logger,
22
22
  parseErrorMessage
23
- } from "../shared/bunup-b5xfnqft.js";
23
+ } from "../shared/bunup-wssv441a.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.14.21";
29
+ var version = "0.15.1";
30
30
 
31
31
  // packages/bunup/src/printer/print-build-report.ts
32
32
  import { promisify } from "util";
@@ -250,7 +250,9 @@ var program = cli().name("bunup").version(version).description("A blazing-fast b
250
250
  entry: z.union(z.string().describe("Single entrypoint for declaration file generation"), z.array(z.string()).describe("Multiple entrypoints for declaration file generation")).optional(),
251
251
  resolve: z.union(z.boolean().describe("Resolve types from dependencies"), z.array(z.string()).describe("Names or patterns of packages from which to resolve types")).optional(),
252
252
  splitting: z.boolean().describe("Enable declaration file splitting").optional(),
253
- minify: z.boolean().describe("Minify generated declaration files").optional()
253
+ minify: z.boolean().describe("Minify generated declaration files").optional(),
254
+ "infer-types": z.boolean().describe("Use TypeScript compiler (tsc) for declarations generation (removes need for explicit type annotations)").optional(),
255
+ tsgo: z.boolean().describe("Use TypeScript's native compiler (tsgo), 10x faster than tsc (only applicable with inferTypes enabled)").optional()
254
256
  })).default(true)).option("preferred-tsconfig", z.string().describe("Path to a custom tsconfig.json file used for path resolution during both bundling and TypeScript declaration generation.").example("./tsconfig.build.json").optional()).option("sourcemap", z.union(z.boolean().describe("Generate a sourcemap (uses the inline type by default)"), z.string().choices(["none", "linked", "inline", "external"]).describe("Generate a sourcemap with a specific type")).optional()).option("define", z.object(z.string()).describe("Define global constants replaced at build time").example(`--define.PACKAGE_VERSION='"1.0.0"'`).optional()).option("env", z.union(z.string().choices(["inline", "disable"]).describe("inline: inject all, disable: inject none"), z.string().regex(/\*$/, "Environment prefix must end with *").describe("Inject env vars with this prefix").example("MYAPP_*").transform((val) => val), z.object(z.string()).describe("Explicit env var mapping").example('--env.NODE_ENV="production" --env.API_URL="https://api.example.com"')).optional()).option("banner", z.string().describe("Banner text added to the top of bundle files").optional()).option("footer", z.string().describe("Footer text added to the bottom of bundle files").optional()).option("drop", z.array(z.string()).describe("Remove function calls from bundle").example("--drop console,debugger").optional()).option("loader", z.object(z.string().choices([
255
257
  "js",
256
258
  "jsx",
@@ -277,9 +279,9 @@ var program = cli().name("bunup").version(version).description("A blazing-fast b
277
279
  "include-package-json": z.boolean().describe('Whether to include "./package.json" in exports field').default(true),
278
280
  all: z.boolean().describe("Whether to add wildcard export for deep imports").optional()
279
281
  })).describe("Configure automatic package.json exports generation").optional()).option("unused", z.union(z.boolean(), z.object({
280
- level: z.string().choices(["warn", "error"]).describe("The level of reporting for unused dependencies").default("warn"),
281
- ignore: z.array(z.string()).describe("Dependencies to ignore when checking for unused dependencies").optional()
282
- })).describe("Detect and report unused dependencies").optional()).option("css", z.object({
282
+ level: z.string().choices(["warn", "error"]).describe("The level of reporting for unused or incorrectly categorized dependencies").default("warn"),
283
+ ignore: z.array(z.string()).describe("Dependencies to ignore when checking").optional()
284
+ })).describe("Detect unused or incorrectly categorized dependencies").optional()).option("css", z.object({
283
285
  "typed-modules": z.boolean().describe("Generate TypeScript definitions for CSS modules").default(true),
284
286
  inject: z.union(z.boolean(), z.object({
285
287
  minify: z.boolean().describe("Whether to minify the styles being injected").optional()
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BuildContext, BuildMeta, BuildOptions, BuildOutput, BuildOutputFile, BunupPlugin, DefineConfigItem, DefineWorkspaceItem, WithOptional, WithRequired } from "./shared/bunup-9dy62rzf";
1
+ import { BuildContext, BuildMeta, BuildOptions, BuildOutput, BuildOutputFile, BunupPlugin, DefineConfigItem, DefineWorkspaceItem, WithOptional, WithRequired } from "./shared/bunup-zhf51h48";
2
2
  declare function build(userOptions: Partial<BuildOptions>, rootDir?: string): Promise<BuildOutput>;
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[];
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // @bun
2
2
  import {
3
3
  build
4
- } from "./shared/bunup-3cppvv1c.js";
5
- import"./shared/bunup-b5xfnqft.js";
4
+ } from "./shared/bunup-04me8aq6.js";
5
+ import"./shared/bunup-wssv441a.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-9dy62rzf";
1
+ import { BuildOptions, BunupPlugin, BunupPluginHooks, exports, injectStyles, unused } from "./shared/bunup-zhf51h48";
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-b5xfnqft.js";
10
+ } from "./shared/bunup-wssv441a.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-b5xfnqft.js";
23
+ } from "./bunup-wssv441a.js";
24
24
 
25
25
  // packages/bunup/src/loaders.ts
26
26
  import path from "path";
@@ -113,7 +113,7 @@ async function executeOnSuccess(onSuccess, options, signal) {
113
113
  }
114
114
  }
115
115
 
116
- // packages/bunup/src/plugins/internal/css-typed-modules.ts
116
+ // packages/bunup/src/plugins/css-typed-modules.ts
117
117
  import { transform } from "lightningcss";
118
118
  function cssTypedModulesPlugin() {
119
119
  return {
@@ -68,13 +68,22 @@ class Logger {
68
68
  muted = false,
69
69
  tick = false,
70
70
  type = "info",
71
- noIcon = false
71
+ noIcon = false,
72
+ leftPadding
72
73
  } = options;
73
74
  const icon = noIcon ? "" : options.icon ?? this.getIcon(type, tick);
74
75
  const styledMessage = muted ? pc.dim(message) : type === "error" ? pc.red(message) : type === "warn" ? pc.yellow(message) : message;
75
76
  const identifierPart = this.formatIdentifier(identifier);
76
77
  const iconPart = icon ? `${icon} ` : "";
77
- return `${iconPart}${styledMessage}${identifierPart}`;
78
+ const baseMessage = `${iconPart}${styledMessage}${identifierPart}`;
79
+ const paddingCount = leftPadding === true ? 2 : typeof leftPadding === "number" ? leftPadding : 0;
80
+ if (paddingCount > 0) {
81
+ const padding = " ".repeat(paddingCount);
82
+ return baseMessage.split(`
83
+ `).map((line) => `${padding}${line}`).join(`
84
+ `);
85
+ }
86
+ return baseMessage;
78
87
  }
79
88
  output(message, options = {}, logFn = console.log) {
80
89
  if (this.silent || !this.shouldLog(options)) {
@@ -125,10 +134,14 @@ class Logger {
125
134
  console.log("");
126
135
  }
127
136
  }
128
- log(...args) {
129
- if (!this.silent) {
130
- console.log(...args);
131
- }
137
+ log(message, options = {}) {
138
+ const formattedMessage = this.formatMessage({
139
+ ...options,
140
+ message,
141
+ type: "info",
142
+ noIcon: true
143
+ });
144
+ this.output(formattedMessage, options);
132
145
  }
133
146
  list(items, options) {
134
147
  return items.map((item) => {
@@ -295,9 +308,7 @@ var handleError = (error, context) => {
295
308
  logger.error(`
296
309
  ${pc2.bgRed(` ${errorType} `)}
297
310
 
298
- ${contextPrefix}${errorMessage}`.split(`
299
- `).map((line) => pc2.white(` ${line}`)).join(`
300
- `), { noIcon: true });
311
+ ${contextPrefix}${errorMessage}`, { noIcon: true, leftPadding: true });
301
312
  }
302
313
  if (knownError) {
303
314
  logger.space();
@@ -837,59 +848,92 @@ function unused(options = {}) {
837
848
  hooks: {
838
849
  onBuildDone: async (ctx) => {
839
850
  const { options: buildOptions, output, meta } = ctx;
840
- if (buildOptions.watch) {
851
+ if (buildOptions.watch)
841
852
  return;
842
- }
843
- const transpiler = new Bun.Transpiler({
844
- loader: "js"
845
- });
846
- const jsFiles = output.files.filter((file) => isJavascriptFile(file.fullPath));
847
- const packageDependencies = typeof meta.packageJson.data?.dependencies === "object" ? meta.packageJson.data.dependencies : {};
848
- const externals = [
849
- ...buildOptions.external ?? [],
850
- ...buildOptions.noExternal ?? []
851
- ];
852
- const allImportPaths = new Set;
853
- for (const file of jsFiles) {
854
- const code = await Bun.file(file.fullPath).text();
855
- const codeWithoutShebang = code.replace(/^#!.*$/m, "");
856
- const importPaths = transpiler.scanImports(codeWithoutShebang).map((imp) => imp.path);
857
- for (const importPath of importPaths) {
858
- if (externals.some((ex) => typeof ex === "string" ? importPath.startsWith(ex) : ex.test(importPath)))
859
- continue;
860
- if (importPath.startsWith("node:") || importPath.startsWith("bun:"))
861
- continue;
862
- allImportPaths.add(importPath);
863
- }
864
- }
865
- const allDependencies = Object.keys(packageDependencies);
866
- const unusedDependencies = allDependencies.filter((dependency) => {
867
- if (ignore.includes(dependency))
868
- return false;
869
- return !Array.from(allImportPaths).some((importPath) => importPath === dependency || importPath.startsWith(`${dependency}/`));
870
- });
871
- if (unusedDependencies.length > 0) {
872
- const count = unusedDependencies.length;
873
- const depText = count === 1 ? "dependency" : "dependencies";
874
- const coloredDeps = formatListWithAnd(unusedDependencies.map((dep) => pc3.yellow(dep)));
875
- const removeCommand = pc3.cyan(`bun remove ${unusedDependencies.join(" ")}`);
876
- const message = [
877
- `
878
- Your project${buildOptions.name ? ` ${buildOptions.name}` : ""} has ${count} unused ${depText}: ${coloredDeps}.`,
879
- `You can remove ${count === 1 ? "it" : "them"} with ${removeCommand}`,
880
- `or move to devDependencies if you are using ${count === 1 ? "it" : "them"} only for types.`
881
- ].join(" ");
882
- if (level === "error") {
883
- logger.log(pc3.red(message));
884
- process.exit(1);
885
- } else {
886
- logger.log(message);
887
- }
888
- }
853
+ const usedDeps = await collectUsedDependencies(output.files, buildOptions);
854
+ const pkgDeps = extractPackageDependencies(meta.packageJson.data?.dependencies);
855
+ const unusedDeps = findUnusedDependencies(pkgDeps, usedDeps, ignore);
856
+ const misplacedTypes = findMisplacedTypes(pkgDeps, usedDeps, ignore);
857
+ reportIssues(unusedDeps, misplacedTypes, buildOptions.name, level);
889
858
  }
890
859
  }
891
860
  };
892
861
  }
862
+ async function collectUsedDependencies(files, buildOptions) {
863
+ const transpiler = new Bun.Transpiler({ loader: "ts" });
864
+ const externals = [
865
+ ...buildOptions.external ?? [],
866
+ ...buildOptions.noExternal ?? []
867
+ ];
868
+ const usedDeps = new Set;
869
+ const jsFiles = files.filter((f) => isJavascriptFile(f.fullPath) || isTypeScriptFile(f.fullPath));
870
+ for (const file of jsFiles) {
871
+ const code = (await Bun.file(file.fullPath).text()).replace(/^#!.*$/m, "");
872
+ const imports = transpiler.scanImports(code).map((imp) => imp.path);
873
+ for (const path4 of imports) {
874
+ if (isExternal(path4, externals) || isBuiltin(path4))
875
+ continue;
876
+ usedDeps.add(path4);
877
+ }
878
+ }
879
+ return usedDeps;
880
+ }
881
+ function isExternal(path4, externals) {
882
+ return externals.some((ex) => typeof ex === "string" ? path4.startsWith(ex) : ex.test(path4));
883
+ }
884
+ function isBuiltin(path4) {
885
+ return path4.startsWith("node:") || path4.startsWith("bun:");
886
+ }
887
+ function extractPackageDependencies(deps) {
888
+ return typeof deps === "object" ? Object.keys(deps) : [];
889
+ }
890
+ function findUnusedDependencies(allDeps, usedDeps, ignore) {
891
+ return allDeps.filter((dep) => {
892
+ if (ignore.includes(dep))
893
+ return false;
894
+ return !Array.from(usedDeps).some((used) => used === dep || used.startsWith(`${dep}/`));
895
+ });
896
+ }
897
+ function findMisplacedTypes(allDeps, usedDeps, ignore) {
898
+ return allDeps.filter((dep) => {
899
+ if (!dep.startsWith("@types/"))
900
+ return false;
901
+ if (ignore.includes(dep))
902
+ return false;
903
+ return !Array.from(usedDeps).some((used) => used === dep || used.startsWith(`${dep}/`));
904
+ });
905
+ }
906
+ function reportIssues(unused2, misplaced, projectName, level) {
907
+ reportIssue(unused2, "unused", projectName, level);
908
+ reportIssue(misplaced, "misplaced-types", projectName, level);
909
+ }
910
+ function reportIssue(deps, type, projectName, level) {
911
+ if (deps.length === 0)
912
+ return;
913
+ const count = deps.length;
914
+ const coloredDeps = formatListWithAnd(deps.map((d) => pc3.yellow(d)));
915
+ const project = projectName ? ` ${projectName}` : "";
916
+ const message = buildMessage(type, count, coloredDeps, project, deps);
917
+ if (level === "error") {
918
+ logger.log(pc3.red(message), { leftPadding: true });
919
+ process.exit(1);
920
+ } else {
921
+ logger.log(message, { leftPadding: true });
922
+ }
923
+ }
924
+ function buildMessage(type, count, coloredDeps, project, deps) {
925
+ const plural = count === 1 ? "it" : "them";
926
+ if (type === "unused") {
927
+ const depText2 = count === 1 ? "dependency" : "dependencies";
928
+ const cmd2 = pc3.cyan(`bun remove ${deps.join(" ")}`);
929
+ return `
930
+ Your project${project} has ${count} unused ${depText2}: ${coloredDeps}. You can remove ${plural} with ${cmd2}`;
931
+ }
932
+ const depText = count === 1 ? "package" : "packages";
933
+ const cmd = pc3.cyan(`bun remove ${deps.join(" ")} && bun add --dev ${deps.join(" ")}`);
934
+ return `
935
+ Your project${project} has ${count} type ${depText} that should be in devDependencies: ${coloredDeps}. Move ${plural} to devDependencies with ${cmd}`;
936
+ }
893
937
 
894
938
  // packages/bunup/src/utils/common.ts
895
939
  function ensureArray(value) {
@@ -171,18 +171,19 @@ type InjectStylesOptions = {
171
171
  declare function injectStyles(options?: InjectStylesOptions): BunPlugin;
172
172
  interface UnusedOptions {
173
173
  /**
174
- * The level of reporting for unused dependencies
174
+ * The level of reporting for unused or incorrectly categorized dependencies
175
175
  * @default 'warn'
176
176
  */
177
177
  level?: "warn" | "error";
178
178
  /**
179
- * Dependencies to ignore when checking for unused dependencies
179
+ * Dependencies to ignore when checking
180
180
  * @default []
181
181
  */
182
182
  ignore?: string[];
183
183
  }
184
184
  /**
185
- * A plugin that detects and reports unused dependencies.
185
+ * Detects and reports unused or incorrectly categorized dependencies in your project,
186
+ * helping you maintain a clean dependency tree and keep your `package.json` up to date.
186
187
  *
187
188
  * @see https://bunup.dev/docs/extra-options/unused
188
189
  */
@@ -368,7 +369,7 @@ interface BuildOptions {
368
369
  * When set to true, generates declaration files for all entry points
369
370
  * Can also be configured with GenerateDtsOptions for more control
370
371
  */
371
- dts?: boolean | (Pick<GenerateDtsOptions, "resolve" | "splitting" | "minify"> & {
372
+ dts?: boolean | (Pick<GenerateDtsOptions, "resolve" | "splitting" | "minify" | "inferTypes" | "tsgo"> & {
372
373
  entry?: string | string[];
373
374
  });
374
375
  /**
@@ -618,11 +619,9 @@ interface BuildOptions {
618
619
  */
619
620
  exports?: boolean | ExportsOptions;
620
621
  /**
621
- * Detect and report unused dependencies in your project.
622
- *
623
- * When `true`, enables unused dependency detection with default warning level.
624
- * When an object is provided, allows customization of the detection behavior,
625
- * including report level (warn/error) and dependencies to ignore.
622
+ * Detect and report dependencies that are unused or incorrectly categorized.
623
+ * This includes dependencies not used in your build output, as well as dependencies
624
+ * that don't need to be packed with your library.
626
625
  *
627
626
  * @see https://bunup.dev/docs/extra-options/unused
628
627
  */
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.14.21",
4
+ "version": "0.15.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -50,15 +50,15 @@
50
50
  "type-check": "tsc --noEmit"
51
51
  },
52
52
  "dependencies": {
53
- "@bunup/dts": "0.14.20",
53
+ "@bunup/dts": "^0.14.26",
54
+ "@bunup/shared": "0.15.0",
54
55
  "chokidar": "^4.0.3",
55
56
  "coffi": "^0.1.37",
56
57
  "lightningcss": "^1.30.2",
57
58
  "picocolors": "^1.1.1",
58
59
  "tinyexec": "^1.0.1",
59
60
  "tree-kill": "^1.2.2",
60
- "zlye": "^0.4.4",
61
- "@bunup/shared": "0.14.20"
61
+ "zlye": "^0.4.4"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "typescript": "latest"