tsdown 0.16.0 → 0.16.2
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-8JTxhwDL.d.mts → config-BNLClkOs.d.mts} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -3
- package/dist/{migrate-C8f4tEcE.mjs → migrate-vnxXpCFh.mjs} +1 -1
- package/dist/{package-CTfVaX9t.mjs → package-DMNYxkVA.mjs} +2 -4
- package/dist/plugins.d.mts +1 -1
- package/dist/plugins.mjs +3 -3
- package/dist/run.mjs +3 -3
- package/dist/{src-B9FIpS_R.mjs → src-CX-S_cyD.mjs} +171 -146
- package/package.json +15 -19
- /package/dist/{config-BPLXnzPK.mjs → config-DLSWqKoz.mjs} +0 -0
- /package/dist/{index-CSOY_TcZ.d.mts → index-BcO8yjl6.d.mts} +0 -0
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./index-
|
|
2
|
-
import { t as defineConfig } from "./config-
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./index-BcO8yjl6.mjs";
|
|
2
|
+
import { t as defineConfig } from "./config-BNLClkOs.mjs";
|
|
3
3
|
export { UserConfig, UserConfigExport, UserConfigFn, defineConfig };
|
package/dist/config.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as TsdownChunks, C as OutExtensionFactory, D as RolldownContext, E as BuildContext, F as AttwOptions, M as CopyEntry, N as CopyOptions, O as TsdownHooks, P as CopyOptionsFn, S as OutExtensionContext, T as PackageType, _ as Logger, a as NormalizedFormat, b as ChunkAddonFunction, c as Sourcemap, d as UserConfig, f as UserConfigExport, h as ReportOptions, i as NoExternalFn, j as DebugOptions, k as ExportsOptions, l as TreeshakingOptions, m as Workspace, n as Format, o as PublintOptions, p as UserConfigFn, r as InlineConfig, s as ResolvedConfig, t as DtsOptions, u as UnusedOptions, v as globalLogger, w as OutExtensionObject, x as ChunkAddonObject, y as ChunkAddon } from "./index-
|
|
2
|
-
import { t as defineConfig } from "./config-
|
|
1
|
+
import { A as TsdownChunks, C as OutExtensionFactory, D as RolldownContext, E as BuildContext, F as AttwOptions, M as CopyEntry, N as CopyOptions, O as TsdownHooks, P as CopyOptionsFn, S as OutExtensionContext, T as PackageType, _ as Logger, a as NormalizedFormat, b as ChunkAddonFunction, c as Sourcemap, d as UserConfig, f as UserConfigExport, h as ReportOptions, i as NoExternalFn, j as DebugOptions, k as ExportsOptions, l as TreeshakingOptions, m as Workspace, n as Format, o as PublintOptions, p as UserConfigFn, r as InlineConfig, s as ResolvedConfig, t as DtsOptions, u as UnusedOptions, v as globalLogger, w as OutExtensionObject, x as ChunkAddonObject, y as ChunkAddon } from "./index-BcO8yjl6.mjs";
|
|
2
|
+
import { t as defineConfig } from "./config-BNLClkOs.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as defineConfig } from "./config-
|
|
2
|
-
import { n as buildSingle, r as shimFile, t as build } from "./src-
|
|
3
|
-
import { a as globalLogger } from "./package-
|
|
1
|
+
import { t as defineConfig } from "./config-DLSWqKoz.mjs";
|
|
2
|
+
import { n as buildSingle, r as shimFile, t as build } from "./src-CX-S_cyD.mjs";
|
|
3
|
+
import { a as globalLogger } from "./package-DMNYxkVA.mjs";
|
|
4
4
|
|
|
5
5
|
export { build, buildSingle, defineConfig, globalLogger, shimFile };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as globalLogger, t as version } from "./package-
|
|
1
|
+
import { a as globalLogger, t as version } from "./package-DMNYxkVA.mjs";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { bold, green, underline } from "ansis";
|
|
4
4
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
@@ -49,9 +49,7 @@ async function importWithError(moduleName) {
|
|
|
49
49
|
try {
|
|
50
50
|
return await import(moduleName);
|
|
51
51
|
} catch (error) {
|
|
52
|
-
|
|
53
|
-
final.cause = error;
|
|
54
|
-
throw final;
|
|
52
|
+
throw new Error(`Failed to import module "${moduleName}". Please ensure it is installed.`, { cause: error });
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
|
|
@@ -162,7 +160,7 @@ function hue2rgb(p, q, t) {
|
|
|
162
160
|
|
|
163
161
|
//#endregion
|
|
164
162
|
//#region package.json
|
|
165
|
-
var version = "0.16.
|
|
163
|
+
var version = "0.16.2";
|
|
166
164
|
|
|
167
165
|
//#endregion
|
|
168
166
|
export { globalLogger as a, debounce as c, noop as d, pkgExists as f, toArray as g, slash as h, generateColor as i, importWithError as l, resolveRegex as m, LogLevels as n, prettyFormat as o, resolveComma as p, createLogger as r, prettyName as s, version as t, matchPattern as u };
|
package/dist/plugins.d.mts
CHANGED
package/dist/plugins.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./config-
|
|
2
|
-
import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, s as ExternalPlugin } from "./src-
|
|
3
|
-
import "./package-
|
|
1
|
+
import "./config-DLSWqKoz.mjs";
|
|
2
|
+
import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, s as ExternalPlugin } from "./src-CX-S_cyD.mjs";
|
|
3
|
+
import "./package-DMNYxkVA.mjs";
|
|
4
4
|
|
|
5
5
|
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
|
package/dist/run.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
3
3
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
import { a as globalLogger, g as toArray, p as resolveComma, t as version } from "./package-
|
|
4
|
+
import { a as globalLogger, g as toArray, p as resolveComma, t as version } from "./package-DMNYxkVA.mjs";
|
|
5
5
|
import module from "node:module";
|
|
6
6
|
import process from "node:process";
|
|
7
7
|
import { dim } from "ansis";
|
|
@@ -30,7 +30,7 @@ cli.help().version(version);
|
|
|
30
30
|
cli.command("[...files]", "Bundle files", {
|
|
31
31
|
ignoreOptionDefaultValue: true,
|
|
32
32
|
allowUnknownOptions: true
|
|
33
|
-
}).option("-c, --config <filename>", "Use a custom config file").option("--config-loader <loader>", "Config loader to use: auto, native,
|
|
33
|
+
}).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("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug", "Enable debug mode").option("--debug-logs [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("-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("--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("-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) => {
|
|
34
34
|
globalLogger.level = flags.logLevel || (flags.silent ? "error" : "info");
|
|
35
35
|
globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
36
36
|
const { build: build$1 } = await import("./index.mjs");
|
|
@@ -38,7 +38,7 @@ cli.command("[...files]", "Bundle files", {
|
|
|
38
38
|
await build$1(flags);
|
|
39
39
|
});
|
|
40
40
|
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
41
|
-
const { migrate } = await import("./migrate-
|
|
41
|
+
const { migrate } = await import("./migrate-vnxXpCFh.mjs");
|
|
42
42
|
await migrate(args);
|
|
43
43
|
});
|
|
44
44
|
async function runCLI() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
-
import { a as globalLogger, c as debounce, d as noop, f as pkgExists, g as toArray, h as slash, i as generateColor, l as importWithError, m as resolveRegex, n as LogLevels, o as prettyFormat, p as resolveComma, r as createLogger, s as prettyName, t as version, u as matchPattern } from "./package-
|
|
3
|
+
import { a as globalLogger, c as debounce, d as noop, f as pkgExists, g as toArray, h as slash, i as generateColor, l as importWithError, m as resolveRegex, n as LogLevels, o as prettyFormat, p as resolveComma, r as createLogger, s as prettyName, t as version, u as matchPattern } from "./package-DMNYxkVA.mjs";
|
|
4
4
|
import { builtinModules, isBuiltin } from "node:module";
|
|
5
5
|
import path, { dirname, join, normalize, sep } from "node:path";
|
|
6
6
|
import process from "node:process";
|
|
@@ -9,20 +9,19 @@ import { blue, bold, dim, green, underline } from "ansis";
|
|
|
9
9
|
import { VERSION, build } from "rolldown";
|
|
10
10
|
import { exec } from "tinyexec";
|
|
11
11
|
const treeKill = __cjs_require("tree-kill");
|
|
12
|
-
const Debug = __cjs_require("debug");
|
|
13
|
-
import { glob } from "tinyglobby";
|
|
14
12
|
import { access, chmod, cp, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
13
|
+
const Debug = __cjs_require("debug");
|
|
14
|
+
import { createConfigCoreLoader } from "unconfig-core";
|
|
15
|
+
import { glob, isDynamicPattern } from "tinyglobby";
|
|
15
16
|
import { RE_CSS, RE_DTS, RE_JS, RE_NODE_MODULES } from "rolldown-plugin-dts/filename";
|
|
16
17
|
const minVersion = __cjs_require("semver/ranges/min-version.js");
|
|
17
18
|
import { up } from "empathic/find";
|
|
18
19
|
import { up as up$1 } from "empathic/package";
|
|
19
|
-
import { loadConfig } from "unconfig";
|
|
20
|
-
import child_process from "node:child_process";
|
|
21
20
|
import { tmpdir } from "node:os";
|
|
22
|
-
import util, { promisify } from "node:util";
|
|
23
21
|
const coerce = __cjs_require("semver/functions/coerce.js");
|
|
24
22
|
const satisfies = __cjs_require("semver/functions/satisfies.js");
|
|
25
23
|
import { createHooks } from "hookable";
|
|
24
|
+
import util, { promisify } from "node:util";
|
|
26
25
|
import { importGlobPlugin } from "rolldown/experimental";
|
|
27
26
|
import { Buffer } from "node:buffer";
|
|
28
27
|
import { brotliCompress, gzip } from "node:zlib";
|
|
@@ -67,6 +66,136 @@ function lowestCommonAncestor(...filepaths) {
|
|
|
67
66
|
return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
|
|
68
67
|
}
|
|
69
68
|
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/config/config.ts
|
|
71
|
+
const debug$8 = Debug("tsdown:config");
|
|
72
|
+
async function loadViteConfig(prefix, cwd, configLoader) {
|
|
73
|
+
const loader = resolveConfigLoader(configLoader);
|
|
74
|
+
debug$8("Loading Vite config via loader: ", loader);
|
|
75
|
+
const parser = createParser(loader);
|
|
76
|
+
const [result] = await createConfigCoreLoader({
|
|
77
|
+
sources: [{
|
|
78
|
+
files: [`${prefix}.config`],
|
|
79
|
+
extensions: [
|
|
80
|
+
"ts",
|
|
81
|
+
"mts",
|
|
82
|
+
"cts",
|
|
83
|
+
"js",
|
|
84
|
+
"mjs",
|
|
85
|
+
"cjs",
|
|
86
|
+
"json",
|
|
87
|
+
""
|
|
88
|
+
],
|
|
89
|
+
parser
|
|
90
|
+
}],
|
|
91
|
+
cwd
|
|
92
|
+
}).load();
|
|
93
|
+
if (!result) return;
|
|
94
|
+
const { config, source } = result;
|
|
95
|
+
globalLogger.info(`Using Vite config: ${underline(source)}`);
|
|
96
|
+
const resolved = await config;
|
|
97
|
+
if (typeof resolved === "function") return resolved({
|
|
98
|
+
command: "build",
|
|
99
|
+
mode: "production"
|
|
100
|
+
});
|
|
101
|
+
return resolved;
|
|
102
|
+
}
|
|
103
|
+
const configPrefix = "tsdown.config";
|
|
104
|
+
let isWatch = false;
|
|
105
|
+
function setWatch() {
|
|
106
|
+
isWatch = true;
|
|
107
|
+
}
|
|
108
|
+
async function loadConfigFile(inlineConfig, workspace) {
|
|
109
|
+
let cwd = inlineConfig.cwd || process.cwd();
|
|
110
|
+
let overrideConfig = false;
|
|
111
|
+
let { config: filePath } = inlineConfig;
|
|
112
|
+
if (filePath === false) return { configs: [{}] };
|
|
113
|
+
if (typeof filePath === "string") {
|
|
114
|
+
const stats = await fsStat(filePath);
|
|
115
|
+
if (stats) {
|
|
116
|
+
const resolved = path.resolve(filePath);
|
|
117
|
+
if (stats.isFile()) {
|
|
118
|
+
overrideConfig = true;
|
|
119
|
+
filePath = resolved;
|
|
120
|
+
cwd = path.dirname(filePath);
|
|
121
|
+
} else if (stats.isDirectory()) cwd = resolved;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const loader = resolveConfigLoader(inlineConfig.configLoader);
|
|
125
|
+
debug$8("Using config loader:", loader);
|
|
126
|
+
const parser = createParser(loader);
|
|
127
|
+
const [result] = await createConfigCoreLoader({
|
|
128
|
+
sources: overrideConfig ? [{
|
|
129
|
+
files: [filePath],
|
|
130
|
+
extensions: [],
|
|
131
|
+
parser
|
|
132
|
+
}] : [{
|
|
133
|
+
files: [configPrefix],
|
|
134
|
+
extensions: [
|
|
135
|
+
"ts",
|
|
136
|
+
"mts",
|
|
137
|
+
"cts",
|
|
138
|
+
"js",
|
|
139
|
+
"mjs",
|
|
140
|
+
"cjs",
|
|
141
|
+
"json",
|
|
142
|
+
""
|
|
143
|
+
],
|
|
144
|
+
parser
|
|
145
|
+
}, {
|
|
146
|
+
files: ["package.json"],
|
|
147
|
+
parser
|
|
148
|
+
}],
|
|
149
|
+
cwd,
|
|
150
|
+
stopAt: workspace && path.dirname(workspace)
|
|
151
|
+
}).load(isWatch);
|
|
152
|
+
let exported = [];
|
|
153
|
+
let file;
|
|
154
|
+
if (result) {
|
|
155
|
+
({config: exported, source: file} = result);
|
|
156
|
+
globalLogger.info(`Using tsdown config: ${underline(file)}`);
|
|
157
|
+
exported = await exported;
|
|
158
|
+
if (typeof exported === "function") exported = await exported(inlineConfig);
|
|
159
|
+
}
|
|
160
|
+
exported = toArray(exported);
|
|
161
|
+
if (exported.length === 0) exported.push({});
|
|
162
|
+
return {
|
|
163
|
+
configs: exported,
|
|
164
|
+
file
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function resolveConfigLoader(configLoader = "auto") {
|
|
168
|
+
if (isWatch) return "unrun";
|
|
169
|
+
else if (configLoader === "auto") return !!(process.features.typescript || process.versions.bun || process.versions.deno) ? "native" : "unrun";
|
|
170
|
+
else return configLoader === "native" ? "native" : "unrun";
|
|
171
|
+
}
|
|
172
|
+
function createParser(loader) {
|
|
173
|
+
return async (filepath) => {
|
|
174
|
+
const basename = path.basename(filepath);
|
|
175
|
+
const isPkgJson = basename === "package.json";
|
|
176
|
+
if (basename === configPrefix || isPkgJson || basename.endsWith(".json")) {
|
|
177
|
+
const contents = await readFile(filepath, "utf8");
|
|
178
|
+
const parsed = JSON.parse(contents);
|
|
179
|
+
if (isPkgJson) return parsed?.tsdown;
|
|
180
|
+
return parsed;
|
|
181
|
+
}
|
|
182
|
+
if (loader === "native") return nativeImport(filepath);
|
|
183
|
+
return unrunImport(filepath);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
async function nativeImport(id) {
|
|
187
|
+
const mod = await import(pathToFileURL(id).href).catch((error) => {
|
|
188
|
+
if (error?.message?.includes?.("Cannot find module")) throw new Error(`Failed to load the config file. Try setting the --config-loader CLI flag to \`unrun\`.\n\n${error.message}`, { cause: error });
|
|
189
|
+
else throw error;
|
|
190
|
+
});
|
|
191
|
+
return mod.default || mod;
|
|
192
|
+
}
|
|
193
|
+
async function unrunImport(id) {
|
|
194
|
+
const { unrun } = await import("unrun");
|
|
195
|
+
const { module: module$1 } = await unrun({ path: pathToFileURL(id).href });
|
|
196
|
+
return module$1;
|
|
197
|
+
}
|
|
198
|
+
|
|
70
199
|
//#endregion
|
|
71
200
|
//#region src/features/clean.ts
|
|
72
201
|
const debug$7 = Debug("tsdown:clean");
|
|
@@ -117,14 +246,18 @@ async function resolveEntry(logger, entry, cwd, name) {
|
|
|
117
246
|
async function toObjectEntry(entry, cwd) {
|
|
118
247
|
if (typeof entry === "string") entry = [entry];
|
|
119
248
|
if (!Array.isArray(entry)) return entry;
|
|
120
|
-
const
|
|
249
|
+
const isGlob = entry.some((e) => isDynamicPattern(e));
|
|
250
|
+
let resolvedEntry;
|
|
251
|
+
if (isGlob) resolvedEntry = (await glob(entry, {
|
|
121
252
|
cwd,
|
|
122
|
-
expandDirectories: false
|
|
123
|
-
|
|
253
|
+
expandDirectories: false,
|
|
254
|
+
absolute: true
|
|
255
|
+
})).map((file) => path.resolve(file));
|
|
256
|
+
else resolvedEntry = entry;
|
|
124
257
|
const base = lowestCommonAncestor(...resolvedEntry);
|
|
125
258
|
return Object.fromEntries(resolvedEntry.map((file) => {
|
|
126
259
|
const relative = path.relative(base, file);
|
|
127
|
-
return [relative.slice(0, relative.length - path.extname(relative).length), file];
|
|
260
|
+
return [slash(relative.slice(0, relative.length - path.extname(relative).length)), file];
|
|
128
261
|
}));
|
|
129
262
|
}
|
|
130
263
|
|
|
@@ -330,116 +463,6 @@ function normalizeFormat(format) {
|
|
|
330
463
|
});
|
|
331
464
|
}
|
|
332
465
|
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region src/config/config.ts
|
|
335
|
-
async function loadViteConfig(prefix, cwd) {
|
|
336
|
-
const { config, sources: [source] } = await loadConfig({
|
|
337
|
-
sources: [{
|
|
338
|
-
files: `${prefix}.config`,
|
|
339
|
-
extensions: [
|
|
340
|
-
"ts",
|
|
341
|
-
"mts",
|
|
342
|
-
"cts",
|
|
343
|
-
"js",
|
|
344
|
-
"mjs",
|
|
345
|
-
"cjs",
|
|
346
|
-
"json",
|
|
347
|
-
""
|
|
348
|
-
]
|
|
349
|
-
}],
|
|
350
|
-
cwd,
|
|
351
|
-
defaults: {}
|
|
352
|
-
});
|
|
353
|
-
if (!source) return;
|
|
354
|
-
globalLogger.info(`Using Vite config: ${underline(source)}`);
|
|
355
|
-
const resolved = await config;
|
|
356
|
-
if (typeof resolved === "function") return resolved({
|
|
357
|
-
command: "build",
|
|
358
|
-
mode: "production"
|
|
359
|
-
});
|
|
360
|
-
return resolved;
|
|
361
|
-
}
|
|
362
|
-
let loaded = false;
|
|
363
|
-
async function loadConfigFile(inlineConfig, workspace) {
|
|
364
|
-
let cwd = inlineConfig.cwd || process.cwd();
|
|
365
|
-
let overrideConfig = false;
|
|
366
|
-
let { config: filePath } = inlineConfig;
|
|
367
|
-
if (filePath === false) return { configs: [{}] };
|
|
368
|
-
if (typeof filePath === "string") {
|
|
369
|
-
const stats = await fsStat(filePath);
|
|
370
|
-
if (stats) {
|
|
371
|
-
const resolved = path.resolve(filePath);
|
|
372
|
-
if (stats.isFile()) {
|
|
373
|
-
overrideConfig = true;
|
|
374
|
-
filePath = resolved;
|
|
375
|
-
cwd = path.dirname(filePath);
|
|
376
|
-
} else if (stats.isDirectory()) cwd = resolved;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
let isNative = false;
|
|
380
|
-
if (!loaded) {
|
|
381
|
-
if (!inlineConfig.configLoader || inlineConfig.configLoader === "auto") isNative = !!(process.features.typescript || process.versions.bun || process.versions.deno);
|
|
382
|
-
else if (inlineConfig.configLoader === "native") isNative = true;
|
|
383
|
-
}
|
|
384
|
-
let { config, sources } = await loadConfig.async({
|
|
385
|
-
sources: overrideConfig ? [{
|
|
386
|
-
files: filePath,
|
|
387
|
-
extensions: []
|
|
388
|
-
}] : [{
|
|
389
|
-
files: "tsdown.config",
|
|
390
|
-
extensions: [
|
|
391
|
-
"ts",
|
|
392
|
-
"mts",
|
|
393
|
-
"cts",
|
|
394
|
-
"js",
|
|
395
|
-
"mjs",
|
|
396
|
-
"cjs",
|
|
397
|
-
"json",
|
|
398
|
-
""
|
|
399
|
-
],
|
|
400
|
-
parser: inlineConfig.configLoader === "unrun" ? unrunImport : isNative ? nativeImport : "auto"
|
|
401
|
-
}, {
|
|
402
|
-
files: "package.json",
|
|
403
|
-
extensions: [],
|
|
404
|
-
rewrite: (config$1) => config$1?.tsdown
|
|
405
|
-
}],
|
|
406
|
-
cwd,
|
|
407
|
-
stopAt: workspace && path.dirname(workspace),
|
|
408
|
-
defaults: {}
|
|
409
|
-
}).finally(() => loaded = true);
|
|
410
|
-
config = await config;
|
|
411
|
-
if (typeof config === "function") config = await config(inlineConfig);
|
|
412
|
-
config = toArray(config);
|
|
413
|
-
if (config.length === 0) config.push({});
|
|
414
|
-
const file = sources[0];
|
|
415
|
-
if (file) globalLogger.info(`Using tsdown config: ${underline(file)}`);
|
|
416
|
-
return {
|
|
417
|
-
configs: config,
|
|
418
|
-
file
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
async function nativeImport(id) {
|
|
422
|
-
const mod = await import(pathToFileURL(id).href).catch((error) => {
|
|
423
|
-
if (error?.message?.includes?.("Cannot find module")) {
|
|
424
|
-
const configError = /* @__PURE__ */ new Error(`Failed to load the config file. Try setting the --config-loader CLI flag to \`unconfig\`.\n\n${error.message}`);
|
|
425
|
-
configError.cause = error;
|
|
426
|
-
throw configError;
|
|
427
|
-
} else throw error;
|
|
428
|
-
});
|
|
429
|
-
return mod.default || mod;
|
|
430
|
-
}
|
|
431
|
-
async function unrunImport(id) {
|
|
432
|
-
const { unrun } = await importWithError("unrun");
|
|
433
|
-
const { module: module$1 } = await unrun({ path: pathToFileURL(id).href }).catch((error) => {
|
|
434
|
-
if (error?.message?.includes?.("Cannot find module")) {
|
|
435
|
-
const configError = /* @__PURE__ */ new Error(`Failed to load the config file. \`unrun\` is experimental; try setting the --config-loader CLI flag to \`unconfig\` instead.\n\n${error.message}`);
|
|
436
|
-
configError.cause = error;
|
|
437
|
-
throw configError;
|
|
438
|
-
} else throw error;
|
|
439
|
-
});
|
|
440
|
-
return module$1;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
466
|
//#endregion
|
|
444
467
|
//#region src/config/index.ts
|
|
445
468
|
const debug$5 = Debug("tsdown:options");
|
|
@@ -461,7 +484,7 @@ async function resolveConfig(inlineConfig) {
|
|
|
461
484
|
const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
|
|
462
485
|
const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, inlineConfig);
|
|
463
486
|
if (workspaceFiles) files.push(...workspaceFiles);
|
|
464
|
-
return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveUserConfig(config)));
|
|
487
|
+
return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveUserConfig(config, inlineConfig)));
|
|
465
488
|
}))).flat();
|
|
466
489
|
debug$5("resolved configs %O", configs);
|
|
467
490
|
return {
|
|
@@ -525,8 +548,8 @@ async function resolveWorkspace(config, inlineConfig) {
|
|
|
525
548
|
files
|
|
526
549
|
};
|
|
527
550
|
}
|
|
528
|
-
async function resolveUserConfig(userConfig) {
|
|
529
|
-
let { entry, format = ["es"], plugins = [], clean = true, silent = false, logLevel = silent ? "silent" : "info", failOnWarn = false, customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, attw: attw$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, inlineOnly, fixedExtension = platform === "node", debug: debug$
|
|
551
|
+
async function resolveUserConfig(userConfig, inlineConfig) {
|
|
552
|
+
let { entry, format = ["es"], plugins = [], clean = true, silent = false, logLevel = silent ? "silent" : "info", failOnWarn = false, customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, attw: attw$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, inlineOnly, fixedExtension = platform === "node", debug: debug$9 = false } = userConfig;
|
|
530
553
|
const logger = createLogger(logLevel, {
|
|
531
554
|
customLogger,
|
|
532
555
|
failOnWarn
|
|
@@ -550,7 +573,7 @@ async function resolveUserConfig(userConfig) {
|
|
|
550
573
|
if (publicDir) if (copy$1) throw new TypeError("`publicDir` is deprecated. Cannot be used with `copy`");
|
|
551
574
|
else logger.warn(`${blue`publicDir`} is deprecated. Use ${blue`copy`} instead.`);
|
|
552
575
|
if (fromVite) {
|
|
553
|
-
const viteUserConfig = await loadViteConfig(fromVite === true ? "vite" : fromVite, cwd);
|
|
576
|
+
const viteUserConfig = await loadViteConfig(fromVite === true ? "vite" : fromVite, cwd, inlineConfig.configLoader);
|
|
554
577
|
if (viteUserConfig) {
|
|
555
578
|
const viteAlias = viteUserConfig.resolve?.alias;
|
|
556
579
|
if (Array.isArray(viteAlias)) throw new TypeError("Unsupported resolve.alias in Vite config. Use object instead of array");
|
|
@@ -571,9 +594,9 @@ async function resolveUserConfig(userConfig) {
|
|
|
571
594
|
noExternal = (id) => matchPattern(id, noExternalPatterns);
|
|
572
595
|
}
|
|
573
596
|
if (inlineOnly != null) inlineOnly = toArray(inlineOnly);
|
|
574
|
-
if (debug$
|
|
575
|
-
if (debug$
|
|
576
|
-
debug$
|
|
597
|
+
if (debug$9) {
|
|
598
|
+
if (debug$9 === true) debug$9 = {};
|
|
599
|
+
debug$9.devtools ??= !!pkgExists("@vitejs/devtools/cli");
|
|
577
600
|
}
|
|
578
601
|
return {
|
|
579
602
|
...userConfig,
|
|
@@ -613,7 +636,7 @@ async function resolveUserConfig(userConfig) {
|
|
|
613
636
|
globImport,
|
|
614
637
|
inlineOnly,
|
|
615
638
|
fixedExtension,
|
|
616
|
-
debug: debug$
|
|
639
|
+
debug: debug$9
|
|
617
640
|
};
|
|
618
641
|
}
|
|
619
642
|
async function mergeUserOptions(defaults, user, args) {
|
|
@@ -627,7 +650,6 @@ async function mergeUserOptions(defaults, user, args) {
|
|
|
627
650
|
//#endregion
|
|
628
651
|
//#region src/features/attw.ts
|
|
629
652
|
const debug$4 = Debug("tsdown:attw");
|
|
630
|
-
const exec$1 = promisify(child_process.exec);
|
|
631
653
|
/**
|
|
632
654
|
* ATTW profiles.
|
|
633
655
|
* Defines the resolution modes to ignore for each profile.
|
|
@@ -674,18 +696,14 @@ async function attw(options) {
|
|
|
674
696
|
const t = performance.now();
|
|
675
697
|
debug$4("Running attw check");
|
|
676
698
|
const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-attw-"));
|
|
677
|
-
|
|
678
|
-
try {
|
|
679
|
-
attwCore = await importWithError("@arethetypeswrong/core");
|
|
680
|
-
} catch {
|
|
681
|
-
options.logger.error(`ATTW check requires ${blue`@arethetypeswrong/core`} to be installed.`);
|
|
682
|
-
return;
|
|
683
|
-
}
|
|
699
|
+
const attwCore = await importWithError("@arethetypeswrong/core");
|
|
684
700
|
try {
|
|
685
|
-
const { stdout: tarballInfo } = await exec
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
701
|
+
const { stdout: tarballInfo } = await exec("npm", [
|
|
702
|
+
"pack",
|
|
703
|
+
"--json",
|
|
704
|
+
"--pack-destination",
|
|
705
|
+
tempDir
|
|
706
|
+
], { nodeOptions: { cwd: options.cwd } });
|
|
689
707
|
const parsed = JSON.parse(tarballInfo);
|
|
690
708
|
if (!Array.isArray(parsed) || !parsed[0]?.filename) throw new Error("Invalid npm pack output format");
|
|
691
709
|
const tarball = await readFile(path.join(tempDir, parsed[0].filename));
|
|
@@ -699,9 +717,9 @@ async function attw(options) {
|
|
|
699
717
|
if (problems.length) {
|
|
700
718
|
const problemMessage = `Are the types wrong problems found:\n${problems.map(formatProblem).join("\n")}`;
|
|
701
719
|
if (level === "error") throw new Error(problemMessage);
|
|
702
|
-
options.logger.warn(problemMessage);
|
|
720
|
+
options.logger.warn(prettyName(options.name), problemMessage);
|
|
703
721
|
}
|
|
704
|
-
} else options.logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
722
|
+
} else options.logger.success(prettyName(options.name), `No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
705
723
|
} catch (error) {
|
|
706
724
|
options.logger.error("ATTW check failed:", error);
|
|
707
725
|
debug$4("Found errors, setting exit code to 1");
|
|
@@ -774,7 +792,10 @@ async function publint(options) {
|
|
|
774
792
|
pkgDir: path.dirname(options.pkg.packageJsonPath)
|
|
775
793
|
});
|
|
776
794
|
debug$3("Found %d issues", messages.length);
|
|
777
|
-
if (!messages.length)
|
|
795
|
+
if (!messages.length) {
|
|
796
|
+
options.logger.success(prettyName(options.name), `No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
778
799
|
let hasError = false;
|
|
779
800
|
for (const message of messages) {
|
|
780
801
|
hasError ||= message.type === "error";
|
|
@@ -1112,7 +1133,7 @@ async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
|
|
|
1112
1133
|
return rolldownConfig;
|
|
1113
1134
|
}
|
|
1114
1135
|
async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
|
|
1115
|
-
const { entry, external, plugins: userPlugins, platform, alias, treeshake, dts, unused, target, shims, tsconfig, cwd, report, env, nodeProtocol, loader, name, logger, cjsDefault, banner, footer, globImport, debug: debug$
|
|
1136
|
+
const { entry, external, plugins: userPlugins, platform, alias, treeshake, dts, unused, target, shims, tsconfig, cwd, report, env, nodeProtocol, loader, name, logger, cjsDefault, banner, footer, globImport, debug: debug$9 } = config;
|
|
1116
1137
|
const plugins = [];
|
|
1117
1138
|
if (nodeProtocol) plugins.push(NodeProtocolPlugin(nodeProtocol));
|
|
1118
1139
|
if (config.pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config));
|
|
@@ -1134,7 +1155,10 @@ async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
|
|
|
1134
1155
|
if (!cjsDts) {
|
|
1135
1156
|
if (unused) {
|
|
1136
1157
|
const { Unused } = await importWithError("unplugin-unused");
|
|
1137
|
-
plugins.push(Unused.rolldown(
|
|
1158
|
+
plugins.push(Unused.rolldown({
|
|
1159
|
+
root: cwd,
|
|
1160
|
+
...unused === true ? {} : unused
|
|
1161
|
+
}));
|
|
1138
1162
|
}
|
|
1139
1163
|
if (target) plugins.push(await LightningCSSPlugin({ target }));
|
|
1140
1164
|
plugins.push(ShebangPlugin(logger, cwd, name, isMultiFormat));
|
|
@@ -1172,7 +1196,7 @@ async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
|
|
|
1172
1196
|
if (log.code === "MIXED_EXPORT") return;
|
|
1173
1197
|
defaultHandler(level, log);
|
|
1174
1198
|
} : void 0,
|
|
1175
|
-
debug: debug$
|
|
1199
|
+
debug: debug$9 || void 0
|
|
1176
1200
|
}, config.inputOptions, [format, { cjsDts }]);
|
|
1177
1201
|
}
|
|
1178
1202
|
async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
|
|
@@ -1340,6 +1364,7 @@ async function build$1(userOptions = {}) {
|
|
|
1340
1364
|
for (const [i, config] of configs.entries()) {
|
|
1341
1365
|
const rebuild = rebuilds[i];
|
|
1342
1366
|
if (!rebuild) continue;
|
|
1367
|
+
setWatch();
|
|
1343
1368
|
const watcher = await watchBuild(config, configFiles, rebuild, restart);
|
|
1344
1369
|
disposeCbs.push(() => watcher.close());
|
|
1345
1370
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,12 +46,11 @@
|
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@arethetypeswrong/core": "^0.18.1",
|
|
49
|
-
"@vitejs/devtools": "^0.0.0-alpha.
|
|
49
|
+
"@vitejs/devtools": "^0.0.0-alpha.17",
|
|
50
50
|
"publint": "^0.3.0",
|
|
51
51
|
"typescript": "^5.0.0",
|
|
52
52
|
"unplugin-lightningcss": "^0.4.0",
|
|
53
|
-
"unplugin-unused": "^0.5.0"
|
|
54
|
-
"unrun": "^0.2.1"
|
|
53
|
+
"unplugin-unused": "^0.5.0"
|
|
55
54
|
},
|
|
56
55
|
"peerDependenciesMeta": {
|
|
57
56
|
"@arethetypeswrong/core": {
|
|
@@ -71,9 +70,6 @@
|
|
|
71
70
|
},
|
|
72
71
|
"unplugin-unused": {
|
|
73
72
|
"optional": true
|
|
74
|
-
},
|
|
75
|
-
"unrun": {
|
|
76
|
-
"optional": true
|
|
77
73
|
}
|
|
78
74
|
},
|
|
79
75
|
"dependencies": {
|
|
@@ -84,24 +80,25 @@
|
|
|
84
80
|
"diff": "^8.0.2",
|
|
85
81
|
"empathic": "^2.0.0",
|
|
86
82
|
"hookable": "^5.5.3",
|
|
87
|
-
"rolldown": "1.0.0-beta.
|
|
88
|
-
"rolldown-plugin-dts": "^0.17.
|
|
83
|
+
"rolldown": "1.0.0-beta.49",
|
|
84
|
+
"rolldown-plugin-dts": "^0.17.5",
|
|
89
85
|
"semver": "^7.7.3",
|
|
90
|
-
"tinyexec": "^1.0.
|
|
86
|
+
"tinyexec": "^1.0.2",
|
|
91
87
|
"tinyglobby": "^0.2.15",
|
|
92
88
|
"tree-kill": "^1.2.2",
|
|
93
|
-
"unconfig": "^7.
|
|
89
|
+
"unconfig-core": "^7.4.1",
|
|
90
|
+
"unrun": "^0.2.7"
|
|
94
91
|
},
|
|
95
92
|
"devDependencies": {
|
|
96
93
|
"@arethetypeswrong/core": "^0.18.2",
|
|
97
|
-
"@sxzz/eslint-config": "^7.2.
|
|
94
|
+
"@sxzz/eslint-config": "^7.2.9",
|
|
98
95
|
"@sxzz/prettier-config": "^2.2.4",
|
|
99
96
|
"@sxzz/test-utils": "^0.5.12",
|
|
100
97
|
"@types/debug": "^4.1.12",
|
|
101
98
|
"@types/node": "^24.10.0",
|
|
102
99
|
"@types/semver": "^7.7.1",
|
|
103
|
-
"@unocss/eslint-plugin": "^66.5.
|
|
104
|
-
"@vitejs/devtools": "^0.0.0-alpha.
|
|
100
|
+
"@unocss/eslint-plugin": "^66.5.5",
|
|
101
|
+
"@vitejs/devtools": "^0.0.0-alpha.17",
|
|
105
102
|
"@vueuse/core": "^14.0.0",
|
|
106
103
|
"bumpp": "^10.3.1",
|
|
107
104
|
"eslint": "^9.39.1",
|
|
@@ -111,12 +108,11 @@
|
|
|
111
108
|
"publint": "^0.3.15",
|
|
112
109
|
"rolldown-plugin-require-cjs": "^0.3.1",
|
|
113
110
|
"typescript": "~5.9.3",
|
|
114
|
-
"unocss": "^66.5.
|
|
111
|
+
"unocss": "^66.5.5",
|
|
115
112
|
"unplugin-lightningcss": "^0.4.3",
|
|
116
|
-
"unplugin-unused": "^0.5.
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"vitest": "^4.0.6"
|
|
113
|
+
"unplugin-unused": "^0.5.6",
|
|
114
|
+
"vite": "npm:rolldown-vite@^7.2.3",
|
|
115
|
+
"vitest": "^4.0.8"
|
|
120
116
|
},
|
|
121
117
|
"engines": {
|
|
122
118
|
"node": ">=20.19.0"
|
|
File without changes
|
|
File without changes
|