bunup 0.15.3 → 0.15.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 +12 -11
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +1 -1
- package/dist/shared/{bunup-04me8aq6.js → bunup-1dt09a96.js} +30 -19
- package/dist/shared/{bunup-zhf51h48.d.ts → bunup-daehgh3v.d.ts} +52 -18
- package/dist/shared/{bunup-wssv441a.js → bunup-k8ycyv8v.js} +66 -22
- package/package.json +4 -4
package/dist/cli/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
build,
|
|
5
5
|
processLoadedConfigs,
|
|
6
6
|
resolveBuildOptions
|
|
7
|
-
} from "../shared/bunup-
|
|
7
|
+
} from "../shared/bunup-1dt09a96.js";
|
|
8
8
|
import {
|
|
9
9
|
BunupCLIError,
|
|
10
10
|
BunupWatchError,
|
|
@@ -20,24 +20,24 @@ import {
|
|
|
20
20
|
logTime,
|
|
21
21
|
logger,
|
|
22
22
|
parseErrorMessage
|
|
23
|
-
} from "../shared/bunup-
|
|
23
|
+
} from "../shared/bunup-k8ycyv8v.js";
|
|
24
24
|
|
|
25
25
|
// packages/bunup/src/cli/index.ts
|
|
26
26
|
import { loadConfig } from "coffi";
|
|
27
27
|
import pc4 from "picocolors";
|
|
28
28
|
// packages/bunup/package.json
|
|
29
|
-
var version = "0.15.
|
|
29
|
+
var version = "0.15.6";
|
|
30
30
|
|
|
31
31
|
// packages/bunup/src/printer/print-build-report.ts
|
|
32
32
|
import { promisify } from "util";
|
|
33
33
|
import { brotliCompress } from "zlib";
|
|
34
34
|
import pc from "picocolors";
|
|
35
35
|
var brotliAsync = promisify(brotliCompress);
|
|
36
|
-
async function printBuildReport(
|
|
37
|
-
const options =
|
|
36
|
+
async function printBuildReport(buildResult) {
|
|
37
|
+
const options = buildResult.build.options;
|
|
38
38
|
const { gzip = true, brotli = false, maxBundleSize } = options.report ?? {};
|
|
39
39
|
const showCompression = gzip || brotli;
|
|
40
|
-
const files = await Promise.all(
|
|
40
|
+
const files = await Promise.all(buildResult.files.map(async (file) => {
|
|
41
41
|
const pathRelative = file.pathRelativeToOutdir;
|
|
42
42
|
const size = file.size;
|
|
43
43
|
const isDts = file.dts && file.kind === "entry-point";
|
|
@@ -193,8 +193,8 @@ async function watch(userOptions, rootDir, configFilePath) {
|
|
|
193
193
|
${buildCount > 1 ? pc2.magentaBright(`[x${buildCount}] `) : ""}${pc2.green(`Changed:`)} ${changed}${options.name ? ` ${pc2.bgBlueBright(` ${options.name} `)}` : ""}`);
|
|
194
194
|
}
|
|
195
195
|
const start = performance.now();
|
|
196
|
-
const
|
|
197
|
-
await printBuildReport(
|
|
196
|
+
const buildResult = await build(userOptions, rootDir);
|
|
197
|
+
await printBuildReport(buildResult);
|
|
198
198
|
if (!initial) {
|
|
199
199
|
console.log(`
|
|
200
200
|
${pc2.green("\u2713")} Rebuild completed in ${pc2.green(logTime(performance.now() - start))}`);
|
|
@@ -275,6 +275,7 @@ var program = cli().name("bunup").version(version).description("A blazing-fast b
|
|
|
275
275
|
development: z.boolean().describe("Use jsx-dev runtime for development").optional()
|
|
276
276
|
}).describe("Configure JSX transform behavior").optional()).option("ignore-dce-annotations", z.boolean().describe("Ignore dead code elimination annotations (@__PURE__, sideEffects)")).option("emit-dce-annotations", z.boolean().describe("Force emit @__PURE__ annotations even with minification")).option("on-success", z.string().describe("Command to run after successful build").optional()).option("exports", z.union(z.boolean(), z.object({
|
|
277
277
|
exclude: z.array(z.string()).describe("Entry points to exclude from exports field").optional(),
|
|
278
|
+
"exclude-cli": z.boolean().describe("Whether to exclude CLI entry points (cli/bin files) from exports field").default(true),
|
|
278
279
|
"exclude-css": z.boolean().describe("Whether to exclude CSS files from exports field").optional(),
|
|
279
280
|
"include-package-json": z.boolean().describe('Whether to include "./package.json" in exports field').default(true),
|
|
280
281
|
all: z.boolean().describe("Whether to add wildcard export for deep imports").optional()
|
|
@@ -330,7 +331,7 @@ async function main(args = Bun.argv.slice(2)) {
|
|
|
330
331
|
}
|
|
331
332
|
logger.info("Build started");
|
|
332
333
|
const startTime = performance.now();
|
|
333
|
-
const
|
|
334
|
+
const buildResults = [];
|
|
334
335
|
await Promise.all(configsToProcess.flatMap(({ options, rootDir }) => {
|
|
335
336
|
const optionsArray = ensureArray(options);
|
|
336
337
|
return optionsArray.map(async (o) => {
|
|
@@ -341,13 +342,13 @@ async function main(args = Bun.argv.slice(2)) {
|
|
|
341
342
|
if (userOptions.watch) {
|
|
342
343
|
await watch(userOptions, rootDir, filepath);
|
|
343
344
|
} else {
|
|
344
|
-
|
|
345
|
+
buildResults.push(await build(userOptions, rootDir));
|
|
345
346
|
}
|
|
346
347
|
});
|
|
347
348
|
}));
|
|
348
349
|
const buildTimeMs = performance.now() - startTime;
|
|
349
350
|
if (!cliOptions.watch && !shouldSilent) {
|
|
350
|
-
await Promise.all(
|
|
351
|
+
await Promise.all(buildResults.map((o) => printBuildReport(o)));
|
|
351
352
|
}
|
|
352
353
|
if (cliOptions.watch) {
|
|
353
354
|
console.log(`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BuildContext, BuildMeta, BuildOptions,
|
|
2
|
-
declare function build(userOptions: Partial<BuildOptions>, rootDir?: string): Promise<
|
|
1
|
+
import { BuildContext, BuildMeta, BuildOptions, BuildOutputFile, BuildResult, BunupPlugin, DefineConfigItem, DefineWorkspaceItem, WithOptional, WithRequired } from "./shared/bunup-daehgh3v";
|
|
2
|
+
declare function build(userOptions: Partial<BuildOptions>, rootDir?: string): Promise<BuildResult>;
|
|
3
3
|
declare function defineConfig(options: DefineConfigItem | WithRequired<DefineConfigItem, "name">[]): DefineConfigItem | WithRequired<DefineConfigItem, "name">[];
|
|
4
4
|
declare function defineWorkspace(options: WithOptional<DefineWorkspaceItem, "config">[], sharedOptions?: Partial<DefineConfigItem>): DefineWorkspaceItem[];
|
|
5
|
-
export { defineWorkspace, defineConfig, build, DefineWorkspaceItem, DefineConfigItem, BunupPlugin,
|
|
5
|
+
export { defineWorkspace, defineConfig, build, DefineWorkspaceItem, DefineConfigItem, BunupPlugin, BuildResult, BuildOutputFile, BuildOptions, BuildMeta, BuildContext };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
build
|
|
4
|
-
} from "./shared/bunup-
|
|
5
|
-
import"./shared/bunup-
|
|
4
|
+
} from "./shared/bunup-1dt09a96.js";
|
|
5
|
+
import"./shared/bunup-k8ycyv8v.js";
|
|
6
6
|
// packages/bunup/src/define.ts
|
|
7
7
|
function defineConfig(options) {
|
|
8
8
|
return options;
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildOptions, BunupPlugin, BunupPluginHooks, exports, injectStyles, unused } from "./shared/bunup-
|
|
1
|
+
import { BuildOptions, BunupPlugin, BunupPluginHooks, exports, injectStyles, unused } from "./shared/bunup-daehgh3v";
|
|
2
2
|
type CopyOptions = {
|
|
3
3
|
/** Whether to follow symbolic links when copying files. */
|
|
4
4
|
followSymlinks?: boolean;
|
package/dist/plugins.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
parseErrorMessage,
|
|
21
21
|
shims,
|
|
22
22
|
unused
|
|
23
|
-
} from "./bunup-
|
|
23
|
+
} from "./bunup-k8ycyv8v.js";
|
|
24
24
|
|
|
25
25
|
// packages/bunup/src/loaders.ts
|
|
26
26
|
import path from "path";
|
|
@@ -205,8 +205,8 @@ function useClient() {
|
|
|
205
205
|
return {
|
|
206
206
|
name: "use-client",
|
|
207
207
|
hooks: {
|
|
208
|
-
onBuildDone: async ({
|
|
209
|
-
for (const file of
|
|
208
|
+
onBuildDone: async ({ files }) => {
|
|
209
|
+
for (const file of files) {
|
|
210
210
|
let text = await Bun.file(file.fullPath).text();
|
|
211
211
|
const hasUseClient = text.split(`
|
|
212
212
|
`).some((line) => line.trim().startsWith(`"use client";`));
|
|
@@ -327,21 +327,21 @@ function filterBunupPlugins(plugins) {
|
|
|
327
327
|
return [];
|
|
328
328
|
return plugins.filter((p) => ("hooks" in p));
|
|
329
329
|
}
|
|
330
|
-
async function runPluginBuildStartHooks(bunupPlugins,
|
|
330
|
+
async function runPluginBuildStartHooks(bunupPlugins, ctx) {
|
|
331
331
|
if (!bunupPlugins)
|
|
332
332
|
return;
|
|
333
333
|
for (const plugin of bunupPlugins) {
|
|
334
334
|
if (plugin.hooks.onBuildStart) {
|
|
335
|
-
await plugin.hooks.onBuildStart(
|
|
335
|
+
await plugin.hooks.onBuildStart(ctx);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
|
-
async function runPluginBuildDoneHooks(bunupPlugins,
|
|
339
|
+
async function runPluginBuildDoneHooks(bunupPlugins, ctx) {
|
|
340
340
|
if (!bunupPlugins)
|
|
341
341
|
return;
|
|
342
342
|
for (const plugin of bunupPlugins) {
|
|
343
343
|
if (plugin.hooks.onBuildDone) {
|
|
344
|
-
await plugin.hooks.onBuildDone(
|
|
344
|
+
await plugin.hooks.onBuildDone(ctx);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
}
|
|
@@ -397,10 +397,6 @@ async function build(userOptions, rootDir = process.cwd()) {
|
|
|
397
397
|
}
|
|
398
398
|
ac = new AbortController;
|
|
399
399
|
const options = resolveBuildOptions(userOptions);
|
|
400
|
-
const buildOutput = {
|
|
401
|
-
files: [],
|
|
402
|
-
options
|
|
403
|
-
};
|
|
404
400
|
if (options.silent) {
|
|
405
401
|
logger.setSilent(options.silent);
|
|
406
402
|
}
|
|
@@ -419,7 +415,7 @@ async function build(userOptions, rootDir = process.cwd()) {
|
|
|
419
415
|
const allPlugins = resolvePlugins(options, packageJson.data);
|
|
420
416
|
const bunupPlugins = filterBunupPlugins(allPlugins);
|
|
421
417
|
const bunPlugins = filterBunPlugins(allPlugins);
|
|
422
|
-
await runPluginBuildStartHooks(bunupPlugins, options);
|
|
418
|
+
await runPluginBuildStartHooks(bunupPlugins, { options });
|
|
423
419
|
const entryArray = ensureArray(options.entry);
|
|
424
420
|
const entrypoints = getFilesFromGlobs(entryArray, rootDir);
|
|
425
421
|
if (!entrypoints.length) {
|
|
@@ -433,6 +429,7 @@ async function build(userOptions, rootDir = process.cwd()) {
|
|
|
433
429
|
once: options.name,
|
|
434
430
|
muted: true
|
|
435
431
|
});
|
|
432
|
+
const buildOutputFiles = [];
|
|
436
433
|
const absoluteEntrypoints = entrypoints.map((file) => `${rootDir}/${file}`);
|
|
437
434
|
const resolvedDefine = getResolvedDefine(options.define, options.env);
|
|
438
435
|
const resolvedMinify = getResolvedMinify(options);
|
|
@@ -484,8 +481,8 @@ async function build(userOptions, rootDir = process.cwd()) {
|
|
|
484
481
|
const pathRelativeToRootDir = path2.join(options.outDir, pathRelativeToOutdir);
|
|
485
482
|
const fullPath = path2.resolve(rootDir, pathRelativeToRootDir);
|
|
486
483
|
await Bun.write(fullPath, content);
|
|
487
|
-
if (!
|
|
488
|
-
|
|
484
|
+
if (!buildOutputFiles.some((f) => f.fullPath === fullPath)) {
|
|
485
|
+
buildOutputFiles.push({
|
|
489
486
|
fullPath,
|
|
490
487
|
pathRelativeToRootDir,
|
|
491
488
|
pathRelativeToOutdir,
|
|
@@ -524,7 +521,7 @@ async function build(userOptions, rootDir = process.cwd()) {
|
|
|
524
521
|
const pathRelativeToRootDir = cleanPath(`${options.outDir}/${pathRelativeToOutdir}`);
|
|
525
522
|
const fullPath = path2.join(rootDir, pathRelativeToRootDir);
|
|
526
523
|
await Bun.write(fullPath, file.dts);
|
|
527
|
-
|
|
524
|
+
buildOutputFiles.push({
|
|
528
525
|
fullPath,
|
|
529
526
|
pathRelativeToRootDir,
|
|
530
527
|
pathRelativeToOutdir,
|
|
@@ -540,14 +537,28 @@ async function build(userOptions, rootDir = process.cwd()) {
|
|
|
540
537
|
throw new BunupDTSBuildError(parseErrorMessage(error));
|
|
541
538
|
}
|
|
542
539
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
540
|
+
const buildResult = {
|
|
541
|
+
files: buildOutputFiles,
|
|
542
|
+
build: {
|
|
543
|
+
options,
|
|
544
|
+
meta: {
|
|
545
|
+
packageJson,
|
|
546
|
+
rootDir
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
await runPluginBuildDoneHooks(bunupPlugins, {
|
|
551
|
+
files: buildOutputFiles,
|
|
552
|
+
options,
|
|
553
|
+
meta: {
|
|
554
|
+
packageJson,
|
|
555
|
+
rootDir
|
|
556
|
+
}
|
|
546
557
|
});
|
|
547
558
|
if (options.onSuccess) {
|
|
548
559
|
await executeOnSuccess(options.onSuccess, options, ac.signal);
|
|
549
560
|
}
|
|
550
|
-
return
|
|
561
|
+
return buildResult;
|
|
551
562
|
}
|
|
552
563
|
|
|
553
564
|
export { processLoadedConfigs, resolveBuildOptions, build };
|
|
@@ -38,39 +38,54 @@ type BuildOutputFile = {
|
|
|
38
38
|
size: number;
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* Build configuration and metadata used during build execution.
|
|
42
42
|
*/
|
|
43
|
-
type
|
|
44
|
-
/**
|
|
43
|
+
type BuildContext = {
|
|
44
|
+
/** Build configuration options that were used */
|
|
45
|
+
options: BuildOptions;
|
|
46
|
+
/** Build execution metadata */
|
|
47
|
+
meta: BuildMeta;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Build output containing generated files and build context.
|
|
51
|
+
*/
|
|
52
|
+
type BuildResult = {
|
|
53
|
+
/** Generated output files */
|
|
45
54
|
files: BuildOutputFile[];
|
|
46
|
-
/**
|
|
55
|
+
/** Build configuration and metadata that were used */
|
|
56
|
+
build: BuildContext;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Context provided when build starts.
|
|
60
|
+
*/
|
|
61
|
+
type OnBuildStartCtx = {
|
|
62
|
+
/** Build configuration options that will be used */
|
|
47
63
|
options: BuildOptions;
|
|
48
64
|
};
|
|
49
65
|
/**
|
|
50
|
-
* Context provided
|
|
66
|
+
* Context provided when build completes.
|
|
67
|
+
* Flattened structure for easy access in plugin hooks.
|
|
51
68
|
*/
|
|
52
|
-
type
|
|
53
|
-
/**
|
|
69
|
+
type OnBuildDoneCtx = {
|
|
70
|
+
/** Generated output files */
|
|
71
|
+
files: BuildOutputFile[];
|
|
72
|
+
/** Build configuration options that were used */
|
|
54
73
|
options: BuildOptions;
|
|
55
|
-
/**
|
|
56
|
-
output: BuildOutput;
|
|
57
|
-
/** The meta data of the build */
|
|
74
|
+
/** Build execution metadata */
|
|
58
75
|
meta: BuildMeta;
|
|
59
76
|
};
|
|
60
77
|
/**
|
|
61
|
-
* Hooks that can be implemented by Bunup plugins
|
|
78
|
+
* Hooks that can be implemented by Bunup plugins.
|
|
62
79
|
*/
|
|
63
80
|
type BunupPluginHooks = {
|
|
64
81
|
/**
|
|
65
|
-
* Called when a build is successfully completed
|
|
66
|
-
* @param ctx Build context containing options and output
|
|
82
|
+
* Called when a build is successfully completed.
|
|
67
83
|
*/
|
|
68
|
-
onBuildDone?: (ctx:
|
|
84
|
+
onBuildDone?: (ctx: OnBuildDoneCtx) => MaybePromise<void>;
|
|
69
85
|
/**
|
|
70
|
-
* Called before a build starts
|
|
71
|
-
* @param options Build options that will be used
|
|
86
|
+
* Called before a build starts.
|
|
72
87
|
*/
|
|
73
|
-
onBuildStart?: (
|
|
88
|
+
onBuildStart?: (ctx: OnBuildStartCtx) => MaybePromise<void>;
|
|
74
89
|
};
|
|
75
90
|
/**
|
|
76
91
|
* Represents a Bunup-specific plugin
|
|
@@ -97,6 +112,25 @@ interface ExportsOptions {
|
|
|
97
112
|
*/
|
|
98
113
|
exclude?: Exclude2;
|
|
99
114
|
/**
|
|
115
|
+
* Whether to automatically exclude CLI entry points from the exports field
|
|
116
|
+
*
|
|
117
|
+
* When enabled (default), CLI-related entry points are automatically excluded
|
|
118
|
+
* from package exports since they are typically used for binaries and should
|
|
119
|
+
* not be exposed as importable package exports.
|
|
120
|
+
*
|
|
121
|
+
* The plugin uses glob patterns to match common CLI entry point patterns:
|
|
122
|
+
* - Files or directories named "cli" (e.g., `cli.ts`, `cli/index.ts`)
|
|
123
|
+
* - Files or directories named "bin" (e.g., `bin.ts`, `bin/index.ts`)
|
|
124
|
+
* - CLI-related paths in src directory (e.g., `src/cli.ts`, `src/bin/index.ts`)
|
|
125
|
+
*
|
|
126
|
+
* If you want to include CLI entries in your exports, set this to `false` and
|
|
127
|
+
* optionally use the `exclude` option for more granular control.
|
|
128
|
+
*
|
|
129
|
+
* @default true
|
|
130
|
+
* @see https://bunup.dev/docs/extra-options/exports#excludecli
|
|
131
|
+
*/
|
|
132
|
+
excludeCli?: boolean;
|
|
133
|
+
/**
|
|
100
134
|
* Whether to exclude CSS files from being added to the exports field
|
|
101
135
|
*
|
|
102
136
|
* @default false
|
|
@@ -642,4 +676,4 @@ type DefineWorkspaceItem = {
|
|
|
642
676
|
root: string;
|
|
643
677
|
config?: DefineConfigItem | WithRequired<DefineConfigItem, "name">[];
|
|
644
678
|
};
|
|
645
|
-
export { WithOptional, WithRequired, DefineConfigItem, DefineWorkspaceItem, BuildMeta, BuildOutputFile,
|
|
679
|
+
export { WithOptional, WithRequired, DefineConfigItem, DefineWorkspaceItem, BuildMeta, BuildOutputFile, BuildContext, BuildResult, BunupPluginHooks, BunupPlugin, exports, injectStyles, unused, BuildOptions };
|
|
@@ -369,6 +369,7 @@ var handleErrorAndExit = (error, context) => {
|
|
|
369
369
|
|
|
370
370
|
// packages/bunup/src/plugins/exports.ts
|
|
371
371
|
import path2 from "path";
|
|
372
|
+
import pc3 from "picocolors";
|
|
372
373
|
|
|
373
374
|
// packages/bunup/src/constants/re.ts
|
|
374
375
|
var JS_RE = /\.(js|jsx|cjs|mjs)$/;
|
|
@@ -465,16 +466,17 @@ function exports(options = {}) {
|
|
|
465
466
|
};
|
|
466
467
|
}
|
|
467
468
|
async function processPackageJsonExports(ctx, options) {
|
|
468
|
-
const {
|
|
469
|
+
const { files, options: buildOptions, meta } = ctx;
|
|
469
470
|
if (!meta.packageJson.path || !meta.packageJson.data) {
|
|
470
471
|
return;
|
|
471
472
|
}
|
|
472
473
|
try {
|
|
473
|
-
const { exportsField, entryPoints } = generateExportsFields(
|
|
474
|
+
const { exportsField, entryPoints } = generateExportsFields(files, options.exclude, options.excludeCli, options.excludeCss, ctx);
|
|
474
475
|
const updatedFiles = createUpdatedFilesArray(meta.packageJson.data, buildOptions.outDir);
|
|
475
476
|
const mergedExports = mergeCustomExportsWithGenerated(exportsField, options.customExports, ctx);
|
|
476
477
|
const finalExports = addPackageJsonOrWildcardExport(mergedExports, options.includePackageJson, options.all);
|
|
477
478
|
const newPackageJson = createUpdatedPackageJson(meta.packageJson.data, entryPoints, finalExports, updatedFiles);
|
|
479
|
+
await validateBinFields(meta.packageJson.data, buildOptions.name, meta.packageJson.path, meta.rootDir);
|
|
478
480
|
if (Bun.deepEquals(newPackageJson, meta.packageJson.data)) {
|
|
479
481
|
return;
|
|
480
482
|
}
|
|
@@ -489,8 +491,8 @@ async function processPackageJsonExports(ctx, options) {
|
|
|
489
491
|
logger.error("Failed to update package.json");
|
|
490
492
|
}
|
|
491
493
|
}
|
|
492
|
-
function generateExportsFields(files, exclude, excludeCss, ctx) {
|
|
493
|
-
const filteredFiles = filterFiles(files, exclude, ctx);
|
|
494
|
+
function generateExportsFields(files, exclude, excludeCli, excludeCss, ctx) {
|
|
495
|
+
const filteredFiles = filterFiles(files, exclude, excludeCli, ctx);
|
|
494
496
|
const { filesByExportKey, allDtsFiles, cssFiles } = groupFilesByExportKey(filteredFiles);
|
|
495
497
|
const exportsField = createExportEntries(filesByExportKey);
|
|
496
498
|
if (!excludeCss) {
|
|
@@ -618,7 +620,10 @@ function mergeCustomExportsWithGenerated(baseExports, customExportsProvider, ctx
|
|
|
618
620
|
if (!customExportsProvider) {
|
|
619
621
|
return mergedExports;
|
|
620
622
|
}
|
|
621
|
-
const customExports = customExportsProvider(
|
|
623
|
+
const customExports = customExportsProvider({
|
|
624
|
+
options: ctx.options,
|
|
625
|
+
meta: ctx.meta
|
|
626
|
+
});
|
|
622
627
|
if (!customExports) {
|
|
623
628
|
return mergedExports;
|
|
624
629
|
}
|
|
@@ -657,18 +662,19 @@ function createUpdatedPackageJson(originalData, entryPoints, exports2, files) {
|
|
|
657
662
|
}
|
|
658
663
|
return newPackageJson;
|
|
659
664
|
}
|
|
660
|
-
function filterFiles(files, exclude, ctx) {
|
|
661
|
-
return files.filter((file) => (JS_DTS_RE.test(file.fullPath) || CSS_RE.test(file.fullPath)) && (file.kind === "entry-point" || file.kind === "asset") && (file.format === "esm" || file.format === "cjs" || CSS_RE.test(file.fullPath)) && (!file.entrypoint || !isExcluded(file.entrypoint, exclude, ctx)));
|
|
665
|
+
function filterFiles(files, exclude, excludeCli, ctx) {
|
|
666
|
+
return files.filter((file) => (JS_DTS_RE.test(file.fullPath) || CSS_RE.test(file.fullPath)) && (file.kind === "entry-point" || file.kind === "asset") && (file.format === "esm" || file.format === "cjs" || CSS_RE.test(file.fullPath)) && (!file.entrypoint || !isExcluded(file.entrypoint, exclude, excludeCli, ctx)));
|
|
662
667
|
}
|
|
663
|
-
var
|
|
664
|
-
"cli.ts",
|
|
665
|
-
"cli/index.ts",
|
|
666
|
-
"
|
|
667
|
-
"
|
|
668
|
+
var CLI_EXCLUSION_PATTERNS = [
|
|
669
|
+
"**/cli.{ts,tsx,js,jsx,mjs,cjs}",
|
|
670
|
+
"**/cli/index.{ts,tsx,js,jsx,mjs,cjs}",
|
|
671
|
+
"**/bin.{ts,tsx,js,jsx,mjs,cjs}",
|
|
672
|
+
"**/bin/index.{ts,tsx,js,jsx,mjs,cjs}"
|
|
668
673
|
];
|
|
669
|
-
function isExcluded(entrypoint, exclude, ctx) {
|
|
670
|
-
const userPatterns = typeof exclude === "function" ? exclude(ctx) : exclude;
|
|
671
|
-
const
|
|
674
|
+
function isExcluded(entrypoint, exclude, excludeCli, ctx) {
|
|
675
|
+
const userPatterns = typeof exclude === "function" ? exclude({ options: ctx.options, meta: ctx.meta }) : exclude;
|
|
676
|
+
const cliPatterns = excludeCli !== false ? CLI_EXCLUSION_PATTERNS : [];
|
|
677
|
+
const allPatterns = [...cliPatterns, ...userPatterns ?? []];
|
|
672
678
|
return allPatterns.some((pattern) => new Bun.Glob(pattern).match(entrypoint));
|
|
673
679
|
}
|
|
674
680
|
function getExportKey(pathRelativeToOutdir) {
|
|
@@ -730,6 +736,44 @@ function exportFieldToEntryPoint(exportField) {
|
|
|
730
736
|
return "module";
|
|
731
737
|
}
|
|
732
738
|
}
|
|
739
|
+
async function validateBinFields(packageJsonData, projectName, packageJsonPath, rootDir) {
|
|
740
|
+
if (!packageJsonData?.bin || !rootDir)
|
|
741
|
+
return;
|
|
742
|
+
const bin = packageJsonData.bin;
|
|
743
|
+
const invalidBins = [];
|
|
744
|
+
if (typeof bin === "string") {
|
|
745
|
+
const fullPath = path2.resolve(rootDir, bin);
|
|
746
|
+
const exists = await Bun.file(fullPath).exists();
|
|
747
|
+
if (!exists) {
|
|
748
|
+
invalidBins.push(`bin field points to ${pc3.yellow(bin)}`);
|
|
749
|
+
}
|
|
750
|
+
} else if (typeof bin === "object" && bin !== null) {
|
|
751
|
+
for (const [name, binPath] of Object.entries(bin)) {
|
|
752
|
+
if (typeof binPath === "string") {
|
|
753
|
+
const fullPath = path2.resolve(rootDir, binPath);
|
|
754
|
+
const exists = await Bun.file(fullPath).exists();
|
|
755
|
+
if (!exists) {
|
|
756
|
+
invalidBins.push(`${pc3.yellow(pc3.bold(name))} points to ${pc3.red(binPath)}`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (invalidBins.length === 0)
|
|
762
|
+
return;
|
|
763
|
+
const project = projectName ? ` ${projectName}` : "";
|
|
764
|
+
const count = invalidBins.length;
|
|
765
|
+
const depText = count === 1 ? "binary" : "binaries";
|
|
766
|
+
const verb = count === 1 ? "points" : "point";
|
|
767
|
+
const fileText = count === 1 ? "file" : "files";
|
|
768
|
+
const pathPrefix = packageJsonPath ? pc3.cyan(getShortFilePath(packageJsonPath)) : "";
|
|
769
|
+
const message = `
|
|
770
|
+
Your project${project} has ${count} ${depText} in the bin field that ${verb} to invalid ${fileText}:
|
|
771
|
+
|
|
772
|
+
${pathPrefix}:
|
|
773
|
+
${invalidBins.join(`
|
|
774
|
+
`)}`;
|
|
775
|
+
logger.log(message, { leftPadding: true });
|
|
776
|
+
}
|
|
733
777
|
|
|
734
778
|
// packages/bunup/src/plugins/inject-styles.ts
|
|
735
779
|
import path3 from "path";
|
|
@@ -840,17 +884,17 @@ const importMetaUrl = pathToFileURL(__filename).href;
|
|
|
840
884
|
}
|
|
841
885
|
|
|
842
886
|
// packages/bunup/src/plugins/unused.ts
|
|
843
|
-
import
|
|
887
|
+
import pc4 from "picocolors";
|
|
844
888
|
function unused(options = {}) {
|
|
845
889
|
const { level = "warn", ignore = [] } = options;
|
|
846
890
|
return {
|
|
847
891
|
name: "unused",
|
|
848
892
|
hooks: {
|
|
849
893
|
onBuildDone: async (ctx) => {
|
|
850
|
-
const { options: buildOptions,
|
|
894
|
+
const { options: buildOptions, meta, files } = ctx;
|
|
851
895
|
if (buildOptions.watch)
|
|
852
896
|
return;
|
|
853
|
-
const usedDeps = await collectUsedDependencies(
|
|
897
|
+
const usedDeps = await collectUsedDependencies(files, buildOptions);
|
|
854
898
|
const pkgDeps = extractPackageDependencies(meta.packageJson.data?.dependencies);
|
|
855
899
|
const unusedDeps = findUnusedDependencies(pkgDeps, usedDeps, ignore);
|
|
856
900
|
const misplacedTypes = findMisplacedTypes(pkgDeps, usedDeps, ignore);
|
|
@@ -911,11 +955,11 @@ function reportIssue(deps, type, projectName, level) {
|
|
|
911
955
|
if (deps.length === 0)
|
|
912
956
|
return;
|
|
913
957
|
const count = deps.length;
|
|
914
|
-
const coloredDeps = formatListWithAnd(deps.map((d) =>
|
|
958
|
+
const coloredDeps = formatListWithAnd(deps.map((d) => pc4.yellow(d)));
|
|
915
959
|
const project = projectName ? ` ${projectName}` : "";
|
|
916
960
|
const message = buildMessage(type, count, coloredDeps, project, deps);
|
|
917
961
|
if (level === "error") {
|
|
918
|
-
logger.log(
|
|
962
|
+
logger.log(pc4.red(message), { leftPadding: true });
|
|
919
963
|
process.exit(1);
|
|
920
964
|
} else {
|
|
921
965
|
logger.log(message, { leftPadding: true });
|
|
@@ -925,12 +969,12 @@ function buildMessage(type, count, coloredDeps, project, deps) {
|
|
|
925
969
|
const plural = count === 1 ? "it" : "them";
|
|
926
970
|
if (type === "unused") {
|
|
927
971
|
const depText2 = count === 1 ? "dependency" : "dependencies";
|
|
928
|
-
const cmd2 =
|
|
972
|
+
const cmd2 = pc4.cyan(`bun remove ${deps.join(" ")}`);
|
|
929
973
|
return `
|
|
930
974
|
Your project${project} has ${count} unused ${depText2}: ${coloredDeps}. You can remove ${plural} with ${cmd2}`;
|
|
931
975
|
}
|
|
932
976
|
const depText = count === 1 ? "package" : "packages";
|
|
933
|
-
const cmd =
|
|
977
|
+
const cmd = pc4.cyan(`bun remove ${deps.join(" ")} && bun add --dev ${deps.join(" ")}`);
|
|
934
978
|
return `
|
|
935
979
|
Your project${project} has ${count} type ${depText} that should be in devDependencies: ${coloredDeps}. Move ${plural} to devDependencies with ${cmd}`;
|
|
936
980
|
}
|
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.15.
|
|
4
|
+
"version": "0.15.6",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"type-check": "tsc --noEmit"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@bunup/dts": "^0.14.
|
|
54
|
-
"@bunup/shared": "0.15.
|
|
53
|
+
"@bunup/dts": "^0.14.32",
|
|
54
|
+
"@bunup/shared": "0.15.4",
|
|
55
55
|
"chokidar": "^4.0.3",
|
|
56
56
|
"coffi": "^0.1.37",
|
|
57
57
|
"lightningcss": "^1.30.2",
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@types/bun": "^1.
|
|
72
|
+
"@types/bun": "^1.3.0"
|
|
73
73
|
}
|
|
74
74
|
}
|