tsdown 0.11.13 → 0.12.0
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/{config-GQTSGL72.d.ts → config-DttGOO6N.d.ts} +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +82 -7
- package/dist/{migrate-hgmWgN5I.js → migrate-Cq_lJ3EI.js} +1 -1
- package/dist/package-rd2yGx0m.js +5 -0
- package/dist/plugins.d.ts +1 -1
- package/dist/run.js +3 -3
- package/dist/{types-CsOn0For.d.ts → types-CHTYRF4v.d.ts} +14 -7
- package/package.json +3 -2
- package/dist/package-BjscpG31.js +0 -5
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { UserConfig, UserConfigFn } from "./types-
|
|
2
|
-
import { defineConfig$1 as defineConfig } from "./config-
|
|
1
|
+
import { UserConfig, UserConfigFn } from "./types-CHTYRF4v.js";
|
|
2
|
+
import { defineConfig$1 as defineConfig } from "./config-DttGOO6N.js";
|
|
3
3
|
export { UserConfig, UserConfigFn, defineConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn } from "./types-
|
|
2
|
-
import { defineConfig$1 as defineConfig } from "./config-
|
|
1
|
+
import { BuildContext, NormalizedFormat, Options, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn } from "./types-CHTYRF4v.js";
|
|
2
|
+
import { defineConfig$1 as defineConfig } from "./config-DttGOO6N.js";
|
|
3
3
|
import "ansis";
|
|
4
|
-
import { InternalModuleFormat } from "rolldown";
|
|
4
|
+
import { InternalModuleFormat, OutputAsset, OutputChunk } from "rolldown";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/logger.d.ts
|
|
7
7
|
declare class Logger {
|
|
@@ -20,6 +20,7 @@ declare const logger: Logger; //#endregion
|
|
|
20
20
|
*/
|
|
21
21
|
declare function build(userOptions?: Options): Promise<void>;
|
|
22
22
|
declare const pkgRoot: string;
|
|
23
|
+
type TsdownChunks = Partial<Record<NormalizedFormat, Array<OutputChunk | OutputAsset>>>;
|
|
23
24
|
/**
|
|
24
25
|
* Build a single configuration, without watch and shortcuts features.
|
|
25
26
|
*
|
|
@@ -31,4 +32,4 @@ declare const pkgRoot: string;
|
|
|
31
32
|
declare function buildSingle(config: ResolvedOptions, clean: () => Promise<void>): Promise<(() => Promise<void>) | undefined>;
|
|
32
33
|
|
|
33
34
|
//#endregion
|
|
34
|
-
export { BuildContext, Options, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot };
|
|
35
|
+
export { BuildContext, Options, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot };
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ import { build as build$1 } from "rolldown";
|
|
|
9
9
|
import { exec } from "tinyexec";
|
|
10
10
|
import Debug from "debug";
|
|
11
11
|
import { glob } from "tinyglobby";
|
|
12
|
-
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
13
|
+
import { RE_DTS } from "rolldown-plugin-dts";
|
|
13
14
|
import { createHooks } from "hookable";
|
|
14
15
|
import { up } from "empathic/package";
|
|
15
16
|
import readline from "node:readline";
|
|
@@ -65,6 +66,71 @@ function cp$1(cwd, from, to) {
|
|
|
65
66
|
return fsCopy(path.resolve(cwd, from), path.resolve(cwd, to));
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/features/exports.ts
|
|
71
|
+
async function writeExports(options, chunks) {
|
|
72
|
+
if (!options.exports) return;
|
|
73
|
+
const { outDir, pkg } = options;
|
|
74
|
+
if (!pkg) throw new Error("`package.json` not found, cannot write exports");
|
|
75
|
+
const generated = generateExports(pkg, outDir, chunks);
|
|
76
|
+
await writeFile(pkg.packageJsonPath, `${JSON.stringify({
|
|
77
|
+
...pkg,
|
|
78
|
+
...generated,
|
|
79
|
+
packageJsonPath: void 0
|
|
80
|
+
}, null, 2)}\n`);
|
|
81
|
+
}
|
|
82
|
+
function generateExports(pkg, outDir, chunks) {
|
|
83
|
+
const packageJsonPath = pkg.packageJsonPath;
|
|
84
|
+
const basePath = path.relative(path.dirname(packageJsonPath), outDir);
|
|
85
|
+
let main, module, cjsTypes, esmTypes;
|
|
86
|
+
const exportsMap = new Map();
|
|
87
|
+
for (const [format, chunksByFormat] of Object.entries(chunks)) {
|
|
88
|
+
if (format !== "es" && format !== "cjs") continue;
|
|
89
|
+
const onlyOneEntry = chunksByFormat.filter((chunk) => chunk.type === "chunk" && chunk.isEntry && !RE_DTS.test(chunk.fileName)).length === 1;
|
|
90
|
+
for (const chunk of chunksByFormat) {
|
|
91
|
+
if (chunk.type !== "chunk" || !chunk.isEntry) continue;
|
|
92
|
+
const distFile = `./${path.join(basePath, chunk.fileName)}`;
|
|
93
|
+
const ext = path.extname(chunk.fileName);
|
|
94
|
+
let name = chunk.fileName.slice(0, -ext.length);
|
|
95
|
+
const isDts = name.endsWith(".d");
|
|
96
|
+
if (isDts) name = name.slice(0, -2);
|
|
97
|
+
const isIndex = name === "index" || onlyOneEntry;
|
|
98
|
+
if (isIndex) {
|
|
99
|
+
name = ".";
|
|
100
|
+
if (format === "cjs") if (isDts) cjsTypes = distFile;
|
|
101
|
+
else main = distFile;
|
|
102
|
+
else if (format === "es") if (isDts) esmTypes = distFile;
|
|
103
|
+
else module = distFile;
|
|
104
|
+
} else name = `./${name}`;
|
|
105
|
+
let map = exportsMap.get(name);
|
|
106
|
+
if (!map) {
|
|
107
|
+
map = new Map();
|
|
108
|
+
exportsMap.set(name, map);
|
|
109
|
+
}
|
|
110
|
+
if (!isDts && !RE_DTS.test(chunk.fileName)) map.set(format, distFile);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const exports = Object.fromEntries(Array.from(exportsMap.entries()).sort(([a], [b]) => {
|
|
114
|
+
if (a === "index") return -1;
|
|
115
|
+
return a.localeCompare(b);
|
|
116
|
+
}).map(([name, map]) => {
|
|
117
|
+
let value;
|
|
118
|
+
if (map.size === 1) value = map.get("cjs") || map.get("es");
|
|
119
|
+
else value = {
|
|
120
|
+
import: map.get("es"),
|
|
121
|
+
require: map.get("cjs")
|
|
122
|
+
};
|
|
123
|
+
return [name, value];
|
|
124
|
+
}));
|
|
125
|
+
if (!exports["./package.json"]) exports["./package.json"] = "./package.json";
|
|
126
|
+
return {
|
|
127
|
+
main: main || module || pkg.main,
|
|
128
|
+
module: module || pkg.module,
|
|
129
|
+
types: cjsTypes || esmTypes || pkg.types,
|
|
130
|
+
exports
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
68
134
|
//#endregion
|
|
69
135
|
//#region src/features/hooks.ts
|
|
70
136
|
async function createHooks$1(options, pkg) {
|
|
@@ -141,7 +207,10 @@ async function readPackageJson(dir) {
|
|
|
141
207
|
if (!packageJsonPath) return;
|
|
142
208
|
debug$2("Reading package.json:", packageJsonPath);
|
|
143
209
|
const contents = await readFile(packageJsonPath, "utf8");
|
|
144
|
-
return
|
|
210
|
+
return {
|
|
211
|
+
...JSON.parse(contents),
|
|
212
|
+
packageJsonPath
|
|
213
|
+
};
|
|
145
214
|
}
|
|
146
215
|
function getPackageType(pkg) {
|
|
147
216
|
if (pkg?.type) {
|
|
@@ -714,15 +783,20 @@ async function buildSingle(config, clean) {
|
|
|
714
783
|
await clean();
|
|
715
784
|
let hasErrors = false;
|
|
716
785
|
const isMultiFormat = formats.length > 1;
|
|
786
|
+
const chunks = {};
|
|
717
787
|
await Promise.all(formats.map(async (format) => {
|
|
718
788
|
try {
|
|
719
|
-
const buildOptions = await getBuildOptions(config, format,
|
|
789
|
+
const buildOptions = await getBuildOptions(config, format, isMultiFormat, false);
|
|
720
790
|
await hooks.callHook("build:before", {
|
|
721
791
|
...context,
|
|
722
792
|
buildOptions
|
|
723
793
|
});
|
|
724
|
-
await build$1(buildOptions);
|
|
725
|
-
|
|
794
|
+
const { output } = await build$1(buildOptions);
|
|
795
|
+
chunks[format] = output;
|
|
796
|
+
if (format === "cjs" && dts) {
|
|
797
|
+
const { output: output$1 } = await build$1(await getBuildOptions(config, format, isMultiFormat, true));
|
|
798
|
+
chunks[format].push(...output$1);
|
|
799
|
+
}
|
|
726
800
|
} catch (error) {
|
|
727
801
|
if (watch) {
|
|
728
802
|
logger.error(error);
|
|
@@ -733,6 +807,7 @@ async function buildSingle(config, clean) {
|
|
|
733
807
|
}
|
|
734
808
|
}));
|
|
735
809
|
if (hasErrors) return;
|
|
810
|
+
await writeExports(config, chunks);
|
|
736
811
|
await publint(config);
|
|
737
812
|
await copy(config);
|
|
738
813
|
await hooks.callHook("build:done", context);
|
|
@@ -749,7 +824,7 @@ async function buildSingle(config, clean) {
|
|
|
749
824
|
} else await onSuccess?.(config);
|
|
750
825
|
}
|
|
751
826
|
}
|
|
752
|
-
async function getBuildOptions(config, format,
|
|
827
|
+
async function getBuildOptions(config, format, isMultiFormat, cjsDts) {
|
|
753
828
|
const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report, env, removeNodeProtocol, loader, name } = config;
|
|
754
829
|
const plugins = [];
|
|
755
830
|
if (removeNodeProtocol) plugins.push(NodeProtocolPlugin());
|
|
@@ -806,7 +881,7 @@ async function getBuildOptions(config, format, cjsDts, isMultiFormat) {
|
|
|
806
881
|
sourcemap,
|
|
807
882
|
dir: outDir,
|
|
808
883
|
target,
|
|
809
|
-
minify,
|
|
884
|
+
minify: !cjsDts && minify,
|
|
810
885
|
entryFileNames,
|
|
811
886
|
chunkFileNames
|
|
812
887
|
}, config.outputOptions, [format]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from "./logger-DcIo21Wv.js";
|
|
2
|
-
import { version } from "./package-
|
|
2
|
+
import { version } from "./package-rd2yGx0m.js";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { bold, green, underline } from "ansis";
|
|
5
5
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
package/dist/plugins.d.ts
CHANGED
package/dist/run.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { logger, resolveComma, toArray } from "./logger-DcIo21Wv.js";
|
|
3
|
-
import { version } from "./package-
|
|
3
|
+
import { version } from "./package-rd2yGx0m.js";
|
|
4
4
|
import module from "node:module";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { dim } from "ansis";
|
|
@@ -14,7 +14,7 @@ cli.help().version(version);
|
|
|
14
14
|
cli.command("[...files]", "Bundle files", {
|
|
15
15
|
ignoreOptionDefaultValue: true,
|
|
16
16
|
allowUnknownOptions: true
|
|
17
|
-
}).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").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("--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("--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("-W, --workspace [dir]", "Enable workspace mode").option("-
|
|
17
|
+
}).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").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("--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("--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("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter workspace packages, e.g. /regex/ or substring").action(async (input, flags) => {
|
|
18
18
|
logger.setSilent(!!flags.silent);
|
|
19
19
|
logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
20
20
|
const { build: build$1 } = await import("./index.js");
|
|
@@ -22,7 +22,7 @@ cli.command("[...files]", "Bundle files", {
|
|
|
22
22
|
await build$1(flags);
|
|
23
23
|
});
|
|
24
24
|
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
25
|
-
const { migrate } = await import("./migrate-
|
|
25
|
+
const { migrate } = await import("./migrate-Cq_lJ3EI.js");
|
|
26
26
|
await migrate(args);
|
|
27
27
|
});
|
|
28
28
|
async function runCLI() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BuildOptions, ExternalOption, InputOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, OutputOptions, Plugin } from "rolldown";
|
|
2
|
+
import { Options } from "rolldown-plugin-dts";
|
|
2
3
|
import { Hookable } from "hookable";
|
|
3
|
-
import { Options } from "publint";
|
|
4
|
-
import { Options as Options$1 } from "rolldown-plugin-dts";
|
|
4
|
+
import { Options as Options$1 } from "publint";
|
|
5
5
|
import { Options as Options$2 } from "unplugin-unused";
|
|
6
6
|
import { PackageJson } from "pkg-types";
|
|
7
7
|
|
|
@@ -229,7 +229,7 @@ interface Options$3 {
|
|
|
229
229
|
* - If the `types` field is present in `package.json`, declaration file emission is enabled.
|
|
230
230
|
* - If the `types` field is absent, declaration file emission is disabled by default.
|
|
231
231
|
*/
|
|
232
|
-
dts?: boolean | Options
|
|
232
|
+
dts?: boolean | Options;
|
|
233
233
|
/**
|
|
234
234
|
* Enable unused dependencies check with `unplugin-unused`
|
|
235
235
|
* Requires `unplugin-unused` to be installed.
|
|
@@ -241,13 +241,20 @@ interface Options$3 {
|
|
|
241
241
|
* Requires `publint` to be installed.
|
|
242
242
|
* @default false
|
|
243
243
|
*/
|
|
244
|
-
publint?: boolean | Options;
|
|
244
|
+
publint?: boolean | Options$1;
|
|
245
245
|
/**
|
|
246
246
|
* Enable size reporting after bundling.
|
|
247
247
|
* @default true
|
|
248
248
|
*/
|
|
249
249
|
report?: boolean | ReportOptions;
|
|
250
250
|
/**
|
|
251
|
+
* Generate exports map for `package.json`.
|
|
252
|
+
*
|
|
253
|
+
* This will set the `main`, `module`, `types`, `exports` fields in `package.json`
|
|
254
|
+
* to point to the generated files.
|
|
255
|
+
*/
|
|
256
|
+
exports?: boolean;
|
|
257
|
+
/**
|
|
251
258
|
* Compile-time env variables.
|
|
252
259
|
* @example
|
|
253
260
|
* ```json
|
|
@@ -310,13 +317,13 @@ interface Options$3 {
|
|
|
310
317
|
*/
|
|
311
318
|
type UserConfig = Arrayable<Omit<Options$3, "config" | "filter">>;
|
|
312
319
|
type UserConfigFn = (cliOptions: Options$3) => Awaitable<UserConfig>;
|
|
313
|
-
type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" | "workspace" | "filter">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name">, {
|
|
320
|
+
type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" | "workspace" | "filter">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name" | "exports">, {
|
|
314
321
|
format: NormalizedFormat[];
|
|
315
322
|
target?: string[];
|
|
316
323
|
clean: string[];
|
|
317
|
-
dts: false | Options
|
|
324
|
+
dts: false | Options;
|
|
318
325
|
report: false | ReportOptions;
|
|
319
326
|
tsconfig: string | false;
|
|
320
327
|
pkg?: PackageJson;
|
|
321
328
|
}>, "config" | "fromVite">; //#endregion
|
|
322
|
-
export { BuildContext, Options$3 as Options, ReportPlugin as ReportPlugin$1, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn };
|
|
329
|
+
export { BuildContext, NormalizedFormat, Options$3 as Options, ReportPlugin as ReportPlugin$1, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
".": "./dist/index.js",
|
|
26
26
|
"./config": "./dist/config.js",
|
|
27
27
|
"./plugins": "./dist/plugins.js",
|
|
28
|
+
"./run": "./dist/run.js",
|
|
28
29
|
"./package.json": "./package.json"
|
|
29
30
|
},
|
|
30
31
|
"typesVersions": {
|
|
@@ -70,7 +71,7 @@
|
|
|
70
71
|
"empathic": "^1.1.0",
|
|
71
72
|
"hookable": "^5.5.3",
|
|
72
73
|
"rolldown": "1.0.0-beta.9",
|
|
73
|
-
"rolldown-plugin-dts": "^0.13.
|
|
74
|
+
"rolldown-plugin-dts": "^0.13.4",
|
|
74
75
|
"semver": "^7.7.2",
|
|
75
76
|
"tinyexec": "^1.0.1",
|
|
76
77
|
"tinyglobby": "^0.2.13",
|