@tsdown/exe 0.21.0-beta.5 → 0.21.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/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Logger } from "tsdown/internal";
2
+
1
3
  //#region src/platform.d.ts
2
4
  type ExePlatform = "win" | "darwin" | "linux";
3
5
  type ExeArch = "x64" | "arm64";
@@ -5,10 +7,15 @@ interface ExeTarget {
5
7
  platform: ExePlatform;
6
8
  arch: ExeArch;
7
9
  /**
8
- * Node.js version to use for the executable. Should be a valid Node.js version string (e.g., "25.7.0").
10
+ * Node.js version to use for the executable.
11
+ *
12
+ * Accepts a valid semver string (e.g., `"25.7.0"`), or the special values
13
+ * `"latest"` / `"latest-lts"` which resolve the version automatically from
14
+ * {@link https://nodejs.org/dist/index.json}.
15
+ *
9
16
  * The minimum required version is 25.7.0, which is when SEA support was added to Node.js.
10
17
  */
11
- nodeVersion: string;
18
+ nodeVersion: (string & {}) | "latest" | "latest-lts" | `${string}.${string}.${string}`;
12
19
  }
13
20
  interface ExeExtensionOptions {
14
21
  /**
@@ -34,9 +41,6 @@ declare function getCacheDir(): string;
34
41
  declare function getCachedBinaryPath(target: ExeTarget): string;
35
42
  //#endregion
36
43
  //#region src/download.d.ts
37
- interface MinimalLogger {
38
- info: (...args: any[]) => void;
39
- }
40
- declare function resolveNodeBinary(target: ExeTarget, logger?: MinimalLogger): Promise<string>;
44
+ declare function resolveNodeBinary(target: ExeTarget, logger?: Logger): Promise<string>;
41
45
  //#endregion
42
46
  export { type ExeArch, type ExeExtensionOptions, type ExePlatform, type ExeTarget, getCacheDir, getCachedBinaryPath, getTargetSuffix, resolveNodeBinary };
package/dist/index.mjs CHANGED
@@ -2,12 +2,12 @@ import os from "node:os";
2
2
  import path from "node:path";
3
3
  import process from "node:process";
4
4
  import { Buffer } from "node:buffer";
5
- import { access, chmod, mkdir, rename, rm, writeFile } from "node:fs/promises";
5
+ import { chmod, mkdir, rename, writeFile } from "node:fs/promises";
6
6
  import { createDebug } from "obug";
7
7
  import { x } from "tinyexec";
8
- import semver from "semver";
8
+ import { fsExists, fsRemove } from "tsdown/internal";
9
9
  import satisfies from "semver/functions/satisfies.js";
10
-
10
+ import valid from "semver/functions/valid.js";
11
11
  //#region src/cache.ts
12
12
  function getCacheDir() {
13
13
  const home = os.homedir();
@@ -24,19 +24,6 @@ function getCachedBinaryPath(target) {
24
24
  const binName = target.platform === "win" ? "node.exe" : "node";
25
25
  return path.join(cacheDir, "node", `v${target.nodeVersion}`, `${target.platform}-${target.arch}`, binName);
26
26
  }
27
-
28
- //#endregion
29
- //#region ../../src/utils/fs.ts
30
- function fsExists(path) {
31
- return access(path).then(() => true, () => false);
32
- }
33
- function fsRemove(path) {
34
- return rm(path, {
35
- force: true,
36
- recursive: true
37
- }).catch(() => {});
38
- }
39
-
40
27
  //#endregion
41
28
  //#region src/platform.ts
42
29
  function getArchiveExtension(platform) {
@@ -54,22 +41,30 @@ function getBinaryPathInArchive(target) {
54
41
  if (platform === "win") return `${dirName}/node.exe`;
55
42
  return `${dirName}/bin/node`;
56
43
  }
57
- function normalizeNodeVersion(target) {
58
- const version = semver.valid(target.nodeVersion);
59
- if (!version) throw new Error(`Invalid Node.js version: ${target.nodeVersion}. Please provide a valid version string (e.g., "25.7.0").`);
44
+ const NODE_DIST_INDEX_URL = "https://nodejs.org/dist/index.json";
45
+ async function resolveNodeVersion(nodeVersion) {
46
+ if (nodeVersion === "latest" || nodeVersion === "latest-lts") {
47
+ const response = await fetch(NODE_DIST_INDEX_URL);
48
+ if (!response.ok) throw new Error(`Failed to fetch Node.js releases: HTTP ${response.status} from ${NODE_DIST_INDEX_URL}`);
49
+ const releases = await response.json();
50
+ const release = nodeVersion === "latest" ? releases[0] : releases.find((r) => r.lts !== false);
51
+ if (!release) throw new Error(`No matching Node.js release found for "${nodeVersion}".`);
52
+ nodeVersion = release.version.replace(/^v/, "");
53
+ }
54
+ const version = valid(nodeVersion);
55
+ if (!version) throw new Error(`Invalid Node.js version: ${nodeVersion}. Please provide a valid version string (e.g., "25.7.0").`);
60
56
  if (!satisfies(version, ">=25.7.0")) throw new Error(`Node.js ${version} does not support SEA (Single Executable Applications). Required minimum version is 25.7.0. Please update the nodeVersion in your target configuration.`);
61
57
  return version;
62
58
  }
63
59
  function getTargetSuffix(target) {
64
60
  return `-${target.platform}-${target.arch}`;
65
61
  }
66
-
67
62
  //#endregion
68
63
  //#region src/download.ts
69
64
  const debug = createDebug("tsdown:exe:download");
70
65
  async function resolveNodeBinary(target, logger) {
71
66
  debug("Resolving Node.js binary for target: %O", target);
72
- target.nodeVersion = normalizeNodeVersion(target);
67
+ target.nodeVersion = await resolveNodeVersion(target.nodeVersion);
73
68
  const cachedPath = getCachedBinaryPath(target);
74
69
  debug("Cache path: %s", cachedPath);
75
70
  if (await fsExists(cachedPath)) {
@@ -128,6 +123,5 @@ async function extractBinary(archivePath, targetBinaryPath, target) {
128
123
  const extractedPath = path.join(outDir, extractedName);
129
124
  if (extractedPath !== targetBinaryPath) await rename(extractedPath, targetBinaryPath);
130
125
  }
131
-
132
126
  //#endregion
133
- export { getCacheDir, getCachedBinaryPath, getTargetSuffix, resolveNodeBinary };
127
+ export { getCacheDir, getCachedBinaryPath, getTargetSuffix, resolveNodeBinary };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsdown/exe",
3
3
  "type": "module",
4
- "version": "0.21.0-beta.5",
4
+ "version": "0.21.1",
5
5
  "description": "Cross-platform executable building for tsdown",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -37,12 +37,15 @@
37
37
  "engines": {
38
38
  "node": ">=20.19.0"
39
39
  },
40
+ "peerDependencies": {
41
+ "tsdown": "0.21.1"
42
+ },
40
43
  "dependencies": {
41
44
  "obug": "^2.1.1",
42
45
  "semver": "^7.7.4",
43
46
  "tinyexec": "^1.0.2"
44
47
  },
45
48
  "scripts": {
46
- "build": "unrun ../../src/run.ts -c ../../tsdown.config.ts -F ."
49
+ "build": "node -C dev ../../src/run.ts -c ../../tsdown.config.ts -F ."
47
50
  }
48
51
  }