create-tsdown 0.0.3 → 0.0.4
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/index.js +30 -0
- package/dist/{migrate-PAss8O89.js → migrate-Bkv2YVUc.js} +4 -4
- package/dist/package-CMEcUNLd.js +5 -0
- package/dist/run.js +60 -16
- package/package.json +17 -17
- package/dist/package-2m3xQSHC.js +0 -5
- package/esm-shims.js +0 -9
package/dist/index.js
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
import { logger } from "./logger-0-2qD2tL.js";
|
|
2
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";
|
|
3
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
|
|
4
33
|
//#region src/index.ts
|
|
5
34
|
/**
|
|
6
35
|
* Create a tsdown project.
|
|
@@ -8,6 +37,7 @@ import { downloadTemplate } from "giget";
|
|
|
8
37
|
async function create(options) {
|
|
9
38
|
if (typeof options.silent === "boolean") logger.setSilent(options.silent);
|
|
10
39
|
await downloadTemplate(`gh:gugustinette/create-tsdown/templates/${options.template}`, { dir: options.name });
|
|
40
|
+
await updatePackageName(options.name);
|
|
11
41
|
}
|
|
12
42
|
|
|
13
43
|
//#endregion
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { logger } from "./logger-0-2qD2tL.js";
|
|
2
|
-
import { version } from "./package-
|
|
3
|
-
import process from "node:process";
|
|
2
|
+
import { version } from "./package-CMEcUNLd.js";
|
|
4
3
|
import { existsSync } from "node:fs";
|
|
5
4
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
5
|
+
import process from "node:process";
|
|
6
6
|
|
|
7
7
|
//#region src/migrate.ts
|
|
8
8
|
async function migrate({ cwd, dryRun }) {
|
|
@@ -16,7 +16,7 @@ async function migratePackageJson(dryRun) {
|
|
|
16
16
|
logger.error("No package.json found");
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
|
-
const pkgRaw = await readFile("package.json", "
|
|
19
|
+
const pkgRaw = await readFile("package.json", "utf8");
|
|
20
20
|
let pkg = JSON.parse(pkgRaw);
|
|
21
21
|
const semver = `^${version}`;
|
|
22
22
|
let found = false;
|
|
@@ -77,7 +77,7 @@ async function migrateTsupConfig(dryRun) {
|
|
|
77
77
|
if (!existsSync(file)) continue;
|
|
78
78
|
logger.info(`Found \`${file}\``);
|
|
79
79
|
found = true;
|
|
80
|
-
const tsupConfigRaw = await readFile(file, "
|
|
80
|
+
const tsupConfigRaw = await readFile(file, "utf8");
|
|
81
81
|
const tsupConfig = tsupConfigRaw.replaceAll(/\btsup\b/g, "tsdown").replaceAll(/\bTSUP\b/g, "TSDOWN");
|
|
82
82
|
const renamed = file.replaceAll("tsup", "tsdown");
|
|
83
83
|
if (dryRun) {
|
package/dist/run.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { logger, resolveComma, toArray } from "./logger-0-2qD2tL.js";
|
|
3
|
-
import { version } from "./package-
|
|
3
|
+
import { version } from "./package-CMEcUNLd.js";
|
|
4
4
|
import module from "node:module";
|
|
5
5
|
import { green, underline } from "ansis";
|
|
6
6
|
import process$1 from "node:process";
|
|
@@ -18,27 +18,18 @@ const debug$1 = debug("create-tsdown:options");
|
|
|
18
18
|
async function resolveOptions(options) {
|
|
19
19
|
debug$1("options %O", options);
|
|
20
20
|
let resolvedName;
|
|
21
|
-
if (options.name
|
|
22
|
-
else resolvedName = await text({
|
|
21
|
+
if (options.name === void 0) resolvedName = await text({
|
|
23
22
|
message: "What is the name of your package?",
|
|
24
23
|
placeholder: "./my-package",
|
|
25
24
|
initialValue: "./my-package"
|
|
26
25
|
});
|
|
26
|
+
else resolvedName = options.name;
|
|
27
27
|
if (isCancel(resolvedName)) {
|
|
28
28
|
cancel("Operation cancelled.");
|
|
29
29
|
process.exit(0);
|
|
30
30
|
}
|
|
31
31
|
let resolvedTemplate;
|
|
32
|
-
if (options.template
|
|
33
|
-
resolvedTemplate = options.template;
|
|
34
|
-
if (![
|
|
35
|
-
"default",
|
|
36
|
-
"minimal",
|
|
37
|
-
"vue",
|
|
38
|
-
"react",
|
|
39
|
-
"solid"
|
|
40
|
-
].includes(resolvedTemplate)) throw new Error(`Invalid template "${resolvedTemplate}". Available templates: default, vue, react, solid`);
|
|
41
|
-
} else resolvedTemplate = await select({
|
|
32
|
+
if (options.template === void 0) resolvedTemplate = await select({
|
|
42
33
|
message: "Which template do you want to use?",
|
|
43
34
|
options: [
|
|
44
35
|
{
|
|
@@ -64,6 +55,16 @@ async function resolveOptions(options) {
|
|
|
64
55
|
],
|
|
65
56
|
initialValue: "default"
|
|
66
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
|
+
}
|
|
67
68
|
if (isCancel(resolvedTemplate)) {
|
|
68
69
|
cancel("Operation cancelled.");
|
|
69
70
|
process.exit(0);
|
|
@@ -78,6 +79,47 @@ async function resolveOptions(options) {
|
|
|
78
79
|
return resolvedOptions;
|
|
79
80
|
}
|
|
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
|
+
|
|
81
123
|
//#endregion
|
|
82
124
|
//#region src/cli.ts
|
|
83
125
|
const cli = cac("create-tsdown");
|
|
@@ -95,7 +137,8 @@ cli.command("[...files]", "Create a tsdown project", {
|
|
|
95
137
|
if (input.length > 0) options.name = input[0];
|
|
96
138
|
await create(resolvedOptions);
|
|
97
139
|
s.stop("Template cloned");
|
|
98
|
-
|
|
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/`}`);
|
|
99
142
|
});
|
|
100
143
|
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
101
144
|
intro(`Starting migration from tsup to tsdown`);
|
|
@@ -110,7 +153,7 @@ cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>",
|
|
|
110
153
|
}
|
|
111
154
|
const s = spinner();
|
|
112
155
|
s.start("Migrating from tsup to tsdown...");
|
|
113
|
-
const { migrate } = await import("./migrate-
|
|
156
|
+
const { migrate } = await import("./migrate-Bkv2YVUc.js");
|
|
114
157
|
await migrate({
|
|
115
158
|
cwd: args.cwd,
|
|
116
159
|
dryRun: !!args.dryRun
|
|
@@ -144,4 +187,5 @@ try {
|
|
|
144
187
|
} catch {}
|
|
145
188
|
runCLI();
|
|
146
189
|
|
|
147
|
-
//#endregion
|
|
190
|
+
//#endregion
|
|
191
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-tsdown",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,27 +50,27 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@clack/prompts": "^0.11.0",
|
|
53
|
-
"ansis": "^4.
|
|
53
|
+
"ansis": "^4.2.0",
|
|
54
54
|
"cac": "^6.7.14",
|
|
55
|
-
"debug": "^4.4.
|
|
56
|
-
"diff": "^8.0.
|
|
55
|
+
"debug": "^4.4.3",
|
|
56
|
+
"diff": "^8.0.2",
|
|
57
57
|
"giget": "^2.0.0",
|
|
58
|
-
"rolldown": "1.0.0-beta.
|
|
58
|
+
"rolldown": "1.0.0-beta.43"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@oxc-node/core": "^0.0.
|
|
62
|
-
"@sxzz/eslint-config": "^7.
|
|
63
|
-
"@sxzz/prettier-config": "^2.2.
|
|
64
|
-
"@sxzz/test-utils": "^0.5.
|
|
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
65
|
"@types/debug": "^4.1.12",
|
|
66
|
-
"@types/node": "^
|
|
67
|
-
"bumpp": "^10.
|
|
68
|
-
"eslint": "^9.
|
|
69
|
-
"prettier": "^3.
|
|
70
|
-
"tsdown": "^0.
|
|
71
|
-
"typescript": "
|
|
72
|
-
"unplugin-unused": "^0.5.
|
|
73
|
-
"vitest": "^3.
|
|
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"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=18.0.0"
|
package/dist/package-2m3xQSHC.js
DELETED
package/esm-shims.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Shim globals in esm bundle
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { fileURLToPath } from 'node:url'
|
|
4
|
-
|
|
5
|
-
const getFilename = () => fileURLToPath(import.meta.url)
|
|
6
|
-
const getDirname = () => path.dirname(getFilename())
|
|
7
|
-
|
|
8
|
-
export const __dirname = /* @__PURE__ */ getDirname()
|
|
9
|
-
export const __filename = /* @__PURE__ */ getFilename()
|