tsdown 0.12.0 → 0.12.1
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/{types-CHTYRF4v.d.ts → config-BVsukpAr.d.ts} +69 -11
- package/dist/config.d.ts +1 -2
- package/dist/index.d.ts +1 -34
- package/dist/index.js +90 -47
- package/dist/{logger-DcIo21Wv.js → logger-CS4H_tpu.js} +1 -1
- package/dist/{migrate-Cq_lJ3EI.js → migrate-BPmYzyBD.js} +2 -2
- package/dist/package-CkWLthTs.js +5 -0
- package/dist/{plugins-BV3QPDFO.js → plugins-D-fqvWYC.js} +11 -11
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +2 -2
- package/dist/run.js +8 -8
- package/package.json +1 -1
- package/dist/config-DttGOO6N.d.ts +0 -13
- package/dist/package-rd2yGx0m.js +0 -5
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "ansis";
|
|
2
|
+
import { BuildOptions, ExternalOption, InputOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, OutputAsset, OutputChunk, OutputOptions, Plugin } from "rolldown";
|
|
2
3
|
import { Options } from "rolldown-plugin-dts";
|
|
3
4
|
import { Hookable } from "hookable";
|
|
4
5
|
import { Options as Options$1 } from "publint";
|
|
@@ -12,13 +13,17 @@ type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T,
|
|
|
12
13
|
type Arrayable<T> = T | T[];
|
|
13
14
|
|
|
14
15
|
//#endregion
|
|
15
|
-
//#region src/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
//#region src/utils/logger.d.ts
|
|
17
|
+
declare class Logger {
|
|
18
|
+
silent: boolean;
|
|
19
|
+
setSilent(value: boolean): void;
|
|
20
|
+
filter(...args: any[]): any[];
|
|
21
|
+
info(...args: any[]): void;
|
|
22
|
+
warn(...args: any[]): void;
|
|
23
|
+
error(...args: any[]): void;
|
|
24
|
+
success(...args: any[]): void;
|
|
19
25
|
}
|
|
20
|
-
|
|
21
|
-
type CopyOptionsFn = (options: ResolvedOptions) => Awaitable<CopyOptions>;
|
|
26
|
+
declare const logger: Logger;
|
|
22
27
|
|
|
23
28
|
//#endregion
|
|
24
29
|
//#region src/features/hooks.d.ts
|
|
@@ -52,6 +57,33 @@ interface TsdownHooks {
|
|
|
52
57
|
"build:done": (ctx: BuildContext) => void | Promise<void>;
|
|
53
58
|
}
|
|
54
59
|
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/index.d.ts
|
|
62
|
+
/**
|
|
63
|
+
* Build with tsdown.
|
|
64
|
+
*/
|
|
65
|
+
declare function build$1(userOptions?: Options$3): Promise<void>;
|
|
66
|
+
declare const pkgRoot: string;
|
|
67
|
+
type TsdownChunks = Partial<Record<NormalizedFormat, Array<OutputChunk | OutputAsset>>>;
|
|
68
|
+
/**
|
|
69
|
+
* Build a single configuration, without watch and shortcuts features.
|
|
70
|
+
*
|
|
71
|
+
* Internal API, not for public use
|
|
72
|
+
*
|
|
73
|
+
* @private
|
|
74
|
+
* @param config Resolved options
|
|
75
|
+
*/
|
|
76
|
+
declare function buildSingle(config: ResolvedOptions, clean: () => Promise<void>): Promise<(() => Promise<void>) | undefined>;
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/features/copy.d.ts
|
|
80
|
+
interface CopyEntry {
|
|
81
|
+
from: string;
|
|
82
|
+
to: string;
|
|
83
|
+
}
|
|
84
|
+
type CopyOptions = Arrayable<string | CopyEntry>;
|
|
85
|
+
type CopyOptionsFn = (options: ResolvedOptions) => Awaitable<CopyOptions>;
|
|
86
|
+
|
|
55
87
|
//#endregion
|
|
56
88
|
//#region src/utils/package.d.ts
|
|
57
89
|
type PackageType = "module" | "commonjs" | undefined;
|
|
@@ -111,6 +143,24 @@ interface Workspace {
|
|
|
111
143
|
*/
|
|
112
144
|
config?: boolean | string;
|
|
113
145
|
}
|
|
146
|
+
interface ExportsOptions {
|
|
147
|
+
/**
|
|
148
|
+
* Generate exports that link to source code during development.
|
|
149
|
+
* - string: add as a custom condition.
|
|
150
|
+
* - true: all conditions point to source files, and add dist exports to `publishConfig`.
|
|
151
|
+
*/
|
|
152
|
+
devExports?: boolean | string;
|
|
153
|
+
/**
|
|
154
|
+
* Exports for all files.
|
|
155
|
+
*/
|
|
156
|
+
all?: boolean;
|
|
157
|
+
customExports?: (exports: Record<string, any>, context: {
|
|
158
|
+
pkg: PackageJson;
|
|
159
|
+
chunks: TsdownChunks;
|
|
160
|
+
outDir: string;
|
|
161
|
+
isPublish: boolean;
|
|
162
|
+
}) => Awaitable<Record<string, any>>;
|
|
163
|
+
}
|
|
114
164
|
/**
|
|
115
165
|
* Options for tsdown.
|
|
116
166
|
*/
|
|
@@ -248,12 +298,12 @@ interface Options$3 {
|
|
|
248
298
|
*/
|
|
249
299
|
report?: boolean | ReportOptions;
|
|
250
300
|
/**
|
|
251
|
-
* Generate exports map for `package.json`.
|
|
301
|
+
* **[experimental]** Generate exports map for `package.json`.
|
|
252
302
|
*
|
|
253
303
|
* This will set the `main`, `module`, `types`, `exports` fields in `package.json`
|
|
254
304
|
* to point to the generated files.
|
|
255
305
|
*/
|
|
256
|
-
exports?: boolean;
|
|
306
|
+
exports?: boolean | ExportsOptions;
|
|
257
307
|
/**
|
|
258
308
|
* Compile-time env variables.
|
|
259
309
|
* @example
|
|
@@ -317,7 +367,7 @@ interface Options$3 {
|
|
|
317
367
|
*/
|
|
318
368
|
type UserConfig = Arrayable<Omit<Options$3, "config" | "filter">>;
|
|
319
369
|
type UserConfigFn = (cliOptions: Options$3) => Awaitable<UserConfig>;
|
|
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"
|
|
370
|
+
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">, {
|
|
321
371
|
format: NormalizedFormat[];
|
|
322
372
|
target?: string[];
|
|
323
373
|
clean: string[];
|
|
@@ -325,5 +375,13 @@ type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" |
|
|
|
325
375
|
report: false | ReportOptions;
|
|
326
376
|
tsconfig: string | false;
|
|
327
377
|
pkg?: PackageJson;
|
|
378
|
+
exports: false | ExportsOptions;
|
|
328
379
|
}>, "config" | "fromVite">; //#endregion
|
|
329
|
-
|
|
380
|
+
//#region src/config.d.ts
|
|
381
|
+
/**
|
|
382
|
+
* Defines the configuration for tsdown.
|
|
383
|
+
*/
|
|
384
|
+
declare function defineConfig(options: UserConfig | UserConfigFn): UserConfig | UserConfigFn;
|
|
385
|
+
|
|
386
|
+
//#endregion
|
|
387
|
+
export { BuildContext, Options$3 as Options, ReportPlugin as ReportPlugin$1, ResolvedOptions, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build$1 as build, buildSingle, defineConfig as defineConfig$1, logger, pkgRoot };
|
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { UserConfig, UserConfigFn } from "./
|
|
2
|
-
import { defineConfig$1 as defineConfig } from "./config-DttGOO6N.js";
|
|
1
|
+
import { UserConfig, UserConfigFn, defineConfig$1 as defineConfig } from "./config-BVsukpAr.js";
|
|
3
2
|
export { UserConfig, UserConfigFn, defineConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
import { BuildContext,
|
|
2
|
-
import { defineConfig$1 as defineConfig } from "./config-DttGOO6N.js";
|
|
3
|
-
import "ansis";
|
|
4
|
-
import { InternalModuleFormat, OutputAsset, OutputChunk } from "rolldown";
|
|
5
|
-
|
|
6
|
-
//#region src/utils/logger.d.ts
|
|
7
|
-
declare class Logger {
|
|
8
|
-
silent: boolean;
|
|
9
|
-
setSilent(value: boolean): void;
|
|
10
|
-
filter(...args: any[]): any[];
|
|
11
|
-
info(...args: any[]): void;
|
|
12
|
-
warn(...args: any[]): void;
|
|
13
|
-
error(...args: any[]): void;
|
|
14
|
-
success(...args: any[]): void;
|
|
15
|
-
}
|
|
16
|
-
declare const logger: Logger; //#endregion
|
|
17
|
-
//#region src/index.d.ts
|
|
18
|
-
/**
|
|
19
|
-
* Build with tsdown.
|
|
20
|
-
*/
|
|
21
|
-
declare function build(userOptions?: Options): Promise<void>;
|
|
22
|
-
declare const pkgRoot: string;
|
|
23
|
-
type TsdownChunks = Partial<Record<NormalizedFormat, Array<OutputChunk | OutputAsset>>>;
|
|
24
|
-
/**
|
|
25
|
-
* Build a single configuration, without watch and shortcuts features.
|
|
26
|
-
*
|
|
27
|
-
* Internal API, not for public use
|
|
28
|
-
*
|
|
29
|
-
* @private
|
|
30
|
-
* @param config Resolved options
|
|
31
|
-
*/
|
|
32
|
-
declare function buildSingle(config: ResolvedOptions, clean: () => Promise<void>): Promise<(() => Promise<void>) | undefined>;
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
1
|
+
import { BuildContext, Options, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig$1 as defineConfig, logger, pkgRoot } from "./config-BVsukpAr.js";
|
|
35
2
|
export { BuildContext, Options, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { defineConfig } from "./config-yiJy1jd0.js";
|
|
2
|
-
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsRemove, fsStat, lowestCommonAncestor } from "./plugins-
|
|
3
|
-
import { debounce, generateColor, logger, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-
|
|
2
|
+
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsRemove, fsStat, lowestCommonAncestor } from "./plugins-D-fqvWYC.js";
|
|
3
|
+
import { debounce, generateColor, logger$1 as logger, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-CS4H_tpu.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import { blue, bold, dim, green, underline } from "ansis";
|
|
8
8
|
import { build as build$1 } from "rolldown";
|
|
9
9
|
import { exec } from "tinyexec";
|
|
10
|
-
import
|
|
10
|
+
import debug from "debug";
|
|
11
11
|
import { glob } from "tinyglobby";
|
|
12
12
|
import { readFile, writeFile } from "node:fs/promises";
|
|
13
13
|
import { RE_DTS } from "rolldown-plugin-dts";
|
|
@@ -19,7 +19,7 @@ import { up as up$1 } from "empathic/find";
|
|
|
19
19
|
import { loadConfig } from "unconfig";
|
|
20
20
|
|
|
21
21
|
//#region src/features/clean.ts
|
|
22
|
-
const debug$
|
|
22
|
+
const debug$4 = debug("tsdown:clean");
|
|
23
23
|
const RE_LAST_SLASH = /[/\\]$/;
|
|
24
24
|
async function cleanOutDir(configs) {
|
|
25
25
|
const removes = new Set();
|
|
@@ -39,10 +39,10 @@ async function cleanOutDir(configs) {
|
|
|
39
39
|
if (!removes.size) return;
|
|
40
40
|
logger.info(`Cleaning ${removes.size} files`);
|
|
41
41
|
await Promise.all([...removes].map(async (file) => {
|
|
42
|
-
debug$
|
|
42
|
+
debug$4("Removing", file);
|
|
43
43
|
await fsRemove(file);
|
|
44
44
|
}));
|
|
45
|
-
debug$
|
|
45
|
+
debug$4("Removed %d files", removes.size);
|
|
46
46
|
}
|
|
47
47
|
function resolveClean(clean, outDir, cwd) {
|
|
48
48
|
if (clean === true) clean = [slash(outDir)];
|
|
@@ -72,16 +72,26 @@ async function writeExports(options, chunks) {
|
|
|
72
72
|
if (!options.exports) return;
|
|
73
73
|
const { outDir, pkg } = options;
|
|
74
74
|
if (!pkg) throw new Error("`package.json` not found, cannot write exports");
|
|
75
|
-
const generated = generateExports(pkg, outDir, chunks);
|
|
75
|
+
const { publishExports,...generated } = await generateExports(pkg, outDir, chunks, options.exports);
|
|
76
|
+
const updatedPkg = {
|
|
77
|
+
...pkg,
|
|
78
|
+
...generated,
|
|
79
|
+
packageJsonPath: void 0
|
|
80
|
+
};
|
|
81
|
+
if (publishExports) {
|
|
82
|
+
updatedPkg.publishConfig ||= {};
|
|
83
|
+
updatedPkg.publishConfig.exports = publishExports;
|
|
84
|
+
}
|
|
76
85
|
await writeFile(pkg.packageJsonPath, `${JSON.stringify({
|
|
77
86
|
...pkg,
|
|
78
87
|
...generated,
|
|
79
88
|
packageJsonPath: void 0
|
|
80
89
|
}, null, 2)}\n`);
|
|
81
90
|
}
|
|
82
|
-
function generateExports(pkg, outDir, chunks) {
|
|
83
|
-
const
|
|
84
|
-
const
|
|
91
|
+
async function generateExports(pkg, outDir, chunks, { devExports, all, customExports }) {
|
|
92
|
+
const pkgJsonPath = pkg.packageJsonPath;
|
|
93
|
+
const pkgRoot$1 = path.dirname(pkgJsonPath);
|
|
94
|
+
const outDirRelative = slash(path.relative(pkgRoot$1, outDir));
|
|
85
95
|
let main, module, cjsTypes, esmTypes;
|
|
86
96
|
const exportsMap = new Map();
|
|
87
97
|
for (const [format, chunksByFormat] of Object.entries(chunks)) {
|
|
@@ -89,12 +99,12 @@ function generateExports(pkg, outDir, chunks) {
|
|
|
89
99
|
const onlyOneEntry = chunksByFormat.filter((chunk) => chunk.type === "chunk" && chunk.isEntry && !RE_DTS.test(chunk.fileName)).length === 1;
|
|
90
100
|
for (const chunk of chunksByFormat) {
|
|
91
101
|
if (chunk.type !== "chunk" || !chunk.isEntry) continue;
|
|
92
|
-
const distFile = `./${path.join(basePath, chunk.fileName)}`;
|
|
93
102
|
const ext = path.extname(chunk.fileName);
|
|
94
103
|
let name = chunk.fileName.slice(0, -ext.length);
|
|
95
104
|
const isDts = name.endsWith(".d");
|
|
96
105
|
if (isDts) name = name.slice(0, -2);
|
|
97
|
-
const isIndex = name === "index"
|
|
106
|
+
const isIndex = onlyOneEntry || name === "index";
|
|
107
|
+
const distFile = `${outDirRelative ? `./${outDirRelative}` : "."}/${chunk.fileName}`;
|
|
98
108
|
if (isIndex) {
|
|
99
109
|
name = ".";
|
|
100
110
|
if (format === "cjs") if (isDts) cjsTypes = distFile;
|
|
@@ -102,34 +112,65 @@ function generateExports(pkg, outDir, chunks) {
|
|
|
102
112
|
else if (format === "es") if (isDts) esmTypes = distFile;
|
|
103
113
|
else module = distFile;
|
|
104
114
|
} else name = `./${name}`;
|
|
105
|
-
let
|
|
106
|
-
if (!
|
|
107
|
-
|
|
108
|
-
exportsMap.set(name,
|
|
115
|
+
let subExport = exportsMap.get(name);
|
|
116
|
+
if (!subExport) {
|
|
117
|
+
subExport = {};
|
|
118
|
+
exportsMap.set(name, subExport);
|
|
119
|
+
}
|
|
120
|
+
if (!isDts) {
|
|
121
|
+
subExport[format] = distFile;
|
|
122
|
+
if (chunk.facadeModuleId && !subExport.src) subExport.src = `./${slash(path.relative(pkgRoot$1, chunk.facadeModuleId))}`;
|
|
109
123
|
}
|
|
110
|
-
if (!isDts && !RE_DTS.test(chunk.fileName)) map.set(format, distFile);
|
|
111
124
|
}
|
|
112
125
|
}
|
|
113
|
-
const
|
|
126
|
+
const sorttedExportsMap = Array.from(exportsMap.entries()).sort(([a], [b]) => {
|
|
114
127
|
if (a === "index") return -1;
|
|
115
128
|
return a.localeCompare(b);
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
|
|
129
|
+
});
|
|
130
|
+
let exports = Object.fromEntries(sorttedExportsMap.map(([name, subExport]) => [name, genSubExport(devExports, subExport)]));
|
|
131
|
+
exportMeta(exports, all);
|
|
132
|
+
if (customExports) exports = await customExports(exports, {
|
|
133
|
+
pkg,
|
|
134
|
+
outDir,
|
|
135
|
+
chunks,
|
|
136
|
+
isPublish: false
|
|
137
|
+
});
|
|
138
|
+
let publishExports;
|
|
139
|
+
if (devExports) {
|
|
140
|
+
publishExports = Object.fromEntries(sorttedExportsMap.map(([name, subExport]) => [name, genSubExport(false, subExport)]));
|
|
141
|
+
exportMeta(publishExports, all);
|
|
142
|
+
if (customExports) publishExports = await customExports(publishExports, {
|
|
143
|
+
pkg,
|
|
144
|
+
outDir,
|
|
145
|
+
chunks,
|
|
146
|
+
isPublish: true
|
|
147
|
+
});
|
|
148
|
+
}
|
|
126
149
|
return {
|
|
127
150
|
main: main || module || pkg.main,
|
|
128
151
|
module: module || pkg.module,
|
|
129
152
|
types: cjsTypes || esmTypes || pkg.types,
|
|
130
|
-
exports
|
|
153
|
+
exports,
|
|
154
|
+
publishExports
|
|
131
155
|
};
|
|
132
156
|
}
|
|
157
|
+
function genSubExport(devExports, { src, es, cjs }) {
|
|
158
|
+
if (devExports === true) return src;
|
|
159
|
+
let value;
|
|
160
|
+
const dualFormat = es && cjs;
|
|
161
|
+
if (!dualFormat && !devExports) value = cjs || es;
|
|
162
|
+
else {
|
|
163
|
+
value = {};
|
|
164
|
+
if (typeof devExports === "string") value[devExports] = src;
|
|
165
|
+
if (es) value[dualFormat ? "import" : "default"] = es;
|
|
166
|
+
if (cjs) value[dualFormat ? "require" : "default"] = cjs;
|
|
167
|
+
}
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
function exportMeta(exports, all) {
|
|
171
|
+
if (all) exports["./*"] = "./*";
|
|
172
|
+
else exports["./package.json"] = "./package.json";
|
|
173
|
+
}
|
|
133
174
|
|
|
134
175
|
//#endregion
|
|
135
176
|
//#region src/features/hooks.ts
|
|
@@ -201,11 +242,11 @@ async function LightningCSSPlugin(options) {
|
|
|
201
242
|
|
|
202
243
|
//#endregion
|
|
203
244
|
//#region src/utils/package.ts
|
|
204
|
-
const debug$
|
|
245
|
+
const debug$3 = debug("tsdown:package");
|
|
205
246
|
async function readPackageJson(dir) {
|
|
206
247
|
const packageJsonPath = up({ cwd: dir });
|
|
207
248
|
if (!packageJsonPath) return;
|
|
208
|
-
debug$
|
|
249
|
+
debug$3("Reading package.json:", packageJsonPath);
|
|
209
250
|
const contents = await readFile(packageJsonPath, "utf8");
|
|
210
251
|
return {
|
|
211
252
|
...JSON.parse(contents),
|
|
@@ -266,7 +307,7 @@ function createChunkFilename(basename, jsExtension, dtsExtension) {
|
|
|
266
307
|
|
|
267
308
|
//#endregion
|
|
268
309
|
//#region src/features/publint.ts
|
|
269
|
-
const debug$
|
|
310
|
+
const debug$2 = debug("tsdown:publint");
|
|
270
311
|
async function publint(options) {
|
|
271
312
|
if (!options.publint) return;
|
|
272
313
|
if (!options.pkg) {
|
|
@@ -274,11 +315,11 @@ async function publint(options) {
|
|
|
274
315
|
return;
|
|
275
316
|
}
|
|
276
317
|
const t = performance.now();
|
|
277
|
-
debug$
|
|
318
|
+
debug$2("Running publint");
|
|
278
319
|
const { publint: publint$1 } = await import("publint");
|
|
279
320
|
const { formatMessage } = await import("publint/utils");
|
|
280
321
|
const { messages } = await publint$1(options.publint === true ? {} : options.publint);
|
|
281
|
-
debug$
|
|
322
|
+
debug$2("Found %d issues", messages.length);
|
|
282
323
|
if (!messages.length) logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
283
324
|
let hasError = false;
|
|
284
325
|
for (const message of messages) {
|
|
@@ -292,7 +333,7 @@ async function publint(options) {
|
|
|
292
333
|
logger[logType](formattedMessage);
|
|
293
334
|
}
|
|
294
335
|
if (hasError) {
|
|
295
|
-
debug$
|
|
336
|
+
debug$2("Found errors, setting exit code to 1");
|
|
296
337
|
process.exitCode = 1;
|
|
297
338
|
}
|
|
298
339
|
}
|
|
@@ -582,7 +623,7 @@ async function loadConfigFile(options, workspace) {
|
|
|
582
623
|
|
|
583
624
|
//#endregion
|
|
584
625
|
//#region src/options/index.ts
|
|
585
|
-
const debug =
|
|
626
|
+
const debug$1 = debug("tsdown:options");
|
|
586
627
|
const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
587
628
|
"**/node_modules/**",
|
|
588
629
|
"**/dist/**",
|
|
@@ -591,20 +632,20 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
|
591
632
|
];
|
|
592
633
|
async function resolveOptions(options) {
|
|
593
634
|
const files = [];
|
|
594
|
-
debug("options %O", options);
|
|
595
|
-
debug("loading config file: %s", options.config);
|
|
635
|
+
debug$1("options %O", options);
|
|
636
|
+
debug$1("loading config file: %s", options.config);
|
|
596
637
|
const { configs: rootConfigs, file } = await loadConfigFile(options);
|
|
597
638
|
if (file) {
|
|
598
639
|
files.push(file);
|
|
599
|
-
debug("loaded root config file %s", file);
|
|
600
|
-
debug("root configs %o", rootConfigs);
|
|
601
|
-
} else debug("no root config file found");
|
|
640
|
+
debug$1("loaded root config file %s", file);
|
|
641
|
+
debug$1("root configs %o", rootConfigs);
|
|
642
|
+
} else debug$1("no root config file found");
|
|
602
643
|
const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
|
|
603
644
|
const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
|
|
604
645
|
if (workspaceFiles) files.push(...workspaceFiles);
|
|
605
646
|
return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveConfig(config)));
|
|
606
647
|
}))).flat();
|
|
607
|
-
debug("resolved configs %O", configs);
|
|
648
|
+
debug$1("resolved configs %O", configs);
|
|
608
649
|
return {
|
|
609
650
|
configs,
|
|
610
651
|
files
|
|
@@ -646,16 +687,16 @@ async function resolveWorkspace(config, options) {
|
|
|
646
687
|
}
|
|
647
688
|
const files = [];
|
|
648
689
|
const configs = (await Promise.all(packages.map(async (cwd) => {
|
|
649
|
-
debug("loading workspace config %s", cwd);
|
|
690
|
+
debug$1("loading workspace config %s", cwd);
|
|
650
691
|
const { configs: configs$1, file } = await loadConfigFile({
|
|
651
692
|
...options,
|
|
652
693
|
config: workspaceConfig,
|
|
653
694
|
cwd
|
|
654
695
|
}, cwd);
|
|
655
696
|
if (file) {
|
|
656
|
-
debug("loaded workspace config file %s", file);
|
|
697
|
+
debug$1("loaded workspace config file %s", file);
|
|
657
698
|
files.push(file);
|
|
658
|
-
} else debug("no workspace config file found in %s", cwd);
|
|
699
|
+
} else debug$1("no workspace config file found in %s", cwd);
|
|
659
700
|
return configs$1.map((config$1) => ({
|
|
660
701
|
...normalized,
|
|
661
702
|
cwd,
|
|
@@ -668,7 +709,7 @@ async function resolveWorkspace(config, options) {
|
|
|
668
709
|
};
|
|
669
710
|
}
|
|
670
711
|
async function resolveConfig(userConfig) {
|
|
671
|
-
let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch = [], shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal } = userConfig;
|
|
712
|
+
let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch = [], shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal, exports = false } = userConfig;
|
|
672
713
|
outDir = path.resolve(cwd, outDir);
|
|
673
714
|
clean = resolveClean(clean, outDir, cwd);
|
|
674
715
|
const pkg = await readPackageJson(cwd);
|
|
@@ -680,6 +721,7 @@ async function resolveConfig(userConfig) {
|
|
|
680
721
|
if (typeof external === "string") external = resolveRegex(external);
|
|
681
722
|
if (typeof noExternal === "string") noExternal = resolveRegex(noExternal);
|
|
682
723
|
if (publint$1 === true) publint$1 = {};
|
|
724
|
+
if (exports === true) exports = {};
|
|
683
725
|
if (publicDir) if (copy$1) throw new TypeError("`publicDir` is deprecated. Cannot be used with `copy`");
|
|
684
726
|
else logger.warn(`${blue`publicDir`} is deprecated. Use ${blue`copy`} instead.`);
|
|
685
727
|
if (fromVite) {
|
|
@@ -720,7 +762,8 @@ async function resolveConfig(userConfig) {
|
|
|
720
762
|
hash: hash ?? true,
|
|
721
763
|
name,
|
|
722
764
|
external,
|
|
723
|
-
noExternal
|
|
765
|
+
noExternal,
|
|
766
|
+
exports
|
|
724
767
|
};
|
|
725
768
|
return config;
|
|
726
769
|
}
|
|
@@ -117,4 +117,4 @@ function hue2rgb(p, q, t) {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
//#endregion
|
|
120
|
-
export { debounce, generateColor, logger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray };
|
|
120
|
+
export { debounce, generateColor, logger as logger$1, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger } from "./logger-
|
|
2
|
-
import { version } from "./package-
|
|
1
|
+
import { logger$1 as logger } from "./logger-CS4H_tpu.js";
|
|
2
|
+
import { version } from "./package-CkWLthTs.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";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { logger, noop, prettyFormat, prettyName, toArray } from "./logger-
|
|
1
|
+
import { logger$1 as logger, noop, prettyFormat, prettyName, toArray } from "./logger-CS4H_tpu.js";
|
|
2
2
|
import path, { dirname, normalize, sep } from "node:path";
|
|
3
3
|
import { bold, dim, green, underline } from "ansis";
|
|
4
|
-
import
|
|
4
|
+
import debug from "debug";
|
|
5
5
|
import { access, chmod, cp, rm, stat } from "node:fs/promises";
|
|
6
|
+
import { RE_DTS } from "rolldown-plugin-dts";
|
|
6
7
|
import { Buffer } from "node:buffer";
|
|
7
8
|
import { promisify } from "node:util";
|
|
8
9
|
import { brotliCompress, gzip } from "node:zlib";
|
|
@@ -47,7 +48,7 @@ function lowestCommonAncestor(...filepaths) {
|
|
|
47
48
|
|
|
48
49
|
//#endregion
|
|
49
50
|
//#region src/features/external.ts
|
|
50
|
-
const debug$
|
|
51
|
+
const debug$2 = debug("tsdown:external");
|
|
51
52
|
function ExternalPlugin(options) {
|
|
52
53
|
const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
|
|
53
54
|
return {
|
|
@@ -70,7 +71,7 @@ function ExternalPlugin(options) {
|
|
|
70
71
|
}
|
|
71
72
|
if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
|
|
72
73
|
if (shouldExternal) {
|
|
73
|
-
debug$
|
|
74
|
+
debug$2("External dependency:", id);
|
|
74
75
|
return {
|
|
75
76
|
id,
|
|
76
77
|
external: shouldExternal
|
|
@@ -119,10 +120,9 @@ function formatBytes(bytes) {
|
|
|
119
120
|
|
|
120
121
|
//#endregion
|
|
121
122
|
//#region src/features/report.ts
|
|
122
|
-
const debug =
|
|
123
|
+
const debug$1 = debug("tsdown:report");
|
|
123
124
|
const brotliCompressAsync = promisify(brotliCompress);
|
|
124
125
|
const gzipAsync = promisify(gzip);
|
|
125
|
-
const RE_DTS = /\.d\.[cm]?ts$/;
|
|
126
126
|
function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
|
|
127
127
|
return {
|
|
128
128
|
name: "tsdown:report",
|
|
@@ -161,19 +161,19 @@ function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
|
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
async function calcSize(options, chunk) {
|
|
164
|
-
debug(`Calculating size for`, chunk.fileName);
|
|
164
|
+
debug$1(`Calculating size for`, chunk.fileName);
|
|
165
165
|
const content = chunk.type === "chunk" ? chunk.code : chunk.source;
|
|
166
166
|
const raw = Buffer.byteLength(content, "utf8");
|
|
167
|
-
debug("[size]", chunk.fileName, raw);
|
|
167
|
+
debug$1("[size]", chunk.fileName, raw);
|
|
168
168
|
let gzip$1 = Infinity;
|
|
169
169
|
let brotli = Infinity;
|
|
170
|
-
if (raw > (options.maxCompressSize ?? 1e6)) debug(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
|
|
170
|
+
if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
|
|
171
171
|
else {
|
|
172
172
|
gzip$1 = (await gzipAsync(content)).length;
|
|
173
|
-
debug("[gzip]", chunk.fileName, gzip$1);
|
|
173
|
+
debug$1("[gzip]", chunk.fileName, gzip$1);
|
|
174
174
|
if (options.brotli) {
|
|
175
175
|
brotli = (await brotliCompressAsync(content)).length;
|
|
176
|
-
debug("[brotli]", chunk.fileName, brotli);
|
|
176
|
+
debug$1("[brotli]", chunk.fileName, brotli);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
return {
|
package/dist/plugins.d.ts
CHANGED
package/dist/plugins.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./plugins-
|
|
2
|
-
import "./logger-
|
|
1
|
+
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./plugins-D-fqvWYC.js";
|
|
2
|
+
import "./logger-CS4H_tpu.js";
|
|
3
3
|
|
|
4
4
|
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
|
package/dist/run.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { logger, resolveComma, toArray } from "./logger-
|
|
3
|
-
import { version } from "./package-
|
|
2
|
+
import { logger$1 as logger, resolveComma, toArray } from "./logger-CS4H_tpu.js";
|
|
3
|
+
import { version } from "./package-CkWLthTs.js";
|
|
4
4
|
import module from "node:module";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { dim } from "ansis";
|
|
7
7
|
import { VERSION } from "rolldown";
|
|
8
|
-
import
|
|
8
|
+
import debug from "debug";
|
|
9
9
|
import { cac } from "cac";
|
|
10
10
|
|
|
11
11
|
//#region src/cli.ts
|
|
@@ -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("-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) => {
|
|
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").option("--exports", "Generate export-related metadata for package.json (experimental)").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-BPmYzyBD.js");
|
|
26
26
|
await migrate(args);
|
|
27
27
|
});
|
|
28
28
|
async function runCLI() {
|
|
@@ -31,10 +31,10 @@ async function runCLI() {
|
|
|
31
31
|
let namespace;
|
|
32
32
|
if (cli.options.debug === true) namespace = "tsdown:*";
|
|
33
33
|
else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
|
|
34
|
-
const enabled =
|
|
34
|
+
const enabled = debug.disable();
|
|
35
35
|
if (enabled) namespace += `,${enabled}`;
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
debug.enable(namespace);
|
|
37
|
+
debug("tsdown:debug")("Debugging enabled", namespace);
|
|
38
38
|
}
|
|
39
39
|
try {
|
|
40
40
|
await cli.runMatchedCommand();
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { UserConfig, UserConfigFn } from "./types-CHTYRF4v.js";
|
|
2
|
-
|
|
3
|
-
//#region src/config.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Defines the configuration for tsdown.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Defines the configuration for tsdown.
|
|
9
|
-
*/
|
|
10
|
-
declare function defineConfig(options: UserConfig | UserConfigFn): UserConfig | UserConfigFn;
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
export { defineConfig as defineConfig$1 };
|