bunup 0.8.47 → 0.8.48

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.
@@ -315,9 +315,11 @@ async function build(partialOptions, rootDir = process.cwd()) {
315
315
  dts: false,
316
316
  format: fmt,
317
317
  kind: file.kind,
318
- entrypoint: entrypoints[entrypointIndex]
318
+ entrypoint: file.kind === "entry-point" ? cleanPath(entrypoints[entrypointIndex]) : undefined
319
319
  });
320
- entrypointIndex++;
320
+ if (file.kind === "entry-point") {
321
+ entrypointIndex++;
322
+ }
321
323
  }
322
324
  });
323
325
  await Promise.all(buildPromises);
@@ -353,7 +355,7 @@ async function build(partialOptions, rootDir = process.cwd()) {
353
355
  dts: true,
354
356
  format: fmt,
355
357
  kind: file.kind,
356
- entrypoint: file.entrypoint
358
+ entrypoint: file.entrypoint ? cleanPath(file.entrypoint) : undefined
357
359
  });
358
360
  }
359
361
  }
package/dist/cli/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  build,
5
5
  createBuildOptions
6
- } from "../chunk-ffytsq4c.js";
6
+ } from "../chunk-kpthwads.js";
7
7
  import"../chunk-snvybwa2.js";
8
8
  import {
9
9
  processLoadedConfigs
@@ -28,7 +28,7 @@ import { loadConfig } from "coffi";
28
28
  import pc3 from "picocolors";
29
29
  import { exec } from "tinyexec";
30
30
  // package.json
31
- var version = "0.8.47";
31
+ var version = "0.8.48";
32
32
 
33
33
  // src/watch.ts
34
34
  import path from "path";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  build
4
- } from "./chunk-ffytsq4c.js";
4
+ } from "./chunk-kpthwads.js";
5
5
  import"./chunk-snvybwa2.js";
6
6
  import"./chunk-gh7z7s46.js";
7
7
  import"./chunk-a76fsvj7.js";
package/dist/plugins.d.ts CHANGED
@@ -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
@@ -70,23 +70,116 @@ async function processPackageJsonExports(ctx, options) {
70
70
  }
71
71
  }
72
72
  function generateExportsFields(files, exclude, ctx) {
73
- const exportsField = {};
74
- const entryPoints = {};
75
73
  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)}`;
74
+ const { filesByExportKey, allDtsFiles } = groupFilesByExportKey(filteredFiles);
75
+ const exportsField = createExportEntries(filesByExportKey);
76
+ const entryPoints = extractEntryPoints(exportsField, allDtsFiles);
77
+ return { exportsField, entryPoints };
78
+ }
79
+ function groupFilesByExportKey(files) {
80
+ const filesByExportKey = new Map;
81
+ const allDtsFiles = new Map;
82
+ for (const file of files) {
79
83
  const exportKey = getExportKey(cleanPath(file.relativePathToOutputDir));
80
- exportsField[exportKey] = {
81
- ...exportsField[exportKey],
82
- [exportType]: relativePath
83
- };
84
+ const format = file.format === "esm" ? "import" : "require";
85
+ if (!filesByExportKey.has(exportKey)) {
86
+ filesByExportKey.set(exportKey, new Map);
87
+ allDtsFiles.set(exportKey, []);
88
+ }
89
+ const formatMap = filesByExportKey.get(exportKey);
90
+ const dtsFiles = allDtsFiles.get(exportKey);
91
+ if (formatMap && dtsFiles) {
92
+ if (!formatMap.has(format)) {
93
+ formatMap.set(format, { dts: undefined, source: undefined });
94
+ }
95
+ const fileEntry = formatMap.get(format);
96
+ if (fileEntry) {
97
+ if (file.dts) {
98
+ fileEntry.dts = file;
99
+ dtsFiles.push(file);
100
+ } else {
101
+ fileEntry.source = file;
102
+ }
103
+ }
104
+ }
105
+ }
106
+ return { filesByExportKey, allDtsFiles };
107
+ }
108
+ function createExportEntries(filesByExportKey) {
109
+ const exportsField = {};
110
+ for (const [exportKey, formatMap] of filesByExportKey.entries()) {
111
+ exportsField[exportKey] = {};
112
+ let hasFormatSpecificTypes = false;
113
+ let primaryTypesPath;
114
+ for (const [format, files] of formatMap.entries()) {
115
+ const formatKey = format;
116
+ if (files.dts && files.source) {
117
+ exportsField[exportKey][formatKey] = {
118
+ types: `./${cleanPath(files.dts.relativePathToRootDir)}`,
119
+ default: `./${cleanPath(files.source.relativePathToRootDir)}`
120
+ };
121
+ hasFormatSpecificTypes = true;
122
+ if (!primaryTypesPath) {
123
+ primaryTypesPath = `./${cleanPath(files.dts.relativePathToRootDir)}`;
124
+ }
125
+ } else if (files.source) {
126
+ exportsField[exportKey][formatKey] = `./${cleanPath(files.source.relativePathToRootDir)}`;
127
+ if (files.dts) {
128
+ primaryTypesPath = `./${cleanPath(files.dts.relativePathToRootDir)}`;
129
+ }
130
+ } else if (files.dts) {
131
+ primaryTypesPath = `./${cleanPath(files.dts.relativePathToRootDir)}`;
132
+ }
133
+ }
134
+ if (!hasFormatSpecificTypes && primaryTypesPath) {
135
+ exportsField[exportKey].types = primaryTypesPath;
136
+ }
137
+ }
138
+ return exportsField;
139
+ }
140
+ function extractEntryPoints(exportsField, allDtsFiles) {
141
+ const entryPoints = {};
142
+ const dotExport = exportsField["."];
143
+ if (!dotExport) {
144
+ return entryPoints;
84
145
  }
85
- for (const field of Object.keys(exportsField["."] ?? {})) {
146
+ for (const [field, value] of Object.entries(dotExport)) {
147
+ if (field === "types")
148
+ continue;
86
149
  const entryPoint = exportFieldToEntryPoint(field);
87
- entryPoints[entryPoint] = exportsField["."][field];
150
+ if (typeof value === "string") {
151
+ entryPoints[entryPoint] = value;
152
+ } else if (value && typeof value === "object" && "default" in value) {
153
+ entryPoints[entryPoint] = value.default;
154
+ }
88
155
  }
89
- return { exportsField, entryPoints };
156
+ const dotEntryDtsFiles = allDtsFiles.get(".");
157
+ if (dotEntryDtsFiles?.length) {
158
+ const standardDts = findStandardDtsFile(dotEntryDtsFiles);
159
+ if (standardDts) {
160
+ entryPoints.types = `./${cleanPath(standardDts.relativePathToRootDir)}`;
161
+ } else {
162
+ entryPoints.types = extractTypesFromExport(dotExport);
163
+ }
164
+ }
165
+ return entryPoints;
166
+ }
167
+ function findStandardDtsFile(dtsFiles) {
168
+ return dtsFiles.find((file) => file.relativePathToRootDir.endsWith(".d.ts") && !file.relativePathToRootDir.endsWith(".d.mts") && !file.relativePathToRootDir.endsWith(".d.cts"));
169
+ }
170
+ function extractTypesFromExport(dotExport) {
171
+ const typesValue = dotExport.types;
172
+ if (typeof typesValue === "string") {
173
+ return typesValue;
174
+ }
175
+ if (typesValue && typeof typesValue === "object" && "types" in typesValue) {
176
+ return typesValue.types;
177
+ }
178
+ const importValue = dotExport.import;
179
+ if (importValue && typeof importValue === "object" && "types" in importValue) {
180
+ return importValue.types;
181
+ }
182
+ return;
90
183
  }
91
184
  function createUpdatedFilesArray(packageJsonData, outDir) {
92
185
  const existingFiles = Array.isArray(packageJsonData.files) ? packageJsonData.files : [];
@@ -97,17 +190,17 @@ function mergeCustomExportsWithGenerated(baseExports, customExportsProvider, ctx
97
190
  if (!customExportsProvider) {
98
191
  return mergedExports;
99
192
  }
100
- const customExports = customExportsProvider(ctx) ?? {};
193
+ const customExports = customExportsProvider(ctx);
194
+ if (!customExports) {
195
+ return mergedExports;
196
+ }
101
197
  for (const [key, value] of Object.entries(customExports)) {
102
198
  if (typeof value === "string") {
103
199
  mergedExports[key] = value;
104
200
  } else {
105
201
  const existingExport = mergedExports[key];
106
202
  if (typeof existingExport === "object" && existingExport !== null) {
107
- mergedExports[key] = {
108
- ...existingExport,
109
- ...value
110
- };
203
+ mergedExports[key] = { ...existingExport, ...value };
111
204
  } else {
112
205
  mergedExports[key] = value;
113
206
  }
@@ -135,22 +228,13 @@ function createUpdatedPackageJson(originalData, entryPoints, exports2, files) {
135
228
  return newPackageJson;
136
229
  }
137
230
  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));
231
+ 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
232
  }
140
233
  function isExcluded(entrypoint, exclude, ctx) {
141
- if (!exclude) {
234
+ if (!exclude)
142
235
  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;
236
+ const patterns = typeof exclude === "function" ? exclude(ctx) : exclude;
237
+ return patterns?.some((pattern) => new Bun.Glob(pattern).match(entrypoint)) ?? false;
154
238
  }
155
239
  function getExportKey(relativePathToOutputDir) {
156
240
  const pathSegments = cleanPath(removeExtension(relativePathToOutputDir)).split("/");
@@ -170,10 +254,14 @@ function removeExtension(filePath) {
170
254
  return directory === "." ? nameWithoutExtensions : path.join(directory, nameWithoutExtensions);
171
255
  }
172
256
  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";
257
+ switch (exportField) {
258
+ case "types":
259
+ return "types";
260
+ case "require":
261
+ return "main";
262
+ default:
263
+ return "module";
264
+ }
177
265
  }
178
266
  // src/plugins/built-in/inject-styles.ts
179
267
  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.48",
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": [