tsdown 0.21.5 → 0.21.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/build-C1dAKhHj.mjs +2 -0
- package/dist/{build-DpU0PBVv.mjs → build-MDnn2xGL.mjs} +34 -17
- package/dist/{config-DR_xLSbh.d.mts → config-CgCV7Kdu.d.mts} +3 -3
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/{format-CzYq8yvJ.mjs → format-DXnmiQIy.mjs} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{options-efTzQ_AE.mjs → options-B1Ye5hV8.mjs} +68 -9
- package/dist/{package-BIUrKRH5.mjs → package-lMx2nkh2.mjs} +1 -1
- package/dist/plugins.d.mts +1 -1
- package/dist/plugins.mjs +2 -2
- package/dist/run.mjs +4 -4
- package/dist/{types-7diXKIyw.d.mts → types-qUp2BCEq.d.mts} +35 -1
- package/dist/{watch-BywZdNr-.mjs → watch-BHPVmWIr.mjs} +2 -2
- package/package.json +13 -13
- package/dist/build-D-zhBXEK.mjs +0 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
3
|
import { a as pkgExists, l as slash, n as importWithError, o as promiseWithResolvers, t as debounce } from "./general-CRszZCrY.mjs";
|
|
4
|
-
import { a as getPackageType, c as isGlobEntry, d as cleanOutDir, i as loadConfigFile, l as toObjectEntry, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, u as cleanChunks } from "./options-
|
|
4
|
+
import { a as getPackageType, c as isGlobEntry, d as cleanOutDir, i as loadConfigFile, l as toObjectEntry, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, t as mergeConfig, u as cleanChunks } from "./options-B1Ye5hV8.mjs";
|
|
5
5
|
import { r as fsRemove } from "./fs-Dd6Htx2P.mjs";
|
|
6
6
|
import { a as globalLogger, t as LogLevels } from "./logger-BU0v7CAk.mjs";
|
|
7
|
-
import { a as getShimsInject, r as DepsPlugin } from "./format-
|
|
8
|
-
import { a as ReportPlugin, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, s as copy, t as WatchPlugin } from "./watch-
|
|
9
|
-
import { t as version } from "./package-
|
|
7
|
+
import { a as getShimsInject, r as DepsPlugin } from "./format-DXnmiQIy.mjs";
|
|
8
|
+
import { a as ReportPlugin, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, s as copy, t as WatchPlugin } from "./watch-BHPVmWIr.mjs";
|
|
9
|
+
import { t as version } from "./package-lMx2nkh2.mjs";
|
|
10
10
|
import { mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process from "node:process";
|
|
@@ -14,7 +14,7 @@ import { bold, dim, green } from "ansis";
|
|
|
14
14
|
import { createDebug } from "obug";
|
|
15
15
|
import { glob } from "tinyglobby";
|
|
16
16
|
import readline from "node:readline";
|
|
17
|
-
import { RE_CSS, RE_DTS, RE_JS } from "rolldown-plugin-dts/
|
|
17
|
+
import { RE_CSS, RE_DTS, RE_JS, filename_js_to_dts } from "rolldown-plugin-dts/internal";
|
|
18
18
|
import { tmpdir } from "node:os";
|
|
19
19
|
const satisfies = __cjs_require("semver/functions/satisfies.js");
|
|
20
20
|
import { exec, x } from "tinyexec";
|
|
@@ -34,10 +34,7 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
|
34
34
|
"**/t?(e)mp/**"
|
|
35
35
|
];
|
|
36
36
|
async function resolveWorkspace(config, inlineConfig) {
|
|
37
|
-
const normalized =
|
|
38
|
-
...config,
|
|
39
|
-
...inlineConfig
|
|
40
|
-
};
|
|
37
|
+
const normalized = mergeConfig(config, inlineConfig);
|
|
41
38
|
const rootCwd = normalized.cwd || process.cwd();
|
|
42
39
|
let { workspace } = normalized;
|
|
43
40
|
if (!workspace) return {
|
|
@@ -68,15 +65,12 @@ async function resolveWorkspace(config, inlineConfig) {
|
|
|
68
65
|
...inlineConfig,
|
|
69
66
|
config: workspaceConfig,
|
|
70
67
|
cwd
|
|
71
|
-
}, cwd);
|
|
68
|
+
}, cwd, normalized);
|
|
72
69
|
if (file) {
|
|
73
70
|
debug$4("loaded workspace config file %s", file);
|
|
74
71
|
files.push(file);
|
|
75
72
|
} else debug$4("no workspace config file found in %s", cwd);
|
|
76
|
-
return configs.map((config) => (
|
|
77
|
-
...normalized,
|
|
78
|
-
...config
|
|
79
|
-
}));
|
|
73
|
+
return configs.map((config) => mergeConfig(normalized, config));
|
|
80
74
|
}))).flat(),
|
|
81
75
|
files
|
|
82
76
|
};
|
|
@@ -469,9 +463,10 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
469
463
|
if (config.pkg || config.deps.skipNodeModulesBundle) plugins.push(DepsPlugin(config, bundle));
|
|
470
464
|
if (dts) {
|
|
471
465
|
const { dts: dtsPlugin } = await import("rolldown-plugin-dts");
|
|
466
|
+
const { cjsReexport: _, ...dtsPluginOptions } = dts;
|
|
472
467
|
const options = {
|
|
473
468
|
tsconfig,
|
|
474
|
-
...
|
|
469
|
+
...dtsPluginOptions
|
|
475
470
|
};
|
|
476
471
|
if (format === "es") plugins.push(dtsPlugin(options));
|
|
477
472
|
else if (cjsDts) plugins.push(dtsPlugin({
|
|
@@ -479,7 +474,9 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
479
474
|
emitDtsOnly: true,
|
|
480
475
|
cjsDefault
|
|
481
476
|
}));
|
|
477
|
+
else if (dts.cjsReexport && isDualFormat) plugins.push(CjsDtsReexportPlugin());
|
|
482
478
|
}
|
|
479
|
+
let cssPostPlugins;
|
|
483
480
|
if (!cjsDts) {
|
|
484
481
|
if (unused) {
|
|
485
482
|
const { Unused } = await importWithError("unplugin-unused");
|
|
@@ -490,7 +487,9 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
490
487
|
}
|
|
491
488
|
if (pkgExists("@tsdown/css")) {
|
|
492
489
|
const { CssPlugin } = await import("@tsdown/css");
|
|
493
|
-
|
|
490
|
+
const cssPlugins = CssPlugin(config, { logger });
|
|
491
|
+
plugins.push(...cssPlugins.pre);
|
|
492
|
+
cssPostPlugins = cssPlugins.post;
|
|
494
493
|
} else plugins.push(CssGuardPlugin());
|
|
495
494
|
plugins.push(ShebangPlugin(logger, cwd, nameLabel, isDualFormat));
|
|
496
495
|
if (globImport) plugins.push(importGlobPlugin({ root: cwd }));
|
|
@@ -498,6 +497,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
498
497
|
if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(config, cjsDts, isDualFormat));
|
|
499
498
|
if (watch) plugins.push(WatchPlugin(configFiles, bundle));
|
|
500
499
|
if (!cjsDts) plugins.push(userPlugins);
|
|
500
|
+
if (cssPostPlugins) plugins.push(...cssPostPlugins);
|
|
501
501
|
const define = {
|
|
502
502
|
...config.define,
|
|
503
503
|
...Object.keys(env).reduce((acc, key) => {
|
|
@@ -587,6 +587,23 @@ function handlePluginInspect(plugins) {
|
|
|
587
587
|
else return `"rolldown plugin: ${plugins.name}"`;
|
|
588
588
|
};
|
|
589
589
|
}
|
|
590
|
+
function CjsDtsReexportPlugin() {
|
|
591
|
+
return {
|
|
592
|
+
name: "tsdown:cjs-dts-reexport",
|
|
593
|
+
generateBundle(_options, bundle) {
|
|
594
|
+
for (const chunk of Object.values(bundle)) {
|
|
595
|
+
if (chunk.type !== "chunk") continue;
|
|
596
|
+
if (!chunk.fileName.endsWith(".cjs") && !chunk.fileName.endsWith(".js")) continue;
|
|
597
|
+
const content = `export * from './${path.basename(chunk.fileName.replace(RE_JS, ".d.mts"))}'\n`;
|
|
598
|
+
this.emitFile({
|
|
599
|
+
type: "prebuilt-chunk",
|
|
600
|
+
fileName: filename_js_to_dts(chunk.fileName),
|
|
601
|
+
code: content
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
590
607
|
function CssGuardPlugin() {
|
|
591
608
|
return {
|
|
592
609
|
name: "tsdown:css-guard",
|
|
@@ -798,7 +815,7 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
798
815
|
});
|
|
799
816
|
if (debugRolldownConfigDir) await debugBuildOptions(debugRolldownConfigDir, config.name, format, buildOptions);
|
|
800
817
|
const configs = [buildOptions];
|
|
801
|
-
if (format === "cjs" && dts) configs.push(await getBuildOptions(config, format, configFiles, bundle, true, isDualFormat));
|
|
818
|
+
if (format === "cjs" && dts && (!isDualFormat || !dts.cjsReexport)) configs.push(await getBuildOptions(config, format, configFiles, bundle, true, isDualFormat));
|
|
802
819
|
return configs;
|
|
803
820
|
}
|
|
804
821
|
async function postBuild() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-qUp2BCEq.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/config/options.d.ts
|
|
4
4
|
/**
|
|
@@ -8,8 +8,8 @@ import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as Resolve
|
|
|
8
8
|
* @private
|
|
9
9
|
*/
|
|
10
10
|
declare function resolveUserConfig(userConfig: UserConfig, inlineConfig: InlineConfig): Promise<ResolvedConfig[]>;
|
|
11
|
-
declare function mergeConfig(defaults: UserConfig, overrides: UserConfig): UserConfig;
|
|
12
|
-
declare function mergeConfig(defaults: InlineConfig, overrides: InlineConfig): InlineConfig;
|
|
11
|
+
declare function mergeConfig(defaults: UserConfig, ...overrides: UserConfig[]): UserConfig;
|
|
12
|
+
declare function mergeConfig(defaults: InlineConfig, ...overrides: InlineConfig[]): InlineConfig;
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/config.d.ts
|
|
15
15
|
/**
|
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-
|
|
2
|
-
import { n as mergeConfig, t as defineConfig } from "./config-
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-qUp2BCEq.mjs";
|
|
2
|
+
import { n as mergeConfig, t as defineConfig } from "./config-CgCV7Kdu.mjs";
|
|
3
3
|
export { UserConfig, UserConfigExport, UserConfigFn, defineConfig, mergeConfig };
|
package/dist/config.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { readFile } from "node:fs/promises";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { blue, underline, yellow } from "ansis";
|
|
6
6
|
import { createDebug } from "obug";
|
|
7
|
-
import { RE_DTS, RE_NODE_MODULES } from "rolldown-plugin-dts/
|
|
7
|
+
import { RE_DTS, RE_NODE_MODULES } from "rolldown-plugin-dts/internal";
|
|
8
8
|
import { and, id, importerId, include } from "rolldown/filter";
|
|
9
9
|
//#region src/features/shims.ts
|
|
10
10
|
const shimFile = path.resolve(import.meta.dirname, "..", "esm-shims.js");
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as Arrayable, n as Logger, r as globalLogger } from "./logger-DtCm1ySP.mjs";
|
|
2
|
-
import { A as RolldownContext, B as TsdownBundle, C as ChunkAddonObject, D as PackageJsonWithPath, E as OutExtensionObject, F as DepsConfig, H as CopyOptions, L as NoExternalFn, M as ExeOptions, N as SeaConfig, O as PackageType, P as DevtoolsOptions, R as ResolvedDepsConfig, S as ChunkAddonFunction, T as OutExtensionFactory, U as CopyOptionsFn, V as CopyEntry, a as NormalizedFormat, b as AttwOptions, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, j as TsdownHooks, k as BuildContext, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, o as ResolvedConfig, p as UserConfigFn, r as Format, s as Sourcemap, t as CIOption, u as UnusedOptions, v as PublintOptions, w as OutExtensionContext, x as ChunkAddon, y as ExportsOptions, z as RolldownChunk } from "./types-
|
|
3
|
-
import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-
|
|
2
|
+
import { A as RolldownContext, B as TsdownBundle, C as ChunkAddonObject, D as PackageJsonWithPath, E as OutExtensionObject, F as DepsConfig, H as CopyOptions, L as NoExternalFn, M as ExeOptions, N as SeaConfig, O as PackageType, P as DevtoolsOptions, R as ResolvedDepsConfig, S as ChunkAddonFunction, T as OutExtensionFactory, U as CopyOptionsFn, V as CopyEntry, a as NormalizedFormat, b as AttwOptions, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, j as TsdownHooks, k as BuildContext, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, o as ResolvedConfig, p as UserConfigFn, r as Format, s as Sourcemap, t as CIOption, u as UnusedOptions, v as PublintOptions, w as OutExtensionContext, x as ChunkAddon, y as ExportsOptions, z as RolldownChunk } from "./types-qUp2BCEq.mjs";
|
|
3
|
+
import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-CgCV7Kdu.mjs";
|
|
4
4
|
import * as Rolldown from "rolldown";
|
|
5
5
|
|
|
6
6
|
//#region src/build.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as resolveUserConfig, t as mergeConfig } from "./options-
|
|
1
|
+
import { r as resolveUserConfig, t as mergeConfig } from "./options-B1Ye5hV8.mjs";
|
|
2
2
|
import { a as globalLogger } from "./logger-BU0v7CAk.mjs";
|
|
3
3
|
import { defineConfig } from "./config.mjs";
|
|
4
|
-
import { n as buildWithConfigs, t as build } from "./build-
|
|
4
|
+
import { n as buildWithConfigs, t as build } from "./build-MDnn2xGL.mjs";
|
|
5
5
|
import { t as enableDebug } from "./debug-C4FmgzkJ.mjs";
|
|
6
6
|
import * as Rolldown from "rolldown";
|
|
7
7
|
export { Rolldown, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
|
@@ -3,7 +3,7 @@ const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
|
3
3
|
import { a as pkgExists, c as resolveRegex, l as slash, n as importWithError, r as matchPattern, s as resolveComma, u as toArray } from "./general-CRszZCrY.mjs";
|
|
4
4
|
import { a as lowestCommonAncestor, i as fsStat, n as fsExists, o as stripExtname, r as fsRemove } from "./fs-Dd6Htx2P.mjs";
|
|
5
5
|
import { a as globalLogger, i as getNameLabel, n as createLogger, r as generateColor } from "./logger-BU0v7CAk.mjs";
|
|
6
|
-
import { i as resolveDepsConfig, n as formatBytes, t as detectIndentation } from "./format-
|
|
6
|
+
import { i as resolveDepsConfig, n as formatBytes, t as detectIndentation } from "./format-DXnmiQIy.mjs";
|
|
7
7
|
import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import process, { env } from "node:process";
|
|
@@ -13,7 +13,7 @@ import { createDebug } from "obug";
|
|
|
13
13
|
import { glob, isDynamicPattern } from "tinyglobby";
|
|
14
14
|
import { pathToFileURL } from "node:url";
|
|
15
15
|
const picomatch = __cjs_require("picomatch");
|
|
16
|
-
import { RE_CSS, RE_DTS, RE_NODE_MODULES } from "rolldown-plugin-dts/
|
|
16
|
+
import { RE_CSS, RE_DTS, RE_NODE_MODULES } from "rolldown-plugin-dts/internal";
|
|
17
17
|
import { tmpdir } from "node:os";
|
|
18
18
|
const satisfies = __cjs_require("semver/functions/satisfies.js");
|
|
19
19
|
import { x } from "tinyexec";
|
|
@@ -80,7 +80,7 @@ async function resolveEntry(logger, entry, cwd, color, nameLabel, root) {
|
|
|
80
80
|
const [entryMap, computedRoot] = await toObjectEntry(entry, cwd, root);
|
|
81
81
|
const entries = Object.values(entryMap);
|
|
82
82
|
if (entries.length === 0) throw new Error(`${nameLabel} Cannot find entry: ${JSON.stringify(entry)}`);
|
|
83
|
-
logger.info(nameLabel, `entry: ${color(entries.map((entry) => path.relative(cwd, entry)).join(", "))}`);
|
|
83
|
+
logger.info(nameLabel, `entry: ${color(entries.map((entry) => path.isAbsolute(entry) ? path.relative(cwd, entry) : entry).join(", "))}`);
|
|
84
84
|
return [entryMap, computedRoot];
|
|
85
85
|
}
|
|
86
86
|
function toObjectEntry(entry, cwd, root) {
|
|
@@ -234,10 +234,11 @@ async function buildSingleExe(config, bundledFile, outputFile, executable, targe
|
|
|
234
234
|
//#region src/features/pkg/exports.ts
|
|
235
235
|
async function writeExports(options, chunks, inlinedDeps) {
|
|
236
236
|
const { pkg } = options;
|
|
237
|
-
const { publishExports, ...generated } = await generateExports(pkg, chunks, options, inlinedDeps);
|
|
237
|
+
const { publishExports, bin, ...generated } = await generateExports(pkg, chunks, options, inlinedDeps);
|
|
238
238
|
const updatedPkg = {
|
|
239
239
|
...pkg,
|
|
240
240
|
...generated,
|
|
241
|
+
...bin === void 0 ? {} : { bin },
|
|
241
242
|
packageJsonPath: void 0
|
|
242
243
|
};
|
|
243
244
|
if (publishExports) {
|
|
@@ -255,7 +256,7 @@ function shouldExclude(fileName, exclude) {
|
|
|
255
256
|
return matchPattern(fileName, exclude);
|
|
256
257
|
}
|
|
257
258
|
async function generateExports(pkg, chunks, options, inlinedDeps) {
|
|
258
|
-
let { exports: { devExports, all, packageJson = true, exclude, customExports, legacy, inlinedDependencies: emitInlinedDeps = true }, css, logger } = options;
|
|
259
|
+
let { exports: { devExports, all, packageJson = true, exclude, customExports, legacy, inlinedDependencies: emitInlinedDeps = true, bin }, css, logger, cwd } = options;
|
|
259
260
|
const pkgRoot = path.dirname(pkg.packageJsonPath);
|
|
260
261
|
let main, module, cjsTypes, esmTypes;
|
|
261
262
|
const exportsMap = /* @__PURE__ */ new Map();
|
|
@@ -334,6 +335,7 @@ async function generateExports(pkg, chunks, options, inlinedDeps) {
|
|
|
334
335
|
module: legacy ? module || pkg.module : void 0,
|
|
335
336
|
types: legacy ? cjsTypes || esmTypes || pkg.types : pkg.types,
|
|
336
337
|
exports,
|
|
338
|
+
bin: generateBin(bin, pkg, chunks, pkgRoot, logger, cwd),
|
|
337
339
|
inlinedDependencies: emitInlinedDeps ? inlinedDeps : void 0,
|
|
338
340
|
publishExports
|
|
339
341
|
};
|
|
@@ -375,6 +377,60 @@ function hasExportsTypes(pkg) {
|
|
|
375
377
|
}
|
|
376
378
|
return false;
|
|
377
379
|
}
|
|
380
|
+
const RE_SHEBANG = /^#!.*/;
|
|
381
|
+
function generateBin(bin, pkg, chunks, pkgRoot, logger, cwd) {
|
|
382
|
+
if (!bin) return;
|
|
383
|
+
if (bin === true || typeof bin === "string") {
|
|
384
|
+
if (!pkg.name) throw new Error("Package name is required when using string form for `bin`");
|
|
385
|
+
const binName = pkg.name[0] === "@" ? pkg.name.split("/", 2)[1] : pkg.name;
|
|
386
|
+
if (bin === true) {
|
|
387
|
+
let detected;
|
|
388
|
+
const seen = /* @__PURE__ */ new Set();
|
|
389
|
+
for (const format of ["es", "cjs"]) {
|
|
390
|
+
const formatChunks = chunks[format];
|
|
391
|
+
if (!formatChunks) continue;
|
|
392
|
+
for (const chunk of formatChunks) {
|
|
393
|
+
if (chunk.type !== "chunk" || !chunk.isEntry || !chunk.facadeModuleId) continue;
|
|
394
|
+
if (!RE_SHEBANG.test(chunk.code)) continue;
|
|
395
|
+
if (seen.has(chunk.facadeModuleId)) continue;
|
|
396
|
+
seen.add(chunk.facadeModuleId);
|
|
397
|
+
if (detected) throw new Error("Multiple entry chunks with shebangs found. Use `exports.bin: { name: \"./src/file.ts\" }` to specify which one to use.");
|
|
398
|
+
detected = join(pkgRoot, chunk.outDir, slash(chunk.fileName));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (detected == null) {
|
|
402
|
+
logger.warn("`exports.bin` is true but no entry chunks with shebangs were found");
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
return { [binName]: detected };
|
|
406
|
+
}
|
|
407
|
+
if (typeof bin === "string") {
|
|
408
|
+
const match = findChunkBySource(bin);
|
|
409
|
+
if (!match) throw new Error(`Could not find output chunk for bin entry "${bin}"`);
|
|
410
|
+
return { [binName]: match };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const result = {};
|
|
414
|
+
for (const [cmdName, sourcePath] of Object.entries(bin)) {
|
|
415
|
+
const match = findChunkBySource(sourcePath);
|
|
416
|
+
if (!match) throw new Error(`Could not find output chunk for bin entry "${cmdName}": "${sourcePath}"`);
|
|
417
|
+
result[cmdName] = match;
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
function findChunkBySource(sourcePath) {
|
|
421
|
+
const resolved = path.resolve(cwd, sourcePath);
|
|
422
|
+
for (const format of ["es", "cjs"]) {
|
|
423
|
+
const formatChunks = chunks[format];
|
|
424
|
+
if (!formatChunks) continue;
|
|
425
|
+
for (const chunk of formatChunks) {
|
|
426
|
+
if (chunk.type !== "chunk" || !chunk.isEntry) continue;
|
|
427
|
+
if (chunk.facadeModuleId !== resolved) continue;
|
|
428
|
+
if (!RE_SHEBANG.test(chunk.code)) logger.warn(`Bin entry "${sourcePath}" does not contain a shebang line`);
|
|
429
|
+
return join(pkgRoot, chunk.outDir, slash(chunk.fileName));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
378
434
|
function getExportName(chunk) {
|
|
379
435
|
const normalizedName = slash(chunk.fileName);
|
|
380
436
|
let name = stripExtname(normalizedName);
|
|
@@ -501,7 +557,7 @@ async function loadViteConfig(prefix, cwd, configLoader) {
|
|
|
501
557
|
return resolved;
|
|
502
558
|
}
|
|
503
559
|
const configPrefix = "tsdown.config";
|
|
504
|
-
async function loadConfigFile(inlineConfig, workspace) {
|
|
560
|
+
async function loadConfigFile(inlineConfig, workspace, rootConfig) {
|
|
505
561
|
let cwd = inlineConfig.cwd || process.cwd();
|
|
506
562
|
let overrideConfig = false;
|
|
507
563
|
let { config: filePath } = inlineConfig;
|
|
@@ -550,7 +606,10 @@ async function loadConfigFile(inlineConfig, workspace) {
|
|
|
550
606
|
({config: exported, source: file} = result);
|
|
551
607
|
globalLogger.info(`config file: ${underline(file)}`, loader === "native" ? "" : `(${loader})`);
|
|
552
608
|
exported = await exported;
|
|
553
|
-
if (typeof exported === "function") exported = await exported(inlineConfig, {
|
|
609
|
+
if (typeof exported === "function") exported = await exported(inlineConfig, {
|
|
610
|
+
ci: isInCi,
|
|
611
|
+
rootConfig
|
|
612
|
+
});
|
|
554
613
|
}
|
|
555
614
|
exported = toArray(exported);
|
|
556
615
|
if (exported.length === 0) exported.push({});
|
|
@@ -769,8 +828,8 @@ const defu = createDefu((obj, key, value) => {
|
|
|
769
828
|
return true;
|
|
770
829
|
}
|
|
771
830
|
});
|
|
772
|
-
function mergeConfig(defaults, overrides) {
|
|
773
|
-
return defu(overrides, defaults);
|
|
831
|
+
function mergeConfig(defaults, ...overrides) {
|
|
832
|
+
return defu(...overrides.toReversed(), defaults);
|
|
774
833
|
}
|
|
775
834
|
async function mergeUserOptions(defaults, user, args) {
|
|
776
835
|
const userOutputOptions = typeof user === "function" ? await user(defaults, ...args) : user;
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as Logger } from "./logger-DtCm1ySP.mjs";
|
|
2
|
-
import { B as TsdownBundle, I as DepsPlugin, _ as ReportPlugin } from "./types-
|
|
2
|
+
import { B as TsdownBundle, I as DepsPlugin, _ as ReportPlugin } from "./types-qUp2BCEq.mjs";
|
|
3
3
|
import { Plugin } from "rolldown";
|
|
4
4
|
|
|
5
5
|
//#region src/features/node-protocol.d.ts
|
package/dist/plugins.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { r as DepsPlugin } from "./format-
|
|
2
|
-
import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-
|
|
1
|
+
import { r as DepsPlugin } from "./format-DXnmiQIy.mjs";
|
|
2
|
+
import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-BHPVmWIr.mjs";
|
|
3
3
|
export { DepsPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
|
package/dist/run.mjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
3
3
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
4
|
import { a as globalLogger } from "./logger-BU0v7CAk.mjs";
|
|
5
|
-
import { t as version } from "./package-
|
|
5
|
+
import { t as version } from "./package-lMx2nkh2.mjs";
|
|
6
6
|
import { t as enableDebug } from "./debug-C4FmgzkJ.mjs";
|
|
7
7
|
import module from "node:module";
|
|
8
8
|
import process from "node:process";
|
|
9
|
-
import {
|
|
9
|
+
import { blue, hex, yellow } from "ansis";
|
|
10
10
|
import { x } from "tinyexec";
|
|
11
11
|
import { VERSION } from "rolldown";
|
|
12
12
|
const lt = __cjs_require("semver/functions/lt.js");
|
|
@@ -19,8 +19,8 @@ cli.command("[...files]", "Bundle files", {
|
|
|
19
19
|
allowUnknownOptions: true
|
|
20
20
|
}).option("-c, --config <filename>", "Use a custom config file").option("--config-loader <loader>", "Config loader to use: auto, native, unrun", { default: "auto" }).option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife, umd", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--deps.never-bundle <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--devtools", "Enable devtools integration").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("-l, --logLevel <level>", "Set log level: info, warn, error, silent").option("--fail-on-warn", "Fail on warnings", { default: true }).option("--no-write", "Disable writing files to disk, incompatible with watch mode").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files").option("--publint", "Enable publint", { default: false }).option("--attw", "Enable Are the types wrong integration", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").option("--env-file <file>", "Load environment variables from a file, when used together with --env, variables in --env take precedence").option("--env-prefix <prefix>", "Prefix for env variables to inject into the bundle", { default: "TSDOWN_" }).option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("--unbundle", "Unbundle mode").option("--root <dir>", "Root directory of input files").option("--exe", "Bundle as executable").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter configs (cwd or name), e.g. /pkg-name$/ or pkg-name").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
|
|
21
21
|
globalLogger.level = flags.logLevel || "info";
|
|
22
|
-
globalLogger.info(`tsdown
|
|
23
|
-
const { build } = await import("./build-
|
|
22
|
+
globalLogger.info(`${blue`tsdown v${version}`} powered by ${hex("#ff7e17")`rolldown v${VERSION}`}`);
|
|
23
|
+
const { build } = await import("./build-C1dAKhHj.mjs");
|
|
24
24
|
if (input.length > 0) flags.entry = input;
|
|
25
25
|
await build(flags);
|
|
26
26
|
});
|
|
@@ -7,7 +7,7 @@ import { StartOptions } from "@vitejs/devtools/cli-commands";
|
|
|
7
7
|
import { ExeExtensionOptions } from "@tsdown/exe";
|
|
8
8
|
import { CheckPackageOptions } from "@arethetypeswrong/core";
|
|
9
9
|
import { Options } from "publint";
|
|
10
|
-
import { Options as
|
|
10
|
+
import { Options as Options$1 } from "rolldown-plugin-dts";
|
|
11
11
|
import { Options as UnusedOptions } from "unplugin-unused";
|
|
12
12
|
|
|
13
13
|
//#region src/features/copy.d.ts
|
|
@@ -638,6 +638,22 @@ interface ExportsOptions {
|
|
|
638
638
|
* @see {@link https://github.com/e18e/ecosystem-issues/issues/237}
|
|
639
639
|
*/
|
|
640
640
|
inlinedDependencies?: boolean;
|
|
641
|
+
/**
|
|
642
|
+
* Auto-generate the `bin` field in package.json.
|
|
643
|
+
*
|
|
644
|
+
* - `true`: Auto-detect entry chunks with shebangs. Uses package name (without scope) as bin name.
|
|
645
|
+
* Errors if multiple shebang entries are found.
|
|
646
|
+
* - `string`: Source file path to use as the bin entry. Bin name defaults to package name (without scope).
|
|
647
|
+
* - `Record<string, string>`: Map of bin command names to source file paths.
|
|
648
|
+
*
|
|
649
|
+
* @example
|
|
650
|
+
* bin: true
|
|
651
|
+
* @example
|
|
652
|
+
* bin: './src/cli.ts'
|
|
653
|
+
* @example
|
|
654
|
+
* bin: { tool: './src/cli-tool.ts' }
|
|
655
|
+
*/
|
|
656
|
+
bin?: boolean | string | Record<string, string>;
|
|
641
657
|
}
|
|
642
658
|
//#endregion
|
|
643
659
|
//#region src/features/pkg/publint.d.ts
|
|
@@ -668,6 +684,23 @@ interface ReportOptions {
|
|
|
668
684
|
declare function ReportPlugin(config: ResolvedConfig, cjsDts?: boolean, isDualFormat?: boolean): Plugin;
|
|
669
685
|
//#endregion
|
|
670
686
|
//#region src/config/types.d.ts
|
|
687
|
+
interface DtsOptions extends Options$1 {
|
|
688
|
+
/**
|
|
689
|
+
* When building dual ESM+CJS formats, generate a `.d.cts` re-export stub
|
|
690
|
+
* instead of running a full second TypeScript compilation pass.
|
|
691
|
+
*
|
|
692
|
+
* The stub re-exports everything from the corresponding `.d.mts` file,
|
|
693
|
+
* ensuring CJS and ESM consumers share the same type declarations. This
|
|
694
|
+
* eliminates the TypeScript "dual module hazard" where separate `.d.cts`
|
|
695
|
+
* and `.d.mts` declarations cause `TS2352` ("neither type sufficiently
|
|
696
|
+
* overlaps") errors when casting between types derived from the same class.
|
|
697
|
+
*
|
|
698
|
+
* Only applies when building both `esm` and `cjs` formats simultaneously.
|
|
699
|
+
*
|
|
700
|
+
* @default false
|
|
701
|
+
*/
|
|
702
|
+
cjsReexport?: boolean;
|
|
703
|
+
}
|
|
671
704
|
type Sourcemap = boolean | "inline" | "hidden";
|
|
672
705
|
type Format = ModuleFormat;
|
|
673
706
|
type NormalizedFormat = InternalModuleFormat;
|
|
@@ -1128,6 +1161,7 @@ interface InlineConfig extends UserConfig {
|
|
|
1128
1161
|
}
|
|
1129
1162
|
type UserConfigFn = (inlineConfig: InlineConfig, context: {
|
|
1130
1163
|
ci: boolean;
|
|
1164
|
+
rootConfig?: UserConfig;
|
|
1131
1165
|
}) => Awaitable<Arrayable<UserConfig>>;
|
|
1132
1166
|
type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>;
|
|
1133
1167
|
type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "fromVite" | "publicDir" | "bundle" | "injectStyle" | "removeNodeProtocol" | "external" | "noExternal" | "inlineOnly" | "skipNodeModulesBundle" | "logLevel" | "failOnWarn" | "customLogger" | "envFile" | "envPrefix">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "onSuccess" | "outExtensions" | "hooks" | "copy" | "loader" | "name" | "banner" | "footer" | "checks" | "css">, {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { i as noop, s as resolveComma, u as toArray } from "./general-CRszZCrY.mjs";
|
|
2
2
|
import { n as fsExists, t as fsCopy } from "./fs-Dd6Htx2P.mjs";
|
|
3
3
|
import { o as prettyFormat } from "./logger-BU0v7CAk.mjs";
|
|
4
|
-
import { n as formatBytes } from "./format-
|
|
4
|
+
import { n as formatBytes } from "./format-DXnmiQIy.mjs";
|
|
5
5
|
import { builtinModules } from "node:module";
|
|
6
6
|
import { chmod } from "node:fs/promises";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { bold, dim, green, underline } from "ansis";
|
|
9
9
|
import { createDebug } from "obug";
|
|
10
10
|
import { glob, isDynamicPattern } from "tinyglobby";
|
|
11
|
-
import { RE_DTS } from "rolldown-plugin-dts/
|
|
11
|
+
import { RE_DTS } from "rolldown-plugin-dts/internal";
|
|
12
12
|
import { promisify } from "node:util";
|
|
13
13
|
import { Buffer } from "node:buffer";
|
|
14
14
|
import { brotliCompress, gzip } from "node:zlib";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.21.
|
|
4
|
+
"version": "0.21.6",
|
|
5
5
|
"description": "The Elegant Bundler for Libraries",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"publint": "^0.3.0",
|
|
53
53
|
"typescript": "^5.0.0 || ^6.0.0",
|
|
54
54
|
"unplugin-unused": "^0.5.0",
|
|
55
|
-
"@tsdown/css": "0.21.
|
|
56
|
-
"@tsdown/exe": "0.21.
|
|
55
|
+
"@tsdown/css": "0.21.6",
|
|
56
|
+
"@tsdown/exe": "0.21.6"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"@arethetypeswrong/core": {
|
|
@@ -87,14 +87,14 @@
|
|
|
87
87
|
"import-without-cache": "^0.2.5",
|
|
88
88
|
"obug": "^2.1.1",
|
|
89
89
|
"picomatch": "^4.0.4",
|
|
90
|
-
"rolldown": "1.0.0-rc.
|
|
91
|
-
"rolldown-plugin-dts": "^0.
|
|
90
|
+
"rolldown": "1.0.0-rc.12",
|
|
91
|
+
"rolldown-plugin-dts": "^0.23.0",
|
|
92
92
|
"semver": "^7.7.4",
|
|
93
93
|
"tinyexec": "^1.0.4",
|
|
94
94
|
"tinyglobby": "^0.2.15",
|
|
95
95
|
"tree-kill": "^1.2.2",
|
|
96
96
|
"unconfig-core": "^7.5.0",
|
|
97
|
-
"unrun": "^0.2.
|
|
97
|
+
"unrun": "^0.2.34"
|
|
98
98
|
},
|
|
99
99
|
"inlinedDependencies": {
|
|
100
100
|
"is-in-ci": "2.0.0",
|
|
@@ -109,11 +109,11 @@
|
|
|
109
109
|
"@types/node": "^25.5.0",
|
|
110
110
|
"@types/picomatch": "^4.0.2",
|
|
111
111
|
"@types/semver": "^7.7.1",
|
|
112
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
112
|
+
"@typescript/native-preview": "7.0.0-dev.20260326.1",
|
|
113
113
|
"@unocss/eslint-plugin": "^66.6.7",
|
|
114
114
|
"@vitejs/devtools": "^0.1.11",
|
|
115
|
-
"@vitest/coverage-v8": "^4.1.
|
|
116
|
-
"@vitest/ui": "^4.1.
|
|
115
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
116
|
+
"@vitest/ui": "^4.1.2",
|
|
117
117
|
"@vueuse/core": "^14.2.1",
|
|
118
118
|
"bumpp": "^11.0.1",
|
|
119
119
|
"dedent": "^1.7.2",
|
|
@@ -135,11 +135,11 @@
|
|
|
135
135
|
"unplugin-raw": "^0.6.4",
|
|
136
136
|
"unplugin-unused": "^0.5.7",
|
|
137
137
|
"unplugin-vue": "^7.1.1",
|
|
138
|
-
"vite": "^8.0.
|
|
139
|
-
"vitest": "^4.1.
|
|
138
|
+
"vite": "^8.0.3",
|
|
139
|
+
"vitest": "^4.1.2",
|
|
140
140
|
"vue": "^3.5.31",
|
|
141
|
-
"@tsdown/css": "0.21.
|
|
142
|
-
"@tsdown/exe": "0.21.
|
|
141
|
+
"@tsdown/css": "0.21.6",
|
|
142
|
+
"@tsdown/exe": "0.21.6"
|
|
143
143
|
},
|
|
144
144
|
"prettier": "@sxzz/prettier-config",
|
|
145
145
|
"scripts": {
|
package/dist/build-D-zhBXEK.mjs
DELETED