engine-kit 0.2.0 → 0.2.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/kit/budget.mjs CHANGED
@@ -50,7 +50,9 @@ const BUDGETS = {
50
50
  // `split("\n")` num arquivo terminado em newline devolve um elemento vazio no fim — linha
51
51
  // fantasma. Sem o `replace`, cada arquivo inflava a conta em 1 e o kill-switch disparava
52
52
  // por medição errada (foi o que aconteceu na primeira execução deste arquivo).
53
- const linesOf = (f) => readFileSync(f, "utf8").replace(/\n$/, "").split("\n");
53
+ // `\r?\n`: o checkout do Windows (autocrlf) traz CRLF, e o `\r` contaria 1 byte por linha — a mesma
54
+ // árvore mediria diferente no Linux e no Windows.
55
+ const linesOf = (f) => readFileSync(f, "utf8").replace(/\r?\n$/, "").split(/\r?\n/);
54
56
  const lines = (f) => linesOf(f).length;
55
57
 
56
58
  /** Bytes que não são linha em branco nem comentário de linha inteira. */
package/kit/update.mjs CHANGED
@@ -8,7 +8,8 @@
8
8
  // ENGINE_KIT_NO_AUTO_UPDATE=1 desliga: o kit não se troca nem troca motor já instalado, só AVISA da versão nova.
9
9
  // ENGINE_KIT_UPDATED_FROM marca o processo relançado, para não entrar em laço.
10
10
  import { spawnSync } from "node:child_process";
11
- import { readFileSync } from "node:fs";
11
+ import { readFileSync, existsSync } from "node:fs";
12
+ import { dirname, join } from "node:path";
12
13
 
13
14
  export const LATEST_URL = "https://registry.npmjs.org/engine-kit/latest";
14
15
 
@@ -30,9 +31,21 @@ async function fetchLatest() {
30
31
  return (await res.json()).version;
31
32
  }
32
33
 
34
+ /**
35
+ * Como relançar sem shell: npx no Windows é npx.cmd, e spawn de .cmd exige shell (argumentos concatenados, DEP0190
36
+ * no Node 24). Rodado pelo npx, `npm_execpath` aponta o npm-cli.js do npm em uso: node + esse arquivo não passa por shell.
37
+ * Fora do npx: o npm-cli.js que acompanha o node, ou o `npx` do PATH (Unix, sem shell).
38
+ */
39
+ export function relaunchCommand(version, args, { env = process.env, execPath = process.execPath, exists = existsSync } = {}) {
40
+ const npmArgs = ["exec", "--yes", `--package=engine-kit@${version}`, "--", "engine-kit", ...args];
41
+ const bundled = join(dirname(execPath), "node_modules", "npm", "bin", "npm-cli.js");
42
+ const cli = /npm-cli\.js$/.test(env.npm_execpath ?? "") ? env.npm_execpath : exists(bundled) ? bundled : null;
43
+ return cli ? { file: execPath, args: [cli, ...npmArgs] } : { file: "npx", args: ["--yes", `engine-kit@${version}`, ...args] };
44
+ }
45
+
33
46
  function runLatest(version, args, env) {
34
- // npx no Windows é npx.cmd: o spawn de .cmd exige shell. Argumentos aqui são nome de motor e flags simples.
35
- const r = spawnSync("npx", ["--yes", `engine-kit@${version}`, ...args], { stdio: "inherit", shell: process.platform === "win32", windowsHide: true, env });
47
+ const c = relaunchCommand(version, args, { env });
48
+ const r = spawnSync(c.file, c.args, { stdio: "inherit", windowsHide: true, env });
36
49
  return r.error ? { status: 1, error: r.error.message } : { status: r.status ?? 1 };
37
50
  }
38
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "engine-kit",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Cliente das dependências compartilhadas (motores) do engine-registry: resolve, provisiona com SHA256 e assinatura Ed25519 fail-closed, e mantém o motor vivo — uma instalação por máquina, N consumidores.",
5
5
  "type": "module",
6
6
  "bin": {