tsdown 0.9.2 → 0.9.3

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,12 +1,9 @@
1
- import { UserConfig } from "./options.d-DxODs1UG.js";
1
+ import { UserConfig } from "./options.d-CRAKIn7H.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  /**
5
5
  * Defines the configuration for tsdown.
6
6
  */
7
- /**
8
- * Defines the configuration for tsdown.
9
- */
10
7
  declare function defineConfig(options: UserConfig): UserConfig;
11
8
 
12
9
  //#endregion
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "./options.d-DxODs1UG.js";
2
- import { defineConfig$1 as defineConfig } from "./config.d-BrQCtlF9.js";
1
+ import "./options.d-CRAKIn7H.js";
2
+ import { defineConfig$1 as defineConfig } from "./config.d-DHsClbv0.js";
3
3
 
4
4
  export { defineConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Options, ResolvedOptions, UserConfig } from "./options.d-DxODs1UG.js";
2
- import { defineConfig$1 as defineConfig } from "./config.d-BrQCtlF9.js";
1
+ import { Options, ResolvedOptions, UserConfig } from "./options.d-CRAKIn7H.js";
2
+ import { defineConfig$1 as defineConfig } from "./config.d-DHsClbv0.js";
3
3
  import Debug from "debug";
4
4
  import { ConsolaInstance } from "consola";
5
5
 
@@ -7,9 +7,6 @@ import { ConsolaInstance } from "consola";
7
7
  /**
8
8
  * Logger instance
9
9
  */
10
- /**
11
- * Logger instance
12
- */
13
10
  declare const logger: ConsolaInstance;
14
11
 
15
12
  //#endregion
@@ -17,9 +14,6 @@ declare const logger: ConsolaInstance;
17
14
  /**
18
15
  * Build with tsdown.
19
16
  */
20
- /**
21
- * Build with tsdown.
22
- */
23
17
  declare function build(userOptions?: Options): Promise<void>;
24
18
  declare const pkgRoot: string;
25
19
  /**
@@ -27,11 +21,6 @@ declare const pkgRoot: string;
27
21
  *
28
22
  * @param config Resolved options
29
23
  */
30
- /**
31
- * Build a single configuration, without watch and shortcuts features.
32
- *
33
- * @param config Resolved options
34
- */
35
24
  declare function buildSingle(config: ResolvedOptions): Promise<(() => Promise<void>) | undefined>;
36
25
 
37
26
  //#endregion
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineConfig } from "./config-yiJy1jd0.js";
2
- import { ExternalPlugin, ShebangPlugin, debounce, fsExists, fsRemove, lowestCommonAncestor, toArray } from "./plugins-CATHxFm7.js";
2
+ import { ExternalPlugin, ReportPlugin, ShebangPlugin, debounce, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, readPackageJson, toArray } from "./plugins-BvgcOKes.js";
3
3
  import { debug, logger, setSilent } from "./logger-Dt3D6T-U.js";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
@@ -7,12 +7,12 @@ import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import { build as build$1 } from "rolldown";
8
8
  import { transformPlugin } from "rolldown/experimental";
9
9
  import { exec } from "tinyexec";
10
- import { readFile, readdir, stat } from "node:fs/promises";
10
+ import { readdir, stat } from "node:fs/promises";
11
11
  import Debug from "debug";
12
12
  import { glob } from "tinyglobby";
13
13
  import { findUp } from "find-up-simple";
14
- import readline from "node:readline";
15
14
  import { blue, bold, dim, underline } from "ansis";
15
+ import readline from "node:readline";
16
16
  import { loadConfig } from "unconfig";
17
17
 
18
18
  //#region src/features/clean.ts
@@ -31,34 +31,6 @@ async function cleanOutDir(cwd, patterns) {
31
31
  }
32
32
  }
33
33
 
34
- //#endregion
35
- //#region src/utils/package.ts
36
- async function readPackageJson(dir) {
37
- const packageJsonPath = await findUp("package.json", { cwd: dir });
38
- if (!packageJsonPath) return;
39
- debug("Reading package.json:", packageJsonPath);
40
- const contents = await readFile(packageJsonPath, "utf8");
41
- return JSON.parse(contents);
42
- }
43
- function getPackageType(pkg) {
44
- if (pkg?.type) {
45
- if (!["module", "commonjs"].includes(pkg.type)) throw new Error(`Invalid package.json type: ${pkg.type}`);
46
- return pkg.type;
47
- }
48
- }
49
- function normalizeFormat(format) {
50
- return toArray(format, "es").map((format$1) => {
51
- switch (format$1) {
52
- case "es":
53
- case "esm":
54
- case "module": return "es";
55
- case "cjs":
56
- case "commonjs": return "cjs";
57
- default: return format$1;
58
- }
59
- });
60
- }
61
-
62
34
  //#endregion
63
35
  //#region src/features/output.ts
64
36
  function resolveJsOutputExtension(packageType, format, fixedExtension) {
@@ -248,7 +220,7 @@ async function resolveOptions(options) {
248
220
  ...subConfig,
249
221
  ...options
250
222
  };
251
- let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias, tsconfig } = subOptions;
223
+ let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias, tsconfig, report = true } = subOptions;
252
224
  entry = await resolveEntry(entry, cwd);
253
225
  if (clean === true) clean = [];
254
226
  if (publint$1 === true) publint$1 = {};
@@ -298,7 +270,8 @@ async function resolveOptions(options) {
298
270
  publint: publint$1,
299
271
  alias,
300
272
  tsconfig,
301
- cwd
273
+ cwd,
274
+ report
302
275
  };
303
276
  return config;
304
277
  }));
@@ -473,7 +446,7 @@ async function buildSingle(config) {
473
446
  }
474
447
  }
475
448
  async function getBuildOptions(config, pkg, format, cjsDts) {
476
- const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd } = config;
449
+ const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report } = config;
477
450
  const plugins = [];
478
451
  if (pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config, pkg));
479
452
  if (dts) {
@@ -500,6 +473,7 @@ async function getBuildOptions(config, pkg, format, cjsDts) {
500
473
  }));
501
474
  plugins.push(ShebangPlugin(cwd));
502
475
  }
476
+ if (report) plugins.push(ReportPlugin(cwd, cjsDts));
503
477
  plugins.push(userPlugins);
504
478
  const inputOptions = await mergeUserOptions({
505
479
  input: entry,
@@ -1,4 +1,4 @@
1
- import { version } from "./package-DTByKj86.js";
1
+ import { version } from "./package-C_4Rg-Ho.js";
2
2
  import process from "node:process";
3
3
  import { readFile, unlink, writeFile } from "node:fs/promises";
4
4
  import consola$1 from "consola";
@@ -40,9 +40,6 @@ type Sourcemap = boolean | "inline" | "hidden";
40
40
  /**
41
41
  * Options for tsdown.
42
42
  */
43
- /**
44
- * Options for tsdown.
45
- */
46
43
  interface Options$3 {
47
44
  entry?: InputOption;
48
45
  external?: ExternalOption;
@@ -114,13 +111,15 @@ interface Options$3 {
114
111
  * Requires `publint` to be installed.
115
112
  */
116
113
  publint?: boolean | Options;
114
+ /**
115
+ * Enable size reporting after bundling.
116
+ * @default true
117
+ */
118
+ report?: boolean;
117
119
  }
118
120
  /**
119
121
  * Options without specifying config file path.
120
122
  */
121
- /**
122
- * Options without specifying config file path.
123
- */
124
123
  type UserConfig = Arrayable<Omit<Options$3, "config">>;
125
124
  type NormalizedFormat = Exclude<InternalModuleFormat, "app"> | "experimental-app";
126
125
  type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "dts" | "fixedExtension" | "outExtensions">, {
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.9.3";
3
+
4
+ //#endregion
5
+ export { version };
@@ -0,0 +1,232 @@
1
+ import { debug, logger } from "./logger-Dt3D6T-U.js";
2
+ import path, { dirname, normalize, sep } from "node:path";
3
+ import { access, chmod, readFile, rm } from "node:fs/promises";
4
+ import Debug from "debug";
5
+ import { findUp } from "find-up-simple";
6
+ import { Buffer } from "node:buffer";
7
+ import { promisify } from "node:util";
8
+ import { brotliCompress, gzip } from "node:zlib";
9
+ import { blue, bold, dim, green, underline, yellow } from "ansis";
10
+
11
+ //#region src/utils/fs.ts
12
+ function fsExists(path$1) {
13
+ return access(path$1).then(() => true, () => false);
14
+ }
15
+ function fsRemove(path$1) {
16
+ return rm(path$1, {
17
+ force: true,
18
+ recursive: true
19
+ }).catch(() => {});
20
+ }
21
+ function lowestCommonAncestor(...filepaths) {
22
+ if (filepaths.length === 0) return "";
23
+ if (filepaths.length === 1) return dirname(filepaths[0]);
24
+ filepaths = filepaths.map(normalize);
25
+ const [first, ...rest] = filepaths;
26
+ let ancestor = first.split(sep);
27
+ for (const filepath of rest) {
28
+ const directories = filepath.split(sep, ancestor.length);
29
+ let index = 0;
30
+ for (const directory of directories) if (directory === ancestor[index]) index += 1;
31
+ else {
32
+ ancestor = ancestor.slice(0, index);
33
+ break;
34
+ }
35
+ ancestor = ancestor.slice(0, index);
36
+ }
37
+ return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
38
+ }
39
+
40
+ //#endregion
41
+ //#region src/utils/general.ts
42
+ function toArray(val, defaultValue) {
43
+ if (Array.isArray(val)) return val;
44
+ else if (val == null) {
45
+ if (defaultValue) return [defaultValue];
46
+ return [];
47
+ } else return [val];
48
+ }
49
+ function debounce(fn, wait) {
50
+ let timeout;
51
+ return function(...args) {
52
+ if (timeout) clearTimeout(timeout);
53
+ timeout = setTimeout(() => {
54
+ timeout = void 0;
55
+ fn.apply(this, args);
56
+ }, wait);
57
+ };
58
+ }
59
+
60
+ //#endregion
61
+ //#region src/features/external.ts
62
+ const debug$2 = Debug("tsdown:external");
63
+ const RE_DTS$1 = /\.d\.[cm]?ts$/;
64
+ function ExternalPlugin(options, pkg) {
65
+ const deps = pkg && Array.from(getProductionDeps(pkg));
66
+ return {
67
+ name: "tsdown:external",
68
+ async resolveId(id, importer, { isEntry }) {
69
+ if (isEntry) return;
70
+ if (importer && RE_DTS$1.test(importer)) return;
71
+ const { noExternal } = options;
72
+ if (typeof noExternal === "function" && noExternal(id, importer)) return;
73
+ if (noExternal) {
74
+ const noExternalPatterns = toArray(noExternal);
75
+ if (noExternalPatterns.some((pattern) => {
76
+ return pattern instanceof RegExp ? pattern.test(id) : id === pattern;
77
+ })) return;
78
+ }
79
+ let shouldExternal = false;
80
+ if (options.skipNodeModulesBundle) {
81
+ const resolved = await this.resolve(id);
82
+ if (!resolved) return;
83
+ shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
84
+ }
85
+ if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
86
+ if (shouldExternal) {
87
+ debug$2("External dependency:", id);
88
+ return {
89
+ id,
90
+ external: shouldExternal
91
+ };
92
+ }
93
+ }
94
+ };
95
+ }
96
+ function getProductionDeps(pkg) {
97
+ return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
98
+ }
99
+
100
+ //#endregion
101
+ //#region src/utils/package.ts
102
+ async function readPackageJson(dir) {
103
+ const packageJsonPath = await findUp("package.json", { cwd: dir });
104
+ if (!packageJsonPath) return;
105
+ debug("Reading package.json:", packageJsonPath);
106
+ const contents = await readFile(packageJsonPath, "utf8");
107
+ return JSON.parse(contents);
108
+ }
109
+ function getPackageType(pkg) {
110
+ if (pkg?.type) {
111
+ if (!["module", "commonjs"].includes(pkg.type)) throw new Error(`Invalid package.json type: ${pkg.type}`);
112
+ return pkg.type;
113
+ }
114
+ }
115
+ function normalizeFormat(format) {
116
+ return toArray(format, "es").map((format$1) => {
117
+ switch (format$1) {
118
+ case "es":
119
+ case "esm":
120
+ case "module": return "es";
121
+ case "cjs":
122
+ case "commonjs": return "cjs";
123
+ default: return format$1;
124
+ }
125
+ });
126
+ }
127
+ function prettyFormat(format) {
128
+ switch (format) {
129
+ case "es": return "ESM";
130
+ case "cjs":
131
+ case "iife":
132
+ case "umd": return format.toUpperCase();
133
+ default: return format;
134
+ }
135
+ }
136
+
137
+ //#endregion
138
+ //#region src/utils/format.ts
139
+ function formatBytes(bytes) {
140
+ const numberFormatter = new Intl.NumberFormat("en", {
141
+ maximumFractionDigits: 2,
142
+ minimumFractionDigits: 2
143
+ });
144
+ return `${numberFormatter.format(bytes / 1e3)} kB`;
145
+ }
146
+
147
+ //#endregion
148
+ //#region src/features/report.ts
149
+ const debug$1 = Debug("tsdown:report");
150
+ const noop = (v) => v;
151
+ const brotliCompressAsync = promisify(brotliCompress);
152
+ const gzipAsync = promisify(gzip);
153
+ const RE_DTS = /\.d\.[cm]?ts$/;
154
+ function ReportPlugin(cwd, cjsDts) {
155
+ return {
156
+ name: "tsdown:report",
157
+ async writeBundle(options, bundle) {
158
+ const outDir = path.relative(cwd, options.file ? path.resolve(cwd, options.file, "..") : path.resolve(cwd, options.dir));
159
+ const sizes = [];
160
+ for (const chunk of Object.values(bundle)) {
161
+ const size = await calcSize(chunk);
162
+ sizes.push(size);
163
+ }
164
+ const filenameLength = Math.max(...sizes.map((size) => size.filename.length));
165
+ const rawTextLength = Math.max(...sizes.map((size) => size.rawText.length));
166
+ const gzipTextLength = Math.max(...sizes.map((size) => size.gzipText.length));
167
+ const brotliTextLength = Math.max(...sizes.map((size) => size.brotliText.length));
168
+ let totalRaw = 0;
169
+ for (const size of sizes) {
170
+ size.rawText = size.rawText.padStart(rawTextLength);
171
+ size.gzipText = size.gzipText.padStart(gzipTextLength);
172
+ size.brotliText = size.brotliText.padStart(brotliTextLength);
173
+ totalRaw += size.raw;
174
+ }
175
+ sizes.sort((a, b) => {
176
+ if (a.dts !== b.dts) return a.dts ? 1 : -1;
177
+ if (a.isEntry !== b.isEntry) return a.isEntry ? -1 : 1;
178
+ return b.brotli - a.brotli;
179
+ });
180
+ const format = cjsDts ? "cjs" : options.format;
181
+ const formatColor = format === "es" ? blue : format === "cjs" ? yellow : noop;
182
+ const formatText = formatColor(`[${prettyFormat(format)}]`);
183
+ for (const size of sizes) {
184
+ const filenameColor = size.dts ? green : noop;
185
+ logger.info(formatText, dim(`${outDir}/`) + filenameColor((size.isEntry ? bold : noop)(size.filename)), ` `.repeat(filenameLength - size.filename.length), dim`${size.rawText} │ gzip: ${size.gzipText} │ brotli: ${size.brotliText}`);
186
+ }
187
+ const totalSizeText = formatBytes(totalRaw);
188
+ logger.info(formatText, `${sizes.length} files, total: ${totalSizeText}`);
189
+ }
190
+ };
191
+ }
192
+ async function calcSize(chunk) {
193
+ debug$1(`Calculating size for ${chunk.fileName}`);
194
+ const content = chunk.type === "chunk" ? chunk.code : chunk.source;
195
+ const raw = Buffer.byteLength(content, "utf8");
196
+ const gzip$1 = (await gzipAsync(content)).length;
197
+ const brotli = (await brotliCompressAsync(content)).length;
198
+ return {
199
+ filename: chunk.fileName,
200
+ dts: RE_DTS.test(chunk.fileName),
201
+ isEntry: chunk.type === "chunk" && chunk.isEntry,
202
+ raw,
203
+ rawText: formatBytes(raw),
204
+ gzip: gzip$1,
205
+ gzipText: formatBytes(gzip$1),
206
+ brotli,
207
+ brotliText: formatBytes(brotli)
208
+ };
209
+ }
210
+
211
+ //#endregion
212
+ //#region src/features/shebang.ts
213
+ const RE_SHEBANG = /^#!.*/;
214
+ function ShebangPlugin(cwd) {
215
+ return {
216
+ name: "tsdown:shebang",
217
+ async writeBundle(options, bundle) {
218
+ for (const chunk of Object.values(bundle)) {
219
+ if (chunk.type !== "chunk" || !chunk.isEntry) continue;
220
+ if (!RE_SHEBANG.test(chunk.code)) continue;
221
+ const filepath = path.resolve(cwd, options.file || path.join(options.dir, chunk.fileName));
222
+ if (await fsExists(filepath)) {
223
+ logger.info(`Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
224
+ await chmod(filepath, 493);
225
+ }
226
+ }
227
+ }
228
+ };
229
+ }
230
+
231
+ //#endregion
232
+ export { ExternalPlugin, ReportPlugin, ShebangPlugin, debounce, fsExists, fsRemove, getPackageType, lowestCommonAncestor, normalizeFormat, readPackageJson, toArray };
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ResolvedOptions } from "./options.d-DxODs1UG.js";
1
+ import { ResolvedOptions } from "./options.d-CRAKIn7H.js";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
@@ -10,4 +10,8 @@ declare function ExternalPlugin(options: ResolvedOptions, pkg?: PackageJson): Pl
10
10
  declare function ShebangPlugin(cwd: string): Plugin;
11
11
 
12
12
  //#endregion
13
- export { ExternalPlugin, ShebangPlugin };
13
+ //#region src/features/report.d.ts
14
+ declare function ReportPlugin(cwd: string, cjsDts?: boolean): Plugin;
15
+
16
+ //#endregion
17
+ export { ExternalPlugin, ReportPlugin, ShebangPlugin };
package/dist/plugins.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ExternalPlugin, ShebangPlugin } from "./plugins-CATHxFm7.js";
1
+ import { ExternalPlugin, ReportPlugin, ShebangPlugin } from "./plugins-BvgcOKes.js";
2
2
  import "./logger-Dt3D6T-U.js";
3
3
 
4
- export { ExternalPlugin, ShebangPlugin };
4
+ export { ExternalPlugin, ReportPlugin, ShebangPlugin };
package/dist/run.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { logger, setSilent } from "./logger-Dt3D6T-U.js";
3
- import { version } from "./package-DTByKj86.js";
3
+ import { version } from "./package-C_4Rg-Ho.js";
4
4
  import process from "node:process";
5
5
  import { VERSION } from "rolldown";
6
6
  import { dim } from "ansis";
@@ -9,7 +9,7 @@ import { cac } from "cac";
9
9
  //#region src/cli.ts
10
10
  const cli = cac("tsdown");
11
11
  cli.help().version(version);
12
- cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--minify", "Minify output").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", { default: false }).option("--publint", "Enable publint", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").action(async (input, flags) => {
12
+ cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--minify", "Minify output").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", { default: false }).option("--publint", "Enable publint", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).action(async (input, flags) => {
13
13
  setSilent(!!flags.silent);
14
14
  logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
15
15
  const { build: build$1 } = await import("./index.js");
@@ -17,7 +17,7 @@ cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).op
17
17
  await build$1(flags);
18
18
  });
19
19
  cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
20
- const { migrate } = await import("./migrate-M59yd0BY.js");
20
+ const { migrate } = await import("./migrate-BB2Nt65I.js");
21
21
  await migrate(args);
22
22
  });
23
23
  async function runCLI() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -61,11 +61,11 @@
61
61
  "debug": "^4.4.0",
62
62
  "diff": "^7.0.0",
63
63
  "find-up-simple": "^1.0.1",
64
- "rolldown": "1.0.0-beta.7-commit.c2596d3",
65
- "rolldown-plugin-dts": "^0.8.0",
64
+ "rolldown": "1.0.0-beta.8-commit.d984417",
65
+ "rolldown-plugin-dts": "^0.8.3",
66
66
  "tinyexec": "^1.0.1",
67
- "tinyglobby": "^0.2.12",
68
- "unconfig": "^7.3.1"
67
+ "tinyglobby": "^0.2.13",
68
+ "unconfig": "^7.3.2"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@sxzz/eslint-config": "^6.1.2",
@@ -76,13 +76,13 @@
76
76
  "@types/node": "^22.14.1",
77
77
  "@unocss/eslint-plugin": "^66.1.0-beta.12",
78
78
  "bumpp": "^10.1.0",
79
- "eslint": "^9.25.0",
79
+ "eslint": "^9.25.1",
80
80
  "pkg-types": "^2.1.0",
81
81
  "prettier": "^3.5.3",
82
82
  "publint": "^0.3.12",
83
83
  "tsup": "^8.4.0",
84
84
  "tsx": "^4.19.3",
85
- "typedoc": "^0.28.2",
85
+ "typedoc": "^0.28.3",
86
86
  "typedoc-plugin-markdown": "^4.6.2",
87
87
  "typescript": "~5.8.3",
88
88
  "unocss": "^66.1.0-beta.12",
@@ -91,7 +91,7 @@
91
91
  "vitepress": "^1.6.3",
92
92
  "vitepress-plugin-group-icons": "^1.5.2",
93
93
  "vitepress-plugin-llms": "^1.1.0",
94
- "vitest": "^3.1.1",
94
+ "vitest": "^3.1.2",
95
95
  "vue": "^3.5.13"
96
96
  },
97
97
  "engines": {
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.9.2";
3
-
4
- //#endregion
5
- export { version };
@@ -1,117 +0,0 @@
1
- import { logger } from "./logger-Dt3D6T-U.js";
2
- import path, { dirname, normalize, sep } from "node:path";
3
- import { access, chmod, rm } from "node:fs/promises";
4
- import Debug from "debug";
5
- import { underline } from "ansis";
6
-
7
- //#region src/utils/fs.ts
8
- function fsExists(path$1) {
9
- return access(path$1).then(() => true, () => false);
10
- }
11
- function fsRemove(path$1) {
12
- return rm(path$1, {
13
- force: true,
14
- recursive: true
15
- }).catch(() => {});
16
- }
17
- function lowestCommonAncestor(...filepaths) {
18
- if (filepaths.length === 0) return "";
19
- if (filepaths.length === 1) return dirname(filepaths[0]);
20
- filepaths = filepaths.map(normalize);
21
- const [first, ...rest] = filepaths;
22
- let ancestor = first.split(sep);
23
- for (const filepath of rest) {
24
- const directories = filepath.split(sep, ancestor.length);
25
- let index = 0;
26
- for (const directory of directories) if (directory === ancestor[index]) index += 1;
27
- else {
28
- ancestor = ancestor.slice(0, index);
29
- break;
30
- }
31
- ancestor = ancestor.slice(0, index);
32
- }
33
- return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
34
- }
35
-
36
- //#endregion
37
- //#region src/utils/general.ts
38
- function toArray(val, defaultValue) {
39
- if (Array.isArray(val)) return val;
40
- else if (val == null) {
41
- if (defaultValue) return [defaultValue];
42
- return [];
43
- } else return [val];
44
- }
45
- function debounce(fn, wait) {
46
- let timeout;
47
- return function(...args) {
48
- if (timeout) clearTimeout(timeout);
49
- timeout = setTimeout(() => {
50
- timeout = void 0;
51
- fn.apply(this, args);
52
- }, wait);
53
- };
54
- }
55
-
56
- //#endregion
57
- //#region src/features/external.ts
58
- const debug = Debug("tsdown:external");
59
- const RE_DTS = /\.d\.[cm]?ts$/;
60
- function ExternalPlugin(options, pkg) {
61
- const deps = pkg && Array.from(getProductionDeps(pkg));
62
- return {
63
- name: "tsdown:external",
64
- async resolveId(id, importer, { isEntry }) {
65
- if (isEntry) return;
66
- if (importer && RE_DTS.test(importer)) return;
67
- const { noExternal } = options;
68
- if (typeof noExternal === "function" && noExternal(id, importer)) return;
69
- if (noExternal) {
70
- const noExternalPatterns = toArray(noExternal);
71
- if (noExternalPatterns.some((pattern) => {
72
- return pattern instanceof RegExp ? pattern.test(id) : id === pattern;
73
- })) return;
74
- }
75
- let shouldExternal = false;
76
- if (options.skipNodeModulesBundle) {
77
- const resolved = await this.resolve(id);
78
- if (!resolved) return;
79
- shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
80
- }
81
- if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
82
- if (shouldExternal) {
83
- debug("External dependency:", id);
84
- return {
85
- id,
86
- external: shouldExternal
87
- };
88
- }
89
- }
90
- };
91
- }
92
- function getProductionDeps(pkg) {
93
- return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
94
- }
95
-
96
- //#endregion
97
- //#region src/features/shebang.ts
98
- const RE_SHEBANG = /^#!.*/;
99
- function ShebangPlugin(cwd) {
100
- return {
101
- name: "tsdown:shebang",
102
- async writeBundle(options, bundle) {
103
- for (const chunk of Object.values(bundle)) {
104
- if (chunk.type !== "chunk" || !chunk.isEntry) continue;
105
- if (!RE_SHEBANG.test(chunk.code)) continue;
106
- const filepath = path.resolve(cwd, options.file || path.join(options.dir, chunk.fileName));
107
- if (await fsExists(filepath)) {
108
- logger.info(`Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
109
- await chmod(filepath, 493);
110
- }
111
- }
112
- }
113
- };
114
- }
115
-
116
- //#endregion
117
- export { ExternalPlugin, ShebangPlugin, debounce, fsExists, fsRemove, lowestCommonAncestor, toArray };