tsdown 0.9.1 → 0.9.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/README.md CHANGED
@@ -37,7 +37,7 @@ Please make sure to commit your changes before migrating. For more details, see
37
37
 
38
38
  ## Credits
39
39
 
40
- This project also partially contains code derived or copied from [tsup](https://github.com/egoist/tsup).
40
+ This project also partially contains code derived or copied from the following projects:
41
41
 
42
42
  - [tsup](https://github.com/egoist/tsup)
43
43
  - [pkgroll](https://github.com/privatenumber/pkgroll)
@@ -1,5 +1,7 @@
1
-
2
1
  //#region src/config.ts
2
+ /**
3
+ * Defines the configuration for tsdown.
4
+ */
3
5
  function defineConfig(options) {
4
6
  return options;
5
7
  }
@@ -1,9 +1,12 @@
1
- import { UserConfig } from "./options.d-ISLuYVFY.js";
1
+ import { UserConfig } from "./options.d-DxODs1UG.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
+ */
7
10
  declare function defineConfig(options: UserConfig): UserConfig;
8
11
 
9
12
  //#endregion
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "./options.d-ISLuYVFY.js";
2
- import { defineConfig$1 as defineConfig } from "./config.d-BcOfBgs6.js";
1
+ import "./options.d-DxODs1UG.js";
2
+ import { defineConfig$1 as defineConfig } from "./config.d-BrQCtlF9.js";
3
3
 
4
4
  export { defineConfig };
package/dist/config.js CHANGED
@@ -1,3 +1,3 @@
1
- import { defineConfig } from "./config-0LDjKwZ7.js";
1
+ import { defineConfig } from "./config-yiJy1jd0.js";
2
2
 
3
3
  export { defineConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Options, ResolvedOptions, UserConfig } from "./options.d-ISLuYVFY.js";
2
- import { defineConfig$1 as defineConfig } from "./config.d-BcOfBgs6.js";
1
+ import { Options, ResolvedOptions, UserConfig } from "./options.d-DxODs1UG.js";
2
+ import { defineConfig$1 as defineConfig } from "./config.d-BrQCtlF9.js";
3
3
  import Debug from "debug";
4
4
  import { ConsolaInstance } from "consola";
5
5
 
@@ -7,6 +7,9 @@ import { ConsolaInstance } from "consola";
7
7
  /**
8
8
  * Logger instance
9
9
  */
10
+ /**
11
+ * Logger instance
12
+ */
10
13
  declare const logger: ConsolaInstance;
11
14
 
12
15
  //#endregion
@@ -14,6 +17,9 @@ declare const logger: ConsolaInstance;
14
17
  /**
15
18
  * Build with tsdown.
16
19
  */
20
+ /**
21
+ * Build with tsdown.
22
+ */
17
23
  declare function build(userOptions?: Options): Promise<void>;
18
24
  declare const pkgRoot: string;
19
25
  /**
@@ -21,6 +27,11 @@ declare const pkgRoot: string;
21
27
  *
22
28
  * @param config Resolved options
23
29
  */
30
+ /**
31
+ * Build a single configuration, without watch and shortcuts features.
32
+ *
33
+ * @param config Resolved options
34
+ */
24
35
  declare function buildSingle(config: ResolvedOptions): Promise<(() => Promise<void>) | undefined>;
25
36
 
26
37
  //#endregion
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { defineConfig } from "./config-0LDjKwZ7.js";
2
- import { ExternalPlugin, ShebangPlugin, debounce, fsExists, fsRemove, lowestCommonAncestor, toArray } from "./plugins-DTE_EFWN.js";
3
- import { debug, logger, setSilent } from "./logger-9p9U7Sx7.js";
1
+ import { defineConfig } from "./config-yiJy1jd0.js";
2
+ import { ExternalPlugin, ShebangPlugin, debounce, fsExists, fsRemove, lowestCommonAncestor, toArray } from "./plugins-CATHxFm7.js";
3
+ import { debug, logger, setSilent } from "./logger-Dt3D6T-U.js";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -213,18 +213,18 @@ async function watchBuild(options, configFile, rebuild, restart) {
213
213
 
214
214
  //#endregion
215
215
  //#region src/features/entry.ts
216
- async function resolveEntry(entry) {
216
+ async function resolveEntry(entry, cwd) {
217
217
  if (!entry || Object.keys(entry).length === 0) throw new Error(`No input files, try "tsdown <your-file>" instead`);
218
- const objectEntry = await toObjectEntry(entry);
218
+ const objectEntry = await toObjectEntry(entry, cwd);
219
219
  const entries = Object.values(objectEntry);
220
220
  if (entries.length === 0) throw new Error(`Cannot find entry: ${JSON.stringify(entry)}`);
221
221
  logger.info(`entry: ${blue(entries.join(", "))}`);
222
222
  return objectEntry;
223
223
  }
224
- async function toObjectEntry(entry) {
224
+ async function toObjectEntry(entry, cwd) {
225
225
  if (typeof entry === "string") entry = [entry];
226
226
  if (!Array.isArray(entry)) return entry;
227
- const resolvedEntry = await glob(entry);
227
+ const resolvedEntry = await glob(entry, { cwd });
228
228
  const base = lowestCommonAncestor(...resolvedEntry);
229
229
  return Object.fromEntries(resolvedEntry.map((file) => {
230
230
  const relative = path.relative(base, file);
@@ -249,7 +249,7 @@ async function resolveOptions(options) {
249
249
  ...options
250
250
  };
251
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;
252
- entry = await resolveEntry(entry);
252
+ entry = await resolveEntry(entry, cwd);
253
253
  if (clean === true) clean = [];
254
254
  if (publint$1 === true) publint$1 = {};
255
255
  if (tsconfig !== false) {
@@ -268,7 +268,7 @@ async function resolveOptions(options) {
268
268
  if (!tsconfig) logger.warn(`No \`${tsconfig}\` found in \`${cwd}\``);
269
269
  }
270
270
  }
271
- if (tsconfig) logger.info(`Using tsconfig: ${underline(tsconfig)}`);
271
+ if (tsconfig) logger.info(`Using tsconfig: ${underline(path.relative(cwd, tsconfig))}`);
272
272
  }
273
273
  if (fromVite) {
274
274
  const viteUserConfig = await loadViteConfig(fromVite === true ? "vite" : fromVite, cwd);
@@ -297,7 +297,8 @@ async function resolveOptions(options) {
297
297
  skipNodeModulesBundle,
298
298
  publint: publint$1,
299
299
  alias,
300
- tsconfig
300
+ tsconfig,
301
+ cwd
301
302
  };
302
303
  return config;
303
304
  }));
@@ -401,6 +402,9 @@ async function mergeUserOptions(defaults, user, args) {
401
402
 
402
403
  //#endregion
403
404
  //#region src/index.ts
405
+ /**
406
+ * Build with tsdown.
407
+ */
404
408
  async function build(userOptions = {}) {
405
409
  if (typeof userOptions.silent === "boolean") setSilent(userOptions.silent);
406
410
  debug("Loading config");
@@ -423,6 +427,11 @@ async function build(userOptions = {}) {
423
427
  }
424
428
  const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
425
429
  const pkgRoot = path.resolve(dirname$1, "..");
430
+ /**
431
+ * Build a single configuration, without watch and shortcuts features.
432
+ *
433
+ * @param config Resolved options
434
+ */
426
435
  async function buildSingle(config) {
427
436
  const { outDir, format: formats, clean, dts, watch, onSuccess } = config;
428
437
  let onSuccessCleanup;
@@ -464,7 +473,7 @@ async function buildSingle(config) {
464
473
  }
465
474
  }
466
475
  async function getBuildOptions(config, pkg, format, cjsDts) {
467
- const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig } = config;
476
+ const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd } = config;
468
477
  const plugins = [];
469
478
  if (pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config, pkg));
470
479
  if (dts) {
@@ -485,14 +494,16 @@ async function getBuildOptions(config, pkg, format, cjsDts) {
485
494
  plugins.push(Unused.rolldown(unused === true ? {} : unused));
486
495
  }
487
496
  if (target) plugins.push(transformPlugin({
488
- target: target && (typeof target === "string" ? target : target.join(",")),
489
- exclude: /\.d\.[cm]?ts$/
497
+ include: /\.[cm]?[jt]sx?$/,
498
+ exclude: /\.d\.[cm]?ts$/,
499
+ transformOptions: { target }
490
500
  }));
491
- plugins.push(ShebangPlugin());
501
+ plugins.push(ShebangPlugin(cwd));
492
502
  }
493
503
  plugins.push(userPlugins);
494
504
  const inputOptions = await mergeUserOptions({
495
505
  input: entry,
506
+ cwd,
496
507
  external,
497
508
  resolve: {
498
509
  alias,
@@ -1,9 +1,12 @@
1
1
  import process from "node:process";
2
2
  import Debug from "debug";
3
- import { consola as consola$1 } from "consola";
3
+ import { consola } from "consola";
4
4
 
5
5
  //#region src/utils/logger.ts
6
- const logger = consola$1.withTag("tsdown");
6
+ /**
7
+ * Logger instance
8
+ */
9
+ const logger = consola.withTag("tsdown");
7
10
  const debug = Debug("tsdown");
8
11
  function setSilent(silent) {
9
12
  if (!("CONSOLA_LEVEL" in process.env)) logger.level = silent ? 0 : 3;
@@ -1,16 +1,16 @@
1
- import { version } from "./package-CSBuPH3y.js";
1
+ import { version } from "./package-DTByKj86.js";
2
2
  import process from "node:process";
3
3
  import { readFile, unlink, writeFile } from "node:fs/promises";
4
- import consola from "consola";
4
+ import consola$1 from "consola";
5
5
  import { existsSync } from "node:fs";
6
6
 
7
7
  //#region src/migrate.ts
8
8
  async function migrate({ cwd, dryRun }) {
9
- if (dryRun) consola.info("Dry run enabled. No changes were made.");
9
+ if (dryRun) consola$1.info("Dry run enabled. No changes were made.");
10
10
  else {
11
- const confirm = await consola.prompt("Please make sure to commit your changes before migrating. Continue?", { type: "confirm" });
11
+ const confirm = await consola$1.prompt("Please make sure to commit your changes before migrating. Continue?", { type: "confirm" });
12
12
  if (!confirm) {
13
- consola.error("Migration cancelled.");
13
+ consola$1.error("Migration cancelled.");
14
14
  process.exitCode = 1;
15
15
  return;
16
16
  }
@@ -18,15 +18,15 @@ async function migrate({ cwd, dryRun }) {
18
18
  if (cwd) process.chdir(cwd);
19
19
  let migrated = await migratePackageJson(dryRun);
20
20
  if (await migrateTsupConfig(dryRun)) migrated = true;
21
- if (migrated) consola.success("Migration completed. Remember to run install command with your package manager.");
21
+ if (migrated) consola$1.success("Migration completed. Remember to run install command with your package manager.");
22
22
  else {
23
- consola.error("No migration performed.");
23
+ consola$1.error("No migration performed.");
24
24
  process.exitCode = 1;
25
25
  }
26
26
  }
27
27
  async function migratePackageJson(dryRun) {
28
28
  if (!existsSync("package.json")) {
29
- consola.error("No package.json found");
29
+ consola$1.error("No package.json found");
30
30
  return false;
31
31
  }
32
32
  const pkgRaw = await readFile("package.json", "utf-8");
@@ -34,44 +34,44 @@ async function migratePackageJson(dryRun) {
34
34
  const semver = `^${version}`;
35
35
  let found = false;
36
36
  if (pkg.dependencies?.tsup) {
37
- consola.info("Migrating `dependencies` to tsdown.");
37
+ consola$1.info("Migrating `dependencies` to tsdown.");
38
38
  found = true;
39
39
  pkg.dependencies = renameKey(pkg.dependencies, "tsup", "tsdown", semver);
40
40
  }
41
41
  if (pkg.devDependencies?.tsup) {
42
- consola.info("Migrating `devDependencies` to tsdown.");
42
+ consola$1.info("Migrating `devDependencies` to tsdown.");
43
43
  found = true;
44
44
  pkg.devDependencies = renameKey(pkg.devDependencies, "tsup", "tsdown", semver);
45
45
  }
46
46
  if (pkg.peerDependencies?.tsup) {
47
- consola.info("Migrating `peerDependencies` to tsdown.");
47
+ consola$1.info("Migrating `peerDependencies` to tsdown.");
48
48
  found = true;
49
49
  pkg.peerDependencies = renameKey(pkg.peerDependencies, "tsup", "tsdown", "*");
50
50
  }
51
51
  if (pkg.scripts) {
52
52
  for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
53
- consola.info(`Migrating \`${key}\` script to tsdown`);
53
+ consola$1.info(`Migrating \`${key}\` script to tsdown`);
54
54
  found = true;
55
55
  pkg.scripts[key] = pkg.scripts[key].replaceAll(/tsup(?:-node)?/g, "tsdown");
56
56
  }
57
57
  }
58
58
  if (pkg.tsup) {
59
- consola.info("Migrating `tsup` field in package.json to `tsdown`.");
59
+ consola$1.info("Migrating `tsup` field in package.json to `tsdown`.");
60
60
  found = true;
61
61
  pkg = renameKey(pkg, "tsup", "tsdown");
62
62
  }
63
63
  if (!found) {
64
- consola.warn("No tsup-related fields found in package.json");
64
+ consola$1.warn("No tsup-related fields found in package.json");
65
65
  return false;
66
66
  }
67
67
  const pkgStr = `${JSON.stringify(pkg, null, 2)}\n`;
68
68
  if (dryRun) {
69
69
  const { createPatch } = await import("diff");
70
- consola.info("[dry-run] package.json:");
70
+ consola$1.info("[dry-run] package.json:");
71
71
  console.info(createPatch("package.json", pkgRaw, pkgStr));
72
72
  } else {
73
73
  await writeFile("package.json", pkgStr);
74
- consola.success("Migrated `package.json`");
74
+ consola$1.success("Migrated `package.json`");
75
75
  }
76
76
  return true;
77
77
  }
@@ -88,22 +88,22 @@ async function migrateTsupConfig(dryRun) {
88
88
  let found = false;
89
89
  for (const file of TSUP_FILES) {
90
90
  if (!existsSync(file)) continue;
91
- consola.info(`Found \`${file}\``);
91
+ consola$1.info(`Found \`${file}\``);
92
92
  found = true;
93
93
  const tsupConfigRaw = await readFile(file, "utf-8");
94
94
  const tsupConfig = tsupConfigRaw.replaceAll(/\btsup\b/g, "tsdown").replaceAll(/\bTSUP\b/g, "TSDOWN");
95
95
  const renamed = file.replaceAll("tsup", "tsdown");
96
96
  if (dryRun) {
97
97
  const { createTwoFilesPatch } = await import("diff");
98
- consola.info(`[dry-run] ${file} -> ${renamed}:`);
98
+ consola$1.info(`[dry-run] ${file} -> ${renamed}:`);
99
99
  console.info(createTwoFilesPatch(file, renamed, tsupConfigRaw, tsupConfig));
100
100
  } else {
101
101
  await writeFile(renamed, tsupConfig, "utf8");
102
102
  await unlink(file);
103
- consola.success(`Migrated \`${file}\` to \`${renamed}\``);
103
+ consola$1.success(`Migrated \`${file}\` to \`${renamed}\``);
104
104
  }
105
105
  }
106
- if (!found) consola.warn("No tsup config found");
106
+ if (!found) consola$1.warn("No tsup config found");
107
107
  return found;
108
108
  }
109
109
  function renameKey(obj, oldKey, newKey, newValue) {
@@ -40,6 +40,9 @@ type Sourcemap = boolean | "inline" | "hidden";
40
40
  /**
41
41
  * Options for tsdown.
42
42
  */
43
+ /**
44
+ * Options for tsdown.
45
+ */
43
46
  interface Options$3 {
44
47
  entry?: InputOption;
45
48
  external?: ExternalOption;
@@ -115,6 +118,9 @@ interface Options$3 {
115
118
  /**
116
119
  * Options without specifying config file path.
117
120
  */
121
+ /**
122
+ * Options without specifying config file path.
123
+ */
118
124
  type UserConfig = Arrayable<Omit<Options$3, "config">>;
119
125
  type NormalizedFormat = Exclude<InternalModuleFormat, "app"> | "experimental-app";
120
126
  type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inputOptions" | "outputOptions" | "minify" | "target" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "dts" | "fixedExtension" | "outExtensions">, {
@@ -122,6 +128,7 @@ type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inp
122
128
  clean: string[] | false
123
129
  dts: false | Options$1
124
130
  tsconfig: string | false
131
+ cwd: string
125
132
  }>, "config" | "fromVite">;
126
133
 
127
134
  //#endregion
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.9.2";
3
+
4
+ //#endregion
5
+ export { version };
@@ -1,4 +1,4 @@
1
- import { logger } from "./logger-9p9U7Sx7.js";
1
+ import { logger } from "./logger-Dt3D6T-U.js";
2
2
  import path, { dirname, normalize, sep } from "node:path";
3
3
  import { access, chmod, rm } from "node:fs/promises";
4
4
  import Debug from "debug";
@@ -96,17 +96,17 @@ function getProductionDeps(pkg) {
96
96
  //#endregion
97
97
  //#region src/features/shebang.ts
98
98
  const RE_SHEBANG = /^#!.*/;
99
- function ShebangPlugin() {
99
+ function ShebangPlugin(cwd) {
100
100
  return {
101
101
  name: "tsdown:shebang",
102
102
  async writeBundle(options, bundle) {
103
103
  for (const chunk of Object.values(bundle)) {
104
104
  if (chunk.type !== "chunk" || !chunk.isEntry) continue;
105
105
  if (!RE_SHEBANG.test(chunk.code)) continue;
106
- const file = options.file || path.resolve(options.dir, chunk.fileName);
107
- if (await fsExists(file)) {
108
- logger.info(`Granting execute permission to ${underline(file)}`);
109
- await chmod(file, 493);
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
110
  }
111
111
  }
112
112
  }
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ResolvedOptions } from "./options.d-ISLuYVFY.js";
1
+ import { ResolvedOptions } from "./options.d-DxODs1UG.js";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
@@ -7,7 +7,7 @@ declare function ExternalPlugin(options: ResolvedOptions, pkg?: PackageJson): Pl
7
7
 
8
8
  //#endregion
9
9
  //#region src/features/shebang.d.ts
10
- declare function ShebangPlugin(): Plugin;
10
+ declare function ShebangPlugin(cwd: string): Plugin;
11
11
 
12
12
  //#endregion
13
13
  export { ExternalPlugin, ShebangPlugin };
package/dist/plugins.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ExternalPlugin, ShebangPlugin } from "./plugins-DTE_EFWN.js";
2
- import "./logger-9p9U7Sx7.js";
1
+ import { ExternalPlugin, ShebangPlugin } from "./plugins-CATHxFm7.js";
2
+ import "./logger-Dt3D6T-U.js";
3
3
 
4
4
  export { ExternalPlugin, ShebangPlugin };
package/dist/run.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { logger, setSilent } from "./logger-9p9U7Sx7.js";
3
- import { version } from "./package-CSBuPH3y.js";
2
+ import { logger, setSilent } from "./logger-Dt3D6T-U.js";
3
+ import { version } from "./package-DTByKj86.js";
4
4
  import process from "node:process";
5
5
  import { VERSION } from "rolldown";
6
6
  import { dim } from "ansis";
@@ -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-BAvHnB3T.js");
20
+ const { migrate } = await import("./migrate-M59yd0BY.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.1",
3
+ "version": "0.9.2",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -61,20 +61,20 @@
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",
64
+ "rolldown": "1.0.0-beta.7-commit.c2596d3",
65
65
  "rolldown-plugin-dts": "^0.8.0",
66
66
  "tinyexec": "^1.0.1",
67
67
  "tinyglobby": "^0.2.12",
68
68
  "unconfig": "^7.3.1"
69
69
  },
70
70
  "devDependencies": {
71
- "@sxzz/eslint-config": "^6.1.1",
71
+ "@sxzz/eslint-config": "^6.1.2",
72
72
  "@sxzz/prettier-config": "^2.2.1",
73
73
  "@sxzz/test-utils": "^0.5.5",
74
74
  "@types/debug": "^4.1.12",
75
75
  "@types/diff": "^7.0.2",
76
76
  "@types/node": "^22.14.1",
77
- "@unocss/eslint-plugin": "66.1.0-beta.12",
77
+ "@unocss/eslint-plugin": "^66.1.0-beta.12",
78
78
  "bumpp": "^10.1.0",
79
79
  "eslint": "^9.25.0",
80
80
  "pkg-types": "^2.1.0",
@@ -86,7 +86,6 @@
86
86
  "typedoc-plugin-markdown": "^4.6.2",
87
87
  "typescript": "~5.8.3",
88
88
  "unocss": "^66.1.0-beta.12",
89
- "unplugin-ast": "^0.14.6",
90
89
  "unplugin-unused": "^0.4.4",
91
90
  "vite": "^6.3.2",
92
91
  "vitepress": "^1.6.3",
@@ -1,6 +0,0 @@
1
-
2
- //#region package.json
3
- var version = "0.9.1";
4
-
5
- //#endregion
6
- export { version };