@t2code/cli 0.1.4-nightly.20261029.136 → 0.1.6-nightly.20261110.707

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/bin/t2code.mjs +55 -3
  2. package/package.json +4 -1
package/bin/t2code.mjs CHANGED
@@ -93,6 +93,24 @@ async function install(dir, key) {
93
93
  });
94
94
  if (extract.status !== 0) throw new Error(`could not extract ${archive}`);
95
95
  fs.rmSync(file);
96
+ const validate = spawnSync(
97
+ path.join(staging, process.platform === "win32" ? "t2.exe" : "t2"),
98
+ ["--version"],
99
+ {
100
+ stdio: ["ignore", "ignore", "pipe"],
101
+ encoding: "utf8",
102
+ timeout: 30_000,
103
+ killSignal: "SIGKILL",
104
+ },
105
+ );
106
+ if (validate.status !== 0) {
107
+ throw executableError(
108
+ key,
109
+ validate.error?.message ||
110
+ validate.stderr?.trim() ||
111
+ `--version exited with ${validate.signal || validate.status}`,
112
+ );
113
+ }
96
114
  fs.writeFileSync(path.join(staging, ".install-complete"), `${version}\n`);
97
115
  publish(staging, dir);
98
116
  } finally {
@@ -117,11 +135,36 @@ const isComplete = (dir) => {
117
135
  function publish(staging, dir) {
118
136
  try {
119
137
  fs.renameSync(staging, dir);
138
+ return;
120
139
  } catch (error) {
121
140
  if (isComplete(dir)) return;
122
141
  if (!fs.existsSync(dir)) throw error;
123
- fs.rmSync(dir, { recursive: true, force: true });
124
- fs.renameSync(staging, dir);
142
+ }
143
+ const lock = `${dir}.lock`;
144
+ try {
145
+ fs.mkdirSync(lock);
146
+ } catch (error) {
147
+ if (error.code !== "EEXIST") throw error;
148
+ throw new Error(
149
+ `another t3 is installing ${version}. If none is running, delete ${lock} and try again.`,
150
+ { cause: error },
151
+ );
152
+ }
153
+ const stale = `${staging}.stale`;
154
+ try {
155
+ // A peer may have published between our marker check and taking the lock.
156
+ if (isComplete(dir)) return;
157
+ // Move it aside rather than deleting in place: once the folder is empty, a
158
+ // peer's first rename can land in it.
159
+ fs.renameSync(dir, stale);
160
+ try {
161
+ fs.renameSync(staging, dir);
162
+ } catch (error) {
163
+ if (!isComplete(dir)) throw error;
164
+ }
165
+ } finally {
166
+ fs.rmSync(lock, { recursive: true, force: true });
167
+ fs.rmSync(stale, { recursive: true, force: true });
125
168
  }
126
169
  }
127
170
 
@@ -155,12 +198,21 @@ async function main() {
155
198
  for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
156
199
  process.on(signal, () => (ipc || signal !== "SIGINT") && child.kill(signal));
157
200
  }
158
- child.on("error", (error) => fail(error));
201
+ child.on("error", (error) => fail(executableError(key, error.message)));
159
202
  child.on("exit", (code, signal) =>
160
203
  process.exit(code ?? 128 + (os.constants.signals[signal] || 1)),
161
204
  );
162
205
  }
163
206
 
207
+ function executableError(key, detail) {
208
+ return new Error(
209
+ `could not run T2 Code ${version} for ${key}: ${detail}` +
210
+ (process.platform === "linux"
211
+ ? "\nThe Linux release requires glibc; musl-based systems such as Alpine are not supported. Use a glibc-based Linux environment."
212
+ : ""),
213
+ );
214
+ }
215
+
164
216
  function fail(error) {
165
217
  process.stderr.write(`t2code: ${error.message}\n`);
166
218
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t2code/cli",
3
- "version": "0.1.4-nightly.20261029.136",
3
+ "version": "0.1.6-nightly.20261110.707",
4
4
  "description": "T2 Code CLI. Downloads the self-contained executable for this platform from the GitHub Release.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,5 +17,8 @@
17
17
  ],
18
18
  "engines": {
19
19
  "node": ">=20.11"
20
+ },
21
+ "t2code": {
22
+ "databaseMigration": 80
20
23
  }
21
24
  }