create-tsdown 0.0.4 → 0.15.7
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/dist/index.d.mts +18 -0
- package/dist/index.mjs +3 -0
- package/dist/run.mjs +33 -0
- package/dist/src-B4P8WTtN.mjs +90 -0
- package/package.json +17 -54
- package/README.md +0 -29
- package/dist/index.d.ts +0 -47
- package/dist/index.js +0 -44
- package/dist/logger-0-2qD2tL.js +0 -41
- package/dist/migrate-Bkv2YVUc.js +0 -104
- package/dist/package-CMEcUNLd.js +0 -5
- package/dist/run.js +0 -191
- /package/dist/{run.d.ts → run.d.mts} +0 -0
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2025-present VoidZero Inc. & Contributors
|
|
4
|
-
Copyright (c) 2024
|
|
4
|
+
Copyright (c) 2024 Kevin Deng (https://github.com/sxzz)
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface Options {
|
|
3
|
+
template?: "default" | "minimal" | "vue" | "react" | "solid";
|
|
4
|
+
path?: string;
|
|
5
|
+
}
|
|
6
|
+
type ResolvedOptions = Required<Options>;
|
|
7
|
+
/**
|
|
8
|
+
* Create a tsdown project.
|
|
9
|
+
*/
|
|
10
|
+
declare function create(path: string | undefined, options: Options): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the user options and configs
|
|
13
|
+
* @param options The user options
|
|
14
|
+
* @returns The resolved options
|
|
15
|
+
*/
|
|
16
|
+
declare function resolveOptions(options: Options): Promise<ResolvedOptions>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Options, ResolvedOptions, create, resolveOptions };
|
package/dist/index.mjs
ADDED
package/dist/run.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { create } from "./src-B4P8WTtN.mjs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { log } from "@clack/prompts";
|
|
5
|
+
import { cac } from "cac";
|
|
6
|
+
|
|
7
|
+
//#region package.json
|
|
8
|
+
var version = "0.15.7";
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/cli.ts
|
|
12
|
+
const cli = cac("create-tsdown");
|
|
13
|
+
cli.help().version(version);
|
|
14
|
+
cli.command("[path]", "Create a tsdown project", {
|
|
15
|
+
ignoreOptionDefaultValue: true,
|
|
16
|
+
allowUnknownOptions: true
|
|
17
|
+
}).option("-t, --template <template>", "Available templates: default, minimal, vue, react, solid", { default: "default" }).action((path, options) => create(path, options));
|
|
18
|
+
async function runCLI() {
|
|
19
|
+
cli.parse(process.argv, { run: false });
|
|
20
|
+
try {
|
|
21
|
+
await cli.runMatchedCommand();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
log.error(String(error));
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/run.ts
|
|
30
|
+
runCLI();
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
import { cancel, intro, isCancel, outro, select, spinner, text } from "@clack/prompts";
|
|
4
|
+
import { downloadTemplate } from "giget";
|
|
5
|
+
import { getUserAgent } from "package-manager-detector";
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* Create a tsdown project.
|
|
10
|
+
*/
|
|
11
|
+
async function create(path, options) {
|
|
12
|
+
intro(`Creating a tsdown project...`);
|
|
13
|
+
const resolved = await resolveOptions({
|
|
14
|
+
...options,
|
|
15
|
+
path
|
|
16
|
+
});
|
|
17
|
+
const s = spinner();
|
|
18
|
+
s.start("Cloning the template...");
|
|
19
|
+
await downloadTemplate(`gh:sxzz/tsdown-templates/${resolved.template}`, { dir: resolved.path });
|
|
20
|
+
s.stop("Template cloned");
|
|
21
|
+
const pm = getUserAgent() || "npm";
|
|
22
|
+
outro(`Done! Now run:\n ${styleText("green", `cd ${resolved.path}`)}\n ${styleText("green", `${pm} install`)}\n ${styleText("green", `${pm} run build`)}\n\nFor more information, visit: ${styleText("underline", `https://tsdown.dev/`)}`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the user options and configs
|
|
26
|
+
* @param options The user options
|
|
27
|
+
* @returns The resolved options
|
|
28
|
+
*/
|
|
29
|
+
async function resolveOptions(options) {
|
|
30
|
+
let path = options.path;
|
|
31
|
+
if (!path) {
|
|
32
|
+
const defaultPath = "./my-tsdown-package";
|
|
33
|
+
path = await text({
|
|
34
|
+
message: "What is the name of your package?",
|
|
35
|
+
placeholder: defaultPath
|
|
36
|
+
}) || defaultPath;
|
|
37
|
+
if (isCancel(path)) {
|
|
38
|
+
cancel("Operation cancelled.");
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let template = options.template;
|
|
43
|
+
if (template) {
|
|
44
|
+
if (![
|
|
45
|
+
"default",
|
|
46
|
+
"minimal",
|
|
47
|
+
"vue",
|
|
48
|
+
"react",
|
|
49
|
+
"solid"
|
|
50
|
+
].includes(template)) throw new Error(`Invalid template "${template}". Available templates: default, vue, react, solid`);
|
|
51
|
+
} else {
|
|
52
|
+
template = await select({
|
|
53
|
+
message: "Which template do you want to use?",
|
|
54
|
+
options: [
|
|
55
|
+
{
|
|
56
|
+
value: "default",
|
|
57
|
+
label: "Default"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
value: "minimal",
|
|
61
|
+
label: "Minimal"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
value: "vue",
|
|
65
|
+
label: "Vue"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
value: "react",
|
|
69
|
+
label: "React"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
value: "solid",
|
|
73
|
+
label: "Solid"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
initialValue: "default"
|
|
77
|
+
});
|
|
78
|
+
if (isCancel(template)) {
|
|
79
|
+
cancel("Operation cancelled.");
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
path,
|
|
85
|
+
template
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { create, resolveOptions };
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-tsdown",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.15.7",
|
|
4
|
+
"description": "Create a new tsdown project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://github.com/
|
|
7
|
+
"homepage": "https://github.com/rolldown/tsdown/tree/main/packages/create#readme",
|
|
8
8
|
"bugs": {
|
|
9
|
-
"url": "https://github.com/
|
|
9
|
+
"url": "https://github.com/rolldown/tsdown/issues"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/
|
|
13
|
+
"url": "git+https://github.com/rolldown/tsdown.git",
|
|
14
|
+
"directory": "packages/create-tsdown"
|
|
14
15
|
},
|
|
15
|
-
"author": "
|
|
16
|
+
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
16
17
|
"funding": "https://github.com/sponsors/sxzz",
|
|
17
18
|
"files": [
|
|
18
|
-
"dist"
|
|
19
|
-
"esm-shims.js"
|
|
19
|
+
"dist"
|
|
20
20
|
],
|
|
21
|
-
"main": "./dist/index.
|
|
22
|
-
"module": "./dist/index.
|
|
23
|
-
"types": "./dist/index.d.
|
|
21
|
+
"main": "./dist/index.mjs",
|
|
22
|
+
"module": "./dist/index.mjs",
|
|
23
|
+
"types": "./dist/index.d.mts",
|
|
24
24
|
"exports": {
|
|
25
|
-
".": "./dist/index.
|
|
26
|
-
"./run": "./dist/run.
|
|
25
|
+
".": "./dist/index.mjs",
|
|
26
|
+
"./run": "./dist/run.mjs",
|
|
27
27
|
"./package.json": "./package.json"
|
|
28
28
|
},
|
|
29
29
|
"typesVersions": {
|
|
@@ -35,56 +35,19 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"bin": {
|
|
38
|
-
"create-tsdown": "./dist/run.
|
|
38
|
+
"create-tsdown": "./dist/run.mjs"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"peerDependencies": {
|
|
44
|
-
"typescript": "^5.0.0"
|
|
45
|
-
},
|
|
46
|
-
"peerDependenciesMeta": {
|
|
47
|
-
"typescript": {
|
|
48
|
-
"optional": true
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
43
|
"dependencies": {
|
|
52
44
|
"@clack/prompts": "^0.11.0",
|
|
53
|
-
"ansis": "^4.2.0",
|
|
54
45
|
"cac": "^6.7.14",
|
|
55
|
-
"debug": "^4.4.3",
|
|
56
|
-
"diff": "^8.0.2",
|
|
57
46
|
"giget": "^2.0.0",
|
|
58
|
-
"
|
|
59
|
-
},
|
|
60
|
-
"devDependencies": {
|
|
61
|
-
"@oxc-node/core": "^0.0.32",
|
|
62
|
-
"@sxzz/eslint-config": "^7.2.7",
|
|
63
|
-
"@sxzz/prettier-config": "^2.2.4",
|
|
64
|
-
"@sxzz/test-utils": "^0.5.11",
|
|
65
|
-
"@types/debug": "^4.1.12",
|
|
66
|
-
"@types/node": "^24.7.2",
|
|
67
|
-
"bumpp": "^10.3.1",
|
|
68
|
-
"eslint": "^9.37.0",
|
|
69
|
-
"prettier": "^3.6.2",
|
|
70
|
-
"tsdown": "^0.15.6",
|
|
71
|
-
"typescript": "^5.9.3",
|
|
72
|
-
"unplugin-unused": "^0.5.4",
|
|
73
|
-
"vitest": "^3.2.4"
|
|
47
|
+
"package-manager-detector": "^1.4.0"
|
|
74
48
|
},
|
|
75
49
|
"engines": {
|
|
76
|
-
"node": ">=
|
|
50
|
+
"node": ">=20.19.0"
|
|
77
51
|
},
|
|
78
|
-
"
|
|
79
|
-
"scripts": {
|
|
80
|
-
"lint": "eslint --cache --max-warnings 0 .",
|
|
81
|
-
"lint:fix": "pnpm run lint --fix",
|
|
82
|
-
"build": "tsdown",
|
|
83
|
-
"dev": "node --import @oxc-node/core/register ./src/run.ts",
|
|
84
|
-
"dev:migrate": "node --import @oxc-node/core/register ./src/run.ts migrate --dry-run",
|
|
85
|
-
"test": "vitest",
|
|
86
|
-
"typecheck": "tsc --noEmit",
|
|
87
|
-
"format": "prettier --cache --write .",
|
|
88
|
-
"release": "bumpp && pnpm publish"
|
|
89
|
-
}
|
|
52
|
+
"scripts": {}
|
|
90
53
|
}
|
package/README.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# create-tsdown [](https://npmjs.com/package/create-tsdown) [](https://npmjs.com/package/create-tsdown) [](https://github.com/gugustinette/create-tsdown/actions/workflows/unit-test.yml) [](https://stackblitz.com/github/rolldown/tsdown-starter-stackblitz)
|
|
2
|
-
|
|
3
|
-
**create-tsdown** is the cli tool to create a new project using [tsdown](https://tsdown.dev). It provides a simple and efficient way to set up a TypeScript project with all the necessary configurations and dependencies.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm create tsdown@latest
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Migrate from tsup
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npx create-tsdown@latest migrate
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Please make sure to commit your changes before migrating. For more details, see the [Migration Guide](https://tsdown.dev/guide/migrate-from-tsup).
|
|
18
|
-
|
|
19
|
-
## Sponsors
|
|
20
|
-
|
|
21
|
-
<p align="center">
|
|
22
|
-
<a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
|
|
23
|
-
<img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
|
|
24
|
-
</a>
|
|
25
|
-
</p>
|
|
26
|
-
|
|
27
|
-
## Licenses
|
|
28
|
-
|
|
29
|
-
This project is licensed under the [MIT License](LICENSE).
|
package/dist/index.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
//#region src/utils/types.d.ts
|
|
2
|
-
type Overwrite<T, U> = Omit<T, keyof U> & U;
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/options/types.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Options for tsdown.
|
|
7
|
-
*/
|
|
8
|
-
interface Options {
|
|
9
|
-
/**
|
|
10
|
-
* The name of the package.
|
|
11
|
-
* @default 'my-package'
|
|
12
|
-
*/
|
|
13
|
-
name?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The template to use.
|
|
16
|
-
* @default 'default'
|
|
17
|
-
*/
|
|
18
|
-
template?: "default" | "minimal" | "vue" | "react" | "solid";
|
|
19
|
-
/** @default false */
|
|
20
|
-
silent?: boolean;
|
|
21
|
-
/** @default false */
|
|
22
|
-
debug?: boolean;
|
|
23
|
-
}
|
|
24
|
-
type ResolvedOptions = Overwrite<Options, {
|
|
25
|
-
/**
|
|
26
|
-
* The name of the package.
|
|
27
|
-
* @default 'my-package'
|
|
28
|
-
*/
|
|
29
|
-
name: string;
|
|
30
|
-
/**
|
|
31
|
-
* The template to use.
|
|
32
|
-
* @default 'default'
|
|
33
|
-
*/
|
|
34
|
-
template: "default" | "minimal" | "vue" | "react" | "solid";
|
|
35
|
-
/** @default false */
|
|
36
|
-
silent: boolean;
|
|
37
|
-
/** @default false */
|
|
38
|
-
debug: boolean;
|
|
39
|
-
}>;
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/index.d.ts
|
|
42
|
-
/**
|
|
43
|
-
* Create a tsdown project.
|
|
44
|
-
*/
|
|
45
|
-
declare function create(options: ResolvedOptions): Promise<void>;
|
|
46
|
-
//#endregion
|
|
47
|
-
export { create };
|
package/dist/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { logger } from "./logger-0-2qD2tL.js";
|
|
2
|
-
import { downloadTemplate } from "giget";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
-
import { basename, resolve } from "node:path";
|
|
6
|
-
import process from "node:process";
|
|
7
|
-
|
|
8
|
-
//#region src/utils/update-package-name.ts
|
|
9
|
-
/**
|
|
10
|
-
* Update the package name in the package.json file to match the target directory name.
|
|
11
|
-
* @param targetDir The target directory where the package.json file is located.
|
|
12
|
-
* @returns {Promise<void>}
|
|
13
|
-
*/
|
|
14
|
-
async function updatePackageName(targetDir) {
|
|
15
|
-
const resolvedDir = resolve(process.cwd(), targetDir);
|
|
16
|
-
const packageJsonPath = resolve(resolvedDir, "package.json");
|
|
17
|
-
if (!existsSync(packageJsonPath)) return;
|
|
18
|
-
const pkgRaw = await readFile(packageJsonPath, "utf8");
|
|
19
|
-
let pkg;
|
|
20
|
-
try {
|
|
21
|
-
pkg = JSON.parse(pkgRaw);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
logger.warn("Failed to parse package.json to update name.", error);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const packageName = basename(resolvedDir);
|
|
27
|
-
if (pkg.name === packageName) return;
|
|
28
|
-
pkg.name = packageName;
|
|
29
|
-
await writeFile(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
//#region src/index.ts
|
|
34
|
-
/**
|
|
35
|
-
* Create a tsdown project.
|
|
36
|
-
*/
|
|
37
|
-
async function create(options) {
|
|
38
|
-
if (typeof options.silent === "boolean") logger.setSilent(options.silent);
|
|
39
|
-
await downloadTemplate(`gh:gugustinette/create-tsdown/templates/${options.template}`, { dir: options.name });
|
|
40
|
-
await updatePackageName(options.name);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
export { create };
|
package/dist/logger-0-2qD2tL.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { bgRed, bgYellow, blue, green } from "ansis";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/general.ts
|
|
4
|
-
function toArray(val, defaultValue) {
|
|
5
|
-
if (Array.isArray(val)) return val;
|
|
6
|
-
else if (val == null) {
|
|
7
|
-
if (defaultValue) return [defaultValue];
|
|
8
|
-
return [];
|
|
9
|
-
} else return [val];
|
|
10
|
-
}
|
|
11
|
-
function resolveComma(arr) {
|
|
12
|
-
return arr.flatMap((format) => format.split(","));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/utils/logger.ts
|
|
17
|
-
var Logger = class {
|
|
18
|
-
silent = false;
|
|
19
|
-
setSilent(value) {
|
|
20
|
-
this.silent = value;
|
|
21
|
-
}
|
|
22
|
-
filter(...args) {
|
|
23
|
-
return args.filter((arg) => arg !== void 0 && arg !== false);
|
|
24
|
-
}
|
|
25
|
-
info(...args) {
|
|
26
|
-
if (!this.silent) console.info(blue`ℹ`, ...this.filter(...args));
|
|
27
|
-
}
|
|
28
|
-
warn(...args) {
|
|
29
|
-
if (!this.silent) console.warn("\n", bgYellow` WARN `, ...this.filter(...args), "\n");
|
|
30
|
-
}
|
|
31
|
-
error(...args) {
|
|
32
|
-
if (!this.silent) console.error("\n", bgRed` ERROR `, ...this.filter(...args), "\n");
|
|
33
|
-
}
|
|
34
|
-
success(...args) {
|
|
35
|
-
if (!this.silent) console.info(green`✔`, ...this.filter(...args));
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const logger = new Logger();
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
export { logger, resolveComma, toArray };
|
package/dist/migrate-Bkv2YVUc.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { logger } from "./logger-0-2qD2tL.js";
|
|
2
|
-
import { version } from "./package-CMEcUNLd.js";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
5
|
-
import process from "node:process";
|
|
6
|
-
|
|
7
|
-
//#region src/migrate.ts
|
|
8
|
-
async function migrate({ cwd, dryRun }) {
|
|
9
|
-
if (dryRun) logger.info("Dry run enabled. No changes were made.");
|
|
10
|
-
if (cwd) process.chdir(cwd);
|
|
11
|
-
await migratePackageJson(dryRun);
|
|
12
|
-
await migrateTsupConfig(dryRun);
|
|
13
|
-
}
|
|
14
|
-
async function migratePackageJson(dryRun) {
|
|
15
|
-
if (!existsSync("package.json")) {
|
|
16
|
-
logger.error("No package.json found");
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
const pkgRaw = await readFile("package.json", "utf8");
|
|
20
|
-
let pkg = JSON.parse(pkgRaw);
|
|
21
|
-
const semver = `^${version}`;
|
|
22
|
-
let found = false;
|
|
23
|
-
if (pkg.dependencies?.tsup) {
|
|
24
|
-
logger.info("Migrating `dependencies` to tsdown.");
|
|
25
|
-
found = true;
|
|
26
|
-
pkg.dependencies = renameKey(pkg.dependencies, "tsup", "tsdown", semver);
|
|
27
|
-
}
|
|
28
|
-
if (pkg.devDependencies?.tsup) {
|
|
29
|
-
logger.info("Migrating `devDependencies` to tsdown.");
|
|
30
|
-
found = true;
|
|
31
|
-
pkg.devDependencies = renameKey(pkg.devDependencies, "tsup", "tsdown", semver);
|
|
32
|
-
}
|
|
33
|
-
if (pkg.peerDependencies?.tsup) {
|
|
34
|
-
logger.info("Migrating `peerDependencies` to tsdown.");
|
|
35
|
-
found = true;
|
|
36
|
-
pkg.peerDependencies = renameKey(pkg.peerDependencies, "tsup", "tsdown", "*");
|
|
37
|
-
}
|
|
38
|
-
if (pkg.scripts) {
|
|
39
|
-
for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
|
|
40
|
-
logger.info(`Migrating \`${key}\` script to tsdown`);
|
|
41
|
-
found = true;
|
|
42
|
-
pkg.scripts[key] = pkg.scripts[key].replaceAll(/tsup(?:-node)?/g, "tsdown");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (pkg.tsup) {
|
|
46
|
-
logger.info("Migrating `tsup` field in package.json to `tsdown`.");
|
|
47
|
-
found = true;
|
|
48
|
-
pkg = renameKey(pkg, "tsup", "tsdown");
|
|
49
|
-
}
|
|
50
|
-
if (!found) {
|
|
51
|
-
logger.warn("No tsup-related fields found in package.json");
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
const pkgStr = `${JSON.stringify(pkg, null, 2)}\n`;
|
|
55
|
-
if (dryRun) {
|
|
56
|
-
const { createPatch } = await import("diff");
|
|
57
|
-
logger.info("[dry-run] package.json:");
|
|
58
|
-
console.info(createPatch("package.json", pkgRaw, pkgStr));
|
|
59
|
-
} else {
|
|
60
|
-
await writeFile("package.json", pkgStr);
|
|
61
|
-
logger.success("Migrated `package.json`");
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
const TSUP_FILES = [
|
|
66
|
-
"tsup.config.ts",
|
|
67
|
-
"tsup.config.cts",
|
|
68
|
-
"tsup.config.mts",
|
|
69
|
-
"tsup.config.js",
|
|
70
|
-
"tsup.config.cjs",
|
|
71
|
-
"tsup.config.mjs",
|
|
72
|
-
"tsup.config.json"
|
|
73
|
-
];
|
|
74
|
-
async function migrateTsupConfig(dryRun) {
|
|
75
|
-
let found = false;
|
|
76
|
-
for (const file of TSUP_FILES) {
|
|
77
|
-
if (!existsSync(file)) continue;
|
|
78
|
-
logger.info(`Found \`${file}\``);
|
|
79
|
-
found = true;
|
|
80
|
-
const tsupConfigRaw = await readFile(file, "utf8");
|
|
81
|
-
const tsupConfig = tsupConfigRaw.replaceAll(/\btsup\b/g, "tsdown").replaceAll(/\bTSUP\b/g, "TSDOWN");
|
|
82
|
-
const renamed = file.replaceAll("tsup", "tsdown");
|
|
83
|
-
if (dryRun) {
|
|
84
|
-
const { createTwoFilesPatch } = await import("diff");
|
|
85
|
-
logger.info(`[dry-run] ${file} -> ${renamed}:`);
|
|
86
|
-
console.info(createTwoFilesPatch(file, renamed, tsupConfigRaw, tsupConfig));
|
|
87
|
-
} else {
|
|
88
|
-
await writeFile(renamed, tsupConfig, "utf8");
|
|
89
|
-
await unlink(file);
|
|
90
|
-
logger.success(`Migrated \`${file}\` to \`${renamed}\``);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (!found) logger.warn("No tsup config found");
|
|
94
|
-
return found;
|
|
95
|
-
}
|
|
96
|
-
function renameKey(obj, oldKey, newKey, newValue) {
|
|
97
|
-
const newObj = {};
|
|
98
|
-
for (const key of Object.keys(obj)) if (key === oldKey) newObj[newKey] = newValue || obj[oldKey];
|
|
99
|
-
else newObj[key] = obj[key];
|
|
100
|
-
return newObj;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
export { migrate };
|
package/dist/package-CMEcUNLd.js
DELETED
package/dist/run.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { logger, resolveComma, toArray } from "./logger-0-2qD2tL.js";
|
|
3
|
-
import { version } from "./package-CMEcUNLd.js";
|
|
4
|
-
import module from "node:module";
|
|
5
|
-
import { green, underline } from "ansis";
|
|
6
|
-
import process$1 from "node:process";
|
|
7
|
-
import { cancel, confirm, intro, isCancel, outro, select, spinner, text } from "@clack/prompts";
|
|
8
|
-
import { cac } from "cac";
|
|
9
|
-
import debug from "debug";
|
|
10
|
-
|
|
11
|
-
//#region src/options/index.ts
|
|
12
|
-
const debug$1 = debug("create-tsdown:options");
|
|
13
|
-
/**
|
|
14
|
-
* Resolve the user options and configs
|
|
15
|
-
* @param options The user options
|
|
16
|
-
* @returns The resolved options
|
|
17
|
-
*/
|
|
18
|
-
async function resolveOptions(options) {
|
|
19
|
-
debug$1("options %O", options);
|
|
20
|
-
let resolvedName;
|
|
21
|
-
if (options.name === void 0) resolvedName = await text({
|
|
22
|
-
message: "What is the name of your package?",
|
|
23
|
-
placeholder: "./my-package",
|
|
24
|
-
initialValue: "./my-package"
|
|
25
|
-
});
|
|
26
|
-
else resolvedName = options.name;
|
|
27
|
-
if (isCancel(resolvedName)) {
|
|
28
|
-
cancel("Operation cancelled.");
|
|
29
|
-
process.exit(0);
|
|
30
|
-
}
|
|
31
|
-
let resolvedTemplate;
|
|
32
|
-
if (options.template === void 0) resolvedTemplate = await select({
|
|
33
|
-
message: "Which template do you want to use?",
|
|
34
|
-
options: [
|
|
35
|
-
{
|
|
36
|
-
value: "default",
|
|
37
|
-
label: "Default"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
value: "minimal",
|
|
41
|
-
label: "Minimal"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
value: "vue",
|
|
45
|
-
label: "Vue"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
value: "react",
|
|
49
|
-
label: "React"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
value: "solid",
|
|
53
|
-
label: "Solid"
|
|
54
|
-
}
|
|
55
|
-
],
|
|
56
|
-
initialValue: "default"
|
|
57
|
-
});
|
|
58
|
-
else {
|
|
59
|
-
resolvedTemplate = options.template;
|
|
60
|
-
if (![
|
|
61
|
-
"default",
|
|
62
|
-
"minimal",
|
|
63
|
-
"vue",
|
|
64
|
-
"react",
|
|
65
|
-
"solid"
|
|
66
|
-
].includes(resolvedTemplate)) throw new Error(`Invalid template "${resolvedTemplate}". Available templates: default, vue, react, solid`);
|
|
67
|
-
}
|
|
68
|
-
if (isCancel(resolvedTemplate)) {
|
|
69
|
-
cancel("Operation cancelled.");
|
|
70
|
-
process.exit(0);
|
|
71
|
-
}
|
|
72
|
-
const resolvedOptions = {
|
|
73
|
-
name: resolvedName,
|
|
74
|
-
template: resolvedTemplate,
|
|
75
|
-
silent: !!options.silent,
|
|
76
|
-
debug: !!options.debug
|
|
77
|
-
};
|
|
78
|
-
debug$1("resolved configs %O", resolvedOptions);
|
|
79
|
-
return resolvedOptions;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/utils/package-manager.ts
|
|
84
|
-
const PACKAGE_MANAGERS = [
|
|
85
|
-
"npm",
|
|
86
|
-
"pnpm",
|
|
87
|
-
"yarn",
|
|
88
|
-
"bun",
|
|
89
|
-
"deno"
|
|
90
|
-
];
|
|
91
|
-
function detectPackageManager() {
|
|
92
|
-
const userAgent = process$1.env.npm_config_user_agent?.toLowerCase();
|
|
93
|
-
if (!userAgent) return "npm";
|
|
94
|
-
const [name] = userAgent.split(" ");
|
|
95
|
-
const manager = name?.split("/")[0];
|
|
96
|
-
return PACKAGE_MANAGERS.includes(manager) ? manager : "npm";
|
|
97
|
-
}
|
|
98
|
-
function getPackageManagerCommands() {
|
|
99
|
-
switch (detectPackageManager()) {
|
|
100
|
-
case "pnpm": return {
|
|
101
|
-
install: "pnpm i",
|
|
102
|
-
build: "pnpm build"
|
|
103
|
-
};
|
|
104
|
-
case "yarn": return {
|
|
105
|
-
install: "yarn",
|
|
106
|
-
build: "yarn build"
|
|
107
|
-
};
|
|
108
|
-
case "bun": return {
|
|
109
|
-
install: "bun install",
|
|
110
|
-
build: "bun run build"
|
|
111
|
-
};
|
|
112
|
-
case "deno": return {
|
|
113
|
-
install: "deno install",
|
|
114
|
-
build: "deno task build"
|
|
115
|
-
};
|
|
116
|
-
default: return {
|
|
117
|
-
install: "npm i",
|
|
118
|
-
build: "npm run build"
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/cli.ts
|
|
125
|
-
const cli = cac("create-tsdown");
|
|
126
|
-
cli.help().version(version);
|
|
127
|
-
cli.command("[...files]", "Create a tsdown project", {
|
|
128
|
-
ignoreOptionDefaultValue: true,
|
|
129
|
-
allowUnknownOptions: true
|
|
130
|
-
}).option("-n, --name <name>", "Name of the package to create", { default: "./my-package" }).option("-t, --template <template>", "Available templates: default, vue, react, solid", { default: "default" }).option("--debug", "Show debug logs").option("--silent", "Suppress non-error logs").action(async (input, options) => {
|
|
131
|
-
intro(`tsdown - The Elegant Library Bundler`);
|
|
132
|
-
logger.setSilent(!!options.silent);
|
|
133
|
-
const resolvedOptions = await resolveOptions(options);
|
|
134
|
-
const s = spinner();
|
|
135
|
-
s.start("Cloning the template...");
|
|
136
|
-
const { create } = await import("./index.js");
|
|
137
|
-
if (input.length > 0) options.name = input[0];
|
|
138
|
-
await create(resolvedOptions);
|
|
139
|
-
s.stop("Template cloned");
|
|
140
|
-
const { install: installCommand, build: buildCommand } = getPackageManagerCommands();
|
|
141
|
-
outro(`Done! Now run:\n ${green`cd ${resolvedOptions.name}`}\n ${green(String(installCommand))}\n ${green(String(buildCommand))}\n\nFor more information, visit: ${underline`https://tsdown.dev/`}`);
|
|
142
|
-
});
|
|
143
|
-
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
144
|
-
intro(`Starting migration from tsup to tsdown`);
|
|
145
|
-
const shouldContinue = await confirm({ message: `Before proceeding, review the migration guide at ${underline`https://tsdown.dev/guide/migrate-from-tsup`}, as this process will modify your files.\nUncommitted changes will be lost. Use the ${green`--dry-run`} flag to preview changes without applying them.` });
|
|
146
|
-
if (isCancel(shouldContinue)) {
|
|
147
|
-
cancel("Migration cancelled.");
|
|
148
|
-
process$1.exit(0);
|
|
149
|
-
}
|
|
150
|
-
if (!shouldContinue) {
|
|
151
|
-
outro("Migration cancelled.");
|
|
152
|
-
process$1.exit(0);
|
|
153
|
-
}
|
|
154
|
-
const s = spinner();
|
|
155
|
-
s.start("Migrating from tsup to tsdown...");
|
|
156
|
-
const { migrate } = await import("./migrate-Bkv2YVUc.js");
|
|
157
|
-
await migrate({
|
|
158
|
-
cwd: args.cwd,
|
|
159
|
-
dryRun: !!args.dryRun
|
|
160
|
-
});
|
|
161
|
-
s.stop();
|
|
162
|
-
outro(`Migration completed!`);
|
|
163
|
-
});
|
|
164
|
-
async function runCLI() {
|
|
165
|
-
cli.parse(process$1.argv, { run: false });
|
|
166
|
-
if (cli.options.debug) {
|
|
167
|
-
let namespace;
|
|
168
|
-
if (cli.options.debug === true) namespace = "tsdown:*";
|
|
169
|
-
else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
|
|
170
|
-
const enabled = debug.disable();
|
|
171
|
-
if (enabled) namespace += `,${enabled}`;
|
|
172
|
-
debug.enable(namespace);
|
|
173
|
-
debug("tsdown:debug")("Debugging enabled", namespace);
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
await cli.runMatchedCommand();
|
|
177
|
-
} catch (error) {
|
|
178
|
-
logger.error(error);
|
|
179
|
-
process$1.exit(1);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
//#endregion
|
|
184
|
-
//#region src/run.ts
|
|
185
|
-
try {
|
|
186
|
-
module.enableCompileCache?.();
|
|
187
|
-
} catch {}
|
|
188
|
-
runCLI();
|
|
189
|
-
|
|
190
|
-
//#endregion
|
|
191
|
-
export { };
|
|
File without changes
|