create-tsdown 0.0.2 → 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/README.md CHANGED
@@ -1,17 +1,17 @@
1
- # create-tsdown [![npm](https://img.shields.io/npm/v/create-tsdown.svg)](https://npmjs.com/package/create-tsdown) [![Unit Test](https://github.com/rolldown/tsdown/actions/workflows/tests.yml/badge.svg)](https://github.com/gugustinette/create-tsdown/actions/workflows/tests.yml) [![tsdown-starter-stackblitz](https://developer.stackblitz.com/img/open_in_stackblitz_small.svg)](https://stackblitz.com/github/rolldown/tsdown-starter-stackblitz)
1
+ # create-tsdown [![npm](https://img.shields.io/npm/v/create-tsdown.svg)](https://npmjs.com/package/create-tsdown) [![downloads](https://img.shields.io/npm/dm/create-tsdown.svg)](https://npmjs.com/package/create-tsdown) [![Unit Test](https://github.com/gugustinette/create-tsdown/actions/workflows/unit-test.yml/badge.svg)](https://github.com/gugustinette/create-tsdown/actions/workflows/unit-test.yml) [![tsdown-starter-stackblitz](https://developer.stackblitz.com/img/open_in_stackblitz_small.svg)](https://stackblitz.com/github/rolldown/tsdown-starter-stackblitz)
2
2
 
3
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
4
 
5
5
  ## Usage
6
6
 
7
7
  ```bash
8
- npm create tsdown
8
+ npm create tsdown@latest
9
9
  ```
10
10
 
11
11
  ## Migrate from tsup
12
12
 
13
13
  ```bash
14
- npx create-tsdown migrate
14
+ npx create-tsdown@latest migrate
15
15
  ```
16
16
 
17
17
  Please make sure to commit your changes before migrating. For more details, see the [Migration Guide](https://tsdown.dev/guide/migrate-from-tsup).
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  //#region src/utils/types.d.ts
2
2
  type Overwrite<T, U> = Omit<T, keyof U> & U;
3
-
4
3
  //#endregion
5
4
  //#region src/options/types.d.ts
6
5
  /**
@@ -16,7 +15,7 @@ interface Options {
16
15
  * The template to use.
17
16
  * @default 'default'
18
17
  */
19
- template?: "default" | "minimal" | "vue" | "react";
18
+ template?: "default" | "minimal" | "vue" | "react" | "solid";
20
19
  /** @default false */
21
20
  silent?: boolean;
22
21
  /** @default false */
@@ -32,17 +31,17 @@ type ResolvedOptions = Overwrite<Options, {
32
31
  * The template to use.
33
32
  * @default 'default'
34
33
  */
35
- template: "default" | "minimal" | "vue" | "react";
34
+ template: "default" | "minimal" | "vue" | "react" | "solid";
36
35
  /** @default false */
37
36
  silent: boolean;
38
37
  /** @default false */
39
38
  debug: boolean;
40
- }>; //#endregion
39
+ }>;
40
+ //#endregion
41
41
  //#region src/index.d.ts
42
42
  /**
43
43
  * Create a tsdown project.
44
44
  */
45
45
  declare function create(options: ResolvedOptions): Promise<void>;
46
-
47
46
  //#endregion
48
47
  export { create };
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-Cz8SzpOI.js";
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", "utf-8");
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, "utf-8");
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) {
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.0.4";
3
+
4
+ //#endregion
5
+ export { version };
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-Cz8SzpOI.js";
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,26 +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 !== void 0) resolvedName = 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 !== void 0) {
33
- resolvedTemplate = options.template;
34
- if (![
35
- "default",
36
- "minimal",
37
- "vue",
38
- "react"
39
- ].includes(resolvedTemplate)) throw new Error(`Invalid template "${resolvedTemplate}". Available templates: default, vue, react`);
40
- } else resolvedTemplate = await select({
32
+ if (options.template === void 0) resolvedTemplate = await select({
41
33
  message: "Which template do you want to use?",
42
34
  options: [
43
35
  {
@@ -55,10 +47,24 @@ async function resolveOptions(options) {
55
47
  {
56
48
  value: "react",
57
49
  label: "React"
50
+ },
51
+ {
52
+ value: "solid",
53
+ label: "Solid"
58
54
  }
59
55
  ],
60
56
  initialValue: "default"
61
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
+ }
62
68
  if (isCancel(resolvedTemplate)) {
63
69
  cancel("Operation cancelled.");
64
70
  process.exit(0);
@@ -73,6 +79,47 @@ async function resolveOptions(options) {
73
79
  return resolvedOptions;
74
80
  }
75
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
+
76
123
  //#endregion
77
124
  //#region src/cli.ts
78
125
  const cli = cac("create-tsdown");
@@ -80,7 +127,7 @@ cli.help().version(version);
80
127
  cli.command("[...files]", "Create a tsdown project", {
81
128
  ignoreOptionDefaultValue: true,
82
129
  allowUnknownOptions: true
83
- }).option("-n, --name <name>", "Name of the package to create", { default: "./my-package" }).option("-t, --template <template>", "Available templates: default, vue, react", { default: "default" }).option("--debug", "Show debug logs").option("--silent", "Suppress non-error logs").action(async (input, options) => {
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) => {
84
131
  intro(`tsdown - The Elegant Library Bundler`);
85
132
  logger.setSilent(!!options.silent);
86
133
  const resolvedOptions = await resolveOptions(options);
@@ -90,7 +137,8 @@ cli.command("[...files]", "Create a tsdown project", {
90
137
  if (input.length > 0) options.name = input[0];
91
138
  await create(resolvedOptions);
92
139
  s.stop("Template cloned");
93
- outro(`Done! Now run:\n ${green`cd ${resolvedOptions.name}`}\n ${green`npm install`}\n ${green`npm run build`}\n\nFor more information, visit: ${underline`https://tsdown.dev/`}`);
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/`}`);
94
142
  });
95
143
  cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
96
144
  intro(`Starting migration from tsup to tsdown`);
@@ -105,7 +153,7 @@ cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>",
105
153
  }
106
154
  const s = spinner();
107
155
  s.start("Migrating from tsup to tsdown...");
108
- const { migrate } = await import("./migrate-B3JazpZr.js");
156
+ const { migrate } = await import("./migrate-Bkv2YVUc.js");
109
157
  await migrate({
110
158
  cwd: args.cwd,
111
159
  dryRun: !!args.dryRun
@@ -139,4 +187,5 @@ try {
139
187
  } catch {}
140
188
  runCLI();
141
189
 
142
- //#endregion
190
+ //#endregion
191
+ export { };
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "create-tsdown",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "homepage": "https://github.com/gugustinette/create-tsdown#readme",
7
+ "homepage": "https://github.com/Gugustinette/create-tsdown#readme",
8
8
  "bugs": {
9
- "url": "https://github.com/gugustinette/create-tsdown/issues"
9
+ "url": "https://github.com/Gugustinette/create-tsdown/issues"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/gugustinette/create-tsdown.git"
13
+ "url": "git+https://github.com/Gugustinette/create-tsdown.git"
14
14
  },
15
15
  "author": "三咲智子 Kevin Deng <sxzz@sxzz.moe>",
16
16
  "funding": "https://github.com/sponsors/sxzz",
@@ -50,27 +50,27 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@clack/prompts": "^0.11.0",
53
- "ansis": "^4.0.0",
53
+ "ansis": "^4.2.0",
54
54
  "cac": "^6.7.14",
55
- "debug": "^4.4.1",
56
- "diff": "^8.0.1",
55
+ "debug": "^4.4.3",
56
+ "diff": "^8.0.2",
57
57
  "giget": "^2.0.0",
58
- "rolldown": "1.0.0-beta.9-commit.51df2b7"
58
+ "rolldown": "1.0.0-beta.43"
59
59
  },
60
60
  "devDependencies": {
61
- "@oxc-node/core": "^0.0.27",
62
- "@sxzz/eslint-config": "^7.0.1",
63
- "@sxzz/prettier-config": "^2.2.1",
64
- "@sxzz/test-utils": "^0.5.6",
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": "^22.15.21",
67
- "bumpp": "^10.1.1",
68
- "eslint": "^9.27.0",
69
- "prettier": "^3.5.3",
70
- "tsdown": "^0.12.2",
71
- "typescript": "~5.8.3",
72
- "unplugin-unused": "^0.5.0",
73
- "vitest": "^3.1.4"
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"
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.0.2";
3
-
4
- //#endregion
5
- export { version };
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()