bunup 0.8.47 → 0.8.49

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.
@@ -1,14 +1,14 @@
1
1
  // @bun
2
2
  import {
3
3
  loadPackageJson
4
- } from "./chunk-gh7z7s46.js";
4
+ } from "./chunk-5v78yfze.js";
5
5
  import {
6
6
  displayBunupGradientArt
7
- } from "./chunk-e7gp8gbh.js";
7
+ } from "./chunk-qy8akfev.js";
8
8
  import {
9
9
  formatListWithAnd,
10
10
  link
11
- } from "./chunk-a76fsvj7.js";
11
+ } from "./chunk-y0jgbvca.js";
12
12
 
13
13
  // src/cli/init.ts
14
14
  import fs from "fs";
@@ -1,4 +1,11 @@
1
- import { DtsPluginOptions } from "bun-dts";
1
+ type Resolve = boolean | (string | RegExp)[];
2
+ type GenerateDtsOptions = {
3
+ preferredTsConfigPath?: string
4
+ resolve?: Resolve
5
+ cwd?: string
6
+ splitting?: boolean
7
+ minify?: boolean
8
+ };
2
9
  import { BunPlugin } from "bun";
3
10
  type PackageJson = {
4
11
  /** The parsed content of the package.json file */
@@ -162,7 +169,9 @@ interface BuildOptions {
162
169
  * When set to true, generates declaration files for all entry points
163
170
  * Can also be configured with DtsOptions for more control
164
171
  */
165
- dts?: boolean | Pick<DtsPluginOptions, "entry" | "resolve" | "splitting" | "minify">;
172
+ dts?: boolean | (Pick<GenerateDtsOptions, "resolve" | "splitting" | "minify"> & {
173
+ entry?: string | string[]
174
+ });
166
175
  /**
167
176
  * Path to a preferred tsconfig.json file to use for declaration generation
168
177
  *
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-a76fsvj7.js";
3
+ } from "./chunk-y0jgbvca.js";
4
4
 
5
5
  // src/cli/utils.ts
6
6
  import pc from "picocolors";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BunupPluginError
3
- } from "./chunk-a76fsvj7.js";
3
+ } from "./chunk-y0jgbvca.js";
4
4
 
5
5
  // src/plugins/utils.ts
6
6
  import pc from "picocolors";
@@ -269,6 +269,18 @@ var handleErrorAndExit = (error, context) => {
269
269
  import fsSync from "fs";
270
270
  import fs from "fs/promises";
271
271
  import path, { normalize } from "path";
272
+ import { isCI, isDevelopment } from "std-env";
273
+
274
+ // src/constants/re.ts
275
+ var JS_RE = /\.(js|jsx|cjs|mjs)$/;
276
+ var TS_RE = /\.(ts|tsx|mts|cts)$/;
277
+ var DTS_RE = /\.(d\.(ts|mts|cts))$/;
278
+ var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
279
+ var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
280
+ var CSS_RE = /\.(css)$/;
281
+ var EXTENSION_REGEX = /\.(d\.(ts|cts|mts)|[cm]?[jt]s)$/;
282
+
283
+ // src/utils.ts
272
284
  function ensureArray(value) {
273
285
  return Array.isArray(value) ? value : [value];
274
286
  }
@@ -292,6 +304,13 @@ function getDefaultDtsExtention(format, packageType) {
292
304
  return ".global.d.ts";
293
305
  }
294
306
  }
307
+ function getDeclarationExtensionFromJsExtension(ext) {
308
+ if (ext === ".mjs")
309
+ return ".d.mts";
310
+ if (ext === ".cjs")
311
+ return ".d.cts";
312
+ return ".d.ts";
313
+ }
295
314
  function isModulePackage(packageType) {
296
315
  return packageType === "module";
297
316
  }
@@ -373,5 +392,38 @@ async function getFilesFromGlobs(patterns, cwd) {
373
392
  }
374
393
  return Array.from(includedFiles);
375
394
  }
395
+ function isDev() {
396
+ return isDevelopment || !isCI;
397
+ }
398
+ function generateRandomString(length = 10) {
399
+ return Array.from({ length }, () => String.fromCharCode(97 + Math.floor(Math.random() * 26))).join("");
400
+ }
401
+ function isNullOrUndefined(value) {
402
+ return value === null || value === undefined;
403
+ }
404
+ function isTypeScriptFile(path2) {
405
+ if (!path2)
406
+ return false;
407
+ return TS_RE.test(path2);
408
+ }
409
+ function getExtension(filename) {
410
+ const match = filename.match(EXTENSION_REGEX);
411
+ if (!match)
412
+ return "";
413
+ const ext = match[0];
414
+ return ext;
415
+ }
416
+ function replaceExtension(filename, newExt) {
417
+ if (EXTENSION_REGEX.test(filename)) {
418
+ return filename.replace(EXTENSION_REGEX, newExt);
419
+ }
420
+ return filename + newExt;
421
+ }
422
+ function deleteExtension(filename) {
423
+ return filename.replace(EXTENSION_REGEX, "");
424
+ }
425
+ function returnPathIfExists(path2) {
426
+ return pathExistsSync(path2) ? path2 : null;
427
+ }
376
428
 
377
- export { __toESM, __require, setSilent, logTable, link, logger, BunupBuildError, BunupCLIError, BunupWatchError, BunupPluginError, parseErrorMessage, handleError, handleErrorAndExit, ensureArray, getDefaultOutputExtension, getDefaultDtsExtention, formatTime, getPackageDeps, formatFileSize, getShortFilePath, cleanOutDir, cleanPath, isDirectoryPath, pathExistsSync, formatListWithAnd, getFilesFromGlobs };
429
+ export { __toESM, __require, JS_RE, JS_TS_RE, JS_DTS_RE, CSS_RE, setSilent, logTable, link, logger, BunupBuildError, BunupCLIError, BunupWatchError, BunupPluginError, parseErrorMessage, handleError, handleErrorAndExit, ensureArray, getDefaultOutputExtension, getDefaultDtsExtention, getDeclarationExtensionFromJsExtension, formatTime, getPackageDeps, formatFileSize, getShortFilePath, cleanOutDir, cleanPath, isDirectoryPath, pathExistsSync, formatListWithAnd, getFilesFromGlobs, isDev, generateRandomString, isNullOrUndefined, isTypeScriptFile, getExtension, replaceExtension, deleteExtension, returnPathIfExists };
package/dist/cli/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
3
  import {
4
+ BUNUP_DOCS_URL,
4
5
  build,
5
6
  createBuildOptions
6
- } from "../chunk-ffytsq4c.js";
7
- import"../chunk-snvybwa2.js";
7
+ } from "../chunk-b38k5sg1.js";
8
+ import"../chunk-t9xma3m6.js";
8
9
  import {
9
10
  processLoadedConfigs
10
- } from "../chunk-gh7z7s46.js";
11
+ } from "../chunk-5v78yfze.js";
11
12
  import {
12
13
  BunupCLIError,
13
14
  BunupWatchError,
@@ -21,14 +22,14 @@ import {
21
22
  logger,
22
23
  parseErrorMessage,
23
24
  setSilent
24
- } from "../chunk-a76fsvj7.js";
25
+ } from "../chunk-y0jgbvca.js";
25
26
 
26
27
  // src/cli/index.ts
27
28
  import { loadConfig } from "coffi";
28
29
  import pc3 from "picocolors";
29
30
  import { exec } from "tinyexec";
30
31
  // package.json
31
- var version = "0.8.47";
32
+ var version = "0.8.49";
32
33
 
33
34
  // src/watch.ts
34
35
  import path from "path";
@@ -87,11 +88,6 @@ async function watch(partialOptions, rootDir) {
87
88
 
88
89
  // src/cli/options.ts
89
90
  import pc2 from "picocolors";
90
-
91
- // src/constants/index.ts
92
- var BUNUP_DOCS_URL = "https://bunup.dev/docs";
93
-
94
- // src/cli/options.ts
95
91
  var createHandlers = () => ({
96
92
  boolean: (key) => (value, options) => {
97
93
  options[key] = value === true || value === "true";
@@ -485,12 +481,12 @@ var parseCliOptions = (argv) => {
485
481
  async function main(args = Bun.argv.slice(2)) {
486
482
  const cliOptions = parseCliOptions(args);
487
483
  if (cliOptions.new) {
488
- const { newProject } = await import("../chunk-xebwdvyv.js");
484
+ const { newProject } = await import("../chunk-63s8ht8p.js");
489
485
  await newProject();
490
486
  return;
491
487
  }
492
488
  if (cliOptions.init) {
493
- const { init } = await import("../chunk-rnbj1nec.js");
489
+ const { init } = await import("../chunk-htbpffg4.js");
494
490
  await init();
495
491
  return;
496
492
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Arrayable, BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin } from "./chunk-djb64jje";
1
+ import { Arrayable, BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin } from "./chunk-nsmdhpdd";
2
2
  declare function build(partialOptions: Partial<BuildOptions>, rootDir?: string): Promise<void>;
3
3
  declare function defineConfig(options: Arrayable<DefineConfigItem>): Arrayable<DefineConfigItem>;
4
4
  declare function defineWorkspace(options: DefineWorkspaceItem[]): DefineWorkspaceItem[];
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  // @bun
2
2
  import {
3
3
  build
4
- } from "./chunk-ffytsq4c.js";
5
- import"./chunk-snvybwa2.js";
6
- import"./chunk-gh7z7s46.js";
7
- import"./chunk-a76fsvj7.js";
4
+ } from "./chunk-b38k5sg1.js";
5
+ import"./chunk-t9xma3m6.js";
6
+ import"./chunk-5v78yfze.js";
7
+ import"./chunk-y0jgbvca.js";
8
8
  // src/define.ts
9
9
  function defineConfig(options) {
10
10
  return options;
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BuildContext, BunupPlugin, MaybePromise, Plugin } from "./chunk-djb64jje";
1
+ import { BuildContext, BunupPlugin, MaybePromise, Plugin } from "./chunk-nsmdhpdd";
2
2
  /**
3
3
  * A plugin that copies files and directories to the output directory.
4
4
  *
@@ -14,18 +14,6 @@ interface ExportsPluginOptions {
14
14
  * Additional export fields to preserve alongside automatically generated exports
15
15
  *
16
16
  * @see https://bunup.dev/docs/plugins/exports#customexports
17
- *
18
- * @example
19
- * ```ts
20
- * {
21
- * customExports: (ctx) => {
22
- * const { output, options, meta } = ctx
23
- * return {
24
- * './package.json': "package.json",
25
- * }
26
- * },
27
- * }
28
- * ```
29
17
  */
30
18
  customExports?: (ctx: BuildContext) => CustomExports | undefined;
31
19
  /**
package/dist/plugins.js CHANGED
@@ -1,12 +1,15 @@
1
1
  // @bun
2
2
  import {
3
3
  getPackageForPlugin
4
- } from "./chunk-snvybwa2.js";
4
+ } from "./chunk-t9xma3m6.js";
5
5
  import {
6
+ CSS_RE,
7
+ JS_DTS_RE,
8
+ JS_TS_RE,
6
9
  cleanPath,
7
10
  isDirectoryPath,
8
11
  logger
9
- } from "./chunk-a76fsvj7.js";
12
+ } from "./chunk-y0jgbvca.js";
10
13
 
11
14
  // src/plugins/built-in/copy.ts
12
15
  import { basename, join } from "path";
@@ -33,16 +36,6 @@ function copy(patterns, outPath) {
33
36
  }
34
37
  // src/plugins/built-in/exports.ts
35
38
  import path from "path";
36
-
37
- // src/constants/re.ts
38
- var JS_RE = /\.(js|jsx|cjs|mjs)$/;
39
- var TS_RE = /\.(ts|tsx|mts|cts)$/;
40
- var DTS_RE = /\.(d\.(ts|mts|cts))$/;
41
- var JS_TS_RE = new RegExp(`${JS_RE.source}|${TS_RE.source}`);
42
- var JS_DTS_RE = new RegExp(`${JS_RE.source}|${DTS_RE.source}`);
43
- var CSS_RE = /\.(css)$/;
44
-
45
- // src/plugins/built-in/exports.ts
46
39
  function exports(options = {}) {
47
40
  return {
48
41
  type: "bunup",
@@ -70,23 +63,116 @@ async function processPackageJsonExports(ctx, options) {
70
63
  }
71
64
  }
72
65
  function generateExportsFields(files, exclude, ctx) {
73
- const exportsField = {};
74
- const entryPoints = {};
75
66
  const filteredFiles = filterFiles(files, exclude, ctx);
76
- for (const file of filteredFiles) {
77
- const exportType = formatToExportField(file.format, file.dts);
78
- const relativePath = `./${cleanPath(file.relativePathToRootDir)}`;
67
+ const { filesByExportKey, allDtsFiles } = groupFilesByExportKey(filteredFiles);
68
+ const exportsField = createExportEntries(filesByExportKey);
69
+ const entryPoints = extractEntryPoints(exportsField, allDtsFiles);
70
+ return { exportsField, entryPoints };
71
+ }
72
+ function groupFilesByExportKey(files) {
73
+ const filesByExportKey = new Map;
74
+ const allDtsFiles = new Map;
75
+ for (const file of files) {
79
76
  const exportKey = getExportKey(cleanPath(file.relativePathToOutputDir));
80
- exportsField[exportKey] = {
81
- ...exportsField[exportKey],
82
- [exportType]: relativePath
83
- };
77
+ const format = file.format === "esm" ? "import" : "require";
78
+ if (!filesByExportKey.has(exportKey)) {
79
+ filesByExportKey.set(exportKey, new Map);
80
+ allDtsFiles.set(exportKey, []);
81
+ }
82
+ const formatMap = filesByExportKey.get(exportKey);
83
+ const dtsFiles = allDtsFiles.get(exportKey);
84
+ if (formatMap && dtsFiles) {
85
+ if (!formatMap.has(format)) {
86
+ formatMap.set(format, { dts: undefined, source: undefined });
87
+ }
88
+ const fileEntry = formatMap.get(format);
89
+ if (fileEntry) {
90
+ if (file.dts) {
91
+ fileEntry.dts = file;
92
+ dtsFiles.push(file);
93
+ } else {
94
+ fileEntry.source = file;
95
+ }
96
+ }
97
+ }
98
+ }
99
+ return { filesByExportKey, allDtsFiles };
100
+ }
101
+ function createExportEntries(filesByExportKey) {
102
+ const exportsField = {};
103
+ for (const [exportKey, formatMap] of filesByExportKey.entries()) {
104
+ exportsField[exportKey] = {};
105
+ let hasFormatSpecificTypes = false;
106
+ let primaryTypesPath;
107
+ for (const [format, files] of formatMap.entries()) {
108
+ const formatKey = format;
109
+ if (files.dts && files.source) {
110
+ exportsField[exportKey][formatKey] = {
111
+ types: `./${cleanPath(files.dts.relativePathToRootDir)}`,
112
+ default: `./${cleanPath(files.source.relativePathToRootDir)}`
113
+ };
114
+ hasFormatSpecificTypes = true;
115
+ if (!primaryTypesPath) {
116
+ primaryTypesPath = `./${cleanPath(files.dts.relativePathToRootDir)}`;
117
+ }
118
+ } else if (files.source) {
119
+ exportsField[exportKey][formatKey] = `./${cleanPath(files.source.relativePathToRootDir)}`;
120
+ if (files.dts) {
121
+ primaryTypesPath = `./${cleanPath(files.dts.relativePathToRootDir)}`;
122
+ }
123
+ } else if (files.dts) {
124
+ primaryTypesPath = `./${cleanPath(files.dts.relativePathToRootDir)}`;
125
+ }
126
+ }
127
+ if (!hasFormatSpecificTypes && primaryTypesPath) {
128
+ exportsField[exportKey].types = primaryTypesPath;
129
+ }
130
+ }
131
+ return exportsField;
132
+ }
133
+ function extractEntryPoints(exportsField, allDtsFiles) {
134
+ const entryPoints = {};
135
+ const dotExport = exportsField["."];
136
+ if (!dotExport) {
137
+ return entryPoints;
84
138
  }
85
- for (const field of Object.keys(exportsField["."] ?? {})) {
139
+ for (const [field, value] of Object.entries(dotExport)) {
140
+ if (field === "types")
141
+ continue;
86
142
  const entryPoint = exportFieldToEntryPoint(field);
87
- entryPoints[entryPoint] = exportsField["."][field];
143
+ if (typeof value === "string") {
144
+ entryPoints[entryPoint] = value;
145
+ } else if (value && typeof value === "object" && "default" in value) {
146
+ entryPoints[entryPoint] = value.default;
147
+ }
88
148
  }
89
- return { exportsField, entryPoints };
149
+ const dotEntryDtsFiles = allDtsFiles.get(".");
150
+ if (dotEntryDtsFiles?.length) {
151
+ const standardDts = findStandardDtsFile(dotEntryDtsFiles);
152
+ if (standardDts) {
153
+ entryPoints.types = `./${cleanPath(standardDts.relativePathToRootDir)}`;
154
+ } else {
155
+ entryPoints.types = extractTypesFromExport(dotExport);
156
+ }
157
+ }
158
+ return entryPoints;
159
+ }
160
+ function findStandardDtsFile(dtsFiles) {
161
+ return dtsFiles.find((file) => file.relativePathToRootDir.endsWith(".d.ts") && !file.relativePathToRootDir.endsWith(".d.mts") && !file.relativePathToRootDir.endsWith(".d.cts"));
162
+ }
163
+ function extractTypesFromExport(dotExport) {
164
+ const typesValue = dotExport.types;
165
+ if (typeof typesValue === "string") {
166
+ return typesValue;
167
+ }
168
+ if (typesValue && typeof typesValue === "object" && "types" in typesValue) {
169
+ return typesValue.types;
170
+ }
171
+ const importValue = dotExport.import;
172
+ if (importValue && typeof importValue === "object" && "types" in importValue) {
173
+ return importValue.types;
174
+ }
175
+ return;
90
176
  }
91
177
  function createUpdatedFilesArray(packageJsonData, outDir) {
92
178
  const existingFiles = Array.isArray(packageJsonData.files) ? packageJsonData.files : [];
@@ -97,17 +183,17 @@ function mergeCustomExportsWithGenerated(baseExports, customExportsProvider, ctx
97
183
  if (!customExportsProvider) {
98
184
  return mergedExports;
99
185
  }
100
- const customExports = customExportsProvider(ctx) ?? {};
186
+ const customExports = customExportsProvider(ctx);
187
+ if (!customExports) {
188
+ return mergedExports;
189
+ }
101
190
  for (const [key, value] of Object.entries(customExports)) {
102
191
  if (typeof value === "string") {
103
192
  mergedExports[key] = value;
104
193
  } else {
105
194
  const existingExport = mergedExports[key];
106
195
  if (typeof existingExport === "object" && existingExport !== null) {
107
- mergedExports[key] = {
108
- ...existingExport,
109
- ...value
110
- };
196
+ mergedExports[key] = { ...existingExport, ...value };
111
197
  } else {
112
198
  mergedExports[key] = value;
113
199
  }
@@ -135,22 +221,13 @@ function createUpdatedPackageJson(originalData, entryPoints, exports2, files) {
135
221
  return newPackageJson;
136
222
  }
137
223
  function filterFiles(files, exclude, ctx) {
138
- return files.filter((file) => JS_DTS_RE.test(file.fullPath) && file.kind === "entry-point" && file.entrypoint && !isExcluded(file.entrypoint, exclude, ctx));
224
+ return files.filter((file) => JS_DTS_RE.test(file.fullPath) && file.kind === "entry-point" && file.entrypoint && (file.format === "esm" || file.format === "cjs") && !isExcluded(file.entrypoint, exclude, ctx));
139
225
  }
140
226
  function isExcluded(entrypoint, exclude, ctx) {
141
- if (!exclude) {
227
+ if (!exclude)
142
228
  return false;
143
- }
144
- if (typeof exclude === "function") {
145
- const excluded = exclude(ctx);
146
- if (excluded) {
147
- return excluded.some((pattern) => new Bun.Glob(pattern).match(entrypoint));
148
- }
149
- }
150
- if (Array.isArray(exclude)) {
151
- return exclude.some((pattern) => new Bun.Glob(pattern).match(entrypoint));
152
- }
153
- return false;
229
+ const patterns = typeof exclude === "function" ? exclude(ctx) : exclude;
230
+ return patterns?.some((pattern) => new Bun.Glob(pattern).match(entrypoint)) ?? false;
154
231
  }
155
232
  function getExportKey(relativePathToOutputDir) {
156
233
  const pathSegments = cleanPath(removeExtension(relativePathToOutputDir)).split("/");
@@ -170,10 +247,14 @@ function removeExtension(filePath) {
170
247
  return directory === "." ? nameWithoutExtensions : path.join(directory, nameWithoutExtensions);
171
248
  }
172
249
  function exportFieldToEntryPoint(exportField) {
173
- return exportField === "types" ? "types" : exportField === "require" ? "main" : "module";
174
- }
175
- function formatToExportField(format, dts) {
176
- return dts ? "types" : format === "esm" ? "import" : "require";
250
+ switch (exportField) {
251
+ case "types":
252
+ return "types";
253
+ case "require":
254
+ return "main";
255
+ default:
256
+ return "module";
257
+ }
177
258
  }
178
259
  // src/plugins/built-in/inject-styles.ts
179
260
  import path2 from "path";
package/package.json CHANGED
@@ -1,12 +1,27 @@
1
1
  {
2
2
  "name": "bunup",
3
3
  "description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
4
- "version": "0.8.47",
4
+ "version": "0.8.49",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
9
- "exports": {},
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "./plugins": {
19
+ "import": {
20
+ "types": "./dist/plugins.d.ts",
21
+ "default": "./dist/plugins.js"
22
+ }
23
+ }
24
+ },
10
25
  "license": "MIT",
11
26
  "author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
12
27
  "maintainers": [
@@ -31,16 +46,21 @@
31
46
  "bunup": "dist/cli/index.js"
32
47
  },
33
48
  "dependencies": {
49
+ "@babel/parser": "^7.27.7",
34
50
  "@clack/prompts": "^0.10.1",
35
- "bun-dts": "^0.1.70",
36
51
  "chokidar": "^4.0.3",
37
52
  "coffi": "^0.1.31",
38
53
  "giget": "^2.0.0",
54
+ "oxc-resolver": "^11.3.0",
55
+ "oxc-transform": "^0.75.0",
39
56
  "picocolors": "^1.1.1",
40
57
  "replace-in-file": "^8.3.0",
41
- "tinyexec": "^1.0.1"
58
+ "std-env": "^3.9.0",
59
+ "tinyexec": "^1.0.1",
60
+ "ts-import-resolver": "^0.1.22"
42
61
  },
43
62
  "devDependencies": {
63
+ "@babel/types": "^7.27.7",
44
64
  "@biomejs/biome": "2.0.0",
45
65
  "@types/bun": "^1.2.5",
46
66
  "bumpp": "^10.1.0",