tsdown 0.0.0 → 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/LICENSE +1 -1
- package/README.md +12 -3
- package/dist/chunk-J2CF23Y7.js +18 -0
- package/dist/cli-run.d.ts +2 -0
- package/dist/cli-run.js +31 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +147 -2
- package/package.json +27 -16
- package/dist/index.cjs +0 -5
- package/dist/index.d.cts +0 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright ©
|
|
3
|
+
Copyright © 2024 三咲智子 Kevin Deng (https://github.com/sxzz)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
# tsdown [](https://npmjs.com/package/tsdown)
|
|
1
|
+
# tsdown [](https://npmjs.com/package/tsdown) [](https://github.com/sxzz/tsdown/actions/workflows/unit-test.yml)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An even faster bundler powered by Rolldown.
|
|
4
|
+
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> 🚧 **Work in Progress**
|
|
7
|
+
>
|
|
8
|
+
> tsdown is currently in active development and not usable for production yet.
|
|
4
9
|
|
|
5
10
|
## Install
|
|
6
11
|
|
|
@@ -8,6 +13,10 @@
|
|
|
8
13
|
npm i tsdown
|
|
9
14
|
```
|
|
10
15
|
|
|
16
|
+
## Credits
|
|
17
|
+
|
|
18
|
+
This project also partially contains code derived or copied from [tsup](https://github.com/egoist/tsup).
|
|
19
|
+
|
|
11
20
|
## Sponsors
|
|
12
21
|
|
|
13
22
|
<p align="center">
|
|
@@ -18,4 +27,4 @@ npm i tsdown
|
|
|
18
27
|
|
|
19
28
|
## License
|
|
20
29
|
|
|
21
|
-
[MIT](./LICENSE) License ©
|
|
30
|
+
[MIT](./LICENSE) License © 2024 [三咲智子 Kevin Deng](https://github.com/sxzz)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { unlink } from "node:fs/promises";
|
|
4
|
+
import { globby } from "globby";
|
|
5
|
+
import { consola } from "consola";
|
|
6
|
+
async function removeFiles(patterns, dir) {
|
|
7
|
+
const files = await globby(patterns, {
|
|
8
|
+
cwd: dir,
|
|
9
|
+
absolute: true
|
|
10
|
+
});
|
|
11
|
+
await Promise.all(files.map((file) => existsSync(file) && unlink(file)));
|
|
12
|
+
}
|
|
13
|
+
var logger = consola.withTag("tsdown");
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
removeFiles,
|
|
17
|
+
logger
|
|
18
|
+
};
|
package/dist/cli-run.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logger
|
|
3
|
+
} from "./chunk-J2CF23Y7.js";
|
|
4
|
+
|
|
5
|
+
// src/cli.ts
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import { cac } from "cac";
|
|
8
|
+
|
|
9
|
+
// package.json
|
|
10
|
+
var version = "0.1.0";
|
|
11
|
+
|
|
12
|
+
// src/cli.ts
|
|
13
|
+
async function runCLI() {
|
|
14
|
+
const cli = cac("tsdown");
|
|
15
|
+
cli.command("[...files]", "Bundle files", {
|
|
16
|
+
ignoreOptionDefaultValue: true
|
|
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
|
+
logger.info(`tsdown v${version}`);
|
|
19
|
+
const { build } = await import("./index.js");
|
|
20
|
+
if (input.length > 0)
|
|
21
|
+
flags.entry = input;
|
|
22
|
+
await build(flags);
|
|
23
|
+
});
|
|
24
|
+
cli.help();
|
|
25
|
+
cli.version(version);
|
|
26
|
+
cli.parse(process.argv, { run: false });
|
|
27
|
+
await cli.runMatchedCommand();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/cli-run.ts
|
|
31
|
+
runCLI();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { InputOptions } from 'rolldown';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type Format = 'es' | 'esm';
|
|
4
|
+
interface Options {
|
|
5
|
+
entry?: InputOptions['input'];
|
|
6
|
+
format?: Format | Format[];
|
|
7
|
+
plugins?: InputOptions['plugins'];
|
|
8
|
+
external?: InputOptions['external'];
|
|
9
|
+
outDir?: string;
|
|
10
|
+
clean?: boolean | string[];
|
|
11
|
+
config?: boolean | string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare function build(userOptions?: Options): Promise<void>;
|
|
15
|
+
declare function defineConfig(options: Options): Options;
|
|
16
|
+
|
|
17
|
+
export { build, defineConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logger,
|
|
3
|
+
removeFiles
|
|
4
|
+
} from "./chunk-J2CF23Y7.js";
|
|
5
|
+
|
|
1
6
|
// src/index.ts
|
|
2
|
-
|
|
7
|
+
import { rolldown } from "rolldown";
|
|
8
|
+
|
|
9
|
+
// src/options.ts
|
|
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";
|
|
14
|
+
import { globby } from "globby";
|
|
15
|
+
import { loadConfig } from "unconfig";
|
|
16
|
+
|
|
17
|
+
// src/error.ts
|
|
18
|
+
var PrettyError = class extends Error {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = this.constructor.name;
|
|
22
|
+
if (typeof Error.captureStackTrace === "function") {
|
|
23
|
+
Error.captureStackTrace(this, this.constructor);
|
|
24
|
+
} else {
|
|
25
|
+
this.stack = new Error(message).stack;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/options.ts
|
|
31
|
+
async function normalizeOptions(options) {
|
|
32
|
+
options = {
|
|
33
|
+
...await loadConfigFile(options),
|
|
34
|
+
...options
|
|
35
|
+
};
|
|
36
|
+
let {
|
|
37
|
+
entry,
|
|
38
|
+
format = ["es"],
|
|
39
|
+
plugins = [],
|
|
40
|
+
external = [],
|
|
41
|
+
clean = false
|
|
42
|
+
} = options;
|
|
43
|
+
if (!entry || Object.keys(entry).length === 0) {
|
|
44
|
+
throw new PrettyError(`No input files, try "tsdown <your-file>" instead`);
|
|
45
|
+
}
|
|
46
|
+
if (typeof entry === "string") {
|
|
47
|
+
entry = [entry];
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(entry)) {
|
|
50
|
+
const resolvedEntry = await globby(entry);
|
|
51
|
+
if (resolvedEntry.length > 0) {
|
|
52
|
+
entry = resolvedEntry;
|
|
53
|
+
logger.info(`Building entry: ${entry}`);
|
|
54
|
+
} else {
|
|
55
|
+
throw new PrettyError(`Cannot find ${entry}`);
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
Object.keys(entry).forEach((alias) => {
|
|
59
|
+
const filename = entry[alias];
|
|
60
|
+
if (!existsSync(filename)) {
|
|
61
|
+
throw new PrettyError(`Cannot find ${alias}: ${filename}`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
logger.info(`Building entry: ${JSON.stringify(entry)}`);
|
|
65
|
+
}
|
|
66
|
+
if (!Array.isArray(format))
|
|
67
|
+
format = [format];
|
|
68
|
+
if (format.length === 0)
|
|
69
|
+
format = ["es"];
|
|
70
|
+
if (clean && !Array.isArray(clean))
|
|
71
|
+
clean = [];
|
|
72
|
+
return {
|
|
73
|
+
entry,
|
|
74
|
+
plugins,
|
|
75
|
+
external,
|
|
76
|
+
format,
|
|
77
|
+
outDir: options.outDir || "dist",
|
|
78
|
+
clean: clean ?? false
|
|
79
|
+
};
|
|
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
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/index.ts
|
|
123
|
+
async function build(userOptions = {}) {
|
|
124
|
+
const { entry, external, plugins, outDir, format, clean } = await normalizeOptions(userOptions);
|
|
125
|
+
if (clean) {
|
|
126
|
+
await removeFiles(["**/*", ...clean], outDir);
|
|
127
|
+
logger.info("Cleaning output folder");
|
|
128
|
+
}
|
|
129
|
+
const build2 = await rolldown({
|
|
130
|
+
input: entry,
|
|
131
|
+
external,
|
|
132
|
+
plugins
|
|
133
|
+
});
|
|
134
|
+
await Promise.all(
|
|
135
|
+
format.map(
|
|
136
|
+
(format2) => build2.write({
|
|
137
|
+
format: resolveFormat(format2),
|
|
138
|
+
dir: outDir
|
|
139
|
+
})
|
|
140
|
+
)
|
|
141
|
+
);
|
|
142
|
+
logger.info("Build complete");
|
|
143
|
+
}
|
|
144
|
+
function defineConfig(options) {
|
|
145
|
+
return options;
|
|
146
|
+
}
|
|
3
147
|
export {
|
|
4
|
-
|
|
148
|
+
build,
|
|
149
|
+
defineConfig
|
|
5
150
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"packageManager": "pnpm@8.
|
|
5
|
-
"description": "",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"packageManager": "pnpm@8.15.4",
|
|
5
|
+
"description": "An even faster bundler powered by Rolldown.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/sxzz/tsdown#readme",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git+https://github.com/sxzz/tsdown.git"
|
|
15
15
|
},
|
|
16
|
+
"author": "三咲智子 Kevin Deng <sxzz@sxzz.moe>",
|
|
16
17
|
"files": [
|
|
17
18
|
"dist"
|
|
18
19
|
],
|
|
@@ -26,33 +27,43 @@
|
|
|
26
27
|
},
|
|
27
28
|
"./package.json": "./package.json"
|
|
28
29
|
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"tsdown": "./dist/cli-run.js"
|
|
32
|
+
},
|
|
29
33
|
"publishConfig": {
|
|
30
34
|
"access": "public"
|
|
31
35
|
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"cac": "^6.7.14",
|
|
38
|
+
"consola": "^3.2.3",
|
|
39
|
+
"globby": "^14.0.1",
|
|
40
|
+
"rolldown": "nightly",
|
|
41
|
+
"unconfig": "^0.3.11"
|
|
42
|
+
},
|
|
32
43
|
"devDependencies": {
|
|
33
|
-
"@sxzz/eslint-config": "^3.7
|
|
34
|
-
"@sxzz/prettier-config": "^
|
|
35
|
-
"@types/node": "^20.
|
|
36
|
-
"bumpp": "^9.
|
|
37
|
-
"eslint": "^8.
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"vitest": "^0.34.6"
|
|
44
|
+
"@sxzz/eslint-config": "^3.8.7",
|
|
45
|
+
"@sxzz/prettier-config": "^2.0.1",
|
|
46
|
+
"@types/node": "^20.11.30",
|
|
47
|
+
"bumpp": "^9.4.0",
|
|
48
|
+
"eslint": "^8.57.0",
|
|
49
|
+
"prettier": "^3.2.5",
|
|
50
|
+
"tsup": "^8.0.2",
|
|
51
|
+
"tsx": "^4.7.1",
|
|
52
|
+
"typescript": "^5.4.3",
|
|
53
|
+
"vitest": "^1.4.0"
|
|
44
54
|
},
|
|
45
55
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
56
|
+
"node": ">=18.0.0"
|
|
47
57
|
},
|
|
48
58
|
"prettier": "@sxzz/prettier-config",
|
|
49
59
|
"scripts": {
|
|
50
60
|
"lint": "eslint --cache .",
|
|
51
61
|
"lint:fix": "pnpm run lint --fix",
|
|
52
62
|
"build": "tsup",
|
|
53
|
-
"dev": "
|
|
63
|
+
"dev": "tsx ./src/cli-run.ts",
|
|
54
64
|
"test": "vitest",
|
|
55
65
|
"typecheck": "tsc --noEmit",
|
|
66
|
+
"format": "prettier --cache --write .",
|
|
56
67
|
"release": "bumpp && pnpm publish"
|
|
57
68
|
}
|
|
58
69
|
}
|
package/dist/index.cjs
DELETED
package/dist/index.d.cts
DELETED