tsdown 0.19.0-beta.4 → 0.19.0-beta.5

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.
@@ -1,21 +1,20 @@
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 matchPattern, d as promiseWithResolvers, f as resolveComma, h as toArray, l as noop, m as slash, o as prettyFormat, s as importWithError, t as LogLevels } from "./logger-C5G3WyAl.mjs";
4
- import { a as getPackageType, c as defaultCssBundleName, d as loadConfigFile, f as fsCopy, h as lowestCommonAncestor, i as resolveUserConfig, l as cleanChunks, m as fsRemove, o as writeExports, p as fsExists, r as mergeUserOptions, s as formatBytes, u as cleanOutDir } from "./config-DCPo70ac.mjs";
5
- import { n as version } from "./debug-C60bWO35.mjs";
3
+ import { a as globalLogger, c as matchPattern, d as promiseWithResolvers, f as resolveComma, h as toArray, l as noop, m as slash, o as prettyFormat, s as importWithError, t as LogLevels } from "./logger-D_2uXZBG.mjs";
4
+ import { a as getPackageType, c as defaultCssBundleName, d as fsCopy, f as fsExists, i as loadConfigFile, l as cleanChunks, m as lowestCommonAncestor, n as mergeUserOptions, o as writeExports, p as fsRemove, r as resolveUserConfig, s as formatBytes, u as cleanOutDir } from "./options-D-CZFay6.mjs";
5
+ import { t as version } from "./package-C6IsJEnG.mjs";
6
6
  import { builtinModules, isBuiltin } from "node:module";
7
- import { blue, bold, dim, green, underline } from "ansis";
8
- import { clearRequireCache } from "import-without-cache";
9
- import * as Rolldown from "rolldown";
10
- import { VERSION, build, watch } from "rolldown";
11
- import path from "node:path";
12
- import { createDebug } from "obug";
13
7
  import { chmod, mkdtemp, readFile, writeFile } from "node:fs/promises";
8
+ import path from "node:path";
14
9
  import process from "node:process";
15
- import { fileURLToPath } from "node:url";
16
10
  import { formatWithOptions, inspect, promisify } from "node:util";
11
+ import { blue, bold, dim, green, underline } from "ansis";
12
+ import { createDebug } from "obug";
17
13
  import { glob, isDynamicPattern } from "tinyglobby";
14
+ import { fileURLToPath } from "node:url";
18
15
  import { RE_CSS, RE_DTS, RE_JS, RE_NODE_MODULES } from "rolldown-plugin-dts/filename";
16
+ import { clearRequireCache } from "import-without-cache";
17
+ import { VERSION, build, watch } from "rolldown";
19
18
  const coerce = __cjs_require("semver/functions/coerce.js");
20
19
  const satisfies = __cjs_require("semver/functions/satisfies.js");
21
20
  import { Hookable } from "hookable";
@@ -261,6 +260,7 @@ async function attw(options) {
261
260
  const { stdout: tarballInfo } = await exec("npm", [
262
261
  "pack",
263
262
  "--json",
263
+ "--ignore-scripts",
264
264
  "--pack-destination",
265
265
  tempDir
266
266
  ], { nodeOptions: { cwd: options.cwd } });
@@ -537,13 +537,6 @@ function normalizeChunkFileName(chunkFileName) {
537
537
  return chunkFileName.replace(RE_CHUNK_HASH, "").replace(RE_CHUNK_EXT, "");
538
538
  }
539
539
 
540
- //#endregion
541
- //#region src/index.ts
542
- const dirname = path.dirname(fileURLToPath(import.meta.url));
543
- const pkgRoot = path.resolve(dirname, "..");
544
- /** @internal */
545
- const shimFile = path.resolve(pkgRoot, "esm-shims.js");
546
-
547
540
  //#endregion
548
541
  //#region src/features/external.ts
549
542
  const debug$2 = createDebug("tsdown:external");
@@ -898,7 +891,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
898
891
  defaultHandler(level, log);
899
892
  } : void 0,
900
893
  devtools: devtools || void 0,
901
- checks: { pluginTimings: false }
894
+ checks: { pluginTimings: debug.enabled }
902
895
  }, config.inputOptions, [format, { cjsDts }]);
903
896
  }
904
897
  async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
@@ -1007,6 +1000,9 @@ function shortcuts(restart) {
1007
1000
  //#endregion
1008
1001
  //#region src/build.ts
1009
1002
  const asyncDispose = Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose");
1003
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
1004
+ const pkgRoot = path.resolve(dirname, "..");
1005
+ const shimFile = path.resolve(pkgRoot, "esm-shims.js");
1010
1006
  /**
1011
1007
  * Build with tsdown.
1012
1008
  */
@@ -1018,8 +1014,7 @@ async function build$1(userOptions = {}) {
1018
1014
  /**
1019
1015
  * Build with `ResolvedConfigs`.
1020
1016
  *
1021
- * Internal API, not for public use
1022
- *
1017
+ * **Internal API, not for public use**
1023
1018
  * @private
1024
1019
  */
1025
1020
  async function buildWithConfigs(configs, configFiles) {
@@ -1153,4 +1148,4 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
1153
1148
  }
1154
1149
 
1155
1150
  //#endregion
1156
- export { ReportPlugin as a, Rolldown as c, ShebangPlugin as i, shimFile as l, buildWithConfigs as n, NodeProtocolPlugin as o, WatchPlugin as r, ExternalPlugin as s, build$1 as t };
1151
+ export { ShebangPlugin as a, ExternalPlugin as c, WatchPlugin as i, buildWithConfigs as n, ReportPlugin as o, shimFile as r, NodeProtocolPlugin as s, build$1 as t };
@@ -0,0 +1,3 @@
1
+ import { n as buildWithConfigs, r as shimFile, t as build } from "./build-BZayr9FB.mjs";
2
+
3
+ export { build };
@@ -1,6 +1,14 @@
1
- import { f as UserConfig, i as InlineConfig, m as UserConfigFn, p as UserConfigExport } from "./types-Dxm9xngg.mjs";
1
+ import { f as UserConfig, i as InlineConfig, m as UserConfigFn, p as UserConfigExport, s as ResolvedConfig } from "./types-_V4oT7uO.mjs";
2
2
 
3
3
  //#region src/config/options.d.ts
4
+
5
+ /**
6
+ * Resolve user config into resolved configs
7
+ *
8
+ * **Internal API, not for public use**
9
+ * @private
10
+ */
11
+ declare function resolveUserConfig(userConfig: UserConfig, inlineConfig: InlineConfig): Promise<ResolvedConfig[]>;
4
12
  declare function mergeConfig(defaults: UserConfig, overrides: UserConfig): UserConfig;
5
13
  declare function mergeConfig(defaults: InlineConfig, overrides: InlineConfig): InlineConfig;
6
14
  //#endregion
@@ -13,4 +21,4 @@ declare function defineConfig(options: UserConfig[]): UserConfig[];
13
21
  declare function defineConfig(options: UserConfigFn): UserConfigFn;
14
22
  declare function defineConfig(options: UserConfigExport): UserConfigExport;
15
23
  //#endregion
16
- export { mergeConfig as n, defineConfig as t };
24
+ export { mergeConfig as n, resolveUserConfig as r, defineConfig as t };
package/dist/config.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./types-Dxm9xngg.mjs";
2
- import { n as mergeConfig, t as defineConfig } from "./config-Cj-nN1Zu.mjs";
1
+ import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./types-_V4oT7uO.mjs";
2
+ import { n as mergeConfig, t as defineConfig } from "./config-B_X6YTxy.mjs";
3
3
  export { UserConfig, UserConfigExport, UserConfigFn, defineConfig, mergeConfig };
package/dist/config.mjs CHANGED
@@ -1,3 +1,9 @@
1
- import { n as mergeConfig, t as defineConfig } from "./config-DCPo70ac.mjs";
1
+ import { t as mergeConfig } from "./options-D-CZFay6.mjs";
2
2
 
3
+ //#region src/config.ts
4
+ function defineConfig(options) {
5
+ return options;
6
+ }
7
+
8
+ //#endregion
3
9
  export { defineConfig, mergeConfig };
@@ -1,10 +1,6 @@
1
- import { f as resolveComma, h as toArray } from "./logger-C5G3WyAl.mjs";
1
+ import { f as resolveComma, h as toArray } from "./logger-D_2uXZBG.mjs";
2
2
  import { createDebug, enable, namespaces } from "obug";
3
3
 
4
- //#region package.json
5
- var version = "0.19.0-beta.4";
6
-
7
- //#endregion
8
4
  //#region src/features/debug.ts
9
5
  const debugLog = createDebug("tsdown:debug");
10
6
  function enableDebug(debug) {
@@ -19,4 +15,4 @@ function enableDebug(debug) {
19
15
  }
20
16
 
21
17
  //#endregion
22
- export { version as n, enableDebug as t };
18
+ export { enableDebug as t };
package/dist/index.d.mts CHANGED
@@ -1,9 +1,22 @@
1
- import { A as OutExtensionFactory, B as CopyOptions, C as RolldownChunk, D as ChunkAddonFunction, E as ChunkAddon, F as RolldownContext, H as Arrayable, I as TsdownHooks, L as DevtoolsOptions, M as PackageJsonWithPath, N as PackageType, O as ChunkAddonObject, P as BuildContext, R as CssOptions, S as ExportsOptions, T as AttwOptions, V as CopyOptionsFn, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as Sourcemap, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as OutExtensionObject, k as OutExtensionContext, l as TreeshakingOptions, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as ResolvedConfig, t as CIOption, u as TsdownInputOption, w as TsdownBundle, x as PublintOptions, y as Logger, z as CopyEntry } from "./types-Dxm9xngg.mjs";
2
- import { build, buildWithConfigs } from "./build.mjs";
3
- import { n as mergeConfig, t as defineConfig } from "./config-Cj-nN1Zu.mjs";
1
+ import { A as OutExtensionFactory, B as CopyOptions, C as RolldownChunk, D as ChunkAddonFunction, E as ChunkAddon, F as RolldownContext, H as Arrayable, I as TsdownHooks, L as DevtoolsOptions, M as PackageJsonWithPath, N as PackageType, O as ChunkAddonObject, P as BuildContext, R as CssOptions, S as ExportsOptions, T as AttwOptions, V as CopyOptionsFn, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as Sourcemap, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as OutExtensionObject, k as OutExtensionContext, l as TreeshakingOptions, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as ResolvedConfig, t as CIOption, u as TsdownInputOption, w as TsdownBundle, x as PublintOptions, y as Logger, z as CopyEntry } from "./types-_V4oT7uO.mjs";
2
+ import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-B_X6YTxy.mjs";
4
3
  import * as Rolldown from "rolldown";
5
4
 
5
+ //#region src/build.d.ts
6
+
7
+ /**
8
+ * Build with tsdown.
9
+ */
10
+ declare function build(userOptions?: InlineConfig): Promise<TsdownBundle[]>;
11
+ /**
12
+ * Build with `ResolvedConfigs`.
13
+ *
14
+ * **Internal API, not for public use**
15
+ * @private
16
+ */
17
+ declare function buildWithConfigs(configs: ResolvedConfig[], configFiles: string[]): Promise<TsdownBundle[]>;
18
+ //#endregion
6
19
  //#region src/features/debug.d.ts
7
20
  declare function enableDebug(debug?: boolean | Arrayable<string>): void;
8
21
  //#endregion
9
- export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, CssOptions, DevtoolsOptions, DtsOptions, ExportsOptions, Format, InlineConfig, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PublintOptions, ReportOptions, ResolvedConfig, Rolldown, RolldownChunk, RolldownContext, Sourcemap, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig };
22
+ export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, CssOptions, DevtoolsOptions, DtsOptions, ExportsOptions, Format, InlineConfig, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PublintOptions, ReportOptions, ResolvedConfig, Rolldown, RolldownChunk, RolldownContext, Sourcemap, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
package/dist/index.mjs CHANGED
@@ -1,6 +1,8 @@
1
- import { a as globalLogger } from "./logger-C5G3WyAl.mjs";
2
- import { n as mergeConfig, t as defineConfig } from "./config-DCPo70ac.mjs";
3
- import { c as Rolldown, l as shimFile, n as buildWithConfigs, t as build } from "./build-CczdykTO.mjs";
4
- import { t as enableDebug } from "./debug-C60bWO35.mjs";
1
+ import { a as globalLogger } from "./logger-D_2uXZBG.mjs";
2
+ import { r as resolveUserConfig, t as mergeConfig } from "./options-D-CZFay6.mjs";
3
+ import { defineConfig } from "./config.mjs";
4
+ import { n as buildWithConfigs, t as build } from "./build-BZayr9FB.mjs";
5
+ import { t as enableDebug } from "./debug-Baqdx6K3.mjs";
6
+ import * as Rolldown from "rolldown";
5
7
 
6
- export { Rolldown, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, shimFile };
8
+ export { Rolldown, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
@@ -1,8 +1,8 @@
1
1
  import { createRequire as __cjs_createRequire } from "node:module";
2
2
  const __cjs_require = __cjs_createRequire(import.meta.url);
3
3
  import { createRequire } from "node:module";
4
- import { bgRed, bgYellow, blue, green, rgb, yellow } from "ansis";
5
4
  import process from "node:process";
5
+ import { bgRed, bgYellow, blue, green, rgb, yellow } from "ansis";
6
6
  import { pathToFileURL } from "node:url";
7
7
  const picomatch = __cjs_require("picomatch");
8
8
 
@@ -1,23 +1,23 @@
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 matchPattern, f as resolveComma, h as toArray, i as getNameLabel, m as slash, n as createLogger, p as resolveRegex, r as generateColor, u as pkgExists } from "./logger-C5G3WyAl.mjs";
4
- import { blue, underline } from "ansis";
5
- import { init, isSupported } from "import-without-cache";
6
- import path from "node:path";
7
- import { createDebug } from "obug";
3
+ import { a as globalLogger, c as matchPattern, f as resolveComma, h as toArray, i as getNameLabel, m as slash, n as createLogger, p as resolveRegex, r as generateColor, u as pkgExists } from "./logger-D_2uXZBG.mjs";
8
4
  import { access, cp, readFile, rm, stat } from "node:fs/promises";
5
+ import path from "node:path";
9
6
  import process, { env } from "node:process";
10
- import { pathToFileURL } from "node:url";
11
- import { createConfigCoreLoader } from "unconfig-core";
12
- const picomatch = __cjs_require("picomatch");
13
7
  import { parseEnv } from "node:util";
8
+ import { blue, underline } from "ansis";
14
9
  import { createDefu } from "defu";
10
+ import { createDebug } from "obug";
15
11
  import { glob, isDynamicPattern } from "tinyglobby";
12
+ import { pathToFileURL } from "node:url";
13
+ const picomatch = __cjs_require("picomatch");
16
14
  import { readFileSync, writeFileSync } from "node:fs";
17
15
  import { RE_CSS, RE_DTS } from "rolldown-plugin-dts/filename";
18
16
  const minVersion = __cjs_require("semver/ranges/min-version.js");
19
17
  import { up } from "empathic/find";
20
18
  import { up as up$1 } from "empathic/package";
19
+ import { init, isSupported } from "import-without-cache";
20
+ import { createConfigCoreLoader } from "unconfig-core";
21
21
 
22
22
  //#region node_modules/.pnpm/is-in-ci@2.0.0/node_modules/is-in-ci/index.js
23
23
  const check = (key) => key in env && env[key] !== "0" && env[key] !== "false";
@@ -68,144 +68,9 @@ function stripExtname(filePath) {
68
68
  return filePath.slice(0, -ext.length);
69
69
  }
70
70
 
71
- //#endregion
72
- //#region src/config/file.ts
73
- const debug$3 = createDebug("tsdown:config:file");
74
- async function loadViteConfig(prefix, cwd, configLoader) {
75
- const loader = resolveConfigLoader(configLoader);
76
- debug$3("Loading Vite config via loader: ", loader);
77
- const parser = createParser(loader);
78
- const [result] = await createConfigCoreLoader({
79
- sources: [{
80
- files: [`${prefix}.config`],
81
- extensions: [
82
- "js",
83
- "mjs",
84
- "ts",
85
- "cjs",
86
- "mts",
87
- "mts"
88
- ],
89
- parser
90
- }],
91
- cwd
92
- }).load(true);
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
- async function loadConfigFile(inlineConfig, workspace) {
105
- let cwd = inlineConfig.cwd || process.cwd();
106
- let overrideConfig = false;
107
- let { config: filePath } = inlineConfig;
108
- if (filePath === false) return { configs: [{}] };
109
- if (typeof filePath === "string") {
110
- const stats = await fsStat(filePath);
111
- if (stats) {
112
- const resolved = path.resolve(filePath);
113
- if (stats.isFile()) {
114
- overrideConfig = true;
115
- filePath = resolved;
116
- cwd = path.dirname(filePath);
117
- } else if (stats.isDirectory()) cwd = resolved;
118
- }
119
- }
120
- const loader = resolveConfigLoader(inlineConfig.configLoader);
121
- debug$3("Using config loader:", loader);
122
- const parser = createParser(loader);
123
- const [result] = await createConfigCoreLoader({
124
- sources: overrideConfig ? [{
125
- files: [filePath],
126
- extensions: [],
127
- parser
128
- }] : [{
129
- files: [configPrefix],
130
- extensions: [
131
- "ts",
132
- "mts",
133
- "cts",
134
- "js",
135
- "mjs",
136
- "cjs",
137
- "json"
138
- ],
139
- parser
140
- }, {
141
- files: ["package.json"],
142
- parser
143
- }],
144
- cwd,
145
- stopAt: workspace && path.dirname(workspace)
146
- }).load(true);
147
- let exported = [];
148
- let file;
149
- if (result) {
150
- ({config: exported, source: file} = result);
151
- globalLogger.info(`config file: ${underline(file)}`, loader === "native" ? "" : `(${loader})`);
152
- exported = await exported;
153
- if (typeof exported === "function") exported = await exported(inlineConfig, { ci: is_in_ci_default });
154
- }
155
- exported = toArray(exported);
156
- if (exported.length === 0) exported.push({});
157
- if (exported.some((config) => typeof config === "function")) throw new Error("Function should not be nested within multiple tsdown configurations. It must be at the top level.\nExample: export default defineConfig(() => [...])");
158
- return {
159
- configs: exported.map((config) => ({
160
- ...config,
161
- cwd: config.cwd ? path.resolve(cwd, config.cwd) : cwd
162
- })),
163
- file
164
- };
165
- }
166
- const isBun = !!process.versions.bun;
167
- const nativeTS = process.features.typescript || process.versions.deno;
168
- const autoLoader = isBun || nativeTS && isSupported ? "native" : "unrun";
169
- function resolveConfigLoader(configLoader = "auto") {
170
- if (configLoader === "auto") return autoLoader;
171
- else return configLoader === "native" ? "native" : "unrun";
172
- }
173
- function createParser(loader) {
174
- return async (filepath) => {
175
- const basename = path.basename(filepath);
176
- const isPkgJson = basename === "package.json";
177
- if (basename === configPrefix || isPkgJson || basename.endsWith(".json")) {
178
- const contents = await readFile(filepath, "utf8");
179
- const parsed = JSON.parse(contents);
180
- if (isPkgJson) return parsed?.tsdown;
181
- return parsed;
182
- }
183
- if (loader === "native") return nativeImport(filepath);
184
- return unrunImport(filepath);
185
- };
186
- }
187
- async function nativeImport(id) {
188
- const url = pathToFileURL(id);
189
- const importAttributes = Object.create(null);
190
- if (isSupported) {
191
- importAttributes.cache = "no";
192
- init({ skipNodeModules: true });
193
- } else if (!isBun) url.searchParams.set("no-cache", crypto.randomUUID());
194
- const mod = await import(url.href, { with: importAttributes }).catch((error) => {
195
- 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 });
196
- else throw error;
197
- });
198
- return mod.default || mod;
199
- }
200
- async function unrunImport(id) {
201
- const { unrun } = await import("unrun");
202
- const { module } = await unrun({ path: pathToFileURL(id).href });
203
- return module;
204
- }
205
-
206
71
  //#endregion
207
72
  //#region src/features/clean.ts
208
- const debug$2 = createDebug("tsdown:clean");
73
+ const debug$3 = createDebug("tsdown:clean");
209
74
  const RE_LAST_SLASH = /[/\\]$/;
210
75
  async function cleanOutDir(configs) {
211
76
  const removes = /* @__PURE__ */ new Set();
@@ -224,10 +89,10 @@ async function cleanOutDir(configs) {
224
89
  if (!removes.size) return;
225
90
  globalLogger.info(`Cleaning ${removes.size} files`);
226
91
  await Promise.all([...removes].map(async (file) => {
227
- debug$2("Removing", file);
92
+ debug$3("Removing", file);
228
93
  await fsRemove(file);
229
94
  }));
230
- debug$2("Removed %d files", removes.size);
95
+ debug$3("Removed %d files", removes.size);
231
96
  }
232
97
  function resolveClean(clean, outDir, cwd) {
233
98
  if (clean === true) clean = [slash(outDir)];
@@ -238,7 +103,7 @@ function resolveClean(clean, outDir, cwd) {
238
103
  async function cleanChunks(outDir, chunks) {
239
104
  await Promise.all(chunks.map(async (chunk) => {
240
105
  const filePath = path.resolve(outDir, chunk.fileName);
241
- debug$2("Removing chunk file", filePath);
106
+ debug$3("Removing chunk file", filePath);
242
107
  await fsRemove(filePath);
243
108
  }));
244
109
  }
@@ -521,11 +386,11 @@ async function resolveTsconfig(logger, tsconfig, cwd, color, nameLabel) {
521
386
 
522
387
  //#endregion
523
388
  //#region src/utils/package.ts
524
- const debug$1 = createDebug("tsdown:package");
389
+ const debug$2 = createDebug("tsdown:package");
525
390
  async function readPackageJson(dir) {
526
391
  const packageJsonPath = up$1({ cwd: dir });
527
392
  if (!packageJsonPath) return;
528
- debug$1("Reading package.json:", packageJsonPath);
393
+ debug$2("Reading package.json:", packageJsonPath);
529
394
  const contents = await readFile(packageJsonPath, "utf8");
530
395
  return {
531
396
  ...JSON.parse(contents),
@@ -549,9 +414,150 @@ function normalizeFormat(format) {
549
414
  }
550
415
  }
551
416
 
417
+ //#endregion
418
+ //#region src/config/file.ts
419
+ const debug$1 = createDebug("tsdown:config:file");
420
+ async function loadViteConfig(prefix, cwd, configLoader) {
421
+ const loader = resolveConfigLoader(configLoader);
422
+ debug$1("Loading Vite config via loader: ", loader);
423
+ const parser = createParser(loader);
424
+ const [result] = await createConfigCoreLoader({
425
+ sources: [{
426
+ files: [`${prefix}.config`],
427
+ extensions: [
428
+ "js",
429
+ "mjs",
430
+ "ts",
431
+ "cjs",
432
+ "mts",
433
+ "mts"
434
+ ],
435
+ parser
436
+ }],
437
+ cwd
438
+ }).load(true);
439
+ if (!result) return;
440
+ const { config, source } = result;
441
+ globalLogger.info(`Using Vite config: ${underline(source)}`);
442
+ const resolved = await config;
443
+ if (typeof resolved === "function") return resolved({
444
+ command: "build",
445
+ mode: "production"
446
+ });
447
+ return resolved;
448
+ }
449
+ const configPrefix = "tsdown.config";
450
+ async function loadConfigFile(inlineConfig, workspace) {
451
+ let cwd = inlineConfig.cwd || process.cwd();
452
+ let overrideConfig = false;
453
+ let { config: filePath } = inlineConfig;
454
+ if (filePath === false) return { configs: [{}] };
455
+ if (typeof filePath === "string") {
456
+ const stats = await fsStat(filePath);
457
+ if (stats) {
458
+ const resolved = path.resolve(filePath);
459
+ if (stats.isFile()) {
460
+ overrideConfig = true;
461
+ filePath = resolved;
462
+ cwd = path.dirname(filePath);
463
+ } else if (stats.isDirectory()) cwd = resolved;
464
+ }
465
+ }
466
+ const loader = resolveConfigLoader(inlineConfig.configLoader);
467
+ debug$1("Using config loader:", loader);
468
+ const parser = createParser(loader);
469
+ const [result] = await createConfigCoreLoader({
470
+ sources: overrideConfig ? [{
471
+ files: [filePath],
472
+ extensions: [],
473
+ parser
474
+ }] : [{
475
+ files: [configPrefix],
476
+ extensions: [
477
+ "ts",
478
+ "mts",
479
+ "cts",
480
+ "js",
481
+ "mjs",
482
+ "cjs",
483
+ "json"
484
+ ],
485
+ parser
486
+ }, {
487
+ files: ["package.json"],
488
+ parser
489
+ }],
490
+ cwd,
491
+ stopAt: workspace && path.dirname(workspace)
492
+ }).load(true);
493
+ let exported = [];
494
+ let file;
495
+ if (result) {
496
+ ({config: exported, source: file} = result);
497
+ globalLogger.info(`config file: ${underline(file)}`, loader === "native" ? "" : `(${loader})`);
498
+ exported = await exported;
499
+ if (typeof exported === "function") exported = await exported(inlineConfig, { ci: is_in_ci_default });
500
+ }
501
+ exported = toArray(exported);
502
+ if (exported.length === 0) exported.push({});
503
+ if (exported.some((config) => typeof config === "function")) throw new Error("Function should not be nested within multiple tsdown configurations. It must be at the top level.\nExample: export default defineConfig(() => [...])");
504
+ return {
505
+ configs: exported.map((config) => ({
506
+ ...config,
507
+ cwd: config.cwd ? path.resolve(cwd, config.cwd) : cwd
508
+ })),
509
+ file
510
+ };
511
+ }
512
+ const isBun = !!process.versions.bun;
513
+ const nativeTS = process.features.typescript || process.versions.deno;
514
+ const autoLoader = isBun || nativeTS && isSupported ? "native" : "unrun";
515
+ function resolveConfigLoader(configLoader = "auto") {
516
+ if (configLoader === "auto") return autoLoader;
517
+ else return configLoader === "native" ? "native" : "unrun";
518
+ }
519
+ function createParser(loader) {
520
+ return async (filepath) => {
521
+ const basename = path.basename(filepath);
522
+ const isPkgJson = basename === "package.json";
523
+ if (basename === configPrefix || isPkgJson || basename.endsWith(".json")) {
524
+ const contents = await readFile(filepath, "utf8");
525
+ const parsed = JSON.parse(contents);
526
+ if (isPkgJson) return parsed?.tsdown;
527
+ return parsed;
528
+ }
529
+ if (loader === "native") return nativeImport(filepath);
530
+ return unrunImport(filepath);
531
+ };
532
+ }
533
+ async function nativeImport(id) {
534
+ const url = pathToFileURL(id);
535
+ const importAttributes = Object.create(null);
536
+ if (isSupported) {
537
+ importAttributes.cache = "no";
538
+ init({ skipNodeModules: true });
539
+ } else if (!isBun) url.searchParams.set("no-cache", crypto.randomUUID());
540
+ const mod = await import(url.href, { with: importAttributes }).catch((error) => {
541
+ 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 });
542
+ else throw error;
543
+ });
544
+ return mod.default || mod;
545
+ }
546
+ async function unrunImport(id) {
547
+ const { unrun } = await import("unrun");
548
+ const { module } = await unrun({ path: pathToFileURL(id).href });
549
+ return module;
550
+ }
551
+
552
552
  //#endregion
553
553
  //#region src/config/options.ts
554
554
  const debug = createDebug("tsdown:config:options");
555
+ /**
556
+ * Resolve user config into resolved configs
557
+ *
558
+ * **Internal API, not for public use**
559
+ * @private
560
+ */
555
561
  async function resolveUserConfig(userConfig, inlineConfig) {
556
562
  let { entry, format = ["es"], plugins = [], clean = true, logLevel = "info", failOnWarn = "ci-only", customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, skipNodeModulesBundle = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env: env$1 = {}, envFile, envPrefix = "TSDOWN_", copy, publicDir, hash = true, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, inlineOnly, css, fixedExtension = platform === "node", devtools = false, write = true } = userConfig;
557
563
  const pkg = await readPackageJson(cwd);
@@ -729,10 +735,4 @@ function filterConfig(filter, configCwd, name) {
729
735
  }
730
736
 
731
737
  //#endregion
732
- //#region src/config.ts
733
- function defineConfig(options) {
734
- return options;
735
- }
736
-
737
- //#endregion
738
- export { getPackageType as a, defaultCssBundleName as c, loadConfigFile as d, fsCopy as f, lowestCommonAncestor as h, resolveUserConfig as i, cleanChunks as l, fsRemove as m, mergeConfig as n, writeExports as o, fsExists as p, mergeUserOptions as r, formatBytes as s, defineConfig as t, cleanOutDir as u };
738
+ export { getPackageType as a, defaultCssBundleName as c, fsCopy as d, fsExists as f, loadConfigFile as i, cleanChunks as l, lowestCommonAncestor as m, mergeUserOptions as n, writeExports as o, fsRemove as p, resolveUserConfig as r, formatBytes as s, mergeConfig as t, cleanOutDir as u };
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.19.0-beta.5";
3
+
4
+ //#endregion
5
+ export { version as t };
@@ -1,4 +1,4 @@
1
- import { s as ResolvedConfig, v as ReportPlugin, w as TsdownBundle, y as Logger } from "./types-Dxm9xngg.mjs";
1
+ import { s as ResolvedConfig, v as ReportPlugin, w as TsdownBundle, y as Logger } from "./types-_V4oT7uO.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
 
4
4
  //#region src/features/external.d.ts
package/dist/plugins.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, r as WatchPlugin, s as ExternalPlugin } from "./build-CczdykTO.mjs";
1
+ import { a as ShebangPlugin, c as ExternalPlugin, i as WatchPlugin, o as ReportPlugin, s as NodeProtocolPlugin } from "./build-BZayr9FB.mjs";
2
2
 
3
3
  export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
package/dist/run.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { a as globalLogger } from "./logger-C5G3WyAl.mjs";
3
- import { n as version, t as enableDebug } from "./debug-C60bWO35.mjs";
2
+ import { a as globalLogger } from "./logger-D_2uXZBG.mjs";
3
+ import { t as version } from "./package-C6IsJEnG.mjs";
4
+ import { t as enableDebug } from "./debug-Baqdx6K3.mjs";
4
5
  import module from "node:module";
6
+ import process from "node:process";
5
7
  import { dim } from "ansis";
6
8
  import { VERSION } from "rolldown";
7
- import process from "node:process";
8
9
  import { x } from "tinyexec";
9
10
  import { cac } from "cac";
10
11
 
@@ -17,7 +18,7 @@ cli.command("[...files]", "Bundle files", {
17
18
  }).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("--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("-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) => {
18
19
  globalLogger.level = flags.logLevel || "info";
19
20
  globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
20
- const { build: build$1 } = await import("./build.mjs");
21
+ const { build: build$1 } = await import("./build-DN921Mon.mjs");
21
22
  if (input.length > 0) flags.entry = input;
22
23
  await build$1(flags);
23
24
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tsdown",
3
3
  "type": "module",
4
- "version": "0.19.0-beta.4",
4
+ "version": "0.19.0-beta.5",
5
5
  "description": "The Elegant Bundler for Libraries",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -16,7 +16,6 @@
16
16
  },
17
17
  "exports": {
18
18
  ".": "./dist/index.mjs",
19
- "./build": "./dist/build.mjs",
20
19
  "./config": "./dist/config.mjs",
21
20
  "./plugins": "./dist/plugins.mjs",
22
21
  "./run": "./dist/run.mjs",
@@ -83,14 +82,14 @@
83
82
  "import-without-cache": "^0.2.5",
84
83
  "obug": "^2.1.1",
85
84
  "picomatch": "^4.0.3",
86
- "rolldown": "1.0.0-beta.58",
85
+ "rolldown": "1.0.0-beta.59",
87
86
  "rolldown-plugin-dts": "^0.20.0",
88
87
  "semver": "^7.7.3",
89
88
  "tinyexec": "^1.0.2",
90
89
  "tinyglobby": "^0.2.15",
91
90
  "tree-kill": "^1.2.2",
92
91
  "unconfig-core": "^7.4.2",
93
- "unrun": "^0.2.22"
92
+ "unrun": "^0.2.23"
94
93
  },
95
94
  "devDependencies": {
96
95
  "@arethetypeswrong/core": "^0.18.2",
@@ -102,7 +101,7 @@
102
101
  "@types/semver": "^7.7.1",
103
102
  "@typescript/native-preview": "7.0.0-dev.20260107.1",
104
103
  "@unocss/eslint-plugin": "^66.5.12",
105
- "@vitejs/devtools": "^0.0.0-alpha.22",
104
+ "@vitejs/devtools": "^0.0.0-alpha.24",
106
105
  "@vitest/coverage-v8": "4.0.16",
107
106
  "@vitest/ui": "^4.0.16",
108
107
  "@vueuse/core": "^14.1.0",
package/dist/build.d.mts DELETED
@@ -1,18 +0,0 @@
1
- import { i as InlineConfig, s as ResolvedConfig, w as TsdownBundle } from "./types-Dxm9xngg.mjs";
2
-
3
- //#region src/build.d.ts
4
-
5
- /**
6
- * Build with tsdown.
7
- */
8
- declare function build(userOptions?: InlineConfig): Promise<TsdownBundle[]>;
9
- /**
10
- * Build with `ResolvedConfigs`.
11
- *
12
- * Internal API, not for public use
13
- *
14
- * @private
15
- */
16
- declare function buildWithConfigs(configs: ResolvedConfig[], configFiles: string[]): Promise<TsdownBundle[]>;
17
- //#endregion
18
- export { build, buildWithConfigs };
package/dist/build.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { n as buildWithConfigs, t as build } from "./build-CczdykTO.mjs";
2
-
3
- export { build, buildWithConfigs };