tsdown 0.0.0 → 0.0.1
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 +32 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.js +95 -2
- package/package.json +26 -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,32 @@
|
|
|
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.0.1";
|
|
11
|
+
|
|
12
|
+
// src/cli.ts
|
|
13
|
+
async function main() {
|
|
14
|
+
const cli = cac("tsdown");
|
|
15
|
+
cli.command("[...files]", "Bundle files", {
|
|
16
|
+
ignoreOptionDefaultValue: true
|
|
17
|
+
}).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
|
+
await build({
|
|
21
|
+
entry: input,
|
|
22
|
+
...flags
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
cli.help();
|
|
26
|
+
cli.version(version);
|
|
27
|
+
cli.parse(process.argv, { run: false });
|
|
28
|
+
await cli.runMatchedCommand();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/cli-run.ts
|
|
32
|
+
await main();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { InputOptions, OutputOptions } from '@rolldown/node';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type Format = NonNullable<OutputOptions['format']>;
|
|
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
|
+
}
|
|
12
|
+
|
|
13
|
+
declare function build(userOptions?: Options): Promise<void>;
|
|
14
|
+
|
|
15
|
+
export { build };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logger,
|
|
3
|
+
removeFiles
|
|
4
|
+
} from "./chunk-J2CF23Y7.js";
|
|
5
|
+
|
|
1
6
|
// src/index.ts
|
|
2
|
-
|
|
7
|
+
import { rolldown } from "@rolldown/node";
|
|
8
|
+
|
|
9
|
+
// src/options.ts
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { globby } from "globby";
|
|
12
|
+
|
|
13
|
+
// src/error.ts
|
|
14
|
+
var PrettyError = class extends Error {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = this.constructor.name;
|
|
18
|
+
if (typeof Error.captureStackTrace === "function") {
|
|
19
|
+
Error.captureStackTrace(this, this.constructor);
|
|
20
|
+
} else {
|
|
21
|
+
this.stack = new Error(message).stack;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/options.ts
|
|
27
|
+
async function normalizeOptions(options) {
|
|
28
|
+
let {
|
|
29
|
+
entry,
|
|
30
|
+
format = ["esm"],
|
|
31
|
+
plugins = [],
|
|
32
|
+
external = [],
|
|
33
|
+
clean = false
|
|
34
|
+
} = options;
|
|
35
|
+
if (!entry || Object.keys(entry).length === 0) {
|
|
36
|
+
throw new PrettyError(`No input files, try "tsdown <your-file>" instead`);
|
|
37
|
+
}
|
|
38
|
+
if (typeof entry === "string") {
|
|
39
|
+
entry = [entry];
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(entry)) {
|
|
42
|
+
const resolvedEntry = await globby(entry);
|
|
43
|
+
if (resolvedEntry.length > 0) {
|
|
44
|
+
entry = resolvedEntry;
|
|
45
|
+
logger.info(`Building entry: ${entry}`);
|
|
46
|
+
} else {
|
|
47
|
+
throw new PrettyError(`Cannot find ${entry}`);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
Object.keys(entry).forEach((alias) => {
|
|
51
|
+
const filename = entry[alias];
|
|
52
|
+
if (!existsSync(filename)) {
|
|
53
|
+
throw new PrettyError(`Cannot find ${alias}: ${filename}`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
logger.info(`Building entry: ${JSON.stringify(entry)}`);
|
|
57
|
+
}
|
|
58
|
+
if (!Array.isArray(format))
|
|
59
|
+
format = [format];
|
|
60
|
+
if (format.length === 0)
|
|
61
|
+
format = ["esm"];
|
|
62
|
+
if (clean && !Array.isArray(clean))
|
|
63
|
+
clean = [];
|
|
64
|
+
return {
|
|
65
|
+
entry,
|
|
66
|
+
plugins,
|
|
67
|
+
external,
|
|
68
|
+
format,
|
|
69
|
+
outDir: options.outDir || "dist",
|
|
70
|
+
clean: clean ?? false
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/index.ts
|
|
75
|
+
async function build(userOptions = {}) {
|
|
76
|
+
const { entry, external, plugins, outDir, format, clean } = await normalizeOptions(userOptions);
|
|
77
|
+
if (clean) {
|
|
78
|
+
await removeFiles(["**/*", ...clean], outDir);
|
|
79
|
+
logger.info("Cleaning output folder");
|
|
80
|
+
}
|
|
81
|
+
const build2 = await rolldown({
|
|
82
|
+
input: entry,
|
|
83
|
+
external,
|
|
84
|
+
plugins
|
|
85
|
+
});
|
|
86
|
+
await Promise.all(
|
|
87
|
+
format.map(
|
|
88
|
+
(format2) => build2.write({
|
|
89
|
+
format: format2,
|
|
90
|
+
dir: outDir
|
|
91
|
+
})
|
|
92
|
+
)
|
|
93
|
+
);
|
|
94
|
+
logger.info("Build complete");
|
|
95
|
+
}
|
|
3
96
|
export {
|
|
4
|
-
|
|
97
|
+
build
|
|
5
98
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"packageManager": "pnpm@8.
|
|
5
|
-
"description": "",
|
|
3
|
+
"version": "0.0.1",
|
|
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,42 @@
|
|
|
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
|
+
"@rolldown/node": "^0.0.5",
|
|
38
|
+
"cac": "^6.7.14",
|
|
39
|
+
"consola": "^3.2.3",
|
|
40
|
+
"globby": "^14.0.1"
|
|
41
|
+
},
|
|
32
42
|
"devDependencies": {
|
|
33
|
-
"@sxzz/eslint-config": "^3.
|
|
34
|
-
"@sxzz/prettier-config": "^
|
|
35
|
-
"@types/node": "^20.
|
|
36
|
-
"bumpp": "^9.
|
|
37
|
-
"eslint": "^8.
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"vitest": "^0.34.6"
|
|
43
|
+
"@sxzz/eslint-config": "^3.8.4",
|
|
44
|
+
"@sxzz/prettier-config": "^2.0.1",
|
|
45
|
+
"@types/node": "^20.11.24",
|
|
46
|
+
"bumpp": "^9.3.1",
|
|
47
|
+
"eslint": "^8.57.0",
|
|
48
|
+
"prettier": "^3.2.5",
|
|
49
|
+
"tsup": "^8.0.2",
|
|
50
|
+
"tsx": "^4.7.1",
|
|
51
|
+
"typescript": "^5.3.3",
|
|
52
|
+
"vitest": "^1.3.1"
|
|
44
53
|
},
|
|
45
54
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
55
|
+
"node": ">=18.0.0"
|
|
47
56
|
},
|
|
48
57
|
"prettier": "@sxzz/prettier-config",
|
|
49
58
|
"scripts": {
|
|
50
59
|
"lint": "eslint --cache .",
|
|
51
60
|
"lint:fix": "pnpm run lint --fix",
|
|
52
61
|
"build": "tsup",
|
|
53
|
-
"dev": "
|
|
62
|
+
"dev": "tsx ./src/cli-run.ts",
|
|
54
63
|
"test": "vitest",
|
|
55
64
|
"typecheck": "tsc --noEmit",
|
|
65
|
+
"format": "prettier --cache --write .",
|
|
56
66
|
"release": "bumpp && pnpm publish"
|
|
57
67
|
}
|
|
58
68
|
}
|
package/dist/index.cjs
DELETED
package/dist/index.d.cts
DELETED