bunup 0.8.46 → 0.8.47
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/{chunk-0f0jc2gd.d.ts → chunk-djb64jje.d.ts} +6 -0
- package/dist/{chunk-ycxcdce7.js → chunk-ffytsq4c.js} +6 -2
- package/dist/cli/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/plugins.d.ts +10 -1
- package/dist/plugins.js +88 -61
- package/package.json +2 -16
|
@@ -27,6 +27,12 @@ type BuildMeta = {
|
|
|
27
27
|
rootDir: string
|
|
28
28
|
};
|
|
29
29
|
type BuildOutputFile = {
|
|
30
|
+
/**
|
|
31
|
+
* The entry point for which this file was generated
|
|
32
|
+
*
|
|
33
|
+
* Undefined for non-entry point files (e.g., assets, sourcemaps, chunks)
|
|
34
|
+
*/
|
|
35
|
+
entrypoint: string | undefined
|
|
30
36
|
/** The kind of the file */
|
|
31
37
|
kind: "entry-point" | "chunk" | "asset" | "sourcemap" | "bytecode"
|
|
32
38
|
/** Path to the generated file */
|
|
@@ -299,6 +299,7 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
299
299
|
else if (log.level === "info")
|
|
300
300
|
logger.info(log.message);
|
|
301
301
|
}
|
|
302
|
+
let entrypointIndex = 0;
|
|
302
303
|
for (const file of result.outputs) {
|
|
303
304
|
const relativePathToRootDir = getRelativePathToRootDir(file.path, rootDir);
|
|
304
305
|
const relativePathToOutputDir = getRelativePathToOutputDir(relativePathToRootDir, options.outDir);
|
|
@@ -313,8 +314,10 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
313
314
|
relativePathToOutputDir,
|
|
314
315
|
dts: false,
|
|
315
316
|
format: fmt,
|
|
316
|
-
kind: file.kind
|
|
317
|
+
kind: file.kind,
|
|
318
|
+
entrypoint: entrypoints[entrypointIndex]
|
|
317
319
|
});
|
|
320
|
+
entrypointIndex++;
|
|
318
321
|
}
|
|
319
322
|
});
|
|
320
323
|
await Promise.all(buildPromises);
|
|
@@ -349,7 +352,8 @@ async function build(partialOptions, rootDir = process.cwd()) {
|
|
|
349
352
|
relativePathToOutputDir,
|
|
350
353
|
dts: true,
|
|
351
354
|
format: fmt,
|
|
352
|
-
kind: file.kind
|
|
355
|
+
kind: file.kind,
|
|
356
|
+
entrypoint: file.entrypoint
|
|
353
357
|
});
|
|
354
358
|
}
|
|
355
359
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
build,
|
|
5
5
|
createBuildOptions
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-ffytsq4c.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.
|
|
31
|
+
var version = "0.8.47";
|
|
32
32
|
|
|
33
33
|
// src/watch.ts
|
|
34
34
|
import path from "path";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Arrayable, BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin } from "./chunk-
|
|
1
|
+
import { Arrayable, BuildOptions, DefineConfigItem, DefineWorkspaceItem, Plugin } from "./chunk-djb64jje";
|
|
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
package/dist/plugins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildContext, BunupPlugin, MaybePromise, Plugin } from "./chunk-
|
|
1
|
+
import { BuildContext, BunupPlugin, MaybePromise, Plugin } from "./chunk-djb64jje";
|
|
2
2
|
/**
|
|
3
3
|
* A plugin that copies files and directories to the output directory.
|
|
4
4
|
*
|
|
@@ -8,10 +8,13 @@ import { BuildContext, BunupPlugin, MaybePromise, Plugin } from "./chunk-0f0jc2g
|
|
|
8
8
|
*/
|
|
9
9
|
declare function copy(patterns: string[], outPath?: string): BunupPlugin;
|
|
10
10
|
type CustomExports = Record<string, string | Record<string, string | Record<string, string>>>;
|
|
11
|
+
type Exclude = ((ctx: BuildContext) => string[] | undefined) | string[];
|
|
11
12
|
interface ExportsPluginOptions {
|
|
12
13
|
/**
|
|
13
14
|
* Additional export fields to preserve alongside automatically generated exports
|
|
14
15
|
*
|
|
16
|
+
* @see https://bunup.dev/docs/plugins/exports#customexports
|
|
17
|
+
*
|
|
15
18
|
* @example
|
|
16
19
|
* ```ts
|
|
17
20
|
* {
|
|
@@ -25,6 +28,12 @@ interface ExportsPluginOptions {
|
|
|
25
28
|
* ```
|
|
26
29
|
*/
|
|
27
30
|
customExports?: (ctx: BuildContext) => CustomExports | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Entry points to exclude from the exports field
|
|
33
|
+
*
|
|
34
|
+
* @see https://bunup.dev/docs/plugins/exports#exclude
|
|
35
|
+
*/
|
|
36
|
+
exclude?: Exclude;
|
|
28
37
|
}
|
|
29
38
|
/**
|
|
30
39
|
* A plugin that generates the exports field in the package.json file automatically.
|
package/dist/plugins.js
CHANGED
|
@@ -49,64 +49,30 @@ function exports(options = {}) {
|
|
|
49
49
|
name: "exports",
|
|
50
50
|
hooks: {
|
|
51
51
|
onBuildDone: async (ctx) => {
|
|
52
|
-
|
|
53
|
-
if (!meta.packageJson.path || !meta.packageJson.data) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
const { exportsField, entryPoints } = generateExportsFields(output.files);
|
|
58
|
-
const files = Array.isArray(meta.packageJson.data.files) ? [
|
|
59
|
-
...new Set([
|
|
60
|
-
...meta.packageJson.data.files,
|
|
61
|
-
buildOptions.outDir
|
|
62
|
-
])
|
|
63
|
-
] : [buildOptions.outDir];
|
|
64
|
-
const mergedExports = { ...exportsField };
|
|
65
|
-
if (options.customExports) {
|
|
66
|
-
for (const [key, value] of Object.entries(options.customExports(ctx) ?? {})) {
|
|
67
|
-
if (typeof value === "string") {
|
|
68
|
-
mergedExports[key] = value;
|
|
69
|
-
} else {
|
|
70
|
-
const existingExport = mergedExports[key];
|
|
71
|
-
if (typeof existingExport === "object" && existingExport !== null) {
|
|
72
|
-
mergedExports[key] = {
|
|
73
|
-
...existingExport,
|
|
74
|
-
...value
|
|
75
|
-
};
|
|
76
|
-
} else {
|
|
77
|
-
mergedExports[key] = value;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const { main, module, types, ...restPackageJson } = meta.packageJson.data;
|
|
83
|
-
const newPackageJson = {
|
|
84
|
-
name: meta.packageJson.data.name,
|
|
85
|
-
description: meta.packageJson.data.description,
|
|
86
|
-
version: meta.packageJson.data.version,
|
|
87
|
-
type: meta.packageJson.data.type,
|
|
88
|
-
private: meta.packageJson.data.private,
|
|
89
|
-
files,
|
|
90
|
-
...entryPoints,
|
|
91
|
-
exports: mergedExports
|
|
92
|
-
};
|
|
93
|
-
for (const key in restPackageJson) {
|
|
94
|
-
if (Object.hasOwn(restPackageJson, key) && !Object.hasOwn(newPackageJson, key)) {
|
|
95
|
-
newPackageJson[key] = restPackageJson[key];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
await Bun.write(meta.packageJson.path, JSON.stringify(newPackageJson, null, 2));
|
|
99
|
-
} catch {
|
|
100
|
-
logger.error("Failed to update package.json");
|
|
101
|
-
}
|
|
52
|
+
await processPackageJsonExports(ctx, options);
|
|
102
53
|
}
|
|
103
54
|
}
|
|
104
55
|
};
|
|
105
56
|
}
|
|
106
|
-
function
|
|
57
|
+
async function processPackageJsonExports(ctx, options) {
|
|
58
|
+
const { output, options: buildOptions, meta } = ctx;
|
|
59
|
+
if (!meta.packageJson.path || !meta.packageJson.data) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const { exportsField, entryPoints } = generateExportsFields(output.files, options.exclude, ctx);
|
|
64
|
+
const updatedFiles = createUpdatedFilesArray(meta.packageJson.data, buildOptions.outDir);
|
|
65
|
+
const mergedExports = mergeCustomExportsWithGenerated(exportsField, options.customExports, ctx);
|
|
66
|
+
const newPackageJson = createUpdatedPackageJson(meta.packageJson.data, entryPoints, mergedExports, updatedFiles);
|
|
67
|
+
await Bun.write(meta.packageJson.path, JSON.stringify(newPackageJson, null, 2));
|
|
68
|
+
} catch {
|
|
69
|
+
logger.error("Failed to update package.json");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function generateExportsFields(files, exclude, ctx) {
|
|
107
73
|
const exportsField = {};
|
|
108
74
|
const entryPoints = {};
|
|
109
|
-
const filteredFiles = filterFiles(files);
|
|
75
|
+
const filteredFiles = filterFiles(files, exclude, ctx);
|
|
110
76
|
for (const file of filteredFiles) {
|
|
111
77
|
const exportType = formatToExportField(file.format, file.dts);
|
|
112
78
|
const relativePath = `./${cleanPath(file.relativePathToRootDir)}`;
|
|
@@ -122,21 +88,76 @@ function generateExportsFields(files) {
|
|
|
122
88
|
}
|
|
123
89
|
return { exportsField, entryPoints };
|
|
124
90
|
}
|
|
125
|
-
function
|
|
126
|
-
|
|
91
|
+
function createUpdatedFilesArray(packageJsonData, outDir) {
|
|
92
|
+
const existingFiles = Array.isArray(packageJsonData.files) ? packageJsonData.files : [];
|
|
93
|
+
return [...new Set([...existingFiles, outDir])];
|
|
94
|
+
}
|
|
95
|
+
function mergeCustomExportsWithGenerated(baseExports, customExportsProvider, ctx) {
|
|
96
|
+
const mergedExports = { ...baseExports };
|
|
97
|
+
if (!customExportsProvider) {
|
|
98
|
+
return mergedExports;
|
|
99
|
+
}
|
|
100
|
+
const customExports = customExportsProvider(ctx) ?? {};
|
|
101
|
+
for (const [key, value] of Object.entries(customExports)) {
|
|
102
|
+
if (typeof value === "string") {
|
|
103
|
+
mergedExports[key] = value;
|
|
104
|
+
} else {
|
|
105
|
+
const existingExport = mergedExports[key];
|
|
106
|
+
if (typeof existingExport === "object" && existingExport !== null) {
|
|
107
|
+
mergedExports[key] = {
|
|
108
|
+
...existingExport,
|
|
109
|
+
...value
|
|
110
|
+
};
|
|
111
|
+
} else {
|
|
112
|
+
mergedExports[key] = value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return mergedExports;
|
|
117
|
+
}
|
|
118
|
+
function createUpdatedPackageJson(originalData, entryPoints, exports2, files) {
|
|
119
|
+
const { main, module, types, ...restPackageJson } = originalData;
|
|
120
|
+
const newPackageJson = {
|
|
121
|
+
name: originalData.name,
|
|
122
|
+
description: originalData.description,
|
|
123
|
+
version: originalData.version,
|
|
124
|
+
type: originalData.type,
|
|
125
|
+
private: originalData.private,
|
|
126
|
+
files,
|
|
127
|
+
...entryPoints,
|
|
128
|
+
exports: exports2
|
|
129
|
+
};
|
|
130
|
+
for (const key in restPackageJson) {
|
|
131
|
+
if (Object.hasOwn(restPackageJson, key) && !Object.hasOwn(newPackageJson, key)) {
|
|
132
|
+
newPackageJson[key] = restPackageJson[key];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return newPackageJson;
|
|
136
|
+
}
|
|
137
|
+
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));
|
|
139
|
+
}
|
|
140
|
+
function isExcluded(entrypoint, exclude, ctx) {
|
|
141
|
+
if (!exclude) {
|
|
142
|
+
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;
|
|
127
154
|
}
|
|
128
155
|
function getExportKey(relativePathToOutputDir) {
|
|
129
156
|
const pathSegments = cleanPath(removeExtension(relativePathToOutputDir)).split("/");
|
|
130
157
|
if (pathSegments.length === 1 && pathSegments[0].startsWith("index")) {
|
|
131
158
|
return ".";
|
|
132
159
|
}
|
|
133
|
-
return `./${pathSegments.filter((
|
|
134
|
-
}
|
|
135
|
-
function exportFieldToEntryPoint(exportField) {
|
|
136
|
-
return exportField === "types" ? "types" : exportField === "require" ? "main" : "module";
|
|
137
|
-
}
|
|
138
|
-
function formatToExportField(format, dts) {
|
|
139
|
-
return dts ? "types" : format === "esm" ? "import" : "require";
|
|
160
|
+
return `./${pathSegments.filter((segment) => !segment.startsWith("index")).join("/")}`;
|
|
140
161
|
}
|
|
141
162
|
function removeExtension(filePath) {
|
|
142
163
|
const basename2 = path.basename(filePath);
|
|
@@ -148,6 +169,12 @@ function removeExtension(filePath) {
|
|
|
148
169
|
const directory = path.dirname(filePath);
|
|
149
170
|
return directory === "." ? nameWithoutExtensions : path.join(directory, nameWithoutExtensions);
|
|
150
171
|
}
|
|
172
|
+
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";
|
|
177
|
+
}
|
|
151
178
|
// src/plugins/built-in/inject-styles.ts
|
|
152
179
|
import path2 from "path";
|
|
153
180
|
function injectStyles(options) {
|
package/package.json
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
3
|
"description": "⚡ A blazing-fast build tool for your libraries built with Bun.",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.47",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
|
-
"
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"import": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
15
|
-
},
|
|
16
|
-
"./plugins": {
|
|
17
|
-
"import": "./dist/plugins.js",
|
|
18
|
-
"types": "./dist/plugins.d.ts"
|
|
19
|
-
},
|
|
20
|
-
"./cli": {
|
|
21
|
-
"import": "./dist/cli/index.js"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
9
|
+
"exports": {},
|
|
24
10
|
"license": "MIT",
|
|
25
11
|
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
26
12
|
"maintainers": [
|