bunup 0.8.36 → 0.8.37

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.
@@ -104,6 +104,9 @@ function getResolvedDefine(define, env) {
104
104
  function getResolvedSplitting(splitting, format) {
105
105
  return splitting === undefined ? format === "esm" : splitting;
106
106
  }
107
+ function getResolvedDtsSplitting(splitting) {
108
+ return splitting ?? true;
109
+ }
107
110
  var DEFAULT_ENTRY_NAMING = "[dir]/[name].[ext]";
108
111
  function getResolvedNaming(fmt, packageType) {
109
112
  const replaceExt = (pattern) => pattern.replace(".[ext]", getDefaultOutputExtension(fmt, packageType));
@@ -228,10 +231,11 @@ async function build(partialOptions, rootDir = process.cwd()) {
228
231
  });
229
232
  await Promise.all(buildPromises);
230
233
  if (options.dts) {
231
- const { entry, ...dtsOptions } = typeof options.dts === "object" ? options.dts : {};
234
+ const { entry, splitting, ...dtsOptions } = typeof options.dts === "object" ? options.dts : {};
232
235
  const dtsResult = await generateDts(ensureArray(entry ?? entrypoints), {
233
236
  cwd: rootDir,
234
237
  preferredTsConfigPath: options.preferredTsconfigPath,
238
+ splitting: getResolvedDtsSplitting(splitting),
235
239
  ...dtsOptions
236
240
  });
237
241
  if (dtsResult.errors.length) {
package/dist/cli/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  build,
5
5
  createBuildOptions
6
- } from "../chunk-vh9fpy39.js";
6
+ } from "../chunk-phd7cn7e.js";
7
7
  import"../chunk-w13gdbvp.js";
8
8
  import {
9
9
  processLoadedConfigs
@@ -26,7 +26,7 @@ import {
26
26
  // src/cli/index.ts
27
27
  import { exec } from "tinyexec";
28
28
  // package.json
29
- var version = "0.8.36";
29
+ var version = "0.8.37";
30
30
 
31
31
  // src/cli/options.ts
32
32
  import pc from "picocolors";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,327 @@
1
- import { Arrayable, BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin } from "./chunk-589998ak";
1
+ import { BuildConfig } from "bun";
2
+ import { DtsPluginOptions } from "bun-dts";
3
+ import { BunPlugin } from "bun";
4
+ type PackageJson = {
5
+ /** The parsed content of the package.json file */
6
+ data: Record<string, any> | null
7
+ /** The path to the package.json file */
8
+ path: string | null
9
+ };
10
+ /**
11
+ * Represents a Bun plugin that can be used with Bunup
12
+ */
13
+ type BunupBunPlugin = {
14
+ /** Identifies this as a native Bun plugin */
15
+ type: "bun"
16
+ /** Optional name for the plugin */
17
+ name?: string
18
+ /** The actual Bun plugin implementation */
19
+ plugin: BunPlugin
20
+ };
21
+ /**
22
+ * Represents the meta data of the build
23
+ */
24
+ type BuildMeta = {
25
+ /** The package.json file */
26
+ packageJson: PackageJson
27
+ /** The root directory of the build */
28
+ rootDir: string
29
+ };
30
+ type BuildOutputFile = {
31
+ /** The kind of the file */
32
+ kind: "entry-point" | "chunk" | "asset" | "sourcemap" | "bytecode"
33
+ /** Path to the generated file */
34
+ fullPath: string
35
+ /** Path to the generated file relative to the root directory */
36
+ relativePathToRootDir: string
37
+ /** Path to the generated file relative to the output directory */
38
+ relativePathToOutputDir: string
39
+ /** Whether the file is a dts file */
40
+ dts: boolean
41
+ /** The format of the output file */
42
+ format: Format
43
+ };
44
+ /**
45
+ * Represents the output of a build operation
46
+ */
47
+ type BuildOutput = {
48
+ /** Array of generated files with their paths and contents */
49
+ files: BuildOutputFile[]
50
+ };
51
+ /**
52
+ * Context provided to build hooks
53
+ */
54
+ type BuildContext = {
55
+ /** The build options that were used */
56
+ options: BuildOptions
57
+ /** The output of the build */
58
+ output: BuildOutput
59
+ /** The meta data of the build */
60
+ meta: BuildMeta
61
+ };
62
+ /**
63
+ * Hooks that can be implemented by Bunup plugins
64
+ */
65
+ type BunupPluginHooks = {
66
+ /**
67
+ * Called when a build is successfully completed
68
+ * @param ctx Build context containing options and output
69
+ */
70
+ onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
71
+ /**
72
+ * Called before a build starts
73
+ * @param options Build options that will be used
74
+ */
75
+ onBuildStart?: (options: BuildOptions) => MaybePromise<void>
76
+ };
77
+ /**
78
+ * Represents a Bunup-specific plugin
79
+ */
80
+ type BunupPlugin = {
81
+ /** Identifies this as a Bunup-specific plugin */
82
+ type: "bunup"
83
+ /** Optional name for the plugin */
84
+ name?: string
85
+ /** The hooks implemented by this plugin */
86
+ hooks: BunupPluginHooks
87
+ };
88
+ /**
89
+ * Union type representing all supported plugin types
90
+ */
91
+ type Plugin = BunupBunPlugin | BunupPlugin;
92
+ type Loader = NonNullable<BuildConfig["loader"]>[string];
93
+ type Define = BuildConfig["define"];
94
+ type Sourcemap = BuildConfig["sourcemap"];
95
+ type Format = Exclude<BuildConfig["format"], undefined>;
96
+ type Target = BuildConfig["target"];
97
+ type External = (string | RegExp)[];
98
+ type Env = BuildConfig["env"] | Record<string, string>;
99
+ interface BuildOptions {
100
+ /**
101
+ * Name of the build configuration
102
+ * Used for logging and identification purposes
103
+ */
104
+ name?: string;
105
+ /**
106
+ * Entry point files for the build
107
+ *
108
+ * This can be:
109
+ * - A string path to a file
110
+ * - An array of file paths
111
+ *
112
+ * @see https://bunup.dev/docs/#entry-points
113
+ */
114
+ entry: string | string[];
115
+ /**
116
+ * Output directory for the bundled files
117
+ * Defaults to 'dist' if not specified
118
+ */
119
+ outDir: string;
120
+ /**
121
+ * Output formats for the bundle
122
+ * Can include 'esm', 'cjs', and/or 'iife'
123
+ * Defaults to ['cjs'] if not specified
124
+ */
125
+ format: Format[];
126
+ /**
127
+ * Whether to enable all minification options
128
+ * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
129
+ */
130
+ minify?: boolean;
131
+ /**
132
+ * Whether to enable code splitting
133
+ * Defaults to true for ESM format, false for CJS format
134
+ */
135
+ splitting?: boolean;
136
+ /**
137
+ * Whether to minify whitespace in the output
138
+ * Removes unnecessary whitespace to reduce file size
139
+ */
140
+ minifyWhitespace?: boolean;
141
+ /**
142
+ * Whether to minify identifiers in the output
143
+ * Renames variables and functions to shorter names
144
+ */
145
+ minifyIdentifiers?: boolean;
146
+ /**
147
+ * Whether to minify syntax in the output
148
+ * Optimizes code structure for smaller file size
149
+ */
150
+ minifySyntax?: boolean;
151
+ /**
152
+ * Whether to watch for file changes and rebuild automatically
153
+ */
154
+ watch?: boolean;
155
+ /**
156
+ * Whether to generate TypeScript declaration files (.d.ts)
157
+ * When set to true, generates declaration files for all entry points
158
+ * Can also be configured with DtsOptions for more control
159
+ */
160
+ dts?: boolean | Pick<DtsPluginOptions, "entry" | "resolve" | "splitting" | "minify">;
161
+ /**
162
+ * Path to a preferred tsconfig.json file to use for declaration generation
163
+ *
164
+ * If not specified, the tsconfig.json in the project root will be used.
165
+ * This option allows you to use a different TypeScript configuration
166
+ * specifically for declaration file generation.
167
+ *
168
+ * @example
169
+ * preferredTsconfigPath: './tsconfig.build.json'
170
+ */
171
+ preferredTsconfigPath?: string;
172
+ /**
173
+ * External packages that should not be bundled
174
+ * Useful for dependencies that should be kept as external imports
175
+ */
176
+ external?: External;
177
+ /**
178
+ * Packages that should be bundled even if they are in external
179
+ * Useful for dependencies that should be included in the bundle
180
+ */
181
+ noExternal?: External;
182
+ /**
183
+ * The target environment for the bundle
184
+ * Can be 'browser', 'bun', 'node', etc.
185
+ * Defaults to 'node' if not specified
186
+ */
187
+ target?: Target;
188
+ /**
189
+ * Whether to clean the output directory before building
190
+ * When true, removes all files in the outDir before starting a new build
191
+ * Defaults to true if not specified
192
+ */
193
+ clean?: boolean;
194
+ /**
195
+ * Specifies the type of sourcemap to generate
196
+ * Can be 'none', 'linked', 'external', or 'inline'
197
+ * Can also be a boolean - when true, it will use 'inline'
198
+ *
199
+ * @see https://bun.sh/docs/bundler#sourcemap
200
+ *
201
+ * @default 'none'
202
+ *
203
+ * @example
204
+ * sourcemap: 'linked'
205
+ * // or
206
+ * sourcemap: true // equivalent to 'inline'
207
+ */
208
+ sourcemap?: Sourcemap;
209
+ define?: Define;
210
+ /**
211
+ * A callback function that runs after the build process completes
212
+ * This can be used for custom post-build operations like copying files,
213
+ * running additional tools, or logging build information
214
+ *
215
+ * If watch mode is enabled, this callback runs after each rebuild
216
+ *
217
+ * @param options The build options that were used
218
+ */
219
+ onSuccess?: (options: Partial<BuildOptions>) => MaybePromise<void>;
220
+ banner?: string;
221
+ /**
222
+ * A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
223
+ *
224
+ * @see https://bun.sh/docs/bundler#footer
225
+ *
226
+ * @example
227
+ * footer: '// built with love in SF'
228
+ */
229
+ footer?: string;
230
+ /**
231
+ * Remove function calls from a bundle. For example, `drop: ["console"]` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
232
+ *
233
+ * @see https://bun.sh/docs/bundler#drop
234
+ *
235
+ * @example
236
+ * drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
237
+ */
238
+ drop?: string[];
239
+ /**
240
+ * A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
241
+ *
242
+ * @see https://bun.sh/docs/bundler#loader
243
+ *
244
+ * @example
245
+ * loader: {
246
+ * ".png": "dataurl",
247
+ * ".txt": "file",
248
+ * }
249
+ */
250
+ loader?: Record<string, Loader>;
251
+ /**
252
+ * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
253
+ *
254
+ * Bytecode is currently only supported for CommonJS (format: "cjs").
255
+ *
256
+ * Must be target: "bun"
257
+ *
258
+ * @see https://bun.sh/docs/bundler#bytecode
259
+ *
260
+ * @default false
261
+ */
262
+ bytecode?: boolean;
263
+ /**
264
+ * Disable logging during the build process. When set to true, no logs will be printed to the console.
265
+ *
266
+ * @default false
267
+ */
268
+ silent?: boolean;
269
+ /**
270
+ * You can specify a prefix to be added to specific import paths in your bundled code
271
+ *
272
+ * Used for assets, external modules, and chunk files when splitting is enabled
273
+ *
274
+ * @see https://bunup.dev/docs#public-path for more information
275
+ *
276
+ * @example
277
+ * publicPath: 'https://cdn.example.com/'
278
+ */
279
+ publicPath?: string;
280
+ /**
281
+ * Controls how environment variables are handled during bundling.
282
+ *
283
+ * Can be one of:
284
+ * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
285
+ * of those environment variables at the time the build runs.
286
+ * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
287
+ * - A string ending in `*`: Only inlines environment variables matching the given prefix.
288
+ * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
289
+ * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
290
+ * with the provided values, regardless of the runtime environment.
291
+ *
292
+ * Note: Values are injected at build time. Secrets or private keys should be excluded
293
+ * from inlining when targeting browser environments.
294
+ *
295
+ * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
296
+ *
297
+ * @example
298
+ * // Inline all environment variables available at build time
299
+ * env: "inline"
300
+ *
301
+ * // Disable all environment variable injection
302
+ * env: "disable"
303
+ *
304
+ * // Only inline environment variables with a specific prefix
305
+ * env: "PUBLIC_*"
306
+ *
307
+ * // Provide specific environment variables manually
308
+ * env: { API_URL: "https://api.example.com", DEBUG: "false" }
309
+ */
310
+ env?: Env;
311
+ plugins?: Plugin[];
312
+ }
313
+ type MaybePromise<T> = Promise<T> | T;
314
+ type WithOptional<
315
+ T,
316
+ K extends keyof T
317
+ > = Omit<T, K> & Partial<Pick<T, K>>;
318
+ type Arrayable<T> = T | T[];
319
+ type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
320
+ type DefineWorkspaceItem = {
321
+ name: string
322
+ root: string
323
+ config: DefineConfigItem | DefineConfigItem[]
324
+ };
2
325
  declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
3
326
  declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
4
327
  declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  build
4
- } from "./chunk-vh9fpy39.js";
4
+ } from "./chunk-phd7cn7e.js";
5
5
  import"./chunk-w13gdbvp.js";
6
6
  import"./chunk-gh7z7s46.js";
7
7
  import"./chunk-ka4kbkdd.js";
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,316 @@
1
- import { BunupPlugin, MaybePromise, Plugin } from "./chunk-589998ak";
1
+ import { BunPlugin } from "bun";
2
+ import { BuildConfig } from "bun";
3
+ import { DtsPluginOptions } from "bun-dts";
4
+ type Loader = NonNullable<BuildConfig["loader"]>[string];
5
+ type Define = BuildConfig["define"];
6
+ type Sourcemap = BuildConfig["sourcemap"];
7
+ type Format = Exclude<BuildConfig["format"], undefined>;
8
+ type Target = BuildConfig["target"];
9
+ type External = (string | RegExp)[];
10
+ type Env = BuildConfig["env"] | Record<string, string>;
11
+ interface BuildOptions {
12
+ /**
13
+ * Name of the build configuration
14
+ * Used for logging and identification purposes
15
+ */
16
+ name?: string;
17
+ /**
18
+ * Entry point files for the build
19
+ *
20
+ * This can be:
21
+ * - A string path to a file
22
+ * - An array of file paths
23
+ *
24
+ * @see https://bunup.dev/docs/#entry-points
25
+ */
26
+ entry: string | string[];
27
+ /**
28
+ * Output directory for the bundled files
29
+ * Defaults to 'dist' if not specified
30
+ */
31
+ outDir: string;
32
+ /**
33
+ * Output formats for the bundle
34
+ * Can include 'esm', 'cjs', and/or 'iife'
35
+ * Defaults to ['cjs'] if not specified
36
+ */
37
+ format: Format[];
38
+ /**
39
+ * Whether to enable all minification options
40
+ * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
41
+ */
42
+ minify?: boolean;
43
+ /**
44
+ * Whether to enable code splitting
45
+ * Defaults to true for ESM format, false for CJS format
46
+ */
47
+ splitting?: boolean;
48
+ /**
49
+ * Whether to minify whitespace in the output
50
+ * Removes unnecessary whitespace to reduce file size
51
+ */
52
+ minifyWhitespace?: boolean;
53
+ /**
54
+ * Whether to minify identifiers in the output
55
+ * Renames variables and functions to shorter names
56
+ */
57
+ minifyIdentifiers?: boolean;
58
+ /**
59
+ * Whether to minify syntax in the output
60
+ * Optimizes code structure for smaller file size
61
+ */
62
+ minifySyntax?: boolean;
63
+ /**
64
+ * Whether to watch for file changes and rebuild automatically
65
+ */
66
+ watch?: boolean;
67
+ /**
68
+ * Whether to generate TypeScript declaration files (.d.ts)
69
+ * When set to true, generates declaration files for all entry points
70
+ * Can also be configured with DtsOptions for more control
71
+ */
72
+ dts?: boolean | Pick<DtsPluginOptions, "entry" | "resolve" | "splitting" | "minify">;
73
+ /**
74
+ * Path to a preferred tsconfig.json file to use for declaration generation
75
+ *
76
+ * If not specified, the tsconfig.json in the project root will be used.
77
+ * This option allows you to use a different TypeScript configuration
78
+ * specifically for declaration file generation.
79
+ *
80
+ * @example
81
+ * preferredTsconfigPath: './tsconfig.build.json'
82
+ */
83
+ preferredTsconfigPath?: string;
84
+ /**
85
+ * External packages that should not be bundled
86
+ * Useful for dependencies that should be kept as external imports
87
+ */
88
+ external?: External;
89
+ /**
90
+ * Packages that should be bundled even if they are in external
91
+ * Useful for dependencies that should be included in the bundle
92
+ */
93
+ noExternal?: External;
94
+ /**
95
+ * The target environment for the bundle
96
+ * Can be 'browser', 'bun', 'node', etc.
97
+ * Defaults to 'node' if not specified
98
+ */
99
+ target?: Target;
100
+ /**
101
+ * Whether to clean the output directory before building
102
+ * When true, removes all files in the outDir before starting a new build
103
+ * Defaults to true if not specified
104
+ */
105
+ clean?: boolean;
106
+ /**
107
+ * Specifies the type of sourcemap to generate
108
+ * Can be 'none', 'linked', 'external', or 'inline'
109
+ * Can also be a boolean - when true, it will use 'inline'
110
+ *
111
+ * @see https://bun.sh/docs/bundler#sourcemap
112
+ *
113
+ * @default 'none'
114
+ *
115
+ * @example
116
+ * sourcemap: 'linked'
117
+ * // or
118
+ * sourcemap: true // equivalent to 'inline'
119
+ */
120
+ sourcemap?: Sourcemap;
121
+ define?: Define;
122
+ /**
123
+ * A callback function that runs after the build process completes
124
+ * This can be used for custom post-build operations like copying files,
125
+ * running additional tools, or logging build information
126
+ *
127
+ * If watch mode is enabled, this callback runs after each rebuild
128
+ *
129
+ * @param options The build options that were used
130
+ */
131
+ onSuccess?: (options: Partial<BuildOptions>) => MaybePromise<void>;
132
+ banner?: string;
133
+ /**
134
+ * A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
135
+ *
136
+ * @see https://bun.sh/docs/bundler#footer
137
+ *
138
+ * @example
139
+ * footer: '// built with love in SF'
140
+ */
141
+ footer?: string;
142
+ /**
143
+ * Remove function calls from a bundle. For example, `drop: ["console"]` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
144
+ *
145
+ * @see https://bun.sh/docs/bundler#drop
146
+ *
147
+ * @example
148
+ * drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
149
+ */
150
+ drop?: string[];
151
+ /**
152
+ * A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
153
+ *
154
+ * @see https://bun.sh/docs/bundler#loader
155
+ *
156
+ * @example
157
+ * loader: {
158
+ * ".png": "dataurl",
159
+ * ".txt": "file",
160
+ * }
161
+ */
162
+ loader?: Record<string, Loader>;
163
+ /**
164
+ * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
165
+ *
166
+ * Bytecode is currently only supported for CommonJS (format: "cjs").
167
+ *
168
+ * Must be target: "bun"
169
+ *
170
+ * @see https://bun.sh/docs/bundler#bytecode
171
+ *
172
+ * @default false
173
+ */
174
+ bytecode?: boolean;
175
+ /**
176
+ * Disable logging during the build process. When set to true, no logs will be printed to the console.
177
+ *
178
+ * @default false
179
+ */
180
+ silent?: boolean;
181
+ /**
182
+ * You can specify a prefix to be added to specific import paths in your bundled code
183
+ *
184
+ * Used for assets, external modules, and chunk files when splitting is enabled
185
+ *
186
+ * @see https://bunup.dev/docs#public-path for more information
187
+ *
188
+ * @example
189
+ * publicPath: 'https://cdn.example.com/'
190
+ */
191
+ publicPath?: string;
192
+ /**
193
+ * Controls how environment variables are handled during bundling.
194
+ *
195
+ * Can be one of:
196
+ * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
197
+ * of those environment variables at the time the build runs.
198
+ * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
199
+ * - A string ending in `*`: Only inlines environment variables matching the given prefix.
200
+ * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
201
+ * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
202
+ * with the provided values, regardless of the runtime environment.
203
+ *
204
+ * Note: Values are injected at build time. Secrets or private keys should be excluded
205
+ * from inlining when targeting browser environments.
206
+ *
207
+ * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
208
+ *
209
+ * @example
210
+ * // Inline all environment variables available at build time
211
+ * env: "inline"
212
+ *
213
+ * // Disable all environment variable injection
214
+ * env: "disable"
215
+ *
216
+ * // Only inline environment variables with a specific prefix
217
+ * env: "PUBLIC_*"
218
+ *
219
+ * // Provide specific environment variables manually
220
+ * env: { API_URL: "https://api.example.com", DEBUG: "false" }
221
+ */
222
+ env?: Env;
223
+ plugins?: Plugin[];
224
+ }
225
+ type MaybePromise<T> = Promise<T> | T;
226
+ type PackageJson = {
227
+ /** The parsed content of the package.json file */
228
+ data: Record<string, any> | null
229
+ /** The path to the package.json file */
230
+ path: string | null
231
+ };
232
+ /**
233
+ * Represents a Bun plugin that can be used with Bunup
234
+ */
235
+ type BunupBunPlugin = {
236
+ /** Identifies this as a native Bun plugin */
237
+ type: "bun"
238
+ /** Optional name for the plugin */
239
+ name?: string
240
+ /** The actual Bun plugin implementation */
241
+ plugin: BunPlugin
242
+ };
243
+ /**
244
+ * Represents the meta data of the build
245
+ */
246
+ type BuildMeta = {
247
+ /** The package.json file */
248
+ packageJson: PackageJson
249
+ /** The root directory of the build */
250
+ rootDir: string
251
+ };
252
+ type BuildOutputFile = {
253
+ /** The kind of the file */
254
+ kind: "entry-point" | "chunk" | "asset" | "sourcemap" | "bytecode"
255
+ /** Path to the generated file */
256
+ fullPath: string
257
+ /** Path to the generated file relative to the root directory */
258
+ relativePathToRootDir: string
259
+ /** Path to the generated file relative to the output directory */
260
+ relativePathToOutputDir: string
261
+ /** Whether the file is a dts file */
262
+ dts: boolean
263
+ /** The format of the output file */
264
+ format: Format
265
+ };
266
+ /**
267
+ * Represents the output of a build operation
268
+ */
269
+ type BuildOutput = {
270
+ /** Array of generated files with their paths and contents */
271
+ files: BuildOutputFile[]
272
+ };
273
+ /**
274
+ * Context provided to build hooks
275
+ */
276
+ type BuildContext = {
277
+ /** The build options that were used */
278
+ options: BuildOptions
279
+ /** The output of the build */
280
+ output: BuildOutput
281
+ /** The meta data of the build */
282
+ meta: BuildMeta
283
+ };
284
+ /**
285
+ * Hooks that can be implemented by Bunup plugins
286
+ */
287
+ type BunupPluginHooks = {
288
+ /**
289
+ * Called when a build is successfully completed
290
+ * @param ctx Build context containing options and output
291
+ */
292
+ onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
293
+ /**
294
+ * Called before a build starts
295
+ * @param options Build options that will be used
296
+ */
297
+ onBuildStart?: (options: BuildOptions) => MaybePromise<void>
298
+ };
299
+ /**
300
+ * Represents a Bunup-specific plugin
301
+ */
302
+ type BunupPlugin = {
303
+ /** Identifies this as a Bunup-specific plugin */
304
+ type: "bunup"
305
+ /** Optional name for the plugin */
306
+ name?: string
307
+ /** The hooks implemented by this plugin */
308
+ hooks: BunupPluginHooks
309
+ };
310
+ /**
311
+ * Union type representing all supported plugin types
312
+ */
313
+ type Plugin = BunupBunPlugin | BunupPlugin;
2
314
  /**
3
315
  * A plugin that provides shims for Node.js globals and ESM/CJS interoperability.
4
316
  */
package/package.json CHANGED
@@ -1,22 +1,21 @@
1
1
  {
2
2
  "name": "bunup",
3
3
  "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
- "version": "0.8.36",
4
+ "version": "0.8.37",
5
5
  "type": "module",
6
6
  "files": [
7
- "dist",
8
- "bin"
7
+ "dist"
9
8
  ],
10
- "types": "./dist/index.d.ts",
11
9
  "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
12
11
  "exports": {
13
12
  ".": {
14
- "types": "./dist/index.d.ts",
15
- "import": "./dist/index.js"
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
16
15
  },
17
16
  "./plugins": {
18
- "types": "./dist/plugins.d.ts",
19
- "import": "./dist/plugins.js"
17
+ "import": "./dist/plugins.js",
18
+ "types": "./dist/plugins.d.ts"
20
19
  },
21
20
  "./cli": {
22
21
  "import": "./dist/cli/index.js"
@@ -43,7 +42,7 @@
43
42
  "bun-bundler"
44
43
  ],
45
44
  "bin": {
46
- "bunup": "bin/bunup.mjs"
45
+ "bunup": "dist/cli/index.js"
47
46
  },
48
47
  "dependencies": {
49
48
  "@clack/prompts": "^0.10.1",
package/bin/bunup.mjs DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- import '../dist/cli/index.js'
@@ -1,325 +0,0 @@
1
- import { BunPlugin } from "bun";
2
- import { BuildConfig } from "bun";
3
- import { DtsPluginOptions } from "bun-dts";
4
- type Loader = NonNullable<BuildConfig["loader"]>[string];
5
- type Define = BuildConfig["define"];
6
- type Sourcemap = BuildConfig["sourcemap"];
7
- type Format = Exclude<BuildConfig["format"], undefined>;
8
- type Target = BuildConfig["target"];
9
- type External = (string | RegExp)[];
10
- type Env = BuildConfig["env"] | Record<string, string>;
11
- interface BuildOptions {
12
- /**
13
- * Name of the build configuration
14
- * Used for logging and identification purposes
15
- */
16
- name?: string;
17
- /**
18
- * Entry point files for the build
19
- *
20
- * This can be:
21
- * - A string path to a file
22
- * - An array of file paths
23
- *
24
- * @see https://bunup.dev/docs/#entry-points
25
- */
26
- entry: string | string[];
27
- /**
28
- * Output directory for the bundled files
29
- * Defaults to 'dist' if not specified
30
- */
31
- outDir: string;
32
- /**
33
- * Output formats for the bundle
34
- * Can include 'esm', 'cjs', and/or 'iife'
35
- * Defaults to ['cjs'] if not specified
36
- */
37
- format: Format[];
38
- /**
39
- * Whether to enable all minification options
40
- * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
41
- */
42
- minify?: boolean;
43
- /**
44
- * Whether to enable code splitting
45
- * Defaults to true for ESM format, false for CJS format
46
- */
47
- splitting?: boolean;
48
- /**
49
- * Whether to minify whitespace in the output
50
- * Removes unnecessary whitespace to reduce file size
51
- */
52
- minifyWhitespace?: boolean;
53
- /**
54
- * Whether to minify identifiers in the output
55
- * Renames variables and functions to shorter names
56
- */
57
- minifyIdentifiers?: boolean;
58
- /**
59
- * Whether to minify syntax in the output
60
- * Optimizes code structure for smaller file size
61
- */
62
- minifySyntax?: boolean;
63
- /**
64
- * Whether to watch for file changes and rebuild automatically
65
- */
66
- watch?: boolean;
67
- /**
68
- * Whether to generate TypeScript declaration files (.d.ts)
69
- * When set to true, generates declaration files for all entry points
70
- * Can also be configured with DtsOptions for more control
71
- */
72
- dts?: boolean | Pick<DtsPluginOptions, "entry" | "resolve" | "splitting" | "minify">;
73
- /**
74
- * Path to a preferred tsconfig.json file to use for declaration generation
75
- *
76
- * If not specified, the tsconfig.json in the project root will be used.
77
- * This option allows you to use a different TypeScript configuration
78
- * specifically for declaration file generation.
79
- *
80
- * @example
81
- * preferredTsconfigPath: './tsconfig.build.json'
82
- */
83
- preferredTsconfigPath?: string;
84
- /**
85
- * External packages that should not be bundled
86
- * Useful for dependencies that should be kept as external imports
87
- */
88
- external?: External;
89
- /**
90
- * Packages that should be bundled even if they are in external
91
- * Useful for dependencies that should be included in the bundle
92
- */
93
- noExternal?: External;
94
- /**
95
- * The target environment for the bundle
96
- * Can be 'browser', 'bun', 'node', etc.
97
- * Defaults to 'node' if not specified
98
- */
99
- target?: Target;
100
- /**
101
- * Whether to clean the output directory before building
102
- * When true, removes all files in the outDir before starting a new build
103
- * Defaults to true if not specified
104
- */
105
- clean?: boolean;
106
- /**
107
- * Specifies the type of sourcemap to generate
108
- * Can be 'none', 'linked', 'external', or 'inline'
109
- * Can also be a boolean - when true, it will use 'inline'
110
- *
111
- * @see https://bun.sh/docs/bundler#sourcemap
112
- *
113
- * @default 'none'
114
- *
115
- * @example
116
- * sourcemap: 'linked'
117
- * // or
118
- * sourcemap: true // equivalent to 'inline'
119
- */
120
- sourcemap?: Sourcemap;
121
- define?: Define;
122
- /**
123
- * A callback function that runs after the build process completes
124
- * This can be used for custom post-build operations like copying files,
125
- * running additional tools, or logging build information
126
- *
127
- * If watch mode is enabled, this callback runs after each rebuild
128
- *
129
- * @param options The build options that were used
130
- */
131
- onSuccess?: (options: Partial<BuildOptions>) => MaybePromise<void>;
132
- banner?: string;
133
- /**
134
- * A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
135
- *
136
- * @see https://bun.sh/docs/bundler#footer
137
- *
138
- * @example
139
- * footer: '// built with love in SF'
140
- */
141
- footer?: string;
142
- /**
143
- * Remove function calls from a bundle. For example, `drop: ["console"]` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
144
- *
145
- * @see https://bun.sh/docs/bundler#drop
146
- *
147
- * @example
148
- * drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"]
149
- */
150
- drop?: string[];
151
- /**
152
- * A map of file extensions to [built-in loader names](https://bun.sh/docs/bundler/loaders#built-in-loaders). This can be used to quickly customize how certain files are loaded.
153
- *
154
- * @see https://bun.sh/docs/bundler#loader
155
- *
156
- * @example
157
- * loader: {
158
- * ".png": "dataurl",
159
- * ".txt": "file",
160
- * }
161
- */
162
- loader?: Record<string, Loader>;
163
- /**
164
- * Generate bytecode for the output. This can dramatically improve cold start times, but will make the final output larger and slightly increase memory usage.
165
- *
166
- * Bytecode is currently only supported for CommonJS (format: "cjs").
167
- *
168
- * Must be target: "bun"
169
- *
170
- * @see https://bun.sh/docs/bundler#bytecode
171
- *
172
- * @default false
173
- */
174
- bytecode?: boolean;
175
- /**
176
- * Disable logging during the build process. When set to true, no logs will be printed to the console.
177
- *
178
- * @default false
179
- */
180
- silent?: boolean;
181
- /**
182
- * You can specify a prefix to be added to specific import paths in your bundled code
183
- *
184
- * Used for assets, external modules, and chunk files when splitting is enabled
185
- *
186
- * @see https://bunup.dev/docs#public-path for more information
187
- *
188
- * @example
189
- * publicPath: 'https://cdn.example.com/'
190
- */
191
- publicPath?: string;
192
- /**
193
- * Controls how environment variables are handled during bundling.
194
- *
195
- * Can be one of:
196
- * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
197
- * of those environment variables at the time the build runs.
198
- * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
199
- * - A string ending in `*`: Only inlines environment variables matching the given prefix.
200
- * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
201
- * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
202
- * with the provided values, regardless of the runtime environment.
203
- *
204
- * Note: Values are injected at build time. Secrets or private keys should be excluded
205
- * from inlining when targeting browser environments.
206
- *
207
- * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
208
- *
209
- * @example
210
- * // Inline all environment variables available at build time
211
- * env: "inline"
212
- *
213
- * // Disable all environment variable injection
214
- * env: "disable"
215
- *
216
- * // Only inline environment variables with a specific prefix
217
- * env: "PUBLIC_*"
218
- *
219
- * // Provide specific environment variables manually
220
- * env: { API_URL: "https://api.example.com", DEBUG: "false" }
221
- */
222
- env?: Env;
223
- plugins?: Plugin[];
224
- }
225
- type MaybePromise<T> = Promise<T> | T;
226
- type WithOptional<
227
- T,
228
- K extends keyof T
229
- > = Omit<T, K> & Partial<Pick<T, K>>;
230
- type Arrayable<T> = T | T[];
231
- type DefineConfigItem = Omit<WithOptional<BuildOptions, "outDir" | "format">, "watch">;
232
- type DefineWorkspaceItem = {
233
- name: string
234
- root: string
235
- config: DefineConfigItem | DefineConfigItem[]
236
- };
237
- type PackageJson = {
238
- /** The parsed content of the package.json file */
239
- data: Record<string, any> | null
240
- /** The path to the package.json file */
241
- path: string | null
242
- };
243
- /**
244
- * Represents a Bun plugin that can be used with Bunup
245
- */
246
- type BunupBunPlugin = {
247
- /** Identifies this as a native Bun plugin */
248
- type: "bun"
249
- /** Optional name for the plugin */
250
- name?: string
251
- /** The actual Bun plugin implementation */
252
- plugin: BunPlugin
253
- };
254
- /**
255
- * Represents the meta data of the build
256
- */
257
- type BuildMeta = {
258
- /** The package.json file */
259
- packageJson: PackageJson
260
- /** The root directory of the build */
261
- rootDir: string
262
- };
263
- type BuildOutputFile = {
264
- /** The kind of the file */
265
- kind: "entry-point" | "chunk" | "asset" | "sourcemap" | "bytecode"
266
- /** Path to the generated file */
267
- fullPath: string
268
- /** Path to the generated file relative to the root directory */
269
- relativePathToRootDir: string
270
- /** Path to the generated file relative to the output directory */
271
- relativePathToOutputDir: string
272
- /** Whether the file is a dts file */
273
- dts: boolean
274
- /** The format of the output file */
275
- format: Format
276
- };
277
- /**
278
- * Represents the output of a build operation
279
- */
280
- type BuildOutput = {
281
- /** Array of generated files with their paths and contents */
282
- files: BuildOutputFile[]
283
- };
284
- /**
285
- * Context provided to build hooks
286
- */
287
- type BuildContext = {
288
- /** The build options that were used */
289
- options: BuildOptions
290
- /** The output of the build */
291
- output: BuildOutput
292
- /** The meta data of the build */
293
- meta: BuildMeta
294
- };
295
- /**
296
- * Hooks that can be implemented by Bunup plugins
297
- */
298
- type BunupPluginHooks = {
299
- /**
300
- * Called when a build is successfully completed
301
- * @param ctx Build context containing options and output
302
- */
303
- onBuildDone?: (ctx: BuildContext) => MaybePromise<void>
304
- /**
305
- * Called before a build starts
306
- * @param options Build options that will be used
307
- */
308
- onBuildStart?: (options: BuildOptions) => MaybePromise<void>
309
- };
310
- /**
311
- * Represents a Bunup-specific plugin
312
- */
313
- type BunupPlugin = {
314
- /** Identifies this as a Bunup-specific plugin */
315
- type: "bunup"
316
- /** Optional name for the plugin */
317
- name?: string
318
- /** The hooks implemented by this plugin */
319
- hooks: BunupPluginHooks
320
- };
321
- /**
322
- * Union type representing all supported plugin types
323
- */
324
- type Plugin = BunupBunPlugin | BunupPlugin;
325
- export { BunupPlugin, Plugin, BuildOptions, MaybePromise, Arrayable, DefineConfigItem, DefineWorkspaceItem };