@longzai-intelligence-builder/exe 0.2.11 → 0.2.13

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.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -127
  2. package/package.json +7 -4
package/dist/index.mjs CHANGED
@@ -1,127 +1 @@
1
- import os from "node:os";
2
- import path from "node:path";
3
- import process from "node:process";
4
- import { Buffer } from "node:buffer";
5
- import { chmod, mkdir, rename, writeFile } from "node:fs/promises";
6
- import { createDebug } from "obug";
7
- import { x } from "tinyexec";
8
- import { fsExists, fsRemove } from "@longzai-intelligence-builder/core";
9
- import satisfies from "semver/functions/satisfies.js";
10
- import valid from "semver/functions/valid.js";
11
- //#region src/cache.ts
12
- function getCacheDir() {
13
- const home = os.homedir();
14
- if (process.platform === "win32") {
15
- const localAppData = process.env.LOCALAPPDATA || path.join(home, "AppData/Local");
16
- return path.join(localAppData, "lzi-builder/Caches");
17
- }
18
- if (process.platform === "darwin") return path.join(home, "Library/Caches/lzi-builder");
19
- const xdgCache = process.env.XDG_CACHE_HOME || path.join(home, ".cache");
20
- return path.join(xdgCache, "lzi-builder");
21
- }
22
- function getCachedBinaryPath(target) {
23
- const cacheDir = getCacheDir();
24
- const binName = target.platform === "win" ? "node.exe" : "node";
25
- return path.join(cacheDir, "node", `v${target.nodeVersion}`, `${target.platform}-${target.arch}`, binName);
26
- }
27
- //#endregion
28
- //#region src/platform.ts
29
- function getArchiveExtension(platform) {
30
- if (platform === "win") return "zip";
31
- if (platform === "linux") return "tar.xz";
32
- return "tar.gz";
33
- }
34
- function getDownloadUrl(target) {
35
- const { platform, arch, nodeVersion } = target;
36
- return `https://nodejs.org/dist/v${nodeVersion}/node-v${nodeVersion}-${platform}-${arch}.${getArchiveExtension(platform)}`;
37
- }
38
- function getBinaryPathInArchive(target) {
39
- const { platform, arch, nodeVersion } = target;
40
- const dirName = `node-v${nodeVersion}-${platform}-${arch}`;
41
- if (platform === "win") return `${dirName}/node.exe`;
42
- return `${dirName}/bin/node`;
43
- }
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").`);
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.`);
57
- return version;
58
- }
59
- function getTargetSuffix(target) {
60
- return `-${target.platform}-${target.arch}`;
61
- }
62
- //#endregion
63
- //#region src/download.ts
64
- const debug = createDebug("lzi-builder:exe:download");
65
- async function resolveNodeBinary(target, logger) {
66
- debug("Resolving Node.js binary for target: %O", target);
67
- target.nodeVersion = await resolveNodeVersion(target.nodeVersion);
68
- const cachedPath = getCachedBinaryPath(target);
69
- debug("Cache path: %s", cachedPath);
70
- if (await fsExists(cachedPath)) {
71
- debug("Cache hit: %s", cachedPath);
72
- logger?.info(`Using cached Node.js ${target.nodeVersion} for ${target.platform}-${target.arch}`);
73
- return cachedPath;
74
- }
75
- const url = getDownloadUrl(target);
76
- debug("Cache miss, downloading from: %s", url);
77
- logger?.info(`Downloading Node.js ${target.nodeVersion} for ${target.platform}-${target.arch}...`);
78
- logger?.info(` ${url}`);
79
- await mkdir(path.dirname(cachedPath), { recursive: true });
80
- const response = await fetch(url);
81
- if (!response.ok) throw new Error(`Failed to download Node.js binary: HTTP ${response.status} from ${url}`);
82
- const archivePath = `${cachedPath}.download.${getArchiveExtension(target.platform)}`;
83
- const buffer = Buffer.from(await response.arrayBuffer());
84
- debug("Downloaded %d bytes, writing to: %s", buffer.length, archivePath);
85
- await writeFile(archivePath, buffer);
86
- try {
87
- await extractBinary(archivePath, cachedPath, target);
88
- if (target.platform !== "win") await chmod(cachedPath, 493);
89
- debug("Binary cached at: %s", cachedPath);
90
- logger?.info(`Cached Node.js binary at: ${cachedPath}`);
91
- } finally {
92
- await fsRemove(archivePath);
93
- }
94
- return cachedPath;
95
- }
96
- async function extractBinary(archivePath, targetBinaryPath, target) {
97
- const binaryInArchive = getBinaryPathInArchive(target);
98
- const outDir = path.dirname(targetBinaryPath);
99
- debug("Extracting %s from archive to %s", binaryInArchive, outDir);
100
- if (target.platform === "win") await x("tar", [
101
- "-xf",
102
- archivePath,
103
- "-C",
104
- outDir,
105
- "--strip-components=1",
106
- binaryInArchive
107
- ], {
108
- nodeOptions: { stdio: "inherit" },
109
- throwOnError: true
110
- });
111
- else await x("tar", [
112
- `-x${archivePath.endsWith(".tar.xz") ? "J" : "z"}f`,
113
- archivePath,
114
- "-C",
115
- outDir,
116
- "--strip-components=2",
117
- binaryInArchive
118
- ], {
119
- nodeOptions: { stdio: "inherit" },
120
- throwOnError: true
121
- });
122
- const extractedName = target.platform === "win" ? "node.exe" : "node";
123
- const extractedPath = path.join(outDir, extractedName);
124
- if (extractedPath !== targetBinaryPath) await rename(extractedPath, targetBinaryPath);
125
- }
126
- //#endregion
127
- export { getCacheDir, getCachedBinaryPath, getTargetSuffix, resolveNodeBinary };
1
+ import"node:module";import e from"node:os";import t from"node:path";import n from"node:process";import{Buffer as r}from"node:buffer";import{chmod as i,mkdir as a,rename as o,writeFile as s}from"node:fs/promises";import{createDebug as c}from"obug";import{x as l}from"tinyexec";import{fsExists as u,fsRemove as d}from"@longzai-intelligence-builder/core";import f from"semver/functions/satisfies.js";import p from"semver/functions/valid.js";function m(){let r=e.homedir();if(n.platform===`win32`){let e=n.env.LOCALAPPDATA||t.join(r,`AppData/Local`);return t.join(e,`lzi-builder/Caches`)}if(n.platform===`darwin`)return t.join(r,`Library/Caches/lzi-builder`);let i=n.env.XDG_CACHE_HOME||t.join(r,`.cache`);return t.join(i,`lzi-builder`)}function h(e){let n=m(),r=e.platform===`win`?`node.exe`:`node`;return t.join(n,`node`,`v${e.nodeVersion}`,`${e.platform}-${e.arch}`,r)}function g(e){return e===`win`?`zip`:e===`linux`?`tar.xz`:`tar.gz`}function _(e){let{platform:t,arch:n,nodeVersion:r}=e;return`https://nodejs.org/dist/v${r}/node-v${r}-${t}-${n}.${g(t)}`}function v(e){let{platform:t,arch:n,nodeVersion:r}=e,i=`node-v${r}-${t}-${n}`;return t===`win`?`${i}/node.exe`:`${i}/bin/node`}const y=`https://nodejs.org/dist/index.json`;async function b(e){if(e===`latest`||e===`latest-lts`){let t=await fetch(y);if(!t.ok)throw Error(`Failed to fetch Node.js releases: HTTP ${t.status} from ${y}`);let n=await t.json(),r=e===`latest`?n[0]:n.find(e=>e.lts!==!1);if(!r)throw Error(`No matching Node.js release found for "${e}".`);e=r.version.replace(/^v/,``)}let t=p(e);if(!t)throw Error(`Invalid Node.js version: ${e}. Please provide a valid version string (e.g., "25.7.0").`);if(!f(t,`>=25.7.0`))throw Error(`Node.js ${t} does not support SEA (Single Executable Applications). Required minimum version is 25.7.0. Please update the nodeVersion in your target configuration.`);return t}function x(e){return`-${e.platform}-${e.arch}`}const S=c(`lzi-builder:exe:download`);async function C(e,n){S(`Resolving Node.js binary for target: %O`,e),e.nodeVersion=await b(e.nodeVersion);let o=h(e);if(S(`Cache path: %s`,o),await u(o))return S(`Cache hit: %s`,o),n?.info(`Using cached Node.js ${e.nodeVersion} for ${e.platform}-${e.arch}`),o;let c=_(e);S(`Cache miss, downloading from: %s`,c),n?.info(`Downloading Node.js ${e.nodeVersion} for ${e.platform}-${e.arch}...`),n?.info(` ${c}`),await a(t.dirname(o),{recursive:!0});let l=await fetch(c);if(!l.ok)throw Error(`Failed to download Node.js binary: HTTP ${l.status} from ${c}`);let f=`${o}.download.${g(e.platform)}`,p=r.from(await l.arrayBuffer());S(`Downloaded %d bytes, writing to: %s`,p.length,f),await s(f,p);try{await w(f,o,e),e.platform!==`win`&&await i(o,493),S(`Binary cached at: %s`,o),n?.info(`Cached Node.js binary at: ${o}`)}finally{await d(f)}return o}async function w(e,n,r){let i=v(r),a=t.dirname(n);S(`Extracting %s from archive to %s`,i,a),r.platform===`win`?await l(`tar`,[`-xf`,e,`-C`,a,`--strip-components=1`,i],{nodeOptions:{stdio:`inherit`},throwOnError:!0}):await l(`tar`,[`-x${e.endsWith(`.tar.xz`)?`J`:`z`}f`,e,`-C`,a,`--strip-components=2`,i],{nodeOptions:{stdio:`inherit`},throwOnError:!0});let s=r.platform===`win`?`node.exe`:`node`,c=t.join(a,s);c!==n&&await o(c,n)}export{m as getCacheDir,h as getCachedBinaryPath,x as getTargetSuffix,C as resolveNodeBinary};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-builder/exe",
3
3
  "type": "module",
4
- "version": "0.2.11",
4
+ "version": "0.2.13",
5
5
  "license": "UNLICENSED",
6
6
  "exports": {
7
7
  ".": "./dist/index.mjs",
@@ -15,8 +15,8 @@
15
15
  "node": "^22.18.0 || >=24.11.0"
16
16
  },
17
17
  "scripts": {
18
- "build": "tsdown",
19
- "build:prod": "NODE_ENV=production tsdown",
18
+ "build": "lzi-builder",
19
+ "build:prod": "NODE_ENV=production lzi-builder",
20
20
  "prepublishOnly": "bun run build:prod",
21
21
  "typecheck": "tsgo --noEmit",
22
22
  "lint": "oxlint && oxfmt --check",
@@ -24,11 +24,14 @@
24
24
  "clean": "lzi-dev-cli clean"
25
25
  },
26
26
  "peerDependencies": {
27
- "@longzai-intelligence-builder/core": "0.2.10"
27
+ "@longzai-intelligence-builder/core": "0.2.13"
28
28
  },
29
29
  "dependencies": {
30
30
  "obug": "^2.1.3",
31
31
  "semver": "^7.8.5",
32
32
  "tinyexec": "^1.2.4"
33
+ },
34
+ "devDependencies": {
35
+ "@longzai-intelligence-builder/esm": "0.2.13"
33
36
  }
34
37
  }