codex-copilot-dx 0.9.38 → 0.9.39

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.
@@ -0,0 +1,77 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { readBoundedFileSync } from "./bounded-file.mjs";
5
+ import { withFileLockSync } from "./lock.mjs";
6
+
7
+ // Match npm's generated launcher, not an arbitrary script mentioning CCDX.
8
+ function npmPowerShellShim(target) {
9
+ return `#!/usr/bin/env pwsh
10
+ $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
11
+
12
+ $exe=""
13
+ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
14
+ # Fix case when both the Windows and Linux builds of Node
15
+ # are installed in the same directory
16
+ $exe=".exe"
17
+ }
18
+ $ret=0
19
+ if (Test-Path "$basedir/node$exe") {
20
+ # Support pipeline input
21
+ if ($MyInvocation.ExpectingInput) {
22
+ $input | & "$basedir/node$exe" "$basedir/${target}" $args
23
+ } else {
24
+ & "$basedir/node$exe" "$basedir/${target}" $args
25
+ }
26
+ $ret=$LASTEXITCODE
27
+ } else {
28
+ # Support pipeline input
29
+ if ($MyInvocation.ExpectingInput) {
30
+ $input | & "node$exe" "$basedir/${target}" $args
31
+ } else {
32
+ & "node$exe" "$basedir/${target}" $args
33
+ }
34
+ $ret=$LASTEXITCODE
35
+ }
36
+ exit $ret
37
+ `;
38
+ }
39
+
40
+ export function inspectWindowsCommand({ platform = process.platform,
41
+ packageRoot = fileURLToPath(new URL("../", import.meta.url)), repair = false, locked = false } = {}) {
42
+ if (platform !== "win32") return { status: "not_applicable", changed: false };
43
+ const root = path.resolve(packageRoot);
44
+ if (path.basename(path.dirname(root)).toLowerCase() !== "node_modules"
45
+ || path.basename(root) !== "codex-copilot-dx") return { status: "checkout", changed: false };
46
+ try {
47
+ const pkg = JSON.parse(readBoundedFileSync(path.join(root, "package.json"), { encoding: "utf8", maxBytes: 64 * 1024 }));
48
+ if (pkg.name !== "codex-copilot-dx" || pkg.bin?.ccdx !== "bin/cli.mjs"
49
+ || pkg.bin?.["codex-copilot-dx"] !== "bin/codex-copilot-dx.mjs") throw new Error();
50
+ } catch { return { status: "preserved", changed: false }; }
51
+ if (repair && !locked) return withFileLockSync(path.join(root, ".ccdx-command.lock"),
52
+ () => inspectWindowsCommand({ platform, packageRoot, repair, locked: true }), { timeoutMs: 1000 });
53
+ const prefix = path.dirname(path.dirname(root));
54
+ const results = [];
55
+ for (const [name, script] of [["ccdx", "cli.mjs"], ["codex-copilot-dx", "codex-copilot-dx.mjs"]]) {
56
+ const ps1 = path.join(prefix, `${name}.ps1`), cmd = path.join(prefix, `${name}.cmd`);
57
+ const target = `node_modules/codex-copilot-dx/bin/${script}`;
58
+ try {
59
+ if (!fs.lstatSync(cmd).isFile() || fs.statSync(cmd).size > 8192) throw new Error();
60
+ const batch = fs.readFileSync(cmd, "utf8");
61
+ if (!batch.startsWith("@ECHO off") || !batch.includes(`"%dp0%\\${target.replaceAll("/", "\\")}" %*`)) throw new Error();
62
+ let stat;
63
+ try { stat = fs.lstatSync(ps1); } catch (error) { if (error.code !== "ENOENT") throw error; }
64
+ if (!stat) { results.push({ name, status: "ready", changed: false });continue; }
65
+ if (!stat.isFile() || stat.size > 8192 || fs.readFileSync(ps1, "utf8").replaceAll("\r\n", "\n") !== npmPowerShellShim(target)) {
66
+ results.push({ name, status: "custom_preserved", changed: false });continue;
67
+ }
68
+ if (repair) fs.unlinkSync(ps1);
69
+ results.push({ name, status: repair ? "ready" : "repairable", changed: repair });
70
+ } catch {
71
+ results.push({ name, status: "unavailable", changed: false });
72
+ }
73
+ }
74
+ return { status: results.every(item => item.status === "ready") ? "ready"
75
+ : results.some(item => item.status === "repairable") ? "repairable" : "preserved",
76
+ changed: results.some(item => item.changed), commands: results };
77
+ }