bunup 0.13.4 → 0.13.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
@@ -5,7 +5,7 @@ import {
5
5
  printBuildReport,
6
6
  processLoadedConfigs,
7
7
  resolveBuildOptions
8
- } from "../shared/bunup-sq2zmkp5.js";
8
+ } from "../shared/bunup-q245t34y.js";
9
9
  import {
10
10
  BunupCLIError,
11
11
  BunupWatchError,
@@ -18,13 +18,13 @@ import {
18
18
  logTime,
19
19
  logger,
20
20
  parseErrorMessage
21
- } from "../plugins.js";
21
+ } from "../shared/bunup-r5agr54b.js";
22
22
 
23
23
  // packages/bunup/src/cli/index.ts
24
24
  import { loadConfig } from "coffi";
25
25
  import pc3 from "picocolors";
26
26
  // packages/bunup/package.json
27
- var version = "0.11.30";
27
+ var version = "0.13.6";
28
28
 
29
29
  // packages/bunup/src/watch.ts
30
30
  import path from "path";
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // @bun
2
2
  import {
3
3
  build
4
- } from "./shared/bunup-sq2zmkp5.js";
5
- import"./plugins.js";
4
+ } from "./shared/bunup-q245t34y.js";
5
+ import"./shared/bunup-r5agr54b.js";
6
6
  // packages/bunup/src/define.ts
7
7
  function defineConfig(options) {
8
8
  return options;
package/dist/plugins.js CHANGED
@@ -1,423 +1,18 @@
1
1
  // @bun
2
- var __create = Object.create;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __toESM = (mod, isNodeMode, target) => {
8
- target = mod != null ? __create(__getProtoOf(mod)) : {};
9
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
- for (let key of __getOwnPropNames(mod))
11
- if (!__hasOwnProp.call(to, key))
12
- __defProp(to, key, {
13
- get: () => mod[key],
14
- enumerable: true
15
- });
16
- return to;
17
- };
18
- var __require = import.meta.require;
2
+ import {
3
+ CSS_RE,
4
+ JS_DTS_RE,
5
+ cleanPath,
6
+ detectFileFormatting,
7
+ ensureArray,
8
+ formatListWithAnd,
9
+ isGlobPattern,
10
+ logger,
11
+ shims
12
+ } from "./shared/bunup-r5agr54b.js";
19
13
 
20
14
  // packages/bunup/src/plugins/built-in/copy.ts
21
15
  import { basename, extname, join } from "path";
22
-
23
- // packages/bunup/src/printer/logger.ts
24
- import pc from "picocolors";
25
-
26
- class Logger {
27
- static instance;
28
- loggedOnceMessages = new Set;
29
- silent = false;
30
- constructor() {}
31
- static getInstance() {
32
- if (!Logger.instance) {
33
- Logger.instance = new Logger;
34
- }
35
- return Logger.instance;
36
- }
37
- dispose() {
38
- this.loggedOnceMessages.clear();
39
- }
40
- setSilent(value) {
41
- this.silent = value ?? false;
42
- }
43
- isSilent() {
44
- return this.silent;
45
- }
46
- shouldLog(options) {
47
- if (!options?.once) {
48
- return true;
49
- }
50
- if (this.loggedOnceMessages.has(options.once)) {
51
- return false;
52
- }
53
- this.loggedOnceMessages.add(options.once);
54
- return true;
55
- }
56
- getIcon(type, tick) {
57
- if (tick) {
58
- return pc.green("\u2713");
59
- }
60
- const iconMap = {
61
- info: pc.blue("i"),
62
- warn: pc.yellow("!"),
63
- error: pc.red("\u2715")
64
- };
65
- return iconMap[type];
66
- }
67
- formatIdentifier(identifier) {
68
- return identifier ? ` ${pc.bgBlueBright(` ${identifier} `)}` : "";
69
- }
70
- formatMessage(options) {
71
- const {
72
- message,
73
- identifier,
74
- muted = false,
75
- tick = false,
76
- type = "info"
77
- } = options;
78
- const icon = options.icon ?? this.getIcon(type, tick);
79
- const styledMessage = muted ? pc.dim(message) : type === "error" ? pc.red(message) : type === "warn" ? pc.yellow(message) : message;
80
- const identifierPart = this.formatIdentifier(identifier);
81
- return `${icon} ${styledMessage}${identifierPart}`;
82
- }
83
- output(message, options = {}, logFn = console.log) {
84
- if (this.silent || !this.shouldLog(options)) {
85
- return;
86
- }
87
- if (options.verticalSpace) {
88
- logFn("");
89
- }
90
- logFn(message);
91
- if (options.verticalSpace) {
92
- logFn("");
93
- }
94
- }
95
- info(message, options = {}) {
96
- const formattedMessage = this.formatMessage({
97
- ...options,
98
- message,
99
- type: "info"
100
- });
101
- this.output(formattedMessage, options);
102
- }
103
- warn(message, options = {}) {
104
- const formattedMessage = this.formatMessage({
105
- ...options,
106
- message,
107
- type: "warn"
108
- });
109
- this.output(formattedMessage, options);
110
- }
111
- error(message, options = {}) {
112
- const formattedMessage = this.formatMessage({
113
- ...options,
114
- message,
115
- type: "error"
116
- });
117
- this.output(formattedMessage, options);
118
- }
119
- success(message, options = {}) {
120
- const formattedMessage = this.formatMessage({
121
- ...options,
122
- message,
123
- tick: true
124
- });
125
- this.output(formattedMessage, options);
126
- }
127
- space() {
128
- if (!this.silent) {
129
- console.log("");
130
- }
131
- }
132
- log(...args) {
133
- if (!this.silent) {
134
- console.log(...args);
135
- }
136
- }
137
- }
138
- function logTime(ms) {
139
- return ms >= 1000 ? pc.green(`${(ms / 1000).toFixed(2)}s`) : pc.green(`${Math.round(ms)}ms`);
140
- }
141
- function link(url, label) {
142
- if (!label) {
143
- label = url;
144
- }
145
- return `\x1B]8;;${url}\x07${pc.underline(pc.cyan(label))}\x1B]8;;\x07`;
146
- }
147
- var logger = Logger.getInstance();
148
-
149
- // packages/bunup/src/utils.ts
150
- import fs from "fs/promises";
151
- import path, { normalize } from "path";
152
-
153
- // packages/bunup/src/constants/re.ts
154
- var JS_RE = /\.(js|jsx|cjs|mjs)$/;
155
- var TS_RE = /\.(ts|tsx|mts|cts)$/;
156
- var DTS_RE = /\.(d\.(ts|mts|cts))$/;
157
- var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
158
- var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
159
- var CSS_RE = /\.(css)$/;
160
-
161
- // packages/bunup/src/errors.ts
162
- import pc2 from "picocolors";
163
- class BunupError extends Error {
164
- constructor(message) {
165
- super(message);
166
- this.name = "BunupError";
167
- }
168
- }
169
-
170
- class BunupBuildError extends BunupError {
171
- constructor(message) {
172
- super(message);
173
- this.name = "BunupBuildError";
174
- }
175
- }
176
-
177
- class BunupDTSBuildError extends BunupError {
178
- constructor(message) {
179
- super(message);
180
- this.name = "BunupDTSBuildError";
181
- }
182
- }
183
-
184
- class BunupCLIError extends BunupError {
185
- constructor(message) {
186
- super(message);
187
- this.name = "BunupCLIError";
188
- }
189
- }
190
-
191
- class BunupWatchError extends BunupError {
192
- constructor(message) {
193
- super(message);
194
- this.name = "BunupWatchError";
195
- }
196
- }
197
-
198
- class BunupPluginError extends BunupError {
199
- constructor(message) {
200
- super(message);
201
- this.name = "BunupPluginError";
202
- }
203
- }
204
- var parseErrorMessage = (error) => {
205
- if (error instanceof Error) {
206
- return error.message;
207
- }
208
- return String(error);
209
- };
210
- var KNOWN_ERRORS = [
211
- {
212
- pattern: /Could not resolve: "bun"/i,
213
- errorType: "BUILD ERROR",
214
- logSolution: () => {
215
- logger.log("You're trying to build a project that uses Bun. " + "Please set the target option to " + pc2.cyan("`bun`") + `.
216
- ` + "Example: " + pc2.green("`bunup --target bun`") + " or in config: " + pc2.green("{ target: 'bun' }"));
217
- }
218
- },
219
- {
220
- pattern: /has already been exported. Exported identifiers must be unique./i,
221
- errorType: "DTS ERROR",
222
- logSolution: () => {
223
- logger.log("An error occurred while bundling dts files. This issue occurs when dts splitting is enabled due to a bug in the Bun bundler. Please ping the GitHub issue to help get it fixed faster: " + link("https://github.com/oven-sh/bun/issues/5344") + ". To fix this issue for now, you can disable dts splitting by removing " + pc2.dim("dts: { splitting: true }") + " from your config." + " You can re-enable it once the issue is fixed.");
224
- }
225
- }
226
- ];
227
- var handleError = (error, context) => {
228
- const errorMessage = parseErrorMessage(error);
229
- const contextPrefix = context ? `[${context}] ` : "";
230
- let errorType = "UNKNOWN ERROR";
231
- if (error instanceof BunupBuildError) {
232
- errorType = "BUILD ERROR";
233
- } else if (error instanceof BunupDTSBuildError) {
234
- errorType = "DTS ERROR";
235
- } else if (error instanceof BunupCLIError) {
236
- errorType = "CLI ERROR";
237
- } else if (error instanceof BunupWatchError) {
238
- errorType = "WATCH ERROR";
239
- } else if (error instanceof BunupPluginError) {
240
- errorType = "PLUGIN ERROR";
241
- } else if (error instanceof BunupError) {
242
- errorType = "BUNUP ERROR";
243
- }
244
- const knownError = KNOWN_ERRORS.find((error2) => error2.pattern.test(errorMessage) && (error2.errorType === errorType || !error2.errorType));
245
- if (!knownError && errorType) {
246
- console.error(`
247
- ${pc2.red(errorType)} ${contextPrefix}${errorMessage}`);
248
- }
249
- if (knownError) {
250
- console.log(`
251
- `);
252
- knownError.logSolution(errorMessage);
253
- console.log(`
254
- `);
255
- } else {
256
- const issueUrl = new URL("https://github.com/bunup/bunup/issues/new");
257
- issueUrl.searchParams.set("title", `[${errorType}] Error encountered`);
258
- issueUrl.searchParams.set("body", `## Error Details
259
-
260
- **Error Type:** ${errorType}
261
- **Error Message:** ${errorMessage}
262
-
263
- ## Additional Context
264
-
265
- <!-- Please provide any additional context about what you were trying to do when the error occurred -->`);
266
- console.error(pc2.white(`
267
- If you think this is a bug, please `) + link(issueUrl.toString(), "open an issue") + ` with details about this error
268
- `);
269
- }
270
- };
271
- var handleErrorAndExit = (error, context) => {
272
- handleError(error, context);
273
- process.exit(1);
274
- };
275
-
276
- // packages/bunup/src/utils.ts
277
- function ensureArray(value) {
278
- return Array.isArray(value) ? value : [value];
279
- }
280
- function getDefaultJsOutputExtension(format, packageType) {
281
- switch (format) {
282
- case "esm":
283
- return isModulePackage(packageType) ? ".js" : ".mjs";
284
- case "cjs":
285
- return isModulePackage(packageType) ? ".cjs" : ".js";
286
- case "iife":
287
- return ".global.js";
288
- }
289
- }
290
- function getDefaultDtsOutputExtention(format, packageType, kind) {
291
- if (kind === "chunk")
292
- return ".d.ts";
293
- switch (format) {
294
- case "esm":
295
- return isModulePackage(packageType) ? ".d.ts" : ".d.mts";
296
- case "cjs":
297
- return isModulePackage(packageType) ? ".d.cts" : ".d.ts";
298
- case "iife":
299
- return ".global.d.ts";
300
- }
301
- }
302
- function isModulePackage(packageType) {
303
- return packageType === "module";
304
- }
305
- function getPackageDeps(packageJson) {
306
- if (!packageJson)
307
- return [];
308
- return Array.from(new Set([
309
- ...Object.keys(packageJson.dependencies || {}),
310
- ...Object.keys(packageJson.peerDependencies || {})
311
- ]));
312
- }
313
- function formatFileSize(bytes) {
314
- if (bytes === 0)
315
- return "0 B";
316
- const units = ["B", "KB", "MB", "GB"];
317
- const i = Math.floor(Math.log(bytes) / Math.log(1024));
318
- if (i === 0)
319
- return `${bytes} ${units[i]}`;
320
- return `${(bytes / 1024 ** i).toFixed(2)} ${units[i]}`;
321
- }
322
- function getShortFilePath(filePath, maxLength = 3) {
323
- const fileParts = filePath.split("/");
324
- const shortPath = fileParts.slice(-maxLength).join("/");
325
- return shortPath;
326
- }
327
- async function cleanOutDir(rootDir, outDir) {
328
- const outDirPath = path.join(rootDir, outDir);
329
- try {
330
- await fs.rm(outDirPath, { recursive: true, force: true });
331
- } catch (error) {
332
- throw new BunupBuildError(`Failed to clean output directory: ${error}`);
333
- }
334
- await fs.mkdir(outDirPath, { recursive: true });
335
- }
336
- function cleanPath(path2) {
337
- let cleaned = normalize(path2).replace(/\\/g, "/");
338
- cleaned = cleaned.replace(/^[a-zA-Z]:\//, "");
339
- cleaned = cleaned.replace(/^\/+/, "");
340
- cleaned = cleaned.replace(/\/+/g, "/");
341
- return cleaned;
342
- }
343
- function formatListWithAnd(arr) {
344
- return new Intl.ListFormat("en", {
345
- style: "long",
346
- type: "conjunction"
347
- }).format(arr);
348
- }
349
- async function getFilesFromGlobs(patterns, cwd) {
350
- const includePatterns = patterns.filter((p) => !p.startsWith("!"));
351
- const excludePatterns = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
352
- const includedFiles = new Set;
353
- for (const pattern of includePatterns) {
354
- const glob = new Bun.Glob(pattern);
355
- for await (const file of glob.scan(cwd)) {
356
- includedFiles.add(file);
357
- }
358
- }
359
- if (excludePatterns.length > 0) {
360
- for (const pattern of excludePatterns) {
361
- const glob = new Bun.Glob(pattern);
362
- for await (const file of glob.scan(cwd)) {
363
- includedFiles.delete(file);
364
- }
365
- }
366
- }
367
- return Array.from(includedFiles);
368
- }
369
- function isTypeScriptFile(path2) {
370
- if (!path2)
371
- return false;
372
- return TS_RE.test(path2);
373
- }
374
- function isJavascriptFile(path2) {
375
- if (!path2)
376
- return false;
377
- return JS_RE.test(path2);
378
- }
379
- function replaceExtension(filePath, newExtension) {
380
- if (!filePath) {
381
- return filePath;
382
- }
383
- const normalizedExtension = newExtension.startsWith(".") ? newExtension : `.${newExtension}`;
384
- const lastSlashIndex = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
385
- const directory = lastSlashIndex >= 0 ? filePath.substring(0, lastSlashIndex + 1) : "";
386
- const filename = lastSlashIndex >= 0 ? filePath.substring(lastSlashIndex + 1) : filePath;
387
- const lastDotIndex = filename.lastIndexOf(".");
388
- if (lastDotIndex === -1) {
389
- return directory + filename + normalizedExtension;
390
- }
391
- const nameWithoutExtension = filename.substring(0, lastDotIndex);
392
- return directory + nameWithoutExtension + normalizedExtension;
393
- }
394
- async function detectFileFormatting(filePath) {
395
- try {
396
- const content = await Bun.file(filePath).text();
397
- const hasTrailingNewline = content.endsWith(`
398
- `);
399
- const lines = content.split(`
400
- `);
401
- for (const line of lines) {
402
- const match = line.match(/^(\s+)/);
403
- if (match) {
404
- const indent = match[1];
405
- if (indent.startsWith("\t")) {
406
- return { indentation: "\t", hasTrailingNewline };
407
- }
408
- return { indentation: indent, hasTrailingNewline };
409
- }
410
- }
411
- return { indentation: " ", hasTrailingNewline };
412
- } catch {
413
- return { indentation: " ", hasTrailingNewline: true };
414
- }
415
- }
416
- function isGlobPattern(pattern) {
417
- return /[*?[\]{}]/.test(pattern);
418
- }
419
-
420
- // packages/bunup/src/plugins/built-in/copy.ts
421
16
  function copy(pattern) {
422
17
  return new CopyBuilder(pattern);
423
18
  }
@@ -497,7 +92,7 @@ async function copyFile(sourcePath, finalDestinationPath) {
497
92
  await Bun.write(finalDestinationPath, sourceFile);
498
93
  }
499
94
  // packages/bunup/src/plugins/built-in/exports.ts
500
- import path2 from "path";
95
+ import path from "path";
501
96
  function exports(options = {}) {
502
97
  return {
503
98
  name: "exports",
@@ -723,14 +318,14 @@ function getExportKey(pathRelativeToOutdir) {
723
318
  return `./${pathSegments.filter((segment) => !segment.startsWith("index")).join("/")}`;
724
319
  }
725
320
  function removeExtension(filePath) {
726
- const basename2 = path2.basename(filePath);
321
+ const basename2 = path.basename(filePath);
727
322
  const firstDotIndex = basename2.indexOf(".");
728
323
  if (firstDotIndex === -1) {
729
324
  return filePath;
730
325
  }
731
326
  const nameWithoutExtensions = basename2.slice(0, firstDotIndex);
732
- const directory = path2.dirname(filePath);
733
- return directory === "." ? nameWithoutExtensions : path2.join(directory, nameWithoutExtensions);
327
+ const directory = path.dirname(filePath);
328
+ return directory === "." ? nameWithoutExtensions : path.join(directory, nameWithoutExtensions);
734
329
  }
735
330
  function addCssToExports(exportsField, cssFiles) {
736
331
  if (cssFiles.length === 0)
@@ -775,7 +370,7 @@ function exportFieldToEntryPoint(exportField) {
775
370
  }
776
371
  }
777
372
  // packages/bunup/src/plugins/built-in/inject-styles.ts
778
- import path3 from "path";
373
+ import path2 from "path";
779
374
  import { getDefaultCssBrowserTargets } from "@bunup/shared";
780
375
  import { transform } from "lightningcss";
781
376
  function injectStyles(options) {
@@ -812,7 +407,7 @@ function injectStyles(options) {
812
407
  build.onLoad({ filter: CSS_RE }, async (args) => {
813
408
  const source = await Bun.file(args.path).text();
814
409
  const { code, warnings } = transform({
815
- filename: path3.basename(args.path),
410
+ filename: path2.basename(args.path),
816
411
  code: Buffer.from(source),
817
412
  minify,
818
413
  targets: getDefaultCssBrowserTargets()
@@ -830,58 +425,8 @@ function injectStyles(options) {
830
425
  }
831
426
  };
832
427
  }
833
- // packages/bunup/src/plugins/built-in/shims.ts
834
- function shims() {
835
- return {
836
- name: "bunup:shims",
837
- setup(build) {
838
- const isNodeCompatibleTarget = build.config.target === "node" || build.config.target === "bun";
839
- const isEsm = build.config.format === "esm";
840
- const isCjs = build.config.format === "cjs";
841
- if (!isNodeCompatibleTarget || !isEsm && !isCjs) {
842
- return;
843
- }
844
- build.config.define = {
845
- ...build.config.define,
846
- ...isCjs && {
847
- "import.meta.url": "importMetaUrl"
848
- }
849
- };
850
- build.onLoad({ filter: JS_TS_RE }, async ({ path: path4 }) => {
851
- const content = await Bun.file(path4).text();
852
- let shimCode = "";
853
- if (isEsm && (/\b__dirname\b/.test(content) || /\b__filename\b/.test(content))) {
854
- shimCode = `import { fileURLToPath } from 'url';
855
- import { dirname } from 'path';
856
-
857
- const __filename = fileURLToPath(import.meta.url);
858
- const __dirname = dirname(__filename);
859
-
860
- `;
861
- }
862
- if (isCjs && /\bimport\.meta\.url\b/.test(content)) {
863
- shimCode = `import { pathToFileURL } from 'url';
864
-
865
- const importMetaUrl = pathToFileURL(__filename).href;
866
-
867
- `;
868
- }
869
- if (!shimCode)
870
- return;
871
- const lines = content.split(`
872
- `);
873
- const firstLine = lines[0];
874
- const restLines = lines.slice(1);
875
- return {
876
- contents: [firstLine, shimCode, ...restLines].join(`
877
- `)
878
- };
879
- });
880
- }
881
- };
882
- }
883
428
  // packages/bunup/src/plugins/built-in/unused.ts
884
- import pc3 from "picocolors";
429
+ import pc from "picocolors";
885
430
  function unused(options = {}) {
886
431
  const { level = "warn", ignore = [] } = options;
887
432
  return {
@@ -923,15 +468,15 @@ function unused(options = {}) {
923
468
  if (unusedDependencies.length > 0) {
924
469
  const count = unusedDependencies.length;
925
470
  const depText = count === 1 ? "dependency" : "dependencies";
926
- const coloredDeps = formatListWithAnd(unusedDependencies.map((dep) => pc3.yellow(dep)));
927
- const removeCommand = pc3.cyan(`bun remove ${unusedDependencies.join(" ")}`);
471
+ const coloredDeps = formatListWithAnd(unusedDependencies.map((dep) => pc.yellow(dep)));
472
+ const removeCommand = pc.cyan(`bun remove ${unusedDependencies.join(" ")}`);
928
473
  const message = [
929
474
  `
930
475
  Your project${buildOptions.name ? ` ${buildOptions.name}` : ""} has ${count} unused ${depText}: ${coloredDeps}.`,
931
476
  `You can remove ${count === 1 ? "it" : "them"} with ${removeCommand}`
932
477
  ].join(" ");
933
478
  if (level === "error") {
934
- logger.log(pc3.red(message));
479
+ logger.log(pc.red(message));
935
480
  process.exit(1);
936
481
  } else {
937
482
  logger.log(message);
@@ -948,4 +493,3 @@ export {
948
493
  exports,
949
494
  copy
950
495
  };
951
- export { __toESM, __require, logTime, logger, BunupBuildError, BunupDTSBuildError, BunupCLIError, BunupWatchError, parseErrorMessage, handleError, handleErrorAndExit, ensureArray, getDefaultJsOutputExtension, getDefaultDtsOutputExtention, getPackageDeps, formatFileSize, getShortFilePath, cleanOutDir, cleanPath, getFilesFromGlobs, isTypeScriptFile, isJavascriptFile, replaceExtension, shims };
@@ -17,7 +17,7 @@ import {
17
17
  parseErrorMessage,
18
18
  replaceExtension,
19
19
  shims
20
- } from "../plugins.js";
20
+ } from "./bunup-r5agr54b.js";
21
21
 
22
22
  // packages/bunup/src/loaders.ts
23
23
  import path from "path";
@@ -0,0 +1,466 @@
1
+ // @bun
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __require = import.meta.require;
19
+
20
+ // packages/bunup/src/printer/logger.ts
21
+ import pc from "picocolors";
22
+
23
+ class Logger {
24
+ static instance;
25
+ loggedOnceMessages = new Set;
26
+ silent = false;
27
+ constructor() {}
28
+ static getInstance() {
29
+ if (!Logger.instance) {
30
+ Logger.instance = new Logger;
31
+ }
32
+ return Logger.instance;
33
+ }
34
+ dispose() {
35
+ this.loggedOnceMessages.clear();
36
+ }
37
+ setSilent(value) {
38
+ this.silent = value ?? false;
39
+ }
40
+ isSilent() {
41
+ return this.silent;
42
+ }
43
+ shouldLog(options) {
44
+ if (!options?.once) {
45
+ return true;
46
+ }
47
+ if (this.loggedOnceMessages.has(options.once)) {
48
+ return false;
49
+ }
50
+ this.loggedOnceMessages.add(options.once);
51
+ return true;
52
+ }
53
+ getIcon(type, tick) {
54
+ if (tick) {
55
+ return pc.green("\u2713");
56
+ }
57
+ const iconMap = {
58
+ info: pc.blue("i"),
59
+ warn: pc.yellow("!"),
60
+ error: pc.red("\u2715")
61
+ };
62
+ return iconMap[type];
63
+ }
64
+ formatIdentifier(identifier) {
65
+ return identifier ? ` ${pc.bgBlueBright(` ${identifier} `)}` : "";
66
+ }
67
+ formatMessage(options) {
68
+ const {
69
+ message,
70
+ identifier,
71
+ muted = false,
72
+ tick = false,
73
+ type = "info"
74
+ } = options;
75
+ const icon = options.icon ?? this.getIcon(type, tick);
76
+ const styledMessage = muted ? pc.dim(message) : type === "error" ? pc.red(message) : type === "warn" ? pc.yellow(message) : message;
77
+ const identifierPart = this.formatIdentifier(identifier);
78
+ return `${icon} ${styledMessage}${identifierPart}`;
79
+ }
80
+ output(message, options = {}, logFn = console.log) {
81
+ if (this.silent || !this.shouldLog(options)) {
82
+ return;
83
+ }
84
+ if (options.verticalSpace) {
85
+ logFn("");
86
+ }
87
+ logFn(message);
88
+ if (options.verticalSpace) {
89
+ logFn("");
90
+ }
91
+ }
92
+ info(message, options = {}) {
93
+ const formattedMessage = this.formatMessage({
94
+ ...options,
95
+ message,
96
+ type: "info"
97
+ });
98
+ this.output(formattedMessage, options);
99
+ }
100
+ warn(message, options = {}) {
101
+ const formattedMessage = this.formatMessage({
102
+ ...options,
103
+ message,
104
+ type: "warn"
105
+ });
106
+ this.output(formattedMessage, options);
107
+ }
108
+ error(message, options = {}) {
109
+ const formattedMessage = this.formatMessage({
110
+ ...options,
111
+ message,
112
+ type: "error"
113
+ });
114
+ this.output(formattedMessage, options);
115
+ }
116
+ success(message, options = {}) {
117
+ const formattedMessage = this.formatMessage({
118
+ ...options,
119
+ message,
120
+ tick: true
121
+ });
122
+ this.output(formattedMessage, options);
123
+ }
124
+ space() {
125
+ if (!this.silent) {
126
+ console.log("");
127
+ }
128
+ }
129
+ log(...args) {
130
+ if (!this.silent) {
131
+ console.log(...args);
132
+ }
133
+ }
134
+ }
135
+ function logTime(ms) {
136
+ return ms >= 1000 ? pc.green(`${(ms / 1000).toFixed(2)}s`) : pc.green(`${Math.round(ms)}ms`);
137
+ }
138
+ function link(url, label) {
139
+ if (!label) {
140
+ label = url;
141
+ }
142
+ return `\x1B]8;;${url}\x07${pc.underline(pc.cyan(label))}\x1B]8;;\x07`;
143
+ }
144
+ var logger = Logger.getInstance();
145
+
146
+ // packages/bunup/src/errors.ts
147
+ import pc2 from "picocolors";
148
+ class BunupError extends Error {
149
+ constructor(message) {
150
+ super(message);
151
+ this.name = "BunupError";
152
+ }
153
+ }
154
+
155
+ class BunupBuildError extends BunupError {
156
+ constructor(message) {
157
+ super(message);
158
+ this.name = "BunupBuildError";
159
+ }
160
+ }
161
+
162
+ class BunupDTSBuildError extends BunupError {
163
+ constructor(message) {
164
+ super(message);
165
+ this.name = "BunupDTSBuildError";
166
+ }
167
+ }
168
+
169
+ class BunupCLIError extends BunupError {
170
+ constructor(message) {
171
+ super(message);
172
+ this.name = "BunupCLIError";
173
+ }
174
+ }
175
+
176
+ class BunupWatchError extends BunupError {
177
+ constructor(message) {
178
+ super(message);
179
+ this.name = "BunupWatchError";
180
+ }
181
+ }
182
+
183
+ class BunupPluginError extends BunupError {
184
+ constructor(message) {
185
+ super(message);
186
+ this.name = "BunupPluginError";
187
+ }
188
+ }
189
+ var parseErrorMessage = (error) => {
190
+ if (error instanceof Error) {
191
+ return error.message;
192
+ }
193
+ return String(error);
194
+ };
195
+ var KNOWN_ERRORS = [
196
+ {
197
+ pattern: /Could not resolve: "bun"/i,
198
+ errorType: "BUILD ERROR",
199
+ logSolution: () => {
200
+ logger.log("You're trying to build a project that uses Bun. " + "Please set the target option to " + pc2.cyan("`bun`") + `.
201
+ ` + "Example: " + pc2.green("`bunup --target bun`") + " or in config: " + pc2.green("{ target: 'bun' }"));
202
+ }
203
+ },
204
+ {
205
+ pattern: /has already been exported. Exported identifiers must be unique./i,
206
+ errorType: "DTS ERROR",
207
+ logSolution: () => {
208
+ logger.log("An error occurred while bundling dts files. This issue occurs when dts splitting is enabled due to a bug in the Bun bundler. Please ping the GitHub issue to help get it fixed faster: " + link("https://github.com/oven-sh/bun/issues/5344") + ". To fix this issue for now, you can disable dts splitting by removing " + pc2.dim("dts: { splitting: true }") + " from your config." + " You can re-enable it once the issue is fixed.");
209
+ }
210
+ }
211
+ ];
212
+ var handleError = (error, context) => {
213
+ const errorMessage = parseErrorMessage(error);
214
+ const contextPrefix = context ? `[${context}] ` : "";
215
+ let errorType = "UNKNOWN ERROR";
216
+ if (error instanceof BunupBuildError) {
217
+ errorType = "BUILD ERROR";
218
+ } else if (error instanceof BunupDTSBuildError) {
219
+ errorType = "DTS ERROR";
220
+ } else if (error instanceof BunupCLIError) {
221
+ errorType = "CLI ERROR";
222
+ } else if (error instanceof BunupWatchError) {
223
+ errorType = "WATCH ERROR";
224
+ } else if (error instanceof BunupPluginError) {
225
+ errorType = "PLUGIN ERROR";
226
+ } else if (error instanceof BunupError) {
227
+ errorType = "BUNUP ERROR";
228
+ }
229
+ const knownError = KNOWN_ERRORS.find((error2) => error2.pattern.test(errorMessage) && (error2.errorType === errorType || !error2.errorType));
230
+ if (!knownError && errorType) {
231
+ console.error(`
232
+ ${pc2.red(errorType)} ${contextPrefix}${errorMessage}`);
233
+ }
234
+ if (knownError) {
235
+ console.log(`
236
+ `);
237
+ knownError.logSolution(errorMessage);
238
+ console.log(`
239
+ `);
240
+ } else {
241
+ const issueUrl = new URL("https://github.com/bunup/bunup/issues/new");
242
+ issueUrl.searchParams.set("title", `[${errorType}] Error encountered`);
243
+ issueUrl.searchParams.set("body", `## Error Details
244
+
245
+ **Error Type:** ${errorType}
246
+ **Error Message:** ${errorMessage}
247
+
248
+ ## Additional Context
249
+
250
+ <!-- Please provide any additional context about what you were trying to do when the error occurred -->`);
251
+ console.error(pc2.white(`
252
+ If you think this is a bug, please `) + link(issueUrl.toString(), "open an issue") + ` with details about this error
253
+ `);
254
+ }
255
+ };
256
+ var handleErrorAndExit = (error, context) => {
257
+ handleError(error, context);
258
+ process.exit(1);
259
+ };
260
+
261
+ // packages/bunup/src/constants/re.ts
262
+ var JS_RE = /\.(js|jsx|cjs|mjs)$/;
263
+ var TS_RE = /\.(ts|tsx|mts|cts)$/;
264
+ var DTS_RE = /\.(d\.(ts|mts|cts))$/;
265
+ var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
266
+ var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
267
+ var CSS_RE = /\.(css)$/;
268
+
269
+ // packages/bunup/src/plugins/built-in/shims.ts
270
+ function shims() {
271
+ return {
272
+ name: "bunup:shims",
273
+ setup(build) {
274
+ const isNodeCompatibleTarget = build.config.target === "node" || build.config.target === "bun";
275
+ const isEsm = build.config.format === "esm";
276
+ const isCjs = build.config.format === "cjs";
277
+ if (!isNodeCompatibleTarget || !isEsm && !isCjs) {
278
+ return;
279
+ }
280
+ build.config.define = {
281
+ ...build.config.define,
282
+ ...isCjs && {
283
+ "import.meta.url": "importMetaUrl"
284
+ }
285
+ };
286
+ build.onLoad({ filter: JS_TS_RE }, async ({ path }) => {
287
+ const content = await Bun.file(path).text();
288
+ let shimCode = "";
289
+ if (isEsm && (/\b__dirname\b/.test(content) || /\b__filename\b/.test(content))) {
290
+ shimCode = `import { fileURLToPath } from 'url';
291
+ import { dirname } from 'path';
292
+
293
+ const __filename = fileURLToPath(import.meta.url);
294
+ const __dirname = dirname(__filename);
295
+
296
+ `;
297
+ }
298
+ if (isCjs && /\bimport\.meta\.url\b/.test(content)) {
299
+ shimCode = `import { pathToFileURL } from 'url';
300
+
301
+ const importMetaUrl = pathToFileURL(__filename).href;
302
+
303
+ `;
304
+ }
305
+ if (!shimCode)
306
+ return;
307
+ const lines = content.split(`
308
+ `);
309
+ const firstLine = lines[0];
310
+ const restLines = lines.slice(1);
311
+ return {
312
+ contents: [firstLine, shimCode, ...restLines].join(`
313
+ `)
314
+ };
315
+ });
316
+ }
317
+ };
318
+ }
319
+
320
+ // packages/bunup/src/utils.ts
321
+ import fs from "fs/promises";
322
+ import path, { normalize } from "path";
323
+ function ensureArray(value) {
324
+ return Array.isArray(value) ? value : [value];
325
+ }
326
+ function getDefaultJsOutputExtension(format, packageType) {
327
+ switch (format) {
328
+ case "esm":
329
+ return isModulePackage(packageType) ? ".js" : ".mjs";
330
+ case "cjs":
331
+ return isModulePackage(packageType) ? ".cjs" : ".js";
332
+ case "iife":
333
+ return ".global.js";
334
+ }
335
+ }
336
+ function getDefaultDtsOutputExtention(format, packageType, kind) {
337
+ if (kind === "chunk")
338
+ return ".d.ts";
339
+ switch (format) {
340
+ case "esm":
341
+ return isModulePackage(packageType) ? ".d.ts" : ".d.mts";
342
+ case "cjs":
343
+ return isModulePackage(packageType) ? ".d.cts" : ".d.ts";
344
+ case "iife":
345
+ return ".global.d.ts";
346
+ }
347
+ }
348
+ function isModulePackage(packageType) {
349
+ return packageType === "module";
350
+ }
351
+ function getPackageDeps(packageJson) {
352
+ if (!packageJson)
353
+ return [];
354
+ return Array.from(new Set([
355
+ ...Object.keys(packageJson.dependencies || {}),
356
+ ...Object.keys(packageJson.peerDependencies || {})
357
+ ]));
358
+ }
359
+ function formatFileSize(bytes) {
360
+ if (bytes === 0)
361
+ return "0 B";
362
+ const units = ["B", "KB", "MB", "GB"];
363
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
364
+ if (i === 0)
365
+ return `${bytes} ${units[i]}`;
366
+ return `${(bytes / 1024 ** i).toFixed(2)} ${units[i]}`;
367
+ }
368
+ function getShortFilePath(filePath, maxLength = 3) {
369
+ const fileParts = filePath.split("/");
370
+ const shortPath = fileParts.slice(-maxLength).join("/");
371
+ return shortPath;
372
+ }
373
+ async function cleanOutDir(rootDir, outDir) {
374
+ const outDirPath = path.join(rootDir, outDir);
375
+ try {
376
+ await fs.rm(outDirPath, { recursive: true, force: true });
377
+ } catch (error) {
378
+ throw new BunupBuildError(`Failed to clean output directory: ${error}`);
379
+ }
380
+ await fs.mkdir(outDirPath, { recursive: true });
381
+ }
382
+ function cleanPath(path2) {
383
+ let cleaned = normalize(path2).replace(/\\/g, "/");
384
+ cleaned = cleaned.replace(/^[a-zA-Z]:\//, "");
385
+ cleaned = cleaned.replace(/^\/+/, "");
386
+ cleaned = cleaned.replace(/\/+/g, "/");
387
+ return cleaned;
388
+ }
389
+ function formatListWithAnd(arr) {
390
+ return new Intl.ListFormat("en", {
391
+ style: "long",
392
+ type: "conjunction"
393
+ }).format(arr);
394
+ }
395
+ async function getFilesFromGlobs(patterns, cwd) {
396
+ const includePatterns = patterns.filter((p) => !p.startsWith("!"));
397
+ const excludePatterns = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
398
+ const includedFiles = new Set;
399
+ for (const pattern of includePatterns) {
400
+ const glob = new Bun.Glob(pattern);
401
+ for await (const file of glob.scan(cwd)) {
402
+ includedFiles.add(file);
403
+ }
404
+ }
405
+ if (excludePatterns.length > 0) {
406
+ for (const pattern of excludePatterns) {
407
+ const glob = new Bun.Glob(pattern);
408
+ for await (const file of glob.scan(cwd)) {
409
+ includedFiles.delete(file);
410
+ }
411
+ }
412
+ }
413
+ return Array.from(includedFiles);
414
+ }
415
+ function isTypeScriptFile(path2) {
416
+ if (!path2)
417
+ return false;
418
+ return TS_RE.test(path2);
419
+ }
420
+ function isJavascriptFile(path2) {
421
+ if (!path2)
422
+ return false;
423
+ return JS_RE.test(path2);
424
+ }
425
+ function replaceExtension(filePath, newExtension) {
426
+ if (!filePath) {
427
+ return filePath;
428
+ }
429
+ const normalizedExtension = newExtension.startsWith(".") ? newExtension : `.${newExtension}`;
430
+ const lastSlashIndex = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
431
+ const directory = lastSlashIndex >= 0 ? filePath.substring(0, lastSlashIndex + 1) : "";
432
+ const filename = lastSlashIndex >= 0 ? filePath.substring(lastSlashIndex + 1) : filePath;
433
+ const lastDotIndex = filename.lastIndexOf(".");
434
+ if (lastDotIndex === -1) {
435
+ return directory + filename + normalizedExtension;
436
+ }
437
+ const nameWithoutExtension = filename.substring(0, lastDotIndex);
438
+ return directory + nameWithoutExtension + normalizedExtension;
439
+ }
440
+ async function detectFileFormatting(filePath) {
441
+ try {
442
+ const content = await Bun.file(filePath).text();
443
+ const hasTrailingNewline = content.endsWith(`
444
+ `);
445
+ const lines = content.split(`
446
+ `);
447
+ for (const line of lines) {
448
+ const match = line.match(/^(\s+)/);
449
+ if (match) {
450
+ const indent = match[1];
451
+ if (indent.startsWith("\t")) {
452
+ return { indentation: "\t", hasTrailingNewline };
453
+ }
454
+ return { indentation: indent, hasTrailingNewline };
455
+ }
456
+ }
457
+ return { indentation: " ", hasTrailingNewline };
458
+ } catch {
459
+ return { indentation: " ", hasTrailingNewline: true };
460
+ }
461
+ }
462
+ function isGlobPattern(pattern) {
463
+ return /[*?[\]{}]/.test(pattern);
464
+ }
465
+
466
+ export { __toESM, __require, logTime, logger, BunupBuildError, BunupDTSBuildError, BunupCLIError, BunupWatchError, parseErrorMessage, handleError, handleErrorAndExit, JS_DTS_RE, CSS_RE, shims, ensureArray, getDefaultJsOutputExtension, getDefaultDtsOutputExtention, getPackageDeps, formatFileSize, getShortFilePath, cleanOutDir, cleanPath, formatListWithAnd, getFilesFromGlobs, isTypeScriptFile, isJavascriptFile, replaceExtension, detectFileFormatting, isGlobPattern };
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.13.4",
4
+ "version": "0.13.6",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -15,11 +15,11 @@
15
15
  "default": "./dist/index.js"
16
16
  }
17
17
  },
18
- "./cli": {
19
- "import": "./dist/cli/index.js"
20
- },
21
18
  "./plugins": {
22
- "types": "./dist/plugins.d.ts"
19
+ "import": {
20
+ "types": "./dist/plugins.d.ts",
21
+ "default": "./dist/plugins.js"
22
+ }
23
23
  },
24
24
  "./package.json": "./package.json"
25
25
  },