tsdown 0.0.1 → 0.1.0

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/cli-run.js CHANGED
@@ -7,20 +7,19 @@ import process from "node:process";
7
7
  import { cac } from "cac";
8
8
 
9
9
  // package.json
10
- var version = "0.0.1";
10
+ var version = "0.1.0";
11
11
 
12
12
  // src/cli.ts
13
- async function main() {
13
+ async function runCLI() {
14
14
  const cli = cac("tsdown");
15
15
  cli.command("[...files]", "Bundle files", {
16
16
  ignoreOptionDefaultValue: true
17
- }).option("--clean", "Clean output directory").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).action(async (input, flags) => {
17
+ }).option("--config <filename>", "Use a custom config file").option("--clean", "Clean output directory").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).action(async (input, flags) => {
18
18
  logger.info(`tsdown v${version}`);
19
19
  const { build } = await import("./index.js");
20
- await build({
21
- entry: input,
22
- ...flags
23
- });
20
+ if (input.length > 0)
21
+ flags.entry = input;
22
+ await build(flags);
24
23
  });
25
24
  cli.help();
26
25
  cli.version(version);
@@ -29,4 +28,4 @@ async function main() {
29
28
  }
30
29
 
31
30
  // src/cli-run.ts
32
- await main();
31
+ runCLI();
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { InputOptions, OutputOptions } from '@rolldown/node';
1
+ import { InputOptions } from 'rolldown';
2
2
 
3
- type Format = NonNullable<OutputOptions['format']>;
3
+ type Format = 'es' | 'esm';
4
4
  interface Options {
5
5
  entry?: InputOptions['input'];
6
6
  format?: Format | Format[];
@@ -8,8 +8,10 @@ interface Options {
8
8
  external?: InputOptions['external'];
9
9
  outDir?: string;
10
10
  clean?: boolean | string[];
11
+ config?: boolean | string;
11
12
  }
12
13
 
13
14
  declare function build(userOptions?: Options): Promise<void>;
15
+ declare function defineConfig(options: Options): Options;
14
16
 
15
- export { build };
17
+ export { build, defineConfig };
package/dist/index.js CHANGED
@@ -4,11 +4,15 @@ import {
4
4
  } from "./chunk-J2CF23Y7.js";
5
5
 
6
6
  // src/index.ts
7
- import { rolldown } from "@rolldown/node";
7
+ import { rolldown } from "rolldown";
8
8
 
9
9
  // src/options.ts
10
10
  import { existsSync } from "node:fs";
11
+ import { stat } from "node:fs/promises";
12
+ import process from "node:process";
13
+ import path from "node:path";
11
14
  import { globby } from "globby";
15
+ import { loadConfig } from "unconfig";
12
16
 
13
17
  // src/error.ts
14
18
  var PrettyError = class extends Error {
@@ -25,9 +29,13 @@ var PrettyError = class extends Error {
25
29
 
26
30
  // src/options.ts
27
31
  async function normalizeOptions(options) {
32
+ options = {
33
+ ...await loadConfigFile(options),
34
+ ...options
35
+ };
28
36
  let {
29
37
  entry,
30
- format = ["esm"],
38
+ format = ["es"],
31
39
  plugins = [],
32
40
  external = [],
33
41
  clean = false
@@ -58,7 +66,7 @@ async function normalizeOptions(options) {
58
66
  if (!Array.isArray(format))
59
67
  format = [format];
60
68
  if (format.length === 0)
61
- format = ["esm"];
69
+ format = ["es"];
62
70
  if (clean && !Array.isArray(clean))
63
71
  clean = [];
64
72
  return {
@@ -70,6 +78,46 @@ async function normalizeOptions(options) {
70
78
  clean: clean ?? false
71
79
  };
72
80
  }
81
+ async function loadConfigFile(options) {
82
+ let { config: filePath } = options;
83
+ if (filePath === false)
84
+ return {};
85
+ let cwd = process.cwd();
86
+ let overrideConfig = false;
87
+ let stats;
88
+ if (typeof filePath === "string" && (stats = await stat(filePath).catch(() => null))) {
89
+ const resolved = path.resolve(filePath);
90
+ if (stats.isFile()) {
91
+ overrideConfig = true;
92
+ filePath = resolved;
93
+ cwd = path.dirname(filePath);
94
+ } else {
95
+ cwd = resolved;
96
+ }
97
+ }
98
+ const { config, sources } = await loadConfig({
99
+ sources: overrideConfig ? [{ files: filePath, extensions: [] }] : [
100
+ {
101
+ files: "tsdown.config",
102
+ extensions: ["ts", "mts", "cts", "js", "mjs", "cjs", "json", ""]
103
+ },
104
+ {
105
+ files: "package.json",
106
+ extensions: [],
107
+ rewrite: (config2) => config2?.tsdown
108
+ }
109
+ ],
110
+ cwd,
111
+ defaults: {}
112
+ });
113
+ if (sources.length > 0) {
114
+ logger.info(`Using tsdown config: ${sources.join(", ")}`);
115
+ }
116
+ return config;
117
+ }
118
+ function resolveFormat(format) {
119
+ return format === "esm" ? "es" : format;
120
+ }
73
121
 
74
122
  // src/index.ts
75
123
  async function build(userOptions = {}) {
@@ -86,13 +134,17 @@ async function build(userOptions = {}) {
86
134
  await Promise.all(
87
135
  format.map(
88
136
  (format2) => build2.write({
89
- format: format2,
137
+ format: resolveFormat(format2),
90
138
  dir: outDir
91
139
  })
92
140
  )
93
141
  );
94
142
  logger.info("Build complete");
95
143
  }
144
+ function defineConfig(options) {
145
+ return options;
146
+ }
96
147
  export {
97
- build
148
+ build,
149
+ defineConfig
98
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "packageManager": "pnpm@8.15.4",
5
5
  "description": "An even faster bundler powered by Rolldown.",
6
6
  "type": "module",
@@ -34,22 +34,23 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@rolldown/node": "^0.0.5",
38
37
  "cac": "^6.7.14",
39
38
  "consola": "^3.2.3",
40
- "globby": "^14.0.1"
39
+ "globby": "^14.0.1",
40
+ "rolldown": "nightly",
41
+ "unconfig": "^0.3.11"
41
42
  },
42
43
  "devDependencies": {
43
- "@sxzz/eslint-config": "^3.8.4",
44
+ "@sxzz/eslint-config": "^3.8.7",
44
45
  "@sxzz/prettier-config": "^2.0.1",
45
- "@types/node": "^20.11.24",
46
- "bumpp": "^9.3.1",
46
+ "@types/node": "^20.11.30",
47
+ "bumpp": "^9.4.0",
47
48
  "eslint": "^8.57.0",
48
49
  "prettier": "^3.2.5",
49
50
  "tsup": "^8.0.2",
50
51
  "tsx": "^4.7.1",
51
- "typescript": "^5.3.3",
52
- "vitest": "^1.3.1"
52
+ "typescript": "^5.4.3",
53
+ "vitest": "^1.4.0"
53
54
  },
54
55
  "engines": {
55
56
  "node": ">=18.0.0"